diff options
Diffstat (limited to 'drivers/net/wireless/iwlwifi/dvm')
27 files changed, 28847 insertions, 0 deletions
diff --git a/drivers/net/wireless/iwlwifi/dvm/Makefile b/drivers/net/wireless/iwlwifi/dvm/Makefile new file mode 100644 index 000000000000..5ff76b204141 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | # DVM | ||
2 | obj-$(CONFIG_IWLDVM) += iwldvm.o | ||
3 | iwldvm-objs += main.o rs.o mac80211.o ucode.o tx.o | ||
4 | iwldvm-objs += lib.o calib.o tt.o sta.o rx.o | ||
5 | |||
6 | iwldvm-objs += power.o | ||
7 | iwldvm-objs += scan.o led.o | ||
8 | iwldvm-objs += rxon.o devices.o | ||
9 | |||
10 | iwldvm-$(CONFIG_IWLWIFI_DEBUGFS) += debugfs.o | ||
11 | iwldvm-$(CONFIG_IWLWIFI_DEVICE_TESTMODE) += testmode.o | ||
12 | |||
13 | ccflags-y += -D__CHECK_ENDIAN__ -I$(src)/../ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/agn.h b/drivers/net/wireless/iwlwifi/dvm/agn.h new file mode 100644 index 000000000000..2ae3608472a6 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/agn.h | |||
@@ -0,0 +1,524 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
4 | * redistributing this file, you may do so under either license. | ||
5 | * | ||
6 | * GPL LICENSE SUMMARY | ||
7 | * | ||
8 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of version 2 of the GNU General Public License as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
22 | * USA | ||
23 | * | ||
24 | * The full GNU General Public License is included in this distribution | ||
25 | * in the file called LICENSE.GPL. | ||
26 | * | ||
27 | * Contact Information: | ||
28 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
30 | * | ||
31 | * BSD LICENSE | ||
32 | * | ||
33 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. | ||
34 | * All rights reserved. | ||
35 | * | ||
36 | * Redistribution and use in source and binary forms, with or without | ||
37 | * modification, are permitted provided that the following conditions | ||
38 | * are met: | ||
39 | * | ||
40 | * * Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * * Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in | ||
44 | * the documentation and/or other materials provided with the | ||
45 | * distribution. | ||
46 | * * Neither the name Intel Corporation nor the names of its | ||
47 | * contributors may be used to endorse or promote products derived | ||
48 | * from this software without specific prior written permission. | ||
49 | * | ||
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
61 | *****************************************************************************/ | ||
62 | |||
63 | #ifndef __iwl_agn_h__ | ||
64 | #define __iwl_agn_h__ | ||
65 | |||
66 | #include "iwl-config.h" | ||
67 | |||
68 | #include "dev.h" | ||
69 | |||
70 | /* The first 11 queues (0-10) are used otherwise */ | ||
71 | #define IWLAGN_FIRST_AMPDU_QUEUE 11 | ||
72 | |||
73 | /* AUX (TX during scan dwell) queue */ | ||
74 | #define IWL_AUX_QUEUE 10 | ||
75 | |||
76 | /* device operations */ | ||
77 | extern struct iwl_lib_ops iwl1000_lib; | ||
78 | extern struct iwl_lib_ops iwl2000_lib; | ||
79 | extern struct iwl_lib_ops iwl2030_lib; | ||
80 | extern struct iwl_lib_ops iwl5000_lib; | ||
81 | extern struct iwl_lib_ops iwl5150_lib; | ||
82 | extern struct iwl_lib_ops iwl6000_lib; | ||
83 | extern struct iwl_lib_ops iwl6030_lib; | ||
84 | |||
85 | |||
86 | #define TIME_UNIT 1024 | ||
87 | |||
88 | /***************************************************** | ||
89 | * DRIVER STATUS FUNCTIONS | ||
90 | ******************************************************/ | ||
91 | #define STATUS_RF_KILL_HW 0 | ||
92 | #define STATUS_CT_KILL 1 | ||
93 | #define STATUS_ALIVE 2 | ||
94 | #define STATUS_READY 3 | ||
95 | #define STATUS_EXIT_PENDING 5 | ||
96 | #define STATUS_STATISTICS 6 | ||
97 | #define STATUS_SCANNING 7 | ||
98 | #define STATUS_SCAN_ABORTING 8 | ||
99 | #define STATUS_SCAN_HW 9 | ||
100 | #define STATUS_FW_ERROR 10 | ||
101 | #define STATUS_CHANNEL_SWITCH_PENDING 11 | ||
102 | #define STATUS_SCAN_COMPLETE 12 | ||
103 | #define STATUS_POWER_PMI 13 | ||
104 | #define STATUS_SCAN_ROC_EXPIRED 14 | ||
105 | |||
106 | struct iwl_ucode_capabilities; | ||
107 | |||
108 | extern struct ieee80211_ops iwlagn_hw_ops; | ||
109 | |||
110 | static inline void iwl_set_calib_hdr(struct iwl_calib_hdr *hdr, u8 cmd) | ||
111 | { | ||
112 | hdr->op_code = cmd; | ||
113 | hdr->first_group = 0; | ||
114 | hdr->groups_num = 1; | ||
115 | hdr->data_valid = 1; | ||
116 | } | ||
117 | |||
118 | void iwl_down(struct iwl_priv *priv); | ||
119 | void iwl_cancel_deferred_work(struct iwl_priv *priv); | ||
120 | void iwlagn_prepare_restart(struct iwl_priv *priv); | ||
121 | int __must_check iwl_rx_dispatch(struct iwl_op_mode *op_mode, | ||
122 | struct iwl_rx_cmd_buffer *rxb, | ||
123 | struct iwl_device_cmd *cmd); | ||
124 | |||
125 | bool iwl_check_for_ct_kill(struct iwl_priv *priv); | ||
126 | |||
127 | void iwlagn_lift_passive_no_rx(struct iwl_priv *priv); | ||
128 | |||
129 | /* MAC80211 */ | ||
130 | struct ieee80211_hw *iwl_alloc_all(void); | ||
131 | int iwlagn_mac_setup_register(struct iwl_priv *priv, | ||
132 | const struct iwl_ucode_capabilities *capa); | ||
133 | void iwlagn_mac_unregister(struct iwl_priv *priv); | ||
134 | |||
135 | /* commands */ | ||
136 | int iwl_dvm_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd); | ||
137 | int iwl_dvm_send_cmd_pdu(struct iwl_priv *priv, u8 id, | ||
138 | u32 flags, u16 len, const void *data); | ||
139 | |||
140 | /* RXON */ | ||
141 | void iwl_connection_init_rx_config(struct iwl_priv *priv, | ||
142 | struct iwl_rxon_context *ctx); | ||
143 | int iwlagn_set_pan_params(struct iwl_priv *priv); | ||
144 | int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx); | ||
145 | void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx); | ||
146 | int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed); | ||
147 | void iwlagn_bss_info_changed(struct ieee80211_hw *hw, | ||
148 | struct ieee80211_vif *vif, | ||
149 | struct ieee80211_bss_conf *bss_conf, | ||
150 | u32 changes); | ||
151 | void iwlagn_config_ht40(struct ieee80211_conf *conf, | ||
152 | struct iwl_rxon_context *ctx); | ||
153 | void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf); | ||
154 | void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch, | ||
155 | struct iwl_rxon_context *ctx); | ||
156 | void iwl_set_flags_for_band(struct iwl_priv *priv, | ||
157 | struct iwl_rxon_context *ctx, | ||
158 | enum ieee80211_band band, | ||
159 | struct ieee80211_vif *vif); | ||
160 | |||
161 | /* uCode */ | ||
162 | int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type); | ||
163 | void iwl_send_prio_tbl(struct iwl_priv *priv); | ||
164 | int iwl_init_alive_start(struct iwl_priv *priv); | ||
165 | int iwl_run_init_ucode(struct iwl_priv *priv); | ||
166 | int iwl_load_ucode_wait_alive(struct iwl_priv *priv, | ||
167 | enum iwl_ucode_type ucode_type); | ||
168 | int iwl_send_calib_results(struct iwl_priv *priv); | ||
169 | int iwl_calib_set(struct iwl_priv *priv, | ||
170 | const struct iwl_calib_hdr *cmd, int len); | ||
171 | void iwl_calib_free_results(struct iwl_priv *priv); | ||
172 | int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log, | ||
173 | char **buf, bool display); | ||
174 | int iwlagn_hw_valid_rtc_data_addr(u32 addr); | ||
175 | |||
176 | /* lib */ | ||
177 | int iwlagn_send_tx_power(struct iwl_priv *priv); | ||
178 | void iwlagn_temperature(struct iwl_priv *priv); | ||
179 | int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control); | ||
180 | void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control); | ||
181 | int iwlagn_send_beacon_cmd(struct iwl_priv *priv); | ||
182 | int iwl_send_statistics_request(struct iwl_priv *priv, | ||
183 | u8 flags, bool clear); | ||
184 | |||
185 | static inline const struct ieee80211_supported_band *iwl_get_hw_mode( | ||
186 | struct iwl_priv *priv, enum ieee80211_band band) | ||
187 | { | ||
188 | return priv->hw->wiphy->bands[band]; | ||
189 | } | ||
190 | |||
191 | #ifdef CONFIG_PM_SLEEP | ||
192 | int iwlagn_send_patterns(struct iwl_priv *priv, | ||
193 | struct cfg80211_wowlan *wowlan); | ||
194 | int iwlagn_suspend(struct iwl_priv *priv, struct cfg80211_wowlan *wowlan); | ||
195 | #endif | ||
196 | |||
197 | /* rx */ | ||
198 | int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band); | ||
199 | void iwl_setup_rx_handlers(struct iwl_priv *priv); | ||
200 | void iwl_chswitch_done(struct iwl_priv *priv, bool is_success); | ||
201 | |||
202 | |||
203 | /* tx */ | ||
204 | int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb); | ||
205 | int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif, | ||
206 | struct ieee80211_sta *sta, u16 tid, u16 *ssn); | ||
207 | int iwlagn_tx_agg_oper(struct iwl_priv *priv, struct ieee80211_vif *vif, | ||
208 | struct ieee80211_sta *sta, u16 tid, u8 buf_size); | ||
209 | int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif, | ||
210 | struct ieee80211_sta *sta, u16 tid); | ||
211 | int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv, | ||
212 | struct iwl_rx_cmd_buffer *rxb, | ||
213 | struct iwl_device_cmd *cmd); | ||
214 | int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, | ||
215 | struct iwl_device_cmd *cmd); | ||
216 | |||
217 | static inline u32 iwl_tx_status_to_mac80211(u32 status) | ||
218 | { | ||
219 | status &= TX_STATUS_MSK; | ||
220 | |||
221 | switch (status) { | ||
222 | case TX_STATUS_SUCCESS: | ||
223 | case TX_STATUS_DIRECT_DONE: | ||
224 | return IEEE80211_TX_STAT_ACK; | ||
225 | case TX_STATUS_FAIL_DEST_PS: | ||
226 | case TX_STATUS_FAIL_PASSIVE_NO_RX: | ||
227 | return IEEE80211_TX_STAT_TX_FILTERED; | ||
228 | default: | ||
229 | return 0; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | static inline bool iwl_is_tx_success(u32 status) | ||
234 | { | ||
235 | status &= TX_STATUS_MSK; | ||
236 | return (status == TX_STATUS_SUCCESS) || | ||
237 | (status == TX_STATUS_DIRECT_DONE); | ||
238 | } | ||
239 | |||
240 | u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid); | ||
241 | |||
242 | /* scan */ | ||
243 | void iwlagn_post_scan(struct iwl_priv *priv); | ||
244 | void iwlagn_disable_roc(struct iwl_priv *priv); | ||
245 | int iwl_force_rf_reset(struct iwl_priv *priv, bool external); | ||
246 | void iwl_init_scan_params(struct iwl_priv *priv); | ||
247 | int iwl_scan_cancel(struct iwl_priv *priv); | ||
248 | void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms); | ||
249 | void iwl_force_scan_end(struct iwl_priv *priv); | ||
250 | void iwl_internal_short_hw_scan(struct iwl_priv *priv); | ||
251 | void iwl_setup_rx_scan_handlers(struct iwl_priv *priv); | ||
252 | void iwl_setup_scan_deferred_work(struct iwl_priv *priv); | ||
253 | void iwl_cancel_scan_deferred_work(struct iwl_priv *priv); | ||
254 | int __must_check iwl_scan_initiate(struct iwl_priv *priv, | ||
255 | struct ieee80211_vif *vif, | ||
256 | enum iwl_scan_type scan_type, | ||
257 | enum ieee80211_band band); | ||
258 | |||
259 | void iwl_scan_roc_expired(struct iwl_priv *priv); | ||
260 | void iwl_scan_offchannel_skb(struct iwl_priv *priv); | ||
261 | void iwl_scan_offchannel_skb_status(struct iwl_priv *priv); | ||
262 | |||
263 | /* For faster active scanning, scan will move to the next channel if fewer than | ||
264 | * PLCP_QUIET_THRESH packets are heard on this channel within | ||
265 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell | ||
266 | * time if it's a quiet channel (nothing responded to our probe, and there's | ||
267 | * no other traffic). | ||
268 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ | ||
269 | #define IWL_ACTIVE_QUIET_TIME cpu_to_le16(10) /* msec */ | ||
270 | #define IWL_PLCP_QUIET_THRESH cpu_to_le16(1) /* packets */ | ||
271 | |||
272 | #define IWL_SCAN_CHECK_WATCHDOG (HZ * 7) | ||
273 | |||
274 | |||
275 | /* bt coex */ | ||
276 | void iwlagn_send_advance_bt_config(struct iwl_priv *priv); | ||
277 | int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv, | ||
278 | struct iwl_rx_cmd_buffer *rxb, | ||
279 | struct iwl_device_cmd *cmd); | ||
280 | void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv); | ||
281 | void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv); | ||
282 | void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv); | ||
283 | void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv); | ||
284 | void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena); | ||
285 | |||
286 | static inline bool iwl_advanced_bt_coexist(struct iwl_priv *priv) | ||
287 | { | ||
288 | return priv->cfg->bt_params && | ||
289 | priv->cfg->bt_params->advanced_bt_coexist; | ||
290 | } | ||
291 | |||
292 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
293 | const char *iwl_get_tx_fail_reason(u32 status); | ||
294 | const char *iwl_get_agg_tx_fail_reason(u16 status); | ||
295 | #else | ||
296 | static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; } | ||
297 | static inline const char *iwl_get_agg_tx_fail_reason(u16 status) { return ""; } | ||
298 | #endif | ||
299 | |||
300 | |||
301 | /* station management */ | ||
302 | int iwlagn_manage_ibss_station(struct iwl_priv *priv, | ||
303 | struct ieee80211_vif *vif, bool add); | ||
304 | #define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */ | ||
305 | #define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */ | ||
306 | #define IWL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of | ||
307 | being activated */ | ||
308 | #define IWL_STA_LOCAL BIT(3) /* station state not directed by mac80211; | ||
309 | (this is for the IBSS BSSID stations) */ | ||
310 | #define IWL_STA_BCAST BIT(4) /* this station is the special bcast station */ | ||
311 | |||
312 | |||
313 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx); | ||
314 | void iwl_clear_ucode_stations(struct iwl_priv *priv, | ||
315 | struct iwl_rxon_context *ctx); | ||
316 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv); | ||
317 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv); | ||
318 | int iwl_send_add_sta(struct iwl_priv *priv, | ||
319 | struct iwl_addsta_cmd *sta, u8 flags); | ||
320 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
321 | const u8 *addr, bool is_ap, | ||
322 | struct ieee80211_sta *sta, u8 *sta_id_r); | ||
323 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, | ||
324 | const u8 *addr); | ||
325 | void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id, | ||
326 | const u8 *addr); | ||
327 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
328 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta); | ||
329 | |||
330 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
331 | struct iwl_link_quality_cmd *lq, u8 flags, bool init); | ||
332 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, | ||
333 | struct iwl_device_cmd *cmd); | ||
334 | int iwl_sta_update_ht(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
335 | struct ieee80211_sta *sta); | ||
336 | |||
337 | bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv, | ||
338 | struct iwl_rxon_context *ctx, | ||
339 | struct ieee80211_sta_ht_cap *ht_cap); | ||
340 | |||
341 | static inline int iwl_sta_id(struct ieee80211_sta *sta) | ||
342 | { | ||
343 | if (WARN_ON(!sta)) | ||
344 | return IWL_INVALID_STATION; | ||
345 | |||
346 | return ((struct iwl_station_priv *)sta->drv_priv)->sta_id; | ||
347 | } | ||
348 | |||
349 | int iwlagn_alloc_bcast_station(struct iwl_priv *priv, | ||
350 | struct iwl_rxon_context *ctx); | ||
351 | int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
352 | const u8 *addr, u8 *sta_id_r); | ||
353 | int iwl_remove_default_wep_key(struct iwl_priv *priv, | ||
354 | struct iwl_rxon_context *ctx, | ||
355 | struct ieee80211_key_conf *key); | ||
356 | int iwl_set_default_wep_key(struct iwl_priv *priv, | ||
357 | struct iwl_rxon_context *ctx, | ||
358 | struct ieee80211_key_conf *key); | ||
359 | int iwl_restore_default_wep_keys(struct iwl_priv *priv, | ||
360 | struct iwl_rxon_context *ctx); | ||
361 | int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
362 | struct ieee80211_key_conf *key, | ||
363 | struct ieee80211_sta *sta); | ||
364 | int iwl_remove_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
365 | struct ieee80211_key_conf *key, | ||
366 | struct ieee80211_sta *sta); | ||
367 | void iwl_update_tkip_key(struct iwl_priv *priv, | ||
368 | struct ieee80211_vif *vif, | ||
369 | struct ieee80211_key_conf *keyconf, | ||
370 | struct ieee80211_sta *sta, u32 iv32, u16 *phase1key); | ||
371 | int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid); | ||
372 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, | ||
373 | int tid, u16 ssn); | ||
374 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, | ||
375 | int tid); | ||
376 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt); | ||
377 | int iwl_update_bcast_station(struct iwl_priv *priv, | ||
378 | struct iwl_rxon_context *ctx); | ||
379 | int iwl_update_bcast_stations(struct iwl_priv *priv); | ||
380 | |||
381 | /* rate */ | ||
382 | static inline u32 iwl_ant_idx_to_flags(u8 ant_idx) | ||
383 | { | ||
384 | return BIT(ant_idx) << RATE_MCS_ANT_POS; | ||
385 | } | ||
386 | |||
387 | static inline u8 iwl_hw_get_rate(__le32 rate_n_flags) | ||
388 | { | ||
389 | return le32_to_cpu(rate_n_flags) & RATE_MCS_RATE_MSK; | ||
390 | } | ||
391 | |||
392 | static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u32 flags) | ||
393 | { | ||
394 | return cpu_to_le32(flags|(u32)rate); | ||
395 | } | ||
396 | |||
397 | extern int iwl_alive_start(struct iwl_priv *priv); | ||
398 | /* svtool */ | ||
399 | #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE | ||
400 | extern int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, | ||
401 | int len); | ||
402 | extern int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, | ||
403 | struct sk_buff *skb, | ||
404 | struct netlink_callback *cb, | ||
405 | void *data, int len); | ||
406 | extern void iwl_testmode_init(struct iwl_priv *priv); | ||
407 | extern void iwl_testmode_cleanup(struct iwl_priv *priv); | ||
408 | #else | ||
409 | static inline | ||
410 | int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len) | ||
411 | { | ||
412 | return -ENOSYS; | ||
413 | } | ||
414 | static inline | ||
415 | int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb, | ||
416 | struct netlink_callback *cb, | ||
417 | void *data, int len) | ||
418 | { | ||
419 | return -ENOSYS; | ||
420 | } | ||
421 | static inline | ||
422 | void iwl_testmode_init(struct iwl_priv *priv) | ||
423 | { | ||
424 | } | ||
425 | static inline | ||
426 | void iwl_testmode_cleanup(struct iwl_priv *priv) | ||
427 | { | ||
428 | } | ||
429 | #endif | ||
430 | |||
431 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
432 | void iwl_print_rx_config_cmd(struct iwl_priv *priv, | ||
433 | enum iwl_rxon_context_id ctxid); | ||
434 | #else | ||
435 | static inline void iwl_print_rx_config_cmd(struct iwl_priv *priv, | ||
436 | enum iwl_rxon_context_id ctxid) | ||
437 | { | ||
438 | } | ||
439 | #endif | ||
440 | |||
441 | /* status checks */ | ||
442 | |||
443 | static inline int iwl_is_ready(struct iwl_priv *priv) | ||
444 | { | ||
445 | /* The adapter is 'ready' if READY EXIT_PENDING is not set */ | ||
446 | return test_bit(STATUS_READY, &priv->status) && | ||
447 | !test_bit(STATUS_EXIT_PENDING, &priv->status); | ||
448 | } | ||
449 | |||
450 | static inline int iwl_is_alive(struct iwl_priv *priv) | ||
451 | { | ||
452 | return test_bit(STATUS_ALIVE, &priv->status); | ||
453 | } | ||
454 | |||
455 | static inline int iwl_is_rfkill(struct iwl_priv *priv) | ||
456 | { | ||
457 | return test_bit(STATUS_RF_KILL_HW, &priv->status); | ||
458 | } | ||
459 | |||
460 | static inline int iwl_is_ctkill(struct iwl_priv *priv) | ||
461 | { | ||
462 | return test_bit(STATUS_CT_KILL, &priv->status); | ||
463 | } | ||
464 | |||
465 | static inline int iwl_is_ready_rf(struct iwl_priv *priv) | ||
466 | { | ||
467 | if (iwl_is_rfkill(priv)) | ||
468 | return 0; | ||
469 | |||
470 | return iwl_is_ready(priv); | ||
471 | } | ||
472 | |||
473 | static inline void iwl_dvm_set_pmi(struct iwl_priv *priv, bool state) | ||
474 | { | ||
475 | if (state) | ||
476 | set_bit(STATUS_POWER_PMI, &priv->status); | ||
477 | else | ||
478 | clear_bit(STATUS_POWER_PMI, &priv->status); | ||
479 | iwl_trans_set_pmi(priv->trans, state); | ||
480 | } | ||
481 | |||
482 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
483 | int iwl_dbgfs_register(struct iwl_priv *priv, const char *name); | ||
484 | void iwl_dbgfs_unregister(struct iwl_priv *priv); | ||
485 | #else | ||
486 | static inline int iwl_dbgfs_register(struct iwl_priv *priv, const char *name) | ||
487 | { | ||
488 | return 0; | ||
489 | } | ||
490 | static inline void iwl_dbgfs_unregister(struct iwl_priv *priv) | ||
491 | { | ||
492 | } | ||
493 | #endif /* CONFIG_IWLWIFI_DEBUGFS */ | ||
494 | |||
495 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
496 | #define IWL_DEBUG_QUIET_RFKILL(m, fmt, args...) \ | ||
497 | do { \ | ||
498 | if (!iwl_is_rfkill((m))) \ | ||
499 | IWL_ERR(m, fmt, ##args); \ | ||
500 | else \ | ||
501 | __iwl_err((m)->dev, true, \ | ||
502 | !iwl_have_debug_level(IWL_DL_RADIO), \ | ||
503 | fmt, ##args); \ | ||
504 | } while (0) | ||
505 | #else | ||
506 | #define IWL_DEBUG_QUIET_RFKILL(m, fmt, args...) \ | ||
507 | do { \ | ||
508 | if (!iwl_is_rfkill((m))) \ | ||
509 | IWL_ERR(m, fmt, ##args); \ | ||
510 | else \ | ||
511 | __iwl_err((m)->dev, true, true, fmt, ##args); \ | ||
512 | } while (0) | ||
513 | #endif /* CONFIG_IWLWIFI_DEBUG */ | ||
514 | |||
515 | extern const char *iwl_dvm_cmd_strings[REPLY_MAX]; | ||
516 | |||
517 | static inline const char *iwl_dvm_get_cmd_string(u8 cmd) | ||
518 | { | ||
519 | const char *s = iwl_dvm_cmd_strings[cmd]; | ||
520 | if (s) | ||
521 | return s; | ||
522 | return "UNKNOWN"; | ||
523 | } | ||
524 | #endif /* __iwl_agn_h__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/calib.c b/drivers/net/wireless/iwlwifi/dvm/calib.c new file mode 100644 index 000000000000..f2dd671d7dc8 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/calib.c | |||
@@ -0,0 +1,1114 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
4 | * redistributing this file, you may do so under either license. | ||
5 | * | ||
6 | * GPL LICENSE SUMMARY | ||
7 | * | ||
8 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of version 2 of the GNU General Public License as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
22 | * USA | ||
23 | * | ||
24 | * The full GNU General Public License is included in this distribution | ||
25 | * in the file called LICENSE.GPL. | ||
26 | * | ||
27 | * Contact Information: | ||
28 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
30 | * | ||
31 | * BSD LICENSE | ||
32 | * | ||
33 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. | ||
34 | * All rights reserved. | ||
35 | * | ||
36 | * Redistribution and use in source and binary forms, with or without | ||
37 | * modification, are permitted provided that the following conditions | ||
38 | * are met: | ||
39 | * | ||
40 | * * Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * * Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in | ||
44 | * the documentation and/or other materials provided with the | ||
45 | * distribution. | ||
46 | * * Neither the name Intel Corporation nor the names of its | ||
47 | * contributors may be used to endorse or promote products derived | ||
48 | * from this software without specific prior written permission. | ||
49 | * | ||
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
61 | *****************************************************************************/ | ||
62 | |||
63 | #include <linux/slab.h> | ||
64 | #include <net/mac80211.h> | ||
65 | |||
66 | #include "iwl-trans.h" | ||
67 | |||
68 | #include "dev.h" | ||
69 | #include "calib.h" | ||
70 | #include "agn.h" | ||
71 | |||
72 | /***************************************************************************** | ||
73 | * INIT calibrations framework | ||
74 | *****************************************************************************/ | ||
75 | |||
76 | /* Opaque calibration results */ | ||
77 | struct iwl_calib_result { | ||
78 | struct list_head list; | ||
79 | size_t cmd_len; | ||
80 | struct iwl_calib_hdr hdr; | ||
81 | /* data follows */ | ||
82 | }; | ||
83 | |||
84 | struct statistics_general_data { | ||
85 | u32 beacon_silence_rssi_a; | ||
86 | u32 beacon_silence_rssi_b; | ||
87 | u32 beacon_silence_rssi_c; | ||
88 | u32 beacon_energy_a; | ||
89 | u32 beacon_energy_b; | ||
90 | u32 beacon_energy_c; | ||
91 | }; | ||
92 | |||
93 | int iwl_send_calib_results(struct iwl_priv *priv) | ||
94 | { | ||
95 | struct iwl_host_cmd hcmd = { | ||
96 | .id = REPLY_PHY_CALIBRATION_CMD, | ||
97 | .flags = CMD_SYNC, | ||
98 | }; | ||
99 | struct iwl_calib_result *res; | ||
100 | |||
101 | list_for_each_entry(res, &priv->calib_results, list) { | ||
102 | int ret; | ||
103 | |||
104 | hcmd.len[0] = res->cmd_len; | ||
105 | hcmd.data[0] = &res->hdr; | ||
106 | hcmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; | ||
107 | ret = iwl_dvm_send_cmd(priv, &hcmd); | ||
108 | if (ret) { | ||
109 | IWL_ERR(priv, "Error %d on calib cmd %d\n", | ||
110 | ret, res->hdr.op_code); | ||
111 | return ret; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | int iwl_calib_set(struct iwl_priv *priv, | ||
119 | const struct iwl_calib_hdr *cmd, int len) | ||
120 | { | ||
121 | struct iwl_calib_result *res, *tmp; | ||
122 | |||
123 | res = kmalloc(sizeof(*res) + len - sizeof(struct iwl_calib_hdr), | ||
124 | GFP_ATOMIC); | ||
125 | if (!res) | ||
126 | return -ENOMEM; | ||
127 | memcpy(&res->hdr, cmd, len); | ||
128 | res->cmd_len = len; | ||
129 | |||
130 | list_for_each_entry(tmp, &priv->calib_results, list) { | ||
131 | if (tmp->hdr.op_code == res->hdr.op_code) { | ||
132 | list_replace(&tmp->list, &res->list); | ||
133 | kfree(tmp); | ||
134 | return 0; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | /* wasn't in list already */ | ||
139 | list_add_tail(&res->list, &priv->calib_results); | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | void iwl_calib_free_results(struct iwl_priv *priv) | ||
145 | { | ||
146 | struct iwl_calib_result *res, *tmp; | ||
147 | |||
148 | list_for_each_entry_safe(res, tmp, &priv->calib_results, list) { | ||
149 | list_del(&res->list); | ||
150 | kfree(res); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | /***************************************************************************** | ||
155 | * RUNTIME calibrations framework | ||
156 | *****************************************************************************/ | ||
157 | |||
158 | /* "false alarms" are signals that our DSP tries to lock onto, | ||
159 | * but then determines that they are either noise, or transmissions | ||
160 | * from a distant wireless network (also "noise", really) that get | ||
161 | * "stepped on" by stronger transmissions within our own network. | ||
162 | * This algorithm attempts to set a sensitivity level that is high | ||
163 | * enough to receive all of our own network traffic, but not so | ||
164 | * high that our DSP gets too busy trying to lock onto non-network | ||
165 | * activity/noise. */ | ||
166 | static int iwl_sens_energy_cck(struct iwl_priv *priv, | ||
167 | u32 norm_fa, | ||
168 | u32 rx_enable_time, | ||
169 | struct statistics_general_data *rx_info) | ||
170 | { | ||
171 | u32 max_nrg_cck = 0; | ||
172 | int i = 0; | ||
173 | u8 max_silence_rssi = 0; | ||
174 | u32 silence_ref = 0; | ||
175 | u8 silence_rssi_a = 0; | ||
176 | u8 silence_rssi_b = 0; | ||
177 | u8 silence_rssi_c = 0; | ||
178 | u32 val; | ||
179 | |||
180 | /* "false_alarms" values below are cross-multiplications to assess the | ||
181 | * numbers of false alarms within the measured period of actual Rx | ||
182 | * (Rx is off when we're txing), vs the min/max expected false alarms | ||
183 | * (some should be expected if rx is sensitive enough) in a | ||
184 | * hypothetical listening period of 200 time units (TU), 204.8 msec: | ||
185 | * | ||
186 | * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time | ||
187 | * | ||
188 | * */ | ||
189 | u32 false_alarms = norm_fa * 200 * 1024; | ||
190 | u32 max_false_alarms = MAX_FA_CCK * rx_enable_time; | ||
191 | u32 min_false_alarms = MIN_FA_CCK * rx_enable_time; | ||
192 | struct iwl_sensitivity_data *data = NULL; | ||
193 | const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens; | ||
194 | |||
195 | data = &(priv->sensitivity_data); | ||
196 | |||
197 | data->nrg_auto_corr_silence_diff = 0; | ||
198 | |||
199 | /* Find max silence rssi among all 3 receivers. | ||
200 | * This is background noise, which may include transmissions from other | ||
201 | * networks, measured during silence before our network's beacon */ | ||
202 | silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a & | ||
203 | ALL_BAND_FILTER) >> 8); | ||
204 | silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b & | ||
205 | ALL_BAND_FILTER) >> 8); | ||
206 | silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c & | ||
207 | ALL_BAND_FILTER) >> 8); | ||
208 | |||
209 | val = max(silence_rssi_b, silence_rssi_c); | ||
210 | max_silence_rssi = max(silence_rssi_a, (u8) val); | ||
211 | |||
212 | /* Store silence rssi in 20-beacon history table */ | ||
213 | data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi; | ||
214 | data->nrg_silence_idx++; | ||
215 | if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L) | ||
216 | data->nrg_silence_idx = 0; | ||
217 | |||
218 | /* Find max silence rssi across 20 beacon history */ | ||
219 | for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) { | ||
220 | val = data->nrg_silence_rssi[i]; | ||
221 | silence_ref = max(silence_ref, val); | ||
222 | } | ||
223 | IWL_DEBUG_CALIB(priv, "silence a %u, b %u, c %u, 20-bcn max %u\n", | ||
224 | silence_rssi_a, silence_rssi_b, silence_rssi_c, | ||
225 | silence_ref); | ||
226 | |||
227 | /* Find max rx energy (min value!) among all 3 receivers, | ||
228 | * measured during beacon frame. | ||
229 | * Save it in 10-beacon history table. */ | ||
230 | i = data->nrg_energy_idx; | ||
231 | val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c); | ||
232 | data->nrg_value[i] = min(rx_info->beacon_energy_a, val); | ||
233 | |||
234 | data->nrg_energy_idx++; | ||
235 | if (data->nrg_energy_idx >= 10) | ||
236 | data->nrg_energy_idx = 0; | ||
237 | |||
238 | /* Find min rx energy (max value) across 10 beacon history. | ||
239 | * This is the minimum signal level that we want to receive well. | ||
240 | * Add backoff (margin so we don't miss slightly lower energy frames). | ||
241 | * This establishes an upper bound (min value) for energy threshold. */ | ||
242 | max_nrg_cck = data->nrg_value[0]; | ||
243 | for (i = 1; i < 10; i++) | ||
244 | max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i])); | ||
245 | max_nrg_cck += 6; | ||
246 | |||
247 | IWL_DEBUG_CALIB(priv, "rx energy a %u, b %u, c %u, 10-bcn max/min %u\n", | ||
248 | rx_info->beacon_energy_a, rx_info->beacon_energy_b, | ||
249 | rx_info->beacon_energy_c, max_nrg_cck - 6); | ||
250 | |||
251 | /* Count number of consecutive beacons with fewer-than-desired | ||
252 | * false alarms. */ | ||
253 | if (false_alarms < min_false_alarms) | ||
254 | data->num_in_cck_no_fa++; | ||
255 | else | ||
256 | data->num_in_cck_no_fa = 0; | ||
257 | IWL_DEBUG_CALIB(priv, "consecutive bcns with few false alarms = %u\n", | ||
258 | data->num_in_cck_no_fa); | ||
259 | |||
260 | /* If we got too many false alarms this time, reduce sensitivity */ | ||
261 | if ((false_alarms > max_false_alarms) && | ||
262 | (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK)) { | ||
263 | IWL_DEBUG_CALIB(priv, "norm FA %u > max FA %u\n", | ||
264 | false_alarms, max_false_alarms); | ||
265 | IWL_DEBUG_CALIB(priv, "... reducing sensitivity\n"); | ||
266 | data->nrg_curr_state = IWL_FA_TOO_MANY; | ||
267 | /* Store for "fewer than desired" on later beacon */ | ||
268 | data->nrg_silence_ref = silence_ref; | ||
269 | |||
270 | /* increase energy threshold (reduce nrg value) | ||
271 | * to decrease sensitivity */ | ||
272 | data->nrg_th_cck = data->nrg_th_cck - NRG_STEP_CCK; | ||
273 | /* Else if we got fewer than desired, increase sensitivity */ | ||
274 | } else if (false_alarms < min_false_alarms) { | ||
275 | data->nrg_curr_state = IWL_FA_TOO_FEW; | ||
276 | |||
277 | /* Compare silence level with silence level for most recent | ||
278 | * healthy number or too many false alarms */ | ||
279 | data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref - | ||
280 | (s32)silence_ref; | ||
281 | |||
282 | IWL_DEBUG_CALIB(priv, "norm FA %u < min FA %u, silence diff %d\n", | ||
283 | false_alarms, min_false_alarms, | ||
284 | data->nrg_auto_corr_silence_diff); | ||
285 | |||
286 | /* Increase value to increase sensitivity, but only if: | ||
287 | * 1a) previous beacon did *not* have *too many* false alarms | ||
288 | * 1b) AND there's a significant difference in Rx levels | ||
289 | * from a previous beacon with too many, or healthy # FAs | ||
290 | * OR 2) We've seen a lot of beacons (100) with too few | ||
291 | * false alarms */ | ||
292 | if ((data->nrg_prev_state != IWL_FA_TOO_MANY) && | ||
293 | ((data->nrg_auto_corr_silence_diff > NRG_DIFF) || | ||
294 | (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) { | ||
295 | |||
296 | IWL_DEBUG_CALIB(priv, "... increasing sensitivity\n"); | ||
297 | /* Increase nrg value to increase sensitivity */ | ||
298 | val = data->nrg_th_cck + NRG_STEP_CCK; | ||
299 | data->nrg_th_cck = min((u32)ranges->min_nrg_cck, val); | ||
300 | } else { | ||
301 | IWL_DEBUG_CALIB(priv, "... but not changing sensitivity\n"); | ||
302 | } | ||
303 | |||
304 | /* Else we got a healthy number of false alarms, keep status quo */ | ||
305 | } else { | ||
306 | IWL_DEBUG_CALIB(priv, " FA in safe zone\n"); | ||
307 | data->nrg_curr_state = IWL_FA_GOOD_RANGE; | ||
308 | |||
309 | /* Store for use in "fewer than desired" with later beacon */ | ||
310 | data->nrg_silence_ref = silence_ref; | ||
311 | |||
312 | /* If previous beacon had too many false alarms, | ||
313 | * give it some extra margin by reducing sensitivity again | ||
314 | * (but don't go below measured energy of desired Rx) */ | ||
315 | if (IWL_FA_TOO_MANY == data->nrg_prev_state) { | ||
316 | IWL_DEBUG_CALIB(priv, "... increasing margin\n"); | ||
317 | if (data->nrg_th_cck > (max_nrg_cck + NRG_MARGIN)) | ||
318 | data->nrg_th_cck -= NRG_MARGIN; | ||
319 | else | ||
320 | data->nrg_th_cck = max_nrg_cck; | ||
321 | } | ||
322 | } | ||
323 | |||
324 | /* Make sure the energy threshold does not go above the measured | ||
325 | * energy of the desired Rx signals (reduced by backoff margin), | ||
326 | * or else we might start missing Rx frames. | ||
327 | * Lower value is higher energy, so we use max()! | ||
328 | */ | ||
329 | data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck); | ||
330 | IWL_DEBUG_CALIB(priv, "new nrg_th_cck %u\n", data->nrg_th_cck); | ||
331 | |||
332 | data->nrg_prev_state = data->nrg_curr_state; | ||
333 | |||
334 | /* Auto-correlation CCK algorithm */ | ||
335 | if (false_alarms > min_false_alarms) { | ||
336 | |||
337 | /* increase auto_corr values to decrease sensitivity | ||
338 | * so the DSP won't be disturbed by the noise | ||
339 | */ | ||
340 | if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK) | ||
341 | data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1; | ||
342 | else { | ||
343 | val = data->auto_corr_cck + AUTO_CORR_STEP_CCK; | ||
344 | data->auto_corr_cck = | ||
345 | min((u32)ranges->auto_corr_max_cck, val); | ||
346 | } | ||
347 | val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK; | ||
348 | data->auto_corr_cck_mrc = | ||
349 | min((u32)ranges->auto_corr_max_cck_mrc, val); | ||
350 | } else if ((false_alarms < min_false_alarms) && | ||
351 | ((data->nrg_auto_corr_silence_diff > NRG_DIFF) || | ||
352 | (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) { | ||
353 | |||
354 | /* Decrease auto_corr values to increase sensitivity */ | ||
355 | val = data->auto_corr_cck - AUTO_CORR_STEP_CCK; | ||
356 | data->auto_corr_cck = | ||
357 | max((u32)ranges->auto_corr_min_cck, val); | ||
358 | val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK; | ||
359 | data->auto_corr_cck_mrc = | ||
360 | max((u32)ranges->auto_corr_min_cck_mrc, val); | ||
361 | } | ||
362 | |||
363 | return 0; | ||
364 | } | ||
365 | |||
366 | |||
367 | static int iwl_sens_auto_corr_ofdm(struct iwl_priv *priv, | ||
368 | u32 norm_fa, | ||
369 | u32 rx_enable_time) | ||
370 | { | ||
371 | u32 val; | ||
372 | u32 false_alarms = norm_fa * 200 * 1024; | ||
373 | u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time; | ||
374 | u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time; | ||
375 | struct iwl_sensitivity_data *data = NULL; | ||
376 | const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens; | ||
377 | |||
378 | data = &(priv->sensitivity_data); | ||
379 | |||
380 | /* If we got too many false alarms this time, reduce sensitivity */ | ||
381 | if (false_alarms > max_false_alarms) { | ||
382 | |||
383 | IWL_DEBUG_CALIB(priv, "norm FA %u > max FA %u)\n", | ||
384 | false_alarms, max_false_alarms); | ||
385 | |||
386 | val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM; | ||
387 | data->auto_corr_ofdm = | ||
388 | min((u32)ranges->auto_corr_max_ofdm, val); | ||
389 | |||
390 | val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM; | ||
391 | data->auto_corr_ofdm_mrc = | ||
392 | min((u32)ranges->auto_corr_max_ofdm_mrc, val); | ||
393 | |||
394 | val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM; | ||
395 | data->auto_corr_ofdm_x1 = | ||
396 | min((u32)ranges->auto_corr_max_ofdm_x1, val); | ||
397 | |||
398 | val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM; | ||
399 | data->auto_corr_ofdm_mrc_x1 = | ||
400 | min((u32)ranges->auto_corr_max_ofdm_mrc_x1, val); | ||
401 | } | ||
402 | |||
403 | /* Else if we got fewer than desired, increase sensitivity */ | ||
404 | else if (false_alarms < min_false_alarms) { | ||
405 | |||
406 | IWL_DEBUG_CALIB(priv, "norm FA %u < min FA %u\n", | ||
407 | false_alarms, min_false_alarms); | ||
408 | |||
409 | val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM; | ||
410 | data->auto_corr_ofdm = | ||
411 | max((u32)ranges->auto_corr_min_ofdm, val); | ||
412 | |||
413 | val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM; | ||
414 | data->auto_corr_ofdm_mrc = | ||
415 | max((u32)ranges->auto_corr_min_ofdm_mrc, val); | ||
416 | |||
417 | val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM; | ||
418 | data->auto_corr_ofdm_x1 = | ||
419 | max((u32)ranges->auto_corr_min_ofdm_x1, val); | ||
420 | |||
421 | val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM; | ||
422 | data->auto_corr_ofdm_mrc_x1 = | ||
423 | max((u32)ranges->auto_corr_min_ofdm_mrc_x1, val); | ||
424 | } else { | ||
425 | IWL_DEBUG_CALIB(priv, "min FA %u < norm FA %u < max FA %u OK\n", | ||
426 | min_false_alarms, false_alarms, max_false_alarms); | ||
427 | } | ||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | static void iwl_prepare_legacy_sensitivity_tbl(struct iwl_priv *priv, | ||
432 | struct iwl_sensitivity_data *data, | ||
433 | __le16 *tbl) | ||
434 | { | ||
435 | tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] = | ||
436 | cpu_to_le16((u16)data->auto_corr_ofdm); | ||
437 | tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] = | ||
438 | cpu_to_le16((u16)data->auto_corr_ofdm_mrc); | ||
439 | tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] = | ||
440 | cpu_to_le16((u16)data->auto_corr_ofdm_x1); | ||
441 | tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] = | ||
442 | cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1); | ||
443 | |||
444 | tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] = | ||
445 | cpu_to_le16((u16)data->auto_corr_cck); | ||
446 | tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] = | ||
447 | cpu_to_le16((u16)data->auto_corr_cck_mrc); | ||
448 | |||
449 | tbl[HD_MIN_ENERGY_CCK_DET_INDEX] = | ||
450 | cpu_to_le16((u16)data->nrg_th_cck); | ||
451 | tbl[HD_MIN_ENERGY_OFDM_DET_INDEX] = | ||
452 | cpu_to_le16((u16)data->nrg_th_ofdm); | ||
453 | |||
454 | tbl[HD_BARKER_CORR_TH_ADD_MIN_INDEX] = | ||
455 | cpu_to_le16(data->barker_corr_th_min); | ||
456 | tbl[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] = | ||
457 | cpu_to_le16(data->barker_corr_th_min_mrc); | ||
458 | tbl[HD_OFDM_ENERGY_TH_IN_INDEX] = | ||
459 | cpu_to_le16(data->nrg_th_cca); | ||
460 | |||
461 | IWL_DEBUG_CALIB(priv, "ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n", | ||
462 | data->auto_corr_ofdm, data->auto_corr_ofdm_mrc, | ||
463 | data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1, | ||
464 | data->nrg_th_ofdm); | ||
465 | |||
466 | IWL_DEBUG_CALIB(priv, "cck: ac %u mrc %u thresh %u\n", | ||
467 | data->auto_corr_cck, data->auto_corr_cck_mrc, | ||
468 | data->nrg_th_cck); | ||
469 | } | ||
470 | |||
471 | /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */ | ||
472 | static int iwl_sensitivity_write(struct iwl_priv *priv) | ||
473 | { | ||
474 | struct iwl_sensitivity_cmd cmd; | ||
475 | struct iwl_sensitivity_data *data = NULL; | ||
476 | struct iwl_host_cmd cmd_out = { | ||
477 | .id = SENSITIVITY_CMD, | ||
478 | .len = { sizeof(struct iwl_sensitivity_cmd), }, | ||
479 | .flags = CMD_ASYNC, | ||
480 | .data = { &cmd, }, | ||
481 | }; | ||
482 | |||
483 | data = &(priv->sensitivity_data); | ||
484 | |||
485 | memset(&cmd, 0, sizeof(cmd)); | ||
486 | |||
487 | iwl_prepare_legacy_sensitivity_tbl(priv, data, &cmd.table[0]); | ||
488 | |||
489 | /* Update uCode's "work" table, and copy it to DSP */ | ||
490 | cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE; | ||
491 | |||
492 | /* Don't send command to uCode if nothing has changed */ | ||
493 | if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]), | ||
494 | sizeof(u16)*HD_TABLE_SIZE)) { | ||
495 | IWL_DEBUG_CALIB(priv, "No change in SENSITIVITY_CMD\n"); | ||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | /* Copy table for comparison next time */ | ||
500 | memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]), | ||
501 | sizeof(u16)*HD_TABLE_SIZE); | ||
502 | |||
503 | return iwl_dvm_send_cmd(priv, &cmd_out); | ||
504 | } | ||
505 | |||
506 | /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */ | ||
507 | static int iwl_enhance_sensitivity_write(struct iwl_priv *priv) | ||
508 | { | ||
509 | struct iwl_enhance_sensitivity_cmd cmd; | ||
510 | struct iwl_sensitivity_data *data = NULL; | ||
511 | struct iwl_host_cmd cmd_out = { | ||
512 | .id = SENSITIVITY_CMD, | ||
513 | .len = { sizeof(struct iwl_enhance_sensitivity_cmd), }, | ||
514 | .flags = CMD_ASYNC, | ||
515 | .data = { &cmd, }, | ||
516 | }; | ||
517 | |||
518 | data = &(priv->sensitivity_data); | ||
519 | |||
520 | memset(&cmd, 0, sizeof(cmd)); | ||
521 | |||
522 | iwl_prepare_legacy_sensitivity_tbl(priv, data, &cmd.enhance_table[0]); | ||
523 | |||
524 | if (priv->cfg->base_params->hd_v2) { | ||
525 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX] = | ||
526 | HD_INA_NON_SQUARE_DET_OFDM_DATA_V2; | ||
527 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_CCK_INDEX] = | ||
528 | HD_INA_NON_SQUARE_DET_CCK_DATA_V2; | ||
529 | cmd.enhance_table[HD_CORR_11_INSTEAD_OF_CORR_9_EN_INDEX] = | ||
530 | HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA_V2; | ||
531 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_INDEX] = | ||
532 | HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA_V2; | ||
533 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = | ||
534 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V2; | ||
535 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_INDEX] = | ||
536 | HD_OFDM_NON_SQUARE_DET_SLOPE_DATA_V2; | ||
537 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_INDEX] = | ||
538 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA_V2; | ||
539 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_MRC_INDEX] = | ||
540 | HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA_V2; | ||
541 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = | ||
542 | HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V2; | ||
543 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_INDEX] = | ||
544 | HD_CCK_NON_SQUARE_DET_SLOPE_DATA_V2; | ||
545 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_INDEX] = | ||
546 | HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA_V2; | ||
547 | } else { | ||
548 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX] = | ||
549 | HD_INA_NON_SQUARE_DET_OFDM_DATA_V1; | ||
550 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_CCK_INDEX] = | ||
551 | HD_INA_NON_SQUARE_DET_CCK_DATA_V1; | ||
552 | cmd.enhance_table[HD_CORR_11_INSTEAD_OF_CORR_9_EN_INDEX] = | ||
553 | HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA_V1; | ||
554 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_INDEX] = | ||
555 | HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA_V1; | ||
556 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = | ||
557 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V1; | ||
558 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_INDEX] = | ||
559 | HD_OFDM_NON_SQUARE_DET_SLOPE_DATA_V1; | ||
560 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_INDEX] = | ||
561 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA_V1; | ||
562 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_MRC_INDEX] = | ||
563 | HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA_V1; | ||
564 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = | ||
565 | HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V1; | ||
566 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_INDEX] = | ||
567 | HD_CCK_NON_SQUARE_DET_SLOPE_DATA_V1; | ||
568 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_INDEX] = | ||
569 | HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA_V1; | ||
570 | } | ||
571 | |||
572 | /* Update uCode's "work" table, and copy it to DSP */ | ||
573 | cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE; | ||
574 | |||
575 | /* Don't send command to uCode if nothing has changed */ | ||
576 | if (!memcmp(&cmd.enhance_table[0], &(priv->sensitivity_tbl[0]), | ||
577 | sizeof(u16)*HD_TABLE_SIZE) && | ||
578 | !memcmp(&cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX], | ||
579 | &(priv->enhance_sensitivity_tbl[0]), | ||
580 | sizeof(u16)*ENHANCE_HD_TABLE_ENTRIES)) { | ||
581 | IWL_DEBUG_CALIB(priv, "No change in SENSITIVITY_CMD\n"); | ||
582 | return 0; | ||
583 | } | ||
584 | |||
585 | /* Copy table for comparison next time */ | ||
586 | memcpy(&(priv->sensitivity_tbl[0]), &(cmd.enhance_table[0]), | ||
587 | sizeof(u16)*HD_TABLE_SIZE); | ||
588 | memcpy(&(priv->enhance_sensitivity_tbl[0]), | ||
589 | &(cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX]), | ||
590 | sizeof(u16)*ENHANCE_HD_TABLE_ENTRIES); | ||
591 | |||
592 | return iwl_dvm_send_cmd(priv, &cmd_out); | ||
593 | } | ||
594 | |||
595 | void iwl_init_sensitivity(struct iwl_priv *priv) | ||
596 | { | ||
597 | int ret = 0; | ||
598 | int i; | ||
599 | struct iwl_sensitivity_data *data = NULL; | ||
600 | const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens; | ||
601 | |||
602 | if (priv->calib_disabled & IWL_SENSITIVITY_CALIB_DISABLED) | ||
603 | return; | ||
604 | |||
605 | IWL_DEBUG_CALIB(priv, "Start iwl_init_sensitivity\n"); | ||
606 | |||
607 | /* Clear driver's sensitivity algo data */ | ||
608 | data = &(priv->sensitivity_data); | ||
609 | |||
610 | if (ranges == NULL) | ||
611 | return; | ||
612 | |||
613 | memset(data, 0, sizeof(struct iwl_sensitivity_data)); | ||
614 | |||
615 | data->num_in_cck_no_fa = 0; | ||
616 | data->nrg_curr_state = IWL_FA_TOO_MANY; | ||
617 | data->nrg_prev_state = IWL_FA_TOO_MANY; | ||
618 | data->nrg_silence_ref = 0; | ||
619 | data->nrg_silence_idx = 0; | ||
620 | data->nrg_energy_idx = 0; | ||
621 | |||
622 | for (i = 0; i < 10; i++) | ||
623 | data->nrg_value[i] = 0; | ||
624 | |||
625 | for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) | ||
626 | data->nrg_silence_rssi[i] = 0; | ||
627 | |||
628 | data->auto_corr_ofdm = ranges->auto_corr_min_ofdm; | ||
629 | data->auto_corr_ofdm_mrc = ranges->auto_corr_min_ofdm_mrc; | ||
630 | data->auto_corr_ofdm_x1 = ranges->auto_corr_min_ofdm_x1; | ||
631 | data->auto_corr_ofdm_mrc_x1 = ranges->auto_corr_min_ofdm_mrc_x1; | ||
632 | data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF; | ||
633 | data->auto_corr_cck_mrc = ranges->auto_corr_min_cck_mrc; | ||
634 | data->nrg_th_cck = ranges->nrg_th_cck; | ||
635 | data->nrg_th_ofdm = ranges->nrg_th_ofdm; | ||
636 | data->barker_corr_th_min = ranges->barker_corr_th_min; | ||
637 | data->barker_corr_th_min_mrc = ranges->barker_corr_th_min_mrc; | ||
638 | data->nrg_th_cca = ranges->nrg_th_cca; | ||
639 | |||
640 | data->last_bad_plcp_cnt_ofdm = 0; | ||
641 | data->last_fa_cnt_ofdm = 0; | ||
642 | data->last_bad_plcp_cnt_cck = 0; | ||
643 | data->last_fa_cnt_cck = 0; | ||
644 | |||
645 | if (priv->fw->enhance_sensitivity_table) | ||
646 | ret |= iwl_enhance_sensitivity_write(priv); | ||
647 | else | ||
648 | ret |= iwl_sensitivity_write(priv); | ||
649 | IWL_DEBUG_CALIB(priv, "<<return 0x%X\n", ret); | ||
650 | } | ||
651 | |||
652 | void iwl_sensitivity_calibration(struct iwl_priv *priv) | ||
653 | { | ||
654 | u32 rx_enable_time; | ||
655 | u32 fa_cck; | ||
656 | u32 fa_ofdm; | ||
657 | u32 bad_plcp_cck; | ||
658 | u32 bad_plcp_ofdm; | ||
659 | u32 norm_fa_ofdm; | ||
660 | u32 norm_fa_cck; | ||
661 | struct iwl_sensitivity_data *data = NULL; | ||
662 | struct statistics_rx_non_phy *rx_info; | ||
663 | struct statistics_rx_phy *ofdm, *cck; | ||
664 | struct statistics_general_data statis; | ||
665 | |||
666 | if (priv->calib_disabled & IWL_SENSITIVITY_CALIB_DISABLED) | ||
667 | return; | ||
668 | |||
669 | data = &(priv->sensitivity_data); | ||
670 | |||
671 | if (!iwl_is_any_associated(priv)) { | ||
672 | IWL_DEBUG_CALIB(priv, "<< - not associated\n"); | ||
673 | return; | ||
674 | } | ||
675 | |||
676 | spin_lock_bh(&priv->statistics.lock); | ||
677 | rx_info = &priv->statistics.rx_non_phy; | ||
678 | ofdm = &priv->statistics.rx_ofdm; | ||
679 | cck = &priv->statistics.rx_cck; | ||
680 | if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { | ||
681 | IWL_DEBUG_CALIB(priv, "<< invalid data.\n"); | ||
682 | spin_unlock_bh(&priv->statistics.lock); | ||
683 | return; | ||
684 | } | ||
685 | |||
686 | /* Extract Statistics: */ | ||
687 | rx_enable_time = le32_to_cpu(rx_info->channel_load); | ||
688 | fa_cck = le32_to_cpu(cck->false_alarm_cnt); | ||
689 | fa_ofdm = le32_to_cpu(ofdm->false_alarm_cnt); | ||
690 | bad_plcp_cck = le32_to_cpu(cck->plcp_err); | ||
691 | bad_plcp_ofdm = le32_to_cpu(ofdm->plcp_err); | ||
692 | |||
693 | statis.beacon_silence_rssi_a = | ||
694 | le32_to_cpu(rx_info->beacon_silence_rssi_a); | ||
695 | statis.beacon_silence_rssi_b = | ||
696 | le32_to_cpu(rx_info->beacon_silence_rssi_b); | ||
697 | statis.beacon_silence_rssi_c = | ||
698 | le32_to_cpu(rx_info->beacon_silence_rssi_c); | ||
699 | statis.beacon_energy_a = | ||
700 | le32_to_cpu(rx_info->beacon_energy_a); | ||
701 | statis.beacon_energy_b = | ||
702 | le32_to_cpu(rx_info->beacon_energy_b); | ||
703 | statis.beacon_energy_c = | ||
704 | le32_to_cpu(rx_info->beacon_energy_c); | ||
705 | |||
706 | spin_unlock_bh(&priv->statistics.lock); | ||
707 | |||
708 | IWL_DEBUG_CALIB(priv, "rx_enable_time = %u usecs\n", rx_enable_time); | ||
709 | |||
710 | if (!rx_enable_time) { | ||
711 | IWL_DEBUG_CALIB(priv, "<< RX Enable Time == 0!\n"); | ||
712 | return; | ||
713 | } | ||
714 | |||
715 | /* These statistics increase monotonically, and do not reset | ||
716 | * at each beacon. Calculate difference from last value, or just | ||
717 | * use the new statistics value if it has reset or wrapped around. */ | ||
718 | if (data->last_bad_plcp_cnt_cck > bad_plcp_cck) | ||
719 | data->last_bad_plcp_cnt_cck = bad_plcp_cck; | ||
720 | else { | ||
721 | bad_plcp_cck -= data->last_bad_plcp_cnt_cck; | ||
722 | data->last_bad_plcp_cnt_cck += bad_plcp_cck; | ||
723 | } | ||
724 | |||
725 | if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm) | ||
726 | data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm; | ||
727 | else { | ||
728 | bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm; | ||
729 | data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm; | ||
730 | } | ||
731 | |||
732 | if (data->last_fa_cnt_ofdm > fa_ofdm) | ||
733 | data->last_fa_cnt_ofdm = fa_ofdm; | ||
734 | else { | ||
735 | fa_ofdm -= data->last_fa_cnt_ofdm; | ||
736 | data->last_fa_cnt_ofdm += fa_ofdm; | ||
737 | } | ||
738 | |||
739 | if (data->last_fa_cnt_cck > fa_cck) | ||
740 | data->last_fa_cnt_cck = fa_cck; | ||
741 | else { | ||
742 | fa_cck -= data->last_fa_cnt_cck; | ||
743 | data->last_fa_cnt_cck += fa_cck; | ||
744 | } | ||
745 | |||
746 | /* Total aborted signal locks */ | ||
747 | norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm; | ||
748 | norm_fa_cck = fa_cck + bad_plcp_cck; | ||
749 | |||
750 | IWL_DEBUG_CALIB(priv, "cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck, | ||
751 | bad_plcp_cck, fa_ofdm, bad_plcp_ofdm); | ||
752 | |||
753 | iwl_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time); | ||
754 | iwl_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis); | ||
755 | if (priv->fw->enhance_sensitivity_table) | ||
756 | iwl_enhance_sensitivity_write(priv); | ||
757 | else | ||
758 | iwl_sensitivity_write(priv); | ||
759 | } | ||
760 | |||
761 | static inline u8 find_first_chain(u8 mask) | ||
762 | { | ||
763 | if (mask & ANT_A) | ||
764 | return CHAIN_A; | ||
765 | if (mask & ANT_B) | ||
766 | return CHAIN_B; | ||
767 | return CHAIN_C; | ||
768 | } | ||
769 | |||
770 | /** | ||
771 | * Run disconnected antenna algorithm to find out which antennas are | ||
772 | * disconnected. | ||
773 | */ | ||
774 | static void iwl_find_disconn_antenna(struct iwl_priv *priv, u32* average_sig, | ||
775 | struct iwl_chain_noise_data *data) | ||
776 | { | ||
777 | u32 active_chains = 0; | ||
778 | u32 max_average_sig; | ||
779 | u16 max_average_sig_antenna_i; | ||
780 | u8 num_tx_chains; | ||
781 | u8 first_chain; | ||
782 | u16 i = 0; | ||
783 | |||
784 | average_sig[0] = data->chain_signal_a / IWL_CAL_NUM_BEACONS; | ||
785 | average_sig[1] = data->chain_signal_b / IWL_CAL_NUM_BEACONS; | ||
786 | average_sig[2] = data->chain_signal_c / IWL_CAL_NUM_BEACONS; | ||
787 | |||
788 | if (average_sig[0] >= average_sig[1]) { | ||
789 | max_average_sig = average_sig[0]; | ||
790 | max_average_sig_antenna_i = 0; | ||
791 | active_chains = (1 << max_average_sig_antenna_i); | ||
792 | } else { | ||
793 | max_average_sig = average_sig[1]; | ||
794 | max_average_sig_antenna_i = 1; | ||
795 | active_chains = (1 << max_average_sig_antenna_i); | ||
796 | } | ||
797 | |||
798 | if (average_sig[2] >= max_average_sig) { | ||
799 | max_average_sig = average_sig[2]; | ||
800 | max_average_sig_antenna_i = 2; | ||
801 | active_chains = (1 << max_average_sig_antenna_i); | ||
802 | } | ||
803 | |||
804 | IWL_DEBUG_CALIB(priv, "average_sig: a %d b %d c %d\n", | ||
805 | average_sig[0], average_sig[1], average_sig[2]); | ||
806 | IWL_DEBUG_CALIB(priv, "max_average_sig = %d, antenna %d\n", | ||
807 | max_average_sig, max_average_sig_antenna_i); | ||
808 | |||
809 | /* Compare signal strengths for all 3 receivers. */ | ||
810 | for (i = 0; i < NUM_RX_CHAINS; i++) { | ||
811 | if (i != max_average_sig_antenna_i) { | ||
812 | s32 rssi_delta = (max_average_sig - average_sig[i]); | ||
813 | |||
814 | /* If signal is very weak, compared with | ||
815 | * strongest, mark it as disconnected. */ | ||
816 | if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS) | ||
817 | data->disconn_array[i] = 1; | ||
818 | else | ||
819 | active_chains |= (1 << i); | ||
820 | IWL_DEBUG_CALIB(priv, "i = %d rssiDelta = %d " | ||
821 | "disconn_array[i] = %d\n", | ||
822 | i, rssi_delta, data->disconn_array[i]); | ||
823 | } | ||
824 | } | ||
825 | |||
826 | /* | ||
827 | * The above algorithm sometimes fails when the ucode | ||
828 | * reports 0 for all chains. It's not clear why that | ||
829 | * happens to start with, but it is then causing trouble | ||
830 | * because this can make us enable more chains than the | ||
831 | * hardware really has. | ||
832 | * | ||
833 | * To be safe, simply mask out any chains that we know | ||
834 | * are not on the device. | ||
835 | */ | ||
836 | active_chains &= priv->eeprom_data->valid_rx_ant; | ||
837 | |||
838 | num_tx_chains = 0; | ||
839 | for (i = 0; i < NUM_RX_CHAINS; i++) { | ||
840 | /* loops on all the bits of | ||
841 | * priv->hw_setting.valid_tx_ant */ | ||
842 | u8 ant_msk = (1 << i); | ||
843 | if (!(priv->eeprom_data->valid_tx_ant & ant_msk)) | ||
844 | continue; | ||
845 | |||
846 | num_tx_chains++; | ||
847 | if (data->disconn_array[i] == 0) | ||
848 | /* there is a Tx antenna connected */ | ||
849 | break; | ||
850 | if (num_tx_chains == priv->hw_params.tx_chains_num && | ||
851 | data->disconn_array[i]) { | ||
852 | /* | ||
853 | * If all chains are disconnected | ||
854 | * connect the first valid tx chain | ||
855 | */ | ||
856 | first_chain = | ||
857 | find_first_chain(priv->eeprom_data->valid_tx_ant); | ||
858 | data->disconn_array[first_chain] = 0; | ||
859 | active_chains |= BIT(first_chain); | ||
860 | IWL_DEBUG_CALIB(priv, | ||
861 | "All Tx chains are disconnected W/A - declare %d as connected\n", | ||
862 | first_chain); | ||
863 | break; | ||
864 | } | ||
865 | } | ||
866 | |||
867 | if (active_chains != priv->eeprom_data->valid_rx_ant && | ||
868 | active_chains != priv->chain_noise_data.active_chains) | ||
869 | IWL_DEBUG_CALIB(priv, | ||
870 | "Detected that not all antennas are connected! " | ||
871 | "Connected: %#x, valid: %#x.\n", | ||
872 | active_chains, | ||
873 | priv->eeprom_data->valid_rx_ant); | ||
874 | |||
875 | /* Save for use within RXON, TX, SCAN commands, etc. */ | ||
876 | data->active_chains = active_chains; | ||
877 | IWL_DEBUG_CALIB(priv, "active_chains (bitwise) = 0x%x\n", | ||
878 | active_chains); | ||
879 | } | ||
880 | |||
881 | static void iwlagn_gain_computation(struct iwl_priv *priv, | ||
882 | u32 average_noise[NUM_RX_CHAINS], | ||
883 | u8 default_chain) | ||
884 | { | ||
885 | int i; | ||
886 | s32 delta_g; | ||
887 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; | ||
888 | |||
889 | /* | ||
890 | * Find Gain Code for the chains based on "default chain" | ||
891 | */ | ||
892 | for (i = default_chain + 1; i < NUM_RX_CHAINS; i++) { | ||
893 | if ((data->disconn_array[i])) { | ||
894 | data->delta_gain_code[i] = 0; | ||
895 | continue; | ||
896 | } | ||
897 | |||
898 | delta_g = (priv->cfg->base_params->chain_noise_scale * | ||
899 | ((s32)average_noise[default_chain] - | ||
900 | (s32)average_noise[i])) / 1500; | ||
901 | |||
902 | /* bound gain by 2 bits value max, 3rd bit is sign */ | ||
903 | data->delta_gain_code[i] = | ||
904 | min(abs(delta_g), | ||
905 | (long) CHAIN_NOISE_MAX_DELTA_GAIN_CODE); | ||
906 | |||
907 | if (delta_g < 0) | ||
908 | /* | ||
909 | * set negative sign ... | ||
910 | * note to Intel developers: This is uCode API format, | ||
911 | * not the format of any internal device registers. | ||
912 | * Do not change this format for e.g. 6050 or similar | ||
913 | * devices. Change format only if more resolution | ||
914 | * (i.e. more than 2 bits magnitude) is needed. | ||
915 | */ | ||
916 | data->delta_gain_code[i] |= (1 << 2); | ||
917 | } | ||
918 | |||
919 | IWL_DEBUG_CALIB(priv, "Delta gains: ANT_B = %d ANT_C = %d\n", | ||
920 | data->delta_gain_code[1], data->delta_gain_code[2]); | ||
921 | |||
922 | if (!data->radio_write) { | ||
923 | struct iwl_calib_chain_noise_gain_cmd cmd; | ||
924 | |||
925 | memset(&cmd, 0, sizeof(cmd)); | ||
926 | |||
927 | iwl_set_calib_hdr(&cmd.hdr, | ||
928 | priv->phy_calib_chain_noise_gain_cmd); | ||
929 | cmd.delta_gain_1 = data->delta_gain_code[1]; | ||
930 | cmd.delta_gain_2 = data->delta_gain_code[2]; | ||
931 | iwl_dvm_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, | ||
932 | CMD_ASYNC, sizeof(cmd), &cmd); | ||
933 | |||
934 | data->radio_write = 1; | ||
935 | data->state = IWL_CHAIN_NOISE_CALIBRATED; | ||
936 | } | ||
937 | } | ||
938 | |||
939 | /* | ||
940 | * Accumulate 16 beacons of signal and noise statistics for each of | ||
941 | * 3 receivers/antennas/rx-chains, then figure out: | ||
942 | * 1) Which antennas are connected. | ||
943 | * 2) Differential rx gain settings to balance the 3 receivers. | ||
944 | */ | ||
945 | void iwl_chain_noise_calibration(struct iwl_priv *priv) | ||
946 | { | ||
947 | struct iwl_chain_noise_data *data = NULL; | ||
948 | |||
949 | u32 chain_noise_a; | ||
950 | u32 chain_noise_b; | ||
951 | u32 chain_noise_c; | ||
952 | u32 chain_sig_a; | ||
953 | u32 chain_sig_b; | ||
954 | u32 chain_sig_c; | ||
955 | u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE}; | ||
956 | u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE}; | ||
957 | u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE; | ||
958 | u16 min_average_noise_antenna_i = INITIALIZATION_VALUE; | ||
959 | u16 i = 0; | ||
960 | u16 rxon_chnum = INITIALIZATION_VALUE; | ||
961 | u16 stat_chnum = INITIALIZATION_VALUE; | ||
962 | u8 rxon_band24; | ||
963 | u8 stat_band24; | ||
964 | struct statistics_rx_non_phy *rx_info; | ||
965 | |||
966 | /* | ||
967 | * MULTI-FIXME: | ||
968 | * When we support multiple interfaces on different channels, | ||
969 | * this must be modified/fixed. | ||
970 | */ | ||
971 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
972 | |||
973 | if (priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED) | ||
974 | return; | ||
975 | |||
976 | data = &(priv->chain_noise_data); | ||
977 | |||
978 | /* | ||
979 | * Accumulate just the first "chain_noise_num_beacons" after | ||
980 | * the first association, then we're done forever. | ||
981 | */ | ||
982 | if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) { | ||
983 | if (data->state == IWL_CHAIN_NOISE_ALIVE) | ||
984 | IWL_DEBUG_CALIB(priv, "Wait for noise calib reset\n"); | ||
985 | return; | ||
986 | } | ||
987 | |||
988 | spin_lock_bh(&priv->statistics.lock); | ||
989 | |||
990 | rx_info = &priv->statistics.rx_non_phy; | ||
991 | |||
992 | if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { | ||
993 | IWL_DEBUG_CALIB(priv, " << Interference data unavailable\n"); | ||
994 | spin_unlock_bh(&priv->statistics.lock); | ||
995 | return; | ||
996 | } | ||
997 | |||
998 | rxon_band24 = !!(ctx->staging.flags & RXON_FLG_BAND_24G_MSK); | ||
999 | rxon_chnum = le16_to_cpu(ctx->staging.channel); | ||
1000 | stat_band24 = | ||
1001 | !!(priv->statistics.flag & STATISTICS_REPLY_FLG_BAND_24G_MSK); | ||
1002 | stat_chnum = le32_to_cpu(priv->statistics.flag) >> 16; | ||
1003 | |||
1004 | /* Make sure we accumulate data for just the associated channel | ||
1005 | * (even if scanning). */ | ||
1006 | if ((rxon_chnum != stat_chnum) || (rxon_band24 != stat_band24)) { | ||
1007 | IWL_DEBUG_CALIB(priv, "Stats not from chan=%d, band24=%d\n", | ||
1008 | rxon_chnum, rxon_band24); | ||
1009 | spin_unlock_bh(&priv->statistics.lock); | ||
1010 | return; | ||
1011 | } | ||
1012 | |||
1013 | /* | ||
1014 | * Accumulate beacon statistics values across | ||
1015 | * "chain_noise_num_beacons" | ||
1016 | */ | ||
1017 | chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) & | ||
1018 | IN_BAND_FILTER; | ||
1019 | chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) & | ||
1020 | IN_BAND_FILTER; | ||
1021 | chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) & | ||
1022 | IN_BAND_FILTER; | ||
1023 | |||
1024 | chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER; | ||
1025 | chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER; | ||
1026 | chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER; | ||
1027 | |||
1028 | spin_unlock_bh(&priv->statistics.lock); | ||
1029 | |||
1030 | data->beacon_count++; | ||
1031 | |||
1032 | data->chain_noise_a = (chain_noise_a + data->chain_noise_a); | ||
1033 | data->chain_noise_b = (chain_noise_b + data->chain_noise_b); | ||
1034 | data->chain_noise_c = (chain_noise_c + data->chain_noise_c); | ||
1035 | |||
1036 | data->chain_signal_a = (chain_sig_a + data->chain_signal_a); | ||
1037 | data->chain_signal_b = (chain_sig_b + data->chain_signal_b); | ||
1038 | data->chain_signal_c = (chain_sig_c + data->chain_signal_c); | ||
1039 | |||
1040 | IWL_DEBUG_CALIB(priv, "chan=%d, band24=%d, beacon=%d\n", | ||
1041 | rxon_chnum, rxon_band24, data->beacon_count); | ||
1042 | IWL_DEBUG_CALIB(priv, "chain_sig: a %d b %d c %d\n", | ||
1043 | chain_sig_a, chain_sig_b, chain_sig_c); | ||
1044 | IWL_DEBUG_CALIB(priv, "chain_noise: a %d b %d c %d\n", | ||
1045 | chain_noise_a, chain_noise_b, chain_noise_c); | ||
1046 | |||
1047 | /* If this is the "chain_noise_num_beacons", determine: | ||
1048 | * 1) Disconnected antennas (using signal strengths) | ||
1049 | * 2) Differential gain (using silence noise) to balance receivers */ | ||
1050 | if (data->beacon_count != IWL_CAL_NUM_BEACONS) | ||
1051 | return; | ||
1052 | |||
1053 | /* Analyze signal for disconnected antenna */ | ||
1054 | if (priv->cfg->bt_params && | ||
1055 | priv->cfg->bt_params->advanced_bt_coexist) { | ||
1056 | /* Disable disconnected antenna algorithm for advanced | ||
1057 | bt coex, assuming valid antennas are connected */ | ||
1058 | data->active_chains = priv->eeprom_data->valid_rx_ant; | ||
1059 | for (i = 0; i < NUM_RX_CHAINS; i++) | ||
1060 | if (!(data->active_chains & (1<<i))) | ||
1061 | data->disconn_array[i] = 1; | ||
1062 | } else | ||
1063 | iwl_find_disconn_antenna(priv, average_sig, data); | ||
1064 | |||
1065 | /* Analyze noise for rx balance */ | ||
1066 | average_noise[0] = data->chain_noise_a / IWL_CAL_NUM_BEACONS; | ||
1067 | average_noise[1] = data->chain_noise_b / IWL_CAL_NUM_BEACONS; | ||
1068 | average_noise[2] = data->chain_noise_c / IWL_CAL_NUM_BEACONS; | ||
1069 | |||
1070 | for (i = 0; i < NUM_RX_CHAINS; i++) { | ||
1071 | if (!(data->disconn_array[i]) && | ||
1072 | (average_noise[i] <= min_average_noise)) { | ||
1073 | /* This means that chain i is active and has | ||
1074 | * lower noise values so far: */ | ||
1075 | min_average_noise = average_noise[i]; | ||
1076 | min_average_noise_antenna_i = i; | ||
1077 | } | ||
1078 | } | ||
1079 | |||
1080 | IWL_DEBUG_CALIB(priv, "average_noise: a %d b %d c %d\n", | ||
1081 | average_noise[0], average_noise[1], | ||
1082 | average_noise[2]); | ||
1083 | |||
1084 | IWL_DEBUG_CALIB(priv, "min_average_noise = %d, antenna %d\n", | ||
1085 | min_average_noise, min_average_noise_antenna_i); | ||
1086 | |||
1087 | iwlagn_gain_computation( | ||
1088 | priv, average_noise, | ||
1089 | find_first_chain(priv->eeprom_data->valid_rx_ant)); | ||
1090 | |||
1091 | /* Some power changes may have been made during the calibration. | ||
1092 | * Update and commit the RXON | ||
1093 | */ | ||
1094 | iwl_update_chain_flags(priv); | ||
1095 | |||
1096 | data->state = IWL_CHAIN_NOISE_DONE; | ||
1097 | iwl_power_update_mode(priv, false); | ||
1098 | } | ||
1099 | |||
1100 | void iwl_reset_run_time_calib(struct iwl_priv *priv) | ||
1101 | { | ||
1102 | int i; | ||
1103 | memset(&(priv->sensitivity_data), 0, | ||
1104 | sizeof(struct iwl_sensitivity_data)); | ||
1105 | memset(&(priv->chain_noise_data), 0, | ||
1106 | sizeof(struct iwl_chain_noise_data)); | ||
1107 | for (i = 0; i < NUM_RX_CHAINS; i++) | ||
1108 | priv->chain_noise_data.delta_gain_code[i] = | ||
1109 | CHAIN_NOISE_DELTA_GAIN_INIT_VAL; | ||
1110 | |||
1111 | /* Ask for statistics now, the uCode will send notification | ||
1112 | * periodically after association */ | ||
1113 | iwl_send_statistics_request(priv, CMD_ASYNC, true); | ||
1114 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/calib.h b/drivers/net/wireless/iwlwifi/dvm/calib.h new file mode 100644 index 000000000000..2349f393cc42 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/calib.h | |||
@@ -0,0 +1,74 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
4 | * redistributing this file, you may do so under either license. | ||
5 | * | ||
6 | * GPL LICENSE SUMMARY | ||
7 | * | ||
8 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of version 2 of the GNU General Public License as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
22 | * USA | ||
23 | * | ||
24 | * The full GNU General Public License is included in this distribution | ||
25 | * in the file called LICENSE.GPL. | ||
26 | * | ||
27 | * Contact Information: | ||
28 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
30 | * | ||
31 | * BSD LICENSE | ||
32 | * | ||
33 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. | ||
34 | * All rights reserved. | ||
35 | * | ||
36 | * Redistribution and use in source and binary forms, with or without | ||
37 | * modification, are permitted provided that the following conditions | ||
38 | * are met: | ||
39 | * | ||
40 | * * Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * * Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in | ||
44 | * the documentation and/or other materials provided with the | ||
45 | * distribution. | ||
46 | * * Neither the name Intel Corporation nor the names of its | ||
47 | * contributors may be used to endorse or promote products derived | ||
48 | * from this software without specific prior written permission. | ||
49 | * | ||
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
61 | *****************************************************************************/ | ||
62 | #ifndef __iwl_calib_h__ | ||
63 | #define __iwl_calib_h__ | ||
64 | |||
65 | #include "dev.h" | ||
66 | #include "commands.h" | ||
67 | |||
68 | void iwl_chain_noise_calibration(struct iwl_priv *priv); | ||
69 | void iwl_sensitivity_calibration(struct iwl_priv *priv); | ||
70 | |||
71 | void iwl_init_sensitivity(struct iwl_priv *priv); | ||
72 | void iwl_reset_run_time_calib(struct iwl_priv *priv); | ||
73 | |||
74 | #endif /* __iwl_calib_h__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/commands.h b/drivers/net/wireless/iwlwifi/dvm/commands.h new file mode 100644 index 000000000000..64811cd91635 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/commands.h | |||
@@ -0,0 +1,3958 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
4 | * redistributing this file, you may do so under either license. | ||
5 | * | ||
6 | * GPL LICENSE SUMMARY | ||
7 | * | ||
8 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of version 2 of the GNU General Public License as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
22 | * USA | ||
23 | * | ||
24 | * The full GNU General Public License is included in this distribution | ||
25 | * in the file called LICENSE.GPL. | ||
26 | * | ||
27 | * Contact Information: | ||
28 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
30 | * | ||
31 | * BSD LICENSE | ||
32 | * | ||
33 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. | ||
34 | * All rights reserved. | ||
35 | * | ||
36 | * Redistribution and use in source and binary forms, with or without | ||
37 | * modification, are permitted provided that the following conditions | ||
38 | * are met: | ||
39 | * | ||
40 | * * Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * * Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in | ||
44 | * the documentation and/or other materials provided with the | ||
45 | * distribution. | ||
46 | * * Neither the name Intel Corporation nor the names of its | ||
47 | * contributors may be used to endorse or promote products derived | ||
48 | * from this software without specific prior written permission. | ||
49 | * | ||
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
61 | * | ||
62 | *****************************************************************************/ | ||
63 | /* | ||
64 | * Please use this file (commands.h) only for uCode API definitions. | ||
65 | * Please use iwl-xxxx-hw.h for hardware-related definitions. | ||
66 | * Please use dev.h for driver implementation definitions. | ||
67 | */ | ||
68 | |||
69 | #ifndef __iwl_commands_h__ | ||
70 | #define __iwl_commands_h__ | ||
71 | |||
72 | #include <linux/ieee80211.h> | ||
73 | #include <linux/types.h> | ||
74 | |||
75 | |||
76 | enum { | ||
77 | REPLY_ALIVE = 0x1, | ||
78 | REPLY_ERROR = 0x2, | ||
79 | REPLY_ECHO = 0x3, /* test command */ | ||
80 | |||
81 | /* RXON and QOS commands */ | ||
82 | REPLY_RXON = 0x10, | ||
83 | REPLY_RXON_ASSOC = 0x11, | ||
84 | REPLY_QOS_PARAM = 0x13, | ||
85 | REPLY_RXON_TIMING = 0x14, | ||
86 | |||
87 | /* Multi-Station support */ | ||
88 | REPLY_ADD_STA = 0x18, | ||
89 | REPLY_REMOVE_STA = 0x19, | ||
90 | REPLY_REMOVE_ALL_STA = 0x1a, /* not used */ | ||
91 | REPLY_TXFIFO_FLUSH = 0x1e, | ||
92 | |||
93 | /* Security */ | ||
94 | REPLY_WEPKEY = 0x20, | ||
95 | |||
96 | /* RX, TX, LEDs */ | ||
97 | REPLY_TX = 0x1c, | ||
98 | REPLY_LEDS_CMD = 0x48, | ||
99 | REPLY_TX_LINK_QUALITY_CMD = 0x4e, | ||
100 | |||
101 | /* WiMAX coexistence */ | ||
102 | COEX_PRIORITY_TABLE_CMD = 0x5a, | ||
103 | COEX_MEDIUM_NOTIFICATION = 0x5b, | ||
104 | COEX_EVENT_CMD = 0x5c, | ||
105 | |||
106 | /* Calibration */ | ||
107 | TEMPERATURE_NOTIFICATION = 0x62, | ||
108 | CALIBRATION_CFG_CMD = 0x65, | ||
109 | CALIBRATION_RES_NOTIFICATION = 0x66, | ||
110 | CALIBRATION_COMPLETE_NOTIFICATION = 0x67, | ||
111 | |||
112 | /* 802.11h related */ | ||
113 | REPLY_QUIET_CMD = 0x71, /* not used */ | ||
114 | REPLY_CHANNEL_SWITCH = 0x72, | ||
115 | CHANNEL_SWITCH_NOTIFICATION = 0x73, | ||
116 | REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74, | ||
117 | SPECTRUM_MEASURE_NOTIFICATION = 0x75, | ||
118 | |||
119 | /* Power Management */ | ||
120 | POWER_TABLE_CMD = 0x77, | ||
121 | PM_SLEEP_NOTIFICATION = 0x7A, | ||
122 | PM_DEBUG_STATISTIC_NOTIFIC = 0x7B, | ||
123 | |||
124 | /* Scan commands and notifications */ | ||
125 | REPLY_SCAN_CMD = 0x80, | ||
126 | REPLY_SCAN_ABORT_CMD = 0x81, | ||
127 | SCAN_START_NOTIFICATION = 0x82, | ||
128 | SCAN_RESULTS_NOTIFICATION = 0x83, | ||
129 | SCAN_COMPLETE_NOTIFICATION = 0x84, | ||
130 | |||
131 | /* IBSS/AP commands */ | ||
132 | BEACON_NOTIFICATION = 0x90, | ||
133 | REPLY_TX_BEACON = 0x91, | ||
134 | WHO_IS_AWAKE_NOTIFICATION = 0x94, /* not used */ | ||
135 | |||
136 | /* Miscellaneous commands */ | ||
137 | REPLY_TX_POWER_DBM_CMD = 0x95, | ||
138 | QUIET_NOTIFICATION = 0x96, /* not used */ | ||
139 | REPLY_TX_PWR_TABLE_CMD = 0x97, | ||
140 | REPLY_TX_POWER_DBM_CMD_V1 = 0x98, /* old version of API */ | ||
141 | TX_ANT_CONFIGURATION_CMD = 0x98, | ||
142 | MEASURE_ABORT_NOTIFICATION = 0x99, /* not used */ | ||
143 | |||
144 | /* Bluetooth device coexistence config command */ | ||
145 | REPLY_BT_CONFIG = 0x9b, | ||
146 | |||
147 | /* Statistics */ | ||
148 | REPLY_STATISTICS_CMD = 0x9c, | ||
149 | STATISTICS_NOTIFICATION = 0x9d, | ||
150 | |||
151 | /* RF-KILL commands and notifications */ | ||
152 | REPLY_CARD_STATE_CMD = 0xa0, | ||
153 | CARD_STATE_NOTIFICATION = 0xa1, | ||
154 | |||
155 | /* Missed beacons notification */ | ||
156 | MISSED_BEACONS_NOTIFICATION = 0xa2, | ||
157 | |||
158 | REPLY_CT_KILL_CONFIG_CMD = 0xa4, | ||
159 | SENSITIVITY_CMD = 0xa8, | ||
160 | REPLY_PHY_CALIBRATION_CMD = 0xb0, | ||
161 | REPLY_RX_PHY_CMD = 0xc0, | ||
162 | REPLY_RX_MPDU_CMD = 0xc1, | ||
163 | REPLY_RX = 0xc3, | ||
164 | REPLY_COMPRESSED_BA = 0xc5, | ||
165 | |||
166 | /* BT Coex */ | ||
167 | REPLY_BT_COEX_PRIO_TABLE = 0xcc, | ||
168 | REPLY_BT_COEX_PROT_ENV = 0xcd, | ||
169 | REPLY_BT_COEX_PROFILE_NOTIF = 0xce, | ||
170 | |||
171 | /* PAN commands */ | ||
172 | REPLY_WIPAN_PARAMS = 0xb2, | ||
173 | REPLY_WIPAN_RXON = 0xb3, /* use REPLY_RXON structure */ | ||
174 | REPLY_WIPAN_RXON_TIMING = 0xb4, /* use REPLY_RXON_TIMING structure */ | ||
175 | REPLY_WIPAN_RXON_ASSOC = 0xb6, /* use REPLY_RXON_ASSOC structure */ | ||
176 | REPLY_WIPAN_QOS_PARAM = 0xb7, /* use REPLY_QOS_PARAM structure */ | ||
177 | REPLY_WIPAN_WEPKEY = 0xb8, /* use REPLY_WEPKEY structure */ | ||
178 | REPLY_WIPAN_P2P_CHANNEL_SWITCH = 0xb9, | ||
179 | REPLY_WIPAN_NOA_NOTIFICATION = 0xbc, | ||
180 | REPLY_WIPAN_DEACTIVATION_COMPLETE = 0xbd, | ||
181 | |||
182 | REPLY_WOWLAN_PATTERNS = 0xe0, | ||
183 | REPLY_WOWLAN_WAKEUP_FILTER = 0xe1, | ||
184 | REPLY_WOWLAN_TSC_RSC_PARAMS = 0xe2, | ||
185 | REPLY_WOWLAN_TKIP_PARAMS = 0xe3, | ||
186 | REPLY_WOWLAN_KEK_KCK_MATERIAL = 0xe4, | ||
187 | REPLY_WOWLAN_GET_STATUS = 0xe5, | ||
188 | REPLY_D3_CONFIG = 0xd3, | ||
189 | |||
190 | REPLY_MAX = 0xff | ||
191 | }; | ||
192 | |||
193 | /****************************************************************************** | ||
194 | * (0) | ||
195 | * Commonly used structures and definitions: | ||
196 | * Command header, rate_n_flags, txpower | ||
197 | * | ||
198 | *****************************************************************************/ | ||
199 | |||
200 | /** | ||
201 | * iwlagn rate_n_flags bit fields | ||
202 | * | ||
203 | * rate_n_flags format is used in following iwlagn commands: | ||
204 | * REPLY_RX (response only) | ||
205 | * REPLY_RX_MPDU (response only) | ||
206 | * REPLY_TX (both command and response) | ||
207 | * REPLY_TX_LINK_QUALITY_CMD | ||
208 | * | ||
209 | * High-throughput (HT) rate format for bits 7:0 (bit 8 must be "1"): | ||
210 | * 2-0: 0) 6 Mbps | ||
211 | * 1) 12 Mbps | ||
212 | * 2) 18 Mbps | ||
213 | * 3) 24 Mbps | ||
214 | * 4) 36 Mbps | ||
215 | * 5) 48 Mbps | ||
216 | * 6) 54 Mbps | ||
217 | * 7) 60 Mbps | ||
218 | * | ||
219 | * 4-3: 0) Single stream (SISO) | ||
220 | * 1) Dual stream (MIMO) | ||
221 | * 2) Triple stream (MIMO) | ||
222 | * | ||
223 | * 5: Value of 0x20 in bits 7:0 indicates 6 Mbps HT40 duplicate data | ||
224 | * | ||
225 | * Legacy OFDM rate format for bits 7:0 (bit 8 must be "0", bit 9 "0"): | ||
226 | * 3-0: 0xD) 6 Mbps | ||
227 | * 0xF) 9 Mbps | ||
228 | * 0x5) 12 Mbps | ||
229 | * 0x7) 18 Mbps | ||
230 | * 0x9) 24 Mbps | ||
231 | * 0xB) 36 Mbps | ||
232 | * 0x1) 48 Mbps | ||
233 | * 0x3) 54 Mbps | ||
234 | * | ||
235 | * Legacy CCK rate format for bits 7:0 (bit 8 must be "0", bit 9 "1"): | ||
236 | * 6-0: 10) 1 Mbps | ||
237 | * 20) 2 Mbps | ||
238 | * 55) 5.5 Mbps | ||
239 | * 110) 11 Mbps | ||
240 | */ | ||
241 | #define RATE_MCS_CODE_MSK 0x7 | ||
242 | #define RATE_MCS_SPATIAL_POS 3 | ||
243 | #define RATE_MCS_SPATIAL_MSK 0x18 | ||
244 | #define RATE_MCS_HT_DUP_POS 5 | ||
245 | #define RATE_MCS_HT_DUP_MSK 0x20 | ||
246 | /* Both legacy and HT use bits 7:0 as the CCK/OFDM rate or HT MCS */ | ||
247 | #define RATE_MCS_RATE_MSK 0xff | ||
248 | |||
249 | /* Bit 8: (1) HT format, (0) legacy format in bits 7:0 */ | ||
250 | #define RATE_MCS_FLAGS_POS 8 | ||
251 | #define RATE_MCS_HT_POS 8 | ||
252 | #define RATE_MCS_HT_MSK 0x100 | ||
253 | |||
254 | /* Bit 9: (1) CCK, (0) OFDM. HT (bit 8) must be "0" for this bit to be valid */ | ||
255 | #define RATE_MCS_CCK_POS 9 | ||
256 | #define RATE_MCS_CCK_MSK 0x200 | ||
257 | |||
258 | /* Bit 10: (1) Use Green Field preamble */ | ||
259 | #define RATE_MCS_GF_POS 10 | ||
260 | #define RATE_MCS_GF_MSK 0x400 | ||
261 | |||
262 | /* Bit 11: (1) Use 40Mhz HT40 chnl width, (0) use 20 MHz legacy chnl width */ | ||
263 | #define RATE_MCS_HT40_POS 11 | ||
264 | #define RATE_MCS_HT40_MSK 0x800 | ||
265 | |||
266 | /* Bit 12: (1) Duplicate data on both 20MHz chnls. HT40 (bit 11) must be set. */ | ||
267 | #define RATE_MCS_DUP_POS 12 | ||
268 | #define RATE_MCS_DUP_MSK 0x1000 | ||
269 | |||
270 | /* Bit 13: (1) Short guard interval (0.4 usec), (0) normal GI (0.8 usec) */ | ||
271 | #define RATE_MCS_SGI_POS 13 | ||
272 | #define RATE_MCS_SGI_MSK 0x2000 | ||
273 | |||
274 | /** | ||
275 | * rate_n_flags Tx antenna masks | ||
276 | * 4965 has 2 transmitters | ||
277 | * 5100 has 1 transmitter B | ||
278 | * 5150 has 1 transmitter A | ||
279 | * 5300 has 3 transmitters | ||
280 | * 5350 has 3 transmitters | ||
281 | * bit14:16 | ||
282 | */ | ||
283 | #define RATE_MCS_ANT_POS 14 | ||
284 | #define RATE_MCS_ANT_A_MSK 0x04000 | ||
285 | #define RATE_MCS_ANT_B_MSK 0x08000 | ||
286 | #define RATE_MCS_ANT_C_MSK 0x10000 | ||
287 | #define RATE_MCS_ANT_AB_MSK (RATE_MCS_ANT_A_MSK | RATE_MCS_ANT_B_MSK) | ||
288 | #define RATE_MCS_ANT_ABC_MSK (RATE_MCS_ANT_AB_MSK | RATE_MCS_ANT_C_MSK) | ||
289 | #define RATE_ANT_NUM 3 | ||
290 | |||
291 | #define POWER_TABLE_NUM_ENTRIES 33 | ||
292 | #define POWER_TABLE_NUM_HT_OFDM_ENTRIES 32 | ||
293 | #define POWER_TABLE_CCK_ENTRY 32 | ||
294 | |||
295 | #define IWL_PWR_NUM_HT_OFDM_ENTRIES 24 | ||
296 | #define IWL_PWR_CCK_ENTRIES 2 | ||
297 | |||
298 | /** | ||
299 | * struct tx_power_dual_stream | ||
300 | * | ||
301 | * Table entries in REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH | ||
302 | * | ||
303 | * Same format as iwl_tx_power_dual_stream, but __le32 | ||
304 | */ | ||
305 | struct tx_power_dual_stream { | ||
306 | __le32 dw; | ||
307 | } __packed; | ||
308 | |||
309 | /** | ||
310 | * Command REPLY_TX_POWER_DBM_CMD = 0x98 | ||
311 | * struct iwlagn_tx_power_dbm_cmd | ||
312 | */ | ||
313 | #define IWLAGN_TX_POWER_AUTO 0x7f | ||
314 | #define IWLAGN_TX_POWER_NO_CLOSED (0x1 << 6) | ||
315 | |||
316 | struct iwlagn_tx_power_dbm_cmd { | ||
317 | s8 global_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */ | ||
318 | u8 flags; | ||
319 | s8 srv_chan_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */ | ||
320 | u8 reserved; | ||
321 | } __packed; | ||
322 | |||
323 | /** | ||
324 | * Command TX_ANT_CONFIGURATION_CMD = 0x98 | ||
325 | * This command is used to configure valid Tx antenna. | ||
326 | * By default uCode concludes the valid antenna according to the radio flavor. | ||
327 | * This command enables the driver to override/modify this conclusion. | ||
328 | */ | ||
329 | struct iwl_tx_ant_config_cmd { | ||
330 | __le32 valid; | ||
331 | } __packed; | ||
332 | |||
333 | /****************************************************************************** | ||
334 | * (0a) | ||
335 | * Alive and Error Commands & Responses: | ||
336 | * | ||
337 | *****************************************************************************/ | ||
338 | |||
339 | #define UCODE_VALID_OK cpu_to_le32(0x1) | ||
340 | |||
341 | /** | ||
342 | * REPLY_ALIVE = 0x1 (response only, not a command) | ||
343 | * | ||
344 | * uCode issues this "alive" notification once the runtime image is ready | ||
345 | * to receive commands from the driver. This is the *second* "alive" | ||
346 | * notification that the driver will receive after rebooting uCode; | ||
347 | * this "alive" is indicated by subtype field != 9. | ||
348 | * | ||
349 | * See comments documenting "BSM" (bootstrap state machine). | ||
350 | * | ||
351 | * This response includes two pointers to structures within the device's | ||
352 | * data SRAM (access via HBUS_TARG_MEM_* regs) that are useful for debugging: | ||
353 | * | ||
354 | * 1) log_event_table_ptr indicates base of the event log. This traces | ||
355 | * a 256-entry history of uCode execution within a circular buffer. | ||
356 | * Its header format is: | ||
357 | * | ||
358 | * __le32 log_size; log capacity (in number of entries) | ||
359 | * __le32 type; (1) timestamp with each entry, (0) no timestamp | ||
360 | * __le32 wraps; # times uCode has wrapped to top of circular buffer | ||
361 | * __le32 write_index; next circular buffer entry that uCode would fill | ||
362 | * | ||
363 | * The header is followed by the circular buffer of log entries. Entries | ||
364 | * with timestamps have the following format: | ||
365 | * | ||
366 | * __le32 event_id; range 0 - 1500 | ||
367 | * __le32 timestamp; low 32 bits of TSF (of network, if associated) | ||
368 | * __le32 data; event_id-specific data value | ||
369 | * | ||
370 | * Entries without timestamps contain only event_id and data. | ||
371 | * | ||
372 | * | ||
373 | * 2) error_event_table_ptr indicates base of the error log. This contains | ||
374 | * information about any uCode error that occurs. For agn, the format | ||
375 | * of the error log is defined by struct iwl_error_event_table. | ||
376 | * | ||
377 | * The Linux driver can print both logs to the system log when a uCode error | ||
378 | * occurs. | ||
379 | */ | ||
380 | |||
381 | /* | ||
382 | * Note: This structure is read from the device with IO accesses, | ||
383 | * and the reading already does the endian conversion. As it is | ||
384 | * read with u32-sized accesses, any members with a different size | ||
385 | * need to be ordered correctly though! | ||
386 | */ | ||
387 | struct iwl_error_event_table { | ||
388 | u32 valid; /* (nonzero) valid, (0) log is empty */ | ||
389 | u32 error_id; /* type of error */ | ||
390 | u32 pc; /* program counter */ | ||
391 | u32 blink1; /* branch link */ | ||
392 | u32 blink2; /* branch link */ | ||
393 | u32 ilink1; /* interrupt link */ | ||
394 | u32 ilink2; /* interrupt link */ | ||
395 | u32 data1; /* error-specific data */ | ||
396 | u32 data2; /* error-specific data */ | ||
397 | u32 line; /* source code line of error */ | ||
398 | u32 bcon_time; /* beacon timer */ | ||
399 | u32 tsf_low; /* network timestamp function timer */ | ||
400 | u32 tsf_hi; /* network timestamp function timer */ | ||
401 | u32 gp1; /* GP1 timer register */ | ||
402 | u32 gp2; /* GP2 timer register */ | ||
403 | u32 gp3; /* GP3 timer register */ | ||
404 | u32 ucode_ver; /* uCode version */ | ||
405 | u32 hw_ver; /* HW Silicon version */ | ||
406 | u32 brd_ver; /* HW board version */ | ||
407 | u32 log_pc; /* log program counter */ | ||
408 | u32 frame_ptr; /* frame pointer */ | ||
409 | u32 stack_ptr; /* stack pointer */ | ||
410 | u32 hcmd; /* last host command header */ | ||
411 | u32 isr0; /* isr status register LMPM_NIC_ISR0: | ||
412 | * rxtx_flag */ | ||
413 | u32 isr1; /* isr status register LMPM_NIC_ISR1: | ||
414 | * host_flag */ | ||
415 | u32 isr2; /* isr status register LMPM_NIC_ISR2: | ||
416 | * enc_flag */ | ||
417 | u32 isr3; /* isr status register LMPM_NIC_ISR3: | ||
418 | * time_flag */ | ||
419 | u32 isr4; /* isr status register LMPM_NIC_ISR4: | ||
420 | * wico interrupt */ | ||
421 | u32 isr_pref; /* isr status register LMPM_NIC_PREF_STAT */ | ||
422 | u32 wait_event; /* wait event() caller address */ | ||
423 | u32 l2p_control; /* L2pControlField */ | ||
424 | u32 l2p_duration; /* L2pDurationField */ | ||
425 | u32 l2p_mhvalid; /* L2pMhValidBits */ | ||
426 | u32 l2p_addr_match; /* L2pAddrMatchStat */ | ||
427 | u32 lmpm_pmg_sel; /* indicate which clocks are turned on | ||
428 | * (LMPM_PMG_SEL) */ | ||
429 | u32 u_timestamp; /* indicate when the date and time of the | ||
430 | * compilation */ | ||
431 | u32 flow_handler; /* FH read/write pointers, RX credit */ | ||
432 | } __packed; | ||
433 | |||
434 | struct iwl_alive_resp { | ||
435 | u8 ucode_minor; | ||
436 | u8 ucode_major; | ||
437 | __le16 reserved1; | ||
438 | u8 sw_rev[8]; | ||
439 | u8 ver_type; | ||
440 | u8 ver_subtype; /* not "9" for runtime alive */ | ||
441 | __le16 reserved2; | ||
442 | __le32 log_event_table_ptr; /* SRAM address for event log */ | ||
443 | __le32 error_event_table_ptr; /* SRAM address for error log */ | ||
444 | __le32 timestamp; | ||
445 | __le32 is_valid; | ||
446 | } __packed; | ||
447 | |||
448 | /* | ||
449 | * REPLY_ERROR = 0x2 (response only, not a command) | ||
450 | */ | ||
451 | struct iwl_error_resp { | ||
452 | __le32 error_type; | ||
453 | u8 cmd_id; | ||
454 | u8 reserved1; | ||
455 | __le16 bad_cmd_seq_num; | ||
456 | __le32 error_info; | ||
457 | __le64 timestamp; | ||
458 | } __packed; | ||
459 | |||
460 | /****************************************************************************** | ||
461 | * (1) | ||
462 | * RXON Commands & Responses: | ||
463 | * | ||
464 | *****************************************************************************/ | ||
465 | |||
466 | /* | ||
467 | * Rx config defines & structure | ||
468 | */ | ||
469 | /* rx_config device types */ | ||
470 | enum { | ||
471 | RXON_DEV_TYPE_AP = 1, | ||
472 | RXON_DEV_TYPE_ESS = 3, | ||
473 | RXON_DEV_TYPE_IBSS = 4, | ||
474 | RXON_DEV_TYPE_SNIFFER = 6, | ||
475 | RXON_DEV_TYPE_CP = 7, | ||
476 | RXON_DEV_TYPE_2STA = 8, | ||
477 | RXON_DEV_TYPE_P2P = 9, | ||
478 | }; | ||
479 | |||
480 | |||
481 | #define RXON_RX_CHAIN_DRIVER_FORCE_MSK cpu_to_le16(0x1 << 0) | ||
482 | #define RXON_RX_CHAIN_DRIVER_FORCE_POS (0) | ||
483 | #define RXON_RX_CHAIN_VALID_MSK cpu_to_le16(0x7 << 1) | ||
484 | #define RXON_RX_CHAIN_VALID_POS (1) | ||
485 | #define RXON_RX_CHAIN_FORCE_SEL_MSK cpu_to_le16(0x7 << 4) | ||
486 | #define RXON_RX_CHAIN_FORCE_SEL_POS (4) | ||
487 | #define RXON_RX_CHAIN_FORCE_MIMO_SEL_MSK cpu_to_le16(0x7 << 7) | ||
488 | #define RXON_RX_CHAIN_FORCE_MIMO_SEL_POS (7) | ||
489 | #define RXON_RX_CHAIN_CNT_MSK cpu_to_le16(0x3 << 10) | ||
490 | #define RXON_RX_CHAIN_CNT_POS (10) | ||
491 | #define RXON_RX_CHAIN_MIMO_CNT_MSK cpu_to_le16(0x3 << 12) | ||
492 | #define RXON_RX_CHAIN_MIMO_CNT_POS (12) | ||
493 | #define RXON_RX_CHAIN_MIMO_FORCE_MSK cpu_to_le16(0x1 << 14) | ||
494 | #define RXON_RX_CHAIN_MIMO_FORCE_POS (14) | ||
495 | |||
496 | /* rx_config flags */ | ||
497 | /* band & modulation selection */ | ||
498 | #define RXON_FLG_BAND_24G_MSK cpu_to_le32(1 << 0) | ||
499 | #define RXON_FLG_CCK_MSK cpu_to_le32(1 << 1) | ||
500 | /* auto detection enable */ | ||
501 | #define RXON_FLG_AUTO_DETECT_MSK cpu_to_le32(1 << 2) | ||
502 | /* TGg protection when tx */ | ||
503 | #define RXON_FLG_TGG_PROTECT_MSK cpu_to_le32(1 << 3) | ||
504 | /* cck short slot & preamble */ | ||
505 | #define RXON_FLG_SHORT_SLOT_MSK cpu_to_le32(1 << 4) | ||
506 | #define RXON_FLG_SHORT_PREAMBLE_MSK cpu_to_le32(1 << 5) | ||
507 | /* antenna selection */ | ||
508 | #define RXON_FLG_DIS_DIV_MSK cpu_to_le32(1 << 7) | ||
509 | #define RXON_FLG_ANT_SEL_MSK cpu_to_le32(0x0f00) | ||
510 | #define RXON_FLG_ANT_A_MSK cpu_to_le32(1 << 8) | ||
511 | #define RXON_FLG_ANT_B_MSK cpu_to_le32(1 << 9) | ||
512 | /* radar detection enable */ | ||
513 | #define RXON_FLG_RADAR_DETECT_MSK cpu_to_le32(1 << 12) | ||
514 | #define RXON_FLG_TGJ_NARROW_BAND_MSK cpu_to_le32(1 << 13) | ||
515 | /* rx response to host with 8-byte TSF | ||
516 | * (according to ON_AIR deassertion) */ | ||
517 | #define RXON_FLG_TSF2HOST_MSK cpu_to_le32(1 << 15) | ||
518 | |||
519 | |||
520 | /* HT flags */ | ||
521 | #define RXON_FLG_CTRL_CHANNEL_LOC_POS (22) | ||
522 | #define RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK cpu_to_le32(0x1 << 22) | ||
523 | |||
524 | #define RXON_FLG_HT_OPERATING_MODE_POS (23) | ||
525 | |||
526 | #define RXON_FLG_HT_PROT_MSK cpu_to_le32(0x1 << 23) | ||
527 | #define RXON_FLG_HT40_PROT_MSK cpu_to_le32(0x2 << 23) | ||
528 | |||
529 | #define RXON_FLG_CHANNEL_MODE_POS (25) | ||
530 | #define RXON_FLG_CHANNEL_MODE_MSK cpu_to_le32(0x3 << 25) | ||
531 | |||
532 | /* channel mode */ | ||
533 | enum { | ||
534 | CHANNEL_MODE_LEGACY = 0, | ||
535 | CHANNEL_MODE_PURE_40 = 1, | ||
536 | CHANNEL_MODE_MIXED = 2, | ||
537 | CHANNEL_MODE_RESERVED = 3, | ||
538 | }; | ||
539 | #define RXON_FLG_CHANNEL_MODE_LEGACY cpu_to_le32(CHANNEL_MODE_LEGACY << RXON_FLG_CHANNEL_MODE_POS) | ||
540 | #define RXON_FLG_CHANNEL_MODE_PURE_40 cpu_to_le32(CHANNEL_MODE_PURE_40 << RXON_FLG_CHANNEL_MODE_POS) | ||
541 | #define RXON_FLG_CHANNEL_MODE_MIXED cpu_to_le32(CHANNEL_MODE_MIXED << RXON_FLG_CHANNEL_MODE_POS) | ||
542 | |||
543 | /* CTS to self (if spec allows) flag */ | ||
544 | #define RXON_FLG_SELF_CTS_EN cpu_to_le32(0x1<<30) | ||
545 | |||
546 | /* rx_config filter flags */ | ||
547 | /* accept all data frames */ | ||
548 | #define RXON_FILTER_PROMISC_MSK cpu_to_le32(1 << 0) | ||
549 | /* pass control & management to host */ | ||
550 | #define RXON_FILTER_CTL2HOST_MSK cpu_to_le32(1 << 1) | ||
551 | /* accept multi-cast */ | ||
552 | #define RXON_FILTER_ACCEPT_GRP_MSK cpu_to_le32(1 << 2) | ||
553 | /* don't decrypt uni-cast frames */ | ||
554 | #define RXON_FILTER_DIS_DECRYPT_MSK cpu_to_le32(1 << 3) | ||
555 | /* don't decrypt multi-cast frames */ | ||
556 | #define RXON_FILTER_DIS_GRP_DECRYPT_MSK cpu_to_le32(1 << 4) | ||
557 | /* STA is associated */ | ||
558 | #define RXON_FILTER_ASSOC_MSK cpu_to_le32(1 << 5) | ||
559 | /* transfer to host non bssid beacons in associated state */ | ||
560 | #define RXON_FILTER_BCON_AWARE_MSK cpu_to_le32(1 << 6) | ||
561 | |||
562 | /** | ||
563 | * REPLY_RXON = 0x10 (command, has simple generic response) | ||
564 | * | ||
565 | * RXON tunes the radio tuner to a service channel, and sets up a number | ||
566 | * of parameters that are used primarily for Rx, but also for Tx operations. | ||
567 | * | ||
568 | * NOTE: When tuning to a new channel, driver must set the | ||
569 | * RXON_FILTER_ASSOC_MSK to 0. This will clear station-dependent | ||
570 | * info within the device, including the station tables, tx retry | ||
571 | * rate tables, and txpower tables. Driver must build a new station | ||
572 | * table and txpower table before transmitting anything on the RXON | ||
573 | * channel. | ||
574 | * | ||
575 | * NOTE: All RXONs wipe clean the internal txpower table. Driver must | ||
576 | * issue a new REPLY_TX_PWR_TABLE_CMD after each REPLY_RXON (0x10), | ||
577 | * regardless of whether RXON_FILTER_ASSOC_MSK is set. | ||
578 | */ | ||
579 | |||
580 | struct iwl_rxon_cmd { | ||
581 | u8 node_addr[6]; | ||
582 | __le16 reserved1; | ||
583 | u8 bssid_addr[6]; | ||
584 | __le16 reserved2; | ||
585 | u8 wlap_bssid_addr[6]; | ||
586 | __le16 reserved3; | ||
587 | u8 dev_type; | ||
588 | u8 air_propagation; | ||
589 | __le16 rx_chain; | ||
590 | u8 ofdm_basic_rates; | ||
591 | u8 cck_basic_rates; | ||
592 | __le16 assoc_id; | ||
593 | __le32 flags; | ||
594 | __le32 filter_flags; | ||
595 | __le16 channel; | ||
596 | u8 ofdm_ht_single_stream_basic_rates; | ||
597 | u8 ofdm_ht_dual_stream_basic_rates; | ||
598 | u8 ofdm_ht_triple_stream_basic_rates; | ||
599 | u8 reserved5; | ||
600 | __le16 acquisition_data; | ||
601 | __le16 reserved6; | ||
602 | } __packed; | ||
603 | |||
604 | /* | ||
605 | * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response) | ||
606 | */ | ||
607 | struct iwl_rxon_assoc_cmd { | ||
608 | __le32 flags; | ||
609 | __le32 filter_flags; | ||
610 | u8 ofdm_basic_rates; | ||
611 | u8 cck_basic_rates; | ||
612 | __le16 reserved1; | ||
613 | u8 ofdm_ht_single_stream_basic_rates; | ||
614 | u8 ofdm_ht_dual_stream_basic_rates; | ||
615 | u8 ofdm_ht_triple_stream_basic_rates; | ||
616 | u8 reserved2; | ||
617 | __le16 rx_chain_select_flags; | ||
618 | __le16 acquisition_data; | ||
619 | __le32 reserved3; | ||
620 | } __packed; | ||
621 | |||
622 | #define IWL_CONN_MAX_LISTEN_INTERVAL 10 | ||
623 | #define IWL_MAX_UCODE_BEACON_INTERVAL 4 /* 4096 */ | ||
624 | |||
625 | /* | ||
626 | * REPLY_RXON_TIMING = 0x14 (command, has simple generic response) | ||
627 | */ | ||
628 | struct iwl_rxon_time_cmd { | ||
629 | __le64 timestamp; | ||
630 | __le16 beacon_interval; | ||
631 | __le16 atim_window; | ||
632 | __le32 beacon_init_val; | ||
633 | __le16 listen_interval; | ||
634 | u8 dtim_period; | ||
635 | u8 delta_cp_bss_tbtts; | ||
636 | } __packed; | ||
637 | |||
638 | /* | ||
639 | * REPLY_CHANNEL_SWITCH = 0x72 (command, has simple generic response) | ||
640 | */ | ||
641 | /** | ||
642 | * struct iwl5000_channel_switch_cmd | ||
643 | * @band: 0- 5.2GHz, 1- 2.4GHz | ||
644 | * @expect_beacon: 0- resume transmits after channel switch | ||
645 | * 1- wait for beacon to resume transmits | ||
646 | * @channel: new channel number | ||
647 | * @rxon_flags: Rx on flags | ||
648 | * @rxon_filter_flags: filtering parameters | ||
649 | * @switch_time: switch time in extended beacon format | ||
650 | * @reserved: reserved bytes | ||
651 | */ | ||
652 | struct iwl5000_channel_switch_cmd { | ||
653 | u8 band; | ||
654 | u8 expect_beacon; | ||
655 | __le16 channel; | ||
656 | __le32 rxon_flags; | ||
657 | __le32 rxon_filter_flags; | ||
658 | __le32 switch_time; | ||
659 | __le32 reserved[2][IWL_PWR_NUM_HT_OFDM_ENTRIES + IWL_PWR_CCK_ENTRIES]; | ||
660 | } __packed; | ||
661 | |||
662 | /** | ||
663 | * struct iwl6000_channel_switch_cmd | ||
664 | * @band: 0- 5.2GHz, 1- 2.4GHz | ||
665 | * @expect_beacon: 0- resume transmits after channel switch | ||
666 | * 1- wait for beacon to resume transmits | ||
667 | * @channel: new channel number | ||
668 | * @rxon_flags: Rx on flags | ||
669 | * @rxon_filter_flags: filtering parameters | ||
670 | * @switch_time: switch time in extended beacon format | ||
671 | * @reserved: reserved bytes | ||
672 | */ | ||
673 | struct iwl6000_channel_switch_cmd { | ||
674 | u8 band; | ||
675 | u8 expect_beacon; | ||
676 | __le16 channel; | ||
677 | __le32 rxon_flags; | ||
678 | __le32 rxon_filter_flags; | ||
679 | __le32 switch_time; | ||
680 | __le32 reserved[3][IWL_PWR_NUM_HT_OFDM_ENTRIES + IWL_PWR_CCK_ENTRIES]; | ||
681 | } __packed; | ||
682 | |||
683 | /* | ||
684 | * CHANNEL_SWITCH_NOTIFICATION = 0x73 (notification only, not a command) | ||
685 | */ | ||
686 | struct iwl_csa_notification { | ||
687 | __le16 band; | ||
688 | __le16 channel; | ||
689 | __le32 status; /* 0 - OK, 1 - fail */ | ||
690 | } __packed; | ||
691 | |||
692 | /****************************************************************************** | ||
693 | * (2) | ||
694 | * Quality-of-Service (QOS) Commands & Responses: | ||
695 | * | ||
696 | *****************************************************************************/ | ||
697 | |||
698 | /** | ||
699 | * struct iwl_ac_qos -- QOS timing params for REPLY_QOS_PARAM | ||
700 | * One for each of 4 EDCA access categories in struct iwl_qosparam_cmd | ||
701 | * | ||
702 | * @cw_min: Contention window, start value in numbers of slots. | ||
703 | * Should be a power-of-2, minus 1. Device's default is 0x0f. | ||
704 | * @cw_max: Contention window, max value in numbers of slots. | ||
705 | * Should be a power-of-2, minus 1. Device's default is 0x3f. | ||
706 | * @aifsn: Number of slots in Arbitration Interframe Space (before | ||
707 | * performing random backoff timing prior to Tx). Device default 1. | ||
708 | * @edca_txop: Length of Tx opportunity, in uSecs. Device default is 0. | ||
709 | * | ||
710 | * Device will automatically increase contention window by (2*CW) + 1 for each | ||
711 | * transmission retry. Device uses cw_max as a bit mask, ANDed with new CW | ||
712 | * value, to cap the CW value. | ||
713 | */ | ||
714 | struct iwl_ac_qos { | ||
715 | __le16 cw_min; | ||
716 | __le16 cw_max; | ||
717 | u8 aifsn; | ||
718 | u8 reserved1; | ||
719 | __le16 edca_txop; | ||
720 | } __packed; | ||
721 | |||
722 | /* QoS flags defines */ | ||
723 | #define QOS_PARAM_FLG_UPDATE_EDCA_MSK cpu_to_le32(0x01) | ||
724 | #define QOS_PARAM_FLG_TGN_MSK cpu_to_le32(0x02) | ||
725 | #define QOS_PARAM_FLG_TXOP_TYPE_MSK cpu_to_le32(0x10) | ||
726 | |||
727 | /* Number of Access Categories (AC) (EDCA), queues 0..3 */ | ||
728 | #define AC_NUM 4 | ||
729 | |||
730 | /* | ||
731 | * REPLY_QOS_PARAM = 0x13 (command, has simple generic response) | ||
732 | * | ||
733 | * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs | ||
734 | * 0: Background, 1: Best Effort, 2: Video, 3: Voice. | ||
735 | */ | ||
736 | struct iwl_qosparam_cmd { | ||
737 | __le32 qos_flags; | ||
738 | struct iwl_ac_qos ac[AC_NUM]; | ||
739 | } __packed; | ||
740 | |||
741 | /****************************************************************************** | ||
742 | * (3) | ||
743 | * Add/Modify Stations Commands & Responses: | ||
744 | * | ||
745 | *****************************************************************************/ | ||
746 | /* | ||
747 | * Multi station support | ||
748 | */ | ||
749 | |||
750 | /* Special, dedicated locations within device's station table */ | ||
751 | #define IWL_AP_ID 0 | ||
752 | #define IWL_AP_ID_PAN 1 | ||
753 | #define IWL_STA_ID 2 | ||
754 | #define IWLAGN_PAN_BCAST_ID 14 | ||
755 | #define IWLAGN_BROADCAST_ID 15 | ||
756 | #define IWLAGN_STATION_COUNT 16 | ||
757 | |||
758 | #define IWL_INVALID_STATION 255 | ||
759 | #define IWL_MAX_TID_COUNT 8 | ||
760 | #define IWL_TID_NON_QOS IWL_MAX_TID_COUNT | ||
761 | |||
762 | #define STA_FLG_TX_RATE_MSK cpu_to_le32(1 << 2) | ||
763 | #define STA_FLG_PWR_SAVE_MSK cpu_to_le32(1 << 8) | ||
764 | #define STA_FLG_PAN_STATION cpu_to_le32(1 << 13) | ||
765 | #define STA_FLG_RTS_MIMO_PROT_MSK cpu_to_le32(1 << 17) | ||
766 | #define STA_FLG_AGG_MPDU_8US_MSK cpu_to_le32(1 << 18) | ||
767 | #define STA_FLG_MAX_AGG_SIZE_POS (19) | ||
768 | #define STA_FLG_MAX_AGG_SIZE_MSK cpu_to_le32(3 << 19) | ||
769 | #define STA_FLG_HT40_EN_MSK cpu_to_le32(1 << 21) | ||
770 | #define STA_FLG_MIMO_DIS_MSK cpu_to_le32(1 << 22) | ||
771 | #define STA_FLG_AGG_MPDU_DENSITY_POS (23) | ||
772 | #define STA_FLG_AGG_MPDU_DENSITY_MSK cpu_to_le32(7 << 23) | ||
773 | |||
774 | /* Use in mode field. 1: modify existing entry, 0: add new station entry */ | ||
775 | #define STA_CONTROL_MODIFY_MSK 0x01 | ||
776 | |||
777 | /* key flags __le16*/ | ||
778 | #define STA_KEY_FLG_ENCRYPT_MSK cpu_to_le16(0x0007) | ||
779 | #define STA_KEY_FLG_NO_ENC cpu_to_le16(0x0000) | ||
780 | #define STA_KEY_FLG_WEP cpu_to_le16(0x0001) | ||
781 | #define STA_KEY_FLG_CCMP cpu_to_le16(0x0002) | ||
782 | #define STA_KEY_FLG_TKIP cpu_to_le16(0x0003) | ||
783 | |||
784 | #define STA_KEY_FLG_KEYID_POS 8 | ||
785 | #define STA_KEY_FLG_INVALID cpu_to_le16(0x0800) | ||
786 | /* wep key is either from global key (0) or from station info array (1) */ | ||
787 | #define STA_KEY_FLG_MAP_KEY_MSK cpu_to_le16(0x0008) | ||
788 | |||
789 | /* wep key in STA: 5-bytes (0) or 13-bytes (1) */ | ||
790 | #define STA_KEY_FLG_KEY_SIZE_MSK cpu_to_le16(0x1000) | ||
791 | #define STA_KEY_MULTICAST_MSK cpu_to_le16(0x4000) | ||
792 | #define STA_KEY_MAX_NUM 8 | ||
793 | #define STA_KEY_MAX_NUM_PAN 16 | ||
794 | /* must not match WEP_INVALID_OFFSET */ | ||
795 | #define IWLAGN_HW_KEY_DEFAULT 0xfe | ||
796 | |||
797 | /* Flags indicate whether to modify vs. don't change various station params */ | ||
798 | #define STA_MODIFY_KEY_MASK 0x01 | ||
799 | #define STA_MODIFY_TID_DISABLE_TX 0x02 | ||
800 | #define STA_MODIFY_TX_RATE_MSK 0x04 | ||
801 | #define STA_MODIFY_ADDBA_TID_MSK 0x08 | ||
802 | #define STA_MODIFY_DELBA_TID_MSK 0x10 | ||
803 | #define STA_MODIFY_SLEEP_TX_COUNT_MSK 0x20 | ||
804 | |||
805 | /* Receiver address (actually, Rx station's index into station table), | ||
806 | * combined with Traffic ID (QOS priority), in format used by Tx Scheduler */ | ||
807 | #define BUILD_RAxTID(sta_id, tid) (((sta_id) << 4) + (tid)) | ||
808 | |||
809 | /* agn */ | ||
810 | struct iwl_keyinfo { | ||
811 | __le16 key_flags; | ||
812 | u8 tkip_rx_tsc_byte2; /* TSC[2] for key mix ph1 detection */ | ||
813 | u8 reserved1; | ||
814 | __le16 tkip_rx_ttak[5]; /* 10-byte unicast TKIP TTAK */ | ||
815 | u8 key_offset; | ||
816 | u8 reserved2; | ||
817 | u8 key[16]; /* 16-byte unicast decryption key */ | ||
818 | __le64 tx_secur_seq_cnt; | ||
819 | __le64 hw_tkip_mic_rx_key; | ||
820 | __le64 hw_tkip_mic_tx_key; | ||
821 | } __packed; | ||
822 | |||
823 | /** | ||
824 | * struct sta_id_modify | ||
825 | * @addr[ETH_ALEN]: station's MAC address | ||
826 | * @sta_id: index of station in uCode's station table | ||
827 | * @modify_mask: STA_MODIFY_*, 1: modify, 0: don't change | ||
828 | * | ||
829 | * Driver selects unused table index when adding new station, | ||
830 | * or the index to a pre-existing station entry when modifying that station. | ||
831 | * Some indexes have special purposes (IWL_AP_ID, index 0, is for AP). | ||
832 | * | ||
833 | * modify_mask flags select which parameters to modify vs. leave alone. | ||
834 | */ | ||
835 | struct sta_id_modify { | ||
836 | u8 addr[ETH_ALEN]; | ||
837 | __le16 reserved1; | ||
838 | u8 sta_id; | ||
839 | u8 modify_mask; | ||
840 | __le16 reserved2; | ||
841 | } __packed; | ||
842 | |||
843 | /* | ||
844 | * REPLY_ADD_STA = 0x18 (command) | ||
845 | * | ||
846 | * The device contains an internal table of per-station information, | ||
847 | * with info on security keys, aggregation parameters, and Tx rates for | ||
848 | * initial Tx attempt and any retries (agn devices uses | ||
849 | * REPLY_TX_LINK_QUALITY_CMD, | ||
850 | * | ||
851 | * REPLY_ADD_STA sets up the table entry for one station, either creating | ||
852 | * a new entry, or modifying a pre-existing one. | ||
853 | * | ||
854 | * NOTE: RXON command (without "associated" bit set) wipes the station table | ||
855 | * clean. Moving into RF_KILL state does this also. Driver must set up | ||
856 | * new station table before transmitting anything on the RXON channel | ||
857 | * (except active scans or active measurements; those commands carry | ||
858 | * their own txpower/rate setup data). | ||
859 | * | ||
860 | * When getting started on a new channel, driver must set up the | ||
861 | * IWL_BROADCAST_ID entry (last entry in the table). For a client | ||
862 | * station in a BSS, once an AP is selected, driver sets up the AP STA | ||
863 | * in the IWL_AP_ID entry (1st entry in the table). BROADCAST and AP | ||
864 | * are all that are needed for a BSS client station. If the device is | ||
865 | * used as AP, or in an IBSS network, driver must set up station table | ||
866 | * entries for all STAs in network, starting with index IWL_STA_ID. | ||
867 | */ | ||
868 | |||
869 | struct iwl_addsta_cmd { | ||
870 | u8 mode; /* 1: modify existing, 0: add new station */ | ||
871 | u8 reserved[3]; | ||
872 | struct sta_id_modify sta; | ||
873 | struct iwl_keyinfo key; | ||
874 | __le32 station_flags; /* STA_FLG_* */ | ||
875 | __le32 station_flags_msk; /* STA_FLG_* */ | ||
876 | |||
877 | /* bit field to disable (1) or enable (0) Tx for Traffic ID (TID) | ||
878 | * corresponding to bit (e.g. bit 5 controls TID 5). | ||
879 | * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */ | ||
880 | __le16 tid_disable_tx; | ||
881 | __le16 legacy_reserved; | ||
882 | |||
883 | /* TID for which to add block-ack support. | ||
884 | * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ | ||
885 | u8 add_immediate_ba_tid; | ||
886 | |||
887 | /* TID for which to remove block-ack support. | ||
888 | * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */ | ||
889 | u8 remove_immediate_ba_tid; | ||
890 | |||
891 | /* Starting Sequence Number for added block-ack support. | ||
892 | * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ | ||
893 | __le16 add_immediate_ba_ssn; | ||
894 | |||
895 | /* | ||
896 | * Number of packets OK to transmit to station even though | ||
897 | * it is asleep -- used to synchronise PS-poll and u-APSD | ||
898 | * responses while ucode keeps track of STA sleep state. | ||
899 | */ | ||
900 | __le16 sleep_tx_count; | ||
901 | |||
902 | __le16 reserved2; | ||
903 | } __packed; | ||
904 | |||
905 | |||
906 | #define ADD_STA_SUCCESS_MSK 0x1 | ||
907 | #define ADD_STA_NO_ROOM_IN_TABLE 0x2 | ||
908 | #define ADD_STA_NO_BLOCK_ACK_RESOURCE 0x4 | ||
909 | #define ADD_STA_MODIFY_NON_EXIST_STA 0x8 | ||
910 | /* | ||
911 | * REPLY_ADD_STA = 0x18 (response) | ||
912 | */ | ||
913 | struct iwl_add_sta_resp { | ||
914 | u8 status; /* ADD_STA_* */ | ||
915 | } __packed; | ||
916 | |||
917 | #define REM_STA_SUCCESS_MSK 0x1 | ||
918 | /* | ||
919 | * REPLY_REM_STA = 0x19 (response) | ||
920 | */ | ||
921 | struct iwl_rem_sta_resp { | ||
922 | u8 status; | ||
923 | } __packed; | ||
924 | |||
925 | /* | ||
926 | * REPLY_REM_STA = 0x19 (command) | ||
927 | */ | ||
928 | struct iwl_rem_sta_cmd { | ||
929 | u8 num_sta; /* number of removed stations */ | ||
930 | u8 reserved[3]; | ||
931 | u8 addr[ETH_ALEN]; /* MAC addr of the first station */ | ||
932 | u8 reserved2[2]; | ||
933 | } __packed; | ||
934 | |||
935 | |||
936 | /* WiFi queues mask */ | ||
937 | #define IWL_SCD_BK_MSK cpu_to_le32(BIT(0)) | ||
938 | #define IWL_SCD_BE_MSK cpu_to_le32(BIT(1)) | ||
939 | #define IWL_SCD_VI_MSK cpu_to_le32(BIT(2)) | ||
940 | #define IWL_SCD_VO_MSK cpu_to_le32(BIT(3)) | ||
941 | #define IWL_SCD_MGMT_MSK cpu_to_le32(BIT(3)) | ||
942 | |||
943 | /* PAN queues mask */ | ||
944 | #define IWL_PAN_SCD_BK_MSK cpu_to_le32(BIT(4)) | ||
945 | #define IWL_PAN_SCD_BE_MSK cpu_to_le32(BIT(5)) | ||
946 | #define IWL_PAN_SCD_VI_MSK cpu_to_le32(BIT(6)) | ||
947 | #define IWL_PAN_SCD_VO_MSK cpu_to_le32(BIT(7)) | ||
948 | #define IWL_PAN_SCD_MGMT_MSK cpu_to_le32(BIT(7)) | ||
949 | #define IWL_PAN_SCD_MULTICAST_MSK cpu_to_le32(BIT(8)) | ||
950 | |||
951 | #define IWL_AGG_TX_QUEUE_MSK cpu_to_le32(0xffc00) | ||
952 | |||
953 | #define IWL_DROP_SINGLE 0 | ||
954 | #define IWL_DROP_ALL (BIT(IWL_RXON_CTX_BSS) | BIT(IWL_RXON_CTX_PAN)) | ||
955 | |||
956 | /* | ||
957 | * REPLY_TXFIFO_FLUSH = 0x1e(command and response) | ||
958 | * | ||
959 | * When using full FIFO flush this command checks the scheduler HW block WR/RD | ||
960 | * pointers to check if all the frames were transferred by DMA into the | ||
961 | * relevant TX FIFO queue. Only when the DMA is finished and the queue is | ||
962 | * empty the command can finish. | ||
963 | * This command is used to flush the TXFIFO from transmit commands, it may | ||
964 | * operate on single or multiple queues, the command queue can't be flushed by | ||
965 | * this command. The command response is returned when all the queue flush | ||
966 | * operations are done. Each TX command flushed return response with the FLUSH | ||
967 | * status set in the TX response status. When FIFO flush operation is used, | ||
968 | * the flush operation ends when both the scheduler DMA done and TXFIFO empty | ||
969 | * are set. | ||
970 | * | ||
971 | * @fifo_control: bit mask for which queues to flush | ||
972 | * @flush_control: flush controls | ||
973 | * 0: Dump single MSDU | ||
974 | * 1: Dump multiple MSDU according to PS, INVALID STA, TTL, TID disable. | ||
975 | * 2: Dump all FIFO | ||
976 | */ | ||
977 | struct iwl_txfifo_flush_cmd { | ||
978 | __le32 fifo_control; | ||
979 | __le16 flush_control; | ||
980 | __le16 reserved; | ||
981 | } __packed; | ||
982 | |||
983 | /* | ||
984 | * REPLY_WEP_KEY = 0x20 | ||
985 | */ | ||
986 | struct iwl_wep_key { | ||
987 | u8 key_index; | ||
988 | u8 key_offset; | ||
989 | u8 reserved1[2]; | ||
990 | u8 key_size; | ||
991 | u8 reserved2[3]; | ||
992 | u8 key[16]; | ||
993 | } __packed; | ||
994 | |||
995 | struct iwl_wep_cmd { | ||
996 | u8 num_keys; | ||
997 | u8 global_key_type; | ||
998 | u8 flags; | ||
999 | u8 reserved; | ||
1000 | struct iwl_wep_key key[0]; | ||
1001 | } __packed; | ||
1002 | |||
1003 | #define WEP_KEY_WEP_TYPE 1 | ||
1004 | #define WEP_KEYS_MAX 4 | ||
1005 | #define WEP_INVALID_OFFSET 0xff | ||
1006 | #define WEP_KEY_LEN_64 5 | ||
1007 | #define WEP_KEY_LEN_128 13 | ||
1008 | |||
1009 | /****************************************************************************** | ||
1010 | * (4) | ||
1011 | * Rx Responses: | ||
1012 | * | ||
1013 | *****************************************************************************/ | ||
1014 | |||
1015 | #define RX_RES_STATUS_NO_CRC32_ERROR cpu_to_le32(1 << 0) | ||
1016 | #define RX_RES_STATUS_NO_RXE_OVERFLOW cpu_to_le32(1 << 1) | ||
1017 | |||
1018 | #define RX_RES_PHY_FLAGS_BAND_24_MSK cpu_to_le16(1 << 0) | ||
1019 | #define RX_RES_PHY_FLAGS_MOD_CCK_MSK cpu_to_le16(1 << 1) | ||
1020 | #define RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK cpu_to_le16(1 << 2) | ||
1021 | #define RX_RES_PHY_FLAGS_NARROW_BAND_MSK cpu_to_le16(1 << 3) | ||
1022 | #define RX_RES_PHY_FLAGS_ANTENNA_MSK 0xf0 | ||
1023 | #define RX_RES_PHY_FLAGS_ANTENNA_POS 4 | ||
1024 | |||
1025 | #define RX_RES_STATUS_SEC_TYPE_MSK (0x7 << 8) | ||
1026 | #define RX_RES_STATUS_SEC_TYPE_NONE (0x0 << 8) | ||
1027 | #define RX_RES_STATUS_SEC_TYPE_WEP (0x1 << 8) | ||
1028 | #define RX_RES_STATUS_SEC_TYPE_CCMP (0x2 << 8) | ||
1029 | #define RX_RES_STATUS_SEC_TYPE_TKIP (0x3 << 8) | ||
1030 | #define RX_RES_STATUS_SEC_TYPE_ERR (0x7 << 8) | ||
1031 | |||
1032 | #define RX_RES_STATUS_STATION_FOUND (1<<6) | ||
1033 | #define RX_RES_STATUS_NO_STATION_INFO_MISMATCH (1<<7) | ||
1034 | |||
1035 | #define RX_RES_STATUS_DECRYPT_TYPE_MSK (0x3 << 11) | ||
1036 | #define RX_RES_STATUS_NOT_DECRYPT (0x0 << 11) | ||
1037 | #define RX_RES_STATUS_DECRYPT_OK (0x3 << 11) | ||
1038 | #define RX_RES_STATUS_BAD_ICV_MIC (0x1 << 11) | ||
1039 | #define RX_RES_STATUS_BAD_KEY_TTAK (0x2 << 11) | ||
1040 | |||
1041 | #define RX_MPDU_RES_STATUS_ICV_OK (0x20) | ||
1042 | #define RX_MPDU_RES_STATUS_MIC_OK (0x40) | ||
1043 | #define RX_MPDU_RES_STATUS_TTAK_OK (1 << 7) | ||
1044 | #define RX_MPDU_RES_STATUS_DEC_DONE_MSK (0x800) | ||
1045 | |||
1046 | |||
1047 | #define IWLAGN_RX_RES_PHY_CNT 8 | ||
1048 | #define IWLAGN_RX_RES_AGC_IDX 1 | ||
1049 | #define IWLAGN_RX_RES_RSSI_AB_IDX 2 | ||
1050 | #define IWLAGN_RX_RES_RSSI_C_IDX 3 | ||
1051 | #define IWLAGN_OFDM_AGC_MSK 0xfe00 | ||
1052 | #define IWLAGN_OFDM_AGC_BIT_POS 9 | ||
1053 | #define IWLAGN_OFDM_RSSI_INBAND_A_BITMSK 0x00ff | ||
1054 | #define IWLAGN_OFDM_RSSI_ALLBAND_A_BITMSK 0xff00 | ||
1055 | #define IWLAGN_OFDM_RSSI_A_BIT_POS 0 | ||
1056 | #define IWLAGN_OFDM_RSSI_INBAND_B_BITMSK 0xff0000 | ||
1057 | #define IWLAGN_OFDM_RSSI_ALLBAND_B_BITMSK 0xff000000 | ||
1058 | #define IWLAGN_OFDM_RSSI_B_BIT_POS 16 | ||
1059 | #define IWLAGN_OFDM_RSSI_INBAND_C_BITMSK 0x00ff | ||
1060 | #define IWLAGN_OFDM_RSSI_ALLBAND_C_BITMSK 0xff00 | ||
1061 | #define IWLAGN_OFDM_RSSI_C_BIT_POS 0 | ||
1062 | |||
1063 | struct iwlagn_non_cfg_phy { | ||
1064 | __le32 non_cfg_phy[IWLAGN_RX_RES_PHY_CNT]; /* up to 8 phy entries */ | ||
1065 | } __packed; | ||
1066 | |||
1067 | |||
1068 | /* | ||
1069 | * REPLY_RX = 0xc3 (response only, not a command) | ||
1070 | * Used only for legacy (non 11n) frames. | ||
1071 | */ | ||
1072 | struct iwl_rx_phy_res { | ||
1073 | u8 non_cfg_phy_cnt; /* non configurable DSP phy data byte count */ | ||
1074 | u8 cfg_phy_cnt; /* configurable DSP phy data byte count */ | ||
1075 | u8 stat_id; /* configurable DSP phy data set ID */ | ||
1076 | u8 reserved1; | ||
1077 | __le64 timestamp; /* TSF at on air rise */ | ||
1078 | __le32 beacon_time_stamp; /* beacon at on-air rise */ | ||
1079 | __le16 phy_flags; /* general phy flags: band, modulation, ... */ | ||
1080 | __le16 channel; /* channel number */ | ||
1081 | u8 non_cfg_phy_buf[32]; /* for various implementations of non_cfg_phy */ | ||
1082 | __le32 rate_n_flags; /* RATE_MCS_* */ | ||
1083 | __le16 byte_count; /* frame's byte-count */ | ||
1084 | __le16 frame_time; /* frame's time on the air */ | ||
1085 | } __packed; | ||
1086 | |||
1087 | struct iwl_rx_mpdu_res_start { | ||
1088 | __le16 byte_count; | ||
1089 | __le16 reserved; | ||
1090 | } __packed; | ||
1091 | |||
1092 | |||
1093 | /****************************************************************************** | ||
1094 | * (5) | ||
1095 | * Tx Commands & Responses: | ||
1096 | * | ||
1097 | * Driver must place each REPLY_TX command into one of the prioritized Tx | ||
1098 | * queues in host DRAM, shared between driver and device (see comments for | ||
1099 | * SCD registers and Tx/Rx Queues). When the device's Tx scheduler and uCode | ||
1100 | * are preparing to transmit, the device pulls the Tx command over the PCI | ||
1101 | * bus via one of the device's Tx DMA channels, to fill an internal FIFO | ||
1102 | * from which data will be transmitted. | ||
1103 | * | ||
1104 | * uCode handles all timing and protocol related to control frames | ||
1105 | * (RTS/CTS/ACK), based on flags in the Tx command. uCode and Tx scheduler | ||
1106 | * handle reception of block-acks; uCode updates the host driver via | ||
1107 | * REPLY_COMPRESSED_BA. | ||
1108 | * | ||
1109 | * uCode handles retrying Tx when an ACK is expected but not received. | ||
1110 | * This includes trying lower data rates than the one requested in the Tx | ||
1111 | * command, as set up by the REPLY_TX_LINK_QUALITY_CMD (agn). | ||
1112 | * | ||
1113 | * Driver sets up transmit power for various rates via REPLY_TX_PWR_TABLE_CMD. | ||
1114 | * This command must be executed after every RXON command, before Tx can occur. | ||
1115 | *****************************************************************************/ | ||
1116 | |||
1117 | /* REPLY_TX Tx flags field */ | ||
1118 | |||
1119 | /* | ||
1120 | * 1: Use RTS/CTS protocol or CTS-to-self if spec allows it | ||
1121 | * before this frame. if CTS-to-self required check | ||
1122 | * RXON_FLG_SELF_CTS_EN status. | ||
1123 | */ | ||
1124 | #define TX_CMD_FLG_PROT_REQUIRE_MSK cpu_to_le32(1 << 0) | ||
1125 | |||
1126 | /* 1: Expect ACK from receiving station | ||
1127 | * 0: Don't expect ACK (MAC header's duration field s/b 0) | ||
1128 | * Set this for unicast frames, but not broadcast/multicast. */ | ||
1129 | #define TX_CMD_FLG_ACK_MSK cpu_to_le32(1 << 3) | ||
1130 | |||
1131 | /* For agn devices: | ||
1132 | * 1: Use rate scale table (see REPLY_TX_LINK_QUALITY_CMD). | ||
1133 | * Tx command's initial_rate_index indicates first rate to try; | ||
1134 | * uCode walks through table for additional Tx attempts. | ||
1135 | * 0: Use Tx rate/MCS from Tx command's rate_n_flags field. | ||
1136 | * This rate will be used for all Tx attempts; it will not be scaled. */ | ||
1137 | #define TX_CMD_FLG_STA_RATE_MSK cpu_to_le32(1 << 4) | ||
1138 | |||
1139 | /* 1: Expect immediate block-ack. | ||
1140 | * Set when Txing a block-ack request frame. Also set TX_CMD_FLG_ACK_MSK. */ | ||
1141 | #define TX_CMD_FLG_IMM_BA_RSP_MASK cpu_to_le32(1 << 6) | ||
1142 | |||
1143 | /* Tx antenna selection field; reserved (0) for agn devices. */ | ||
1144 | #define TX_CMD_FLG_ANT_SEL_MSK cpu_to_le32(0xf00) | ||
1145 | |||
1146 | /* 1: Ignore Bluetooth priority for this frame. | ||
1147 | * 0: Delay Tx until Bluetooth device is done (normal usage). */ | ||
1148 | #define TX_CMD_FLG_IGNORE_BT cpu_to_le32(1 << 12) | ||
1149 | |||
1150 | /* 1: uCode overrides sequence control field in MAC header. | ||
1151 | * 0: Driver provides sequence control field in MAC header. | ||
1152 | * Set this for management frames, non-QOS data frames, non-unicast frames, | ||
1153 | * and also in Tx command embedded in REPLY_SCAN_CMD for active scans. */ | ||
1154 | #define TX_CMD_FLG_SEQ_CTL_MSK cpu_to_le32(1 << 13) | ||
1155 | |||
1156 | /* 1: This frame is non-last MPDU; more fragments are coming. | ||
1157 | * 0: Last fragment, or not using fragmentation. */ | ||
1158 | #define TX_CMD_FLG_MORE_FRAG_MSK cpu_to_le32(1 << 14) | ||
1159 | |||
1160 | /* 1: uCode calculates and inserts Timestamp Function (TSF) in outgoing frame. | ||
1161 | * 0: No TSF required in outgoing frame. | ||
1162 | * Set this for transmitting beacons and probe responses. */ | ||
1163 | #define TX_CMD_FLG_TSF_MSK cpu_to_le32(1 << 16) | ||
1164 | |||
1165 | /* 1: Driver inserted 2 bytes pad after the MAC header, for (required) dword | ||
1166 | * alignment of frame's payload data field. | ||
1167 | * 0: No pad | ||
1168 | * Set this for MAC headers with 26 or 30 bytes, i.e. those with QOS or ADDR4 | ||
1169 | * field (but not both). Driver must align frame data (i.e. data following | ||
1170 | * MAC header) to DWORD boundary. */ | ||
1171 | #define TX_CMD_FLG_MH_PAD_MSK cpu_to_le32(1 << 20) | ||
1172 | |||
1173 | /* accelerate aggregation support | ||
1174 | * 0 - no CCMP encryption; 1 - CCMP encryption */ | ||
1175 | #define TX_CMD_FLG_AGG_CCMP_MSK cpu_to_le32(1 << 22) | ||
1176 | |||
1177 | /* HCCA-AP - disable duration overwriting. */ | ||
1178 | #define TX_CMD_FLG_DUR_MSK cpu_to_le32(1 << 25) | ||
1179 | |||
1180 | |||
1181 | /* | ||
1182 | * TX command security control | ||
1183 | */ | ||
1184 | #define TX_CMD_SEC_WEP 0x01 | ||
1185 | #define TX_CMD_SEC_CCM 0x02 | ||
1186 | #define TX_CMD_SEC_TKIP 0x03 | ||
1187 | #define TX_CMD_SEC_MSK 0x03 | ||
1188 | #define TX_CMD_SEC_SHIFT 6 | ||
1189 | #define TX_CMD_SEC_KEY128 0x08 | ||
1190 | |||
1191 | /* | ||
1192 | * security overhead sizes | ||
1193 | */ | ||
1194 | #define WEP_IV_LEN 4 | ||
1195 | #define WEP_ICV_LEN 4 | ||
1196 | #define CCMP_MIC_LEN 8 | ||
1197 | #define TKIP_ICV_LEN 4 | ||
1198 | |||
1199 | /* | ||
1200 | * REPLY_TX = 0x1c (command) | ||
1201 | */ | ||
1202 | |||
1203 | /* | ||
1204 | * 4965 uCode updates these Tx attempt count values in host DRAM. | ||
1205 | * Used for managing Tx retries when expecting block-acks. | ||
1206 | * Driver should set these fields to 0. | ||
1207 | */ | ||
1208 | struct iwl_dram_scratch { | ||
1209 | u8 try_cnt; /* Tx attempts */ | ||
1210 | u8 bt_kill_cnt; /* Tx attempts blocked by Bluetooth device */ | ||
1211 | __le16 reserved; | ||
1212 | } __packed; | ||
1213 | |||
1214 | struct iwl_tx_cmd { | ||
1215 | /* | ||
1216 | * MPDU byte count: | ||
1217 | * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size, | ||
1218 | * + 8 byte IV for CCM or TKIP (not used for WEP) | ||
1219 | * + Data payload | ||
1220 | * + 8-byte MIC (not used for CCM/WEP) | ||
1221 | * NOTE: Does not include Tx command bytes, post-MAC pad bytes, | ||
1222 | * MIC (CCM) 8 bytes, ICV (WEP/TKIP/CKIP) 4 bytes, CRC 4 bytes.i | ||
1223 | * Range: 14-2342 bytes. | ||
1224 | */ | ||
1225 | __le16 len; | ||
1226 | |||
1227 | /* | ||
1228 | * MPDU or MSDU byte count for next frame. | ||
1229 | * Used for fragmentation and bursting, but not 11n aggregation. | ||
1230 | * Same as "len", but for next frame. Set to 0 if not applicable. | ||
1231 | */ | ||
1232 | __le16 next_frame_len; | ||
1233 | |||
1234 | __le32 tx_flags; /* TX_CMD_FLG_* */ | ||
1235 | |||
1236 | /* uCode may modify this field of the Tx command (in host DRAM!). | ||
1237 | * Driver must also set dram_lsb_ptr and dram_msb_ptr in this cmd. */ | ||
1238 | struct iwl_dram_scratch scratch; | ||
1239 | |||
1240 | /* Rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is cleared. */ | ||
1241 | __le32 rate_n_flags; /* RATE_MCS_* */ | ||
1242 | |||
1243 | /* Index of destination station in uCode's station table */ | ||
1244 | u8 sta_id; | ||
1245 | |||
1246 | /* Type of security encryption: CCM or TKIP */ | ||
1247 | u8 sec_ctl; /* TX_CMD_SEC_* */ | ||
1248 | |||
1249 | /* | ||
1250 | * Index into rate table (see REPLY_TX_LINK_QUALITY_CMD) for initial | ||
1251 | * Tx attempt, if TX_CMD_FLG_STA_RATE_MSK is set. Normally "0" for | ||
1252 | * data frames, this field may be used to selectively reduce initial | ||
1253 | * rate (via non-0 value) for special frames (e.g. management), while | ||
1254 | * still supporting rate scaling for all frames. | ||
1255 | */ | ||
1256 | u8 initial_rate_index; | ||
1257 | u8 reserved; | ||
1258 | u8 key[16]; | ||
1259 | __le16 next_frame_flags; | ||
1260 | __le16 reserved2; | ||
1261 | union { | ||
1262 | __le32 life_time; | ||
1263 | __le32 attempt; | ||
1264 | } stop_time; | ||
1265 | |||
1266 | /* Host DRAM physical address pointer to "scratch" in this command. | ||
1267 | * Must be dword aligned. "0" in dram_lsb_ptr disables usage. */ | ||
1268 | __le32 dram_lsb_ptr; | ||
1269 | u8 dram_msb_ptr; | ||
1270 | |||
1271 | u8 rts_retry_limit; /*byte 50 */ | ||
1272 | u8 data_retry_limit; /*byte 51 */ | ||
1273 | u8 tid_tspec; | ||
1274 | union { | ||
1275 | __le16 pm_frame_timeout; | ||
1276 | __le16 attempt_duration; | ||
1277 | } timeout; | ||
1278 | |||
1279 | /* | ||
1280 | * Duration of EDCA burst Tx Opportunity, in 32-usec units. | ||
1281 | * Set this if txop time is not specified by HCCA protocol (e.g. by AP). | ||
1282 | */ | ||
1283 | __le16 driver_txop; | ||
1284 | |||
1285 | /* | ||
1286 | * MAC header goes here, followed by 2 bytes padding if MAC header | ||
1287 | * length is 26 or 30 bytes, followed by payload data | ||
1288 | */ | ||
1289 | u8 payload[0]; | ||
1290 | struct ieee80211_hdr hdr[0]; | ||
1291 | } __packed; | ||
1292 | |||
1293 | /* | ||
1294 | * TX command response is sent after *agn* transmission attempts. | ||
1295 | * | ||
1296 | * both postpone and abort status are expected behavior from uCode. there is | ||
1297 | * no special operation required from driver; except for RFKILL_FLUSH, | ||
1298 | * which required tx flush host command to flush all the tx frames in queues | ||
1299 | */ | ||
1300 | enum { | ||
1301 | TX_STATUS_SUCCESS = 0x01, | ||
1302 | TX_STATUS_DIRECT_DONE = 0x02, | ||
1303 | /* postpone TX */ | ||
1304 | TX_STATUS_POSTPONE_DELAY = 0x40, | ||
1305 | TX_STATUS_POSTPONE_FEW_BYTES = 0x41, | ||
1306 | TX_STATUS_POSTPONE_BT_PRIO = 0x42, | ||
1307 | TX_STATUS_POSTPONE_QUIET_PERIOD = 0x43, | ||
1308 | TX_STATUS_POSTPONE_CALC_TTAK = 0x44, | ||
1309 | /* abort TX */ | ||
1310 | TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY = 0x81, | ||
1311 | TX_STATUS_FAIL_SHORT_LIMIT = 0x82, | ||
1312 | TX_STATUS_FAIL_LONG_LIMIT = 0x83, | ||
1313 | TX_STATUS_FAIL_FIFO_UNDERRUN = 0x84, | ||
1314 | TX_STATUS_FAIL_DRAIN_FLOW = 0x85, | ||
1315 | TX_STATUS_FAIL_RFKILL_FLUSH = 0x86, | ||
1316 | TX_STATUS_FAIL_LIFE_EXPIRE = 0x87, | ||
1317 | TX_STATUS_FAIL_DEST_PS = 0x88, | ||
1318 | TX_STATUS_FAIL_HOST_ABORTED = 0x89, | ||
1319 | TX_STATUS_FAIL_BT_RETRY = 0x8a, | ||
1320 | TX_STATUS_FAIL_STA_INVALID = 0x8b, | ||
1321 | TX_STATUS_FAIL_FRAG_DROPPED = 0x8c, | ||
1322 | TX_STATUS_FAIL_TID_DISABLE = 0x8d, | ||
1323 | TX_STATUS_FAIL_FIFO_FLUSHED = 0x8e, | ||
1324 | TX_STATUS_FAIL_INSUFFICIENT_CF_POLL = 0x8f, | ||
1325 | TX_STATUS_FAIL_PASSIVE_NO_RX = 0x90, | ||
1326 | TX_STATUS_FAIL_NO_BEACON_ON_RADAR = 0x91, | ||
1327 | }; | ||
1328 | |||
1329 | #define TX_PACKET_MODE_REGULAR 0x0000 | ||
1330 | #define TX_PACKET_MODE_BURST_SEQ 0x0100 | ||
1331 | #define TX_PACKET_MODE_BURST_FIRST 0x0200 | ||
1332 | |||
1333 | enum { | ||
1334 | TX_POWER_PA_NOT_ACTIVE = 0x0, | ||
1335 | }; | ||
1336 | |||
1337 | enum { | ||
1338 | TX_STATUS_MSK = 0x000000ff, /* bits 0:7 */ | ||
1339 | TX_STATUS_DELAY_MSK = 0x00000040, | ||
1340 | TX_STATUS_ABORT_MSK = 0x00000080, | ||
1341 | TX_PACKET_MODE_MSK = 0x0000ff00, /* bits 8:15 */ | ||
1342 | TX_FIFO_NUMBER_MSK = 0x00070000, /* bits 16:18 */ | ||
1343 | TX_RESERVED = 0x00780000, /* bits 19:22 */ | ||
1344 | TX_POWER_PA_DETECT_MSK = 0x7f800000, /* bits 23:30 */ | ||
1345 | TX_ABORT_REQUIRED_MSK = 0x80000000, /* bits 31:31 */ | ||
1346 | }; | ||
1347 | |||
1348 | /* ******************************* | ||
1349 | * TX aggregation status | ||
1350 | ******************************* */ | ||
1351 | |||
1352 | enum { | ||
1353 | AGG_TX_STATE_TRANSMITTED = 0x00, | ||
1354 | AGG_TX_STATE_UNDERRUN_MSK = 0x01, | ||
1355 | AGG_TX_STATE_BT_PRIO_MSK = 0x02, | ||
1356 | AGG_TX_STATE_FEW_BYTES_MSK = 0x04, | ||
1357 | AGG_TX_STATE_ABORT_MSK = 0x08, | ||
1358 | AGG_TX_STATE_LAST_SENT_TTL_MSK = 0x10, | ||
1359 | AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK = 0x20, | ||
1360 | AGG_TX_STATE_LAST_SENT_BT_KILL_MSK = 0x40, | ||
1361 | AGG_TX_STATE_SCD_QUERY_MSK = 0x80, | ||
1362 | AGG_TX_STATE_TEST_BAD_CRC32_MSK = 0x100, | ||
1363 | AGG_TX_STATE_RESPONSE_MSK = 0x1ff, | ||
1364 | AGG_TX_STATE_DUMP_TX_MSK = 0x200, | ||
1365 | AGG_TX_STATE_DELAY_TX_MSK = 0x400 | ||
1366 | }; | ||
1367 | |||
1368 | #define AGG_TX_STATUS_MSK 0x00000fff /* bits 0:11 */ | ||
1369 | #define AGG_TX_TRY_MSK 0x0000f000 /* bits 12:15 */ | ||
1370 | |||
1371 | #define AGG_TX_STATE_LAST_SENT_MSK (AGG_TX_STATE_LAST_SENT_TTL_MSK | \ | ||
1372 | AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK | \ | ||
1373 | AGG_TX_STATE_LAST_SENT_BT_KILL_MSK) | ||
1374 | |||
1375 | /* # tx attempts for first frame in aggregation */ | ||
1376 | #define AGG_TX_STATE_TRY_CNT_POS 12 | ||
1377 | #define AGG_TX_STATE_TRY_CNT_MSK 0xf000 | ||
1378 | |||
1379 | /* Command ID and sequence number of Tx command for this frame */ | ||
1380 | #define AGG_TX_STATE_SEQ_NUM_POS 16 | ||
1381 | #define AGG_TX_STATE_SEQ_NUM_MSK 0xffff0000 | ||
1382 | |||
1383 | /* | ||
1384 | * REPLY_TX = 0x1c (response) | ||
1385 | * | ||
1386 | * This response may be in one of two slightly different formats, indicated | ||
1387 | * by the frame_count field: | ||
1388 | * | ||
1389 | * 1) No aggregation (frame_count == 1). This reports Tx results for | ||
1390 | * a single frame. Multiple attempts, at various bit rates, may have | ||
1391 | * been made for this frame. | ||
1392 | * | ||
1393 | * 2) Aggregation (frame_count > 1). This reports Tx results for | ||
1394 | * 2 or more frames that used block-acknowledge. All frames were | ||
1395 | * transmitted at same rate. Rate scaling may have been used if first | ||
1396 | * frame in this new agg block failed in previous agg block(s). | ||
1397 | * | ||
1398 | * Note that, for aggregation, ACK (block-ack) status is not delivered here; | ||
1399 | * block-ack has not been received by the time the agn device records | ||
1400 | * this status. | ||
1401 | * This status relates to reasons the tx might have been blocked or aborted | ||
1402 | * within the sending station (this agn device), rather than whether it was | ||
1403 | * received successfully by the destination station. | ||
1404 | */ | ||
1405 | struct agg_tx_status { | ||
1406 | __le16 status; | ||
1407 | __le16 sequence; | ||
1408 | } __packed; | ||
1409 | |||
1410 | /* | ||
1411 | * definitions for initial rate index field | ||
1412 | * bits [3:0] initial rate index | ||
1413 | * bits [6:4] rate table color, used for the initial rate | ||
1414 | * bit-7 invalid rate indication | ||
1415 | * i.e. rate was not chosen from rate table | ||
1416 | * or rate table color was changed during frame retries | ||
1417 | * refer tlc rate info | ||
1418 | */ | ||
1419 | |||
1420 | #define IWL50_TX_RES_INIT_RATE_INDEX_POS 0 | ||
1421 | #define IWL50_TX_RES_INIT_RATE_INDEX_MSK 0x0f | ||
1422 | #define IWL50_TX_RES_RATE_TABLE_COLOR_POS 4 | ||
1423 | #define IWL50_TX_RES_RATE_TABLE_COLOR_MSK 0x70 | ||
1424 | #define IWL50_TX_RES_INV_RATE_INDEX_MSK 0x80 | ||
1425 | |||
1426 | /* refer to ra_tid */ | ||
1427 | #define IWLAGN_TX_RES_TID_POS 0 | ||
1428 | #define IWLAGN_TX_RES_TID_MSK 0x0f | ||
1429 | #define IWLAGN_TX_RES_RA_POS 4 | ||
1430 | #define IWLAGN_TX_RES_RA_MSK 0xf0 | ||
1431 | |||
1432 | struct iwlagn_tx_resp { | ||
1433 | u8 frame_count; /* 1 no aggregation, >1 aggregation */ | ||
1434 | u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */ | ||
1435 | u8 failure_rts; /* # failures due to unsuccessful RTS */ | ||
1436 | u8 failure_frame; /* # failures due to no ACK (unused for agg) */ | ||
1437 | |||
1438 | /* For non-agg: Rate at which frame was successful. | ||
1439 | * For agg: Rate at which all frames were transmitted. */ | ||
1440 | __le32 rate_n_flags; /* RATE_MCS_* */ | ||
1441 | |||
1442 | /* For non-agg: RTS + CTS + frame tx attempts time + ACK. | ||
1443 | * For agg: RTS + CTS + aggregation tx time + block-ack time. */ | ||
1444 | __le16 wireless_media_time; /* uSecs */ | ||
1445 | |||
1446 | u8 pa_status; /* RF power amplifier measurement (not used) */ | ||
1447 | u8 pa_integ_res_a[3]; | ||
1448 | u8 pa_integ_res_b[3]; | ||
1449 | u8 pa_integ_res_C[3]; | ||
1450 | |||
1451 | __le32 tfd_info; | ||
1452 | __le16 seq_ctl; | ||
1453 | __le16 byte_cnt; | ||
1454 | u8 tlc_info; | ||
1455 | u8 ra_tid; /* tid (0:3), sta_id (4:7) */ | ||
1456 | __le16 frame_ctrl; | ||
1457 | /* | ||
1458 | * For non-agg: frame status TX_STATUS_* | ||
1459 | * For agg: status of 1st frame, AGG_TX_STATE_*; other frame status | ||
1460 | * fields follow this one, up to frame_count. | ||
1461 | * Bit fields: | ||
1462 | * 11- 0: AGG_TX_STATE_* status code | ||
1463 | * 15-12: Retry count for 1st frame in aggregation (retries | ||
1464 | * occur if tx failed for this frame when it was a | ||
1465 | * member of a previous aggregation block). If rate | ||
1466 | * scaling is used, retry count indicates the rate | ||
1467 | * table entry used for all frames in the new agg. | ||
1468 | * 31-16: Sequence # for this frame's Tx cmd (not SSN!) | ||
1469 | */ | ||
1470 | struct agg_tx_status status; /* TX status (in aggregation - | ||
1471 | * status of 1st frame) */ | ||
1472 | } __packed; | ||
1473 | /* | ||
1474 | * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command) | ||
1475 | * | ||
1476 | * Reports Block-Acknowledge from recipient station | ||
1477 | */ | ||
1478 | struct iwl_compressed_ba_resp { | ||
1479 | __le32 sta_addr_lo32; | ||
1480 | __le16 sta_addr_hi16; | ||
1481 | __le16 reserved; | ||
1482 | |||
1483 | /* Index of recipient (BA-sending) station in uCode's station table */ | ||
1484 | u8 sta_id; | ||
1485 | u8 tid; | ||
1486 | __le16 seq_ctl; | ||
1487 | __le64 bitmap; | ||
1488 | __le16 scd_flow; | ||
1489 | __le16 scd_ssn; | ||
1490 | u8 txed; /* number of frames sent */ | ||
1491 | u8 txed_2_done; /* number of frames acked */ | ||
1492 | } __packed; | ||
1493 | |||
1494 | /* | ||
1495 | * REPLY_TX_PWR_TABLE_CMD = 0x97 (command, has simple generic response) | ||
1496 | * | ||
1497 | */ | ||
1498 | |||
1499 | /*RS_NEW_API: only TLC_RTS remains and moved to bit 0 */ | ||
1500 | #define LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK (1 << 0) | ||
1501 | |||
1502 | /* # of EDCA prioritized tx fifos */ | ||
1503 | #define LINK_QUAL_AC_NUM AC_NUM | ||
1504 | |||
1505 | /* # entries in rate scale table to support Tx retries */ | ||
1506 | #define LINK_QUAL_MAX_RETRY_NUM 16 | ||
1507 | |||
1508 | /* Tx antenna selection values */ | ||
1509 | #define LINK_QUAL_ANT_A_MSK (1 << 0) | ||
1510 | #define LINK_QUAL_ANT_B_MSK (1 << 1) | ||
1511 | #define LINK_QUAL_ANT_MSK (LINK_QUAL_ANT_A_MSK|LINK_QUAL_ANT_B_MSK) | ||
1512 | |||
1513 | |||
1514 | /** | ||
1515 | * struct iwl_link_qual_general_params | ||
1516 | * | ||
1517 | * Used in REPLY_TX_LINK_QUALITY_CMD | ||
1518 | */ | ||
1519 | struct iwl_link_qual_general_params { | ||
1520 | u8 flags; | ||
1521 | |||
1522 | /* No entries at or above this (driver chosen) index contain MIMO */ | ||
1523 | u8 mimo_delimiter; | ||
1524 | |||
1525 | /* Best single antenna to use for single stream (legacy, SISO). */ | ||
1526 | u8 single_stream_ant_msk; /* LINK_QUAL_ANT_* */ | ||
1527 | |||
1528 | /* Best antennas to use for MIMO (unused for 4965, assumes both). */ | ||
1529 | u8 dual_stream_ant_msk; /* LINK_QUAL_ANT_* */ | ||
1530 | |||
1531 | /* | ||
1532 | * If driver needs to use different initial rates for different | ||
1533 | * EDCA QOS access categories (as implemented by tx fifos 0-3), | ||
1534 | * this table will set that up, by indicating the indexes in the | ||
1535 | * rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table at which to start. | ||
1536 | * Otherwise, driver should set all entries to 0. | ||
1537 | * | ||
1538 | * Entry usage: | ||
1539 | * 0 = Background, 1 = Best Effort (normal), 2 = Video, 3 = Voice | ||
1540 | * TX FIFOs above 3 use same value (typically 0) as TX FIFO 3. | ||
1541 | */ | ||
1542 | u8 start_rate_index[LINK_QUAL_AC_NUM]; | ||
1543 | } __packed; | ||
1544 | |||
1545 | #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) /* 4 milliseconds */ | ||
1546 | #define LINK_QUAL_AGG_TIME_LIMIT_MAX (8000) | ||
1547 | #define LINK_QUAL_AGG_TIME_LIMIT_MIN (100) | ||
1548 | |||
1549 | #define LINK_QUAL_AGG_DISABLE_START_DEF (3) | ||
1550 | #define LINK_QUAL_AGG_DISABLE_START_MAX (255) | ||
1551 | #define LINK_QUAL_AGG_DISABLE_START_MIN (0) | ||
1552 | |||
1553 | #define LINK_QUAL_AGG_FRAME_LIMIT_DEF (63) | ||
1554 | #define LINK_QUAL_AGG_FRAME_LIMIT_MAX (63) | ||
1555 | #define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0) | ||
1556 | |||
1557 | /** | ||
1558 | * struct iwl_link_qual_agg_params | ||
1559 | * | ||
1560 | * Used in REPLY_TX_LINK_QUALITY_CMD | ||
1561 | */ | ||
1562 | struct iwl_link_qual_agg_params { | ||
1563 | |||
1564 | /* | ||
1565 | *Maximum number of uSec in aggregation. | ||
1566 | * default set to 4000 (4 milliseconds) if not configured in .cfg | ||
1567 | */ | ||
1568 | __le16 agg_time_limit; | ||
1569 | |||
1570 | /* | ||
1571 | * Number of Tx retries allowed for a frame, before that frame will | ||
1572 | * no longer be considered for the start of an aggregation sequence | ||
1573 | * (scheduler will then try to tx it as single frame). | ||
1574 | * Driver should set this to 3. | ||
1575 | */ | ||
1576 | u8 agg_dis_start_th; | ||
1577 | |||
1578 | /* | ||
1579 | * Maximum number of frames in aggregation. | ||
1580 | * 0 = no limit (default). 1 = no aggregation. | ||
1581 | * Other values = max # frames in aggregation. | ||
1582 | */ | ||
1583 | u8 agg_frame_cnt_limit; | ||
1584 | |||
1585 | __le32 reserved; | ||
1586 | } __packed; | ||
1587 | |||
1588 | /* | ||
1589 | * REPLY_TX_LINK_QUALITY_CMD = 0x4e (command, has simple generic response) | ||
1590 | * | ||
1591 | * For agn devices | ||
1592 | * | ||
1593 | * Each station in the agn device's internal station table has its own table | ||
1594 | * of 16 | ||
1595 | * Tx rates and modulation modes (e.g. legacy/SISO/MIMO) for retrying Tx when | ||
1596 | * an ACK is not received. This command replaces the entire table for | ||
1597 | * one station. | ||
1598 | * | ||
1599 | * NOTE: Station must already be in agn device's station table. | ||
1600 | * Use REPLY_ADD_STA. | ||
1601 | * | ||
1602 | * The rate scaling procedures described below work well. Of course, other | ||
1603 | * procedures are possible, and may work better for particular environments. | ||
1604 | * | ||
1605 | * | ||
1606 | * FILLING THE RATE TABLE | ||
1607 | * | ||
1608 | * Given a particular initial rate and mode, as determined by the rate | ||
1609 | * scaling algorithm described below, the Linux driver uses the following | ||
1610 | * formula to fill the rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table in the | ||
1611 | * Link Quality command: | ||
1612 | * | ||
1613 | * | ||
1614 | * 1) If using High-throughput (HT) (SISO or MIMO) initial rate: | ||
1615 | * a) Use this same initial rate for first 3 entries. | ||
1616 | * b) Find next lower available rate using same mode (SISO or MIMO), | ||
1617 | * use for next 3 entries. If no lower rate available, switch to | ||
1618 | * legacy mode (no HT40 channel, no MIMO, no short guard interval). | ||
1619 | * c) If using MIMO, set command's mimo_delimiter to number of entries | ||
1620 | * using MIMO (3 or 6). | ||
1621 | * d) After trying 2 HT rates, switch to legacy mode (no HT40 channel, | ||
1622 | * no MIMO, no short guard interval), at the next lower bit rate | ||
1623 | * (e.g. if second HT bit rate was 54, try 48 legacy), and follow | ||
1624 | * legacy procedure for remaining table entries. | ||
1625 | * | ||
1626 | * 2) If using legacy initial rate: | ||
1627 | * a) Use the initial rate for only one entry. | ||
1628 | * b) For each following entry, reduce the rate to next lower available | ||
1629 | * rate, until reaching the lowest available rate. | ||
1630 | * c) When reducing rate, also switch antenna selection. | ||
1631 | * d) Once lowest available rate is reached, repeat this rate until | ||
1632 | * rate table is filled (16 entries), switching antenna each entry. | ||
1633 | * | ||
1634 | * | ||
1635 | * ACCUMULATING HISTORY | ||
1636 | * | ||
1637 | * The rate scaling algorithm for agn devices, as implemented in Linux driver, | ||
1638 | * uses two sets of frame Tx success history: One for the current/active | ||
1639 | * modulation mode, and one for a speculative/search mode that is being | ||
1640 | * attempted. If the speculative mode turns out to be more effective (i.e. | ||
1641 | * actual transfer rate is better), then the driver continues to use the | ||
1642 | * speculative mode as the new current active mode. | ||
1643 | * | ||
1644 | * Each history set contains, separately for each possible rate, data for a | ||
1645 | * sliding window of the 62 most recent tx attempts at that rate. The data | ||
1646 | * includes a shifting bitmap of success(1)/failure(0), and sums of successful | ||
1647 | * and attempted frames, from which the driver can additionally calculate a | ||
1648 | * success ratio (success / attempted) and number of failures | ||
1649 | * (attempted - success), and control the size of the window (attempted). | ||
1650 | * The driver uses the bit map to remove successes from the success sum, as | ||
1651 | * the oldest tx attempts fall out of the window. | ||
1652 | * | ||
1653 | * When the agn device makes multiple tx attempts for a given frame, each | ||
1654 | * attempt might be at a different rate, and have different modulation | ||
1655 | * characteristics (e.g. antenna, fat channel, short guard interval), as set | ||
1656 | * up in the rate scaling table in the Link Quality command. The driver must | ||
1657 | * determine which rate table entry was used for each tx attempt, to determine | ||
1658 | * which rate-specific history to update, and record only those attempts that | ||
1659 | * match the modulation characteristics of the history set. | ||
1660 | * | ||
1661 | * When using block-ack (aggregation), all frames are transmitted at the same | ||
1662 | * rate, since there is no per-attempt acknowledgment from the destination | ||
1663 | * station. The Tx response struct iwl_tx_resp indicates the Tx rate in | ||
1664 | * rate_n_flags field. After receiving a block-ack, the driver can update | ||
1665 | * history for the entire block all at once. | ||
1666 | * | ||
1667 | * | ||
1668 | * FINDING BEST STARTING RATE: | ||
1669 | * | ||
1670 | * When working with a selected initial modulation mode (see below), the | ||
1671 | * driver attempts to find a best initial rate. The initial rate is the | ||
1672 | * first entry in the Link Quality command's rate table. | ||
1673 | * | ||
1674 | * 1) Calculate actual throughput (success ratio * expected throughput, see | ||
1675 | * table below) for current initial rate. Do this only if enough frames | ||
1676 | * have been attempted to make the value meaningful: at least 6 failed | ||
1677 | * tx attempts, or at least 8 successes. If not enough, don't try rate | ||
1678 | * scaling yet. | ||
1679 | * | ||
1680 | * 2) Find available rates adjacent to current initial rate. Available means: | ||
1681 | * a) supported by hardware && | ||
1682 | * b) supported by association && | ||
1683 | * c) within any constraints selected by user | ||
1684 | * | ||
1685 | * 3) Gather measured throughputs for adjacent rates. These might not have | ||
1686 | * enough history to calculate a throughput. That's okay, we might try | ||
1687 | * using one of them anyway! | ||
1688 | * | ||
1689 | * 4) Try decreasing rate if, for current rate: | ||
1690 | * a) success ratio is < 15% || | ||
1691 | * b) lower adjacent rate has better measured throughput || | ||
1692 | * c) higher adjacent rate has worse throughput, and lower is unmeasured | ||
1693 | * | ||
1694 | * As a sanity check, if decrease was determined above, leave rate | ||
1695 | * unchanged if: | ||
1696 | * a) lower rate unavailable | ||
1697 | * b) success ratio at current rate > 85% (very good) | ||
1698 | * c) current measured throughput is better than expected throughput | ||
1699 | * of lower rate (under perfect 100% tx conditions, see table below) | ||
1700 | * | ||
1701 | * 5) Try increasing rate if, for current rate: | ||
1702 | * a) success ratio is < 15% || | ||
1703 | * b) both adjacent rates' throughputs are unmeasured (try it!) || | ||
1704 | * b) higher adjacent rate has better measured throughput || | ||
1705 | * c) lower adjacent rate has worse throughput, and higher is unmeasured | ||
1706 | * | ||
1707 | * As a sanity check, if increase was determined above, leave rate | ||
1708 | * unchanged if: | ||
1709 | * a) success ratio at current rate < 70%. This is not particularly | ||
1710 | * good performance; higher rate is sure to have poorer success. | ||
1711 | * | ||
1712 | * 6) Re-evaluate the rate after each tx frame. If working with block- | ||
1713 | * acknowledge, history and statistics may be calculated for the entire | ||
1714 | * block (including prior history that fits within the history windows), | ||
1715 | * before re-evaluation. | ||
1716 | * | ||
1717 | * FINDING BEST STARTING MODULATION MODE: | ||
1718 | * | ||
1719 | * After working with a modulation mode for a "while" (and doing rate scaling), | ||
1720 | * the driver searches for a new initial mode in an attempt to improve | ||
1721 | * throughput. The "while" is measured by numbers of attempted frames: | ||
1722 | * | ||
1723 | * For legacy mode, search for new mode after: | ||
1724 | * 480 successful frames, or 160 failed frames | ||
1725 | * For high-throughput modes (SISO or MIMO), search for new mode after: | ||
1726 | * 4500 successful frames, or 400 failed frames | ||
1727 | * | ||
1728 | * Mode switch possibilities are (3 for each mode): | ||
1729 | * | ||
1730 | * For legacy: | ||
1731 | * Change antenna, try SISO (if HT association), try MIMO (if HT association) | ||
1732 | * For SISO: | ||
1733 | * Change antenna, try MIMO, try shortened guard interval (SGI) | ||
1734 | * For MIMO: | ||
1735 | * Try SISO antenna A, SISO antenna B, try shortened guard interval (SGI) | ||
1736 | * | ||
1737 | * When trying a new mode, use the same bit rate as the old/current mode when | ||
1738 | * trying antenna switches and shortened guard interval. When switching to | ||
1739 | * SISO from MIMO or legacy, or to MIMO from SISO or legacy, use a rate | ||
1740 | * for which the expected throughput (under perfect conditions) is about the | ||
1741 | * same or slightly better than the actual measured throughput delivered by | ||
1742 | * the old/current mode. | ||
1743 | * | ||
1744 | * Actual throughput can be estimated by multiplying the expected throughput | ||
1745 | * by the success ratio (successful / attempted tx frames). Frame size is | ||
1746 | * not considered in this calculation; it assumes that frame size will average | ||
1747 | * out to be fairly consistent over several samples. The following are | ||
1748 | * metric values for expected throughput assuming 100% success ratio. | ||
1749 | * Only G band has support for CCK rates: | ||
1750 | * | ||
1751 | * RATE: 1 2 5 11 6 9 12 18 24 36 48 54 60 | ||
1752 | * | ||
1753 | * G: 7 13 35 58 40 57 72 98 121 154 177 186 186 | ||
1754 | * A: 0 0 0 0 40 57 72 98 121 154 177 186 186 | ||
1755 | * SISO 20MHz: 0 0 0 0 42 42 76 102 124 159 183 193 202 | ||
1756 | * SGI SISO 20MHz: 0 0 0 0 46 46 82 110 132 168 192 202 211 | ||
1757 | * MIMO 20MHz: 0 0 0 0 74 74 123 155 179 214 236 244 251 | ||
1758 | * SGI MIMO 20MHz: 0 0 0 0 81 81 131 164 188 222 243 251 257 | ||
1759 | * SISO 40MHz: 0 0 0 0 77 77 127 160 184 220 242 250 257 | ||
1760 | * SGI SISO 40MHz: 0 0 0 0 83 83 135 169 193 229 250 257 264 | ||
1761 | * MIMO 40MHz: 0 0 0 0 123 123 182 214 235 264 279 285 289 | ||
1762 | * SGI MIMO 40MHz: 0 0 0 0 131 131 191 222 242 270 284 289 293 | ||
1763 | * | ||
1764 | * After the new mode has been tried for a short while (minimum of 6 failed | ||
1765 | * frames or 8 successful frames), compare success ratio and actual throughput | ||
1766 | * estimate of the new mode with the old. If either is better with the new | ||
1767 | * mode, continue to use the new mode. | ||
1768 | * | ||
1769 | * Continue comparing modes until all 3 possibilities have been tried. | ||
1770 | * If moving from legacy to HT, try all 3 possibilities from the new HT | ||
1771 | * mode. After trying all 3, a best mode is found. Continue to use this mode | ||
1772 | * for the longer "while" described above (e.g. 480 successful frames for | ||
1773 | * legacy), and then repeat the search process. | ||
1774 | * | ||
1775 | */ | ||
1776 | struct iwl_link_quality_cmd { | ||
1777 | |||
1778 | /* Index of destination/recipient station in uCode's station table */ | ||
1779 | u8 sta_id; | ||
1780 | u8 reserved1; | ||
1781 | __le16 control; /* not used */ | ||
1782 | struct iwl_link_qual_general_params general_params; | ||
1783 | struct iwl_link_qual_agg_params agg_params; | ||
1784 | |||
1785 | /* | ||
1786 | * Rate info; when using rate-scaling, Tx command's initial_rate_index | ||
1787 | * specifies 1st Tx rate attempted, via index into this table. | ||
1788 | * agn devices works its way through table when retrying Tx. | ||
1789 | */ | ||
1790 | struct { | ||
1791 | __le32 rate_n_flags; /* RATE_MCS_*, IWL_RATE_* */ | ||
1792 | } rs_table[LINK_QUAL_MAX_RETRY_NUM]; | ||
1793 | __le32 reserved2; | ||
1794 | } __packed; | ||
1795 | |||
1796 | /* | ||
1797 | * BT configuration enable flags: | ||
1798 | * bit 0 - 1: BT channel announcement enabled | ||
1799 | * 0: disable | ||
1800 | * bit 1 - 1: priority of BT device enabled | ||
1801 | * 0: disable | ||
1802 | * bit 2 - 1: BT 2 wire support enabled | ||
1803 | * 0: disable | ||
1804 | */ | ||
1805 | #define BT_COEX_DISABLE (0x0) | ||
1806 | #define BT_ENABLE_CHANNEL_ANNOUNCE BIT(0) | ||
1807 | #define BT_ENABLE_PRIORITY BIT(1) | ||
1808 | #define BT_ENABLE_2_WIRE BIT(2) | ||
1809 | |||
1810 | #define BT_COEX_DISABLE (0x0) | ||
1811 | #define BT_COEX_ENABLE (BT_ENABLE_CHANNEL_ANNOUNCE | BT_ENABLE_PRIORITY) | ||
1812 | |||
1813 | #define BT_LEAD_TIME_MIN (0x0) | ||
1814 | #define BT_LEAD_TIME_DEF (0x1E) | ||
1815 | #define BT_LEAD_TIME_MAX (0xFF) | ||
1816 | |||
1817 | #define BT_MAX_KILL_MIN (0x1) | ||
1818 | #define BT_MAX_KILL_DEF (0x5) | ||
1819 | #define BT_MAX_KILL_MAX (0xFF) | ||
1820 | |||
1821 | #define BT_DURATION_LIMIT_DEF 625 | ||
1822 | #define BT_DURATION_LIMIT_MAX 1250 | ||
1823 | #define BT_DURATION_LIMIT_MIN 625 | ||
1824 | |||
1825 | #define BT_ON_THRESHOLD_DEF 4 | ||
1826 | #define BT_ON_THRESHOLD_MAX 1000 | ||
1827 | #define BT_ON_THRESHOLD_MIN 1 | ||
1828 | |||
1829 | #define BT_FRAG_THRESHOLD_DEF 0 | ||
1830 | #define BT_FRAG_THRESHOLD_MAX 0 | ||
1831 | #define BT_FRAG_THRESHOLD_MIN 0 | ||
1832 | |||
1833 | #define BT_AGG_THRESHOLD_DEF 1200 | ||
1834 | #define BT_AGG_THRESHOLD_MAX 8000 | ||
1835 | #define BT_AGG_THRESHOLD_MIN 400 | ||
1836 | |||
1837 | /* | ||
1838 | * REPLY_BT_CONFIG = 0x9b (command, has simple generic response) | ||
1839 | * | ||
1840 | * agn devices support hardware handshake with Bluetooth device on | ||
1841 | * same platform. Bluetooth device alerts wireless device when it will Tx; | ||
1842 | * wireless device can delay or kill its own Tx to accommodate. | ||
1843 | */ | ||
1844 | struct iwl_bt_cmd { | ||
1845 | u8 flags; | ||
1846 | u8 lead_time; | ||
1847 | u8 max_kill; | ||
1848 | u8 reserved; | ||
1849 | __le32 kill_ack_mask; | ||
1850 | __le32 kill_cts_mask; | ||
1851 | } __packed; | ||
1852 | |||
1853 | #define IWLAGN_BT_FLAG_CHANNEL_INHIBITION BIT(0) | ||
1854 | |||
1855 | #define IWLAGN_BT_FLAG_COEX_MODE_MASK (BIT(3)|BIT(4)|BIT(5)) | ||
1856 | #define IWLAGN_BT_FLAG_COEX_MODE_SHIFT 3 | ||
1857 | #define IWLAGN_BT_FLAG_COEX_MODE_DISABLED 0 | ||
1858 | #define IWLAGN_BT_FLAG_COEX_MODE_LEGACY_2W 1 | ||
1859 | #define IWLAGN_BT_FLAG_COEX_MODE_3W 2 | ||
1860 | #define IWLAGN_BT_FLAG_COEX_MODE_4W 3 | ||
1861 | |||
1862 | #define IWLAGN_BT_FLAG_UCODE_DEFAULT BIT(6) | ||
1863 | /* Disable Sync PSPoll on SCO/eSCO */ | ||
1864 | #define IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE BIT(7) | ||
1865 | |||
1866 | #define IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD -75 /* dBm */ | ||
1867 | #define IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD -65 /* dBm */ | ||
1868 | |||
1869 | #define IWLAGN_BT_PRIO_BOOST_MAX 0xFF | ||
1870 | #define IWLAGN_BT_PRIO_BOOST_MIN 0x00 | ||
1871 | #define IWLAGN_BT_PRIO_BOOST_DEFAULT 0xF0 | ||
1872 | |||
1873 | #define IWLAGN_BT_MAX_KILL_DEFAULT 5 | ||
1874 | |||
1875 | #define IWLAGN_BT3_T7_DEFAULT 1 | ||
1876 | |||
1877 | enum iwl_bt_kill_idx { | ||
1878 | IWL_BT_KILL_DEFAULT = 0, | ||
1879 | IWL_BT_KILL_OVERRIDE = 1, | ||
1880 | IWL_BT_KILL_REDUCE = 2, | ||
1881 | }; | ||
1882 | |||
1883 | #define IWLAGN_BT_KILL_ACK_MASK_DEFAULT cpu_to_le32(0xffff0000) | ||
1884 | #define IWLAGN_BT_KILL_CTS_MASK_DEFAULT cpu_to_le32(0xffff0000) | ||
1885 | #define IWLAGN_BT_KILL_ACK_CTS_MASK_SCO cpu_to_le32(0xffffffff) | ||
1886 | #define IWLAGN_BT_KILL_ACK_CTS_MASK_REDUCE cpu_to_le32(0) | ||
1887 | |||
1888 | #define IWLAGN_BT3_PRIO_SAMPLE_DEFAULT 2 | ||
1889 | |||
1890 | #define IWLAGN_BT3_T2_DEFAULT 0xc | ||
1891 | |||
1892 | #define IWLAGN_BT_VALID_ENABLE_FLAGS cpu_to_le16(BIT(0)) | ||
1893 | #define IWLAGN_BT_VALID_BOOST cpu_to_le16(BIT(1)) | ||
1894 | #define IWLAGN_BT_VALID_MAX_KILL cpu_to_le16(BIT(2)) | ||
1895 | #define IWLAGN_BT_VALID_3W_TIMERS cpu_to_le16(BIT(3)) | ||
1896 | #define IWLAGN_BT_VALID_KILL_ACK_MASK cpu_to_le16(BIT(4)) | ||
1897 | #define IWLAGN_BT_VALID_KILL_CTS_MASK cpu_to_le16(BIT(5)) | ||
1898 | #define IWLAGN_BT_VALID_REDUCED_TX_PWR cpu_to_le16(BIT(6)) | ||
1899 | #define IWLAGN_BT_VALID_3W_LUT cpu_to_le16(BIT(7)) | ||
1900 | |||
1901 | #define IWLAGN_BT_ALL_VALID_MSK (IWLAGN_BT_VALID_ENABLE_FLAGS | \ | ||
1902 | IWLAGN_BT_VALID_BOOST | \ | ||
1903 | IWLAGN_BT_VALID_MAX_KILL | \ | ||
1904 | IWLAGN_BT_VALID_3W_TIMERS | \ | ||
1905 | IWLAGN_BT_VALID_KILL_ACK_MASK | \ | ||
1906 | IWLAGN_BT_VALID_KILL_CTS_MASK | \ | ||
1907 | IWLAGN_BT_VALID_REDUCED_TX_PWR | \ | ||
1908 | IWLAGN_BT_VALID_3W_LUT) | ||
1909 | |||
1910 | #define IWLAGN_BT_REDUCED_TX_PWR BIT(0) | ||
1911 | |||
1912 | #define IWLAGN_BT_DECISION_LUT_SIZE 12 | ||
1913 | |||
1914 | struct iwl_basic_bt_cmd { | ||
1915 | u8 flags; | ||
1916 | u8 ledtime; /* unused */ | ||
1917 | u8 max_kill; | ||
1918 | u8 bt3_timer_t7_value; | ||
1919 | __le32 kill_ack_mask; | ||
1920 | __le32 kill_cts_mask; | ||
1921 | u8 bt3_prio_sample_time; | ||
1922 | u8 bt3_timer_t2_value; | ||
1923 | __le16 bt4_reaction_time; /* unused */ | ||
1924 | __le32 bt3_lookup_table[IWLAGN_BT_DECISION_LUT_SIZE]; | ||
1925 | /* | ||
1926 | * bit 0: use reduced tx power for control frame | ||
1927 | * bit 1 - 7: reserved | ||
1928 | */ | ||
1929 | u8 reduce_txpower; | ||
1930 | u8 reserved; | ||
1931 | __le16 valid; | ||
1932 | }; | ||
1933 | |||
1934 | struct iwl_bt_cmd_v1 { | ||
1935 | struct iwl_basic_bt_cmd basic; | ||
1936 | u8 prio_boost; | ||
1937 | /* | ||
1938 | * set IWLAGN_BT_VALID_BOOST to "1" in "valid" bitmask | ||
1939 | * if configure the following patterns | ||
1940 | */ | ||
1941 | u8 tx_prio_boost; /* SW boost of WiFi tx priority */ | ||
1942 | __le16 rx_prio_boost; /* SW boost of WiFi rx priority */ | ||
1943 | }; | ||
1944 | |||
1945 | struct iwl_bt_cmd_v2 { | ||
1946 | struct iwl_basic_bt_cmd basic; | ||
1947 | __le32 prio_boost; | ||
1948 | /* | ||
1949 | * set IWLAGN_BT_VALID_BOOST to "1" in "valid" bitmask | ||
1950 | * if configure the following patterns | ||
1951 | */ | ||
1952 | u8 reserved; | ||
1953 | u8 tx_prio_boost; /* SW boost of WiFi tx priority */ | ||
1954 | __le16 rx_prio_boost; /* SW boost of WiFi rx priority */ | ||
1955 | }; | ||
1956 | |||
1957 | #define IWLAGN_BT_SCO_ACTIVE cpu_to_le32(BIT(0)) | ||
1958 | |||
1959 | struct iwlagn_bt_sco_cmd { | ||
1960 | __le32 flags; | ||
1961 | }; | ||
1962 | |||
1963 | /****************************************************************************** | ||
1964 | * (6) | ||
1965 | * Spectrum Management (802.11h) Commands, Responses, Notifications: | ||
1966 | * | ||
1967 | *****************************************************************************/ | ||
1968 | |||
1969 | /* | ||
1970 | * Spectrum Management | ||
1971 | */ | ||
1972 | #define MEASUREMENT_FILTER_FLAG (RXON_FILTER_PROMISC_MSK | \ | ||
1973 | RXON_FILTER_CTL2HOST_MSK | \ | ||
1974 | RXON_FILTER_ACCEPT_GRP_MSK | \ | ||
1975 | RXON_FILTER_DIS_DECRYPT_MSK | \ | ||
1976 | RXON_FILTER_DIS_GRP_DECRYPT_MSK | \ | ||
1977 | RXON_FILTER_ASSOC_MSK | \ | ||
1978 | RXON_FILTER_BCON_AWARE_MSK) | ||
1979 | |||
1980 | struct iwl_measure_channel { | ||
1981 | __le32 duration; /* measurement duration in extended beacon | ||
1982 | * format */ | ||
1983 | u8 channel; /* channel to measure */ | ||
1984 | u8 type; /* see enum iwl_measure_type */ | ||
1985 | __le16 reserved; | ||
1986 | } __packed; | ||
1987 | |||
1988 | /* | ||
1989 | * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (command) | ||
1990 | */ | ||
1991 | struct iwl_spectrum_cmd { | ||
1992 | __le16 len; /* number of bytes starting from token */ | ||
1993 | u8 token; /* token id */ | ||
1994 | u8 id; /* measurement id -- 0 or 1 */ | ||
1995 | u8 origin; /* 0 = TGh, 1 = other, 2 = TGk */ | ||
1996 | u8 periodic; /* 1 = periodic */ | ||
1997 | __le16 path_loss_timeout; | ||
1998 | __le32 start_time; /* start time in extended beacon format */ | ||
1999 | __le32 reserved2; | ||
2000 | __le32 flags; /* rxon flags */ | ||
2001 | __le32 filter_flags; /* rxon filter flags */ | ||
2002 | __le16 channel_count; /* minimum 1, maximum 10 */ | ||
2003 | __le16 reserved3; | ||
2004 | struct iwl_measure_channel channels[10]; | ||
2005 | } __packed; | ||
2006 | |||
2007 | /* | ||
2008 | * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (response) | ||
2009 | */ | ||
2010 | struct iwl_spectrum_resp { | ||
2011 | u8 token; | ||
2012 | u8 id; /* id of the prior command replaced, or 0xff */ | ||
2013 | __le16 status; /* 0 - command will be handled | ||
2014 | * 1 - cannot handle (conflicts with another | ||
2015 | * measurement) */ | ||
2016 | } __packed; | ||
2017 | |||
2018 | enum iwl_measurement_state { | ||
2019 | IWL_MEASUREMENT_START = 0, | ||
2020 | IWL_MEASUREMENT_STOP = 1, | ||
2021 | }; | ||
2022 | |||
2023 | enum iwl_measurement_status { | ||
2024 | IWL_MEASUREMENT_OK = 0, | ||
2025 | IWL_MEASUREMENT_CONCURRENT = 1, | ||
2026 | IWL_MEASUREMENT_CSA_CONFLICT = 2, | ||
2027 | IWL_MEASUREMENT_TGH_CONFLICT = 3, | ||
2028 | /* 4-5 reserved */ | ||
2029 | IWL_MEASUREMENT_STOPPED = 6, | ||
2030 | IWL_MEASUREMENT_TIMEOUT = 7, | ||
2031 | IWL_MEASUREMENT_PERIODIC_FAILED = 8, | ||
2032 | }; | ||
2033 | |||
2034 | #define NUM_ELEMENTS_IN_HISTOGRAM 8 | ||
2035 | |||
2036 | struct iwl_measurement_histogram { | ||
2037 | __le32 ofdm[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 0.8usec counts */ | ||
2038 | __le32 cck[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 1usec counts */ | ||
2039 | } __packed; | ||
2040 | |||
2041 | /* clear channel availability counters */ | ||
2042 | struct iwl_measurement_cca_counters { | ||
2043 | __le32 ofdm; | ||
2044 | __le32 cck; | ||
2045 | } __packed; | ||
2046 | |||
2047 | enum iwl_measure_type { | ||
2048 | IWL_MEASURE_BASIC = (1 << 0), | ||
2049 | IWL_MEASURE_CHANNEL_LOAD = (1 << 1), | ||
2050 | IWL_MEASURE_HISTOGRAM_RPI = (1 << 2), | ||
2051 | IWL_MEASURE_HISTOGRAM_NOISE = (1 << 3), | ||
2052 | IWL_MEASURE_FRAME = (1 << 4), | ||
2053 | /* bits 5:6 are reserved */ | ||
2054 | IWL_MEASURE_IDLE = (1 << 7), | ||
2055 | }; | ||
2056 | |||
2057 | /* | ||
2058 | * SPECTRUM_MEASURE_NOTIFICATION = 0x75 (notification only, not a command) | ||
2059 | */ | ||
2060 | struct iwl_spectrum_notification { | ||
2061 | u8 id; /* measurement id -- 0 or 1 */ | ||
2062 | u8 token; | ||
2063 | u8 channel_index; /* index in measurement channel list */ | ||
2064 | u8 state; /* 0 - start, 1 - stop */ | ||
2065 | __le32 start_time; /* lower 32-bits of TSF */ | ||
2066 | u8 band; /* 0 - 5.2GHz, 1 - 2.4GHz */ | ||
2067 | u8 channel; | ||
2068 | u8 type; /* see enum iwl_measurement_type */ | ||
2069 | u8 reserved1; | ||
2070 | /* NOTE: cca_ofdm, cca_cck, basic_type, and histogram are only only | ||
2071 | * valid if applicable for measurement type requested. */ | ||
2072 | __le32 cca_ofdm; /* cca fraction time in 40Mhz clock periods */ | ||
2073 | __le32 cca_cck; /* cca fraction time in 44Mhz clock periods */ | ||
2074 | __le32 cca_time; /* channel load time in usecs */ | ||
2075 | u8 basic_type; /* 0 - bss, 1 - ofdm preamble, 2 - | ||
2076 | * unidentified */ | ||
2077 | u8 reserved2[3]; | ||
2078 | struct iwl_measurement_histogram histogram; | ||
2079 | __le32 stop_time; /* lower 32-bits of TSF */ | ||
2080 | __le32 status; /* see iwl_measurement_status */ | ||
2081 | } __packed; | ||
2082 | |||
2083 | /****************************************************************************** | ||
2084 | * (7) | ||
2085 | * Power Management Commands, Responses, Notifications: | ||
2086 | * | ||
2087 | *****************************************************************************/ | ||
2088 | |||
2089 | /** | ||
2090 | * struct iwl_powertable_cmd - Power Table Command | ||
2091 | * @flags: See below: | ||
2092 | * | ||
2093 | * POWER_TABLE_CMD = 0x77 (command, has simple generic response) | ||
2094 | * | ||
2095 | * PM allow: | ||
2096 | * bit 0 - '0' Driver not allow power management | ||
2097 | * '1' Driver allow PM (use rest of parameters) | ||
2098 | * | ||
2099 | * uCode send sleep notifications: | ||
2100 | * bit 1 - '0' Don't send sleep notification | ||
2101 | * '1' send sleep notification (SEND_PM_NOTIFICATION) | ||
2102 | * | ||
2103 | * Sleep over DTIM | ||
2104 | * bit 2 - '0' PM have to walk up every DTIM | ||
2105 | * '1' PM could sleep over DTIM till listen Interval. | ||
2106 | * | ||
2107 | * PCI power managed | ||
2108 | * bit 3 - '0' (PCI_CFG_LINK_CTRL & 0x1) | ||
2109 | * '1' !(PCI_CFG_LINK_CTRL & 0x1) | ||
2110 | * | ||
2111 | * Fast PD | ||
2112 | * bit 4 - '1' Put radio to sleep when receiving frame for others | ||
2113 | * | ||
2114 | * Force sleep Modes | ||
2115 | * bit 31/30- '00' use both mac/xtal sleeps | ||
2116 | * '01' force Mac sleep | ||
2117 | * '10' force xtal sleep | ||
2118 | * '11' Illegal set | ||
2119 | * | ||
2120 | * NOTE: if sleep_interval[SLEEP_INTRVL_TABLE_SIZE-1] > DTIM period then | ||
2121 | * ucode assume sleep over DTIM is allowed and we don't need to wake up | ||
2122 | * for every DTIM. | ||
2123 | */ | ||
2124 | #define IWL_POWER_VEC_SIZE 5 | ||
2125 | |||
2126 | #define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK cpu_to_le16(BIT(0)) | ||
2127 | #define IWL_POWER_POWER_SAVE_ENA_MSK cpu_to_le16(BIT(0)) | ||
2128 | #define IWL_POWER_POWER_MANAGEMENT_ENA_MSK cpu_to_le16(BIT(1)) | ||
2129 | #define IWL_POWER_SLEEP_OVER_DTIM_MSK cpu_to_le16(BIT(2)) | ||
2130 | #define IWL_POWER_PCI_PM_MSK cpu_to_le16(BIT(3)) | ||
2131 | #define IWL_POWER_FAST_PD cpu_to_le16(BIT(4)) | ||
2132 | #define IWL_POWER_BEACON_FILTERING cpu_to_le16(BIT(5)) | ||
2133 | #define IWL_POWER_SHADOW_REG_ENA cpu_to_le16(BIT(6)) | ||
2134 | #define IWL_POWER_CT_KILL_SET cpu_to_le16(BIT(7)) | ||
2135 | #define IWL_POWER_BT_SCO_ENA cpu_to_le16(BIT(8)) | ||
2136 | #define IWL_POWER_ADVANCE_PM_ENA_MSK cpu_to_le16(BIT(9)) | ||
2137 | |||
2138 | struct iwl_powertable_cmd { | ||
2139 | __le16 flags; | ||
2140 | u8 keep_alive_seconds; | ||
2141 | u8 debug_flags; | ||
2142 | __le32 rx_data_timeout; | ||
2143 | __le32 tx_data_timeout; | ||
2144 | __le32 sleep_interval[IWL_POWER_VEC_SIZE]; | ||
2145 | __le32 keep_alive_beacons; | ||
2146 | } __packed; | ||
2147 | |||
2148 | /* | ||
2149 | * PM_SLEEP_NOTIFICATION = 0x7A (notification only, not a command) | ||
2150 | * all devices identical. | ||
2151 | */ | ||
2152 | struct iwl_sleep_notification { | ||
2153 | u8 pm_sleep_mode; | ||
2154 | u8 pm_wakeup_src; | ||
2155 | __le16 reserved; | ||
2156 | __le32 sleep_time; | ||
2157 | __le32 tsf_low; | ||
2158 | __le32 bcon_timer; | ||
2159 | } __packed; | ||
2160 | |||
2161 | /* Sleep states. all devices identical. */ | ||
2162 | enum { | ||
2163 | IWL_PM_NO_SLEEP = 0, | ||
2164 | IWL_PM_SLP_MAC = 1, | ||
2165 | IWL_PM_SLP_FULL_MAC_UNASSOCIATE = 2, | ||
2166 | IWL_PM_SLP_FULL_MAC_CARD_STATE = 3, | ||
2167 | IWL_PM_SLP_PHY = 4, | ||
2168 | IWL_PM_SLP_REPENT = 5, | ||
2169 | IWL_PM_WAKEUP_BY_TIMER = 6, | ||
2170 | IWL_PM_WAKEUP_BY_DRIVER = 7, | ||
2171 | IWL_PM_WAKEUP_BY_RFKILL = 8, | ||
2172 | /* 3 reserved */ | ||
2173 | IWL_PM_NUM_OF_MODES = 12, | ||
2174 | }; | ||
2175 | |||
2176 | /* | ||
2177 | * REPLY_CARD_STATE_CMD = 0xa0 (command, has simple generic response) | ||
2178 | */ | ||
2179 | #define CARD_STATE_CMD_DISABLE 0x00 /* Put card to sleep */ | ||
2180 | #define CARD_STATE_CMD_ENABLE 0x01 /* Wake up card */ | ||
2181 | #define CARD_STATE_CMD_HALT 0x02 /* Power down permanently */ | ||
2182 | struct iwl_card_state_cmd { | ||
2183 | __le32 status; /* CARD_STATE_CMD_* request new power state */ | ||
2184 | } __packed; | ||
2185 | |||
2186 | /* | ||
2187 | * CARD_STATE_NOTIFICATION = 0xa1 (notification only, not a command) | ||
2188 | */ | ||
2189 | struct iwl_card_state_notif { | ||
2190 | __le32 flags; | ||
2191 | } __packed; | ||
2192 | |||
2193 | #define HW_CARD_DISABLED 0x01 | ||
2194 | #define SW_CARD_DISABLED 0x02 | ||
2195 | #define CT_CARD_DISABLED 0x04 | ||
2196 | #define RXON_CARD_DISABLED 0x10 | ||
2197 | |||
2198 | struct iwl_ct_kill_config { | ||
2199 | __le32 reserved; | ||
2200 | __le32 critical_temperature_M; | ||
2201 | __le32 critical_temperature_R; | ||
2202 | } __packed; | ||
2203 | |||
2204 | /* 1000, and 6x00 */ | ||
2205 | struct iwl_ct_kill_throttling_config { | ||
2206 | __le32 critical_temperature_exit; | ||
2207 | __le32 reserved; | ||
2208 | __le32 critical_temperature_enter; | ||
2209 | } __packed; | ||
2210 | |||
2211 | /****************************************************************************** | ||
2212 | * (8) | ||
2213 | * Scan Commands, Responses, Notifications: | ||
2214 | * | ||
2215 | *****************************************************************************/ | ||
2216 | |||
2217 | #define SCAN_CHANNEL_TYPE_PASSIVE cpu_to_le32(0) | ||
2218 | #define SCAN_CHANNEL_TYPE_ACTIVE cpu_to_le32(1) | ||
2219 | |||
2220 | /** | ||
2221 | * struct iwl_scan_channel - entry in REPLY_SCAN_CMD channel table | ||
2222 | * | ||
2223 | * One for each channel in the scan list. | ||
2224 | * Each channel can independently select: | ||
2225 | * 1) SSID for directed active scans | ||
2226 | * 2) Txpower setting (for rate specified within Tx command) | ||
2227 | * 3) How long to stay on-channel (behavior may be modified by quiet_time, | ||
2228 | * quiet_plcp_th, good_CRC_th) | ||
2229 | * | ||
2230 | * To avoid uCode errors, make sure the following are true (see comments | ||
2231 | * under struct iwl_scan_cmd about max_out_time and quiet_time): | ||
2232 | * 1) If using passive_dwell (i.e. passive_dwell != 0): | ||
2233 | * active_dwell <= passive_dwell (< max_out_time if max_out_time != 0) | ||
2234 | * 2) quiet_time <= active_dwell | ||
2235 | * 3) If restricting off-channel time (i.e. max_out_time !=0): | ||
2236 | * passive_dwell < max_out_time | ||
2237 | * active_dwell < max_out_time | ||
2238 | */ | ||
2239 | |||
2240 | struct iwl_scan_channel { | ||
2241 | /* | ||
2242 | * type is defined as: | ||
2243 | * 0:0 1 = active, 0 = passive | ||
2244 | * 1:20 SSID direct bit map; if a bit is set, then corresponding | ||
2245 | * SSID IE is transmitted in probe request. | ||
2246 | * 21:31 reserved | ||
2247 | */ | ||
2248 | __le32 type; | ||
2249 | __le16 channel; /* band is selected by iwl_scan_cmd "flags" field */ | ||
2250 | u8 tx_gain; /* gain for analog radio */ | ||
2251 | u8 dsp_atten; /* gain for DSP */ | ||
2252 | __le16 active_dwell; /* in 1024-uSec TU (time units), typ 5-50 */ | ||
2253 | __le16 passive_dwell; /* in 1024-uSec TU (time units), typ 20-500 */ | ||
2254 | } __packed; | ||
2255 | |||
2256 | /* set number of direct probes __le32 type */ | ||
2257 | #define IWL_SCAN_PROBE_MASK(n) cpu_to_le32((BIT(n) | (BIT(n) - BIT(1)))) | ||
2258 | |||
2259 | /** | ||
2260 | * struct iwl_ssid_ie - directed scan network information element | ||
2261 | * | ||
2262 | * Up to 20 of these may appear in REPLY_SCAN_CMD, | ||
2263 | * selected by "type" bit field in struct iwl_scan_channel; | ||
2264 | * each channel may select different ssids from among the 20 entries. | ||
2265 | * SSID IEs get transmitted in reverse order of entry. | ||
2266 | */ | ||
2267 | struct iwl_ssid_ie { | ||
2268 | u8 id; | ||
2269 | u8 len; | ||
2270 | u8 ssid[32]; | ||
2271 | } __packed; | ||
2272 | |||
2273 | #define PROBE_OPTION_MAX 20 | ||
2274 | #define TX_CMD_LIFE_TIME_INFINITE cpu_to_le32(0xFFFFFFFF) | ||
2275 | #define IWL_GOOD_CRC_TH_DISABLED 0 | ||
2276 | #define IWL_GOOD_CRC_TH_DEFAULT cpu_to_le16(1) | ||
2277 | #define IWL_GOOD_CRC_TH_NEVER cpu_to_le16(0xffff) | ||
2278 | #define IWL_MAX_CMD_SIZE 4096 | ||
2279 | |||
2280 | /* | ||
2281 | * REPLY_SCAN_CMD = 0x80 (command) | ||
2282 | * | ||
2283 | * The hardware scan command is very powerful; the driver can set it up to | ||
2284 | * maintain (relatively) normal network traffic while doing a scan in the | ||
2285 | * background. The max_out_time and suspend_time control the ratio of how | ||
2286 | * long the device stays on an associated network channel ("service channel") | ||
2287 | * vs. how long it's away from the service channel, i.e. tuned to other channels | ||
2288 | * for scanning. | ||
2289 | * | ||
2290 | * max_out_time is the max time off-channel (in usec), and suspend_time | ||
2291 | * is how long (in "extended beacon" format) that the scan is "suspended" | ||
2292 | * after returning to the service channel. That is, suspend_time is the | ||
2293 | * time that we stay on the service channel, doing normal work, between | ||
2294 | * scan segments. The driver may set these parameters differently to support | ||
2295 | * scanning when associated vs. not associated, and light vs. heavy traffic | ||
2296 | * loads when associated. | ||
2297 | * | ||
2298 | * After receiving this command, the device's scan engine does the following; | ||
2299 | * | ||
2300 | * 1) Sends SCAN_START notification to driver | ||
2301 | * 2) Checks to see if it has time to do scan for one channel | ||
2302 | * 3) Sends NULL packet, with power-save (PS) bit set to 1, | ||
2303 | * to tell AP that we're going off-channel | ||
2304 | * 4) Tunes to first channel in scan list, does active or passive scan | ||
2305 | * 5) Sends SCAN_RESULT notification to driver | ||
2306 | * 6) Checks to see if it has time to do scan on *next* channel in list | ||
2307 | * 7) Repeats 4-6 until it no longer has time to scan the next channel | ||
2308 | * before max_out_time expires | ||
2309 | * 8) Returns to service channel | ||
2310 | * 9) Sends NULL packet with PS=0 to tell AP that we're back | ||
2311 | * 10) Stays on service channel until suspend_time expires | ||
2312 | * 11) Repeats entire process 2-10 until list is complete | ||
2313 | * 12) Sends SCAN_COMPLETE notification | ||
2314 | * | ||
2315 | * For fast, efficient scans, the scan command also has support for staying on | ||
2316 | * a channel for just a short time, if doing active scanning and getting no | ||
2317 | * responses to the transmitted probe request. This time is controlled by | ||
2318 | * quiet_time, and the number of received packets below which a channel is | ||
2319 | * considered "quiet" is controlled by quiet_plcp_threshold. | ||
2320 | * | ||
2321 | * For active scanning on channels that have regulatory restrictions against | ||
2322 | * blindly transmitting, the scan can listen before transmitting, to make sure | ||
2323 | * that there is already legitimate activity on the channel. If enough | ||
2324 | * packets are cleanly received on the channel (controlled by good_CRC_th, | ||
2325 | * typical value 1), the scan engine starts transmitting probe requests. | ||
2326 | * | ||
2327 | * Driver must use separate scan commands for 2.4 vs. 5 GHz bands. | ||
2328 | * | ||
2329 | * To avoid uCode errors, see timing restrictions described under | ||
2330 | * struct iwl_scan_channel. | ||
2331 | */ | ||
2332 | |||
2333 | enum iwl_scan_flags { | ||
2334 | /* BIT(0) currently unused */ | ||
2335 | IWL_SCAN_FLAGS_ACTION_FRAME_TX = BIT(1), | ||
2336 | /* bits 2-7 reserved */ | ||
2337 | }; | ||
2338 | |||
2339 | struct iwl_scan_cmd { | ||
2340 | __le16 len; | ||
2341 | u8 scan_flags; /* scan flags: see enum iwl_scan_flags */ | ||
2342 | u8 channel_count; /* # channels in channel list */ | ||
2343 | __le16 quiet_time; /* dwell only this # millisecs on quiet channel | ||
2344 | * (only for active scan) */ | ||
2345 | __le16 quiet_plcp_th; /* quiet chnl is < this # pkts (typ. 1) */ | ||
2346 | __le16 good_CRC_th; /* passive -> active promotion threshold */ | ||
2347 | __le16 rx_chain; /* RXON_RX_CHAIN_* */ | ||
2348 | __le32 max_out_time; /* max usec to be away from associated (service) | ||
2349 | * channel */ | ||
2350 | __le32 suspend_time; /* pause scan this long (in "extended beacon | ||
2351 | * format") when returning to service chnl: | ||
2352 | */ | ||
2353 | __le32 flags; /* RXON_FLG_* */ | ||
2354 | __le32 filter_flags; /* RXON_FILTER_* */ | ||
2355 | |||
2356 | /* For active scans (set to all-0s for passive scans). | ||
2357 | * Does not include payload. Must specify Tx rate; no rate scaling. */ | ||
2358 | struct iwl_tx_cmd tx_cmd; | ||
2359 | |||
2360 | /* For directed active scans (set to all-0s otherwise) */ | ||
2361 | struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX]; | ||
2362 | |||
2363 | /* | ||
2364 | * Probe request frame, followed by channel list. | ||
2365 | * | ||
2366 | * Size of probe request frame is specified by byte count in tx_cmd. | ||
2367 | * Channel list follows immediately after probe request frame. | ||
2368 | * Number of channels in list is specified by channel_count. | ||
2369 | * Each channel in list is of type: | ||
2370 | * | ||
2371 | * struct iwl_scan_channel channels[0]; | ||
2372 | * | ||
2373 | * NOTE: Only one band of channels can be scanned per pass. You | ||
2374 | * must not mix 2.4GHz channels and 5.2GHz channels, and you must wait | ||
2375 | * for one scan to complete (i.e. receive SCAN_COMPLETE_NOTIFICATION) | ||
2376 | * before requesting another scan. | ||
2377 | */ | ||
2378 | u8 data[0]; | ||
2379 | } __packed; | ||
2380 | |||
2381 | /* Can abort will notify by complete notification with abort status. */ | ||
2382 | #define CAN_ABORT_STATUS cpu_to_le32(0x1) | ||
2383 | /* complete notification statuses */ | ||
2384 | #define ABORT_STATUS 0x2 | ||
2385 | |||
2386 | /* | ||
2387 | * REPLY_SCAN_CMD = 0x80 (response) | ||
2388 | */ | ||
2389 | struct iwl_scanreq_notification { | ||
2390 | __le32 status; /* 1: okay, 2: cannot fulfill request */ | ||
2391 | } __packed; | ||
2392 | |||
2393 | /* | ||
2394 | * SCAN_START_NOTIFICATION = 0x82 (notification only, not a command) | ||
2395 | */ | ||
2396 | struct iwl_scanstart_notification { | ||
2397 | __le32 tsf_low; | ||
2398 | __le32 tsf_high; | ||
2399 | __le32 beacon_timer; | ||
2400 | u8 channel; | ||
2401 | u8 band; | ||
2402 | u8 reserved[2]; | ||
2403 | __le32 status; | ||
2404 | } __packed; | ||
2405 | |||
2406 | #define SCAN_OWNER_STATUS 0x1 | ||
2407 | #define MEASURE_OWNER_STATUS 0x2 | ||
2408 | |||
2409 | #define IWL_PROBE_STATUS_OK 0 | ||
2410 | #define IWL_PROBE_STATUS_TX_FAILED BIT(0) | ||
2411 | /* error statuses combined with TX_FAILED */ | ||
2412 | #define IWL_PROBE_STATUS_FAIL_TTL BIT(1) | ||
2413 | #define IWL_PROBE_STATUS_FAIL_BT BIT(2) | ||
2414 | |||
2415 | #define NUMBER_OF_STATISTICS 1 /* first __le32 is good CRC */ | ||
2416 | /* | ||
2417 | * SCAN_RESULTS_NOTIFICATION = 0x83 (notification only, not a command) | ||
2418 | */ | ||
2419 | struct iwl_scanresults_notification { | ||
2420 | u8 channel; | ||
2421 | u8 band; | ||
2422 | u8 probe_status; | ||
2423 | u8 num_probe_not_sent; /* not enough time to send */ | ||
2424 | __le32 tsf_low; | ||
2425 | __le32 tsf_high; | ||
2426 | __le32 statistics[NUMBER_OF_STATISTICS]; | ||
2427 | } __packed; | ||
2428 | |||
2429 | /* | ||
2430 | * SCAN_COMPLETE_NOTIFICATION = 0x84 (notification only, not a command) | ||
2431 | */ | ||
2432 | struct iwl_scancomplete_notification { | ||
2433 | u8 scanned_channels; | ||
2434 | u8 status; | ||
2435 | u8 bt_status; /* BT On/Off status */ | ||
2436 | u8 last_channel; | ||
2437 | __le32 tsf_low; | ||
2438 | __le32 tsf_high; | ||
2439 | } __packed; | ||
2440 | |||
2441 | |||
2442 | /****************************************************************************** | ||
2443 | * (9) | ||
2444 | * IBSS/AP Commands and Notifications: | ||
2445 | * | ||
2446 | *****************************************************************************/ | ||
2447 | |||
2448 | enum iwl_ibss_manager { | ||
2449 | IWL_NOT_IBSS_MANAGER = 0, | ||
2450 | IWL_IBSS_MANAGER = 1, | ||
2451 | }; | ||
2452 | |||
2453 | /* | ||
2454 | * BEACON_NOTIFICATION = 0x90 (notification only, not a command) | ||
2455 | */ | ||
2456 | |||
2457 | struct iwlagn_beacon_notif { | ||
2458 | struct iwlagn_tx_resp beacon_notify_hdr; | ||
2459 | __le32 low_tsf; | ||
2460 | __le32 high_tsf; | ||
2461 | __le32 ibss_mgr_status; | ||
2462 | } __packed; | ||
2463 | |||
2464 | /* | ||
2465 | * REPLY_TX_BEACON = 0x91 (command, has simple generic response) | ||
2466 | */ | ||
2467 | |||
2468 | struct iwl_tx_beacon_cmd { | ||
2469 | struct iwl_tx_cmd tx; | ||
2470 | __le16 tim_idx; | ||
2471 | u8 tim_size; | ||
2472 | u8 reserved1; | ||
2473 | struct ieee80211_hdr frame[0]; /* beacon frame */ | ||
2474 | } __packed; | ||
2475 | |||
2476 | /****************************************************************************** | ||
2477 | * (10) | ||
2478 | * Statistics Commands and Notifications: | ||
2479 | * | ||
2480 | *****************************************************************************/ | ||
2481 | |||
2482 | #define IWL_TEMP_CONVERT 260 | ||
2483 | |||
2484 | #define SUP_RATE_11A_MAX_NUM_CHANNELS 8 | ||
2485 | #define SUP_RATE_11B_MAX_NUM_CHANNELS 4 | ||
2486 | #define SUP_RATE_11G_MAX_NUM_CHANNELS 12 | ||
2487 | |||
2488 | /* Used for passing to driver number of successes and failures per rate */ | ||
2489 | struct rate_histogram { | ||
2490 | union { | ||
2491 | __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS]; | ||
2492 | __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS]; | ||
2493 | __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS]; | ||
2494 | } success; | ||
2495 | union { | ||
2496 | __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS]; | ||
2497 | __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS]; | ||
2498 | __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS]; | ||
2499 | } failed; | ||
2500 | } __packed; | ||
2501 | |||
2502 | /* statistics command response */ | ||
2503 | |||
2504 | struct statistics_dbg { | ||
2505 | __le32 burst_check; | ||
2506 | __le32 burst_count; | ||
2507 | __le32 wait_for_silence_timeout_cnt; | ||
2508 | __le32 reserved[3]; | ||
2509 | } __packed; | ||
2510 | |||
2511 | struct statistics_rx_phy { | ||
2512 | __le32 ina_cnt; | ||
2513 | __le32 fina_cnt; | ||
2514 | __le32 plcp_err; | ||
2515 | __le32 crc32_err; | ||
2516 | __le32 overrun_err; | ||
2517 | __le32 early_overrun_err; | ||
2518 | __le32 crc32_good; | ||
2519 | __le32 false_alarm_cnt; | ||
2520 | __le32 fina_sync_err_cnt; | ||
2521 | __le32 sfd_timeout; | ||
2522 | __le32 fina_timeout; | ||
2523 | __le32 unresponded_rts; | ||
2524 | __le32 rxe_frame_limit_overrun; | ||
2525 | __le32 sent_ack_cnt; | ||
2526 | __le32 sent_cts_cnt; | ||
2527 | __le32 sent_ba_rsp_cnt; | ||
2528 | __le32 dsp_self_kill; | ||
2529 | __le32 mh_format_err; | ||
2530 | __le32 re_acq_main_rssi_sum; | ||
2531 | __le32 reserved3; | ||
2532 | } __packed; | ||
2533 | |||
2534 | struct statistics_rx_ht_phy { | ||
2535 | __le32 plcp_err; | ||
2536 | __le32 overrun_err; | ||
2537 | __le32 early_overrun_err; | ||
2538 | __le32 crc32_good; | ||
2539 | __le32 crc32_err; | ||
2540 | __le32 mh_format_err; | ||
2541 | __le32 agg_crc32_good; | ||
2542 | __le32 agg_mpdu_cnt; | ||
2543 | __le32 agg_cnt; | ||
2544 | __le32 unsupport_mcs; | ||
2545 | } __packed; | ||
2546 | |||
2547 | #define INTERFERENCE_DATA_AVAILABLE cpu_to_le32(1) | ||
2548 | |||
2549 | struct statistics_rx_non_phy { | ||
2550 | __le32 bogus_cts; /* CTS received when not expecting CTS */ | ||
2551 | __le32 bogus_ack; /* ACK received when not expecting ACK */ | ||
2552 | __le32 non_bssid_frames; /* number of frames with BSSID that | ||
2553 | * doesn't belong to the STA BSSID */ | ||
2554 | __le32 filtered_frames; /* count frames that were dumped in the | ||
2555 | * filtering process */ | ||
2556 | __le32 non_channel_beacons; /* beacons with our bss id but not on | ||
2557 | * our serving channel */ | ||
2558 | __le32 channel_beacons; /* beacons with our bss id and in our | ||
2559 | * serving channel */ | ||
2560 | __le32 num_missed_bcon; /* number of missed beacons */ | ||
2561 | __le32 adc_rx_saturation_time; /* count in 0.8us units the time the | ||
2562 | * ADC was in saturation */ | ||
2563 | __le32 ina_detection_search_time;/* total time (in 0.8us) searched | ||
2564 | * for INA */ | ||
2565 | __le32 beacon_silence_rssi_a; /* RSSI silence after beacon frame */ | ||
2566 | __le32 beacon_silence_rssi_b; /* RSSI silence after beacon frame */ | ||
2567 | __le32 beacon_silence_rssi_c; /* RSSI silence after beacon frame */ | ||
2568 | __le32 interference_data_flag; /* flag for interference data | ||
2569 | * availability. 1 when data is | ||
2570 | * available. */ | ||
2571 | __le32 channel_load; /* counts RX Enable time in uSec */ | ||
2572 | __le32 dsp_false_alarms; /* DSP false alarm (both OFDM | ||
2573 | * and CCK) counter */ | ||
2574 | __le32 beacon_rssi_a; | ||
2575 | __le32 beacon_rssi_b; | ||
2576 | __le32 beacon_rssi_c; | ||
2577 | __le32 beacon_energy_a; | ||
2578 | __le32 beacon_energy_b; | ||
2579 | __le32 beacon_energy_c; | ||
2580 | } __packed; | ||
2581 | |||
2582 | struct statistics_rx_non_phy_bt { | ||
2583 | struct statistics_rx_non_phy common; | ||
2584 | /* additional stats for bt */ | ||
2585 | __le32 num_bt_kills; | ||
2586 | __le32 reserved[2]; | ||
2587 | } __packed; | ||
2588 | |||
2589 | struct statistics_rx { | ||
2590 | struct statistics_rx_phy ofdm; | ||
2591 | struct statistics_rx_phy cck; | ||
2592 | struct statistics_rx_non_phy general; | ||
2593 | struct statistics_rx_ht_phy ofdm_ht; | ||
2594 | } __packed; | ||
2595 | |||
2596 | struct statistics_rx_bt { | ||
2597 | struct statistics_rx_phy ofdm; | ||
2598 | struct statistics_rx_phy cck; | ||
2599 | struct statistics_rx_non_phy_bt general; | ||
2600 | struct statistics_rx_ht_phy ofdm_ht; | ||
2601 | } __packed; | ||
2602 | |||
2603 | /** | ||
2604 | * struct statistics_tx_power - current tx power | ||
2605 | * | ||
2606 | * @ant_a: current tx power on chain a in 1/2 dB step | ||
2607 | * @ant_b: current tx power on chain b in 1/2 dB step | ||
2608 | * @ant_c: current tx power on chain c in 1/2 dB step | ||
2609 | */ | ||
2610 | struct statistics_tx_power { | ||
2611 | u8 ant_a; | ||
2612 | u8 ant_b; | ||
2613 | u8 ant_c; | ||
2614 | u8 reserved; | ||
2615 | } __packed; | ||
2616 | |||
2617 | struct statistics_tx_non_phy_agg { | ||
2618 | __le32 ba_timeout; | ||
2619 | __le32 ba_reschedule_frames; | ||
2620 | __le32 scd_query_agg_frame_cnt; | ||
2621 | __le32 scd_query_no_agg; | ||
2622 | __le32 scd_query_agg; | ||
2623 | __le32 scd_query_mismatch; | ||
2624 | __le32 frame_not_ready; | ||
2625 | __le32 underrun; | ||
2626 | __le32 bt_prio_kill; | ||
2627 | __le32 rx_ba_rsp_cnt; | ||
2628 | } __packed; | ||
2629 | |||
2630 | struct statistics_tx { | ||
2631 | __le32 preamble_cnt; | ||
2632 | __le32 rx_detected_cnt; | ||
2633 | __le32 bt_prio_defer_cnt; | ||
2634 | __le32 bt_prio_kill_cnt; | ||
2635 | __le32 few_bytes_cnt; | ||
2636 | __le32 cts_timeout; | ||
2637 | __le32 ack_timeout; | ||
2638 | __le32 expected_ack_cnt; | ||
2639 | __le32 actual_ack_cnt; | ||
2640 | __le32 dump_msdu_cnt; | ||
2641 | __le32 burst_abort_next_frame_mismatch_cnt; | ||
2642 | __le32 burst_abort_missing_next_frame_cnt; | ||
2643 | __le32 cts_timeout_collision; | ||
2644 | __le32 ack_or_ba_timeout_collision; | ||
2645 | struct statistics_tx_non_phy_agg agg; | ||
2646 | /* | ||
2647 | * "tx_power" are optional parameters provided by uCode, | ||
2648 | * 6000 series is the only device provide the information, | ||
2649 | * Those are reserved fields for all the other devices | ||
2650 | */ | ||
2651 | struct statistics_tx_power tx_power; | ||
2652 | __le32 reserved1; | ||
2653 | } __packed; | ||
2654 | |||
2655 | |||
2656 | struct statistics_div { | ||
2657 | __le32 tx_on_a; | ||
2658 | __le32 tx_on_b; | ||
2659 | __le32 exec_time; | ||
2660 | __le32 probe_time; | ||
2661 | __le32 reserved1; | ||
2662 | __le32 reserved2; | ||
2663 | } __packed; | ||
2664 | |||
2665 | struct statistics_general_common { | ||
2666 | __le32 temperature; /* radio temperature */ | ||
2667 | __le32 temperature_m; /* radio voltage */ | ||
2668 | struct statistics_dbg dbg; | ||
2669 | __le32 sleep_time; | ||
2670 | __le32 slots_out; | ||
2671 | __le32 slots_idle; | ||
2672 | __le32 ttl_timestamp; | ||
2673 | struct statistics_div div; | ||
2674 | __le32 rx_enable_counter; | ||
2675 | /* | ||
2676 | * num_of_sos_states: | ||
2677 | * count the number of times we have to re-tune | ||
2678 | * in order to get out of bad PHY status | ||
2679 | */ | ||
2680 | __le32 num_of_sos_states; | ||
2681 | } __packed; | ||
2682 | |||
2683 | struct statistics_bt_activity { | ||
2684 | /* Tx statistics */ | ||
2685 | __le32 hi_priority_tx_req_cnt; | ||
2686 | __le32 hi_priority_tx_denied_cnt; | ||
2687 | __le32 lo_priority_tx_req_cnt; | ||
2688 | __le32 lo_priority_tx_denied_cnt; | ||
2689 | /* Rx statistics */ | ||
2690 | __le32 hi_priority_rx_req_cnt; | ||
2691 | __le32 hi_priority_rx_denied_cnt; | ||
2692 | __le32 lo_priority_rx_req_cnt; | ||
2693 | __le32 lo_priority_rx_denied_cnt; | ||
2694 | } __packed; | ||
2695 | |||
2696 | struct statistics_general { | ||
2697 | struct statistics_general_common common; | ||
2698 | __le32 reserved2; | ||
2699 | __le32 reserved3; | ||
2700 | } __packed; | ||
2701 | |||
2702 | struct statistics_general_bt { | ||
2703 | struct statistics_general_common common; | ||
2704 | struct statistics_bt_activity activity; | ||
2705 | __le32 reserved2; | ||
2706 | __le32 reserved3; | ||
2707 | } __packed; | ||
2708 | |||
2709 | #define UCODE_STATISTICS_CLEAR_MSK (0x1 << 0) | ||
2710 | #define UCODE_STATISTICS_FREQUENCY_MSK (0x1 << 1) | ||
2711 | #define UCODE_STATISTICS_NARROW_BAND_MSK (0x1 << 2) | ||
2712 | |||
2713 | /* | ||
2714 | * REPLY_STATISTICS_CMD = 0x9c, | ||
2715 | * all devices identical. | ||
2716 | * | ||
2717 | * This command triggers an immediate response containing uCode statistics. | ||
2718 | * The response is in the same format as STATISTICS_NOTIFICATION 0x9d, below. | ||
2719 | * | ||
2720 | * If the CLEAR_STATS configuration flag is set, uCode will clear its | ||
2721 | * internal copy of the statistics (counters) after issuing the response. | ||
2722 | * This flag does not affect STATISTICS_NOTIFICATIONs after beacons (see below). | ||
2723 | * | ||
2724 | * If the DISABLE_NOTIF configuration flag is set, uCode will not issue | ||
2725 | * STATISTICS_NOTIFICATIONs after received beacons (see below). This flag | ||
2726 | * does not affect the response to the REPLY_STATISTICS_CMD 0x9c itself. | ||
2727 | */ | ||
2728 | #define IWL_STATS_CONF_CLEAR_STATS cpu_to_le32(0x1) /* see above */ | ||
2729 | #define IWL_STATS_CONF_DISABLE_NOTIF cpu_to_le32(0x2)/* see above */ | ||
2730 | struct iwl_statistics_cmd { | ||
2731 | __le32 configuration_flags; /* IWL_STATS_CONF_* */ | ||
2732 | } __packed; | ||
2733 | |||
2734 | /* | ||
2735 | * STATISTICS_NOTIFICATION = 0x9d (notification only, not a command) | ||
2736 | * | ||
2737 | * By default, uCode issues this notification after receiving a beacon | ||
2738 | * while associated. To disable this behavior, set DISABLE_NOTIF flag in the | ||
2739 | * REPLY_STATISTICS_CMD 0x9c, above. | ||
2740 | * | ||
2741 | * Statistics counters continue to increment beacon after beacon, but are | ||
2742 | * cleared when changing channels or when driver issues REPLY_STATISTICS_CMD | ||
2743 | * 0x9c with CLEAR_STATS bit set (see above). | ||
2744 | * | ||
2745 | * uCode also issues this notification during scans. uCode clears statistics | ||
2746 | * appropriately so that each notification contains statistics for only the | ||
2747 | * one channel that has just been scanned. | ||
2748 | */ | ||
2749 | #define STATISTICS_REPLY_FLG_BAND_24G_MSK cpu_to_le32(0x2) | ||
2750 | #define STATISTICS_REPLY_FLG_HT40_MODE_MSK cpu_to_le32(0x8) | ||
2751 | |||
2752 | struct iwl_notif_statistics { | ||
2753 | __le32 flag; | ||
2754 | struct statistics_rx rx; | ||
2755 | struct statistics_tx tx; | ||
2756 | struct statistics_general general; | ||
2757 | } __packed; | ||
2758 | |||
2759 | struct iwl_bt_notif_statistics { | ||
2760 | __le32 flag; | ||
2761 | struct statistics_rx_bt rx; | ||
2762 | struct statistics_tx tx; | ||
2763 | struct statistics_general_bt general; | ||
2764 | } __packed; | ||
2765 | |||
2766 | /* | ||
2767 | * MISSED_BEACONS_NOTIFICATION = 0xa2 (notification only, not a command) | ||
2768 | * | ||
2769 | * uCode send MISSED_BEACONS_NOTIFICATION to driver when detect beacon missed | ||
2770 | * in regardless of how many missed beacons, which mean when driver receive the | ||
2771 | * notification, inside the command, it can find all the beacons information | ||
2772 | * which include number of total missed beacons, number of consecutive missed | ||
2773 | * beacons, number of beacons received and number of beacons expected to | ||
2774 | * receive. | ||
2775 | * | ||
2776 | * If uCode detected consecutive_missed_beacons > 5, it will reset the radio | ||
2777 | * in order to bring the radio/PHY back to working state; which has no relation | ||
2778 | * to when driver will perform sensitivity calibration. | ||
2779 | * | ||
2780 | * Driver should set it own missed_beacon_threshold to decide when to perform | ||
2781 | * sensitivity calibration based on number of consecutive missed beacons in | ||
2782 | * order to improve overall performance, especially in noisy environment. | ||
2783 | * | ||
2784 | */ | ||
2785 | |||
2786 | #define IWL_MISSED_BEACON_THRESHOLD_MIN (1) | ||
2787 | #define IWL_MISSED_BEACON_THRESHOLD_DEF (5) | ||
2788 | #define IWL_MISSED_BEACON_THRESHOLD_MAX IWL_MISSED_BEACON_THRESHOLD_DEF | ||
2789 | |||
2790 | struct iwl_missed_beacon_notif { | ||
2791 | __le32 consecutive_missed_beacons; | ||
2792 | __le32 total_missed_becons; | ||
2793 | __le32 num_expected_beacons; | ||
2794 | __le32 num_recvd_beacons; | ||
2795 | } __packed; | ||
2796 | |||
2797 | |||
2798 | /****************************************************************************** | ||
2799 | * (11) | ||
2800 | * Rx Calibration Commands: | ||
2801 | * | ||
2802 | * With the uCode used for open source drivers, most Tx calibration (except | ||
2803 | * for Tx Power) and most Rx calibration is done by uCode during the | ||
2804 | * "initialize" phase of uCode boot. Driver must calibrate only: | ||
2805 | * | ||
2806 | * 1) Tx power (depends on temperature), described elsewhere | ||
2807 | * 2) Receiver gain balance (optimize MIMO, and detect disconnected antennas) | ||
2808 | * 3) Receiver sensitivity (to optimize signal detection) | ||
2809 | * | ||
2810 | *****************************************************************************/ | ||
2811 | |||
2812 | /** | ||
2813 | * SENSITIVITY_CMD = 0xa8 (command, has simple generic response) | ||
2814 | * | ||
2815 | * This command sets up the Rx signal detector for a sensitivity level that | ||
2816 | * is high enough to lock onto all signals within the associated network, | ||
2817 | * but low enough to ignore signals that are below a certain threshold, so as | ||
2818 | * not to have too many "false alarms". False alarms are signals that the | ||
2819 | * Rx DSP tries to lock onto, but then discards after determining that they | ||
2820 | * are noise. | ||
2821 | * | ||
2822 | * The optimum number of false alarms is between 5 and 50 per 200 TUs | ||
2823 | * (200 * 1024 uSecs, i.e. 204.8 milliseconds) of actual Rx time (i.e. | ||
2824 | * time listening, not transmitting). Driver must adjust sensitivity so that | ||
2825 | * the ratio of actual false alarms to actual Rx time falls within this range. | ||
2826 | * | ||
2827 | * While associated, uCode delivers STATISTICS_NOTIFICATIONs after each | ||
2828 | * received beacon. These provide information to the driver to analyze the | ||
2829 | * sensitivity. Don't analyze statistics that come in from scanning, or any | ||
2830 | * other non-associated-network source. Pertinent statistics include: | ||
2831 | * | ||
2832 | * From "general" statistics (struct statistics_rx_non_phy): | ||
2833 | * | ||
2834 | * (beacon_energy_[abc] & 0x0FF00) >> 8 (unsigned, higher value is lower level) | ||
2835 | * Measure of energy of desired signal. Used for establishing a level | ||
2836 | * below which the device does not detect signals. | ||
2837 | * | ||
2838 | * (beacon_silence_rssi_[abc] & 0x0FF00) >> 8 (unsigned, units in dB) | ||
2839 | * Measure of background noise in silent period after beacon. | ||
2840 | * | ||
2841 | * channel_load | ||
2842 | * uSecs of actual Rx time during beacon period (varies according to | ||
2843 | * how much time was spent transmitting). | ||
2844 | * | ||
2845 | * From "cck" and "ofdm" statistics (struct statistics_rx_phy), separately: | ||
2846 | * | ||
2847 | * false_alarm_cnt | ||
2848 | * Signal locks abandoned early (before phy-level header). | ||
2849 | * | ||
2850 | * plcp_err | ||
2851 | * Signal locks abandoned late (during phy-level header). | ||
2852 | * | ||
2853 | * NOTE: Both false_alarm_cnt and plcp_err increment monotonically from | ||
2854 | * beacon to beacon, i.e. each value is an accumulation of all errors | ||
2855 | * before and including the latest beacon. Values will wrap around to 0 | ||
2856 | * after counting up to 2^32 - 1. Driver must differentiate vs. | ||
2857 | * previous beacon's values to determine # false alarms in the current | ||
2858 | * beacon period. | ||
2859 | * | ||
2860 | * Total number of false alarms = false_alarms + plcp_errs | ||
2861 | * | ||
2862 | * For OFDM, adjust the following table entries in struct iwl_sensitivity_cmd | ||
2863 | * (notice that the start points for OFDM are at or close to settings for | ||
2864 | * maximum sensitivity): | ||
2865 | * | ||
2866 | * START / MIN / MAX | ||
2867 | * HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX 90 / 85 / 120 | ||
2868 | * HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX 170 / 170 / 210 | ||
2869 | * HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX 105 / 105 / 140 | ||
2870 | * HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX 220 / 220 / 270 | ||
2871 | * | ||
2872 | * If actual rate of OFDM false alarms (+ plcp_errors) is too high | ||
2873 | * (greater than 50 for each 204.8 msecs listening), reduce sensitivity | ||
2874 | * by *adding* 1 to all 4 of the table entries above, up to the max for | ||
2875 | * each entry. Conversely, if false alarm rate is too low (less than 5 | ||
2876 | * for each 204.8 msecs listening), *subtract* 1 from each entry to | ||
2877 | * increase sensitivity. | ||
2878 | * | ||
2879 | * For CCK sensitivity, keep track of the following: | ||
2880 | * | ||
2881 | * 1). 20-beacon history of maximum background noise, indicated by | ||
2882 | * (beacon_silence_rssi_[abc] & 0x0FF00), units in dB, across the | ||
2883 | * 3 receivers. For any given beacon, the "silence reference" is | ||
2884 | * the maximum of last 60 samples (20 beacons * 3 receivers). | ||
2885 | * | ||
2886 | * 2). 10-beacon history of strongest signal level, as indicated | ||
2887 | * by (beacon_energy_[abc] & 0x0FF00) >> 8, across the 3 receivers, | ||
2888 | * i.e. the strength of the signal through the best receiver at the | ||
2889 | * moment. These measurements are "upside down", with lower values | ||
2890 | * for stronger signals, so max energy will be *minimum* value. | ||
2891 | * | ||
2892 | * Then for any given beacon, the driver must determine the *weakest* | ||
2893 | * of the strongest signals; this is the minimum level that needs to be | ||
2894 | * successfully detected, when using the best receiver at the moment. | ||
2895 | * "Max cck energy" is the maximum (higher value means lower energy!) | ||
2896 | * of the last 10 minima. Once this is determined, driver must add | ||
2897 | * a little margin by adding "6" to it. | ||
2898 | * | ||
2899 | * 3). Number of consecutive beacon periods with too few false alarms. | ||
2900 | * Reset this to 0 at the first beacon period that falls within the | ||
2901 | * "good" range (5 to 50 false alarms per 204.8 milliseconds rx). | ||
2902 | * | ||
2903 | * Then, adjust the following CCK table entries in struct iwl_sensitivity_cmd | ||
2904 | * (notice that the start points for CCK are at maximum sensitivity): | ||
2905 | * | ||
2906 | * START / MIN / MAX | ||
2907 | * HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX 125 / 125 / 200 | ||
2908 | * HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX 200 / 200 / 400 | ||
2909 | * HD_MIN_ENERGY_CCK_DET_INDEX 100 / 0 / 100 | ||
2910 | * | ||
2911 | * If actual rate of CCK false alarms (+ plcp_errors) is too high | ||
2912 | * (greater than 50 for each 204.8 msecs listening), method for reducing | ||
2913 | * sensitivity is: | ||
2914 | * | ||
2915 | * 1) *Add* 3 to value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX, | ||
2916 | * up to max 400. | ||
2917 | * | ||
2918 | * 2) If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is < 160, | ||
2919 | * sensitivity has been reduced a significant amount; bring it up to | ||
2920 | * a moderate 161. Otherwise, *add* 3, up to max 200. | ||
2921 | * | ||
2922 | * 3) a) If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is > 160, | ||
2923 | * sensitivity has been reduced only a moderate or small amount; | ||
2924 | * *subtract* 2 from value in HD_MIN_ENERGY_CCK_DET_INDEX, | ||
2925 | * down to min 0. Otherwise (if gain has been significantly reduced), | ||
2926 | * don't change the HD_MIN_ENERGY_CCK_DET_INDEX value. | ||
2927 | * | ||
2928 | * b) Save a snapshot of the "silence reference". | ||
2929 | * | ||
2930 | * If actual rate of CCK false alarms (+ plcp_errors) is too low | ||
2931 | * (less than 5 for each 204.8 msecs listening), method for increasing | ||
2932 | * sensitivity is used only if: | ||
2933 | * | ||
2934 | * 1a) Previous beacon did not have too many false alarms | ||
2935 | * 1b) AND difference between previous "silence reference" and current | ||
2936 | * "silence reference" (prev - current) is 2 or more, | ||
2937 | * OR 2) 100 or more consecutive beacon periods have had rate of | ||
2938 | * less than 5 false alarms per 204.8 milliseconds rx time. | ||
2939 | * | ||
2940 | * Method for increasing sensitivity: | ||
2941 | * | ||
2942 | * 1) *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX, | ||
2943 | * down to min 125. | ||
2944 | * | ||
2945 | * 2) *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX, | ||
2946 | * down to min 200. | ||
2947 | * | ||
2948 | * 3) *Add* 2 to value in HD_MIN_ENERGY_CCK_DET_INDEX, up to max 100. | ||
2949 | * | ||
2950 | * If actual rate of CCK false alarms (+ plcp_errors) is within good range | ||
2951 | * (between 5 and 50 for each 204.8 msecs listening): | ||
2952 | * | ||
2953 | * 1) Save a snapshot of the silence reference. | ||
2954 | * | ||
2955 | * 2) If previous beacon had too many CCK false alarms (+ plcp_errors), | ||
2956 | * give some extra margin to energy threshold by *subtracting* 8 | ||
2957 | * from value in HD_MIN_ENERGY_CCK_DET_INDEX. | ||
2958 | * | ||
2959 | * For all cases (too few, too many, good range), make sure that the CCK | ||
2960 | * detection threshold (energy) is below the energy level for robust | ||
2961 | * detection over the past 10 beacon periods, the "Max cck energy". | ||
2962 | * Lower values mean higher energy; this means making sure that the value | ||
2963 | * in HD_MIN_ENERGY_CCK_DET_INDEX is at or *above* "Max cck energy". | ||
2964 | * | ||
2965 | */ | ||
2966 | |||
2967 | /* | ||
2968 | * Table entries in SENSITIVITY_CMD (struct iwl_sensitivity_cmd) | ||
2969 | */ | ||
2970 | #define HD_TABLE_SIZE (11) /* number of entries */ | ||
2971 | #define HD_MIN_ENERGY_CCK_DET_INDEX (0) /* table indexes */ | ||
2972 | #define HD_MIN_ENERGY_OFDM_DET_INDEX (1) | ||
2973 | #define HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX (2) | ||
2974 | #define HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX (3) | ||
2975 | #define HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX (4) | ||
2976 | #define HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX (5) | ||
2977 | #define HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX (6) | ||
2978 | #define HD_BARKER_CORR_TH_ADD_MIN_INDEX (7) | ||
2979 | #define HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX (8) | ||
2980 | #define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX (9) | ||
2981 | #define HD_OFDM_ENERGY_TH_IN_INDEX (10) | ||
2982 | |||
2983 | /* | ||
2984 | * Additional table entries in enhance SENSITIVITY_CMD | ||
2985 | */ | ||
2986 | #define HD_INA_NON_SQUARE_DET_OFDM_INDEX (11) | ||
2987 | #define HD_INA_NON_SQUARE_DET_CCK_INDEX (12) | ||
2988 | #define HD_CORR_11_INSTEAD_OF_CORR_9_EN_INDEX (13) | ||
2989 | #define HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_INDEX (14) | ||
2990 | #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_INDEX (15) | ||
2991 | #define HD_OFDM_NON_SQUARE_DET_SLOPE_INDEX (16) | ||
2992 | #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_INDEX (17) | ||
2993 | #define HD_CCK_NON_SQUARE_DET_SLOPE_MRC_INDEX (18) | ||
2994 | #define HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_INDEX (19) | ||
2995 | #define HD_CCK_NON_SQUARE_DET_SLOPE_INDEX (20) | ||
2996 | #define HD_CCK_NON_SQUARE_DET_INTERCEPT_INDEX (21) | ||
2997 | #define HD_RESERVED (22) | ||
2998 | |||
2999 | /* number of entries for enhanced tbl */ | ||
3000 | #define ENHANCE_HD_TABLE_SIZE (23) | ||
3001 | |||
3002 | /* number of additional entries for enhanced tbl */ | ||
3003 | #define ENHANCE_HD_TABLE_ENTRIES (ENHANCE_HD_TABLE_SIZE - HD_TABLE_SIZE) | ||
3004 | |||
3005 | #define HD_INA_NON_SQUARE_DET_OFDM_DATA_V1 cpu_to_le16(0) | ||
3006 | #define HD_INA_NON_SQUARE_DET_CCK_DATA_V1 cpu_to_le16(0) | ||
3007 | #define HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA_V1 cpu_to_le16(0) | ||
3008 | #define HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA_V1 cpu_to_le16(668) | ||
3009 | #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V1 cpu_to_le16(4) | ||
3010 | #define HD_OFDM_NON_SQUARE_DET_SLOPE_DATA_V1 cpu_to_le16(486) | ||
3011 | #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA_V1 cpu_to_le16(37) | ||
3012 | #define HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA_V1 cpu_to_le16(853) | ||
3013 | #define HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V1 cpu_to_le16(4) | ||
3014 | #define HD_CCK_NON_SQUARE_DET_SLOPE_DATA_V1 cpu_to_le16(476) | ||
3015 | #define HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA_V1 cpu_to_le16(99) | ||
3016 | |||
3017 | #define HD_INA_NON_SQUARE_DET_OFDM_DATA_V2 cpu_to_le16(1) | ||
3018 | #define HD_INA_NON_SQUARE_DET_CCK_DATA_V2 cpu_to_le16(1) | ||
3019 | #define HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA_V2 cpu_to_le16(1) | ||
3020 | #define HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA_V2 cpu_to_le16(600) | ||
3021 | #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V2 cpu_to_le16(40) | ||
3022 | #define HD_OFDM_NON_SQUARE_DET_SLOPE_DATA_V2 cpu_to_le16(486) | ||
3023 | #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA_V2 cpu_to_le16(45) | ||
3024 | #define HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA_V2 cpu_to_le16(853) | ||
3025 | #define HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V2 cpu_to_le16(60) | ||
3026 | #define HD_CCK_NON_SQUARE_DET_SLOPE_DATA_V2 cpu_to_le16(476) | ||
3027 | #define HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA_V2 cpu_to_le16(99) | ||
3028 | |||
3029 | |||
3030 | /* Control field in struct iwl_sensitivity_cmd */ | ||
3031 | #define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE cpu_to_le16(0) | ||
3032 | #define SENSITIVITY_CMD_CONTROL_WORK_TABLE cpu_to_le16(1) | ||
3033 | |||
3034 | /** | ||
3035 | * struct iwl_sensitivity_cmd | ||
3036 | * @control: (1) updates working table, (0) updates default table | ||
3037 | * @table: energy threshold values, use HD_* as index into table | ||
3038 | * | ||
3039 | * Always use "1" in "control" to update uCode's working table and DSP. | ||
3040 | */ | ||
3041 | struct iwl_sensitivity_cmd { | ||
3042 | __le16 control; /* always use "1" */ | ||
3043 | __le16 table[HD_TABLE_SIZE]; /* use HD_* as index */ | ||
3044 | } __packed; | ||
3045 | |||
3046 | /* | ||
3047 | * | ||
3048 | */ | ||
3049 | struct iwl_enhance_sensitivity_cmd { | ||
3050 | __le16 control; /* always use "1" */ | ||
3051 | __le16 enhance_table[ENHANCE_HD_TABLE_SIZE]; /* use HD_* as index */ | ||
3052 | } __packed; | ||
3053 | |||
3054 | |||
3055 | /** | ||
3056 | * REPLY_PHY_CALIBRATION_CMD = 0xb0 (command, has simple generic response) | ||
3057 | * | ||
3058 | * This command sets the relative gains of agn device's 3 radio receiver chains. | ||
3059 | * | ||
3060 | * After the first association, driver should accumulate signal and noise | ||
3061 | * statistics from the STATISTICS_NOTIFICATIONs that follow the first 20 | ||
3062 | * beacons from the associated network (don't collect statistics that come | ||
3063 | * in from scanning, or any other non-network source). | ||
3064 | * | ||
3065 | * DISCONNECTED ANTENNA: | ||
3066 | * | ||
3067 | * Driver should determine which antennas are actually connected, by comparing | ||
3068 | * average beacon signal levels for the 3 Rx chains. Accumulate (add) the | ||
3069 | * following values over 20 beacons, one accumulator for each of the chains | ||
3070 | * a/b/c, from struct statistics_rx_non_phy: | ||
3071 | * | ||
3072 | * beacon_rssi_[abc] & 0x0FF (unsigned, units in dB) | ||
3073 | * | ||
3074 | * Find the strongest signal from among a/b/c. Compare the other two to the | ||
3075 | * strongest. If any signal is more than 15 dB (times 20, unless you | ||
3076 | * divide the accumulated values by 20) below the strongest, the driver | ||
3077 | * considers that antenna to be disconnected, and should not try to use that | ||
3078 | * antenna/chain for Rx or Tx. If both A and B seem to be disconnected, | ||
3079 | * driver should declare the stronger one as connected, and attempt to use it | ||
3080 | * (A and B are the only 2 Tx chains!). | ||
3081 | * | ||
3082 | * | ||
3083 | * RX BALANCE: | ||
3084 | * | ||
3085 | * Driver should balance the 3 receivers (but just the ones that are connected | ||
3086 | * to antennas, see above) for gain, by comparing the average signal levels | ||
3087 | * detected during the silence after each beacon (background noise). | ||
3088 | * Accumulate (add) the following values over 20 beacons, one accumulator for | ||
3089 | * each of the chains a/b/c, from struct statistics_rx_non_phy: | ||
3090 | * | ||
3091 | * beacon_silence_rssi_[abc] & 0x0FF (unsigned, units in dB) | ||
3092 | * | ||
3093 | * Find the weakest background noise level from among a/b/c. This Rx chain | ||
3094 | * will be the reference, with 0 gain adjustment. Attenuate other channels by | ||
3095 | * finding noise difference: | ||
3096 | * | ||
3097 | * (accum_noise[i] - accum_noise[reference]) / 30 | ||
3098 | * | ||
3099 | * The "30" adjusts the dB in the 20 accumulated samples to units of 1.5 dB. | ||
3100 | * For use in diff_gain_[abc] fields of struct iwl_calibration_cmd, the | ||
3101 | * driver should limit the difference results to a range of 0-3 (0-4.5 dB), | ||
3102 | * and set bit 2 to indicate "reduce gain". The value for the reference | ||
3103 | * (weakest) chain should be "0". | ||
3104 | * | ||
3105 | * diff_gain_[abc] bit fields: | ||
3106 | * 2: (1) reduce gain, (0) increase gain | ||
3107 | * 1-0: amount of gain, units of 1.5 dB | ||
3108 | */ | ||
3109 | |||
3110 | /* Phy calibration command for series */ | ||
3111 | enum { | ||
3112 | IWL_PHY_CALIBRATE_DC_CMD = 8, | ||
3113 | IWL_PHY_CALIBRATE_LO_CMD = 9, | ||
3114 | IWL_PHY_CALIBRATE_TX_IQ_CMD = 11, | ||
3115 | IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD = 15, | ||
3116 | IWL_PHY_CALIBRATE_BASE_BAND_CMD = 16, | ||
3117 | IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD = 17, | ||
3118 | IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD = 18, | ||
3119 | }; | ||
3120 | |||
3121 | /* This enum defines the bitmap of various calibrations to enable in both | ||
3122 | * init ucode and runtime ucode through CALIBRATION_CFG_CMD. | ||
3123 | */ | ||
3124 | enum iwl_ucode_calib_cfg { | ||
3125 | IWL_CALIB_CFG_RX_BB_IDX = BIT(0), | ||
3126 | IWL_CALIB_CFG_DC_IDX = BIT(1), | ||
3127 | IWL_CALIB_CFG_LO_IDX = BIT(2), | ||
3128 | IWL_CALIB_CFG_TX_IQ_IDX = BIT(3), | ||
3129 | IWL_CALIB_CFG_RX_IQ_IDX = BIT(4), | ||
3130 | IWL_CALIB_CFG_NOISE_IDX = BIT(5), | ||
3131 | IWL_CALIB_CFG_CRYSTAL_IDX = BIT(6), | ||
3132 | IWL_CALIB_CFG_TEMPERATURE_IDX = BIT(7), | ||
3133 | IWL_CALIB_CFG_PAPD_IDX = BIT(8), | ||
3134 | IWL_CALIB_CFG_SENSITIVITY_IDX = BIT(9), | ||
3135 | IWL_CALIB_CFG_TX_PWR_IDX = BIT(10), | ||
3136 | }; | ||
3137 | |||
3138 | #define IWL_CALIB_INIT_CFG_ALL cpu_to_le32(IWL_CALIB_CFG_RX_BB_IDX | \ | ||
3139 | IWL_CALIB_CFG_DC_IDX | \ | ||
3140 | IWL_CALIB_CFG_LO_IDX | \ | ||
3141 | IWL_CALIB_CFG_TX_IQ_IDX | \ | ||
3142 | IWL_CALIB_CFG_RX_IQ_IDX | \ | ||
3143 | IWL_CALIB_CFG_CRYSTAL_IDX) | ||
3144 | |||
3145 | #define IWL_CALIB_RT_CFG_ALL cpu_to_le32(IWL_CALIB_CFG_RX_BB_IDX | \ | ||
3146 | IWL_CALIB_CFG_DC_IDX | \ | ||
3147 | IWL_CALIB_CFG_LO_IDX | \ | ||
3148 | IWL_CALIB_CFG_TX_IQ_IDX | \ | ||
3149 | IWL_CALIB_CFG_RX_IQ_IDX | \ | ||
3150 | IWL_CALIB_CFG_TEMPERATURE_IDX | \ | ||
3151 | IWL_CALIB_CFG_PAPD_IDX | \ | ||
3152 | IWL_CALIB_CFG_TX_PWR_IDX | \ | ||
3153 | IWL_CALIB_CFG_CRYSTAL_IDX) | ||
3154 | |||
3155 | #define IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK cpu_to_le32(BIT(0)) | ||
3156 | |||
3157 | struct iwl_calib_cfg_elmnt_s { | ||
3158 | __le32 is_enable; | ||
3159 | __le32 start; | ||
3160 | __le32 send_res; | ||
3161 | __le32 apply_res; | ||
3162 | __le32 reserved; | ||
3163 | } __packed; | ||
3164 | |||
3165 | struct iwl_calib_cfg_status_s { | ||
3166 | struct iwl_calib_cfg_elmnt_s once; | ||
3167 | struct iwl_calib_cfg_elmnt_s perd; | ||
3168 | __le32 flags; | ||
3169 | } __packed; | ||
3170 | |||
3171 | struct iwl_calib_cfg_cmd { | ||
3172 | struct iwl_calib_cfg_status_s ucd_calib_cfg; | ||
3173 | struct iwl_calib_cfg_status_s drv_calib_cfg; | ||
3174 | __le32 reserved1; | ||
3175 | } __packed; | ||
3176 | |||
3177 | struct iwl_calib_hdr { | ||
3178 | u8 op_code; | ||
3179 | u8 first_group; | ||
3180 | u8 groups_num; | ||
3181 | u8 data_valid; | ||
3182 | } __packed; | ||
3183 | |||
3184 | struct iwl_calib_cmd { | ||
3185 | struct iwl_calib_hdr hdr; | ||
3186 | u8 data[0]; | ||
3187 | } __packed; | ||
3188 | |||
3189 | struct iwl_calib_xtal_freq_cmd { | ||
3190 | struct iwl_calib_hdr hdr; | ||
3191 | u8 cap_pin1; | ||
3192 | u8 cap_pin2; | ||
3193 | u8 pad[2]; | ||
3194 | } __packed; | ||
3195 | |||
3196 | #define DEFAULT_RADIO_SENSOR_OFFSET cpu_to_le16(2700) | ||
3197 | struct iwl_calib_temperature_offset_cmd { | ||
3198 | struct iwl_calib_hdr hdr; | ||
3199 | __le16 radio_sensor_offset; | ||
3200 | __le16 reserved; | ||
3201 | } __packed; | ||
3202 | |||
3203 | struct iwl_calib_temperature_offset_v2_cmd { | ||
3204 | struct iwl_calib_hdr hdr; | ||
3205 | __le16 radio_sensor_offset_high; | ||
3206 | __le16 radio_sensor_offset_low; | ||
3207 | __le16 burntVoltageRef; | ||
3208 | __le16 reserved; | ||
3209 | } __packed; | ||
3210 | |||
3211 | /* IWL_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD */ | ||
3212 | struct iwl_calib_chain_noise_reset_cmd { | ||
3213 | struct iwl_calib_hdr hdr; | ||
3214 | u8 data[0]; | ||
3215 | }; | ||
3216 | |||
3217 | /* IWL_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD */ | ||
3218 | struct iwl_calib_chain_noise_gain_cmd { | ||
3219 | struct iwl_calib_hdr hdr; | ||
3220 | u8 delta_gain_1; | ||
3221 | u8 delta_gain_2; | ||
3222 | u8 pad[2]; | ||
3223 | } __packed; | ||
3224 | |||
3225 | /****************************************************************************** | ||
3226 | * (12) | ||
3227 | * Miscellaneous Commands: | ||
3228 | * | ||
3229 | *****************************************************************************/ | ||
3230 | |||
3231 | /* | ||
3232 | * LEDs Command & Response | ||
3233 | * REPLY_LEDS_CMD = 0x48 (command, has simple generic response) | ||
3234 | * | ||
3235 | * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field), | ||
3236 | * this command turns it on or off, or sets up a periodic blinking cycle. | ||
3237 | */ | ||
3238 | struct iwl_led_cmd { | ||
3239 | __le32 interval; /* "interval" in uSec */ | ||
3240 | u8 id; /* 1: Activity, 2: Link, 3: Tech */ | ||
3241 | u8 off; /* # intervals off while blinking; | ||
3242 | * "0", with >0 "on" value, turns LED on */ | ||
3243 | u8 on; /* # intervals on while blinking; | ||
3244 | * "0", regardless of "off", turns LED off */ | ||
3245 | u8 reserved; | ||
3246 | } __packed; | ||
3247 | |||
3248 | /* | ||
3249 | * station priority table entries | ||
3250 | * also used as potential "events" value for both | ||
3251 | * COEX_MEDIUM_NOTIFICATION and COEX_EVENT_CMD | ||
3252 | */ | ||
3253 | |||
3254 | /* | ||
3255 | * COEX events entry flag masks | ||
3256 | * RP - Requested Priority | ||
3257 | * WP - Win Medium Priority: priority assigned when the contention has been won | ||
3258 | */ | ||
3259 | #define COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG (0x1) | ||
3260 | #define COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG (0x2) | ||
3261 | #define COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG (0x4) | ||
3262 | |||
3263 | #define COEX_CU_UNASSOC_IDLE_RP 4 | ||
3264 | #define COEX_CU_UNASSOC_MANUAL_SCAN_RP 4 | ||
3265 | #define COEX_CU_UNASSOC_AUTO_SCAN_RP 4 | ||
3266 | #define COEX_CU_CALIBRATION_RP 4 | ||
3267 | #define COEX_CU_PERIODIC_CALIBRATION_RP 4 | ||
3268 | #define COEX_CU_CONNECTION_ESTAB_RP 4 | ||
3269 | #define COEX_CU_ASSOCIATED_IDLE_RP 4 | ||
3270 | #define COEX_CU_ASSOC_MANUAL_SCAN_RP 4 | ||
3271 | #define COEX_CU_ASSOC_AUTO_SCAN_RP 4 | ||
3272 | #define COEX_CU_ASSOC_ACTIVE_LEVEL_RP 4 | ||
3273 | #define COEX_CU_RF_ON_RP 6 | ||
3274 | #define COEX_CU_RF_OFF_RP 4 | ||
3275 | #define COEX_CU_STAND_ALONE_DEBUG_RP 6 | ||
3276 | #define COEX_CU_IPAN_ASSOC_LEVEL_RP 4 | ||
3277 | #define COEX_CU_RSRVD1_RP 4 | ||
3278 | #define COEX_CU_RSRVD2_RP 4 | ||
3279 | |||
3280 | #define COEX_CU_UNASSOC_IDLE_WP 3 | ||
3281 | #define COEX_CU_UNASSOC_MANUAL_SCAN_WP 3 | ||
3282 | #define COEX_CU_UNASSOC_AUTO_SCAN_WP 3 | ||
3283 | #define COEX_CU_CALIBRATION_WP 3 | ||
3284 | #define COEX_CU_PERIODIC_CALIBRATION_WP 3 | ||
3285 | #define COEX_CU_CONNECTION_ESTAB_WP 3 | ||
3286 | #define COEX_CU_ASSOCIATED_IDLE_WP 3 | ||
3287 | #define COEX_CU_ASSOC_MANUAL_SCAN_WP 3 | ||
3288 | #define COEX_CU_ASSOC_AUTO_SCAN_WP 3 | ||
3289 | #define COEX_CU_ASSOC_ACTIVE_LEVEL_WP 3 | ||
3290 | #define COEX_CU_RF_ON_WP 3 | ||
3291 | #define COEX_CU_RF_OFF_WP 3 | ||
3292 | #define COEX_CU_STAND_ALONE_DEBUG_WP 6 | ||
3293 | #define COEX_CU_IPAN_ASSOC_LEVEL_WP 3 | ||
3294 | #define COEX_CU_RSRVD1_WP 3 | ||
3295 | #define COEX_CU_RSRVD2_WP 3 | ||
3296 | |||
3297 | #define COEX_UNASSOC_IDLE_FLAGS 0 | ||
3298 | #define COEX_UNASSOC_MANUAL_SCAN_FLAGS \ | ||
3299 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3300 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG) | ||
3301 | #define COEX_UNASSOC_AUTO_SCAN_FLAGS \ | ||
3302 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3303 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG) | ||
3304 | #define COEX_CALIBRATION_FLAGS \ | ||
3305 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3306 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG) | ||
3307 | #define COEX_PERIODIC_CALIBRATION_FLAGS 0 | ||
3308 | /* | ||
3309 | * COEX_CONNECTION_ESTAB: | ||
3310 | * we need DELAY_MEDIUM_FREE_NTFY to let WiMAX disconnect from network. | ||
3311 | */ | ||
3312 | #define COEX_CONNECTION_ESTAB_FLAGS \ | ||
3313 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3314 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG | \ | ||
3315 | COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG) | ||
3316 | #define COEX_ASSOCIATED_IDLE_FLAGS 0 | ||
3317 | #define COEX_ASSOC_MANUAL_SCAN_FLAGS \ | ||
3318 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3319 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG) | ||
3320 | #define COEX_ASSOC_AUTO_SCAN_FLAGS \ | ||
3321 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3322 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG) | ||
3323 | #define COEX_ASSOC_ACTIVE_LEVEL_FLAGS 0 | ||
3324 | #define COEX_RF_ON_FLAGS 0 | ||
3325 | #define COEX_RF_OFF_FLAGS 0 | ||
3326 | #define COEX_STAND_ALONE_DEBUG_FLAGS \ | ||
3327 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3328 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG) | ||
3329 | #define COEX_IPAN_ASSOC_LEVEL_FLAGS \ | ||
3330 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3331 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG | \ | ||
3332 | COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG) | ||
3333 | #define COEX_RSRVD1_FLAGS 0 | ||
3334 | #define COEX_RSRVD2_FLAGS 0 | ||
3335 | /* | ||
3336 | * COEX_CU_RF_ON is the event wrapping all radio ownership. | ||
3337 | * We need DELAY_MEDIUM_FREE_NTFY to let WiMAX disconnect from network. | ||
3338 | */ | ||
3339 | #define COEX_CU_RF_ON_FLAGS \ | ||
3340 | (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \ | ||
3341 | COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG | \ | ||
3342 | COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG) | ||
3343 | |||
3344 | |||
3345 | enum { | ||
3346 | /* un-association part */ | ||
3347 | COEX_UNASSOC_IDLE = 0, | ||
3348 | COEX_UNASSOC_MANUAL_SCAN = 1, | ||
3349 | COEX_UNASSOC_AUTO_SCAN = 2, | ||
3350 | /* calibration */ | ||
3351 | COEX_CALIBRATION = 3, | ||
3352 | COEX_PERIODIC_CALIBRATION = 4, | ||
3353 | /* connection */ | ||
3354 | COEX_CONNECTION_ESTAB = 5, | ||
3355 | /* association part */ | ||
3356 | COEX_ASSOCIATED_IDLE = 6, | ||
3357 | COEX_ASSOC_MANUAL_SCAN = 7, | ||
3358 | COEX_ASSOC_AUTO_SCAN = 8, | ||
3359 | COEX_ASSOC_ACTIVE_LEVEL = 9, | ||
3360 | /* RF ON/OFF */ | ||
3361 | COEX_RF_ON = 10, | ||
3362 | COEX_RF_OFF = 11, | ||
3363 | COEX_STAND_ALONE_DEBUG = 12, | ||
3364 | /* IPAN */ | ||
3365 | COEX_IPAN_ASSOC_LEVEL = 13, | ||
3366 | /* reserved */ | ||
3367 | COEX_RSRVD1 = 14, | ||
3368 | COEX_RSRVD2 = 15, | ||
3369 | COEX_NUM_OF_EVENTS = 16 | ||
3370 | }; | ||
3371 | |||
3372 | /* | ||
3373 | * Coexistence WIFI/WIMAX Command | ||
3374 | * COEX_PRIORITY_TABLE_CMD = 0x5a | ||
3375 | * | ||
3376 | */ | ||
3377 | struct iwl_wimax_coex_event_entry { | ||
3378 | u8 request_prio; | ||
3379 | u8 win_medium_prio; | ||
3380 | u8 reserved; | ||
3381 | u8 flags; | ||
3382 | } __packed; | ||
3383 | |||
3384 | /* COEX flag masks */ | ||
3385 | |||
3386 | /* Station table is valid */ | ||
3387 | #define COEX_FLAGS_STA_TABLE_VALID_MSK (0x1) | ||
3388 | /* UnMask wake up src at unassociated sleep */ | ||
3389 | #define COEX_FLAGS_UNASSOC_WA_UNMASK_MSK (0x4) | ||
3390 | /* UnMask wake up src at associated sleep */ | ||
3391 | #define COEX_FLAGS_ASSOC_WA_UNMASK_MSK (0x8) | ||
3392 | /* Enable CoEx feature. */ | ||
3393 | #define COEX_FLAGS_COEX_ENABLE_MSK (0x80) | ||
3394 | |||
3395 | struct iwl_wimax_coex_cmd { | ||
3396 | u8 flags; | ||
3397 | u8 reserved[3]; | ||
3398 | struct iwl_wimax_coex_event_entry sta_prio[COEX_NUM_OF_EVENTS]; | ||
3399 | } __packed; | ||
3400 | |||
3401 | /* | ||
3402 | * Coexistence MEDIUM NOTIFICATION | ||
3403 | * COEX_MEDIUM_NOTIFICATION = 0x5b | ||
3404 | * | ||
3405 | * notification from uCode to host to indicate medium changes | ||
3406 | * | ||
3407 | */ | ||
3408 | /* | ||
3409 | * status field | ||
3410 | * bit 0 - 2: medium status | ||
3411 | * bit 3: medium change indication | ||
3412 | * bit 4 - 31: reserved | ||
3413 | */ | ||
3414 | /* status option values, (0 - 2 bits) */ | ||
3415 | #define COEX_MEDIUM_BUSY (0x0) /* radio belongs to WiMAX */ | ||
3416 | #define COEX_MEDIUM_ACTIVE (0x1) /* radio belongs to WiFi */ | ||
3417 | #define COEX_MEDIUM_PRE_RELEASE (0x2) /* received radio release */ | ||
3418 | #define COEX_MEDIUM_MSK (0x7) | ||
3419 | |||
3420 | /* send notification status (1 bit) */ | ||
3421 | #define COEX_MEDIUM_CHANGED (0x8) | ||
3422 | #define COEX_MEDIUM_CHANGED_MSK (0x8) | ||
3423 | #define COEX_MEDIUM_SHIFT (3) | ||
3424 | |||
3425 | struct iwl_coex_medium_notification { | ||
3426 | __le32 status; | ||
3427 | __le32 events; | ||
3428 | } __packed; | ||
3429 | |||
3430 | /* | ||
3431 | * Coexistence EVENT Command | ||
3432 | * COEX_EVENT_CMD = 0x5c | ||
3433 | * | ||
3434 | * send from host to uCode for coex event request. | ||
3435 | */ | ||
3436 | /* flags options */ | ||
3437 | #define COEX_EVENT_REQUEST_MSK (0x1) | ||
3438 | |||
3439 | struct iwl_coex_event_cmd { | ||
3440 | u8 flags; | ||
3441 | u8 event; | ||
3442 | __le16 reserved; | ||
3443 | } __packed; | ||
3444 | |||
3445 | struct iwl_coex_event_resp { | ||
3446 | __le32 status; | ||
3447 | } __packed; | ||
3448 | |||
3449 | |||
3450 | /****************************************************************************** | ||
3451 | * Bluetooth Coexistence commands | ||
3452 | * | ||
3453 | *****************************************************************************/ | ||
3454 | |||
3455 | /* | ||
3456 | * BT Status notification | ||
3457 | * REPLY_BT_COEX_PROFILE_NOTIF = 0xce | ||
3458 | */ | ||
3459 | enum iwl_bt_coex_profile_traffic_load { | ||
3460 | IWL_BT_COEX_TRAFFIC_LOAD_NONE = 0, | ||
3461 | IWL_BT_COEX_TRAFFIC_LOAD_LOW = 1, | ||
3462 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH = 2, | ||
3463 | IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS = 3, | ||
3464 | /* | ||
3465 | * There are no more even though below is a u8, the | ||
3466 | * indication from the BT device only has two bits. | ||
3467 | */ | ||
3468 | }; | ||
3469 | |||
3470 | #define BT_SESSION_ACTIVITY_1_UART_MSG 0x1 | ||
3471 | #define BT_SESSION_ACTIVITY_2_UART_MSG 0x2 | ||
3472 | |||
3473 | /* BT UART message - Share Part (BT -> WiFi) */ | ||
3474 | #define BT_UART_MSG_FRAME1MSGTYPE_POS (0) | ||
3475 | #define BT_UART_MSG_FRAME1MSGTYPE_MSK \ | ||
3476 | (0x7 << BT_UART_MSG_FRAME1MSGTYPE_POS) | ||
3477 | #define BT_UART_MSG_FRAME1SSN_POS (3) | ||
3478 | #define BT_UART_MSG_FRAME1SSN_MSK \ | ||
3479 | (0x3 << BT_UART_MSG_FRAME1SSN_POS) | ||
3480 | #define BT_UART_MSG_FRAME1UPDATEREQ_POS (5) | ||
3481 | #define BT_UART_MSG_FRAME1UPDATEREQ_MSK \ | ||
3482 | (0x1 << BT_UART_MSG_FRAME1UPDATEREQ_POS) | ||
3483 | #define BT_UART_MSG_FRAME1RESERVED_POS (6) | ||
3484 | #define BT_UART_MSG_FRAME1RESERVED_MSK \ | ||
3485 | (0x3 << BT_UART_MSG_FRAME1RESERVED_POS) | ||
3486 | |||
3487 | #define BT_UART_MSG_FRAME2OPENCONNECTIONS_POS (0) | ||
3488 | #define BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK \ | ||
3489 | (0x3 << BT_UART_MSG_FRAME2OPENCONNECTIONS_POS) | ||
3490 | #define BT_UART_MSG_FRAME2TRAFFICLOAD_POS (2) | ||
3491 | #define BT_UART_MSG_FRAME2TRAFFICLOAD_MSK \ | ||
3492 | (0x3 << BT_UART_MSG_FRAME2TRAFFICLOAD_POS) | ||
3493 | #define BT_UART_MSG_FRAME2CHLSEQN_POS (4) | ||
3494 | #define BT_UART_MSG_FRAME2CHLSEQN_MSK \ | ||
3495 | (0x1 << BT_UART_MSG_FRAME2CHLSEQN_POS) | ||
3496 | #define BT_UART_MSG_FRAME2INBAND_POS (5) | ||
3497 | #define BT_UART_MSG_FRAME2INBAND_MSK \ | ||
3498 | (0x1 << BT_UART_MSG_FRAME2INBAND_POS) | ||
3499 | #define BT_UART_MSG_FRAME2RESERVED_POS (6) | ||
3500 | #define BT_UART_MSG_FRAME2RESERVED_MSK \ | ||
3501 | (0x3 << BT_UART_MSG_FRAME2RESERVED_POS) | ||
3502 | |||
3503 | #define BT_UART_MSG_FRAME3SCOESCO_POS (0) | ||
3504 | #define BT_UART_MSG_FRAME3SCOESCO_MSK \ | ||
3505 | (0x1 << BT_UART_MSG_FRAME3SCOESCO_POS) | ||
3506 | #define BT_UART_MSG_FRAME3SNIFF_POS (1) | ||
3507 | #define BT_UART_MSG_FRAME3SNIFF_MSK \ | ||
3508 | (0x1 << BT_UART_MSG_FRAME3SNIFF_POS) | ||
3509 | #define BT_UART_MSG_FRAME3A2DP_POS (2) | ||
3510 | #define BT_UART_MSG_FRAME3A2DP_MSK \ | ||
3511 | (0x1 << BT_UART_MSG_FRAME3A2DP_POS) | ||
3512 | #define BT_UART_MSG_FRAME3ACL_POS (3) | ||
3513 | #define BT_UART_MSG_FRAME3ACL_MSK \ | ||
3514 | (0x1 << BT_UART_MSG_FRAME3ACL_POS) | ||
3515 | #define BT_UART_MSG_FRAME3MASTER_POS (4) | ||
3516 | #define BT_UART_MSG_FRAME3MASTER_MSK \ | ||
3517 | (0x1 << BT_UART_MSG_FRAME3MASTER_POS) | ||
3518 | #define BT_UART_MSG_FRAME3OBEX_POS (5) | ||
3519 | #define BT_UART_MSG_FRAME3OBEX_MSK \ | ||
3520 | (0x1 << BT_UART_MSG_FRAME3OBEX_POS) | ||
3521 | #define BT_UART_MSG_FRAME3RESERVED_POS (6) | ||
3522 | #define BT_UART_MSG_FRAME3RESERVED_MSK \ | ||
3523 | (0x3 << BT_UART_MSG_FRAME3RESERVED_POS) | ||
3524 | |||
3525 | #define BT_UART_MSG_FRAME4IDLEDURATION_POS (0) | ||
3526 | #define BT_UART_MSG_FRAME4IDLEDURATION_MSK \ | ||
3527 | (0x3F << BT_UART_MSG_FRAME4IDLEDURATION_POS) | ||
3528 | #define BT_UART_MSG_FRAME4RESERVED_POS (6) | ||
3529 | #define BT_UART_MSG_FRAME4RESERVED_MSK \ | ||
3530 | (0x3 << BT_UART_MSG_FRAME4RESERVED_POS) | ||
3531 | |||
3532 | #define BT_UART_MSG_FRAME5TXACTIVITY_POS (0) | ||
3533 | #define BT_UART_MSG_FRAME5TXACTIVITY_MSK \ | ||
3534 | (0x3 << BT_UART_MSG_FRAME5TXACTIVITY_POS) | ||
3535 | #define BT_UART_MSG_FRAME5RXACTIVITY_POS (2) | ||
3536 | #define BT_UART_MSG_FRAME5RXACTIVITY_MSK \ | ||
3537 | (0x3 << BT_UART_MSG_FRAME5RXACTIVITY_POS) | ||
3538 | #define BT_UART_MSG_FRAME5ESCORETRANSMIT_POS (4) | ||
3539 | #define BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK \ | ||
3540 | (0x3 << BT_UART_MSG_FRAME5ESCORETRANSMIT_POS) | ||
3541 | #define BT_UART_MSG_FRAME5RESERVED_POS (6) | ||
3542 | #define BT_UART_MSG_FRAME5RESERVED_MSK \ | ||
3543 | (0x3 << BT_UART_MSG_FRAME5RESERVED_POS) | ||
3544 | |||
3545 | #define BT_UART_MSG_FRAME6SNIFFINTERVAL_POS (0) | ||
3546 | #define BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK \ | ||
3547 | (0x1F << BT_UART_MSG_FRAME6SNIFFINTERVAL_POS) | ||
3548 | #define BT_UART_MSG_FRAME6DISCOVERABLE_POS (5) | ||
3549 | #define BT_UART_MSG_FRAME6DISCOVERABLE_MSK \ | ||
3550 | (0x1 << BT_UART_MSG_FRAME6DISCOVERABLE_POS) | ||
3551 | #define BT_UART_MSG_FRAME6RESERVED_POS (6) | ||
3552 | #define BT_UART_MSG_FRAME6RESERVED_MSK \ | ||
3553 | (0x3 << BT_UART_MSG_FRAME6RESERVED_POS) | ||
3554 | |||
3555 | #define BT_UART_MSG_FRAME7SNIFFACTIVITY_POS (0) | ||
3556 | #define BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK \ | ||
3557 | (0x7 << BT_UART_MSG_FRAME7SNIFFACTIVITY_POS) | ||
3558 | #define BT_UART_MSG_FRAME7PAGE_POS (3) | ||
3559 | #define BT_UART_MSG_FRAME7PAGE_MSK \ | ||
3560 | (0x1 << BT_UART_MSG_FRAME7PAGE_POS) | ||
3561 | #define BT_UART_MSG_FRAME7INQUIRY_POS (4) | ||
3562 | #define BT_UART_MSG_FRAME7INQUIRY_MSK \ | ||
3563 | (0x1 << BT_UART_MSG_FRAME7INQUIRY_POS) | ||
3564 | #define BT_UART_MSG_FRAME7CONNECTABLE_POS (5) | ||
3565 | #define BT_UART_MSG_FRAME7CONNECTABLE_MSK \ | ||
3566 | (0x1 << BT_UART_MSG_FRAME7CONNECTABLE_POS) | ||
3567 | #define BT_UART_MSG_FRAME7RESERVED_POS (6) | ||
3568 | #define BT_UART_MSG_FRAME7RESERVED_MSK \ | ||
3569 | (0x3 << BT_UART_MSG_FRAME7RESERVED_POS) | ||
3570 | |||
3571 | /* BT Session Activity 2 UART message (BT -> WiFi) */ | ||
3572 | #define BT_UART_MSG_2_FRAME1RESERVED1_POS (5) | ||
3573 | #define BT_UART_MSG_2_FRAME1RESERVED1_MSK \ | ||
3574 | (0x1<<BT_UART_MSG_2_FRAME1RESERVED1_POS) | ||
3575 | #define BT_UART_MSG_2_FRAME1RESERVED2_POS (6) | ||
3576 | #define BT_UART_MSG_2_FRAME1RESERVED2_MSK \ | ||
3577 | (0x3<<BT_UART_MSG_2_FRAME1RESERVED2_POS) | ||
3578 | |||
3579 | #define BT_UART_MSG_2_FRAME2AGGTRAFFICLOAD_POS (0) | ||
3580 | #define BT_UART_MSG_2_FRAME2AGGTRAFFICLOAD_MSK \ | ||
3581 | (0x3F<<BT_UART_MSG_2_FRAME2AGGTRAFFICLOAD_POS) | ||
3582 | #define BT_UART_MSG_2_FRAME2RESERVED_POS (6) | ||
3583 | #define BT_UART_MSG_2_FRAME2RESERVED_MSK \ | ||
3584 | (0x3<<BT_UART_MSG_2_FRAME2RESERVED_POS) | ||
3585 | |||
3586 | #define BT_UART_MSG_2_FRAME3BRLASTTXPOWER_POS (0) | ||
3587 | #define BT_UART_MSG_2_FRAME3BRLASTTXPOWER_MSK \ | ||
3588 | (0xF<<BT_UART_MSG_2_FRAME3BRLASTTXPOWER_POS) | ||
3589 | #define BT_UART_MSG_2_FRAME3INQPAGESRMODE_POS (4) | ||
3590 | #define BT_UART_MSG_2_FRAME3INQPAGESRMODE_MSK \ | ||
3591 | (0x1<<BT_UART_MSG_2_FRAME3INQPAGESRMODE_POS) | ||
3592 | #define BT_UART_MSG_2_FRAME3LEMASTER_POS (5) | ||
3593 | #define BT_UART_MSG_2_FRAME3LEMASTER_MSK \ | ||
3594 | (0x1<<BT_UART_MSG_2_FRAME3LEMASTER_POS) | ||
3595 | #define BT_UART_MSG_2_FRAME3RESERVED_POS (6) | ||
3596 | #define BT_UART_MSG_2_FRAME3RESERVED_MSK \ | ||
3597 | (0x3<<BT_UART_MSG_2_FRAME3RESERVED_POS) | ||
3598 | |||
3599 | #define BT_UART_MSG_2_FRAME4LELASTTXPOWER_POS (0) | ||
3600 | #define BT_UART_MSG_2_FRAME4LELASTTXPOWER_MSK \ | ||
3601 | (0xF<<BT_UART_MSG_2_FRAME4LELASTTXPOWER_POS) | ||
3602 | #define BT_UART_MSG_2_FRAME4NUMLECONN_POS (4) | ||
3603 | #define BT_UART_MSG_2_FRAME4NUMLECONN_MSK \ | ||
3604 | (0x3<<BT_UART_MSG_2_FRAME4NUMLECONN_POS) | ||
3605 | #define BT_UART_MSG_2_FRAME4RESERVED_POS (6) | ||
3606 | #define BT_UART_MSG_2_FRAME4RESERVED_MSK \ | ||
3607 | (0x3<<BT_UART_MSG_2_FRAME4RESERVED_POS) | ||
3608 | |||
3609 | #define BT_UART_MSG_2_FRAME5BTMINRSSI_POS (0) | ||
3610 | #define BT_UART_MSG_2_FRAME5BTMINRSSI_MSK \ | ||
3611 | (0xF<<BT_UART_MSG_2_FRAME5BTMINRSSI_POS) | ||
3612 | #define BT_UART_MSG_2_FRAME5LESCANINITMODE_POS (4) | ||
3613 | #define BT_UART_MSG_2_FRAME5LESCANINITMODE_MSK \ | ||
3614 | (0x1<<BT_UART_MSG_2_FRAME5LESCANINITMODE_POS) | ||
3615 | #define BT_UART_MSG_2_FRAME5LEADVERMODE_POS (5) | ||
3616 | #define BT_UART_MSG_2_FRAME5LEADVERMODE_MSK \ | ||
3617 | (0x1<<BT_UART_MSG_2_FRAME5LEADVERMODE_POS) | ||
3618 | #define BT_UART_MSG_2_FRAME5RESERVED_POS (6) | ||
3619 | #define BT_UART_MSG_2_FRAME5RESERVED_MSK \ | ||
3620 | (0x3<<BT_UART_MSG_2_FRAME5RESERVED_POS) | ||
3621 | |||
3622 | #define BT_UART_MSG_2_FRAME6LECONNINTERVAL_POS (0) | ||
3623 | #define BT_UART_MSG_2_FRAME6LECONNINTERVAL_MSK \ | ||
3624 | (0x1F<<BT_UART_MSG_2_FRAME6LECONNINTERVAL_POS) | ||
3625 | #define BT_UART_MSG_2_FRAME6RFU_POS (5) | ||
3626 | #define BT_UART_MSG_2_FRAME6RFU_MSK \ | ||
3627 | (0x1<<BT_UART_MSG_2_FRAME6RFU_POS) | ||
3628 | #define BT_UART_MSG_2_FRAME6RESERVED_POS (6) | ||
3629 | #define BT_UART_MSG_2_FRAME6RESERVED_MSK \ | ||
3630 | (0x3<<BT_UART_MSG_2_FRAME6RESERVED_POS) | ||
3631 | |||
3632 | #define BT_UART_MSG_2_FRAME7LECONNSLAVELAT_POS (0) | ||
3633 | #define BT_UART_MSG_2_FRAME7LECONNSLAVELAT_MSK \ | ||
3634 | (0x7<<BT_UART_MSG_2_FRAME7LECONNSLAVELAT_POS) | ||
3635 | #define BT_UART_MSG_2_FRAME7LEPROFILE1_POS (3) | ||
3636 | #define BT_UART_MSG_2_FRAME7LEPROFILE1_MSK \ | ||
3637 | (0x1<<BT_UART_MSG_2_FRAME7LEPROFILE1_POS) | ||
3638 | #define BT_UART_MSG_2_FRAME7LEPROFILE2_POS (4) | ||
3639 | #define BT_UART_MSG_2_FRAME7LEPROFILE2_MSK \ | ||
3640 | (0x1<<BT_UART_MSG_2_FRAME7LEPROFILE2_POS) | ||
3641 | #define BT_UART_MSG_2_FRAME7LEPROFILEOTHER_POS (5) | ||
3642 | #define BT_UART_MSG_2_FRAME7LEPROFILEOTHER_MSK \ | ||
3643 | (0x1<<BT_UART_MSG_2_FRAME7LEPROFILEOTHER_POS) | ||
3644 | #define BT_UART_MSG_2_FRAME7RESERVED_POS (6) | ||
3645 | #define BT_UART_MSG_2_FRAME7RESERVED_MSK \ | ||
3646 | (0x3<<BT_UART_MSG_2_FRAME7RESERVED_POS) | ||
3647 | |||
3648 | |||
3649 | #define BT_ENABLE_REDUCED_TXPOWER_THRESHOLD (-62) | ||
3650 | #define BT_DISABLE_REDUCED_TXPOWER_THRESHOLD (-65) | ||
3651 | |||
3652 | struct iwl_bt_uart_msg { | ||
3653 | u8 header; | ||
3654 | u8 frame1; | ||
3655 | u8 frame2; | ||
3656 | u8 frame3; | ||
3657 | u8 frame4; | ||
3658 | u8 frame5; | ||
3659 | u8 frame6; | ||
3660 | u8 frame7; | ||
3661 | } __attribute__((packed)); | ||
3662 | |||
3663 | struct iwl_bt_coex_profile_notif { | ||
3664 | struct iwl_bt_uart_msg last_bt_uart_msg; | ||
3665 | u8 bt_status; /* 0 - off, 1 - on */ | ||
3666 | u8 bt_traffic_load; /* 0 .. 3? */ | ||
3667 | u8 bt_ci_compliance; /* 0 - not complied, 1 - complied */ | ||
3668 | u8 reserved; | ||
3669 | } __attribute__((packed)); | ||
3670 | |||
3671 | #define IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS 0 | ||
3672 | #define IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_MSK 0x1 | ||
3673 | #define IWL_BT_COEX_PRIO_TBL_PRIO_POS 1 | ||
3674 | #define IWL_BT_COEX_PRIO_TBL_PRIO_MASK 0x0e | ||
3675 | #define IWL_BT_COEX_PRIO_TBL_RESERVED_POS 4 | ||
3676 | #define IWL_BT_COEX_PRIO_TBL_RESERVED_MASK 0xf0 | ||
3677 | #define IWL_BT_COEX_PRIO_TBL_PRIO_SHIFT 1 | ||
3678 | |||
3679 | /* | ||
3680 | * BT Coexistence Priority table | ||
3681 | * REPLY_BT_COEX_PRIO_TABLE = 0xcc | ||
3682 | */ | ||
3683 | enum bt_coex_prio_table_events { | ||
3684 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB1 = 0, | ||
3685 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2 = 1, | ||
3686 | BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW1 = 2, | ||
3687 | BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW2 = 3, /* DC calib */ | ||
3688 | BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH1 = 4, | ||
3689 | BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH2 = 5, | ||
3690 | BT_COEX_PRIO_TBL_EVT_DTIM = 6, | ||
3691 | BT_COEX_PRIO_TBL_EVT_SCAN52 = 7, | ||
3692 | BT_COEX_PRIO_TBL_EVT_SCAN24 = 8, | ||
3693 | BT_COEX_PRIO_TBL_EVT_RESERVED0 = 9, | ||
3694 | BT_COEX_PRIO_TBL_EVT_RESERVED1 = 10, | ||
3695 | BT_COEX_PRIO_TBL_EVT_RESERVED2 = 11, | ||
3696 | BT_COEX_PRIO_TBL_EVT_RESERVED3 = 12, | ||
3697 | BT_COEX_PRIO_TBL_EVT_RESERVED4 = 13, | ||
3698 | BT_COEX_PRIO_TBL_EVT_RESERVED5 = 14, | ||
3699 | BT_COEX_PRIO_TBL_EVT_RESERVED6 = 15, | ||
3700 | /* BT_COEX_PRIO_TBL_EVT_MAX should always be last */ | ||
3701 | BT_COEX_PRIO_TBL_EVT_MAX, | ||
3702 | }; | ||
3703 | |||
3704 | enum bt_coex_prio_table_priorities { | ||
3705 | BT_COEX_PRIO_TBL_DISABLED = 0, | ||
3706 | BT_COEX_PRIO_TBL_PRIO_LOW = 1, | ||
3707 | BT_COEX_PRIO_TBL_PRIO_HIGH = 2, | ||
3708 | BT_COEX_PRIO_TBL_PRIO_BYPASS = 3, | ||
3709 | BT_COEX_PRIO_TBL_PRIO_COEX_OFF = 4, | ||
3710 | BT_COEX_PRIO_TBL_PRIO_COEX_ON = 5, | ||
3711 | BT_COEX_PRIO_TBL_PRIO_RSRVD1 = 6, | ||
3712 | BT_COEX_PRIO_TBL_PRIO_RSRVD2 = 7, | ||
3713 | BT_COEX_PRIO_TBL_MAX, | ||
3714 | }; | ||
3715 | |||
3716 | struct iwl_bt_coex_prio_table_cmd { | ||
3717 | u8 prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX]; | ||
3718 | } __attribute__((packed)); | ||
3719 | |||
3720 | #define IWL_BT_COEX_ENV_CLOSE 0 | ||
3721 | #define IWL_BT_COEX_ENV_OPEN 1 | ||
3722 | /* | ||
3723 | * BT Protection Envelope | ||
3724 | * REPLY_BT_COEX_PROT_ENV = 0xcd | ||
3725 | */ | ||
3726 | struct iwl_bt_coex_prot_env_cmd { | ||
3727 | u8 action; /* 0 = closed, 1 = open */ | ||
3728 | u8 type; /* 0 .. 15 */ | ||
3729 | u8 reserved[2]; | ||
3730 | } __attribute__((packed)); | ||
3731 | |||
3732 | /* | ||
3733 | * REPLY_D3_CONFIG | ||
3734 | */ | ||
3735 | enum iwlagn_d3_wakeup_filters { | ||
3736 | IWLAGN_D3_WAKEUP_RFKILL = BIT(0), | ||
3737 | IWLAGN_D3_WAKEUP_SYSASSERT = BIT(1), | ||
3738 | }; | ||
3739 | |||
3740 | struct iwlagn_d3_config_cmd { | ||
3741 | __le32 min_sleep_time; | ||
3742 | __le32 wakeup_flags; | ||
3743 | } __packed; | ||
3744 | |||
3745 | /* | ||
3746 | * REPLY_WOWLAN_PATTERNS | ||
3747 | */ | ||
3748 | #define IWLAGN_WOWLAN_MIN_PATTERN_LEN 16 | ||
3749 | #define IWLAGN_WOWLAN_MAX_PATTERN_LEN 128 | ||
3750 | |||
3751 | struct iwlagn_wowlan_pattern { | ||
3752 | u8 mask[IWLAGN_WOWLAN_MAX_PATTERN_LEN / 8]; | ||
3753 | u8 pattern[IWLAGN_WOWLAN_MAX_PATTERN_LEN]; | ||
3754 | u8 mask_size; | ||
3755 | u8 pattern_size; | ||
3756 | __le16 reserved; | ||
3757 | } __packed; | ||
3758 | |||
3759 | #define IWLAGN_WOWLAN_MAX_PATTERNS 20 | ||
3760 | |||
3761 | struct iwlagn_wowlan_patterns_cmd { | ||
3762 | __le32 n_patterns; | ||
3763 | struct iwlagn_wowlan_pattern patterns[]; | ||
3764 | } __packed; | ||
3765 | |||
3766 | /* | ||
3767 | * REPLY_WOWLAN_WAKEUP_FILTER | ||
3768 | */ | ||
3769 | enum iwlagn_wowlan_wakeup_filters { | ||
3770 | IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET = BIT(0), | ||
3771 | IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH = BIT(1), | ||
3772 | IWLAGN_WOWLAN_WAKEUP_BEACON_MISS = BIT(2), | ||
3773 | IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE = BIT(3), | ||
3774 | IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL = BIT(4), | ||
3775 | IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ = BIT(5), | ||
3776 | IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE = BIT(6), | ||
3777 | IWLAGN_WOWLAN_WAKEUP_ALWAYS = BIT(7), | ||
3778 | IWLAGN_WOWLAN_WAKEUP_ENABLE_NET_DETECT = BIT(8), | ||
3779 | }; | ||
3780 | |||
3781 | struct iwlagn_wowlan_wakeup_filter_cmd { | ||
3782 | __le32 enabled; | ||
3783 | __le16 non_qos_seq; | ||
3784 | __le16 reserved; | ||
3785 | __le16 qos_seq[8]; | ||
3786 | }; | ||
3787 | |||
3788 | /* | ||
3789 | * REPLY_WOWLAN_TSC_RSC_PARAMS | ||
3790 | */ | ||
3791 | #define IWLAGN_NUM_RSC 16 | ||
3792 | |||
3793 | struct tkip_sc { | ||
3794 | __le16 iv16; | ||
3795 | __le16 pad; | ||
3796 | __le32 iv32; | ||
3797 | } __packed; | ||
3798 | |||
3799 | struct iwlagn_tkip_rsc_tsc { | ||
3800 | struct tkip_sc unicast_rsc[IWLAGN_NUM_RSC]; | ||
3801 | struct tkip_sc multicast_rsc[IWLAGN_NUM_RSC]; | ||
3802 | struct tkip_sc tsc; | ||
3803 | } __packed; | ||
3804 | |||
3805 | struct aes_sc { | ||
3806 | __le64 pn; | ||
3807 | } __packed; | ||
3808 | |||
3809 | struct iwlagn_aes_rsc_tsc { | ||
3810 | struct aes_sc unicast_rsc[IWLAGN_NUM_RSC]; | ||
3811 | struct aes_sc multicast_rsc[IWLAGN_NUM_RSC]; | ||
3812 | struct aes_sc tsc; | ||
3813 | } __packed; | ||
3814 | |||
3815 | union iwlagn_all_tsc_rsc { | ||
3816 | struct iwlagn_tkip_rsc_tsc tkip; | ||
3817 | struct iwlagn_aes_rsc_tsc aes; | ||
3818 | }; | ||
3819 | |||
3820 | struct iwlagn_wowlan_rsc_tsc_params_cmd { | ||
3821 | union iwlagn_all_tsc_rsc all_tsc_rsc; | ||
3822 | } __packed; | ||
3823 | |||
3824 | /* | ||
3825 | * REPLY_WOWLAN_TKIP_PARAMS | ||
3826 | */ | ||
3827 | #define IWLAGN_MIC_KEY_SIZE 8 | ||
3828 | #define IWLAGN_P1K_SIZE 5 | ||
3829 | struct iwlagn_mic_keys { | ||
3830 | u8 tx[IWLAGN_MIC_KEY_SIZE]; | ||
3831 | u8 rx_unicast[IWLAGN_MIC_KEY_SIZE]; | ||
3832 | u8 rx_mcast[IWLAGN_MIC_KEY_SIZE]; | ||
3833 | } __packed; | ||
3834 | |||
3835 | struct iwlagn_p1k_cache { | ||
3836 | __le16 p1k[IWLAGN_P1K_SIZE]; | ||
3837 | } __packed; | ||
3838 | |||
3839 | #define IWLAGN_NUM_RX_P1K_CACHE 2 | ||
3840 | |||
3841 | struct iwlagn_wowlan_tkip_params_cmd { | ||
3842 | struct iwlagn_mic_keys mic_keys; | ||
3843 | struct iwlagn_p1k_cache tx; | ||
3844 | struct iwlagn_p1k_cache rx_uni[IWLAGN_NUM_RX_P1K_CACHE]; | ||
3845 | struct iwlagn_p1k_cache rx_multi[IWLAGN_NUM_RX_P1K_CACHE]; | ||
3846 | } __packed; | ||
3847 | |||
3848 | /* | ||
3849 | * REPLY_WOWLAN_KEK_KCK_MATERIAL | ||
3850 | */ | ||
3851 | |||
3852 | #define IWLAGN_KCK_MAX_SIZE 32 | ||
3853 | #define IWLAGN_KEK_MAX_SIZE 32 | ||
3854 | |||
3855 | struct iwlagn_wowlan_kek_kck_material_cmd { | ||
3856 | u8 kck[IWLAGN_KCK_MAX_SIZE]; | ||
3857 | u8 kek[IWLAGN_KEK_MAX_SIZE]; | ||
3858 | __le16 kck_len; | ||
3859 | __le16 kek_len; | ||
3860 | __le64 replay_ctr; | ||
3861 | } __packed; | ||
3862 | |||
3863 | /* | ||
3864 | * REPLY_WIPAN_PARAMS = 0xb2 (Commands and Notification) | ||
3865 | */ | ||
3866 | |||
3867 | /* | ||
3868 | * Minimum slot time in TU | ||
3869 | */ | ||
3870 | #define IWL_MIN_SLOT_TIME 20 | ||
3871 | |||
3872 | /** | ||
3873 | * struct iwl_wipan_slot | ||
3874 | * @width: Time in TU | ||
3875 | * @type: | ||
3876 | * 0 - BSS | ||
3877 | * 1 - PAN | ||
3878 | */ | ||
3879 | struct iwl_wipan_slot { | ||
3880 | __le16 width; | ||
3881 | u8 type; | ||
3882 | u8 reserved; | ||
3883 | } __packed; | ||
3884 | |||
3885 | #define IWL_WIPAN_PARAMS_FLG_LEAVE_CHANNEL_CTS BIT(1) /* reserved */ | ||
3886 | #define IWL_WIPAN_PARAMS_FLG_LEAVE_CHANNEL_QUIET BIT(2) /* reserved */ | ||
3887 | #define IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE BIT(3) /* reserved */ | ||
3888 | #define IWL_WIPAN_PARAMS_FLG_FILTER_BEACON_NOTIF BIT(4) | ||
3889 | #define IWL_WIPAN_PARAMS_FLG_FULL_SLOTTED_MODE BIT(5) | ||
3890 | |||
3891 | /** | ||
3892 | * struct iwl_wipan_params_cmd | ||
3893 | * @flags: | ||
3894 | * bit0: reserved | ||
3895 | * bit1: CP leave channel with CTS | ||
3896 | * bit2: CP leave channel qith Quiet | ||
3897 | * bit3: slotted mode | ||
3898 | * 1 - work in slotted mode | ||
3899 | * 0 - work in non slotted mode | ||
3900 | * bit4: filter beacon notification | ||
3901 | * bit5: full tx slotted mode. if this flag is set, | ||
3902 | * uCode will perform leaving channel methods in context switch | ||
3903 | * also when working in same channel mode | ||
3904 | * @num_slots: 1 - 10 | ||
3905 | */ | ||
3906 | struct iwl_wipan_params_cmd { | ||
3907 | __le16 flags; | ||
3908 | u8 reserved; | ||
3909 | u8 num_slots; | ||
3910 | struct iwl_wipan_slot slots[10]; | ||
3911 | } __packed; | ||
3912 | |||
3913 | /* | ||
3914 | * REPLY_WIPAN_P2P_CHANNEL_SWITCH = 0xb9 | ||
3915 | * | ||
3916 | * TODO: Figure out what this is used for, | ||
3917 | * it can only switch between 2.4 GHz | ||
3918 | * channels!! | ||
3919 | */ | ||
3920 | |||
3921 | struct iwl_wipan_p2p_channel_switch_cmd { | ||
3922 | __le16 channel; | ||
3923 | __le16 reserved; | ||
3924 | }; | ||
3925 | |||
3926 | /* | ||
3927 | * REPLY_WIPAN_NOA_NOTIFICATION = 0xbc | ||
3928 | * | ||
3929 | * This is used by the device to notify us of the | ||
3930 | * NoA schedule it determined so we can forward it | ||
3931 | * to userspace for inclusion in probe responses. | ||
3932 | * | ||
3933 | * In beacons, the NoA schedule is simply appended | ||
3934 | * to the frame we give the device. | ||
3935 | */ | ||
3936 | |||
3937 | struct iwl_wipan_noa_descriptor { | ||
3938 | u8 count; | ||
3939 | __le32 duration; | ||
3940 | __le32 interval; | ||
3941 | __le32 starttime; | ||
3942 | } __packed; | ||
3943 | |||
3944 | struct iwl_wipan_noa_attribute { | ||
3945 | u8 id; | ||
3946 | __le16 length; | ||
3947 | u8 index; | ||
3948 | u8 ct_window; | ||
3949 | struct iwl_wipan_noa_descriptor descr0, descr1; | ||
3950 | u8 reserved; | ||
3951 | } __packed; | ||
3952 | |||
3953 | struct iwl_wipan_noa_notification { | ||
3954 | u32 noa_active; | ||
3955 | struct iwl_wipan_noa_attribute noa_attribute; | ||
3956 | } __packed; | ||
3957 | |||
3958 | #endif /* __iwl_commands_h__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c new file mode 100644 index 000000000000..8a2d9e643b14 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c | |||
@@ -0,0 +1,2426 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * GPL LICENSE SUMMARY | ||
4 | * | ||
5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of version 2 of the GNU General Public License as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
19 | * USA | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called LICENSE.GPL. | ||
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 | |||
29 | #include <linux/slab.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/debugfs.h> | ||
33 | #include <linux/ieee80211.h> | ||
34 | #include <net/mac80211.h> | ||
35 | #include "iwl-debug.h" | ||
36 | #include "iwl-io.h" | ||
37 | #include "dev.h" | ||
38 | #include "agn.h" | ||
39 | |||
40 | /* create and remove of files */ | ||
41 | #define DEBUGFS_ADD_FILE(name, parent, mode) do { \ | ||
42 | if (!debugfs_create_file(#name, mode, parent, priv, \ | ||
43 | &iwl_dbgfs_##name##_ops)) \ | ||
44 | goto err; \ | ||
45 | } while (0) | ||
46 | |||
47 | #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \ | ||
48 | struct dentry *__tmp; \ | ||
49 | __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \ | ||
50 | parent, ptr); \ | ||
51 | if (IS_ERR(__tmp) || !__tmp) \ | ||
52 | goto err; \ | ||
53 | } while (0) | ||
54 | |||
55 | #define DEBUGFS_ADD_X32(name, parent, ptr) do { \ | ||
56 | struct dentry *__tmp; \ | ||
57 | __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \ | ||
58 | parent, ptr); \ | ||
59 | if (IS_ERR(__tmp) || !__tmp) \ | ||
60 | goto err; \ | ||
61 | } while (0) | ||
62 | |||
63 | #define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \ | ||
64 | struct dentry *__tmp; \ | ||
65 | __tmp = debugfs_create_u32(#name, mode, \ | ||
66 | parent, ptr); \ | ||
67 | if (IS_ERR(__tmp) || !__tmp) \ | ||
68 | goto err; \ | ||
69 | } while (0) | ||
70 | |||
71 | /* file operation */ | ||
72 | #define DEBUGFS_READ_FUNC(name) \ | ||
73 | static ssize_t iwl_dbgfs_##name##_read(struct file *file, \ | ||
74 | char __user *user_buf, \ | ||
75 | size_t count, loff_t *ppos); | ||
76 | |||
77 | #define DEBUGFS_WRITE_FUNC(name) \ | ||
78 | static ssize_t iwl_dbgfs_##name##_write(struct file *file, \ | ||
79 | const char __user *user_buf, \ | ||
80 | size_t count, loff_t *ppos); | ||
81 | |||
82 | |||
83 | #define DEBUGFS_READ_FILE_OPS(name) \ | ||
84 | DEBUGFS_READ_FUNC(name); \ | ||
85 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | ||
86 | .read = iwl_dbgfs_##name##_read, \ | ||
87 | .open = simple_open, \ | ||
88 | .llseek = generic_file_llseek, \ | ||
89 | }; | ||
90 | |||
91 | #define DEBUGFS_WRITE_FILE_OPS(name) \ | ||
92 | DEBUGFS_WRITE_FUNC(name); \ | ||
93 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | ||
94 | .write = iwl_dbgfs_##name##_write, \ | ||
95 | .open = simple_open, \ | ||
96 | .llseek = generic_file_llseek, \ | ||
97 | }; | ||
98 | |||
99 | |||
100 | #define DEBUGFS_READ_WRITE_FILE_OPS(name) \ | ||
101 | DEBUGFS_READ_FUNC(name); \ | ||
102 | DEBUGFS_WRITE_FUNC(name); \ | ||
103 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | ||
104 | .write = iwl_dbgfs_##name##_write, \ | ||
105 | .read = iwl_dbgfs_##name##_read, \ | ||
106 | .open = simple_open, \ | ||
107 | .llseek = generic_file_llseek, \ | ||
108 | }; | ||
109 | |||
110 | static ssize_t iwl_dbgfs_sram_read(struct file *file, | ||
111 | char __user *user_buf, | ||
112 | size_t count, loff_t *ppos) | ||
113 | { | ||
114 | u32 val = 0; | ||
115 | char *buf; | ||
116 | ssize_t ret; | ||
117 | int i = 0; | ||
118 | bool device_format = false; | ||
119 | int offset = 0; | ||
120 | int len = 0; | ||
121 | int pos = 0; | ||
122 | int sram; | ||
123 | struct iwl_priv *priv = file->private_data; | ||
124 | const struct fw_img *img; | ||
125 | size_t bufsz; | ||
126 | |||
127 | /* default is to dump the entire data segment */ | ||
128 | if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) { | ||
129 | priv->dbgfs_sram_offset = 0x800000; | ||
130 | if (!priv->ucode_loaded) | ||
131 | return -EINVAL; | ||
132 | img = &priv->fw->img[priv->cur_ucode]; | ||
133 | priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len; | ||
134 | } | ||
135 | len = priv->dbgfs_sram_len; | ||
136 | |||
137 | if (len == -4) { | ||
138 | device_format = true; | ||
139 | len = 4; | ||
140 | } | ||
141 | |||
142 | bufsz = 50 + len * 4; | ||
143 | buf = kmalloc(bufsz, GFP_KERNEL); | ||
144 | if (!buf) | ||
145 | return -ENOMEM; | ||
146 | |||
147 | pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", | ||
148 | len); | ||
149 | pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", | ||
150 | priv->dbgfs_sram_offset); | ||
151 | |||
152 | /* adjust sram address since reads are only on even u32 boundaries */ | ||
153 | offset = priv->dbgfs_sram_offset & 0x3; | ||
154 | sram = priv->dbgfs_sram_offset & ~0x3; | ||
155 | |||
156 | /* read the first u32 from sram */ | ||
157 | val = iwl_read_targ_mem(priv->trans, sram); | ||
158 | |||
159 | for (; len; len--) { | ||
160 | /* put the address at the start of every line */ | ||
161 | if (i == 0) | ||
162 | pos += scnprintf(buf + pos, bufsz - pos, | ||
163 | "%08X: ", sram + offset); | ||
164 | |||
165 | if (device_format) | ||
166 | pos += scnprintf(buf + pos, bufsz - pos, | ||
167 | "%02x", (val >> (8 * (3 - offset))) & 0xff); | ||
168 | else | ||
169 | pos += scnprintf(buf + pos, bufsz - pos, | ||
170 | "%02x ", (val >> (8 * offset)) & 0xff); | ||
171 | |||
172 | /* if all bytes processed, read the next u32 from sram */ | ||
173 | if (++offset == 4) { | ||
174 | sram += 4; | ||
175 | offset = 0; | ||
176 | val = iwl_read_targ_mem(priv->trans, sram); | ||
177 | } | ||
178 | |||
179 | /* put in extra spaces and split lines for human readability */ | ||
180 | if (++i == 16) { | ||
181 | i = 0; | ||
182 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
183 | } else if (!(i & 7)) { | ||
184 | pos += scnprintf(buf + pos, bufsz - pos, " "); | ||
185 | } else if (!(i & 3)) { | ||
186 | pos += scnprintf(buf + pos, bufsz - pos, " "); | ||
187 | } | ||
188 | } | ||
189 | if (i) | ||
190 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
191 | |||
192 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
193 | kfree(buf); | ||
194 | return ret; | ||
195 | } | ||
196 | |||
197 | static ssize_t iwl_dbgfs_sram_write(struct file *file, | ||
198 | const char __user *user_buf, | ||
199 | size_t count, loff_t *ppos) | ||
200 | { | ||
201 | struct iwl_priv *priv = file->private_data; | ||
202 | char buf[64]; | ||
203 | int buf_size; | ||
204 | u32 offset, len; | ||
205 | |||
206 | memset(buf, 0, sizeof(buf)); | ||
207 | buf_size = min(count, sizeof(buf) - 1); | ||
208 | if (copy_from_user(buf, user_buf, buf_size)) | ||
209 | return -EFAULT; | ||
210 | |||
211 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { | ||
212 | priv->dbgfs_sram_offset = offset; | ||
213 | priv->dbgfs_sram_len = len; | ||
214 | } else if (sscanf(buf, "%x", &offset) == 1) { | ||
215 | priv->dbgfs_sram_offset = offset; | ||
216 | priv->dbgfs_sram_len = -4; | ||
217 | } else { | ||
218 | priv->dbgfs_sram_offset = 0; | ||
219 | priv->dbgfs_sram_len = 0; | ||
220 | } | ||
221 | |||
222 | return count; | ||
223 | } | ||
224 | |||
225 | static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file, | ||
226 | char __user *user_buf, | ||
227 | size_t count, loff_t *ppos) | ||
228 | { | ||
229 | struct iwl_priv *priv = file->private_data; | ||
230 | const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN]; | ||
231 | |||
232 | if (!priv->wowlan_sram) | ||
233 | return -ENODATA; | ||
234 | |||
235 | return simple_read_from_buffer(user_buf, count, ppos, | ||
236 | priv->wowlan_sram, | ||
237 | img->sec[IWL_UCODE_SECTION_DATA].len); | ||
238 | } | ||
239 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, | ||
240 | size_t count, loff_t *ppos) | ||
241 | { | ||
242 | struct iwl_priv *priv = file->private_data; | ||
243 | struct iwl_station_entry *station; | ||
244 | struct iwl_tid_data *tid_data; | ||
245 | char *buf; | ||
246 | int i, j, pos = 0; | ||
247 | ssize_t ret; | ||
248 | /* Add 30 for initial string */ | ||
249 | const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations); | ||
250 | |||
251 | buf = kmalloc(bufsz, GFP_KERNEL); | ||
252 | if (!buf) | ||
253 | return -ENOMEM; | ||
254 | |||
255 | pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n", | ||
256 | priv->num_stations); | ||
257 | |||
258 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
259 | station = &priv->stations[i]; | ||
260 | if (!station->used) | ||
261 | continue; | ||
262 | pos += scnprintf(buf + pos, bufsz - pos, | ||
263 | "station %d - addr: %pM, flags: %#x\n", | ||
264 | i, station->sta.sta.addr, | ||
265 | station->sta.station_flags_msk); | ||
266 | pos += scnprintf(buf + pos, bufsz - pos, | ||
267 | "TID seqno next_rclmd " | ||
268 | "rate_n_flags state txq\n"); | ||
269 | |||
270 | for (j = 0; j < IWL_MAX_TID_COUNT; j++) { | ||
271 | tid_data = &priv->tid_data[i][j]; | ||
272 | pos += scnprintf(buf + pos, bufsz - pos, | ||
273 | "%d: 0x%.4x 0x%.4x 0x%.8x " | ||
274 | "%d %.2d", | ||
275 | j, tid_data->seq_number, | ||
276 | tid_data->next_reclaimed, | ||
277 | tid_data->agg.rate_n_flags, | ||
278 | tid_data->agg.state, | ||
279 | tid_data->agg.txq_id); | ||
280 | |||
281 | if (tid_data->agg.wait_for_ba) | ||
282 | pos += scnprintf(buf + pos, bufsz - pos, | ||
283 | " - waitforba"); | ||
284 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
285 | } | ||
286 | |||
287 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
288 | } | ||
289 | |||
290 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
291 | kfree(buf); | ||
292 | return ret; | ||
293 | } | ||
294 | |||
295 | static ssize_t iwl_dbgfs_nvm_read(struct file *file, | ||
296 | char __user *user_buf, | ||
297 | size_t count, | ||
298 | loff_t *ppos) | ||
299 | { | ||
300 | ssize_t ret; | ||
301 | struct iwl_priv *priv = file->private_data; | ||
302 | int pos = 0, ofs = 0, buf_size = 0; | ||
303 | const u8 *ptr; | ||
304 | char *buf; | ||
305 | u16 eeprom_ver; | ||
306 | size_t eeprom_len = priv->eeprom_blob_size; | ||
307 | buf_size = 4 * eeprom_len + 256; | ||
308 | |||
309 | if (eeprom_len % 16) | ||
310 | return -ENODATA; | ||
311 | |||
312 | ptr = priv->eeprom_blob; | ||
313 | if (!ptr) | ||
314 | return -ENOMEM; | ||
315 | |||
316 | /* 4 characters for byte 0xYY */ | ||
317 | buf = kzalloc(buf_size, GFP_KERNEL); | ||
318 | if (!buf) | ||
319 | return -ENOMEM; | ||
320 | |||
321 | eeprom_ver = priv->eeprom_data->eeprom_version; | ||
322 | pos += scnprintf(buf + pos, buf_size - pos, | ||
323 | "NVM version: 0x%x\n", eeprom_ver); | ||
324 | for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) { | ||
325 | pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs); | ||
326 | hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos, | ||
327 | buf_size - pos, 0); | ||
328 | pos += strlen(buf + pos); | ||
329 | if (buf_size - pos > 0) | ||
330 | buf[pos++] = '\n'; | ||
331 | } | ||
332 | |||
333 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
334 | kfree(buf); | ||
335 | return ret; | ||
336 | } | ||
337 | |||
338 | static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf, | ||
339 | size_t count, loff_t *ppos) | ||
340 | { | ||
341 | struct iwl_priv *priv = file->private_data; | ||
342 | struct ieee80211_channel *channels = NULL; | ||
343 | const struct ieee80211_supported_band *supp_band = NULL; | ||
344 | int pos = 0, i, bufsz = PAGE_SIZE; | ||
345 | char *buf; | ||
346 | ssize_t ret; | ||
347 | |||
348 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
349 | if (!buf) | ||
350 | return -ENOMEM; | ||
351 | |||
352 | supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ); | ||
353 | if (supp_band) { | ||
354 | channels = supp_band->channels; | ||
355 | |||
356 | pos += scnprintf(buf + pos, bufsz - pos, | ||
357 | "Displaying %d channels in 2.4GHz band 802.11bg):\n", | ||
358 | supp_band->n_channels); | ||
359 | |||
360 | for (i = 0; i < supp_band->n_channels; i++) | ||
361 | pos += scnprintf(buf + pos, bufsz - pos, | ||
362 | "%d: %ddBm: BSS%s%s, %s.\n", | ||
363 | channels[i].hw_value, | ||
364 | channels[i].max_power, | ||
365 | channels[i].flags & IEEE80211_CHAN_RADAR ? | ||
366 | " (IEEE 802.11h required)" : "", | ||
367 | ((channels[i].flags & IEEE80211_CHAN_NO_IBSS) | ||
368 | || (channels[i].flags & | ||
369 | IEEE80211_CHAN_RADAR)) ? "" : | ||
370 | ", IBSS", | ||
371 | channels[i].flags & | ||
372 | IEEE80211_CHAN_PASSIVE_SCAN ? | ||
373 | "passive only" : "active/passive"); | ||
374 | } | ||
375 | supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ); | ||
376 | if (supp_band) { | ||
377 | channels = supp_band->channels; | ||
378 | |||
379 | pos += scnprintf(buf + pos, bufsz - pos, | ||
380 | "Displaying %d channels in 5.2GHz band (802.11a)\n", | ||
381 | supp_band->n_channels); | ||
382 | |||
383 | for (i = 0; i < supp_band->n_channels; i++) | ||
384 | pos += scnprintf(buf + pos, bufsz - pos, | ||
385 | "%d: %ddBm: BSS%s%s, %s.\n", | ||
386 | channels[i].hw_value, | ||
387 | channels[i].max_power, | ||
388 | channels[i].flags & IEEE80211_CHAN_RADAR ? | ||
389 | " (IEEE 802.11h required)" : "", | ||
390 | ((channels[i].flags & IEEE80211_CHAN_NO_IBSS) | ||
391 | || (channels[i].flags & | ||
392 | IEEE80211_CHAN_RADAR)) ? "" : | ||
393 | ", IBSS", | ||
394 | channels[i].flags & | ||
395 | IEEE80211_CHAN_PASSIVE_SCAN ? | ||
396 | "passive only" : "active/passive"); | ||
397 | } | ||
398 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
399 | kfree(buf); | ||
400 | return ret; | ||
401 | } | ||
402 | |||
403 | static ssize_t iwl_dbgfs_status_read(struct file *file, | ||
404 | char __user *user_buf, | ||
405 | size_t count, loff_t *ppos) { | ||
406 | |||
407 | struct iwl_priv *priv = file->private_data; | ||
408 | char buf[512]; | ||
409 | int pos = 0; | ||
410 | const size_t bufsz = sizeof(buf); | ||
411 | |||
412 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n", | ||
413 | test_bit(STATUS_RF_KILL_HW, &priv->status)); | ||
414 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n", | ||
415 | test_bit(STATUS_CT_KILL, &priv->status)); | ||
416 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n", | ||
417 | test_bit(STATUS_ALIVE, &priv->status)); | ||
418 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n", | ||
419 | test_bit(STATUS_READY, &priv->status)); | ||
420 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n", | ||
421 | test_bit(STATUS_EXIT_PENDING, &priv->status)); | ||
422 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n", | ||
423 | test_bit(STATUS_STATISTICS, &priv->status)); | ||
424 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n", | ||
425 | test_bit(STATUS_SCANNING, &priv->status)); | ||
426 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n", | ||
427 | test_bit(STATUS_SCAN_ABORTING, &priv->status)); | ||
428 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n", | ||
429 | test_bit(STATUS_SCAN_HW, &priv->status)); | ||
430 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n", | ||
431 | test_bit(STATUS_POWER_PMI, &priv->status)); | ||
432 | pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n", | ||
433 | test_bit(STATUS_FW_ERROR, &priv->status)); | ||
434 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
435 | } | ||
436 | |||
437 | static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file, | ||
438 | char __user *user_buf, | ||
439 | size_t count, loff_t *ppos) { | ||
440 | |||
441 | struct iwl_priv *priv = file->private_data; | ||
442 | |||
443 | int pos = 0; | ||
444 | int cnt = 0; | ||
445 | char *buf; | ||
446 | int bufsz = 24 * 64; /* 24 items * 64 char per item */ | ||
447 | ssize_t ret; | ||
448 | |||
449 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
450 | if (!buf) | ||
451 | return -ENOMEM; | ||
452 | |||
453 | for (cnt = 0; cnt < REPLY_MAX; cnt++) { | ||
454 | if (priv->rx_handlers_stats[cnt] > 0) | ||
455 | pos += scnprintf(buf + pos, bufsz - pos, | ||
456 | "\tRx handler[%36s]:\t\t %u\n", | ||
457 | iwl_dvm_get_cmd_string(cnt), | ||
458 | priv->rx_handlers_stats[cnt]); | ||
459 | } | ||
460 | |||
461 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
462 | kfree(buf); | ||
463 | return ret; | ||
464 | } | ||
465 | |||
466 | static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file, | ||
467 | const char __user *user_buf, | ||
468 | size_t count, loff_t *ppos) | ||
469 | { | ||
470 | struct iwl_priv *priv = file->private_data; | ||
471 | |||
472 | char buf[8]; | ||
473 | int buf_size; | ||
474 | u32 reset_flag; | ||
475 | |||
476 | memset(buf, 0, sizeof(buf)); | ||
477 | buf_size = min(count, sizeof(buf) - 1); | ||
478 | if (copy_from_user(buf, user_buf, buf_size)) | ||
479 | return -EFAULT; | ||
480 | if (sscanf(buf, "%x", &reset_flag) != 1) | ||
481 | return -EFAULT; | ||
482 | if (reset_flag == 0) | ||
483 | memset(&priv->rx_handlers_stats[0], 0, | ||
484 | sizeof(priv->rx_handlers_stats)); | ||
485 | |||
486 | return count; | ||
487 | } | ||
488 | |||
489 | static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf, | ||
490 | size_t count, loff_t *ppos) | ||
491 | { | ||
492 | struct iwl_priv *priv = file->private_data; | ||
493 | struct iwl_rxon_context *ctx; | ||
494 | int pos = 0, i; | ||
495 | char buf[256 * NUM_IWL_RXON_CTX]; | ||
496 | const size_t bufsz = sizeof(buf); | ||
497 | |||
498 | for_each_context(priv, ctx) { | ||
499 | pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n", | ||
500 | ctx->ctxid); | ||
501 | for (i = 0; i < AC_NUM; i++) { | ||
502 | pos += scnprintf(buf + pos, bufsz - pos, | ||
503 | "\tcw_min\tcw_max\taifsn\ttxop\n"); | ||
504 | pos += scnprintf(buf + pos, bufsz - pos, | ||
505 | "AC[%d]\t%u\t%u\t%u\t%u\n", i, | ||
506 | ctx->qos_data.def_qos_parm.ac[i].cw_min, | ||
507 | ctx->qos_data.def_qos_parm.ac[i].cw_max, | ||
508 | ctx->qos_data.def_qos_parm.ac[i].aifsn, | ||
509 | ctx->qos_data.def_qos_parm.ac[i].edca_txop); | ||
510 | } | ||
511 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
512 | } | ||
513 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
514 | } | ||
515 | |||
516 | static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file, | ||
517 | char __user *user_buf, | ||
518 | size_t count, loff_t *ppos) | ||
519 | { | ||
520 | struct iwl_priv *priv = file->private_data; | ||
521 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
522 | struct iwl_tt_restriction *restriction; | ||
523 | char buf[100]; | ||
524 | int pos = 0; | ||
525 | const size_t bufsz = sizeof(buf); | ||
526 | |||
527 | pos += scnprintf(buf + pos, bufsz - pos, | ||
528 | "Thermal Throttling Mode: %s\n", | ||
529 | tt->advanced_tt ? "Advance" : "Legacy"); | ||
530 | pos += scnprintf(buf + pos, bufsz - pos, | ||
531 | "Thermal Throttling State: %d\n", | ||
532 | tt->state); | ||
533 | if (tt->advanced_tt) { | ||
534 | restriction = tt->restriction + tt->state; | ||
535 | pos += scnprintf(buf + pos, bufsz - pos, | ||
536 | "Tx mode: %d\n", | ||
537 | restriction->tx_stream); | ||
538 | pos += scnprintf(buf + pos, bufsz - pos, | ||
539 | "Rx mode: %d\n", | ||
540 | restriction->rx_stream); | ||
541 | pos += scnprintf(buf + pos, bufsz - pos, | ||
542 | "HT mode: %d\n", | ||
543 | restriction->is_ht); | ||
544 | } | ||
545 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
546 | } | ||
547 | |||
548 | static ssize_t iwl_dbgfs_disable_ht40_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 | int ht40; | ||
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, "%d", &ht40) != 1) | ||
562 | return -EFAULT; | ||
563 | if (!iwl_is_any_associated(priv)) | ||
564 | priv->disable_ht40 = ht40 ? true : false; | ||
565 | else | ||
566 | return -EINVAL; | ||
567 | |||
568 | return count; | ||
569 | } | ||
570 | |||
571 | static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file, | ||
572 | char __user *user_buf, | ||
573 | size_t count, loff_t *ppos) | ||
574 | { | ||
575 | struct iwl_priv *priv = file->private_data; | ||
576 | char buf[100]; | ||
577 | int pos = 0; | ||
578 | const size_t bufsz = sizeof(buf); | ||
579 | |||
580 | pos += scnprintf(buf + pos, bufsz - pos, | ||
581 | "11n 40MHz Mode: %s\n", | ||
582 | priv->disable_ht40 ? "Disabled" : "Enabled"); | ||
583 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
584 | } | ||
585 | |||
586 | static ssize_t iwl_dbgfs_temperature_read(struct file *file, | ||
587 | char __user *user_buf, | ||
588 | size_t count, loff_t *ppos) | ||
589 | { | ||
590 | struct iwl_priv *priv = file->private_data; | ||
591 | char buf[8]; | ||
592 | int pos = 0; | ||
593 | const size_t bufsz = sizeof(buf); | ||
594 | |||
595 | pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature); | ||
596 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
597 | } | ||
598 | |||
599 | |||
600 | static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file, | ||
601 | const char __user *user_buf, | ||
602 | size_t count, loff_t *ppos) | ||
603 | { | ||
604 | struct iwl_priv *priv = file->private_data; | ||
605 | char buf[8]; | ||
606 | int buf_size; | ||
607 | int value; | ||
608 | |||
609 | memset(buf, 0, sizeof(buf)); | ||
610 | buf_size = min(count, sizeof(buf) - 1); | ||
611 | if (copy_from_user(buf, user_buf, buf_size)) | ||
612 | return -EFAULT; | ||
613 | |||
614 | if (sscanf(buf, "%d", &value) != 1) | ||
615 | return -EINVAL; | ||
616 | |||
617 | /* | ||
618 | * Our users expect 0 to be "CAM", but 0 isn't actually | ||
619 | * valid here. However, let's not confuse them and present | ||
620 | * IWL_POWER_INDEX_1 as "1", not "0". | ||
621 | */ | ||
622 | if (value == 0) | ||
623 | return -EINVAL; | ||
624 | else if (value > 0) | ||
625 | value -= 1; | ||
626 | |||
627 | if (value != -1 && (value < 0 || value >= IWL_POWER_NUM)) | ||
628 | return -EINVAL; | ||
629 | |||
630 | if (!iwl_is_ready_rf(priv)) | ||
631 | return -EAGAIN; | ||
632 | |||
633 | priv->power_data.debug_sleep_level_override = value; | ||
634 | |||
635 | mutex_lock(&priv->mutex); | ||
636 | iwl_power_update_mode(priv, true); | ||
637 | mutex_unlock(&priv->mutex); | ||
638 | |||
639 | return count; | ||
640 | } | ||
641 | |||
642 | static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file, | ||
643 | char __user *user_buf, | ||
644 | size_t count, loff_t *ppos) | ||
645 | { | ||
646 | struct iwl_priv *priv = file->private_data; | ||
647 | char buf[10]; | ||
648 | int pos, value; | ||
649 | const size_t bufsz = sizeof(buf); | ||
650 | |||
651 | /* see the write function */ | ||
652 | value = priv->power_data.debug_sleep_level_override; | ||
653 | if (value >= 0) | ||
654 | value += 1; | ||
655 | |||
656 | pos = scnprintf(buf, bufsz, "%d\n", value); | ||
657 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
658 | } | ||
659 | |||
660 | static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file, | ||
661 | char __user *user_buf, | ||
662 | size_t count, loff_t *ppos) | ||
663 | { | ||
664 | struct iwl_priv *priv = file->private_data; | ||
665 | char buf[200]; | ||
666 | int pos = 0, i; | ||
667 | const size_t bufsz = sizeof(buf); | ||
668 | struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd; | ||
669 | |||
670 | pos += scnprintf(buf + pos, bufsz - pos, | ||
671 | "flags: %#.2x\n", le16_to_cpu(cmd->flags)); | ||
672 | pos += scnprintf(buf + pos, bufsz - pos, | ||
673 | "RX/TX timeout: %d/%d usec\n", | ||
674 | le32_to_cpu(cmd->rx_data_timeout), | ||
675 | le32_to_cpu(cmd->tx_data_timeout)); | ||
676 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) | ||
677 | pos += scnprintf(buf + pos, bufsz - pos, | ||
678 | "sleep_interval[%d]: %d\n", i, | ||
679 | le32_to_cpu(cmd->sleep_interval[i])); | ||
680 | |||
681 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
682 | } | ||
683 | |||
684 | DEBUGFS_READ_WRITE_FILE_OPS(sram); | ||
685 | DEBUGFS_READ_FILE_OPS(wowlan_sram); | ||
686 | DEBUGFS_READ_FILE_OPS(nvm); | ||
687 | DEBUGFS_READ_FILE_OPS(stations); | ||
688 | DEBUGFS_READ_FILE_OPS(channels); | ||
689 | DEBUGFS_READ_FILE_OPS(status); | ||
690 | DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers); | ||
691 | DEBUGFS_READ_FILE_OPS(qos); | ||
692 | DEBUGFS_READ_FILE_OPS(thermal_throttling); | ||
693 | DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40); | ||
694 | DEBUGFS_READ_FILE_OPS(temperature); | ||
695 | DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override); | ||
696 | DEBUGFS_READ_FILE_OPS(current_sleep_command); | ||
697 | |||
698 | static const char *fmt_value = " %-30s %10u\n"; | ||
699 | static const char *fmt_hex = " %-30s 0x%02X\n"; | ||
700 | static const char *fmt_table = " %-30s %10u %10u %10u %10u\n"; | ||
701 | static const char *fmt_header = | ||
702 | "%-32s current cumulative delta max\n"; | ||
703 | |||
704 | static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz) | ||
705 | { | ||
706 | int p = 0; | ||
707 | u32 flag; | ||
708 | |||
709 | lockdep_assert_held(&priv->statistics.lock); | ||
710 | |||
711 | flag = le32_to_cpu(priv->statistics.flag); | ||
712 | |||
713 | p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag); | ||
714 | if (flag & UCODE_STATISTICS_CLEAR_MSK) | ||
715 | p += scnprintf(buf + p, bufsz - p, | ||
716 | "\tStatistics have been cleared\n"); | ||
717 | p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n", | ||
718 | (flag & UCODE_STATISTICS_FREQUENCY_MSK) | ||
719 | ? "2.4 GHz" : "5.2 GHz"); | ||
720 | p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n", | ||
721 | (flag & UCODE_STATISTICS_NARROW_BAND_MSK) | ||
722 | ? "enabled" : "disabled"); | ||
723 | |||
724 | return p; | ||
725 | } | ||
726 | |||
727 | static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file, | ||
728 | char __user *user_buf, | ||
729 | size_t count, loff_t *ppos) | ||
730 | { | ||
731 | struct iwl_priv *priv = file->private_data; | ||
732 | int pos = 0; | ||
733 | char *buf; | ||
734 | int bufsz = sizeof(struct statistics_rx_phy) * 40 + | ||
735 | sizeof(struct statistics_rx_non_phy) * 40 + | ||
736 | sizeof(struct statistics_rx_ht_phy) * 40 + 400; | ||
737 | ssize_t ret; | ||
738 | struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm; | ||
739 | struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck; | ||
740 | struct statistics_rx_non_phy *general, *accum_general; | ||
741 | struct statistics_rx_non_phy *delta_general, *max_general; | ||
742 | struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht; | ||
743 | |||
744 | if (!iwl_is_alive(priv)) | ||
745 | return -EAGAIN; | ||
746 | |||
747 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
748 | if (!buf) | ||
749 | return -ENOMEM; | ||
750 | |||
751 | /* | ||
752 | * the statistic information display here is based on | ||
753 | * the last statistics notification from uCode | ||
754 | * might not reflect the current uCode activity | ||
755 | */ | ||
756 | spin_lock_bh(&priv->statistics.lock); | ||
757 | ofdm = &priv->statistics.rx_ofdm; | ||
758 | cck = &priv->statistics.rx_cck; | ||
759 | general = &priv->statistics.rx_non_phy; | ||
760 | ht = &priv->statistics.rx_ofdm_ht; | ||
761 | accum_ofdm = &priv->accum_stats.rx_ofdm; | ||
762 | accum_cck = &priv->accum_stats.rx_cck; | ||
763 | accum_general = &priv->accum_stats.rx_non_phy; | ||
764 | accum_ht = &priv->accum_stats.rx_ofdm_ht; | ||
765 | delta_ofdm = &priv->delta_stats.rx_ofdm; | ||
766 | delta_cck = &priv->delta_stats.rx_cck; | ||
767 | delta_general = &priv->delta_stats.rx_non_phy; | ||
768 | delta_ht = &priv->delta_stats.rx_ofdm_ht; | ||
769 | max_ofdm = &priv->max_delta_stats.rx_ofdm; | ||
770 | max_cck = &priv->max_delta_stats.rx_cck; | ||
771 | max_general = &priv->max_delta_stats.rx_non_phy; | ||
772 | max_ht = &priv->max_delta_stats.rx_ofdm_ht; | ||
773 | |||
774 | pos += iwl_statistics_flag(priv, buf, bufsz); | ||
775 | pos += scnprintf(buf + pos, bufsz - pos, | ||
776 | fmt_header, "Statistics_Rx - OFDM:"); | ||
777 | pos += scnprintf(buf + pos, bufsz - pos, | ||
778 | fmt_table, "ina_cnt:", | ||
779 | le32_to_cpu(ofdm->ina_cnt), | ||
780 | accum_ofdm->ina_cnt, | ||
781 | delta_ofdm->ina_cnt, max_ofdm->ina_cnt); | ||
782 | pos += scnprintf(buf + pos, bufsz - pos, | ||
783 | fmt_table, "fina_cnt:", | ||
784 | le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt, | ||
785 | delta_ofdm->fina_cnt, max_ofdm->fina_cnt); | ||
786 | pos += scnprintf(buf + pos, bufsz - pos, | ||
787 | fmt_table, "plcp_err:", | ||
788 | le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err, | ||
789 | delta_ofdm->plcp_err, max_ofdm->plcp_err); | ||
790 | pos += scnprintf(buf + pos, bufsz - pos, | ||
791 | fmt_table, "crc32_err:", | ||
792 | le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err, | ||
793 | delta_ofdm->crc32_err, max_ofdm->crc32_err); | ||
794 | pos += scnprintf(buf + pos, bufsz - pos, | ||
795 | fmt_table, "overrun_err:", | ||
796 | le32_to_cpu(ofdm->overrun_err), | ||
797 | accum_ofdm->overrun_err, delta_ofdm->overrun_err, | ||
798 | max_ofdm->overrun_err); | ||
799 | pos += scnprintf(buf + pos, bufsz - pos, | ||
800 | fmt_table, "early_overrun_err:", | ||
801 | le32_to_cpu(ofdm->early_overrun_err), | ||
802 | accum_ofdm->early_overrun_err, | ||
803 | delta_ofdm->early_overrun_err, | ||
804 | max_ofdm->early_overrun_err); | ||
805 | pos += scnprintf(buf + pos, bufsz - pos, | ||
806 | fmt_table, "crc32_good:", | ||
807 | le32_to_cpu(ofdm->crc32_good), | ||
808 | accum_ofdm->crc32_good, delta_ofdm->crc32_good, | ||
809 | max_ofdm->crc32_good); | ||
810 | pos += scnprintf(buf + pos, bufsz - pos, | ||
811 | fmt_table, "false_alarm_cnt:", | ||
812 | le32_to_cpu(ofdm->false_alarm_cnt), | ||
813 | accum_ofdm->false_alarm_cnt, | ||
814 | delta_ofdm->false_alarm_cnt, | ||
815 | max_ofdm->false_alarm_cnt); | ||
816 | pos += scnprintf(buf + pos, bufsz - pos, | ||
817 | fmt_table, "fina_sync_err_cnt:", | ||
818 | le32_to_cpu(ofdm->fina_sync_err_cnt), | ||
819 | accum_ofdm->fina_sync_err_cnt, | ||
820 | delta_ofdm->fina_sync_err_cnt, | ||
821 | max_ofdm->fina_sync_err_cnt); | ||
822 | pos += scnprintf(buf + pos, bufsz - pos, | ||
823 | fmt_table, "sfd_timeout:", | ||
824 | le32_to_cpu(ofdm->sfd_timeout), | ||
825 | accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout, | ||
826 | max_ofdm->sfd_timeout); | ||
827 | pos += scnprintf(buf + pos, bufsz - pos, | ||
828 | fmt_table, "fina_timeout:", | ||
829 | le32_to_cpu(ofdm->fina_timeout), | ||
830 | accum_ofdm->fina_timeout, delta_ofdm->fina_timeout, | ||
831 | max_ofdm->fina_timeout); | ||
832 | pos += scnprintf(buf + pos, bufsz - pos, | ||
833 | fmt_table, "unresponded_rts:", | ||
834 | le32_to_cpu(ofdm->unresponded_rts), | ||
835 | accum_ofdm->unresponded_rts, | ||
836 | delta_ofdm->unresponded_rts, | ||
837 | max_ofdm->unresponded_rts); | ||
838 | pos += scnprintf(buf + pos, bufsz - pos, | ||
839 | fmt_table, "rxe_frame_lmt_ovrun:", | ||
840 | le32_to_cpu(ofdm->rxe_frame_limit_overrun), | ||
841 | accum_ofdm->rxe_frame_limit_overrun, | ||
842 | delta_ofdm->rxe_frame_limit_overrun, | ||
843 | max_ofdm->rxe_frame_limit_overrun); | ||
844 | pos += scnprintf(buf + pos, bufsz - pos, | ||
845 | fmt_table, "sent_ack_cnt:", | ||
846 | le32_to_cpu(ofdm->sent_ack_cnt), | ||
847 | accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt, | ||
848 | max_ofdm->sent_ack_cnt); | ||
849 | pos += scnprintf(buf + pos, bufsz - pos, | ||
850 | fmt_table, "sent_cts_cnt:", | ||
851 | le32_to_cpu(ofdm->sent_cts_cnt), | ||
852 | accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt, | ||
853 | max_ofdm->sent_cts_cnt); | ||
854 | pos += scnprintf(buf + pos, bufsz - pos, | ||
855 | fmt_table, "sent_ba_rsp_cnt:", | ||
856 | le32_to_cpu(ofdm->sent_ba_rsp_cnt), | ||
857 | accum_ofdm->sent_ba_rsp_cnt, | ||
858 | delta_ofdm->sent_ba_rsp_cnt, | ||
859 | max_ofdm->sent_ba_rsp_cnt); | ||
860 | pos += scnprintf(buf + pos, bufsz - pos, | ||
861 | fmt_table, "dsp_self_kill:", | ||
862 | le32_to_cpu(ofdm->dsp_self_kill), | ||
863 | accum_ofdm->dsp_self_kill, | ||
864 | delta_ofdm->dsp_self_kill, | ||
865 | max_ofdm->dsp_self_kill); | ||
866 | pos += scnprintf(buf + pos, bufsz - pos, | ||
867 | fmt_table, "mh_format_err:", | ||
868 | le32_to_cpu(ofdm->mh_format_err), | ||
869 | accum_ofdm->mh_format_err, | ||
870 | delta_ofdm->mh_format_err, | ||
871 | max_ofdm->mh_format_err); | ||
872 | pos += scnprintf(buf + pos, bufsz - pos, | ||
873 | fmt_table, "re_acq_main_rssi_sum:", | ||
874 | le32_to_cpu(ofdm->re_acq_main_rssi_sum), | ||
875 | accum_ofdm->re_acq_main_rssi_sum, | ||
876 | delta_ofdm->re_acq_main_rssi_sum, | ||
877 | max_ofdm->re_acq_main_rssi_sum); | ||
878 | |||
879 | pos += scnprintf(buf + pos, bufsz - pos, | ||
880 | fmt_header, "Statistics_Rx - CCK:"); | ||
881 | pos += scnprintf(buf + pos, bufsz - pos, | ||
882 | fmt_table, "ina_cnt:", | ||
883 | le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt, | ||
884 | delta_cck->ina_cnt, max_cck->ina_cnt); | ||
885 | pos += scnprintf(buf + pos, bufsz - pos, | ||
886 | fmt_table, "fina_cnt:", | ||
887 | le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt, | ||
888 | delta_cck->fina_cnt, max_cck->fina_cnt); | ||
889 | pos += scnprintf(buf + pos, bufsz - pos, | ||
890 | fmt_table, "plcp_err:", | ||
891 | le32_to_cpu(cck->plcp_err), accum_cck->plcp_err, | ||
892 | delta_cck->plcp_err, max_cck->plcp_err); | ||
893 | pos += scnprintf(buf + pos, bufsz - pos, | ||
894 | fmt_table, "crc32_err:", | ||
895 | le32_to_cpu(cck->crc32_err), accum_cck->crc32_err, | ||
896 | delta_cck->crc32_err, max_cck->crc32_err); | ||
897 | pos += scnprintf(buf + pos, bufsz - pos, | ||
898 | fmt_table, "overrun_err:", | ||
899 | le32_to_cpu(cck->overrun_err), | ||
900 | accum_cck->overrun_err, delta_cck->overrun_err, | ||
901 | max_cck->overrun_err); | ||
902 | pos += scnprintf(buf + pos, bufsz - pos, | ||
903 | fmt_table, "early_overrun_err:", | ||
904 | le32_to_cpu(cck->early_overrun_err), | ||
905 | accum_cck->early_overrun_err, | ||
906 | delta_cck->early_overrun_err, | ||
907 | max_cck->early_overrun_err); | ||
908 | pos += scnprintf(buf + pos, bufsz - pos, | ||
909 | fmt_table, "crc32_good:", | ||
910 | le32_to_cpu(cck->crc32_good), accum_cck->crc32_good, | ||
911 | delta_cck->crc32_good, max_cck->crc32_good); | ||
912 | pos += scnprintf(buf + pos, bufsz - pos, | ||
913 | fmt_table, "false_alarm_cnt:", | ||
914 | le32_to_cpu(cck->false_alarm_cnt), | ||
915 | accum_cck->false_alarm_cnt, | ||
916 | delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt); | ||
917 | pos += scnprintf(buf + pos, bufsz - pos, | ||
918 | fmt_table, "fina_sync_err_cnt:", | ||
919 | le32_to_cpu(cck->fina_sync_err_cnt), | ||
920 | accum_cck->fina_sync_err_cnt, | ||
921 | delta_cck->fina_sync_err_cnt, | ||
922 | max_cck->fina_sync_err_cnt); | ||
923 | pos += scnprintf(buf + pos, bufsz - pos, | ||
924 | fmt_table, "sfd_timeout:", | ||
925 | le32_to_cpu(cck->sfd_timeout), | ||
926 | accum_cck->sfd_timeout, delta_cck->sfd_timeout, | ||
927 | max_cck->sfd_timeout); | ||
928 | pos += scnprintf(buf + pos, bufsz - pos, | ||
929 | fmt_table, "fina_timeout:", | ||
930 | le32_to_cpu(cck->fina_timeout), | ||
931 | accum_cck->fina_timeout, delta_cck->fina_timeout, | ||
932 | max_cck->fina_timeout); | ||
933 | pos += scnprintf(buf + pos, bufsz - pos, | ||
934 | fmt_table, "unresponded_rts:", | ||
935 | le32_to_cpu(cck->unresponded_rts), | ||
936 | accum_cck->unresponded_rts, delta_cck->unresponded_rts, | ||
937 | max_cck->unresponded_rts); | ||
938 | pos += scnprintf(buf + pos, bufsz - pos, | ||
939 | fmt_table, "rxe_frame_lmt_ovrun:", | ||
940 | le32_to_cpu(cck->rxe_frame_limit_overrun), | ||
941 | accum_cck->rxe_frame_limit_overrun, | ||
942 | delta_cck->rxe_frame_limit_overrun, | ||
943 | max_cck->rxe_frame_limit_overrun); | ||
944 | pos += scnprintf(buf + pos, bufsz - pos, | ||
945 | fmt_table, "sent_ack_cnt:", | ||
946 | le32_to_cpu(cck->sent_ack_cnt), | ||
947 | accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt, | ||
948 | max_cck->sent_ack_cnt); | ||
949 | pos += scnprintf(buf + pos, bufsz - pos, | ||
950 | fmt_table, "sent_cts_cnt:", | ||
951 | le32_to_cpu(cck->sent_cts_cnt), | ||
952 | accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt, | ||
953 | max_cck->sent_cts_cnt); | ||
954 | pos += scnprintf(buf + pos, bufsz - pos, | ||
955 | fmt_table, "sent_ba_rsp_cnt:", | ||
956 | le32_to_cpu(cck->sent_ba_rsp_cnt), | ||
957 | accum_cck->sent_ba_rsp_cnt, | ||
958 | delta_cck->sent_ba_rsp_cnt, | ||
959 | max_cck->sent_ba_rsp_cnt); | ||
960 | pos += scnprintf(buf + pos, bufsz - pos, | ||
961 | fmt_table, "dsp_self_kill:", | ||
962 | le32_to_cpu(cck->dsp_self_kill), | ||
963 | accum_cck->dsp_self_kill, delta_cck->dsp_self_kill, | ||
964 | max_cck->dsp_self_kill); | ||
965 | pos += scnprintf(buf + pos, bufsz - pos, | ||
966 | fmt_table, "mh_format_err:", | ||
967 | le32_to_cpu(cck->mh_format_err), | ||
968 | accum_cck->mh_format_err, delta_cck->mh_format_err, | ||
969 | max_cck->mh_format_err); | ||
970 | pos += scnprintf(buf + pos, bufsz - pos, | ||
971 | fmt_table, "re_acq_main_rssi_sum:", | ||
972 | le32_to_cpu(cck->re_acq_main_rssi_sum), | ||
973 | accum_cck->re_acq_main_rssi_sum, | ||
974 | delta_cck->re_acq_main_rssi_sum, | ||
975 | max_cck->re_acq_main_rssi_sum); | ||
976 | |||
977 | pos += scnprintf(buf + pos, bufsz - pos, | ||
978 | fmt_header, "Statistics_Rx - GENERAL:"); | ||
979 | pos += scnprintf(buf + pos, bufsz - pos, | ||
980 | fmt_table, "bogus_cts:", | ||
981 | le32_to_cpu(general->bogus_cts), | ||
982 | accum_general->bogus_cts, delta_general->bogus_cts, | ||
983 | max_general->bogus_cts); | ||
984 | pos += scnprintf(buf + pos, bufsz - pos, | ||
985 | fmt_table, "bogus_ack:", | ||
986 | le32_to_cpu(general->bogus_ack), | ||
987 | accum_general->bogus_ack, delta_general->bogus_ack, | ||
988 | max_general->bogus_ack); | ||
989 | pos += scnprintf(buf + pos, bufsz - pos, | ||
990 | fmt_table, "non_bssid_frames:", | ||
991 | le32_to_cpu(general->non_bssid_frames), | ||
992 | accum_general->non_bssid_frames, | ||
993 | delta_general->non_bssid_frames, | ||
994 | max_general->non_bssid_frames); | ||
995 | pos += scnprintf(buf + pos, bufsz - pos, | ||
996 | fmt_table, "filtered_frames:", | ||
997 | le32_to_cpu(general->filtered_frames), | ||
998 | accum_general->filtered_frames, | ||
999 | delta_general->filtered_frames, | ||
1000 | max_general->filtered_frames); | ||
1001 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1002 | fmt_table, "non_channel_beacons:", | ||
1003 | le32_to_cpu(general->non_channel_beacons), | ||
1004 | accum_general->non_channel_beacons, | ||
1005 | delta_general->non_channel_beacons, | ||
1006 | max_general->non_channel_beacons); | ||
1007 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1008 | fmt_table, "channel_beacons:", | ||
1009 | le32_to_cpu(general->channel_beacons), | ||
1010 | accum_general->channel_beacons, | ||
1011 | delta_general->channel_beacons, | ||
1012 | max_general->channel_beacons); | ||
1013 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1014 | fmt_table, "num_missed_bcon:", | ||
1015 | le32_to_cpu(general->num_missed_bcon), | ||
1016 | accum_general->num_missed_bcon, | ||
1017 | delta_general->num_missed_bcon, | ||
1018 | max_general->num_missed_bcon); | ||
1019 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1020 | fmt_table, "adc_rx_saturation_time:", | ||
1021 | le32_to_cpu(general->adc_rx_saturation_time), | ||
1022 | accum_general->adc_rx_saturation_time, | ||
1023 | delta_general->adc_rx_saturation_time, | ||
1024 | max_general->adc_rx_saturation_time); | ||
1025 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1026 | fmt_table, "ina_detect_search_tm:", | ||
1027 | le32_to_cpu(general->ina_detection_search_time), | ||
1028 | accum_general->ina_detection_search_time, | ||
1029 | delta_general->ina_detection_search_time, | ||
1030 | max_general->ina_detection_search_time); | ||
1031 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1032 | fmt_table, "beacon_silence_rssi_a:", | ||
1033 | le32_to_cpu(general->beacon_silence_rssi_a), | ||
1034 | accum_general->beacon_silence_rssi_a, | ||
1035 | delta_general->beacon_silence_rssi_a, | ||
1036 | max_general->beacon_silence_rssi_a); | ||
1037 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1038 | fmt_table, "beacon_silence_rssi_b:", | ||
1039 | le32_to_cpu(general->beacon_silence_rssi_b), | ||
1040 | accum_general->beacon_silence_rssi_b, | ||
1041 | delta_general->beacon_silence_rssi_b, | ||
1042 | max_general->beacon_silence_rssi_b); | ||
1043 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1044 | fmt_table, "beacon_silence_rssi_c:", | ||
1045 | le32_to_cpu(general->beacon_silence_rssi_c), | ||
1046 | accum_general->beacon_silence_rssi_c, | ||
1047 | delta_general->beacon_silence_rssi_c, | ||
1048 | max_general->beacon_silence_rssi_c); | ||
1049 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1050 | fmt_table, "interference_data_flag:", | ||
1051 | le32_to_cpu(general->interference_data_flag), | ||
1052 | accum_general->interference_data_flag, | ||
1053 | delta_general->interference_data_flag, | ||
1054 | max_general->interference_data_flag); | ||
1055 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1056 | fmt_table, "channel_load:", | ||
1057 | le32_to_cpu(general->channel_load), | ||
1058 | accum_general->channel_load, | ||
1059 | delta_general->channel_load, | ||
1060 | max_general->channel_load); | ||
1061 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1062 | fmt_table, "dsp_false_alarms:", | ||
1063 | le32_to_cpu(general->dsp_false_alarms), | ||
1064 | accum_general->dsp_false_alarms, | ||
1065 | delta_general->dsp_false_alarms, | ||
1066 | max_general->dsp_false_alarms); | ||
1067 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1068 | fmt_table, "beacon_rssi_a:", | ||
1069 | le32_to_cpu(general->beacon_rssi_a), | ||
1070 | accum_general->beacon_rssi_a, | ||
1071 | delta_general->beacon_rssi_a, | ||
1072 | max_general->beacon_rssi_a); | ||
1073 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1074 | fmt_table, "beacon_rssi_b:", | ||
1075 | le32_to_cpu(general->beacon_rssi_b), | ||
1076 | accum_general->beacon_rssi_b, | ||
1077 | delta_general->beacon_rssi_b, | ||
1078 | max_general->beacon_rssi_b); | ||
1079 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1080 | fmt_table, "beacon_rssi_c:", | ||
1081 | le32_to_cpu(general->beacon_rssi_c), | ||
1082 | accum_general->beacon_rssi_c, | ||
1083 | delta_general->beacon_rssi_c, | ||
1084 | max_general->beacon_rssi_c); | ||
1085 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1086 | fmt_table, "beacon_energy_a:", | ||
1087 | le32_to_cpu(general->beacon_energy_a), | ||
1088 | accum_general->beacon_energy_a, | ||
1089 | delta_general->beacon_energy_a, | ||
1090 | max_general->beacon_energy_a); | ||
1091 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1092 | fmt_table, "beacon_energy_b:", | ||
1093 | le32_to_cpu(general->beacon_energy_b), | ||
1094 | accum_general->beacon_energy_b, | ||
1095 | delta_general->beacon_energy_b, | ||
1096 | max_general->beacon_energy_b); | ||
1097 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1098 | fmt_table, "beacon_energy_c:", | ||
1099 | le32_to_cpu(general->beacon_energy_c), | ||
1100 | accum_general->beacon_energy_c, | ||
1101 | delta_general->beacon_energy_c, | ||
1102 | max_general->beacon_energy_c); | ||
1103 | |||
1104 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1105 | fmt_header, "Statistics_Rx - OFDM_HT:"); | ||
1106 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1107 | fmt_table, "plcp_err:", | ||
1108 | le32_to_cpu(ht->plcp_err), accum_ht->plcp_err, | ||
1109 | delta_ht->plcp_err, max_ht->plcp_err); | ||
1110 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1111 | fmt_table, "overrun_err:", | ||
1112 | le32_to_cpu(ht->overrun_err), accum_ht->overrun_err, | ||
1113 | delta_ht->overrun_err, max_ht->overrun_err); | ||
1114 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1115 | fmt_table, "early_overrun_err:", | ||
1116 | le32_to_cpu(ht->early_overrun_err), | ||
1117 | accum_ht->early_overrun_err, | ||
1118 | delta_ht->early_overrun_err, | ||
1119 | max_ht->early_overrun_err); | ||
1120 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1121 | fmt_table, "crc32_good:", | ||
1122 | le32_to_cpu(ht->crc32_good), accum_ht->crc32_good, | ||
1123 | delta_ht->crc32_good, max_ht->crc32_good); | ||
1124 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1125 | fmt_table, "crc32_err:", | ||
1126 | le32_to_cpu(ht->crc32_err), accum_ht->crc32_err, | ||
1127 | delta_ht->crc32_err, max_ht->crc32_err); | ||
1128 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1129 | fmt_table, "mh_format_err:", | ||
1130 | le32_to_cpu(ht->mh_format_err), | ||
1131 | accum_ht->mh_format_err, | ||
1132 | delta_ht->mh_format_err, max_ht->mh_format_err); | ||
1133 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1134 | fmt_table, "agg_crc32_good:", | ||
1135 | le32_to_cpu(ht->agg_crc32_good), | ||
1136 | accum_ht->agg_crc32_good, | ||
1137 | delta_ht->agg_crc32_good, max_ht->agg_crc32_good); | ||
1138 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1139 | fmt_table, "agg_mpdu_cnt:", | ||
1140 | le32_to_cpu(ht->agg_mpdu_cnt), | ||
1141 | accum_ht->agg_mpdu_cnt, | ||
1142 | delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt); | ||
1143 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1144 | fmt_table, "agg_cnt:", | ||
1145 | le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt, | ||
1146 | delta_ht->agg_cnt, max_ht->agg_cnt); | ||
1147 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1148 | fmt_table, "unsupport_mcs:", | ||
1149 | le32_to_cpu(ht->unsupport_mcs), | ||
1150 | accum_ht->unsupport_mcs, | ||
1151 | delta_ht->unsupport_mcs, max_ht->unsupport_mcs); | ||
1152 | |||
1153 | spin_unlock_bh(&priv->statistics.lock); | ||
1154 | |||
1155 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1156 | kfree(buf); | ||
1157 | return ret; | ||
1158 | } | ||
1159 | |||
1160 | static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file, | ||
1161 | char __user *user_buf, | ||
1162 | size_t count, loff_t *ppos) | ||
1163 | { | ||
1164 | struct iwl_priv *priv = file->private_data; | ||
1165 | int pos = 0; | ||
1166 | char *buf; | ||
1167 | int bufsz = (sizeof(struct statistics_tx) * 48) + 250; | ||
1168 | ssize_t ret; | ||
1169 | struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx; | ||
1170 | |||
1171 | if (!iwl_is_alive(priv)) | ||
1172 | return -EAGAIN; | ||
1173 | |||
1174 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
1175 | if (!buf) | ||
1176 | return -ENOMEM; | ||
1177 | |||
1178 | /* the statistic information display here is based on | ||
1179 | * the last statistics notification from uCode | ||
1180 | * might not reflect the current uCode activity | ||
1181 | */ | ||
1182 | spin_lock_bh(&priv->statistics.lock); | ||
1183 | |||
1184 | tx = &priv->statistics.tx; | ||
1185 | accum_tx = &priv->accum_stats.tx; | ||
1186 | delta_tx = &priv->delta_stats.tx; | ||
1187 | max_tx = &priv->max_delta_stats.tx; | ||
1188 | |||
1189 | pos += iwl_statistics_flag(priv, buf, bufsz); | ||
1190 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1191 | fmt_header, "Statistics_Tx:"); | ||
1192 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1193 | fmt_table, "preamble:", | ||
1194 | le32_to_cpu(tx->preamble_cnt), | ||
1195 | accum_tx->preamble_cnt, | ||
1196 | delta_tx->preamble_cnt, max_tx->preamble_cnt); | ||
1197 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1198 | fmt_table, "rx_detected_cnt:", | ||
1199 | le32_to_cpu(tx->rx_detected_cnt), | ||
1200 | accum_tx->rx_detected_cnt, | ||
1201 | delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt); | ||
1202 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1203 | fmt_table, "bt_prio_defer_cnt:", | ||
1204 | le32_to_cpu(tx->bt_prio_defer_cnt), | ||
1205 | accum_tx->bt_prio_defer_cnt, | ||
1206 | delta_tx->bt_prio_defer_cnt, | ||
1207 | max_tx->bt_prio_defer_cnt); | ||
1208 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1209 | fmt_table, "bt_prio_kill_cnt:", | ||
1210 | le32_to_cpu(tx->bt_prio_kill_cnt), | ||
1211 | accum_tx->bt_prio_kill_cnt, | ||
1212 | delta_tx->bt_prio_kill_cnt, | ||
1213 | max_tx->bt_prio_kill_cnt); | ||
1214 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1215 | fmt_table, "few_bytes_cnt:", | ||
1216 | le32_to_cpu(tx->few_bytes_cnt), | ||
1217 | accum_tx->few_bytes_cnt, | ||
1218 | delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt); | ||
1219 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1220 | fmt_table, "cts_timeout:", | ||
1221 | le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout, | ||
1222 | delta_tx->cts_timeout, max_tx->cts_timeout); | ||
1223 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1224 | fmt_table, "ack_timeout:", | ||
1225 | le32_to_cpu(tx->ack_timeout), | ||
1226 | accum_tx->ack_timeout, | ||
1227 | delta_tx->ack_timeout, max_tx->ack_timeout); | ||
1228 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1229 | fmt_table, "expected_ack_cnt:", | ||
1230 | le32_to_cpu(tx->expected_ack_cnt), | ||
1231 | accum_tx->expected_ack_cnt, | ||
1232 | delta_tx->expected_ack_cnt, | ||
1233 | max_tx->expected_ack_cnt); | ||
1234 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1235 | fmt_table, "actual_ack_cnt:", | ||
1236 | le32_to_cpu(tx->actual_ack_cnt), | ||
1237 | accum_tx->actual_ack_cnt, | ||
1238 | delta_tx->actual_ack_cnt, | ||
1239 | max_tx->actual_ack_cnt); | ||
1240 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1241 | fmt_table, "dump_msdu_cnt:", | ||
1242 | le32_to_cpu(tx->dump_msdu_cnt), | ||
1243 | accum_tx->dump_msdu_cnt, | ||
1244 | delta_tx->dump_msdu_cnt, | ||
1245 | max_tx->dump_msdu_cnt); | ||
1246 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1247 | fmt_table, "abort_nxt_frame_mismatch:", | ||
1248 | le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt), | ||
1249 | accum_tx->burst_abort_next_frame_mismatch_cnt, | ||
1250 | delta_tx->burst_abort_next_frame_mismatch_cnt, | ||
1251 | max_tx->burst_abort_next_frame_mismatch_cnt); | ||
1252 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1253 | fmt_table, "abort_missing_nxt_frame:", | ||
1254 | le32_to_cpu(tx->burst_abort_missing_next_frame_cnt), | ||
1255 | accum_tx->burst_abort_missing_next_frame_cnt, | ||
1256 | delta_tx->burst_abort_missing_next_frame_cnt, | ||
1257 | max_tx->burst_abort_missing_next_frame_cnt); | ||
1258 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1259 | fmt_table, "cts_timeout_collision:", | ||
1260 | le32_to_cpu(tx->cts_timeout_collision), | ||
1261 | accum_tx->cts_timeout_collision, | ||
1262 | delta_tx->cts_timeout_collision, | ||
1263 | max_tx->cts_timeout_collision); | ||
1264 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1265 | fmt_table, "ack_ba_timeout_collision:", | ||
1266 | le32_to_cpu(tx->ack_or_ba_timeout_collision), | ||
1267 | accum_tx->ack_or_ba_timeout_collision, | ||
1268 | delta_tx->ack_or_ba_timeout_collision, | ||
1269 | max_tx->ack_or_ba_timeout_collision); | ||
1270 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1271 | fmt_table, "agg ba_timeout:", | ||
1272 | le32_to_cpu(tx->agg.ba_timeout), | ||
1273 | accum_tx->agg.ba_timeout, | ||
1274 | delta_tx->agg.ba_timeout, | ||
1275 | max_tx->agg.ba_timeout); | ||
1276 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1277 | fmt_table, "agg ba_resched_frames:", | ||
1278 | le32_to_cpu(tx->agg.ba_reschedule_frames), | ||
1279 | accum_tx->agg.ba_reschedule_frames, | ||
1280 | delta_tx->agg.ba_reschedule_frames, | ||
1281 | max_tx->agg.ba_reschedule_frames); | ||
1282 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1283 | fmt_table, "agg scd_query_agg_frame:", | ||
1284 | le32_to_cpu(tx->agg.scd_query_agg_frame_cnt), | ||
1285 | accum_tx->agg.scd_query_agg_frame_cnt, | ||
1286 | delta_tx->agg.scd_query_agg_frame_cnt, | ||
1287 | max_tx->agg.scd_query_agg_frame_cnt); | ||
1288 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1289 | fmt_table, "agg scd_query_no_agg:", | ||
1290 | le32_to_cpu(tx->agg.scd_query_no_agg), | ||
1291 | accum_tx->agg.scd_query_no_agg, | ||
1292 | delta_tx->agg.scd_query_no_agg, | ||
1293 | max_tx->agg.scd_query_no_agg); | ||
1294 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1295 | fmt_table, "agg scd_query_agg:", | ||
1296 | le32_to_cpu(tx->agg.scd_query_agg), | ||
1297 | accum_tx->agg.scd_query_agg, | ||
1298 | delta_tx->agg.scd_query_agg, | ||
1299 | max_tx->agg.scd_query_agg); | ||
1300 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1301 | fmt_table, "agg scd_query_mismatch:", | ||
1302 | le32_to_cpu(tx->agg.scd_query_mismatch), | ||
1303 | accum_tx->agg.scd_query_mismatch, | ||
1304 | delta_tx->agg.scd_query_mismatch, | ||
1305 | max_tx->agg.scd_query_mismatch); | ||
1306 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1307 | fmt_table, "agg frame_not_ready:", | ||
1308 | le32_to_cpu(tx->agg.frame_not_ready), | ||
1309 | accum_tx->agg.frame_not_ready, | ||
1310 | delta_tx->agg.frame_not_ready, | ||
1311 | max_tx->agg.frame_not_ready); | ||
1312 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1313 | fmt_table, "agg underrun:", | ||
1314 | le32_to_cpu(tx->agg.underrun), | ||
1315 | accum_tx->agg.underrun, | ||
1316 | delta_tx->agg.underrun, max_tx->agg.underrun); | ||
1317 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1318 | fmt_table, "agg bt_prio_kill:", | ||
1319 | le32_to_cpu(tx->agg.bt_prio_kill), | ||
1320 | accum_tx->agg.bt_prio_kill, | ||
1321 | delta_tx->agg.bt_prio_kill, | ||
1322 | max_tx->agg.bt_prio_kill); | ||
1323 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1324 | fmt_table, "agg rx_ba_rsp_cnt:", | ||
1325 | le32_to_cpu(tx->agg.rx_ba_rsp_cnt), | ||
1326 | accum_tx->agg.rx_ba_rsp_cnt, | ||
1327 | delta_tx->agg.rx_ba_rsp_cnt, | ||
1328 | max_tx->agg.rx_ba_rsp_cnt); | ||
1329 | |||
1330 | if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) { | ||
1331 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1332 | "tx power: (1/2 dB step)\n"); | ||
1333 | if ((priv->eeprom_data->valid_tx_ant & ANT_A) && | ||
1334 | tx->tx_power.ant_a) | ||
1335 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1336 | fmt_hex, "antenna A:", | ||
1337 | tx->tx_power.ant_a); | ||
1338 | if ((priv->eeprom_data->valid_tx_ant & ANT_B) && | ||
1339 | tx->tx_power.ant_b) | ||
1340 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1341 | fmt_hex, "antenna B:", | ||
1342 | tx->tx_power.ant_b); | ||
1343 | if ((priv->eeprom_data->valid_tx_ant & ANT_C) && | ||
1344 | tx->tx_power.ant_c) | ||
1345 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1346 | fmt_hex, "antenna C:", | ||
1347 | tx->tx_power.ant_c); | ||
1348 | } | ||
1349 | |||
1350 | spin_unlock_bh(&priv->statistics.lock); | ||
1351 | |||
1352 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1353 | kfree(buf); | ||
1354 | return ret; | ||
1355 | } | ||
1356 | |||
1357 | static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file, | ||
1358 | char __user *user_buf, | ||
1359 | size_t count, loff_t *ppos) | ||
1360 | { | ||
1361 | struct iwl_priv *priv = file->private_data; | ||
1362 | int pos = 0; | ||
1363 | char *buf; | ||
1364 | int bufsz = sizeof(struct statistics_general) * 10 + 300; | ||
1365 | ssize_t ret; | ||
1366 | struct statistics_general_common *general, *accum_general; | ||
1367 | struct statistics_general_common *delta_general, *max_general; | ||
1368 | struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg; | ||
1369 | struct statistics_div *div, *accum_div, *delta_div, *max_div; | ||
1370 | |||
1371 | if (!iwl_is_alive(priv)) | ||
1372 | return -EAGAIN; | ||
1373 | |||
1374 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
1375 | if (!buf) | ||
1376 | return -ENOMEM; | ||
1377 | |||
1378 | /* the statistic information display here is based on | ||
1379 | * the last statistics notification from uCode | ||
1380 | * might not reflect the current uCode activity | ||
1381 | */ | ||
1382 | |||
1383 | spin_lock_bh(&priv->statistics.lock); | ||
1384 | |||
1385 | general = &priv->statistics.common; | ||
1386 | dbg = &priv->statistics.common.dbg; | ||
1387 | div = &priv->statistics.common.div; | ||
1388 | accum_general = &priv->accum_stats.common; | ||
1389 | accum_dbg = &priv->accum_stats.common.dbg; | ||
1390 | accum_div = &priv->accum_stats.common.div; | ||
1391 | delta_general = &priv->delta_stats.common; | ||
1392 | max_general = &priv->max_delta_stats.common; | ||
1393 | delta_dbg = &priv->delta_stats.common.dbg; | ||
1394 | max_dbg = &priv->max_delta_stats.common.dbg; | ||
1395 | delta_div = &priv->delta_stats.common.div; | ||
1396 | max_div = &priv->max_delta_stats.common.div; | ||
1397 | |||
1398 | pos += iwl_statistics_flag(priv, buf, bufsz); | ||
1399 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1400 | fmt_header, "Statistics_General:"); | ||
1401 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1402 | fmt_value, "temperature:", | ||
1403 | le32_to_cpu(general->temperature)); | ||
1404 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1405 | fmt_value, "temperature_m:", | ||
1406 | le32_to_cpu(general->temperature_m)); | ||
1407 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1408 | fmt_value, "ttl_timestamp:", | ||
1409 | le32_to_cpu(general->ttl_timestamp)); | ||
1410 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1411 | fmt_table, "burst_check:", | ||
1412 | le32_to_cpu(dbg->burst_check), | ||
1413 | accum_dbg->burst_check, | ||
1414 | delta_dbg->burst_check, max_dbg->burst_check); | ||
1415 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1416 | fmt_table, "burst_count:", | ||
1417 | le32_to_cpu(dbg->burst_count), | ||
1418 | accum_dbg->burst_count, | ||
1419 | delta_dbg->burst_count, max_dbg->burst_count); | ||
1420 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1421 | fmt_table, "wait_for_silence_timeout_count:", | ||
1422 | le32_to_cpu(dbg->wait_for_silence_timeout_cnt), | ||
1423 | accum_dbg->wait_for_silence_timeout_cnt, | ||
1424 | delta_dbg->wait_for_silence_timeout_cnt, | ||
1425 | max_dbg->wait_for_silence_timeout_cnt); | ||
1426 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1427 | fmt_table, "sleep_time:", | ||
1428 | le32_to_cpu(general->sleep_time), | ||
1429 | accum_general->sleep_time, | ||
1430 | delta_general->sleep_time, max_general->sleep_time); | ||
1431 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1432 | fmt_table, "slots_out:", | ||
1433 | le32_to_cpu(general->slots_out), | ||
1434 | accum_general->slots_out, | ||
1435 | delta_general->slots_out, max_general->slots_out); | ||
1436 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1437 | fmt_table, "slots_idle:", | ||
1438 | le32_to_cpu(general->slots_idle), | ||
1439 | accum_general->slots_idle, | ||
1440 | delta_general->slots_idle, max_general->slots_idle); | ||
1441 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1442 | fmt_table, "tx_on_a:", | ||
1443 | le32_to_cpu(div->tx_on_a), accum_div->tx_on_a, | ||
1444 | delta_div->tx_on_a, max_div->tx_on_a); | ||
1445 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1446 | fmt_table, "tx_on_b:", | ||
1447 | le32_to_cpu(div->tx_on_b), accum_div->tx_on_b, | ||
1448 | delta_div->tx_on_b, max_div->tx_on_b); | ||
1449 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1450 | fmt_table, "exec_time:", | ||
1451 | le32_to_cpu(div->exec_time), accum_div->exec_time, | ||
1452 | delta_div->exec_time, max_div->exec_time); | ||
1453 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1454 | fmt_table, "probe_time:", | ||
1455 | le32_to_cpu(div->probe_time), accum_div->probe_time, | ||
1456 | delta_div->probe_time, max_div->probe_time); | ||
1457 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1458 | fmt_table, "rx_enable_counter:", | ||
1459 | le32_to_cpu(general->rx_enable_counter), | ||
1460 | accum_general->rx_enable_counter, | ||
1461 | delta_general->rx_enable_counter, | ||
1462 | max_general->rx_enable_counter); | ||
1463 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1464 | fmt_table, "num_of_sos_states:", | ||
1465 | le32_to_cpu(general->num_of_sos_states), | ||
1466 | accum_general->num_of_sos_states, | ||
1467 | delta_general->num_of_sos_states, | ||
1468 | max_general->num_of_sos_states); | ||
1469 | |||
1470 | spin_unlock_bh(&priv->statistics.lock); | ||
1471 | |||
1472 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1473 | kfree(buf); | ||
1474 | return ret; | ||
1475 | } | ||
1476 | |||
1477 | static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file, | ||
1478 | char __user *user_buf, | ||
1479 | size_t count, loff_t *ppos) | ||
1480 | { | ||
1481 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; | ||
1482 | int pos = 0; | ||
1483 | char *buf; | ||
1484 | int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200; | ||
1485 | ssize_t ret; | ||
1486 | struct statistics_bt_activity *bt, *accum_bt; | ||
1487 | |||
1488 | if (!iwl_is_alive(priv)) | ||
1489 | return -EAGAIN; | ||
1490 | |||
1491 | if (!priv->bt_enable_flag) | ||
1492 | return -EINVAL; | ||
1493 | |||
1494 | /* make request to uCode to retrieve statistics information */ | ||
1495 | mutex_lock(&priv->mutex); | ||
1496 | ret = iwl_send_statistics_request(priv, CMD_SYNC, false); | ||
1497 | mutex_unlock(&priv->mutex); | ||
1498 | |||
1499 | if (ret) | ||
1500 | return -EAGAIN; | ||
1501 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
1502 | if (!buf) | ||
1503 | return -ENOMEM; | ||
1504 | |||
1505 | /* | ||
1506 | * the statistic information display here is based on | ||
1507 | * the last statistics notification from uCode | ||
1508 | * might not reflect the current uCode activity | ||
1509 | */ | ||
1510 | |||
1511 | spin_lock_bh(&priv->statistics.lock); | ||
1512 | |||
1513 | bt = &priv->statistics.bt_activity; | ||
1514 | accum_bt = &priv->accum_stats.bt_activity; | ||
1515 | |||
1516 | pos += iwl_statistics_flag(priv, buf, bufsz); | ||
1517 | pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n"); | ||
1518 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1519 | "\t\t\tcurrent\t\t\taccumulative\n"); | ||
1520 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1521 | "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n", | ||
1522 | le32_to_cpu(bt->hi_priority_tx_req_cnt), | ||
1523 | accum_bt->hi_priority_tx_req_cnt); | ||
1524 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1525 | "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n", | ||
1526 | le32_to_cpu(bt->hi_priority_tx_denied_cnt), | ||
1527 | accum_bt->hi_priority_tx_denied_cnt); | ||
1528 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1529 | "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n", | ||
1530 | le32_to_cpu(bt->lo_priority_tx_req_cnt), | ||
1531 | accum_bt->lo_priority_tx_req_cnt); | ||
1532 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1533 | "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n", | ||
1534 | le32_to_cpu(bt->lo_priority_tx_denied_cnt), | ||
1535 | accum_bt->lo_priority_tx_denied_cnt); | ||
1536 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1537 | "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n", | ||
1538 | le32_to_cpu(bt->hi_priority_rx_req_cnt), | ||
1539 | accum_bt->hi_priority_rx_req_cnt); | ||
1540 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1541 | "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n", | ||
1542 | le32_to_cpu(bt->hi_priority_rx_denied_cnt), | ||
1543 | accum_bt->hi_priority_rx_denied_cnt); | ||
1544 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1545 | "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n", | ||
1546 | le32_to_cpu(bt->lo_priority_rx_req_cnt), | ||
1547 | accum_bt->lo_priority_rx_req_cnt); | ||
1548 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1549 | "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n", | ||
1550 | le32_to_cpu(bt->lo_priority_rx_denied_cnt), | ||
1551 | accum_bt->lo_priority_rx_denied_cnt); | ||
1552 | |||
1553 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1554 | "(rx)num_bt_kills:\t\t%u\t\t\t%u\n", | ||
1555 | le32_to_cpu(priv->statistics.num_bt_kills), | ||
1556 | priv->statistics.accum_num_bt_kills); | ||
1557 | |||
1558 | spin_unlock_bh(&priv->statistics.lock); | ||
1559 | |||
1560 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1561 | kfree(buf); | ||
1562 | return ret; | ||
1563 | } | ||
1564 | |||
1565 | static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file, | ||
1566 | char __user *user_buf, | ||
1567 | size_t count, loff_t *ppos) | ||
1568 | { | ||
1569 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; | ||
1570 | int pos = 0; | ||
1571 | char *buf; | ||
1572 | int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) + | ||
1573 | (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200; | ||
1574 | ssize_t ret; | ||
1575 | |||
1576 | if (!iwl_is_alive(priv)) | ||
1577 | return -EAGAIN; | ||
1578 | |||
1579 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
1580 | if (!buf) | ||
1581 | return -ENOMEM; | ||
1582 | |||
1583 | pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n"); | ||
1584 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n", | ||
1585 | iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY), | ||
1586 | priv->reply_tx_stats.pp_delay); | ||
1587 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1588 | iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES), | ||
1589 | priv->reply_tx_stats.pp_few_bytes); | ||
1590 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1591 | iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO), | ||
1592 | priv->reply_tx_stats.pp_bt_prio); | ||
1593 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1594 | iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD), | ||
1595 | priv->reply_tx_stats.pp_quiet_period); | ||
1596 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1597 | iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK), | ||
1598 | priv->reply_tx_stats.pp_calc_ttak); | ||
1599 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", | ||
1600 | iwl_get_tx_fail_reason( | ||
1601 | TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY), | ||
1602 | priv->reply_tx_stats.int_crossed_retry); | ||
1603 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1604 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT), | ||
1605 | priv->reply_tx_stats.short_limit); | ||
1606 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1607 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT), | ||
1608 | priv->reply_tx_stats.long_limit); | ||
1609 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1610 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN), | ||
1611 | priv->reply_tx_stats.fifo_underrun); | ||
1612 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1613 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW), | ||
1614 | priv->reply_tx_stats.drain_flow); | ||
1615 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1616 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH), | ||
1617 | priv->reply_tx_stats.rfkill_flush); | ||
1618 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1619 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE), | ||
1620 | priv->reply_tx_stats.life_expire); | ||
1621 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1622 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS), | ||
1623 | priv->reply_tx_stats.dest_ps); | ||
1624 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1625 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED), | ||
1626 | priv->reply_tx_stats.host_abort); | ||
1627 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1628 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY), | ||
1629 | priv->reply_tx_stats.pp_delay); | ||
1630 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1631 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID), | ||
1632 | priv->reply_tx_stats.sta_invalid); | ||
1633 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1634 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED), | ||
1635 | priv->reply_tx_stats.frag_drop); | ||
1636 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1637 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE), | ||
1638 | priv->reply_tx_stats.tid_disable); | ||
1639 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1640 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED), | ||
1641 | priv->reply_tx_stats.fifo_flush); | ||
1642 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", | ||
1643 | iwl_get_tx_fail_reason( | ||
1644 | TX_STATUS_FAIL_INSUFFICIENT_CF_POLL), | ||
1645 | priv->reply_tx_stats.insuff_cf_poll); | ||
1646 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1647 | iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX), | ||
1648 | priv->reply_tx_stats.fail_hw_drop); | ||
1649 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", | ||
1650 | iwl_get_tx_fail_reason( | ||
1651 | TX_STATUS_FAIL_NO_BEACON_ON_RADAR), | ||
1652 | priv->reply_tx_stats.sta_color_mismatch); | ||
1653 | pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n", | ||
1654 | priv->reply_tx_stats.unknown); | ||
1655 | |||
1656 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1657 | "\nStatistics_Agg_TX_Error:\n"); | ||
1658 | |||
1659 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1660 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK), | ||
1661 | priv->reply_agg_tx_stats.underrun); | ||
1662 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1663 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK), | ||
1664 | priv->reply_agg_tx_stats.bt_prio); | ||
1665 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1666 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK), | ||
1667 | priv->reply_agg_tx_stats.few_bytes); | ||
1668 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1669 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK), | ||
1670 | priv->reply_agg_tx_stats.abort); | ||
1671 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", | ||
1672 | iwl_get_agg_tx_fail_reason( | ||
1673 | AGG_TX_STATE_LAST_SENT_TTL_MSK), | ||
1674 | priv->reply_agg_tx_stats.last_sent_ttl); | ||
1675 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", | ||
1676 | iwl_get_agg_tx_fail_reason( | ||
1677 | AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK), | ||
1678 | priv->reply_agg_tx_stats.last_sent_try); | ||
1679 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", | ||
1680 | iwl_get_agg_tx_fail_reason( | ||
1681 | AGG_TX_STATE_LAST_SENT_BT_KILL_MSK), | ||
1682 | priv->reply_agg_tx_stats.last_sent_bt_kill); | ||
1683 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1684 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK), | ||
1685 | priv->reply_agg_tx_stats.scd_query); | ||
1686 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", | ||
1687 | iwl_get_agg_tx_fail_reason( | ||
1688 | AGG_TX_STATE_TEST_BAD_CRC32_MSK), | ||
1689 | priv->reply_agg_tx_stats.bad_crc32); | ||
1690 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1691 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK), | ||
1692 | priv->reply_agg_tx_stats.response); | ||
1693 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1694 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK), | ||
1695 | priv->reply_agg_tx_stats.dump_tx); | ||
1696 | pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", | ||
1697 | iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK), | ||
1698 | priv->reply_agg_tx_stats.delay_tx); | ||
1699 | pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n", | ||
1700 | priv->reply_agg_tx_stats.unknown); | ||
1701 | |||
1702 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1703 | kfree(buf); | ||
1704 | return ret; | ||
1705 | } | ||
1706 | |||
1707 | static ssize_t iwl_dbgfs_sensitivity_read(struct file *file, | ||
1708 | char __user *user_buf, | ||
1709 | size_t count, loff_t *ppos) { | ||
1710 | |||
1711 | struct iwl_priv *priv = file->private_data; | ||
1712 | int pos = 0; | ||
1713 | int cnt = 0; | ||
1714 | char *buf; | ||
1715 | int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100; | ||
1716 | ssize_t ret; | ||
1717 | struct iwl_sensitivity_data *data; | ||
1718 | |||
1719 | data = &priv->sensitivity_data; | ||
1720 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
1721 | if (!buf) | ||
1722 | return -ENOMEM; | ||
1723 | |||
1724 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n", | ||
1725 | data->auto_corr_ofdm); | ||
1726 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1727 | "auto_corr_ofdm_mrc:\t\t %u\n", | ||
1728 | data->auto_corr_ofdm_mrc); | ||
1729 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n", | ||
1730 | data->auto_corr_ofdm_x1); | ||
1731 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1732 | "auto_corr_ofdm_mrc_x1:\t\t %u\n", | ||
1733 | data->auto_corr_ofdm_mrc_x1); | ||
1734 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n", | ||
1735 | data->auto_corr_cck); | ||
1736 | pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n", | ||
1737 | data->auto_corr_cck_mrc); | ||
1738 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1739 | "last_bad_plcp_cnt_ofdm:\t\t %u\n", | ||
1740 | data->last_bad_plcp_cnt_ofdm); | ||
1741 | pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n", | ||
1742 | data->last_fa_cnt_ofdm); | ||
1743 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1744 | "last_bad_plcp_cnt_cck:\t\t %u\n", | ||
1745 | data->last_bad_plcp_cnt_cck); | ||
1746 | pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n", | ||
1747 | data->last_fa_cnt_cck); | ||
1748 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n", | ||
1749 | data->nrg_curr_state); | ||
1750 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n", | ||
1751 | data->nrg_prev_state); | ||
1752 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t"); | ||
1753 | for (cnt = 0; cnt < 10; cnt++) { | ||
1754 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | ||
1755 | data->nrg_value[cnt]); | ||
1756 | } | ||
1757 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
1758 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t"); | ||
1759 | for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) { | ||
1760 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | ||
1761 | data->nrg_silence_rssi[cnt]); | ||
1762 | } | ||
1763 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
1764 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n", | ||
1765 | data->nrg_silence_ref); | ||
1766 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n", | ||
1767 | data->nrg_energy_idx); | ||
1768 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n", | ||
1769 | data->nrg_silence_idx); | ||
1770 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n", | ||
1771 | data->nrg_th_cck); | ||
1772 | pos += scnprintf(buf + pos, bufsz - pos, | ||
1773 | "nrg_auto_corr_silence_diff:\t %u\n", | ||
1774 | data->nrg_auto_corr_silence_diff); | ||
1775 | pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n", | ||
1776 | data->num_in_cck_no_fa); | ||
1777 | pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n", | ||
1778 | data->nrg_th_ofdm); | ||
1779 | |||
1780 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1781 | kfree(buf); | ||
1782 | return ret; | ||
1783 | } | ||
1784 | |||
1785 | |||
1786 | static ssize_t iwl_dbgfs_chain_noise_read(struct file *file, | ||
1787 | char __user *user_buf, | ||
1788 | size_t count, loff_t *ppos) { | ||
1789 | |||
1790 | struct iwl_priv *priv = file->private_data; | ||
1791 | int pos = 0; | ||
1792 | int cnt = 0; | ||
1793 | char *buf; | ||
1794 | int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100; | ||
1795 | ssize_t ret; | ||
1796 | struct iwl_chain_noise_data *data; | ||
1797 | |||
1798 | data = &priv->chain_noise_data; | ||
1799 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
1800 | if (!buf) | ||
1801 | return -ENOMEM; | ||
1802 | |||
1803 | pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n", | ||
1804 | data->active_chains); | ||
1805 | pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n", | ||
1806 | data->chain_noise_a); | ||
1807 | pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n", | ||
1808 | data->chain_noise_b); | ||
1809 | pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n", | ||
1810 | data->chain_noise_c); | ||
1811 | pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n", | ||
1812 | data->chain_signal_a); | ||
1813 | pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n", | ||
1814 | data->chain_signal_b); | ||
1815 | pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n", | ||
1816 | data->chain_signal_c); | ||
1817 | pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n", | ||
1818 | data->beacon_count); | ||
1819 | |||
1820 | pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t"); | ||
1821 | for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) { | ||
1822 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | ||
1823 | data->disconn_array[cnt]); | ||
1824 | } | ||
1825 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
1826 | pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t"); | ||
1827 | for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) { | ||
1828 | pos += scnprintf(buf + pos, bufsz - pos, " %u", | ||
1829 | data->delta_gain_code[cnt]); | ||
1830 | } | ||
1831 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
1832 | pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n", | ||
1833 | data->radio_write); | ||
1834 | pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n", | ||
1835 | data->state); | ||
1836 | |||
1837 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1838 | kfree(buf); | ||
1839 | return ret; | ||
1840 | } | ||
1841 | |||
1842 | static ssize_t iwl_dbgfs_power_save_status_read(struct file *file, | ||
1843 | char __user *user_buf, | ||
1844 | size_t count, loff_t *ppos) | ||
1845 | { | ||
1846 | struct iwl_priv *priv = file->private_data; | ||
1847 | char buf[60]; | ||
1848 | int pos = 0; | ||
1849 | const size_t bufsz = sizeof(buf); | ||
1850 | u32 pwrsave_status; | ||
1851 | |||
1852 | pwrsave_status = iwl_read32(priv->trans, CSR_GP_CNTRL) & | ||
1853 | CSR_GP_REG_POWER_SAVE_STATUS_MSK; | ||
1854 | |||
1855 | pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: "); | ||
1856 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", | ||
1857 | (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" : | ||
1858 | (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" : | ||
1859 | (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" : | ||
1860 | "error"); | ||
1861 | |||
1862 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1863 | } | ||
1864 | |||
1865 | static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file, | ||
1866 | const char __user *user_buf, | ||
1867 | size_t count, loff_t *ppos) | ||
1868 | { | ||
1869 | struct iwl_priv *priv = file->private_data; | ||
1870 | char buf[8]; | ||
1871 | int buf_size; | ||
1872 | int clear; | ||
1873 | |||
1874 | memset(buf, 0, sizeof(buf)); | ||
1875 | buf_size = min(count, sizeof(buf) - 1); | ||
1876 | if (copy_from_user(buf, user_buf, buf_size)) | ||
1877 | return -EFAULT; | ||
1878 | if (sscanf(buf, "%d", &clear) != 1) | ||
1879 | return -EFAULT; | ||
1880 | |||
1881 | /* make request to uCode to retrieve statistics information */ | ||
1882 | mutex_lock(&priv->mutex); | ||
1883 | iwl_send_statistics_request(priv, CMD_SYNC, true); | ||
1884 | mutex_unlock(&priv->mutex); | ||
1885 | |||
1886 | return count; | ||
1887 | } | ||
1888 | |||
1889 | static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file, | ||
1890 | char __user *user_buf, | ||
1891 | size_t count, loff_t *ppos) { | ||
1892 | |||
1893 | struct iwl_priv *priv = file->private_data; | ||
1894 | int pos = 0; | ||
1895 | char buf[128]; | ||
1896 | const size_t bufsz = sizeof(buf); | ||
1897 | |||
1898 | pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n", | ||
1899 | priv->event_log.ucode_trace ? "On" : "Off"); | ||
1900 | pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n", | ||
1901 | priv->event_log.non_wraps_count); | ||
1902 | pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n", | ||
1903 | priv->event_log.wraps_once_count); | ||
1904 | pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n", | ||
1905 | priv->event_log.wraps_more_count); | ||
1906 | |||
1907 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1908 | } | ||
1909 | |||
1910 | static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file, | ||
1911 | const char __user *user_buf, | ||
1912 | size_t count, loff_t *ppos) | ||
1913 | { | ||
1914 | struct iwl_priv *priv = file->private_data; | ||
1915 | char buf[8]; | ||
1916 | int buf_size; | ||
1917 | int trace; | ||
1918 | |||
1919 | memset(buf, 0, sizeof(buf)); | ||
1920 | buf_size = min(count, sizeof(buf) - 1); | ||
1921 | if (copy_from_user(buf, user_buf, buf_size)) | ||
1922 | return -EFAULT; | ||
1923 | if (sscanf(buf, "%d", &trace) != 1) | ||
1924 | return -EFAULT; | ||
1925 | |||
1926 | if (trace) { | ||
1927 | priv->event_log.ucode_trace = true; | ||
1928 | if (iwl_is_alive(priv)) { | ||
1929 | /* start collecting data now */ | ||
1930 | mod_timer(&priv->ucode_trace, jiffies); | ||
1931 | } | ||
1932 | } else { | ||
1933 | priv->event_log.ucode_trace = false; | ||
1934 | del_timer_sync(&priv->ucode_trace); | ||
1935 | } | ||
1936 | |||
1937 | return count; | ||
1938 | } | ||
1939 | |||
1940 | static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file, | ||
1941 | char __user *user_buf, | ||
1942 | size_t count, loff_t *ppos) { | ||
1943 | |||
1944 | struct iwl_priv *priv = file->private_data; | ||
1945 | int len = 0; | ||
1946 | char buf[20]; | ||
1947 | |||
1948 | len = sprintf(buf, "0x%04X\n", | ||
1949 | le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags)); | ||
1950 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | ||
1951 | } | ||
1952 | |||
1953 | static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file, | ||
1954 | char __user *user_buf, | ||
1955 | size_t count, loff_t *ppos) { | ||
1956 | |||
1957 | struct iwl_priv *priv = file->private_data; | ||
1958 | int len = 0; | ||
1959 | char buf[20]; | ||
1960 | |||
1961 | len = sprintf(buf, "0x%04X\n", | ||
1962 | le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags)); | ||
1963 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | ||
1964 | } | ||
1965 | |||
1966 | static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file, | ||
1967 | char __user *user_buf, | ||
1968 | size_t count, loff_t *ppos) { | ||
1969 | |||
1970 | struct iwl_priv *priv = file->private_data; | ||
1971 | int pos = 0; | ||
1972 | char buf[12]; | ||
1973 | const size_t bufsz = sizeof(buf); | ||
1974 | |||
1975 | pos += scnprintf(buf + pos, bufsz - pos, "%d\n", | ||
1976 | priv->missed_beacon_threshold); | ||
1977 | |||
1978 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
1979 | } | ||
1980 | |||
1981 | static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file, | ||
1982 | const char __user *user_buf, | ||
1983 | size_t count, loff_t *ppos) | ||
1984 | { | ||
1985 | struct iwl_priv *priv = file->private_data; | ||
1986 | char buf[8]; | ||
1987 | int buf_size; | ||
1988 | int missed; | ||
1989 | |||
1990 | memset(buf, 0, sizeof(buf)); | ||
1991 | buf_size = min(count, sizeof(buf) - 1); | ||
1992 | if (copy_from_user(buf, user_buf, buf_size)) | ||
1993 | return -EFAULT; | ||
1994 | if (sscanf(buf, "%d", &missed) != 1) | ||
1995 | return -EINVAL; | ||
1996 | |||
1997 | if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN || | ||
1998 | missed > IWL_MISSED_BEACON_THRESHOLD_MAX) | ||
1999 | priv->missed_beacon_threshold = | ||
2000 | IWL_MISSED_BEACON_THRESHOLD_DEF; | ||
2001 | else | ||
2002 | priv->missed_beacon_threshold = missed; | ||
2003 | |||
2004 | return count; | ||
2005 | } | ||
2006 | |||
2007 | static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file, | ||
2008 | char __user *user_buf, | ||
2009 | size_t count, loff_t *ppos) { | ||
2010 | |||
2011 | struct iwl_priv *priv = file->private_data; | ||
2012 | int pos = 0; | ||
2013 | char buf[12]; | ||
2014 | const size_t bufsz = sizeof(buf); | ||
2015 | |||
2016 | pos += scnprintf(buf + pos, bufsz - pos, "%u\n", | ||
2017 | priv->plcp_delta_threshold); | ||
2018 | |||
2019 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
2020 | } | ||
2021 | |||
2022 | static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file, | ||
2023 | const char __user *user_buf, | ||
2024 | size_t count, loff_t *ppos) { | ||
2025 | |||
2026 | struct iwl_priv *priv = file->private_data; | ||
2027 | char buf[8]; | ||
2028 | int buf_size; | ||
2029 | int plcp; | ||
2030 | |||
2031 | memset(buf, 0, sizeof(buf)); | ||
2032 | buf_size = min(count, sizeof(buf) - 1); | ||
2033 | if (copy_from_user(buf, user_buf, buf_size)) | ||
2034 | return -EFAULT; | ||
2035 | if (sscanf(buf, "%d", &plcp) != 1) | ||
2036 | return -EINVAL; | ||
2037 | if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) || | ||
2038 | (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX)) | ||
2039 | priv->plcp_delta_threshold = | ||
2040 | IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE; | ||
2041 | else | ||
2042 | priv->plcp_delta_threshold = plcp; | ||
2043 | return count; | ||
2044 | } | ||
2045 | |||
2046 | static ssize_t iwl_dbgfs_rf_reset_read(struct file *file, | ||
2047 | char __user *user_buf, | ||
2048 | size_t count, loff_t *ppos) | ||
2049 | { | ||
2050 | struct iwl_priv *priv = file->private_data; | ||
2051 | int pos = 0; | ||
2052 | char buf[300]; | ||
2053 | const size_t bufsz = sizeof(buf); | ||
2054 | struct iwl_rf_reset *rf_reset = &priv->rf_reset; | ||
2055 | |||
2056 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2057 | "RF reset statistics\n"); | ||
2058 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2059 | "\tnumber of reset request: %d\n", | ||
2060 | rf_reset->reset_request_count); | ||
2061 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2062 | "\tnumber of reset request success: %d\n", | ||
2063 | rf_reset->reset_success_count); | ||
2064 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2065 | "\tnumber of reset request reject: %d\n", | ||
2066 | rf_reset->reset_reject_count); | ||
2067 | |||
2068 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
2069 | } | ||
2070 | |||
2071 | static ssize_t iwl_dbgfs_rf_reset_write(struct file *file, | ||
2072 | const char __user *user_buf, | ||
2073 | size_t count, loff_t *ppos) { | ||
2074 | |||
2075 | struct iwl_priv *priv = file->private_data; | ||
2076 | int ret; | ||
2077 | |||
2078 | ret = iwl_force_rf_reset(priv, true); | ||
2079 | return ret ? ret : count; | ||
2080 | } | ||
2081 | |||
2082 | static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file, | ||
2083 | const char __user *user_buf, | ||
2084 | size_t count, loff_t *ppos) { | ||
2085 | |||
2086 | struct iwl_priv *priv = file->private_data; | ||
2087 | char buf[8]; | ||
2088 | int buf_size; | ||
2089 | int flush; | ||
2090 | |||
2091 | memset(buf, 0, sizeof(buf)); | ||
2092 | buf_size = min(count, sizeof(buf) - 1); | ||
2093 | if (copy_from_user(buf, user_buf, buf_size)) | ||
2094 | return -EFAULT; | ||
2095 | if (sscanf(buf, "%d", &flush) != 1) | ||
2096 | return -EINVAL; | ||
2097 | |||
2098 | if (iwl_is_rfkill(priv)) | ||
2099 | return -EFAULT; | ||
2100 | |||
2101 | iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL); | ||
2102 | |||
2103 | return count; | ||
2104 | } | ||
2105 | |||
2106 | static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file, | ||
2107 | char __user *user_buf, | ||
2108 | size_t count, loff_t *ppos) { | ||
2109 | |||
2110 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; | ||
2111 | int pos = 0; | ||
2112 | char buf[200]; | ||
2113 | const size_t bufsz = sizeof(buf); | ||
2114 | |||
2115 | if (!priv->bt_enable_flag) { | ||
2116 | pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n"); | ||
2117 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
2118 | } | ||
2119 | pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n", | ||
2120 | priv->bt_enable_flag); | ||
2121 | pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n", | ||
2122 | priv->bt_full_concurrent ? "full concurrency" : "3-wire"); | ||
2123 | pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, " | ||
2124 | "last traffic notif: %d\n", | ||
2125 | priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load); | ||
2126 | pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, " | ||
2127 | "kill_ack_mask: %x, kill_cts_mask: %x\n", | ||
2128 | priv->bt_ch_announce, priv->kill_ack_mask, | ||
2129 | priv->kill_cts_mask); | ||
2130 | |||
2131 | pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: "); | ||
2132 | switch (priv->bt_traffic_load) { | ||
2133 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | ||
2134 | pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n"); | ||
2135 | break; | ||
2136 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | ||
2137 | pos += scnprintf(buf + pos, bufsz - pos, "High\n"); | ||
2138 | break; | ||
2139 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | ||
2140 | pos += scnprintf(buf + pos, bufsz - pos, "Low\n"); | ||
2141 | break; | ||
2142 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | ||
2143 | default: | ||
2144 | pos += scnprintf(buf + pos, bufsz - pos, "None\n"); | ||
2145 | break; | ||
2146 | } | ||
2147 | |||
2148 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
2149 | } | ||
2150 | |||
2151 | static ssize_t iwl_dbgfs_protection_mode_read(struct file *file, | ||
2152 | char __user *user_buf, | ||
2153 | size_t count, loff_t *ppos) | ||
2154 | { | ||
2155 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; | ||
2156 | |||
2157 | int pos = 0; | ||
2158 | char buf[40]; | ||
2159 | const size_t bufsz = sizeof(buf); | ||
2160 | |||
2161 | if (priv->cfg->ht_params) | ||
2162 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2163 | "use %s for aggregation\n", | ||
2164 | (priv->hw_params.use_rts_for_aggregation) ? | ||
2165 | "rts/cts" : "cts-to-self"); | ||
2166 | else | ||
2167 | pos += scnprintf(buf + pos, bufsz - pos, "N/A"); | ||
2168 | |||
2169 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
2170 | } | ||
2171 | |||
2172 | static ssize_t iwl_dbgfs_protection_mode_write(struct file *file, | ||
2173 | const char __user *user_buf, | ||
2174 | size_t count, loff_t *ppos) { | ||
2175 | |||
2176 | struct iwl_priv *priv = file->private_data; | ||
2177 | char buf[8]; | ||
2178 | int buf_size; | ||
2179 | int rts; | ||
2180 | |||
2181 | if (!priv->cfg->ht_params) | ||
2182 | return -EINVAL; | ||
2183 | |||
2184 | memset(buf, 0, sizeof(buf)); | ||
2185 | buf_size = min(count, sizeof(buf) - 1); | ||
2186 | if (copy_from_user(buf, user_buf, buf_size)) | ||
2187 | return -EFAULT; | ||
2188 | if (sscanf(buf, "%d", &rts) != 1) | ||
2189 | return -EINVAL; | ||
2190 | if (rts) | ||
2191 | priv->hw_params.use_rts_for_aggregation = true; | ||
2192 | else | ||
2193 | priv->hw_params.use_rts_for_aggregation = false; | ||
2194 | return count; | ||
2195 | } | ||
2196 | |||
2197 | static int iwl_cmd_echo_test(struct iwl_priv *priv) | ||
2198 | { | ||
2199 | int ret; | ||
2200 | struct iwl_host_cmd cmd = { | ||
2201 | .id = REPLY_ECHO, | ||
2202 | .len = { 0 }, | ||
2203 | .flags = CMD_SYNC, | ||
2204 | }; | ||
2205 | |||
2206 | ret = iwl_dvm_send_cmd(priv, &cmd); | ||
2207 | if (ret) | ||
2208 | IWL_ERR(priv, "echo testing fail: 0X%x\n", ret); | ||
2209 | else | ||
2210 | IWL_DEBUG_INFO(priv, "echo testing pass\n"); | ||
2211 | return ret; | ||
2212 | } | ||
2213 | |||
2214 | static ssize_t iwl_dbgfs_echo_test_write(struct file *file, | ||
2215 | const char __user *user_buf, | ||
2216 | size_t count, loff_t *ppos) | ||
2217 | { | ||
2218 | struct iwl_priv *priv = file->private_data; | ||
2219 | char buf[8]; | ||
2220 | int buf_size; | ||
2221 | |||
2222 | memset(buf, 0, sizeof(buf)); | ||
2223 | buf_size = min(count, sizeof(buf) - 1); | ||
2224 | if (copy_from_user(buf, user_buf, buf_size)) | ||
2225 | return -EFAULT; | ||
2226 | |||
2227 | iwl_cmd_echo_test(priv); | ||
2228 | return count; | ||
2229 | } | ||
2230 | |||
2231 | static ssize_t iwl_dbgfs_log_event_read(struct file *file, | ||
2232 | char __user *user_buf, | ||
2233 | size_t count, loff_t *ppos) | ||
2234 | { | ||
2235 | struct iwl_priv *priv = file->private_data; | ||
2236 | char *buf; | ||
2237 | int pos = 0; | ||
2238 | ssize_t ret = -ENOMEM; | ||
2239 | |||
2240 | ret = pos = iwl_dump_nic_event_log(priv, true, &buf, true); | ||
2241 | if (buf) { | ||
2242 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
2243 | kfree(buf); | ||
2244 | } | ||
2245 | return ret; | ||
2246 | } | ||
2247 | |||
2248 | static ssize_t iwl_dbgfs_log_event_write(struct file *file, | ||
2249 | const char __user *user_buf, | ||
2250 | size_t count, loff_t *ppos) | ||
2251 | { | ||
2252 | struct iwl_priv *priv = file->private_data; | ||
2253 | u32 event_log_flag; | ||
2254 | char buf[8]; | ||
2255 | int buf_size; | ||
2256 | |||
2257 | memset(buf, 0, sizeof(buf)); | ||
2258 | buf_size = min(count, sizeof(buf) - 1); | ||
2259 | if (copy_from_user(buf, user_buf, buf_size)) | ||
2260 | return -EFAULT; | ||
2261 | if (sscanf(buf, "%d", &event_log_flag) != 1) | ||
2262 | return -EFAULT; | ||
2263 | if (event_log_flag == 1) | ||
2264 | iwl_dump_nic_event_log(priv, true, NULL, false); | ||
2265 | |||
2266 | return count; | ||
2267 | } | ||
2268 | |||
2269 | static ssize_t iwl_dbgfs_calib_disabled_read(struct file *file, | ||
2270 | char __user *user_buf, | ||
2271 | size_t count, loff_t *ppos) | ||
2272 | { | ||
2273 | struct iwl_priv *priv = file->private_data; | ||
2274 | char buf[120]; | ||
2275 | int pos = 0; | ||
2276 | const size_t bufsz = sizeof(buf); | ||
2277 | |||
2278 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2279 | "Sensitivity calibrations %s\n", | ||
2280 | (priv->calib_disabled & | ||
2281 | IWL_SENSITIVITY_CALIB_DISABLED) ? | ||
2282 | "DISABLED" : "ENABLED"); | ||
2283 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2284 | "Chain noise calibrations %s\n", | ||
2285 | (priv->calib_disabled & | ||
2286 | IWL_CHAIN_NOISE_CALIB_DISABLED) ? | ||
2287 | "DISABLED" : "ENABLED"); | ||
2288 | pos += scnprintf(buf + pos, bufsz - pos, | ||
2289 | "Tx power calibrations %s\n", | ||
2290 | (priv->calib_disabled & | ||
2291 | IWL_TX_POWER_CALIB_DISABLED) ? | ||
2292 | "DISABLED" : "ENABLED"); | ||
2293 | |||
2294 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | ||
2295 | } | ||
2296 | |||
2297 | static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file, | ||
2298 | const char __user *user_buf, | ||
2299 | size_t count, loff_t *ppos) | ||
2300 | { | ||
2301 | struct iwl_priv *priv = file->private_data; | ||
2302 | char buf[8]; | ||
2303 | u32 calib_disabled; | ||
2304 | int buf_size; | ||
2305 | |||
2306 | memset(buf, 0, sizeof(buf)); | ||
2307 | buf_size = min(count, sizeof(buf) - 1); | ||
2308 | if (copy_from_user(buf, user_buf, buf_size)) | ||
2309 | return -EFAULT; | ||
2310 | if (sscanf(buf, "%x", &calib_disabled) != 1) | ||
2311 | return -EFAULT; | ||
2312 | |||
2313 | priv->calib_disabled = calib_disabled; | ||
2314 | |||
2315 | return count; | ||
2316 | } | ||
2317 | |||
2318 | DEBUGFS_READ_FILE_OPS(ucode_rx_stats); | ||
2319 | DEBUGFS_READ_FILE_OPS(ucode_tx_stats); | ||
2320 | DEBUGFS_READ_FILE_OPS(ucode_general_stats); | ||
2321 | DEBUGFS_READ_FILE_OPS(sensitivity); | ||
2322 | DEBUGFS_READ_FILE_OPS(chain_noise); | ||
2323 | DEBUGFS_READ_FILE_OPS(power_save_status); | ||
2324 | DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics); | ||
2325 | DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing); | ||
2326 | DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon); | ||
2327 | DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta); | ||
2328 | DEBUGFS_READ_WRITE_FILE_OPS(rf_reset); | ||
2329 | DEBUGFS_READ_FILE_OPS(rxon_flags); | ||
2330 | DEBUGFS_READ_FILE_OPS(rxon_filter_flags); | ||
2331 | DEBUGFS_WRITE_FILE_OPS(txfifo_flush); | ||
2332 | DEBUGFS_READ_FILE_OPS(ucode_bt_stats); | ||
2333 | DEBUGFS_READ_FILE_OPS(bt_traffic); | ||
2334 | DEBUGFS_READ_WRITE_FILE_OPS(protection_mode); | ||
2335 | DEBUGFS_READ_FILE_OPS(reply_tx_error); | ||
2336 | DEBUGFS_WRITE_FILE_OPS(echo_test); | ||
2337 | DEBUGFS_READ_WRITE_FILE_OPS(log_event); | ||
2338 | DEBUGFS_READ_WRITE_FILE_OPS(calib_disabled); | ||
2339 | |||
2340 | /* | ||
2341 | * Create the debugfs files and directories | ||
2342 | * | ||
2343 | */ | ||
2344 | int iwl_dbgfs_register(struct iwl_priv *priv, const char *name) | ||
2345 | { | ||
2346 | struct dentry *phyd = priv->hw->wiphy->debugfsdir; | ||
2347 | struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug; | ||
2348 | |||
2349 | dir_drv = debugfs_create_dir(name, phyd); | ||
2350 | if (!dir_drv) | ||
2351 | return -ENOMEM; | ||
2352 | |||
2353 | priv->debugfs_dir = dir_drv; | ||
2354 | |||
2355 | dir_data = debugfs_create_dir("data", dir_drv); | ||
2356 | if (!dir_data) | ||
2357 | goto err; | ||
2358 | dir_rf = debugfs_create_dir("rf", dir_drv); | ||
2359 | if (!dir_rf) | ||
2360 | goto err; | ||
2361 | dir_debug = debugfs_create_dir("debug", dir_drv); | ||
2362 | if (!dir_debug) | ||
2363 | goto err; | ||
2364 | |||
2365 | DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR); | ||
2366 | DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR); | ||
2367 | DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR); | ||
2368 | DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR); | ||
2369 | DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR); | ||
2370 | DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR); | ||
2371 | DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR); | ||
2372 | DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR); | ||
2373 | DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR); | ||
2374 | DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR); | ||
2375 | DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR); | ||
2376 | DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR); | ||
2377 | DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR); | ||
2378 | |||
2379 | DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR); | ||
2380 | DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR); | ||
2381 | DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR); | ||
2382 | DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR); | ||
2383 | DEBUGFS_ADD_FILE(rf_reset, dir_debug, S_IWUSR | S_IRUSR); | ||
2384 | DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR); | ||
2385 | DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR); | ||
2386 | DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR); | ||
2387 | DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR); | ||
2388 | DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR); | ||
2389 | DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR); | ||
2390 | DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR); | ||
2391 | DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR); | ||
2392 | DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR); | ||
2393 | DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR); | ||
2394 | DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR); | ||
2395 | DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR); | ||
2396 | DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR); | ||
2397 | DEBUGFS_ADD_FILE(log_event, dir_debug, S_IWUSR | S_IRUSR); | ||
2398 | |||
2399 | if (iwl_advanced_bt_coexist(priv)) | ||
2400 | DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR); | ||
2401 | |||
2402 | /* Calibrations disabled/enabled status*/ | ||
2403 | DEBUGFS_ADD_FILE(calib_disabled, dir_rf, S_IWUSR | S_IRUSR); | ||
2404 | |||
2405 | if (iwl_trans_dbgfs_register(priv->trans, dir_debug)) | ||
2406 | goto err; | ||
2407 | return 0; | ||
2408 | |||
2409 | err: | ||
2410 | IWL_ERR(priv, "Can't create the debugfs directory\n"); | ||
2411 | iwl_dbgfs_unregister(priv); | ||
2412 | return -ENOMEM; | ||
2413 | } | ||
2414 | |||
2415 | /** | ||
2416 | * Remove the debugfs files and directories | ||
2417 | * | ||
2418 | */ | ||
2419 | void iwl_dbgfs_unregister(struct iwl_priv *priv) | ||
2420 | { | ||
2421 | if (!priv->debugfs_dir) | ||
2422 | return; | ||
2423 | |||
2424 | debugfs_remove_recursive(priv->debugfs_dir); | ||
2425 | priv->debugfs_dir = NULL; | ||
2426 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/dev.h b/drivers/net/wireless/iwlwifi/dvm/dev.h new file mode 100644 index 000000000000..89f2e1040e7f --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/dev.h | |||
@@ -0,0 +1,953 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of version 2 of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | /* | ||
27 | * Please use this file (dev.h) for driver implementation definitions. | ||
28 | * Please use commands.h for uCode API definitions. | ||
29 | */ | ||
30 | |||
31 | #ifndef __iwl_dev_h__ | ||
32 | #define __iwl_dev_h__ | ||
33 | |||
34 | #include <linux/interrupt.h> | ||
35 | #include <linux/kernel.h> | ||
36 | #include <linux/wait.h> | ||
37 | #include <linux/leds.h> | ||
38 | #include <linux/slab.h> | ||
39 | #include <linux/mutex.h> | ||
40 | |||
41 | #include "iwl-fw.h" | ||
42 | #include "iwl-eeprom-parse.h" | ||
43 | #include "iwl-csr.h" | ||
44 | #include "iwl-debug.h" | ||
45 | #include "iwl-agn-hw.h" | ||
46 | #include "iwl-op-mode.h" | ||
47 | #include "iwl-notif-wait.h" | ||
48 | #include "iwl-trans.h" | ||
49 | |||
50 | #include "led.h" | ||
51 | #include "power.h" | ||
52 | #include "rs.h" | ||
53 | #include "tt.h" | ||
54 | |||
55 | /* CT-KILL constants */ | ||
56 | #define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */ | ||
57 | #define CT_KILL_THRESHOLD 114 /* in Celsius */ | ||
58 | #define CT_KILL_EXIT_THRESHOLD 95 /* in Celsius */ | ||
59 | |||
60 | /* Default noise level to report when noise measurement is not available. | ||
61 | * This may be because we're: | ||
62 | * 1) Not associated no beacon statistics being sent to driver) | ||
63 | * 2) Scanning (noise measurement does not apply to associated channel) | ||
64 | * Use default noise value of -127 ... this is below the range of measurable | ||
65 | * Rx dBm for all agn devices, so it can indicate "unmeasurable" to user. | ||
66 | * Also, -127 works better than 0 when averaging frames with/without | ||
67 | * noise info (e.g. averaging might be done in app); measured dBm values are | ||
68 | * always negative ... using a negative value as the default keeps all | ||
69 | * averages within an s8's (used in some apps) range of negative values. */ | ||
70 | #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127) | ||
71 | |||
72 | /* | ||
73 | * RTS threshold here is total size [2347] minus 4 FCS bytes | ||
74 | * Per spec: | ||
75 | * a value of 0 means RTS on all data/management packets | ||
76 | * a value > max MSDU size means no RTS | ||
77 | * else RTS for data/management frames where MPDU is larger | ||
78 | * than RTS value. | ||
79 | */ | ||
80 | #define DEFAULT_RTS_THRESHOLD 2347U | ||
81 | #define MIN_RTS_THRESHOLD 0U | ||
82 | #define MAX_RTS_THRESHOLD 2347U | ||
83 | #define MAX_MSDU_SIZE 2304U | ||
84 | #define MAX_MPDU_SIZE 2346U | ||
85 | #define DEFAULT_BEACON_INTERVAL 200U | ||
86 | #define DEFAULT_SHORT_RETRY_LIMIT 7U | ||
87 | #define DEFAULT_LONG_RETRY_LIMIT 4U | ||
88 | |||
89 | #define IWL_NUM_SCAN_RATES (2) | ||
90 | |||
91 | /* | ||
92 | * Minimum number of queues. MAX_NUM is defined in hw specific files. | ||
93 | * Set the minimum to accommodate | ||
94 | * - 4 standard TX queues | ||
95 | * - the command queue | ||
96 | * - 4 PAN TX queues | ||
97 | * - the PAN multicast queue, and | ||
98 | * - the AUX (TX during scan dwell) queue. | ||
99 | */ | ||
100 | #define IWL_MIN_NUM_QUEUES 11 | ||
101 | |||
102 | /* | ||
103 | * Command queue depends on iPAN support. | ||
104 | */ | ||
105 | #define IWL_DEFAULT_CMD_QUEUE_NUM 4 | ||
106 | #define IWL_IPAN_CMD_QUEUE_NUM 9 | ||
107 | |||
108 | #define IEEE80211_DATA_LEN 2304 | ||
109 | #define IEEE80211_4ADDR_LEN 30 | ||
110 | #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN) | ||
111 | #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN) | ||
112 | |||
113 | #define SUP_RATE_11A_MAX_NUM_CHANNELS 8 | ||
114 | #define SUP_RATE_11B_MAX_NUM_CHANNELS 4 | ||
115 | #define SUP_RATE_11G_MAX_NUM_CHANNELS 12 | ||
116 | |||
117 | #define IWL_SUPPORTED_RATES_IE_LEN 8 | ||
118 | |||
119 | #define IWL_INVALID_RATE 0xFF | ||
120 | #define IWL_INVALID_VALUE -1 | ||
121 | |||
122 | union iwl_ht_rate_supp { | ||
123 | u16 rates; | ||
124 | struct { | ||
125 | u8 siso_rate; | ||
126 | u8 mimo_rate; | ||
127 | }; | ||
128 | }; | ||
129 | |||
130 | struct iwl_ht_config { | ||
131 | bool single_chain_sufficient; | ||
132 | enum ieee80211_smps_mode smps; /* current smps mode */ | ||
133 | }; | ||
134 | |||
135 | /* QoS structures */ | ||
136 | struct iwl_qos_info { | ||
137 | int qos_active; | ||
138 | struct iwl_qosparam_cmd def_qos_parm; | ||
139 | }; | ||
140 | |||
141 | /** | ||
142 | * enum iwl_agg_state | ||
143 | * | ||
144 | * The state machine of the BA agreement establishment / tear down. | ||
145 | * These states relate to a specific RA / TID. | ||
146 | * | ||
147 | * @IWL_AGG_OFF: aggregation is not used | ||
148 | * @IWL_AGG_STARTING: aggregation are starting (between start and oper) | ||
149 | * @IWL_AGG_ON: aggregation session is up | ||
150 | * @IWL_EMPTYING_HW_QUEUE_ADDBA: establishing a BA session - waiting for the | ||
151 | * HW queue to be empty from packets for this RA /TID. | ||
152 | * @IWL_EMPTYING_HW_QUEUE_DELBA: tearing down a BA session - waiting for the | ||
153 | * HW queue to be empty from packets for this RA /TID. | ||
154 | */ | ||
155 | enum iwl_agg_state { | ||
156 | IWL_AGG_OFF = 0, | ||
157 | IWL_AGG_STARTING, | ||
158 | IWL_AGG_ON, | ||
159 | IWL_EMPTYING_HW_QUEUE_ADDBA, | ||
160 | IWL_EMPTYING_HW_QUEUE_DELBA, | ||
161 | }; | ||
162 | |||
163 | /** | ||
164 | * struct iwl_ht_agg - aggregation state machine | ||
165 | |||
166 | * This structs holds the states for the BA agreement establishment and tear | ||
167 | * down. It also holds the state during the BA session itself. This struct is | ||
168 | * duplicated for each RA / TID. | ||
169 | |||
170 | * @rate_n_flags: Rate at which Tx was attempted. Holds the data between the | ||
171 | * Tx response (REPLY_TX), and the block ack notification | ||
172 | * (REPLY_COMPRESSED_BA). | ||
173 | * @state: state of the BA agreement establishment / tear down. | ||
174 | * @txq_id: Tx queue used by the BA session | ||
175 | * @ssn: the first packet to be sent in AGG HW queue in Tx AGG start flow, or | ||
176 | * the first packet to be sent in legacy HW queue in Tx AGG stop flow. | ||
177 | * Basically when next_reclaimed reaches ssn, we can tell mac80211 that | ||
178 | * we are ready to finish the Tx AGG stop / start flow. | ||
179 | * @wait_for_ba: Expect block-ack before next Tx reply | ||
180 | */ | ||
181 | struct iwl_ht_agg { | ||
182 | u32 rate_n_flags; | ||
183 | enum iwl_agg_state state; | ||
184 | u16 txq_id; | ||
185 | u16 ssn; | ||
186 | bool wait_for_ba; | ||
187 | }; | ||
188 | |||
189 | /** | ||
190 | * struct iwl_tid_data - one for each RA / TID | ||
191 | |||
192 | * This structs holds the states for each RA / TID. | ||
193 | |||
194 | * @seq_number: the next WiFi sequence number to use | ||
195 | * @next_reclaimed: the WiFi sequence number of the next packet to be acked. | ||
196 | * This is basically (last acked packet++). | ||
197 | * @agg: aggregation state machine | ||
198 | */ | ||
199 | struct iwl_tid_data { | ||
200 | u16 seq_number; | ||
201 | u16 next_reclaimed; | ||
202 | struct iwl_ht_agg agg; | ||
203 | }; | ||
204 | |||
205 | /* | ||
206 | * Structure should be accessed with sta_lock held. When station addition | ||
207 | * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only | ||
208 | * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock | ||
209 | * held. | ||
210 | */ | ||
211 | struct iwl_station_entry { | ||
212 | struct iwl_addsta_cmd sta; | ||
213 | u8 used, ctxid; | ||
214 | struct iwl_link_quality_cmd *lq; | ||
215 | }; | ||
216 | |||
217 | /* | ||
218 | * iwl_station_priv: Driver's private station information | ||
219 | * | ||
220 | * When mac80211 creates a station it reserves some space (hw->sta_data_size) | ||
221 | * in the structure for use by driver. This structure is places in that | ||
222 | * space. | ||
223 | */ | ||
224 | struct iwl_station_priv { | ||
225 | struct iwl_rxon_context *ctx; | ||
226 | struct iwl_lq_sta lq_sta; | ||
227 | atomic_t pending_frames; | ||
228 | bool client; | ||
229 | bool asleep; | ||
230 | u8 max_agg_bufsize; | ||
231 | u8 sta_id; | ||
232 | }; | ||
233 | |||
234 | /** | ||
235 | * struct iwl_vif_priv - driver's private per-interface information | ||
236 | * | ||
237 | * When mac80211 allocates a virtual interface, it can allocate | ||
238 | * space for us to put data into. | ||
239 | */ | ||
240 | struct iwl_vif_priv { | ||
241 | struct iwl_rxon_context *ctx; | ||
242 | u8 ibss_bssid_sta_id; | ||
243 | }; | ||
244 | |||
245 | struct iwl_sensitivity_ranges { | ||
246 | u16 min_nrg_cck; | ||
247 | |||
248 | u16 nrg_th_cck; | ||
249 | u16 nrg_th_ofdm; | ||
250 | |||
251 | u16 auto_corr_min_ofdm; | ||
252 | u16 auto_corr_min_ofdm_mrc; | ||
253 | u16 auto_corr_min_ofdm_x1; | ||
254 | u16 auto_corr_min_ofdm_mrc_x1; | ||
255 | |||
256 | u16 auto_corr_max_ofdm; | ||
257 | u16 auto_corr_max_ofdm_mrc; | ||
258 | u16 auto_corr_max_ofdm_x1; | ||
259 | u16 auto_corr_max_ofdm_mrc_x1; | ||
260 | |||
261 | u16 auto_corr_max_cck; | ||
262 | u16 auto_corr_max_cck_mrc; | ||
263 | u16 auto_corr_min_cck; | ||
264 | u16 auto_corr_min_cck_mrc; | ||
265 | |||
266 | u16 barker_corr_th_min; | ||
267 | u16 barker_corr_th_min_mrc; | ||
268 | u16 nrg_th_cca; | ||
269 | }; | ||
270 | |||
271 | |||
272 | #define KELVIN_TO_CELSIUS(x) ((x)-273) | ||
273 | #define CELSIUS_TO_KELVIN(x) ((x)+273) | ||
274 | |||
275 | |||
276 | /****************************************************************************** | ||
277 | * | ||
278 | * Functions implemented in core module which are forward declared here | ||
279 | * for use by iwl-[4-5].c | ||
280 | * | ||
281 | * NOTE: The implementation of these functions are not hardware specific | ||
282 | * which is why they are in the core module files. | ||
283 | * | ||
284 | * Naming convention -- | ||
285 | * iwl_ <-- Is part of iwlwifi | ||
286 | * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX) | ||
287 | * | ||
288 | ****************************************************************************/ | ||
289 | extern void iwl_update_chain_flags(struct iwl_priv *priv); | ||
290 | extern const u8 iwl_bcast_addr[ETH_ALEN]; | ||
291 | |||
292 | #define IWL_OPERATION_MODE_AUTO 0 | ||
293 | #define IWL_OPERATION_MODE_HT_ONLY 1 | ||
294 | #define IWL_OPERATION_MODE_MIXED 2 | ||
295 | #define IWL_OPERATION_MODE_20MHZ 3 | ||
296 | |||
297 | #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000 | ||
298 | |||
299 | /* Sensitivity and chain noise calibration */ | ||
300 | #define INITIALIZATION_VALUE 0xFFFF | ||
301 | #define IWL_CAL_NUM_BEACONS 16 | ||
302 | #define MAXIMUM_ALLOWED_PATHLOSS 15 | ||
303 | |||
304 | #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3 | ||
305 | |||
306 | #define MAX_FA_OFDM 50 | ||
307 | #define MIN_FA_OFDM 5 | ||
308 | #define MAX_FA_CCK 50 | ||
309 | #define MIN_FA_CCK 5 | ||
310 | |||
311 | #define AUTO_CORR_STEP_OFDM 1 | ||
312 | |||
313 | #define AUTO_CORR_STEP_CCK 3 | ||
314 | #define AUTO_CORR_MAX_TH_CCK 160 | ||
315 | |||
316 | #define NRG_DIFF 2 | ||
317 | #define NRG_STEP_CCK 2 | ||
318 | #define NRG_MARGIN 8 | ||
319 | #define MAX_NUMBER_CCK_NO_FA 100 | ||
320 | |||
321 | #define AUTO_CORR_CCK_MIN_VAL_DEF (125) | ||
322 | |||
323 | #define CHAIN_A 0 | ||
324 | #define CHAIN_B 1 | ||
325 | #define CHAIN_C 2 | ||
326 | #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4 | ||
327 | #define ALL_BAND_FILTER 0xFF00 | ||
328 | #define IN_BAND_FILTER 0xFF | ||
329 | #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF | ||
330 | |||
331 | #define NRG_NUM_PREV_STAT_L 20 | ||
332 | #define NUM_RX_CHAINS 3 | ||
333 | |||
334 | enum iwlagn_false_alarm_state { | ||
335 | IWL_FA_TOO_MANY = 0, | ||
336 | IWL_FA_TOO_FEW = 1, | ||
337 | IWL_FA_GOOD_RANGE = 2, | ||
338 | }; | ||
339 | |||
340 | enum iwlagn_chain_noise_state { | ||
341 | IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */ | ||
342 | IWL_CHAIN_NOISE_ACCUMULATE, | ||
343 | IWL_CHAIN_NOISE_CALIBRATED, | ||
344 | IWL_CHAIN_NOISE_DONE, | ||
345 | }; | ||
346 | |||
347 | /* Sensitivity calib data */ | ||
348 | struct iwl_sensitivity_data { | ||
349 | u32 auto_corr_ofdm; | ||
350 | u32 auto_corr_ofdm_mrc; | ||
351 | u32 auto_corr_ofdm_x1; | ||
352 | u32 auto_corr_ofdm_mrc_x1; | ||
353 | u32 auto_corr_cck; | ||
354 | u32 auto_corr_cck_mrc; | ||
355 | |||
356 | u32 last_bad_plcp_cnt_ofdm; | ||
357 | u32 last_fa_cnt_ofdm; | ||
358 | u32 last_bad_plcp_cnt_cck; | ||
359 | u32 last_fa_cnt_cck; | ||
360 | |||
361 | u32 nrg_curr_state; | ||
362 | u32 nrg_prev_state; | ||
363 | u32 nrg_value[10]; | ||
364 | u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L]; | ||
365 | u32 nrg_silence_ref; | ||
366 | u32 nrg_energy_idx; | ||
367 | u32 nrg_silence_idx; | ||
368 | u32 nrg_th_cck; | ||
369 | s32 nrg_auto_corr_silence_diff; | ||
370 | u32 num_in_cck_no_fa; | ||
371 | u32 nrg_th_ofdm; | ||
372 | |||
373 | u16 barker_corr_th_min; | ||
374 | u16 barker_corr_th_min_mrc; | ||
375 | u16 nrg_th_cca; | ||
376 | }; | ||
377 | |||
378 | /* Chain noise (differential Rx gain) calib data */ | ||
379 | struct iwl_chain_noise_data { | ||
380 | u32 active_chains; | ||
381 | u32 chain_noise_a; | ||
382 | u32 chain_noise_b; | ||
383 | u32 chain_noise_c; | ||
384 | u32 chain_signal_a; | ||
385 | u32 chain_signal_b; | ||
386 | u32 chain_signal_c; | ||
387 | u16 beacon_count; | ||
388 | u8 disconn_array[NUM_RX_CHAINS]; | ||
389 | u8 delta_gain_code[NUM_RX_CHAINS]; | ||
390 | u8 radio_write; | ||
391 | u8 state; | ||
392 | }; | ||
393 | |||
394 | enum { | ||
395 | MEASUREMENT_READY = (1 << 0), | ||
396 | MEASUREMENT_ACTIVE = (1 << 1), | ||
397 | }; | ||
398 | |||
399 | /* reply_tx_statistics (for _agn devices) */ | ||
400 | struct reply_tx_error_statistics { | ||
401 | u32 pp_delay; | ||
402 | u32 pp_few_bytes; | ||
403 | u32 pp_bt_prio; | ||
404 | u32 pp_quiet_period; | ||
405 | u32 pp_calc_ttak; | ||
406 | u32 int_crossed_retry; | ||
407 | u32 short_limit; | ||
408 | u32 long_limit; | ||
409 | u32 fifo_underrun; | ||
410 | u32 drain_flow; | ||
411 | u32 rfkill_flush; | ||
412 | u32 life_expire; | ||
413 | u32 dest_ps; | ||
414 | u32 host_abort; | ||
415 | u32 bt_retry; | ||
416 | u32 sta_invalid; | ||
417 | u32 frag_drop; | ||
418 | u32 tid_disable; | ||
419 | u32 fifo_flush; | ||
420 | u32 insuff_cf_poll; | ||
421 | u32 fail_hw_drop; | ||
422 | u32 sta_color_mismatch; | ||
423 | u32 unknown; | ||
424 | }; | ||
425 | |||
426 | /* reply_agg_tx_statistics (for _agn devices) */ | ||
427 | struct reply_agg_tx_error_statistics { | ||
428 | u32 underrun; | ||
429 | u32 bt_prio; | ||
430 | u32 few_bytes; | ||
431 | u32 abort; | ||
432 | u32 last_sent_ttl; | ||
433 | u32 last_sent_try; | ||
434 | u32 last_sent_bt_kill; | ||
435 | u32 scd_query; | ||
436 | u32 bad_crc32; | ||
437 | u32 response; | ||
438 | u32 dump_tx; | ||
439 | u32 delay_tx; | ||
440 | u32 unknown; | ||
441 | }; | ||
442 | |||
443 | /* | ||
444 | * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds | ||
445 | * to perform continuous uCode event logging operation if enabled | ||
446 | */ | ||
447 | #define UCODE_TRACE_PERIOD (10) | ||
448 | |||
449 | /* | ||
450 | * iwl_event_log: current uCode event log position | ||
451 | * | ||
452 | * @ucode_trace: enable/disable ucode continuous trace timer | ||
453 | * @num_wraps: how many times the event buffer wraps | ||
454 | * @next_entry: the entry just before the next one that uCode would fill | ||
455 | * @non_wraps_count: counter for no wrap detected when dump ucode events | ||
456 | * @wraps_once_count: counter for wrap once detected when dump ucode events | ||
457 | * @wraps_more_count: counter for wrap more than once detected | ||
458 | * when dump ucode events | ||
459 | */ | ||
460 | struct iwl_event_log { | ||
461 | bool ucode_trace; | ||
462 | u32 num_wraps; | ||
463 | u32 next_entry; | ||
464 | int non_wraps_count; | ||
465 | int wraps_once_count; | ||
466 | int wraps_more_count; | ||
467 | }; | ||
468 | |||
469 | #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3) | ||
470 | |||
471 | /* BT Antenna Coupling Threshold (dB) */ | ||
472 | #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35) | ||
473 | |||
474 | /* Firmware reload counter and Timestamp */ | ||
475 | #define IWL_MIN_RELOAD_DURATION 1000 /* 1000 ms */ | ||
476 | #define IWL_MAX_CONTINUE_RELOAD_CNT 4 | ||
477 | |||
478 | |||
479 | struct iwl_rf_reset { | ||
480 | int reset_request_count; | ||
481 | int reset_success_count; | ||
482 | int reset_reject_count; | ||
483 | unsigned long last_reset_jiffies; | ||
484 | }; | ||
485 | |||
486 | enum iwl_rxon_context_id { | ||
487 | IWL_RXON_CTX_BSS, | ||
488 | IWL_RXON_CTX_PAN, | ||
489 | |||
490 | NUM_IWL_RXON_CTX | ||
491 | }; | ||
492 | |||
493 | /* extend beacon time format bit shifting */ | ||
494 | /* | ||
495 | * for _agn devices | ||
496 | * bits 31:22 - extended | ||
497 | * bits 21:0 - interval | ||
498 | */ | ||
499 | #define IWLAGN_EXT_BEACON_TIME_POS 22 | ||
500 | |||
501 | struct iwl_rxon_context { | ||
502 | struct ieee80211_vif *vif; | ||
503 | |||
504 | u8 mcast_queue; | ||
505 | u8 ac_to_queue[IEEE80211_NUM_ACS]; | ||
506 | u8 ac_to_fifo[IEEE80211_NUM_ACS]; | ||
507 | |||
508 | /* | ||
509 | * We could use the vif to indicate active, but we | ||
510 | * also need it to be active during disabling when | ||
511 | * we already removed the vif for type setting. | ||
512 | */ | ||
513 | bool always_active, is_active; | ||
514 | |||
515 | bool ht_need_multiple_chains; | ||
516 | |||
517 | enum iwl_rxon_context_id ctxid; | ||
518 | |||
519 | u32 interface_modes, exclusive_interface_modes; | ||
520 | u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype; | ||
521 | |||
522 | /* | ||
523 | * We declare this const so it can only be | ||
524 | * changed via explicit cast within the | ||
525 | * routines that actually update the physical | ||
526 | * hardware. | ||
527 | */ | ||
528 | const struct iwl_rxon_cmd active; | ||
529 | struct iwl_rxon_cmd staging; | ||
530 | |||
531 | struct iwl_rxon_time_cmd timing; | ||
532 | |||
533 | struct iwl_qos_info qos_data; | ||
534 | |||
535 | u8 bcast_sta_id, ap_sta_id; | ||
536 | |||
537 | u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd; | ||
538 | u8 qos_cmd; | ||
539 | u8 wep_key_cmd; | ||
540 | |||
541 | struct iwl_wep_key wep_keys[WEP_KEYS_MAX]; | ||
542 | u8 key_mapping_keys; | ||
543 | |||
544 | __le32 station_flags; | ||
545 | |||
546 | int beacon_int; | ||
547 | |||
548 | struct { | ||
549 | bool non_gf_sta_present; | ||
550 | u8 protection; | ||
551 | bool enabled, is_40mhz; | ||
552 | u8 extension_chan_offset; | ||
553 | } ht; | ||
554 | }; | ||
555 | |||
556 | enum iwl_scan_type { | ||
557 | IWL_SCAN_NORMAL, | ||
558 | IWL_SCAN_RADIO_RESET, | ||
559 | IWL_SCAN_ROC, | ||
560 | }; | ||
561 | |||
562 | /** | ||
563 | * struct iwl_hw_params | ||
564 | * | ||
565 | * Holds the module parameters | ||
566 | * | ||
567 | * @tx_chains_num: Number of TX chains | ||
568 | * @rx_chains_num: Number of RX chains | ||
569 | * @sku: sku read from EEPROM | ||
570 | * @ct_kill_threshold: temperature threshold - in hw dependent unit | ||
571 | * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit | ||
572 | * relevant for 1000, 6000 and up | ||
573 | * @struct iwl_sensitivity_ranges: range of sensitivity values | ||
574 | * @use_rts_for_aggregation: use rts/cts protection for HT traffic | ||
575 | */ | ||
576 | struct iwl_hw_params { | ||
577 | u8 tx_chains_num; | ||
578 | u8 rx_chains_num; | ||
579 | bool use_rts_for_aggregation; | ||
580 | u16 sku; | ||
581 | u32 ct_kill_threshold; | ||
582 | u32 ct_kill_exit_threshold; | ||
583 | |||
584 | const struct iwl_sensitivity_ranges *sens; | ||
585 | }; | ||
586 | |||
587 | struct iwl_lib_ops { | ||
588 | /* set hw dependent parameters */ | ||
589 | void (*set_hw_params)(struct iwl_priv *priv); | ||
590 | int (*set_channel_switch)(struct iwl_priv *priv, | ||
591 | struct ieee80211_channel_switch *ch_switch); | ||
592 | /* device specific configuration */ | ||
593 | void (*nic_config)(struct iwl_priv *priv); | ||
594 | |||
595 | /* temperature */ | ||
596 | void (*temperature)(struct iwl_priv *priv); | ||
597 | }; | ||
598 | |||
599 | #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE | ||
600 | struct iwl_testmode_trace { | ||
601 | u32 buff_size; | ||
602 | u32 total_size; | ||
603 | u32 num_chunks; | ||
604 | u8 *cpu_addr; | ||
605 | u8 *trace_addr; | ||
606 | dma_addr_t dma_addr; | ||
607 | bool trace_enabled; | ||
608 | }; | ||
609 | struct iwl_testmode_mem { | ||
610 | u32 buff_size; | ||
611 | u32 num_chunks; | ||
612 | u8 *buff_addr; | ||
613 | bool read_in_progress; | ||
614 | }; | ||
615 | #endif | ||
616 | |||
617 | struct iwl_wipan_noa_data { | ||
618 | struct rcu_head rcu_head; | ||
619 | u32 length; | ||
620 | u8 data[]; | ||
621 | }; | ||
622 | |||
623 | /* Calibration disabling bit mask */ | ||
624 | enum { | ||
625 | IWL_CALIB_ENABLE_ALL = 0, | ||
626 | |||
627 | IWL_SENSITIVITY_CALIB_DISABLED = BIT(0), | ||
628 | IWL_CHAIN_NOISE_CALIB_DISABLED = BIT(1), | ||
629 | IWL_TX_POWER_CALIB_DISABLED = BIT(2), | ||
630 | |||
631 | IWL_CALIB_DISABLE_ALL = 0xFFFFFFFF, | ||
632 | }; | ||
633 | |||
634 | #define IWL_OP_MODE_GET_DVM(_iwl_op_mode) \ | ||
635 | ((struct iwl_priv *) ((_iwl_op_mode)->op_mode_specific)) | ||
636 | |||
637 | #define IWL_MAC80211_GET_DVM(_hw) \ | ||
638 | ((struct iwl_priv *) ((struct iwl_op_mode *) \ | ||
639 | (_hw)->priv)->op_mode_specific) | ||
640 | |||
641 | struct iwl_priv { | ||
642 | |||
643 | struct iwl_trans *trans; | ||
644 | struct device *dev; /* for debug prints only */ | ||
645 | const struct iwl_cfg *cfg; | ||
646 | const struct iwl_fw *fw; | ||
647 | const struct iwl_lib_ops *lib; | ||
648 | unsigned long status; | ||
649 | |||
650 | spinlock_t sta_lock; | ||
651 | struct mutex mutex; | ||
652 | |||
653 | unsigned long transport_queue_stop; | ||
654 | bool passive_no_rx; | ||
655 | #define IWL_INVALID_MAC80211_QUEUE 0xff | ||
656 | u8 queue_to_mac80211[IWL_MAX_HW_QUEUES]; | ||
657 | atomic_t queue_stop_count[IWL_MAX_HW_QUEUES]; | ||
658 | |||
659 | unsigned long agg_q_alloc[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)]; | ||
660 | |||
661 | /* ieee device used by generic ieee processing code */ | ||
662 | struct ieee80211_hw *hw; | ||
663 | |||
664 | struct list_head calib_results; | ||
665 | |||
666 | struct workqueue_struct *workqueue; | ||
667 | |||
668 | struct iwl_hw_params hw_params; | ||
669 | |||
670 | enum ieee80211_band band; | ||
671 | u8 valid_contexts; | ||
672 | |||
673 | void (*pre_rx_handler)(struct iwl_priv *priv, | ||
674 | struct iwl_rx_cmd_buffer *rxb); | ||
675 | int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv, | ||
676 | struct iwl_rx_cmd_buffer *rxb, | ||
677 | struct iwl_device_cmd *cmd); | ||
678 | |||
679 | struct iwl_notif_wait_data notif_wait; | ||
680 | |||
681 | /* spectrum measurement report caching */ | ||
682 | struct iwl_spectrum_notification measure_report; | ||
683 | u8 measurement_status; | ||
684 | |||
685 | #define IWL_OWNERSHIP_DRIVER 0 | ||
686 | #define IWL_OWNERSHIP_TM 1 | ||
687 | u8 ucode_owner; | ||
688 | |||
689 | /* ucode beacon time */ | ||
690 | u32 ucode_beacon_time; | ||
691 | int missed_beacon_threshold; | ||
692 | |||
693 | /* track IBSS manager (last beacon) status */ | ||
694 | u32 ibss_manager; | ||
695 | |||
696 | /* jiffies when last recovery from statistics was performed */ | ||
697 | unsigned long rx_statistics_jiffies; | ||
698 | |||
699 | /*counters */ | ||
700 | u32 rx_handlers_stats[REPLY_MAX]; | ||
701 | |||
702 | /* rf reset */ | ||
703 | struct iwl_rf_reset rf_reset; | ||
704 | |||
705 | /* firmware reload counter and timestamp */ | ||
706 | unsigned long reload_jiffies; | ||
707 | int reload_count; | ||
708 | bool ucode_loaded; | ||
709 | bool init_ucode_run; /* Don't run init uCode again */ | ||
710 | |||
711 | u8 plcp_delta_threshold; | ||
712 | |||
713 | /* thermal calibration */ | ||
714 | s32 temperature; /* Celsius */ | ||
715 | s32 last_temperature; | ||
716 | |||
717 | struct iwl_wipan_noa_data __rcu *noa_data; | ||
718 | |||
719 | /* Scan related variables */ | ||
720 | unsigned long scan_start; | ||
721 | unsigned long scan_start_tsf; | ||
722 | void *scan_cmd; | ||
723 | enum ieee80211_band scan_band; | ||
724 | struct cfg80211_scan_request *scan_request; | ||
725 | struct ieee80211_vif *scan_vif; | ||
726 | enum iwl_scan_type scan_type; | ||
727 | u8 scan_tx_ant[IEEE80211_NUM_BANDS]; | ||
728 | u8 mgmt_tx_ant; | ||
729 | |||
730 | /* max number of station keys */ | ||
731 | u8 sta_key_max_num; | ||
732 | |||
733 | bool new_scan_threshold_behaviour; | ||
734 | |||
735 | bool wowlan; | ||
736 | |||
737 | /* EEPROM MAC addresses */ | ||
738 | struct mac_address addresses[2]; | ||
739 | |||
740 | struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX]; | ||
741 | |||
742 | __le16 switch_channel; | ||
743 | |||
744 | u8 start_calib; | ||
745 | struct iwl_sensitivity_data sensitivity_data; | ||
746 | struct iwl_chain_noise_data chain_noise_data; | ||
747 | __le16 sensitivity_tbl[HD_TABLE_SIZE]; | ||
748 | __le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES]; | ||
749 | |||
750 | struct iwl_ht_config current_ht_config; | ||
751 | |||
752 | /* Rate scaling data */ | ||
753 | u8 retry_rate; | ||
754 | |||
755 | int activity_timer_active; | ||
756 | |||
757 | struct iwl_power_mgr power_data; | ||
758 | struct iwl_tt_mgmt thermal_throttle; | ||
759 | |||
760 | /* station table variables */ | ||
761 | int num_stations; | ||
762 | struct iwl_station_entry stations[IWLAGN_STATION_COUNT]; | ||
763 | unsigned long ucode_key_table; | ||
764 | struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT]; | ||
765 | atomic_t num_aux_in_flight; | ||
766 | |||
767 | u8 mac80211_registered; | ||
768 | |||
769 | /* Indication if ieee80211_ops->open has been called */ | ||
770 | u8 is_open; | ||
771 | |||
772 | enum nl80211_iftype iw_mode; | ||
773 | |||
774 | /* Last Rx'd beacon timestamp */ | ||
775 | u64 timestamp; | ||
776 | |||
777 | struct { | ||
778 | __le32 flag; | ||
779 | struct statistics_general_common common; | ||
780 | struct statistics_rx_non_phy rx_non_phy; | ||
781 | struct statistics_rx_phy rx_ofdm; | ||
782 | struct statistics_rx_ht_phy rx_ofdm_ht; | ||
783 | struct statistics_rx_phy rx_cck; | ||
784 | struct statistics_tx tx; | ||
785 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
786 | struct statistics_bt_activity bt_activity; | ||
787 | __le32 num_bt_kills, accum_num_bt_kills; | ||
788 | #endif | ||
789 | spinlock_t lock; | ||
790 | } statistics; | ||
791 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
792 | struct { | ||
793 | struct statistics_general_common common; | ||
794 | struct statistics_rx_non_phy rx_non_phy; | ||
795 | struct statistics_rx_phy rx_ofdm; | ||
796 | struct statistics_rx_ht_phy rx_ofdm_ht; | ||
797 | struct statistics_rx_phy rx_cck; | ||
798 | struct statistics_tx tx; | ||
799 | struct statistics_bt_activity bt_activity; | ||
800 | } accum_stats, delta_stats, max_delta_stats; | ||
801 | #endif | ||
802 | |||
803 | /* | ||
804 | * reporting the number of tids has AGG on. 0 means | ||
805 | * no AGGREGATION | ||
806 | */ | ||
807 | u8 agg_tids_count; | ||
808 | |||
809 | struct iwl_rx_phy_res last_phy_res; | ||
810 | bool last_phy_res_valid; | ||
811 | |||
812 | /* | ||
813 | * chain noise reset and gain commands are the | ||
814 | * two extra calibration commands follows the standard | ||
815 | * phy calibration commands | ||
816 | */ | ||
817 | u8 phy_calib_chain_noise_reset_cmd; | ||
818 | u8 phy_calib_chain_noise_gain_cmd; | ||
819 | |||
820 | /* counts reply_tx error */ | ||
821 | struct reply_tx_error_statistics reply_tx_stats; | ||
822 | struct reply_agg_tx_error_statistics reply_agg_tx_stats; | ||
823 | |||
824 | /* remain-on-channel offload support */ | ||
825 | struct ieee80211_channel *hw_roc_channel; | ||
826 | struct delayed_work hw_roc_disable_work; | ||
827 | enum nl80211_channel_type hw_roc_chantype; | ||
828 | int hw_roc_duration; | ||
829 | bool hw_roc_setup, hw_roc_start_notified; | ||
830 | |||
831 | /* bt coex */ | ||
832 | u8 bt_enable_flag; | ||
833 | u8 bt_status; | ||
834 | u8 bt_traffic_load, last_bt_traffic_load; | ||
835 | bool bt_ch_announce; | ||
836 | bool bt_full_concurrent; | ||
837 | bool bt_ant_couple_ok; | ||
838 | __le32 kill_ack_mask; | ||
839 | __le32 kill_cts_mask; | ||
840 | __le16 bt_valid; | ||
841 | bool reduced_txpower; | ||
842 | u16 bt_on_thresh; | ||
843 | u16 bt_duration; | ||
844 | u16 dynamic_frag_thresh; | ||
845 | u8 bt_ci_compliance; | ||
846 | struct work_struct bt_traffic_change_work; | ||
847 | bool bt_enable_pspoll; | ||
848 | struct iwl_rxon_context *cur_rssi_ctx; | ||
849 | bool bt_is_sco; | ||
850 | |||
851 | struct work_struct restart; | ||
852 | struct work_struct scan_completed; | ||
853 | struct work_struct abort_scan; | ||
854 | |||
855 | struct work_struct beacon_update; | ||
856 | struct iwl_rxon_context *beacon_ctx; | ||
857 | struct sk_buff *beacon_skb; | ||
858 | void *beacon_cmd; | ||
859 | |||
860 | struct work_struct tt_work; | ||
861 | struct work_struct ct_enter; | ||
862 | struct work_struct ct_exit; | ||
863 | struct work_struct start_internal_scan; | ||
864 | struct work_struct tx_flush; | ||
865 | struct work_struct bt_full_concurrency; | ||
866 | struct work_struct bt_runtime_config; | ||
867 | |||
868 | struct delayed_work scan_check; | ||
869 | |||
870 | /* TX Power settings */ | ||
871 | s8 tx_power_user_lmt; | ||
872 | s8 tx_power_next; | ||
873 | |||
874 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
875 | /* debugfs */ | ||
876 | struct dentry *debugfs_dir; | ||
877 | u32 dbgfs_sram_offset, dbgfs_sram_len; | ||
878 | bool disable_ht40; | ||
879 | void *wowlan_sram; | ||
880 | #endif /* CONFIG_IWLWIFI_DEBUGFS */ | ||
881 | |||
882 | struct iwl_eeprom_data *eeprom_data; | ||
883 | /* eeprom blob for debugfs/testmode */ | ||
884 | u8 *eeprom_blob; | ||
885 | size_t eeprom_blob_size; | ||
886 | |||
887 | struct work_struct txpower_work; | ||
888 | u32 calib_disabled; | ||
889 | struct work_struct run_time_calib_work; | ||
890 | struct timer_list statistics_periodic; | ||
891 | struct timer_list ucode_trace; | ||
892 | |||
893 | struct iwl_event_log event_log; | ||
894 | |||
895 | struct led_classdev led; | ||
896 | unsigned long blink_on, blink_off; | ||
897 | bool led_registered; | ||
898 | #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE | ||
899 | struct iwl_testmode_trace testmode_trace; | ||
900 | struct iwl_testmode_mem testmode_mem; | ||
901 | u32 tm_fixed_rate; | ||
902 | #endif | ||
903 | |||
904 | /* WoWLAN GTK rekey data */ | ||
905 | u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN]; | ||
906 | __le64 replay_ctr; | ||
907 | __le16 last_seq_ctl; | ||
908 | bool have_rekey_data; | ||
909 | |||
910 | /* device_pointers: pointers to ucode event tables */ | ||
911 | struct { | ||
912 | u32 error_event_table; | ||
913 | u32 log_event_table; | ||
914 | } device_pointers; | ||
915 | |||
916 | /* indicator of loaded ucode image */ | ||
917 | enum iwl_ucode_type cur_ucode; | ||
918 | }; /*iwl_priv */ | ||
919 | |||
920 | static inline struct iwl_rxon_context * | ||
921 | iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif) | ||
922 | { | ||
923 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
924 | |||
925 | return vif_priv->ctx; | ||
926 | } | ||
927 | |||
928 | #define for_each_context(priv, ctx) \ | ||
929 | for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \ | ||
930 | ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \ | ||
931 | if (priv->valid_contexts & BIT(ctx->ctxid)) | ||
932 | |||
933 | static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx) | ||
934 | { | ||
935 | return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0; | ||
936 | } | ||
937 | |||
938 | static inline int iwl_is_associated(struct iwl_priv *priv, | ||
939 | enum iwl_rxon_context_id ctxid) | ||
940 | { | ||
941 | return iwl_is_associated_ctx(&priv->contexts[ctxid]); | ||
942 | } | ||
943 | |||
944 | static inline int iwl_is_any_associated(struct iwl_priv *priv) | ||
945 | { | ||
946 | struct iwl_rxon_context *ctx; | ||
947 | for_each_context(priv, ctx) | ||
948 | if (iwl_is_associated_ctx(ctx)) | ||
949 | return true; | ||
950 | return false; | ||
951 | } | ||
952 | |||
953 | #endif /* __iwl_dev_h__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/devices.c b/drivers/net/wireless/iwlwifi/dvm/devices.c new file mode 100644 index 000000000000..0521a6be09d2 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/devices.c | |||
@@ -0,0 +1,601 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of version 2 of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | |||
27 | /* | ||
28 | * DVM device-specific data & functions | ||
29 | */ | ||
30 | #include "iwl-io.h" | ||
31 | #include "iwl-prph.h" | ||
32 | #include "iwl-eeprom-parse.h" | ||
33 | |||
34 | #include "agn.h" | ||
35 | #include "dev.h" | ||
36 | #include "commands.h" | ||
37 | |||
38 | |||
39 | /* | ||
40 | * 1000 series | ||
41 | * =========== | ||
42 | */ | ||
43 | |||
44 | /* | ||
45 | * For 1000, use advance thermal throttling critical temperature threshold, | ||
46 | * but legacy thermal management implementation for now. | ||
47 | * This is for the reason of 1000 uCode using advance thermal throttling API | ||
48 | * but not implement ct_kill_exit based on ct_kill exit temperature | ||
49 | * so the thermal throttling will still based on legacy thermal throttling | ||
50 | * management. | ||
51 | * The code here need to be modified once 1000 uCode has the advanced thermal | ||
52 | * throttling algorithm in place | ||
53 | */ | ||
54 | static void iwl1000_set_ct_threshold(struct iwl_priv *priv) | ||
55 | { | ||
56 | /* want Celsius */ | ||
57 | priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY; | ||
58 | priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD; | ||
59 | } | ||
60 | |||
61 | /* NIC configuration for 1000 series */ | ||
62 | static void iwl1000_nic_config(struct iwl_priv *priv) | ||
63 | { | ||
64 | /* Setting digital SVR for 1000 card to 1.32V */ | ||
65 | /* locking is acquired in iwl_set_bits_mask_prph() function */ | ||
66 | iwl_set_bits_mask_prph(priv->trans, APMG_DIGITAL_SVR_REG, | ||
67 | APMG_SVR_DIGITAL_VOLTAGE_1_32, | ||
68 | ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK); | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time | ||
73 | * @priv -- pointer to iwl_priv data structure | ||
74 | * @tsf_bits -- number of bits need to shift for masking) | ||
75 | */ | ||
76 | static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv, | ||
77 | u16 tsf_bits) | ||
78 | { | ||
79 | return (1 << tsf_bits) - 1; | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time | ||
84 | * @priv -- pointer to iwl_priv data structure | ||
85 | * @tsf_bits -- number of bits need to shift for masking) | ||
86 | */ | ||
87 | static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv, | ||
88 | u16 tsf_bits) | ||
89 | { | ||
90 | return ((1 << (32 - tsf_bits)) - 1) << tsf_bits; | ||
91 | } | ||
92 | |||
93 | /* | ||
94 | * extended beacon time format | ||
95 | * time in usec will be changed into a 32-bit value in extended:internal format | ||
96 | * the extended part is the beacon counts | ||
97 | * the internal part is the time in usec within one beacon interval | ||
98 | */ | ||
99 | static u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, | ||
100 | u32 beacon_interval) | ||
101 | { | ||
102 | u32 quot; | ||
103 | u32 rem; | ||
104 | u32 interval = beacon_interval * TIME_UNIT; | ||
105 | |||
106 | if (!interval || !usec) | ||
107 | return 0; | ||
108 | |||
109 | quot = (usec / interval) & | ||
110 | (iwl_beacon_time_mask_high(priv, IWLAGN_EXT_BEACON_TIME_POS) >> | ||
111 | IWLAGN_EXT_BEACON_TIME_POS); | ||
112 | rem = (usec % interval) & iwl_beacon_time_mask_low(priv, | ||
113 | IWLAGN_EXT_BEACON_TIME_POS); | ||
114 | |||
115 | return (quot << IWLAGN_EXT_BEACON_TIME_POS) + rem; | ||
116 | } | ||
117 | |||
118 | /* base is usually what we get from ucode with each received frame, | ||
119 | * the same as HW timer counter counting down | ||
120 | */ | ||
121 | static __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base, | ||
122 | u32 addon, u32 beacon_interval) | ||
123 | { | ||
124 | u32 base_low = base & iwl_beacon_time_mask_low(priv, | ||
125 | IWLAGN_EXT_BEACON_TIME_POS); | ||
126 | u32 addon_low = addon & iwl_beacon_time_mask_low(priv, | ||
127 | IWLAGN_EXT_BEACON_TIME_POS); | ||
128 | u32 interval = beacon_interval * TIME_UNIT; | ||
129 | u32 res = (base & iwl_beacon_time_mask_high(priv, | ||
130 | IWLAGN_EXT_BEACON_TIME_POS)) + | ||
131 | (addon & iwl_beacon_time_mask_high(priv, | ||
132 | IWLAGN_EXT_BEACON_TIME_POS)); | ||
133 | |||
134 | if (base_low > addon_low) | ||
135 | res += base_low - addon_low; | ||
136 | else if (base_low < addon_low) { | ||
137 | res += interval + base_low - addon_low; | ||
138 | res += (1 << IWLAGN_EXT_BEACON_TIME_POS); | ||
139 | } else | ||
140 | res += (1 << IWLAGN_EXT_BEACON_TIME_POS); | ||
141 | |||
142 | return cpu_to_le32(res); | ||
143 | } | ||
144 | |||
145 | static const struct iwl_sensitivity_ranges iwl1000_sensitivity = { | ||
146 | .min_nrg_cck = 95, | ||
147 | .auto_corr_min_ofdm = 90, | ||
148 | .auto_corr_min_ofdm_mrc = 170, | ||
149 | .auto_corr_min_ofdm_x1 = 120, | ||
150 | .auto_corr_min_ofdm_mrc_x1 = 240, | ||
151 | |||
152 | .auto_corr_max_ofdm = 120, | ||
153 | .auto_corr_max_ofdm_mrc = 210, | ||
154 | .auto_corr_max_ofdm_x1 = 155, | ||
155 | .auto_corr_max_ofdm_mrc_x1 = 290, | ||
156 | |||
157 | .auto_corr_min_cck = 125, | ||
158 | .auto_corr_max_cck = 200, | ||
159 | .auto_corr_min_cck_mrc = 170, | ||
160 | .auto_corr_max_cck_mrc = 400, | ||
161 | .nrg_th_cck = 95, | ||
162 | .nrg_th_ofdm = 95, | ||
163 | |||
164 | .barker_corr_th_min = 190, | ||
165 | .barker_corr_th_min_mrc = 390, | ||
166 | .nrg_th_cca = 62, | ||
167 | }; | ||
168 | |||
169 | static void iwl1000_hw_set_hw_params(struct iwl_priv *priv) | ||
170 | { | ||
171 | iwl1000_set_ct_threshold(priv); | ||
172 | |||
173 | /* Set initial sensitivity parameters */ | ||
174 | priv->hw_params.sens = &iwl1000_sensitivity; | ||
175 | } | ||
176 | |||
177 | struct iwl_lib_ops iwl1000_lib = { | ||
178 | .set_hw_params = iwl1000_hw_set_hw_params, | ||
179 | .nic_config = iwl1000_nic_config, | ||
180 | .temperature = iwlagn_temperature, | ||
181 | }; | ||
182 | |||
183 | |||
184 | /* | ||
185 | * 2000 series | ||
186 | * =========== | ||
187 | */ | ||
188 | |||
189 | static void iwl2000_set_ct_threshold(struct iwl_priv *priv) | ||
190 | { | ||
191 | /* want Celsius */ | ||
192 | priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD; | ||
193 | priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD; | ||
194 | } | ||
195 | |||
196 | /* NIC configuration for 2000 series */ | ||
197 | static void iwl2000_nic_config(struct iwl_priv *priv) | ||
198 | { | ||
199 | iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, | ||
200 | CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER); | ||
201 | } | ||
202 | |||
203 | static const struct iwl_sensitivity_ranges iwl2000_sensitivity = { | ||
204 | .min_nrg_cck = 97, | ||
205 | .auto_corr_min_ofdm = 80, | ||
206 | .auto_corr_min_ofdm_mrc = 128, | ||
207 | .auto_corr_min_ofdm_x1 = 105, | ||
208 | .auto_corr_min_ofdm_mrc_x1 = 192, | ||
209 | |||
210 | .auto_corr_max_ofdm = 145, | ||
211 | .auto_corr_max_ofdm_mrc = 232, | ||
212 | .auto_corr_max_ofdm_x1 = 110, | ||
213 | .auto_corr_max_ofdm_mrc_x1 = 232, | ||
214 | |||
215 | .auto_corr_min_cck = 125, | ||
216 | .auto_corr_max_cck = 175, | ||
217 | .auto_corr_min_cck_mrc = 160, | ||
218 | .auto_corr_max_cck_mrc = 310, | ||
219 | .nrg_th_cck = 97, | ||
220 | .nrg_th_ofdm = 100, | ||
221 | |||
222 | .barker_corr_th_min = 190, | ||
223 | .barker_corr_th_min_mrc = 390, | ||
224 | .nrg_th_cca = 62, | ||
225 | }; | ||
226 | |||
227 | static void iwl2000_hw_set_hw_params(struct iwl_priv *priv) | ||
228 | { | ||
229 | iwl2000_set_ct_threshold(priv); | ||
230 | |||
231 | /* Set initial sensitivity parameters */ | ||
232 | priv->hw_params.sens = &iwl2000_sensitivity; | ||
233 | } | ||
234 | |||
235 | struct iwl_lib_ops iwl2000_lib = { | ||
236 | .set_hw_params = iwl2000_hw_set_hw_params, | ||
237 | .nic_config = iwl2000_nic_config, | ||
238 | .temperature = iwlagn_temperature, | ||
239 | }; | ||
240 | |||
241 | struct iwl_lib_ops iwl2030_lib = { | ||
242 | .set_hw_params = iwl2000_hw_set_hw_params, | ||
243 | .nic_config = iwl2000_nic_config, | ||
244 | .temperature = iwlagn_temperature, | ||
245 | }; | ||
246 | |||
247 | /* | ||
248 | * 5000 series | ||
249 | * =========== | ||
250 | */ | ||
251 | |||
252 | /* NIC configuration for 5000 series */ | ||
253 | static void iwl5000_nic_config(struct iwl_priv *priv) | ||
254 | { | ||
255 | /* W/A : NIC is stuck in a reset state after Early PCIe power off | ||
256 | * (PCIe power is lost before PERST# is asserted), | ||
257 | * causing ME FW to lose ownership and not being able to obtain it back. | ||
258 | */ | ||
259 | iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG, | ||
260 | APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, | ||
261 | ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); | ||
262 | } | ||
263 | |||
264 | static const struct iwl_sensitivity_ranges iwl5000_sensitivity = { | ||
265 | .min_nrg_cck = 100, | ||
266 | .auto_corr_min_ofdm = 90, | ||
267 | .auto_corr_min_ofdm_mrc = 170, | ||
268 | .auto_corr_min_ofdm_x1 = 105, | ||
269 | .auto_corr_min_ofdm_mrc_x1 = 220, | ||
270 | |||
271 | .auto_corr_max_ofdm = 120, | ||
272 | .auto_corr_max_ofdm_mrc = 210, | ||
273 | .auto_corr_max_ofdm_x1 = 120, | ||
274 | .auto_corr_max_ofdm_mrc_x1 = 240, | ||
275 | |||
276 | .auto_corr_min_cck = 125, | ||
277 | .auto_corr_max_cck = 200, | ||
278 | .auto_corr_min_cck_mrc = 200, | ||
279 | .auto_corr_max_cck_mrc = 400, | ||
280 | .nrg_th_cck = 100, | ||
281 | .nrg_th_ofdm = 100, | ||
282 | |||
283 | .barker_corr_th_min = 190, | ||
284 | .barker_corr_th_min_mrc = 390, | ||
285 | .nrg_th_cca = 62, | ||
286 | }; | ||
287 | |||
288 | static struct iwl_sensitivity_ranges iwl5150_sensitivity = { | ||
289 | .min_nrg_cck = 95, | ||
290 | .auto_corr_min_ofdm = 90, | ||
291 | .auto_corr_min_ofdm_mrc = 170, | ||
292 | .auto_corr_min_ofdm_x1 = 105, | ||
293 | .auto_corr_min_ofdm_mrc_x1 = 220, | ||
294 | |||
295 | .auto_corr_max_ofdm = 120, | ||
296 | .auto_corr_max_ofdm_mrc = 210, | ||
297 | /* max = min for performance bug in 5150 DSP */ | ||
298 | .auto_corr_max_ofdm_x1 = 105, | ||
299 | .auto_corr_max_ofdm_mrc_x1 = 220, | ||
300 | |||
301 | .auto_corr_min_cck = 125, | ||
302 | .auto_corr_max_cck = 200, | ||
303 | .auto_corr_min_cck_mrc = 170, | ||
304 | .auto_corr_max_cck_mrc = 400, | ||
305 | .nrg_th_cck = 95, | ||
306 | .nrg_th_ofdm = 95, | ||
307 | |||
308 | .barker_corr_th_min = 190, | ||
309 | .barker_corr_th_min_mrc = 390, | ||
310 | .nrg_th_cca = 62, | ||
311 | }; | ||
312 | |||
313 | #define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF (-5) | ||
314 | |||
315 | static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv) | ||
316 | { | ||
317 | u16 temperature, voltage; | ||
318 | |||
319 | temperature = le16_to_cpu(priv->eeprom_data->kelvin_temperature); | ||
320 | voltage = le16_to_cpu(priv->eeprom_data->kelvin_voltage); | ||
321 | |||
322 | /* offset = temp - volt / coeff */ | ||
323 | return (s32)(temperature - | ||
324 | voltage / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF); | ||
325 | } | ||
326 | |||
327 | static void iwl5150_set_ct_threshold(struct iwl_priv *priv) | ||
328 | { | ||
329 | const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF; | ||
330 | s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) - | ||
331 | iwl_temp_calib_to_offset(priv); | ||
332 | |||
333 | priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef; | ||
334 | } | ||
335 | |||
336 | static void iwl5000_set_ct_threshold(struct iwl_priv *priv) | ||
337 | { | ||
338 | /* want Celsius */ | ||
339 | priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY; | ||
340 | } | ||
341 | |||
342 | static void iwl5000_hw_set_hw_params(struct iwl_priv *priv) | ||
343 | { | ||
344 | iwl5000_set_ct_threshold(priv); | ||
345 | |||
346 | /* Set initial sensitivity parameters */ | ||
347 | priv->hw_params.sens = &iwl5000_sensitivity; | ||
348 | } | ||
349 | |||
350 | static void iwl5150_hw_set_hw_params(struct iwl_priv *priv) | ||
351 | { | ||
352 | iwl5150_set_ct_threshold(priv); | ||
353 | |||
354 | /* Set initial sensitivity parameters */ | ||
355 | priv->hw_params.sens = &iwl5150_sensitivity; | ||
356 | } | ||
357 | |||
358 | static void iwl5150_temperature(struct iwl_priv *priv) | ||
359 | { | ||
360 | u32 vt = 0; | ||
361 | s32 offset = iwl_temp_calib_to_offset(priv); | ||
362 | |||
363 | vt = le32_to_cpu(priv->statistics.common.temperature); | ||
364 | vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset; | ||
365 | /* now vt hold the temperature in Kelvin */ | ||
366 | priv->temperature = KELVIN_TO_CELSIUS(vt); | ||
367 | iwl_tt_handler(priv); | ||
368 | } | ||
369 | |||
370 | static int iwl5000_hw_channel_switch(struct iwl_priv *priv, | ||
371 | struct ieee80211_channel_switch *ch_switch) | ||
372 | { | ||
373 | /* | ||
374 | * MULTI-FIXME | ||
375 | * See iwlagn_mac_channel_switch. | ||
376 | */ | ||
377 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
378 | struct iwl5000_channel_switch_cmd cmd; | ||
379 | u32 switch_time_in_usec, ucode_switch_time; | ||
380 | u16 ch; | ||
381 | u32 tsf_low; | ||
382 | u8 switch_count; | ||
383 | u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval); | ||
384 | struct ieee80211_vif *vif = ctx->vif; | ||
385 | struct iwl_host_cmd hcmd = { | ||
386 | .id = REPLY_CHANNEL_SWITCH, | ||
387 | .len = { sizeof(cmd), }, | ||
388 | .flags = CMD_SYNC, | ||
389 | .data = { &cmd, }, | ||
390 | }; | ||
391 | |||
392 | cmd.band = priv->band == IEEE80211_BAND_2GHZ; | ||
393 | ch = ch_switch->channel->hw_value; | ||
394 | IWL_DEBUG_11H(priv, "channel switch from %d to %d\n", | ||
395 | ctx->active.channel, ch); | ||
396 | cmd.channel = cpu_to_le16(ch); | ||
397 | cmd.rxon_flags = ctx->staging.flags; | ||
398 | cmd.rxon_filter_flags = ctx->staging.filter_flags; | ||
399 | switch_count = ch_switch->count; | ||
400 | tsf_low = ch_switch->timestamp & 0x0ffffffff; | ||
401 | /* | ||
402 | * calculate the ucode channel switch time | ||
403 | * adding TSF as one of the factor for when to switch | ||
404 | */ | ||
405 | if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) { | ||
406 | if (switch_count > ((priv->ucode_beacon_time - tsf_low) / | ||
407 | beacon_interval)) { | ||
408 | switch_count -= (priv->ucode_beacon_time - | ||
409 | tsf_low) / beacon_interval; | ||
410 | } else | ||
411 | switch_count = 0; | ||
412 | } | ||
413 | if (switch_count <= 1) | ||
414 | cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time); | ||
415 | else { | ||
416 | switch_time_in_usec = | ||
417 | vif->bss_conf.beacon_int * switch_count * TIME_UNIT; | ||
418 | ucode_switch_time = iwl_usecs_to_beacons(priv, | ||
419 | switch_time_in_usec, | ||
420 | beacon_interval); | ||
421 | cmd.switch_time = iwl_add_beacon_time(priv, | ||
422 | priv->ucode_beacon_time, | ||
423 | ucode_switch_time, | ||
424 | beacon_interval); | ||
425 | } | ||
426 | IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n", | ||
427 | cmd.switch_time); | ||
428 | cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR; | ||
429 | |||
430 | return iwl_dvm_send_cmd(priv, &hcmd); | ||
431 | } | ||
432 | |||
433 | struct iwl_lib_ops iwl5000_lib = { | ||
434 | .set_hw_params = iwl5000_hw_set_hw_params, | ||
435 | .set_channel_switch = iwl5000_hw_channel_switch, | ||
436 | .nic_config = iwl5000_nic_config, | ||
437 | .temperature = iwlagn_temperature, | ||
438 | }; | ||
439 | |||
440 | struct iwl_lib_ops iwl5150_lib = { | ||
441 | .set_hw_params = iwl5150_hw_set_hw_params, | ||
442 | .set_channel_switch = iwl5000_hw_channel_switch, | ||
443 | .nic_config = iwl5000_nic_config, | ||
444 | .temperature = iwl5150_temperature, | ||
445 | }; | ||
446 | |||
447 | |||
448 | |||
449 | /* | ||
450 | * 6000 series | ||
451 | * =========== | ||
452 | */ | ||
453 | |||
454 | static void iwl6000_set_ct_threshold(struct iwl_priv *priv) | ||
455 | { | ||
456 | /* want Celsius */ | ||
457 | priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD; | ||
458 | priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD; | ||
459 | } | ||
460 | |||
461 | /* NIC configuration for 6000 series */ | ||
462 | static void iwl6000_nic_config(struct iwl_priv *priv) | ||
463 | { | ||
464 | switch (priv->cfg->device_family) { | ||
465 | case IWL_DEVICE_FAMILY_6005: | ||
466 | case IWL_DEVICE_FAMILY_6030: | ||
467 | case IWL_DEVICE_FAMILY_6000: | ||
468 | break; | ||
469 | case IWL_DEVICE_FAMILY_6000i: | ||
470 | /* 2x2 IPA phy type */ | ||
471 | iwl_write32(priv->trans, CSR_GP_DRIVER_REG, | ||
472 | CSR_GP_DRIVER_REG_BIT_RADIO_SKU_2x2_IPA); | ||
473 | break; | ||
474 | case IWL_DEVICE_FAMILY_6050: | ||
475 | /* Indicate calibration version to uCode. */ | ||
476 | if (priv->eeprom_data->calib_version >= 6) | ||
477 | iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, | ||
478 | CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); | ||
479 | break; | ||
480 | case IWL_DEVICE_FAMILY_6150: | ||
481 | /* Indicate calibration version to uCode. */ | ||
482 | if (priv->eeprom_data->calib_version >= 6) | ||
483 | iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, | ||
484 | CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); | ||
485 | iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, | ||
486 | CSR_GP_DRIVER_REG_BIT_6050_1x2); | ||
487 | break; | ||
488 | default: | ||
489 | WARN_ON(1); | ||
490 | } | ||
491 | } | ||
492 | |||
493 | static const struct iwl_sensitivity_ranges iwl6000_sensitivity = { | ||
494 | .min_nrg_cck = 110, | ||
495 | .auto_corr_min_ofdm = 80, | ||
496 | .auto_corr_min_ofdm_mrc = 128, | ||
497 | .auto_corr_min_ofdm_x1 = 105, | ||
498 | .auto_corr_min_ofdm_mrc_x1 = 192, | ||
499 | |||
500 | .auto_corr_max_ofdm = 145, | ||
501 | .auto_corr_max_ofdm_mrc = 232, | ||
502 | .auto_corr_max_ofdm_x1 = 110, | ||
503 | .auto_corr_max_ofdm_mrc_x1 = 232, | ||
504 | |||
505 | .auto_corr_min_cck = 125, | ||
506 | .auto_corr_max_cck = 175, | ||
507 | .auto_corr_min_cck_mrc = 160, | ||
508 | .auto_corr_max_cck_mrc = 310, | ||
509 | .nrg_th_cck = 110, | ||
510 | .nrg_th_ofdm = 110, | ||
511 | |||
512 | .barker_corr_th_min = 190, | ||
513 | .barker_corr_th_min_mrc = 336, | ||
514 | .nrg_th_cca = 62, | ||
515 | }; | ||
516 | |||
517 | static void iwl6000_hw_set_hw_params(struct iwl_priv *priv) | ||
518 | { | ||
519 | iwl6000_set_ct_threshold(priv); | ||
520 | |||
521 | /* Set initial sensitivity parameters */ | ||
522 | priv->hw_params.sens = &iwl6000_sensitivity; | ||
523 | |||
524 | } | ||
525 | |||
526 | static int iwl6000_hw_channel_switch(struct iwl_priv *priv, | ||
527 | struct ieee80211_channel_switch *ch_switch) | ||
528 | { | ||
529 | /* | ||
530 | * MULTI-FIXME | ||
531 | * See iwlagn_mac_channel_switch. | ||
532 | */ | ||
533 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
534 | struct iwl6000_channel_switch_cmd cmd; | ||
535 | u32 switch_time_in_usec, ucode_switch_time; | ||
536 | u16 ch; | ||
537 | u32 tsf_low; | ||
538 | u8 switch_count; | ||
539 | u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval); | ||
540 | struct ieee80211_vif *vif = ctx->vif; | ||
541 | struct iwl_host_cmd hcmd = { | ||
542 | .id = REPLY_CHANNEL_SWITCH, | ||
543 | .len = { sizeof(cmd), }, | ||
544 | .flags = CMD_SYNC, | ||
545 | .data = { &cmd, }, | ||
546 | }; | ||
547 | |||
548 | cmd.band = priv->band == IEEE80211_BAND_2GHZ; | ||
549 | ch = ch_switch->channel->hw_value; | ||
550 | IWL_DEBUG_11H(priv, "channel switch from %u to %u\n", | ||
551 | ctx->active.channel, ch); | ||
552 | cmd.channel = cpu_to_le16(ch); | ||
553 | cmd.rxon_flags = ctx->staging.flags; | ||
554 | cmd.rxon_filter_flags = ctx->staging.filter_flags; | ||
555 | switch_count = ch_switch->count; | ||
556 | tsf_low = ch_switch->timestamp & 0x0ffffffff; | ||
557 | /* | ||
558 | * calculate the ucode channel switch time | ||
559 | * adding TSF as one of the factor for when to switch | ||
560 | */ | ||
561 | if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) { | ||
562 | if (switch_count > ((priv->ucode_beacon_time - tsf_low) / | ||
563 | beacon_interval)) { | ||
564 | switch_count -= (priv->ucode_beacon_time - | ||
565 | tsf_low) / beacon_interval; | ||
566 | } else | ||
567 | switch_count = 0; | ||
568 | } | ||
569 | if (switch_count <= 1) | ||
570 | cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time); | ||
571 | else { | ||
572 | switch_time_in_usec = | ||
573 | vif->bss_conf.beacon_int * switch_count * TIME_UNIT; | ||
574 | ucode_switch_time = iwl_usecs_to_beacons(priv, | ||
575 | switch_time_in_usec, | ||
576 | beacon_interval); | ||
577 | cmd.switch_time = iwl_add_beacon_time(priv, | ||
578 | priv->ucode_beacon_time, | ||
579 | ucode_switch_time, | ||
580 | beacon_interval); | ||
581 | } | ||
582 | IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n", | ||
583 | cmd.switch_time); | ||
584 | cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR; | ||
585 | |||
586 | return iwl_dvm_send_cmd(priv, &hcmd); | ||
587 | } | ||
588 | |||
589 | struct iwl_lib_ops iwl6000_lib = { | ||
590 | .set_hw_params = iwl6000_hw_set_hw_params, | ||
591 | .set_channel_switch = iwl6000_hw_channel_switch, | ||
592 | .nic_config = iwl6000_nic_config, | ||
593 | .temperature = iwlagn_temperature, | ||
594 | }; | ||
595 | |||
596 | struct iwl_lib_ops iwl6030_lib = { | ||
597 | .set_hw_params = iwl6000_hw_set_hw_params, | ||
598 | .set_channel_switch = iwl6000_hw_channel_switch, | ||
599 | .nic_config = iwl6000_nic_config, | ||
600 | .temperature = iwlagn_temperature, | ||
601 | }; | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/led.c b/drivers/net/wireless/iwlwifi/dvm/led.c new file mode 100644 index 000000000000..bf479f709091 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/led.c | |||
@@ -0,0 +1,224 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of version 2 of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | |||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/delay.h> | ||
32 | #include <linux/skbuff.h> | ||
33 | #include <linux/netdevice.h> | ||
34 | #include <net/mac80211.h> | ||
35 | #include <linux/etherdevice.h> | ||
36 | #include <asm/unaligned.h> | ||
37 | #include "iwl-io.h" | ||
38 | #include "iwl-trans.h" | ||
39 | #include "iwl-modparams.h" | ||
40 | #include "dev.h" | ||
41 | #include "agn.h" | ||
42 | |||
43 | /* Throughput OFF time(ms) ON time (ms) | ||
44 | * >300 25 25 | ||
45 | * >200 to 300 40 40 | ||
46 | * >100 to 200 55 55 | ||
47 | * >70 to 100 65 65 | ||
48 | * >50 to 70 75 75 | ||
49 | * >20 to 50 85 85 | ||
50 | * >10 to 20 95 95 | ||
51 | * >5 to 10 110 110 | ||
52 | * >1 to 5 130 130 | ||
53 | * >0 to 1 167 167 | ||
54 | * <=0 SOLID ON | ||
55 | */ | ||
56 | static const struct ieee80211_tpt_blink iwl_blink[] = { | ||
57 | { .throughput = 0, .blink_time = 334 }, | ||
58 | { .throughput = 1 * 1024 - 1, .blink_time = 260 }, | ||
59 | { .throughput = 5 * 1024 - 1, .blink_time = 220 }, | ||
60 | { .throughput = 10 * 1024 - 1, .blink_time = 190 }, | ||
61 | { .throughput = 20 * 1024 - 1, .blink_time = 170 }, | ||
62 | { .throughput = 50 * 1024 - 1, .blink_time = 150 }, | ||
63 | { .throughput = 70 * 1024 - 1, .blink_time = 130 }, | ||
64 | { .throughput = 100 * 1024 - 1, .blink_time = 110 }, | ||
65 | { .throughput = 200 * 1024 - 1, .blink_time = 80 }, | ||
66 | { .throughput = 300 * 1024 - 1, .blink_time = 50 }, | ||
67 | }; | ||
68 | |||
69 | /* Set led register off */ | ||
70 | void iwlagn_led_enable(struct iwl_priv *priv) | ||
71 | { | ||
72 | iwl_write32(priv->trans, CSR_LED_REG, CSR_LED_REG_TRUN_ON); | ||
73 | } | ||
74 | |||
75 | /* | ||
76 | * Adjust led blink rate to compensate on a MAC Clock difference on every HW | ||
77 | * Led blink rate analysis showed an average deviation of 20% on 5000 series | ||
78 | * and up. | ||
79 | * Need to compensate on the led on/off time per HW according to the deviation | ||
80 | * to achieve the desired led frequency | ||
81 | * The calculation is: (100-averageDeviation)/100 * blinkTime | ||
82 | * For code efficiency the calculation will be: | ||
83 | * compensation = (100 - averageDeviation) * 64 / 100 | ||
84 | * NewBlinkTime = (compensation * BlinkTime) / 64 | ||
85 | */ | ||
86 | static inline u8 iwl_blink_compensation(struct iwl_priv *priv, | ||
87 | u8 time, u16 compensation) | ||
88 | { | ||
89 | if (!compensation) { | ||
90 | IWL_ERR(priv, "undefined blink compensation: " | ||
91 | "use pre-defined blinking time\n"); | ||
92 | return time; | ||
93 | } | ||
94 | |||
95 | return (u8)((time * compensation) >> 6); | ||
96 | } | ||
97 | |||
98 | static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd) | ||
99 | { | ||
100 | struct iwl_host_cmd cmd = { | ||
101 | .id = REPLY_LEDS_CMD, | ||
102 | .len = { sizeof(struct iwl_led_cmd), }, | ||
103 | .data = { led_cmd, }, | ||
104 | .flags = CMD_ASYNC, | ||
105 | }; | ||
106 | u32 reg; | ||
107 | |||
108 | reg = iwl_read32(priv->trans, CSR_LED_REG); | ||
109 | if (reg != (reg & CSR_LED_BSM_CTRL_MSK)) | ||
110 | iwl_write32(priv->trans, CSR_LED_REG, | ||
111 | reg & CSR_LED_BSM_CTRL_MSK); | ||
112 | |||
113 | return iwl_dvm_send_cmd(priv, &cmd); | ||
114 | } | ||
115 | |||
116 | /* Set led pattern command */ | ||
117 | static int iwl_led_cmd(struct iwl_priv *priv, | ||
118 | unsigned long on, | ||
119 | unsigned long off) | ||
120 | { | ||
121 | struct iwl_led_cmd led_cmd = { | ||
122 | .id = IWL_LED_LINK, | ||
123 | .interval = IWL_DEF_LED_INTRVL | ||
124 | }; | ||
125 | int ret; | ||
126 | |||
127 | if (!test_bit(STATUS_READY, &priv->status)) | ||
128 | return -EBUSY; | ||
129 | |||
130 | if (priv->blink_on == on && priv->blink_off == off) | ||
131 | return 0; | ||
132 | |||
133 | if (off == 0) { | ||
134 | /* led is SOLID_ON */ | ||
135 | on = IWL_LED_SOLID; | ||
136 | } | ||
137 | |||
138 | IWL_DEBUG_LED(priv, "Led blink time compensation=%u\n", | ||
139 | priv->cfg->base_params->led_compensation); | ||
140 | led_cmd.on = iwl_blink_compensation(priv, on, | ||
141 | priv->cfg->base_params->led_compensation); | ||
142 | led_cmd.off = iwl_blink_compensation(priv, off, | ||
143 | priv->cfg->base_params->led_compensation); | ||
144 | |||
145 | ret = iwl_send_led_cmd(priv, &led_cmd); | ||
146 | if (!ret) { | ||
147 | priv->blink_on = on; | ||
148 | priv->blink_off = off; | ||
149 | } | ||
150 | return ret; | ||
151 | } | ||
152 | |||
153 | static void iwl_led_brightness_set(struct led_classdev *led_cdev, | ||
154 | enum led_brightness brightness) | ||
155 | { | ||
156 | struct iwl_priv *priv = container_of(led_cdev, struct iwl_priv, led); | ||
157 | unsigned long on = 0; | ||
158 | |||
159 | if (brightness > 0) | ||
160 | on = IWL_LED_SOLID; | ||
161 | |||
162 | iwl_led_cmd(priv, on, 0); | ||
163 | } | ||
164 | |||
165 | static int iwl_led_blink_set(struct led_classdev *led_cdev, | ||
166 | unsigned long *delay_on, | ||
167 | unsigned long *delay_off) | ||
168 | { | ||
169 | struct iwl_priv *priv = container_of(led_cdev, struct iwl_priv, led); | ||
170 | |||
171 | return iwl_led_cmd(priv, *delay_on, *delay_off); | ||
172 | } | ||
173 | |||
174 | void iwl_leds_init(struct iwl_priv *priv) | ||
175 | { | ||
176 | int mode = iwlwifi_mod_params.led_mode; | ||
177 | int ret; | ||
178 | |||
179 | if (mode == IWL_LED_DISABLE) { | ||
180 | IWL_INFO(priv, "Led disabled\n"); | ||
181 | return; | ||
182 | } | ||
183 | if (mode == IWL_LED_DEFAULT) | ||
184 | mode = priv->cfg->led_mode; | ||
185 | |||
186 | priv->led.name = kasprintf(GFP_KERNEL, "%s-led", | ||
187 | wiphy_name(priv->hw->wiphy)); | ||
188 | priv->led.brightness_set = iwl_led_brightness_set; | ||
189 | priv->led.blink_set = iwl_led_blink_set; | ||
190 | priv->led.max_brightness = 1; | ||
191 | |||
192 | switch (mode) { | ||
193 | case IWL_LED_DEFAULT: | ||
194 | WARN_ON(1); | ||
195 | break; | ||
196 | case IWL_LED_BLINK: | ||
197 | priv->led.default_trigger = | ||
198 | ieee80211_create_tpt_led_trigger(priv->hw, | ||
199 | IEEE80211_TPT_LEDTRIG_FL_CONNECTED, | ||
200 | iwl_blink, ARRAY_SIZE(iwl_blink)); | ||
201 | break; | ||
202 | case IWL_LED_RF_STATE: | ||
203 | priv->led.default_trigger = | ||
204 | ieee80211_get_radio_led_name(priv->hw); | ||
205 | break; | ||
206 | } | ||
207 | |||
208 | ret = led_classdev_register(priv->trans->dev, &priv->led); | ||
209 | if (ret) { | ||
210 | kfree(priv->led.name); | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | priv->led_registered = true; | ||
215 | } | ||
216 | |||
217 | void iwl_leds_exit(struct iwl_priv *priv) | ||
218 | { | ||
219 | if (!priv->led_registered) | ||
220 | return; | ||
221 | |||
222 | led_classdev_unregister(&priv->led); | ||
223 | kfree(priv->led.name); | ||
224 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/led.h b/drivers/net/wireless/iwlwifi/dvm/led.h new file mode 100644 index 000000000000..b02a853103d3 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/led.h | |||
@@ -0,0 +1,43 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of version 2 of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | |||
27 | #ifndef __iwl_leds_h__ | ||
28 | #define __iwl_leds_h__ | ||
29 | |||
30 | |||
31 | struct iwl_priv; | ||
32 | |||
33 | #define IWL_LED_SOLID 11 | ||
34 | #define IWL_DEF_LED_INTRVL cpu_to_le32(1000) | ||
35 | |||
36 | #define IWL_LED_ACTIVITY (0<<1) | ||
37 | #define IWL_LED_LINK (1<<1) | ||
38 | |||
39 | void iwlagn_led_enable(struct iwl_priv *priv); | ||
40 | void iwl_leds_init(struct iwl_priv *priv); | ||
41 | void iwl_leds_exit(struct iwl_priv *priv); | ||
42 | |||
43 | #endif /* __iwl_leds_h__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/lib.c b/drivers/net/wireless/iwlwifi/dvm/lib.c new file mode 100644 index 000000000000..cb1ca7a25dd5 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/lib.c | |||
@@ -0,0 +1,1291 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * GPL LICENSE SUMMARY | ||
4 | * | ||
5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of version 2 of the GNU General Public License as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
19 | * USA | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called LICENSE.GPL. | ||
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 | *****************************************************************************/ | ||
29 | #include <linux/etherdevice.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/sched.h> | ||
34 | #include <net/mac80211.h> | ||
35 | |||
36 | #include "iwl-io.h" | ||
37 | #include "iwl-agn-hw.h" | ||
38 | #include "iwl-trans.h" | ||
39 | #include "iwl-modparams.h" | ||
40 | |||
41 | #include "dev.h" | ||
42 | #include "agn.h" | ||
43 | |||
44 | int iwlagn_hw_valid_rtc_data_addr(u32 addr) | ||
45 | { | ||
46 | return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) && | ||
47 | (addr < IWLAGN_RTC_DATA_UPPER_BOUND); | ||
48 | } | ||
49 | |||
50 | int iwlagn_send_tx_power(struct iwl_priv *priv) | ||
51 | { | ||
52 | struct iwlagn_tx_power_dbm_cmd tx_power_cmd; | ||
53 | u8 tx_ant_cfg_cmd; | ||
54 | |||
55 | if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->status), | ||
56 | "TX Power requested while scanning!\n")) | ||
57 | return -EAGAIN; | ||
58 | |||
59 | /* half dBm need to multiply */ | ||
60 | tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt); | ||
61 | |||
62 | if (tx_power_cmd.global_lmt > priv->eeprom_data->max_tx_pwr_half_dbm) { | ||
63 | /* | ||
64 | * For the newer devices which using enhanced/extend tx power | ||
65 | * table in EEPROM, the format is in half dBm. driver need to | ||
66 | * convert to dBm format before report to mac80211. | ||
67 | * By doing so, there is a possibility of 1/2 dBm resolution | ||
68 | * lost. driver will perform "round-up" operation before | ||
69 | * reporting, but it will cause 1/2 dBm tx power over the | ||
70 | * regulatory limit. Perform the checking here, if the | ||
71 | * "tx_power_user_lmt" is higher than EEPROM value (in | ||
72 | * half-dBm format), lower the tx power based on EEPROM | ||
73 | */ | ||
74 | tx_power_cmd.global_lmt = | ||
75 | priv->eeprom_data->max_tx_pwr_half_dbm; | ||
76 | } | ||
77 | tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED; | ||
78 | tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO; | ||
79 | |||
80 | if (IWL_UCODE_API(priv->fw->ucode_ver) == 1) | ||
81 | tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1; | ||
82 | else | ||
83 | tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD; | ||
84 | |||
85 | return iwl_dvm_send_cmd_pdu(priv, tx_ant_cfg_cmd, CMD_SYNC, | ||
86 | sizeof(tx_power_cmd), &tx_power_cmd); | ||
87 | } | ||
88 | |||
89 | void iwlagn_temperature(struct iwl_priv *priv) | ||
90 | { | ||
91 | lockdep_assert_held(&priv->statistics.lock); | ||
92 | |||
93 | /* store temperature from correct statistics (in Celsius) */ | ||
94 | priv->temperature = le32_to_cpu(priv->statistics.common.temperature); | ||
95 | iwl_tt_handler(priv); | ||
96 | } | ||
97 | |||
98 | int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band) | ||
99 | { | ||
100 | int idx = 0; | ||
101 | int band_offset = 0; | ||
102 | |||
103 | /* HT rate format: mac80211 wants an MCS number, which is just LSB */ | ||
104 | if (rate_n_flags & RATE_MCS_HT_MSK) { | ||
105 | idx = (rate_n_flags & 0xff); | ||
106 | return idx; | ||
107 | /* Legacy rate format, search for match in table */ | ||
108 | } else { | ||
109 | if (band == IEEE80211_BAND_5GHZ) | ||
110 | band_offset = IWL_FIRST_OFDM_RATE; | ||
111 | for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++) | ||
112 | if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF)) | ||
113 | return idx - band_offset; | ||
114 | } | ||
115 | |||
116 | return -1; | ||
117 | } | ||
118 | |||
119 | int iwlagn_manage_ibss_station(struct iwl_priv *priv, | ||
120 | struct ieee80211_vif *vif, bool add) | ||
121 | { | ||
122 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
123 | |||
124 | if (add) | ||
125 | return iwlagn_add_bssid_station(priv, vif_priv->ctx, | ||
126 | vif->bss_conf.bssid, | ||
127 | &vif_priv->ibss_bssid_sta_id); | ||
128 | return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id, | ||
129 | vif->bss_conf.bssid); | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode | ||
134 | * | ||
135 | * pre-requirements: | ||
136 | * 1. acquire mutex before calling | ||
137 | * 2. make sure rf is on and not in exit state | ||
138 | */ | ||
139 | int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control) | ||
140 | { | ||
141 | struct iwl_txfifo_flush_cmd flush_cmd; | ||
142 | struct iwl_host_cmd cmd = { | ||
143 | .id = REPLY_TXFIFO_FLUSH, | ||
144 | .len = { sizeof(struct iwl_txfifo_flush_cmd), }, | ||
145 | .flags = CMD_SYNC, | ||
146 | .data = { &flush_cmd, }, | ||
147 | }; | ||
148 | |||
149 | might_sleep(); | ||
150 | |||
151 | memset(&flush_cmd, 0, sizeof(flush_cmd)); | ||
152 | if (flush_control & BIT(IWL_RXON_CTX_BSS)) | ||
153 | flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK | | ||
154 | IWL_SCD_BE_MSK | IWL_SCD_BK_MSK | | ||
155 | IWL_SCD_MGMT_MSK; | ||
156 | if ((flush_control & BIT(IWL_RXON_CTX_PAN)) && | ||
157 | (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))) | ||
158 | flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK | | ||
159 | IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK | | ||
160 | IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK | | ||
161 | IWL_PAN_SCD_MULTICAST_MSK; | ||
162 | |||
163 | if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE) | ||
164 | flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK; | ||
165 | |||
166 | IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n", | ||
167 | flush_cmd.fifo_control); | ||
168 | flush_cmd.flush_control = cpu_to_le16(flush_control); | ||
169 | |||
170 | return iwl_dvm_send_cmd(priv, &cmd); | ||
171 | } | ||
172 | |||
173 | void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control) | ||
174 | { | ||
175 | mutex_lock(&priv->mutex); | ||
176 | ieee80211_stop_queues(priv->hw); | ||
177 | if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) { | ||
178 | IWL_ERR(priv, "flush request fail\n"); | ||
179 | goto done; | ||
180 | } | ||
181 | IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n"); | ||
182 | iwl_trans_wait_tx_queue_empty(priv->trans); | ||
183 | done: | ||
184 | ieee80211_wake_queues(priv->hw); | ||
185 | mutex_unlock(&priv->mutex); | ||
186 | } | ||
187 | |||
188 | /* | ||
189 | * BT coex | ||
190 | */ | ||
191 | /* Notmal TDM */ | ||
192 | static const __le32 iwlagn_def_3w_lookup[IWLAGN_BT_DECISION_LUT_SIZE] = { | ||
193 | cpu_to_le32(0xaaaaaaaa), | ||
194 | cpu_to_le32(0xaaaaaaaa), | ||
195 | cpu_to_le32(0xaeaaaaaa), | ||
196 | cpu_to_le32(0xaaaaaaaa), | ||
197 | cpu_to_le32(0xcc00ff28), | ||
198 | cpu_to_le32(0x0000aaaa), | ||
199 | cpu_to_le32(0xcc00aaaa), | ||
200 | cpu_to_le32(0x0000aaaa), | ||
201 | cpu_to_le32(0xc0004000), | ||
202 | cpu_to_le32(0x00004000), | ||
203 | cpu_to_le32(0xf0005000), | ||
204 | cpu_to_le32(0xf0005000), | ||
205 | }; | ||
206 | |||
207 | |||
208 | /* Loose Coex */ | ||
209 | static const __le32 iwlagn_loose_lookup[IWLAGN_BT_DECISION_LUT_SIZE] = { | ||
210 | cpu_to_le32(0xaaaaaaaa), | ||
211 | cpu_to_le32(0xaaaaaaaa), | ||
212 | cpu_to_le32(0xaeaaaaaa), | ||
213 | cpu_to_le32(0xaaaaaaaa), | ||
214 | cpu_to_le32(0xcc00ff28), | ||
215 | cpu_to_le32(0x0000aaaa), | ||
216 | cpu_to_le32(0xcc00aaaa), | ||
217 | cpu_to_le32(0x0000aaaa), | ||
218 | cpu_to_le32(0x00000000), | ||
219 | cpu_to_le32(0x00000000), | ||
220 | cpu_to_le32(0xf0005000), | ||
221 | cpu_to_le32(0xf0005000), | ||
222 | }; | ||
223 | |||
224 | /* Full concurrency */ | ||
225 | static const __le32 iwlagn_concurrent_lookup[IWLAGN_BT_DECISION_LUT_SIZE] = { | ||
226 | cpu_to_le32(0xaaaaaaaa), | ||
227 | cpu_to_le32(0xaaaaaaaa), | ||
228 | cpu_to_le32(0xaaaaaaaa), | ||
229 | cpu_to_le32(0xaaaaaaaa), | ||
230 | cpu_to_le32(0xaaaaaaaa), | ||
231 | cpu_to_le32(0xaaaaaaaa), | ||
232 | cpu_to_le32(0xaaaaaaaa), | ||
233 | cpu_to_le32(0xaaaaaaaa), | ||
234 | cpu_to_le32(0x00000000), | ||
235 | cpu_to_le32(0x00000000), | ||
236 | cpu_to_le32(0x00000000), | ||
237 | cpu_to_le32(0x00000000), | ||
238 | }; | ||
239 | |||
240 | void iwlagn_send_advance_bt_config(struct iwl_priv *priv) | ||
241 | { | ||
242 | struct iwl_basic_bt_cmd basic = { | ||
243 | .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT, | ||
244 | .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT, | ||
245 | .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT, | ||
246 | .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT, | ||
247 | }; | ||
248 | struct iwl_bt_cmd_v1 bt_cmd_v1; | ||
249 | struct iwl_bt_cmd_v2 bt_cmd_v2; | ||
250 | int ret; | ||
251 | |||
252 | BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) != | ||
253 | sizeof(basic.bt3_lookup_table)); | ||
254 | |||
255 | if (priv->cfg->bt_params) { | ||
256 | /* | ||
257 | * newer generation of devices (2000 series and newer) | ||
258 | * use the version 2 of the bt command | ||
259 | * we need to make sure sending the host command | ||
260 | * with correct data structure to avoid uCode assert | ||
261 | */ | ||
262 | if (priv->cfg->bt_params->bt_session_2) { | ||
263 | bt_cmd_v2.prio_boost = cpu_to_le32( | ||
264 | priv->cfg->bt_params->bt_prio_boost); | ||
265 | bt_cmd_v2.tx_prio_boost = 0; | ||
266 | bt_cmd_v2.rx_prio_boost = 0; | ||
267 | } else { | ||
268 | bt_cmd_v1.prio_boost = | ||
269 | priv->cfg->bt_params->bt_prio_boost; | ||
270 | bt_cmd_v1.tx_prio_boost = 0; | ||
271 | bt_cmd_v1.rx_prio_boost = 0; | ||
272 | } | ||
273 | } else { | ||
274 | IWL_ERR(priv, "failed to construct BT Coex Config\n"); | ||
275 | return; | ||
276 | } | ||
277 | |||
278 | /* | ||
279 | * Possible situations when BT needs to take over for receive, | ||
280 | * at the same time where STA needs to response to AP's frame(s), | ||
281 | * reduce the tx power of the required response frames, by that, | ||
282 | * allow the concurrent BT receive & WiFi transmit | ||
283 | * (BT - ANT A, WiFi -ANT B), without interference to one another | ||
284 | * | ||
285 | * Reduced tx power apply to control frames only (ACK/Back/CTS) | ||
286 | * when indicated by the BT config command | ||
287 | */ | ||
288 | basic.kill_ack_mask = priv->kill_ack_mask; | ||
289 | basic.kill_cts_mask = priv->kill_cts_mask; | ||
290 | if (priv->reduced_txpower) | ||
291 | basic.reduce_txpower = IWLAGN_BT_REDUCED_TX_PWR; | ||
292 | basic.valid = priv->bt_valid; | ||
293 | |||
294 | /* | ||
295 | * Configure BT coex mode to "no coexistence" when the | ||
296 | * user disabled BT coexistence, we have no interface | ||
297 | * (might be in monitor mode), or the interface is in | ||
298 | * IBSS mode (no proper uCode support for coex then). | ||
299 | */ | ||
300 | if (!iwlwifi_mod_params.bt_coex_active || | ||
301 | priv->iw_mode == NL80211_IFTYPE_ADHOC) { | ||
302 | basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED; | ||
303 | } else { | ||
304 | basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W << | ||
305 | IWLAGN_BT_FLAG_COEX_MODE_SHIFT; | ||
306 | |||
307 | if (!priv->bt_enable_pspoll) | ||
308 | basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE; | ||
309 | else | ||
310 | basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE; | ||
311 | |||
312 | if (priv->bt_ch_announce) | ||
313 | basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION; | ||
314 | IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags); | ||
315 | } | ||
316 | priv->bt_enable_flag = basic.flags; | ||
317 | if (priv->bt_full_concurrent) | ||
318 | memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup, | ||
319 | sizeof(iwlagn_concurrent_lookup)); | ||
320 | else | ||
321 | memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup, | ||
322 | sizeof(iwlagn_def_3w_lookup)); | ||
323 | |||
324 | IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n", | ||
325 | basic.flags ? "active" : "disabled", | ||
326 | priv->bt_full_concurrent ? | ||
327 | "full concurrency" : "3-wire"); | ||
328 | |||
329 | if (priv->cfg->bt_params->bt_session_2) { | ||
330 | memcpy(&bt_cmd_v2.basic, &basic, | ||
331 | sizeof(basic)); | ||
332 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG, | ||
333 | CMD_SYNC, sizeof(bt_cmd_v2), &bt_cmd_v2); | ||
334 | } else { | ||
335 | memcpy(&bt_cmd_v1.basic, &basic, | ||
336 | sizeof(basic)); | ||
337 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG, | ||
338 | CMD_SYNC, sizeof(bt_cmd_v1), &bt_cmd_v1); | ||
339 | } | ||
340 | if (ret) | ||
341 | IWL_ERR(priv, "failed to send BT Coex Config\n"); | ||
342 | |||
343 | } | ||
344 | |||
345 | void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena) | ||
346 | { | ||
347 | struct iwl_rxon_context *ctx, *found_ctx = NULL; | ||
348 | bool found_ap = false; | ||
349 | |||
350 | lockdep_assert_held(&priv->mutex); | ||
351 | |||
352 | /* Check whether AP or GO mode is active. */ | ||
353 | if (rssi_ena) { | ||
354 | for_each_context(priv, ctx) { | ||
355 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP && | ||
356 | iwl_is_associated_ctx(ctx)) { | ||
357 | found_ap = true; | ||
358 | break; | ||
359 | } | ||
360 | } | ||
361 | } | ||
362 | |||
363 | /* | ||
364 | * If disable was received or If GO/AP mode, disable RSSI | ||
365 | * measurements. | ||
366 | */ | ||
367 | if (!rssi_ena || found_ap) { | ||
368 | if (priv->cur_rssi_ctx) { | ||
369 | ctx = priv->cur_rssi_ctx; | ||
370 | ieee80211_disable_rssi_reports(ctx->vif); | ||
371 | priv->cur_rssi_ctx = NULL; | ||
372 | } | ||
373 | return; | ||
374 | } | ||
375 | |||
376 | /* | ||
377 | * If rssi measurements need to be enabled, consider all cases now. | ||
378 | * Figure out how many contexts are active. | ||
379 | */ | ||
380 | for_each_context(priv, ctx) { | ||
381 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION && | ||
382 | iwl_is_associated_ctx(ctx)) { | ||
383 | found_ctx = ctx; | ||
384 | break; | ||
385 | } | ||
386 | } | ||
387 | |||
388 | /* | ||
389 | * rssi monitor already enabled for the correct interface...nothing | ||
390 | * to do. | ||
391 | */ | ||
392 | if (found_ctx == priv->cur_rssi_ctx) | ||
393 | return; | ||
394 | |||
395 | /* | ||
396 | * Figure out if rssi monitor is currently enabled, and needs | ||
397 | * to be changed. If rssi monitor is already enabled, disable | ||
398 | * it first else just enable rssi measurements on the | ||
399 | * interface found above. | ||
400 | */ | ||
401 | if (priv->cur_rssi_ctx) { | ||
402 | ctx = priv->cur_rssi_ctx; | ||
403 | if (ctx->vif) | ||
404 | ieee80211_disable_rssi_reports(ctx->vif); | ||
405 | } | ||
406 | |||
407 | priv->cur_rssi_ctx = found_ctx; | ||
408 | |||
409 | if (!found_ctx) | ||
410 | return; | ||
411 | |||
412 | ieee80211_enable_rssi_reports(found_ctx->vif, | ||
413 | IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD, | ||
414 | IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD); | ||
415 | } | ||
416 | |||
417 | static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg) | ||
418 | { | ||
419 | return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >> | ||
420 | BT_UART_MSG_FRAME3SCOESCO_POS; | ||
421 | } | ||
422 | |||
423 | static void iwlagn_bt_traffic_change_work(struct work_struct *work) | ||
424 | { | ||
425 | struct iwl_priv *priv = | ||
426 | container_of(work, struct iwl_priv, bt_traffic_change_work); | ||
427 | struct iwl_rxon_context *ctx; | ||
428 | int smps_request = -1; | ||
429 | |||
430 | if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) { | ||
431 | /* bt coex disabled */ | ||
432 | return; | ||
433 | } | ||
434 | |||
435 | /* | ||
436 | * Note: bt_traffic_load can be overridden by scan complete and | ||
437 | * coex profile notifications. Ignore that since only bad consequence | ||
438 | * can be not matching debug print with actual state. | ||
439 | */ | ||
440 | IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n", | ||
441 | priv->bt_traffic_load); | ||
442 | |||
443 | switch (priv->bt_traffic_load) { | ||
444 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | ||
445 | if (priv->bt_status) | ||
446 | smps_request = IEEE80211_SMPS_DYNAMIC; | ||
447 | else | ||
448 | smps_request = IEEE80211_SMPS_AUTOMATIC; | ||
449 | break; | ||
450 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | ||
451 | smps_request = IEEE80211_SMPS_DYNAMIC; | ||
452 | break; | ||
453 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | ||
454 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | ||
455 | smps_request = IEEE80211_SMPS_STATIC; | ||
456 | break; | ||
457 | default: | ||
458 | IWL_ERR(priv, "Invalid BT traffic load: %d\n", | ||
459 | priv->bt_traffic_load); | ||
460 | break; | ||
461 | } | ||
462 | |||
463 | mutex_lock(&priv->mutex); | ||
464 | |||
465 | /* | ||
466 | * We can not send command to firmware while scanning. When the scan | ||
467 | * complete we will schedule this work again. We do check with mutex | ||
468 | * locked to prevent new scan request to arrive. We do not check | ||
469 | * STATUS_SCANNING to avoid race when queue_work two times from | ||
470 | * different notifications, but quit and not perform any work at all. | ||
471 | */ | ||
472 | if (test_bit(STATUS_SCAN_HW, &priv->status)) | ||
473 | goto out; | ||
474 | |||
475 | iwl_update_chain_flags(priv); | ||
476 | |||
477 | if (smps_request != -1) { | ||
478 | priv->current_ht_config.smps = smps_request; | ||
479 | for_each_context(priv, ctx) { | ||
480 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION) | ||
481 | ieee80211_request_smps(ctx->vif, smps_request); | ||
482 | } | ||
483 | } | ||
484 | |||
485 | /* | ||
486 | * Dynamic PS poll related functionality. Adjust RSSI measurements if | ||
487 | * necessary. | ||
488 | */ | ||
489 | iwlagn_bt_coex_rssi_monitor(priv); | ||
490 | out: | ||
491 | mutex_unlock(&priv->mutex); | ||
492 | } | ||
493 | |||
494 | /* | ||
495 | * If BT sco traffic, and RSSI monitor is enabled, move measurements to the | ||
496 | * correct interface or disable it if this is the last interface to be | ||
497 | * removed. | ||
498 | */ | ||
499 | void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv) | ||
500 | { | ||
501 | if (priv->bt_is_sco && | ||
502 | priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS) | ||
503 | iwlagn_bt_adjust_rssi_monitor(priv, true); | ||
504 | else | ||
505 | iwlagn_bt_adjust_rssi_monitor(priv, false); | ||
506 | } | ||
507 | |||
508 | static void iwlagn_print_uartmsg(struct iwl_priv *priv, | ||
509 | struct iwl_bt_uart_msg *uart_msg) | ||
510 | { | ||
511 | IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, " | ||
512 | "Update Req = 0x%X\n", | ||
513 | (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >> | ||
514 | BT_UART_MSG_FRAME1MSGTYPE_POS, | ||
515 | (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >> | ||
516 | BT_UART_MSG_FRAME1SSN_POS, | ||
517 | (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >> | ||
518 | BT_UART_MSG_FRAME1UPDATEREQ_POS); | ||
519 | |||
520 | IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, " | ||
521 | "Chl_SeqN = 0x%X, In band = 0x%X\n", | ||
522 | (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >> | ||
523 | BT_UART_MSG_FRAME2OPENCONNECTIONS_POS, | ||
524 | (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >> | ||
525 | BT_UART_MSG_FRAME2TRAFFICLOAD_POS, | ||
526 | (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >> | ||
527 | BT_UART_MSG_FRAME2CHLSEQN_POS, | ||
528 | (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >> | ||
529 | BT_UART_MSG_FRAME2INBAND_POS); | ||
530 | |||
531 | IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, " | ||
532 | "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X\n", | ||
533 | (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >> | ||
534 | BT_UART_MSG_FRAME3SCOESCO_POS, | ||
535 | (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >> | ||
536 | BT_UART_MSG_FRAME3SNIFF_POS, | ||
537 | (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >> | ||
538 | BT_UART_MSG_FRAME3A2DP_POS, | ||
539 | (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >> | ||
540 | BT_UART_MSG_FRAME3ACL_POS, | ||
541 | (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >> | ||
542 | BT_UART_MSG_FRAME3MASTER_POS, | ||
543 | (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >> | ||
544 | BT_UART_MSG_FRAME3OBEX_POS); | ||
545 | |||
546 | IWL_DEBUG_COEX(priv, "Idle duration = 0x%X\n", | ||
547 | (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >> | ||
548 | BT_UART_MSG_FRAME4IDLEDURATION_POS); | ||
549 | |||
550 | IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, " | ||
551 | "eSCO Retransmissions = 0x%X\n", | ||
552 | (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >> | ||
553 | BT_UART_MSG_FRAME5TXACTIVITY_POS, | ||
554 | (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >> | ||
555 | BT_UART_MSG_FRAME5RXACTIVITY_POS, | ||
556 | (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >> | ||
557 | BT_UART_MSG_FRAME5ESCORETRANSMIT_POS); | ||
558 | |||
559 | IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X\n", | ||
560 | (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >> | ||
561 | BT_UART_MSG_FRAME6SNIFFINTERVAL_POS, | ||
562 | (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >> | ||
563 | BT_UART_MSG_FRAME6DISCOVERABLE_POS); | ||
564 | |||
565 | IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = " | ||
566 | "0x%X, Inquiry = 0x%X, Connectable = 0x%X\n", | ||
567 | (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >> | ||
568 | BT_UART_MSG_FRAME7SNIFFACTIVITY_POS, | ||
569 | (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >> | ||
570 | BT_UART_MSG_FRAME7PAGE_POS, | ||
571 | (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >> | ||
572 | BT_UART_MSG_FRAME7INQUIRY_POS, | ||
573 | (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >> | ||
574 | BT_UART_MSG_FRAME7CONNECTABLE_POS); | ||
575 | } | ||
576 | |||
577 | static bool iwlagn_set_kill_msk(struct iwl_priv *priv, | ||
578 | struct iwl_bt_uart_msg *uart_msg) | ||
579 | { | ||
580 | bool need_update = false; | ||
581 | u8 kill_msk = IWL_BT_KILL_REDUCE; | ||
582 | static const __le32 bt_kill_ack_msg[3] = { | ||
583 | IWLAGN_BT_KILL_ACK_MASK_DEFAULT, | ||
584 | IWLAGN_BT_KILL_ACK_CTS_MASK_SCO, | ||
585 | IWLAGN_BT_KILL_ACK_CTS_MASK_REDUCE}; | ||
586 | static const __le32 bt_kill_cts_msg[3] = { | ||
587 | IWLAGN_BT_KILL_CTS_MASK_DEFAULT, | ||
588 | IWLAGN_BT_KILL_ACK_CTS_MASK_SCO, | ||
589 | IWLAGN_BT_KILL_ACK_CTS_MASK_REDUCE}; | ||
590 | |||
591 | if (!priv->reduced_txpower) | ||
592 | kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) | ||
593 | ? IWL_BT_KILL_OVERRIDE : IWL_BT_KILL_DEFAULT; | ||
594 | if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] || | ||
595 | priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) { | ||
596 | priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK; | ||
597 | priv->kill_ack_mask = bt_kill_ack_msg[kill_msk]; | ||
598 | priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK; | ||
599 | priv->kill_cts_mask = bt_kill_cts_msg[kill_msk]; | ||
600 | need_update = true; | ||
601 | } | ||
602 | return need_update; | ||
603 | } | ||
604 | |||
605 | /* | ||
606 | * Upon RSSI changes, sends a bt config command with following changes | ||
607 | * 1. enable/disable "reduced control frames tx power | ||
608 | * 2. update the "kill)ack_mask" and "kill_cts_mask" | ||
609 | * | ||
610 | * If "reduced tx power" is enabled, uCode shall | ||
611 | * 1. ACK/Back/CTS rate shall reduced to 6Mbps | ||
612 | * 2. not use duplciate 20/40MHz mode | ||
613 | */ | ||
614 | static bool iwlagn_fill_txpower_mode(struct iwl_priv *priv, | ||
615 | struct iwl_bt_uart_msg *uart_msg) | ||
616 | { | ||
617 | bool need_update = false; | ||
618 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
619 | int ave_rssi; | ||
620 | |||
621 | if (!ctx->vif || (ctx->vif->type != NL80211_IFTYPE_STATION)) { | ||
622 | IWL_DEBUG_INFO(priv, "BSS ctx not active or not in sta mode\n"); | ||
623 | return false; | ||
624 | } | ||
625 | |||
626 | ave_rssi = ieee80211_ave_rssi(ctx->vif); | ||
627 | if (!ave_rssi) { | ||
628 | /* no rssi data, no changes to reduce tx power */ | ||
629 | IWL_DEBUG_COEX(priv, "no rssi data available\n"); | ||
630 | return need_update; | ||
631 | } | ||
632 | if (!priv->reduced_txpower && | ||
633 | !iwl_is_associated(priv, IWL_RXON_CTX_PAN) && | ||
634 | (ave_rssi > BT_ENABLE_REDUCED_TXPOWER_THRESHOLD) && | ||
635 | (uart_msg->frame3 & (BT_UART_MSG_FRAME3ACL_MSK | | ||
636 | BT_UART_MSG_FRAME3OBEX_MSK)) && | ||
637 | !(uart_msg->frame3 & (BT_UART_MSG_FRAME3SCOESCO_MSK | | ||
638 | BT_UART_MSG_FRAME3SNIFF_MSK | BT_UART_MSG_FRAME3A2DP_MSK))) { | ||
639 | /* enabling reduced tx power */ | ||
640 | priv->reduced_txpower = true; | ||
641 | priv->bt_valid |= IWLAGN_BT_VALID_REDUCED_TX_PWR; | ||
642 | need_update = true; | ||
643 | } else if (priv->reduced_txpower && | ||
644 | (iwl_is_associated(priv, IWL_RXON_CTX_PAN) || | ||
645 | (ave_rssi < BT_DISABLE_REDUCED_TXPOWER_THRESHOLD) || | ||
646 | (uart_msg->frame3 & (BT_UART_MSG_FRAME3SCOESCO_MSK | | ||
647 | BT_UART_MSG_FRAME3SNIFF_MSK | BT_UART_MSG_FRAME3A2DP_MSK)) || | ||
648 | !(uart_msg->frame3 & (BT_UART_MSG_FRAME3ACL_MSK | | ||
649 | BT_UART_MSG_FRAME3OBEX_MSK)))) { | ||
650 | /* disable reduced tx power */ | ||
651 | priv->reduced_txpower = false; | ||
652 | priv->bt_valid |= IWLAGN_BT_VALID_REDUCED_TX_PWR; | ||
653 | need_update = true; | ||
654 | } | ||
655 | |||
656 | return need_update; | ||
657 | } | ||
658 | |||
659 | int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv, | ||
660 | struct iwl_rx_cmd_buffer *rxb, | ||
661 | struct iwl_device_cmd *cmd) | ||
662 | { | ||
663 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
664 | struct iwl_bt_coex_profile_notif *coex = (void *)pkt->data; | ||
665 | struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg; | ||
666 | |||
667 | if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) { | ||
668 | /* bt coex disabled */ | ||
669 | return 0; | ||
670 | } | ||
671 | |||
672 | IWL_DEBUG_COEX(priv, "BT Coex notification:\n"); | ||
673 | IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status); | ||
674 | IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load); | ||
675 | IWL_DEBUG_COEX(priv, " CI compliance: %d\n", | ||
676 | coex->bt_ci_compliance); | ||
677 | iwlagn_print_uartmsg(priv, uart_msg); | ||
678 | |||
679 | priv->last_bt_traffic_load = priv->bt_traffic_load; | ||
680 | priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg); | ||
681 | |||
682 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { | ||
683 | if (priv->bt_status != coex->bt_status || | ||
684 | priv->last_bt_traffic_load != coex->bt_traffic_load) { | ||
685 | if (coex->bt_status) { | ||
686 | /* BT on */ | ||
687 | if (!priv->bt_ch_announce) | ||
688 | priv->bt_traffic_load = | ||
689 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH; | ||
690 | else | ||
691 | priv->bt_traffic_load = | ||
692 | coex->bt_traffic_load; | ||
693 | } else { | ||
694 | /* BT off */ | ||
695 | priv->bt_traffic_load = | ||
696 | IWL_BT_COEX_TRAFFIC_LOAD_NONE; | ||
697 | } | ||
698 | priv->bt_status = coex->bt_status; | ||
699 | queue_work(priv->workqueue, | ||
700 | &priv->bt_traffic_change_work); | ||
701 | } | ||
702 | } | ||
703 | |||
704 | /* schedule to send runtime bt_config */ | ||
705 | /* check reduce power before change ack/cts kill mask */ | ||
706 | if (iwlagn_fill_txpower_mode(priv, uart_msg) || | ||
707 | iwlagn_set_kill_msk(priv, uart_msg)) | ||
708 | queue_work(priv->workqueue, &priv->bt_runtime_config); | ||
709 | |||
710 | |||
711 | /* FIXME: based on notification, adjust the prio_boost */ | ||
712 | |||
713 | priv->bt_ci_compliance = coex->bt_ci_compliance; | ||
714 | return 0; | ||
715 | } | ||
716 | |||
717 | void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv) | ||
718 | { | ||
719 | priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] = | ||
720 | iwlagn_bt_coex_profile_notif; | ||
721 | } | ||
722 | |||
723 | void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv) | ||
724 | { | ||
725 | INIT_WORK(&priv->bt_traffic_change_work, | ||
726 | iwlagn_bt_traffic_change_work); | ||
727 | } | ||
728 | |||
729 | void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv) | ||
730 | { | ||
731 | cancel_work_sync(&priv->bt_traffic_change_work); | ||
732 | } | ||
733 | |||
734 | static bool is_single_rx_stream(struct iwl_priv *priv) | ||
735 | { | ||
736 | return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC || | ||
737 | priv->current_ht_config.single_chain_sufficient; | ||
738 | } | ||
739 | |||
740 | #define IWL_NUM_RX_CHAINS_MULTIPLE 3 | ||
741 | #define IWL_NUM_RX_CHAINS_SINGLE 2 | ||
742 | #define IWL_NUM_IDLE_CHAINS_DUAL 2 | ||
743 | #define IWL_NUM_IDLE_CHAINS_SINGLE 1 | ||
744 | |||
745 | /* | ||
746 | * Determine how many receiver/antenna chains to use. | ||
747 | * | ||
748 | * More provides better reception via diversity. Fewer saves power | ||
749 | * at the expense of throughput, but only when not in powersave to | ||
750 | * start with. | ||
751 | * | ||
752 | * MIMO (dual stream) requires at least 2, but works better with 3. | ||
753 | * This does not determine *which* chains to use, just how many. | ||
754 | */ | ||
755 | static int iwl_get_active_rx_chain_count(struct iwl_priv *priv) | ||
756 | { | ||
757 | if (priv->cfg->bt_params && | ||
758 | priv->cfg->bt_params->advanced_bt_coexist && | ||
759 | (priv->bt_full_concurrent || | ||
760 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) { | ||
761 | /* | ||
762 | * only use chain 'A' in bt high traffic load or | ||
763 | * full concurrency mode | ||
764 | */ | ||
765 | return IWL_NUM_RX_CHAINS_SINGLE; | ||
766 | } | ||
767 | /* # of Rx chains to use when expecting MIMO. */ | ||
768 | if (is_single_rx_stream(priv)) | ||
769 | return IWL_NUM_RX_CHAINS_SINGLE; | ||
770 | else | ||
771 | return IWL_NUM_RX_CHAINS_MULTIPLE; | ||
772 | } | ||
773 | |||
774 | /* | ||
775 | * When we are in power saving mode, unless device support spatial | ||
776 | * multiplexing power save, use the active count for rx chain count. | ||
777 | */ | ||
778 | static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt) | ||
779 | { | ||
780 | /* # Rx chains when idling, depending on SMPS mode */ | ||
781 | switch (priv->current_ht_config.smps) { | ||
782 | case IEEE80211_SMPS_STATIC: | ||
783 | case IEEE80211_SMPS_DYNAMIC: | ||
784 | return IWL_NUM_IDLE_CHAINS_SINGLE; | ||
785 | case IEEE80211_SMPS_AUTOMATIC: | ||
786 | case IEEE80211_SMPS_OFF: | ||
787 | return active_cnt; | ||
788 | default: | ||
789 | WARN(1, "invalid SMPS mode %d", | ||
790 | priv->current_ht_config.smps); | ||
791 | return active_cnt; | ||
792 | } | ||
793 | } | ||
794 | |||
795 | /* up to 4 chains */ | ||
796 | static u8 iwl_count_chain_bitmap(u32 chain_bitmap) | ||
797 | { | ||
798 | u8 res; | ||
799 | res = (chain_bitmap & BIT(0)) >> 0; | ||
800 | res += (chain_bitmap & BIT(1)) >> 1; | ||
801 | res += (chain_bitmap & BIT(2)) >> 2; | ||
802 | res += (chain_bitmap & BIT(3)) >> 3; | ||
803 | return res; | ||
804 | } | ||
805 | |||
806 | /** | ||
807 | * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image | ||
808 | * | ||
809 | * Selects how many and which Rx receivers/antennas/chains to use. | ||
810 | * This should not be used for scan command ... it puts data in wrong place. | ||
811 | */ | ||
812 | void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
813 | { | ||
814 | bool is_single = is_single_rx_stream(priv); | ||
815 | bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status); | ||
816 | u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt; | ||
817 | u32 active_chains; | ||
818 | u16 rx_chain; | ||
819 | |||
820 | /* Tell uCode which antennas are actually connected. | ||
821 | * Before first association, we assume all antennas are connected. | ||
822 | * Just after first association, iwl_chain_noise_calibration() | ||
823 | * checks which antennas actually *are* connected. */ | ||
824 | if (priv->chain_noise_data.active_chains) | ||
825 | active_chains = priv->chain_noise_data.active_chains; | ||
826 | else | ||
827 | active_chains = priv->eeprom_data->valid_rx_ant; | ||
828 | |||
829 | if (priv->cfg->bt_params && | ||
830 | priv->cfg->bt_params->advanced_bt_coexist && | ||
831 | (priv->bt_full_concurrent || | ||
832 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) { | ||
833 | /* | ||
834 | * only use chain 'A' in bt high traffic load or | ||
835 | * full concurrency mode | ||
836 | */ | ||
837 | active_chains = first_antenna(active_chains); | ||
838 | } | ||
839 | |||
840 | rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS; | ||
841 | |||
842 | /* How many receivers should we use? */ | ||
843 | active_rx_cnt = iwl_get_active_rx_chain_count(priv); | ||
844 | idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt); | ||
845 | |||
846 | |||
847 | /* correct rx chain count according hw settings | ||
848 | * and chain noise calibration | ||
849 | */ | ||
850 | valid_rx_cnt = iwl_count_chain_bitmap(active_chains); | ||
851 | if (valid_rx_cnt < active_rx_cnt) | ||
852 | active_rx_cnt = valid_rx_cnt; | ||
853 | |||
854 | if (valid_rx_cnt < idle_rx_cnt) | ||
855 | idle_rx_cnt = valid_rx_cnt; | ||
856 | |||
857 | rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS; | ||
858 | rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS; | ||
859 | |||
860 | ctx->staging.rx_chain = cpu_to_le16(rx_chain); | ||
861 | |||
862 | if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam) | ||
863 | ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK; | ||
864 | else | ||
865 | ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK; | ||
866 | |||
867 | IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n", | ||
868 | ctx->staging.rx_chain, | ||
869 | active_rx_cnt, idle_rx_cnt); | ||
870 | |||
871 | WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 || | ||
872 | active_rx_cnt < idle_rx_cnt); | ||
873 | } | ||
874 | |||
875 | u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid) | ||
876 | { | ||
877 | int i; | ||
878 | u8 ind = ant; | ||
879 | |||
880 | if (priv->band == IEEE80211_BAND_2GHZ && | ||
881 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) | ||
882 | return 0; | ||
883 | |||
884 | for (i = 0; i < RATE_ANT_NUM - 1; i++) { | ||
885 | ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0; | ||
886 | if (valid & BIT(ind)) | ||
887 | return ind; | ||
888 | } | ||
889 | return ant; | ||
890 | } | ||
891 | |||
892 | #ifdef CONFIG_PM_SLEEP | ||
893 | static void iwlagn_convert_p1k(u16 *p1k, __le16 *out) | ||
894 | { | ||
895 | int i; | ||
896 | |||
897 | for (i = 0; i < IWLAGN_P1K_SIZE; i++) | ||
898 | out[i] = cpu_to_le16(p1k[i]); | ||
899 | } | ||
900 | |||
901 | struct wowlan_key_data { | ||
902 | struct iwl_rxon_context *ctx; | ||
903 | struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc; | ||
904 | struct iwlagn_wowlan_tkip_params_cmd *tkip; | ||
905 | const u8 *bssid; | ||
906 | bool error, use_rsc_tsc, use_tkip; | ||
907 | }; | ||
908 | |||
909 | |||
910 | static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw, | ||
911 | struct ieee80211_vif *vif, | ||
912 | struct ieee80211_sta *sta, | ||
913 | struct ieee80211_key_conf *key, | ||
914 | void *_data) | ||
915 | { | ||
916 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
917 | struct wowlan_key_data *data = _data; | ||
918 | struct iwl_rxon_context *ctx = data->ctx; | ||
919 | struct aes_sc *aes_sc, *aes_tx_sc = NULL; | ||
920 | struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL; | ||
921 | struct iwlagn_p1k_cache *rx_p1ks; | ||
922 | u8 *rx_mic_key; | ||
923 | struct ieee80211_key_seq seq; | ||
924 | u32 cur_rx_iv32 = 0; | ||
925 | u16 p1k[IWLAGN_P1K_SIZE]; | ||
926 | int ret, i; | ||
927 | |||
928 | mutex_lock(&priv->mutex); | ||
929 | |||
930 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || | ||
931 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && | ||
932 | !sta && !ctx->key_mapping_keys) | ||
933 | ret = iwl_set_default_wep_key(priv, ctx, key); | ||
934 | else | ||
935 | ret = iwl_set_dynamic_key(priv, ctx, key, sta); | ||
936 | |||
937 | if (ret) { | ||
938 | IWL_ERR(priv, "Error setting key during suspend!\n"); | ||
939 | data->error = true; | ||
940 | } | ||
941 | |||
942 | switch (key->cipher) { | ||
943 | case WLAN_CIPHER_SUITE_TKIP: | ||
944 | if (sta) { | ||
945 | tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc; | ||
946 | tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc; | ||
947 | |||
948 | rx_p1ks = data->tkip->rx_uni; | ||
949 | |||
950 | ieee80211_get_key_tx_seq(key, &seq); | ||
951 | tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16); | ||
952 | tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32); | ||
953 | |||
954 | ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k); | ||
955 | iwlagn_convert_p1k(p1k, data->tkip->tx.p1k); | ||
956 | |||
957 | memcpy(data->tkip->mic_keys.tx, | ||
958 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], | ||
959 | IWLAGN_MIC_KEY_SIZE); | ||
960 | |||
961 | rx_mic_key = data->tkip->mic_keys.rx_unicast; | ||
962 | } else { | ||
963 | tkip_sc = | ||
964 | data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc; | ||
965 | rx_p1ks = data->tkip->rx_multi; | ||
966 | rx_mic_key = data->tkip->mic_keys.rx_mcast; | ||
967 | } | ||
968 | |||
969 | /* | ||
970 | * For non-QoS this relies on the fact that both the uCode and | ||
971 | * mac80211 use TID 0 (as they need to to avoid replay attacks) | ||
972 | * for checking the IV in the frames. | ||
973 | */ | ||
974 | for (i = 0; i < IWLAGN_NUM_RSC; i++) { | ||
975 | ieee80211_get_key_rx_seq(key, i, &seq); | ||
976 | tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16); | ||
977 | tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32); | ||
978 | /* wrapping isn't allowed, AP must rekey */ | ||
979 | if (seq.tkip.iv32 > cur_rx_iv32) | ||
980 | cur_rx_iv32 = seq.tkip.iv32; | ||
981 | } | ||
982 | |||
983 | ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k); | ||
984 | iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k); | ||
985 | ieee80211_get_tkip_rx_p1k(key, data->bssid, | ||
986 | cur_rx_iv32 + 1, p1k); | ||
987 | iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k); | ||
988 | |||
989 | memcpy(rx_mic_key, | ||
990 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], | ||
991 | IWLAGN_MIC_KEY_SIZE); | ||
992 | |||
993 | data->use_tkip = true; | ||
994 | data->use_rsc_tsc = true; | ||
995 | break; | ||
996 | case WLAN_CIPHER_SUITE_CCMP: | ||
997 | if (sta) { | ||
998 | u8 *pn = seq.ccmp.pn; | ||
999 | |||
1000 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc; | ||
1001 | aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc; | ||
1002 | |||
1003 | ieee80211_get_key_tx_seq(key, &seq); | ||
1004 | aes_tx_sc->pn = cpu_to_le64( | ||
1005 | (u64)pn[5] | | ||
1006 | ((u64)pn[4] << 8) | | ||
1007 | ((u64)pn[3] << 16) | | ||
1008 | ((u64)pn[2] << 24) | | ||
1009 | ((u64)pn[1] << 32) | | ||
1010 | ((u64)pn[0] << 40)); | ||
1011 | } else | ||
1012 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc; | ||
1013 | |||
1014 | /* | ||
1015 | * For non-QoS this relies on the fact that both the uCode and | ||
1016 | * mac80211 use TID 0 for checking the IV in the frames. | ||
1017 | */ | ||
1018 | for (i = 0; i < IWLAGN_NUM_RSC; i++) { | ||
1019 | u8 *pn = seq.ccmp.pn; | ||
1020 | |||
1021 | ieee80211_get_key_rx_seq(key, i, &seq); | ||
1022 | aes_sc->pn = cpu_to_le64( | ||
1023 | (u64)pn[5] | | ||
1024 | ((u64)pn[4] << 8) | | ||
1025 | ((u64)pn[3] << 16) | | ||
1026 | ((u64)pn[2] << 24) | | ||
1027 | ((u64)pn[1] << 32) | | ||
1028 | ((u64)pn[0] << 40)); | ||
1029 | } | ||
1030 | data->use_rsc_tsc = true; | ||
1031 | break; | ||
1032 | } | ||
1033 | |||
1034 | mutex_unlock(&priv->mutex); | ||
1035 | } | ||
1036 | |||
1037 | int iwlagn_send_patterns(struct iwl_priv *priv, | ||
1038 | struct cfg80211_wowlan *wowlan) | ||
1039 | { | ||
1040 | struct iwlagn_wowlan_patterns_cmd *pattern_cmd; | ||
1041 | struct iwl_host_cmd cmd = { | ||
1042 | .id = REPLY_WOWLAN_PATTERNS, | ||
1043 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | ||
1044 | .flags = CMD_SYNC, | ||
1045 | }; | ||
1046 | int i, err; | ||
1047 | |||
1048 | if (!wowlan->n_patterns) | ||
1049 | return 0; | ||
1050 | |||
1051 | cmd.len[0] = sizeof(*pattern_cmd) + | ||
1052 | wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern); | ||
1053 | |||
1054 | pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL); | ||
1055 | if (!pattern_cmd) | ||
1056 | return -ENOMEM; | ||
1057 | |||
1058 | pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns); | ||
1059 | |||
1060 | for (i = 0; i < wowlan->n_patterns; i++) { | ||
1061 | int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); | ||
1062 | |||
1063 | memcpy(&pattern_cmd->patterns[i].mask, | ||
1064 | wowlan->patterns[i].mask, mask_len); | ||
1065 | memcpy(&pattern_cmd->patterns[i].pattern, | ||
1066 | wowlan->patterns[i].pattern, | ||
1067 | wowlan->patterns[i].pattern_len); | ||
1068 | pattern_cmd->patterns[i].mask_size = mask_len; | ||
1069 | pattern_cmd->patterns[i].pattern_size = | ||
1070 | wowlan->patterns[i].pattern_len; | ||
1071 | } | ||
1072 | |||
1073 | cmd.data[0] = pattern_cmd; | ||
1074 | err = iwl_dvm_send_cmd(priv, &cmd); | ||
1075 | kfree(pattern_cmd); | ||
1076 | return err; | ||
1077 | } | ||
1078 | |||
1079 | int iwlagn_suspend(struct iwl_priv *priv, struct cfg80211_wowlan *wowlan) | ||
1080 | { | ||
1081 | struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd; | ||
1082 | struct iwl_rxon_cmd rxon; | ||
1083 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
1084 | struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd; | ||
1085 | struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {}; | ||
1086 | struct iwlagn_d3_config_cmd d3_cfg_cmd = {}; | ||
1087 | struct wowlan_key_data key_data = { | ||
1088 | .ctx = ctx, | ||
1089 | .bssid = ctx->active.bssid_addr, | ||
1090 | .use_rsc_tsc = false, | ||
1091 | .tkip = &tkip_cmd, | ||
1092 | .use_tkip = false, | ||
1093 | }; | ||
1094 | int ret, i; | ||
1095 | u16 seq; | ||
1096 | |||
1097 | key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL); | ||
1098 | if (!key_data.rsc_tsc) | ||
1099 | return -ENOMEM; | ||
1100 | |||
1101 | memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd)); | ||
1102 | |||
1103 | /* | ||
1104 | * We know the last used seqno, and the uCode expects to know that | ||
1105 | * one, it will increment before TX. | ||
1106 | */ | ||
1107 | seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ; | ||
1108 | wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq); | ||
1109 | |||
1110 | /* | ||
1111 | * For QoS counters, we store the one to use next, so subtract 0x10 | ||
1112 | * since the uCode will add 0x10 before using the value. | ||
1113 | */ | ||
1114 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { | ||
1115 | seq = priv->tid_data[IWL_AP_ID][i].seq_number; | ||
1116 | seq -= 0x10; | ||
1117 | wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq); | ||
1118 | } | ||
1119 | |||
1120 | if (wowlan->disconnect) | ||
1121 | wakeup_filter_cmd.enabled |= | ||
1122 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS | | ||
1123 | IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE); | ||
1124 | if (wowlan->magic_pkt) | ||
1125 | wakeup_filter_cmd.enabled |= | ||
1126 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET); | ||
1127 | if (wowlan->gtk_rekey_failure) | ||
1128 | wakeup_filter_cmd.enabled |= | ||
1129 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL); | ||
1130 | if (wowlan->eap_identity_req) | ||
1131 | wakeup_filter_cmd.enabled |= | ||
1132 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ); | ||
1133 | if (wowlan->four_way_handshake) | ||
1134 | wakeup_filter_cmd.enabled |= | ||
1135 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE); | ||
1136 | if (wowlan->n_patterns) | ||
1137 | wakeup_filter_cmd.enabled |= | ||
1138 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH); | ||
1139 | |||
1140 | if (wowlan->rfkill_release) | ||
1141 | d3_cfg_cmd.wakeup_flags |= | ||
1142 | cpu_to_le32(IWLAGN_D3_WAKEUP_RFKILL); | ||
1143 | |||
1144 | iwl_scan_cancel_timeout(priv, 200); | ||
1145 | |||
1146 | memcpy(&rxon, &ctx->active, sizeof(rxon)); | ||
1147 | |||
1148 | priv->ucode_loaded = false; | ||
1149 | iwl_trans_stop_device(priv->trans); | ||
1150 | |||
1151 | priv->wowlan = true; | ||
1152 | |||
1153 | ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN); | ||
1154 | if (ret) | ||
1155 | goto out; | ||
1156 | |||
1157 | /* now configure WoWLAN ucode */ | ||
1158 | ret = iwl_alive_start(priv); | ||
1159 | if (ret) | ||
1160 | goto out; | ||
1161 | |||
1162 | memcpy(&ctx->staging, &rxon, sizeof(rxon)); | ||
1163 | ret = iwlagn_commit_rxon(priv, ctx); | ||
1164 | if (ret) | ||
1165 | goto out; | ||
1166 | |||
1167 | ret = iwl_power_update_mode(priv, true); | ||
1168 | if (ret) | ||
1169 | goto out; | ||
1170 | |||
1171 | if (!iwlwifi_mod_params.sw_crypto) { | ||
1172 | /* mark all keys clear */ | ||
1173 | priv->ucode_key_table = 0; | ||
1174 | ctx->key_mapping_keys = 0; | ||
1175 | |||
1176 | /* | ||
1177 | * This needs to be unlocked due to lock ordering | ||
1178 | * constraints. Since we're in the suspend path | ||
1179 | * that isn't really a problem though. | ||
1180 | */ | ||
1181 | mutex_unlock(&priv->mutex); | ||
1182 | ieee80211_iter_keys(priv->hw, ctx->vif, | ||
1183 | iwlagn_wowlan_program_keys, | ||
1184 | &key_data); | ||
1185 | mutex_lock(&priv->mutex); | ||
1186 | if (key_data.error) { | ||
1187 | ret = -EIO; | ||
1188 | goto out; | ||
1189 | } | ||
1190 | |||
1191 | if (key_data.use_rsc_tsc) { | ||
1192 | struct iwl_host_cmd rsc_tsc_cmd = { | ||
1193 | .id = REPLY_WOWLAN_TSC_RSC_PARAMS, | ||
1194 | .flags = CMD_SYNC, | ||
1195 | .data[0] = key_data.rsc_tsc, | ||
1196 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | ||
1197 | .len[0] = sizeof(*key_data.rsc_tsc), | ||
1198 | }; | ||
1199 | |||
1200 | ret = iwl_dvm_send_cmd(priv, &rsc_tsc_cmd); | ||
1201 | if (ret) | ||
1202 | goto out; | ||
1203 | } | ||
1204 | |||
1205 | if (key_data.use_tkip) { | ||
1206 | ret = iwl_dvm_send_cmd_pdu(priv, | ||
1207 | REPLY_WOWLAN_TKIP_PARAMS, | ||
1208 | CMD_SYNC, sizeof(tkip_cmd), | ||
1209 | &tkip_cmd); | ||
1210 | if (ret) | ||
1211 | goto out; | ||
1212 | } | ||
1213 | |||
1214 | if (priv->have_rekey_data) { | ||
1215 | memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd)); | ||
1216 | memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN); | ||
1217 | kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN); | ||
1218 | memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN); | ||
1219 | kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN); | ||
1220 | kek_kck_cmd.replay_ctr = priv->replay_ctr; | ||
1221 | |||
1222 | ret = iwl_dvm_send_cmd_pdu(priv, | ||
1223 | REPLY_WOWLAN_KEK_KCK_MATERIAL, | ||
1224 | CMD_SYNC, sizeof(kek_kck_cmd), | ||
1225 | &kek_kck_cmd); | ||
1226 | if (ret) | ||
1227 | goto out; | ||
1228 | } | ||
1229 | } | ||
1230 | |||
1231 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_D3_CONFIG, CMD_SYNC, | ||
1232 | sizeof(d3_cfg_cmd), &d3_cfg_cmd); | ||
1233 | if (ret) | ||
1234 | goto out; | ||
1235 | |||
1236 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WOWLAN_WAKEUP_FILTER, | ||
1237 | CMD_SYNC, sizeof(wakeup_filter_cmd), | ||
1238 | &wakeup_filter_cmd); | ||
1239 | if (ret) | ||
1240 | goto out; | ||
1241 | |||
1242 | ret = iwlagn_send_patterns(priv, wowlan); | ||
1243 | out: | ||
1244 | kfree(key_data.rsc_tsc); | ||
1245 | return ret; | ||
1246 | } | ||
1247 | #endif | ||
1248 | |||
1249 | int iwl_dvm_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) | ||
1250 | { | ||
1251 | if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) { | ||
1252 | IWL_WARN(priv, "Not sending command - %s KILL\n", | ||
1253 | iwl_is_rfkill(priv) ? "RF" : "CT"); | ||
1254 | return -EIO; | ||
1255 | } | ||
1256 | |||
1257 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { | ||
1258 | IWL_ERR(priv, "Command %s failed: FW Error\n", | ||
1259 | iwl_dvm_get_cmd_string(cmd->id)); | ||
1260 | return -EIO; | ||
1261 | } | ||
1262 | |||
1263 | /* | ||
1264 | * Synchronous commands from this op-mode must hold | ||
1265 | * the mutex, this ensures we don't try to send two | ||
1266 | * (or more) synchronous commands at a time. | ||
1267 | */ | ||
1268 | if (cmd->flags & CMD_SYNC) | ||
1269 | lockdep_assert_held(&priv->mutex); | ||
1270 | |||
1271 | if (priv->ucode_owner == IWL_OWNERSHIP_TM && | ||
1272 | !(cmd->flags & CMD_ON_DEMAND)) { | ||
1273 | IWL_DEBUG_HC(priv, "tm own the uCode, no regular hcmd send\n"); | ||
1274 | return -EIO; | ||
1275 | } | ||
1276 | |||
1277 | return iwl_trans_send_cmd(priv->trans, cmd); | ||
1278 | } | ||
1279 | |||
1280 | int iwl_dvm_send_cmd_pdu(struct iwl_priv *priv, u8 id, | ||
1281 | u32 flags, u16 len, const void *data) | ||
1282 | { | ||
1283 | struct iwl_host_cmd cmd = { | ||
1284 | .id = id, | ||
1285 | .len = { len, }, | ||
1286 | .data = { data, }, | ||
1287 | .flags = flags, | ||
1288 | }; | ||
1289 | |||
1290 | return iwl_dvm_send_cmd(priv, &cmd); | ||
1291 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/mac80211.c b/drivers/net/wireless/iwlwifi/dvm/mac80211.c new file mode 100644 index 000000000000..599e8b41f5a8 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c | |||
@@ -0,0 +1,1633 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 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 | *****************************************************************************/ | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/init.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include <linux/dma-mapping.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/sched.h> | ||
36 | #include <linux/skbuff.h> | ||
37 | #include <linux/netdevice.h> | ||
38 | #include <linux/etherdevice.h> | ||
39 | #include <linux/if_arp.h> | ||
40 | |||
41 | #include <net/ieee80211_radiotap.h> | ||
42 | #include <net/mac80211.h> | ||
43 | |||
44 | #include <asm/div64.h> | ||
45 | |||
46 | #include "iwl-io.h" | ||
47 | #include "iwl-trans.h" | ||
48 | #include "iwl-op-mode.h" | ||
49 | #include "iwl-modparams.h" | ||
50 | |||
51 | #include "dev.h" | ||
52 | #include "calib.h" | ||
53 | #include "agn.h" | ||
54 | |||
55 | /***************************************************************************** | ||
56 | * | ||
57 | * mac80211 entry point functions | ||
58 | * | ||
59 | *****************************************************************************/ | ||
60 | |||
61 | static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = { | ||
62 | { | ||
63 | .max = 1, | ||
64 | .types = BIT(NL80211_IFTYPE_STATION), | ||
65 | }, | ||
66 | { | ||
67 | .max = 1, | ||
68 | .types = BIT(NL80211_IFTYPE_AP), | ||
69 | }, | ||
70 | }; | ||
71 | |||
72 | static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = { | ||
73 | { | ||
74 | .max = 2, | ||
75 | .types = BIT(NL80211_IFTYPE_STATION), | ||
76 | }, | ||
77 | }; | ||
78 | |||
79 | static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = { | ||
80 | { | ||
81 | .max = 1, | ||
82 | .types = BIT(NL80211_IFTYPE_STATION), | ||
83 | }, | ||
84 | { | ||
85 | .max = 1, | ||
86 | .types = BIT(NL80211_IFTYPE_P2P_GO) | | ||
87 | BIT(NL80211_IFTYPE_AP), | ||
88 | }, | ||
89 | }; | ||
90 | |||
91 | static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = { | ||
92 | { | ||
93 | .max = 2, | ||
94 | .types = BIT(NL80211_IFTYPE_STATION), | ||
95 | }, | ||
96 | { | ||
97 | .max = 1, | ||
98 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT), | ||
99 | }, | ||
100 | }; | ||
101 | |||
102 | static const struct ieee80211_iface_combination | ||
103 | iwlagn_iface_combinations_dualmode[] = { | ||
104 | { .num_different_channels = 1, | ||
105 | .max_interfaces = 2, | ||
106 | .beacon_int_infra_match = true, | ||
107 | .limits = iwlagn_sta_ap_limits, | ||
108 | .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits), | ||
109 | }, | ||
110 | { .num_different_channels = 1, | ||
111 | .max_interfaces = 2, | ||
112 | .limits = iwlagn_2sta_limits, | ||
113 | .n_limits = ARRAY_SIZE(iwlagn_2sta_limits), | ||
114 | }, | ||
115 | }; | ||
116 | |||
117 | static const struct ieee80211_iface_combination | ||
118 | iwlagn_iface_combinations_p2p[] = { | ||
119 | { .num_different_channels = 1, | ||
120 | .max_interfaces = 2, | ||
121 | .beacon_int_infra_match = true, | ||
122 | .limits = iwlagn_p2p_sta_go_limits, | ||
123 | .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits), | ||
124 | }, | ||
125 | { .num_different_channels = 1, | ||
126 | .max_interfaces = 2, | ||
127 | .limits = iwlagn_p2p_2sta_limits, | ||
128 | .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits), | ||
129 | }, | ||
130 | }; | ||
131 | |||
132 | /* | ||
133 | * Not a mac80211 entry point function, but it fits in with all the | ||
134 | * other mac80211 functions grouped here. | ||
135 | */ | ||
136 | int iwlagn_mac_setup_register(struct iwl_priv *priv, | ||
137 | const struct iwl_ucode_capabilities *capa) | ||
138 | { | ||
139 | int ret; | ||
140 | struct ieee80211_hw *hw = priv->hw; | ||
141 | struct iwl_rxon_context *ctx; | ||
142 | |||
143 | hw->rate_control_algorithm = "iwl-agn-rs"; | ||
144 | |||
145 | /* Tell mac80211 our characteristics */ | ||
146 | hw->flags = IEEE80211_HW_SIGNAL_DBM | | ||
147 | IEEE80211_HW_AMPDU_AGGREGATION | | ||
148 | IEEE80211_HW_NEED_DTIM_PERIOD | | ||
149 | IEEE80211_HW_SPECTRUM_MGMT | | ||
150 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | | ||
151 | IEEE80211_HW_QUEUE_CONTROL | | ||
152 | IEEE80211_HW_SUPPORTS_PS | | ||
153 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | | ||
154 | IEEE80211_HW_WANT_MONITOR_VIF | | ||
155 | IEEE80211_HW_SCAN_WHILE_IDLE; | ||
156 | |||
157 | hw->offchannel_tx_hw_queue = IWL_AUX_QUEUE; | ||
158 | hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FMT; | ||
159 | |||
160 | /* | ||
161 | * Including the following line will crash some AP's. This | ||
162 | * workaround removes the stimulus which causes the crash until | ||
163 | * the AP software can be fixed. | ||
164 | hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF; | ||
165 | */ | ||
166 | |||
167 | if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE) | ||
168 | hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | | ||
169 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; | ||
170 | |||
171 | #ifndef CONFIG_IWLWIFI_EXPERIMENTAL_MFP | ||
172 | /* enable 11w if the uCode advertise */ | ||
173 | if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP) | ||
174 | #endif /* !CONFIG_IWLWIFI_EXPERIMENTAL_MFP */ | ||
175 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; | ||
176 | |||
177 | hw->sta_data_size = sizeof(struct iwl_station_priv); | ||
178 | hw->vif_data_size = sizeof(struct iwl_vif_priv); | ||
179 | |||
180 | for_each_context(priv, ctx) { | ||
181 | hw->wiphy->interface_modes |= ctx->interface_modes; | ||
182 | hw->wiphy->interface_modes |= ctx->exclusive_interface_modes; | ||
183 | } | ||
184 | |||
185 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | ||
186 | |||
187 | if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) { | ||
188 | hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p; | ||
189 | hw->wiphy->n_iface_combinations = | ||
190 | ARRAY_SIZE(iwlagn_iface_combinations_p2p); | ||
191 | } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) { | ||
192 | hw->wiphy->iface_combinations = | ||
193 | iwlagn_iface_combinations_dualmode; | ||
194 | hw->wiphy->n_iface_combinations = | ||
195 | ARRAY_SIZE(iwlagn_iface_combinations_dualmode); | ||
196 | } | ||
197 | |||
198 | hw->wiphy->max_remain_on_channel_duration = 1000; | ||
199 | |||
200 | hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | | ||
201 | WIPHY_FLAG_DISABLE_BEACON_HINTS | | ||
202 | WIPHY_FLAG_IBSS_RSN; | ||
203 | |||
204 | #ifdef CONFIG_PM_SLEEP | ||
205 | if (priv->fw->img[IWL_UCODE_WOWLAN].sec[0].len && | ||
206 | priv->trans->ops->wowlan_suspend && | ||
207 | device_can_wakeup(priv->trans->dev)) { | ||
208 | hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | | ||
209 | WIPHY_WOWLAN_DISCONNECT | | ||
210 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | | ||
211 | WIPHY_WOWLAN_RFKILL_RELEASE; | ||
212 | if (!iwlwifi_mod_params.sw_crypto) | ||
213 | hw->wiphy->wowlan.flags |= | ||
214 | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | | ||
215 | WIPHY_WOWLAN_GTK_REKEY_FAILURE; | ||
216 | |||
217 | hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS; | ||
218 | hw->wiphy->wowlan.pattern_min_len = | ||
219 | IWLAGN_WOWLAN_MIN_PATTERN_LEN; | ||
220 | hw->wiphy->wowlan.pattern_max_len = | ||
221 | IWLAGN_WOWLAN_MAX_PATTERN_LEN; | ||
222 | } | ||
223 | #endif | ||
224 | |||
225 | if (iwlwifi_mod_params.power_save) | ||
226 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; | ||
227 | else | ||
228 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; | ||
229 | |||
230 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; | ||
231 | /* we create the 802.11 header and a max-length SSID element */ | ||
232 | hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 34; | ||
233 | |||
234 | /* | ||
235 | * We don't use all queues: 4 and 9 are unused and any | ||
236 | * aggregation queue gets mapped down to the AC queue. | ||
237 | */ | ||
238 | hw->queues = IWLAGN_FIRST_AMPDU_QUEUE; | ||
239 | |||
240 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; | ||
241 | |||
242 | if (priv->eeprom_data->bands[IEEE80211_BAND_2GHZ].n_channels) | ||
243 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = | ||
244 | &priv->eeprom_data->bands[IEEE80211_BAND_2GHZ]; | ||
245 | if (priv->eeprom_data->bands[IEEE80211_BAND_5GHZ].n_channels) | ||
246 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = | ||
247 | &priv->eeprom_data->bands[IEEE80211_BAND_5GHZ]; | ||
248 | |||
249 | hw->wiphy->hw_version = priv->trans->hw_id; | ||
250 | |||
251 | iwl_leds_init(priv); | ||
252 | |||
253 | ret = ieee80211_register_hw(priv->hw); | ||
254 | if (ret) { | ||
255 | IWL_ERR(priv, "Failed to register hw (error %d)\n", ret); | ||
256 | iwl_leds_exit(priv); | ||
257 | return ret; | ||
258 | } | ||
259 | priv->mac80211_registered = 1; | ||
260 | |||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | void iwlagn_mac_unregister(struct iwl_priv *priv) | ||
265 | { | ||
266 | if (!priv->mac80211_registered) | ||
267 | return; | ||
268 | iwl_leds_exit(priv); | ||
269 | ieee80211_unregister_hw(priv->hw); | ||
270 | priv->mac80211_registered = 0; | ||
271 | } | ||
272 | |||
273 | static int __iwl_up(struct iwl_priv *priv) | ||
274 | { | ||
275 | struct iwl_rxon_context *ctx; | ||
276 | int ret; | ||
277 | |||
278 | lockdep_assert_held(&priv->mutex); | ||
279 | |||
280 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { | ||
281 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); | ||
282 | return -EIO; | ||
283 | } | ||
284 | |||
285 | for_each_context(priv, ctx) { | ||
286 | ret = iwlagn_alloc_bcast_station(priv, ctx); | ||
287 | if (ret) { | ||
288 | iwl_dealloc_bcast_stations(priv); | ||
289 | return ret; | ||
290 | } | ||
291 | } | ||
292 | |||
293 | ret = iwl_run_init_ucode(priv); | ||
294 | if (ret) { | ||
295 | IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret); | ||
296 | goto error; | ||
297 | } | ||
298 | |||
299 | ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR); | ||
300 | if (ret) { | ||
301 | IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret); | ||
302 | goto error; | ||
303 | } | ||
304 | |||
305 | ret = iwl_alive_start(priv); | ||
306 | if (ret) | ||
307 | goto error; | ||
308 | return 0; | ||
309 | |||
310 | error: | ||
311 | set_bit(STATUS_EXIT_PENDING, &priv->status); | ||
312 | iwl_down(priv); | ||
313 | clear_bit(STATUS_EXIT_PENDING, &priv->status); | ||
314 | |||
315 | IWL_ERR(priv, "Unable to initialize device.\n"); | ||
316 | return ret; | ||
317 | } | ||
318 | |||
319 | static int iwlagn_mac_start(struct ieee80211_hw *hw) | ||
320 | { | ||
321 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
322 | int ret; | ||
323 | |||
324 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
325 | |||
326 | /* we should be verifying the device is ready to be opened */ | ||
327 | mutex_lock(&priv->mutex); | ||
328 | ret = __iwl_up(priv); | ||
329 | mutex_unlock(&priv->mutex); | ||
330 | if (ret) | ||
331 | return ret; | ||
332 | |||
333 | IWL_DEBUG_INFO(priv, "Start UP work done.\n"); | ||
334 | |||
335 | /* Now we should be done, and the READY bit should be set. */ | ||
336 | if (WARN_ON(!test_bit(STATUS_READY, &priv->status))) | ||
337 | ret = -EIO; | ||
338 | |||
339 | iwlagn_led_enable(priv); | ||
340 | |||
341 | priv->is_open = 1; | ||
342 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | static void iwlagn_mac_stop(struct ieee80211_hw *hw) | ||
347 | { | ||
348 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
349 | |||
350 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
351 | |||
352 | if (!priv->is_open) | ||
353 | return; | ||
354 | |||
355 | priv->is_open = 0; | ||
356 | |||
357 | mutex_lock(&priv->mutex); | ||
358 | iwl_down(priv); | ||
359 | mutex_unlock(&priv->mutex); | ||
360 | |||
361 | iwl_cancel_deferred_work(priv); | ||
362 | |||
363 | flush_workqueue(priv->workqueue); | ||
364 | |||
365 | /* User space software may expect getting rfkill changes | ||
366 | * even if interface is down, trans->down will leave the RF | ||
367 | * kill interrupt enabled | ||
368 | */ | ||
369 | iwl_trans_stop_hw(priv->trans, false); | ||
370 | |||
371 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
372 | } | ||
373 | |||
374 | static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw, | ||
375 | struct ieee80211_vif *vif, | ||
376 | struct cfg80211_gtk_rekey_data *data) | ||
377 | { | ||
378 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
379 | |||
380 | if (iwlwifi_mod_params.sw_crypto) | ||
381 | return; | ||
382 | |||
383 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
384 | mutex_lock(&priv->mutex); | ||
385 | |||
386 | if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif) | ||
387 | goto out; | ||
388 | |||
389 | memcpy(priv->kek, data->kek, NL80211_KEK_LEN); | ||
390 | memcpy(priv->kck, data->kck, NL80211_KCK_LEN); | ||
391 | priv->replay_ctr = | ||
392 | cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr)); | ||
393 | priv->have_rekey_data = true; | ||
394 | |||
395 | out: | ||
396 | mutex_unlock(&priv->mutex); | ||
397 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
398 | } | ||
399 | |||
400 | #ifdef CONFIG_PM_SLEEP | ||
401 | |||
402 | static int iwlagn_mac_suspend(struct ieee80211_hw *hw, | ||
403 | struct cfg80211_wowlan *wowlan) | ||
404 | { | ||
405 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
406 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
407 | int ret; | ||
408 | |||
409 | if (WARN_ON(!wowlan)) | ||
410 | return -EINVAL; | ||
411 | |||
412 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
413 | mutex_lock(&priv->mutex); | ||
414 | |||
415 | /* Don't attempt WoWLAN when not associated, tear down instead. */ | ||
416 | if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION || | ||
417 | !iwl_is_associated_ctx(ctx)) { | ||
418 | ret = 1; | ||
419 | goto out; | ||
420 | } | ||
421 | |||
422 | ret = iwlagn_suspend(priv, wowlan); | ||
423 | if (ret) | ||
424 | goto error; | ||
425 | |||
426 | iwl_trans_wowlan_suspend(priv->trans); | ||
427 | |||
428 | goto out; | ||
429 | |||
430 | error: | ||
431 | priv->wowlan = false; | ||
432 | iwlagn_prepare_restart(priv); | ||
433 | ieee80211_restart_hw(priv->hw); | ||
434 | out: | ||
435 | mutex_unlock(&priv->mutex); | ||
436 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
437 | |||
438 | return ret; | ||
439 | } | ||
440 | |||
441 | static int iwlagn_mac_resume(struct ieee80211_hw *hw) | ||
442 | { | ||
443 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
444 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
445 | struct ieee80211_vif *vif; | ||
446 | unsigned long flags; | ||
447 | u32 base, status = 0xffffffff; | ||
448 | int ret = -EIO; | ||
449 | |||
450 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
451 | mutex_lock(&priv->mutex); | ||
452 | |||
453 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, | ||
454 | CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE); | ||
455 | |||
456 | base = priv->device_pointers.error_event_table; | ||
457 | if (iwlagn_hw_valid_rtc_data_addr(base)) { | ||
458 | spin_lock_irqsave(&priv->trans->reg_lock, flags); | ||
459 | ret = iwl_grab_nic_access_silent(priv->trans); | ||
460 | if (likely(ret == 0)) { | ||
461 | iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, base); | ||
462 | status = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); | ||
463 | iwl_release_nic_access(priv->trans); | ||
464 | } | ||
465 | spin_unlock_irqrestore(&priv->trans->reg_lock, flags); | ||
466 | |||
467 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
468 | if (ret == 0) { | ||
469 | const struct fw_img *img; | ||
470 | |||
471 | img = &(priv->fw->img[IWL_UCODE_WOWLAN]); | ||
472 | if (!priv->wowlan_sram) { | ||
473 | priv->wowlan_sram = | ||
474 | kzalloc(img->sec[IWL_UCODE_SECTION_DATA].len, | ||
475 | GFP_KERNEL); | ||
476 | } | ||
477 | |||
478 | if (priv->wowlan_sram) | ||
479 | _iwl_read_targ_mem_words( | ||
480 | priv->trans, 0x800000, | ||
481 | priv->wowlan_sram, | ||
482 | img->sec[IWL_UCODE_SECTION_DATA].len / 4); | ||
483 | } | ||
484 | #endif | ||
485 | } | ||
486 | |||
487 | /* we'll clear ctx->vif during iwlagn_prepare_restart() */ | ||
488 | vif = ctx->vif; | ||
489 | |||
490 | priv->wowlan = false; | ||
491 | |||
492 | iwlagn_prepare_restart(priv); | ||
493 | |||
494 | memset((void *)&ctx->active, 0, sizeof(ctx->active)); | ||
495 | iwl_connection_init_rx_config(priv, ctx); | ||
496 | iwlagn_set_rxon_chain(priv, ctx); | ||
497 | |||
498 | mutex_unlock(&priv->mutex); | ||
499 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
500 | |||
501 | ieee80211_resume_disconnect(vif); | ||
502 | |||
503 | return 1; | ||
504 | } | ||
505 | |||
506 | static void iwlagn_mac_set_wakeup(struct ieee80211_hw *hw, bool enabled) | ||
507 | { | ||
508 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
509 | |||
510 | device_set_wakeup_enable(priv->trans->dev, enabled); | ||
511 | } | ||
512 | #endif | ||
513 | |||
514 | static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | ||
515 | { | ||
516 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
517 | |||
518 | IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, | ||
519 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); | ||
520 | |||
521 | if (iwlagn_tx_skb(priv, skb)) | ||
522 | dev_kfree_skb_any(skb); | ||
523 | } | ||
524 | |||
525 | static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw, | ||
526 | struct ieee80211_vif *vif, | ||
527 | struct ieee80211_key_conf *keyconf, | ||
528 | struct ieee80211_sta *sta, | ||
529 | u32 iv32, u16 *phase1key) | ||
530 | { | ||
531 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
532 | |||
533 | iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key); | ||
534 | } | ||
535 | |||
536 | static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | ||
537 | struct ieee80211_vif *vif, | ||
538 | struct ieee80211_sta *sta, | ||
539 | struct ieee80211_key_conf *key) | ||
540 | { | ||
541 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
542 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
543 | struct iwl_rxon_context *ctx = vif_priv->ctx; | ||
544 | int ret; | ||
545 | bool is_default_wep_key = false; | ||
546 | |||
547 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
548 | |||
549 | if (iwlwifi_mod_params.sw_crypto) { | ||
550 | IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n"); | ||
551 | return -EOPNOTSUPP; | ||
552 | } | ||
553 | |||
554 | switch (key->cipher) { | ||
555 | case WLAN_CIPHER_SUITE_TKIP: | ||
556 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | ||
557 | /* fall through */ | ||
558 | case WLAN_CIPHER_SUITE_CCMP: | ||
559 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | ||
560 | break; | ||
561 | default: | ||
562 | break; | ||
563 | } | ||
564 | |||
565 | /* | ||
566 | * We could program these keys into the hardware as well, but we | ||
567 | * don't expect much multicast traffic in IBSS and having keys | ||
568 | * for more stations is probably more useful. | ||
569 | * | ||
570 | * Mark key TX-only and return 0. | ||
571 | */ | ||
572 | if (vif->type == NL80211_IFTYPE_ADHOC && | ||
573 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { | ||
574 | key->hw_key_idx = WEP_INVALID_OFFSET; | ||
575 | return 0; | ||
576 | } | ||
577 | |||
578 | /* If they key was TX-only, accept deletion */ | ||
579 | if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET) | ||
580 | return 0; | ||
581 | |||
582 | mutex_lock(&priv->mutex); | ||
583 | iwl_scan_cancel_timeout(priv, 100); | ||
584 | |||
585 | BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT); | ||
586 | |||
587 | /* | ||
588 | * If we are getting WEP group key and we didn't receive any key mapping | ||
589 | * so far, we are in legacy wep mode (group key only), otherwise we are | ||
590 | * in 1X mode. | ||
591 | * In legacy wep mode, we use another host command to the uCode. | ||
592 | */ | ||
593 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || | ||
594 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) { | ||
595 | if (cmd == SET_KEY) | ||
596 | is_default_wep_key = !ctx->key_mapping_keys; | ||
597 | else | ||
598 | is_default_wep_key = | ||
599 | key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT; | ||
600 | } | ||
601 | |||
602 | |||
603 | switch (cmd) { | ||
604 | case SET_KEY: | ||
605 | if (is_default_wep_key) { | ||
606 | ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key); | ||
607 | break; | ||
608 | } | ||
609 | ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta); | ||
610 | if (ret) { | ||
611 | /* | ||
612 | * can't add key for RX, but we don't need it | ||
613 | * in the device for TX so still return 0 | ||
614 | */ | ||
615 | ret = 0; | ||
616 | key->hw_key_idx = WEP_INVALID_OFFSET; | ||
617 | } | ||
618 | |||
619 | IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n"); | ||
620 | break; | ||
621 | case DISABLE_KEY: | ||
622 | if (is_default_wep_key) | ||
623 | ret = iwl_remove_default_wep_key(priv, ctx, key); | ||
624 | else | ||
625 | ret = iwl_remove_dynamic_key(priv, ctx, key, sta); | ||
626 | |||
627 | IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n"); | ||
628 | break; | ||
629 | default: | ||
630 | ret = -EINVAL; | ||
631 | } | ||
632 | |||
633 | mutex_unlock(&priv->mutex); | ||
634 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
635 | |||
636 | return ret; | ||
637 | } | ||
638 | |||
639 | static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw, | ||
640 | struct ieee80211_vif *vif, | ||
641 | enum ieee80211_ampdu_mlme_action action, | ||
642 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, | ||
643 | u8 buf_size) | ||
644 | { | ||
645 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
646 | int ret = -EINVAL; | ||
647 | struct iwl_station_priv *sta_priv = (void *) sta->drv_priv; | ||
648 | |||
649 | IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n", | ||
650 | sta->addr, tid); | ||
651 | |||
652 | if (!(priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)) | ||
653 | return -EACCES; | ||
654 | |||
655 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
656 | mutex_lock(&priv->mutex); | ||
657 | |||
658 | switch (action) { | ||
659 | case IEEE80211_AMPDU_RX_START: | ||
660 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) | ||
661 | break; | ||
662 | IWL_DEBUG_HT(priv, "start Rx\n"); | ||
663 | ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn); | ||
664 | break; | ||
665 | case IEEE80211_AMPDU_RX_STOP: | ||
666 | IWL_DEBUG_HT(priv, "stop Rx\n"); | ||
667 | ret = iwl_sta_rx_agg_stop(priv, sta, tid); | ||
668 | break; | ||
669 | case IEEE80211_AMPDU_TX_START: | ||
670 | if (!priv->trans->ops->txq_enable) | ||
671 | break; | ||
672 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) | ||
673 | break; | ||
674 | IWL_DEBUG_HT(priv, "start Tx\n"); | ||
675 | ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn); | ||
676 | break; | ||
677 | case IEEE80211_AMPDU_TX_STOP: | ||
678 | IWL_DEBUG_HT(priv, "stop Tx\n"); | ||
679 | ret = iwlagn_tx_agg_stop(priv, vif, sta, tid); | ||
680 | if ((ret == 0) && (priv->agg_tids_count > 0)) { | ||
681 | priv->agg_tids_count--; | ||
682 | IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n", | ||
683 | priv->agg_tids_count); | ||
684 | } | ||
685 | if (!priv->agg_tids_count && | ||
686 | priv->hw_params.use_rts_for_aggregation) { | ||
687 | /* | ||
688 | * switch off RTS/CTS if it was previously enabled | ||
689 | */ | ||
690 | sta_priv->lq_sta.lq.general_params.flags &= | ||
691 | ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; | ||
692 | iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif), | ||
693 | &sta_priv->lq_sta.lq, CMD_ASYNC, false); | ||
694 | } | ||
695 | break; | ||
696 | case IEEE80211_AMPDU_TX_OPERATIONAL: | ||
697 | ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size); | ||
698 | break; | ||
699 | } | ||
700 | mutex_unlock(&priv->mutex); | ||
701 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
702 | return ret; | ||
703 | } | ||
704 | |||
705 | static int iwlagn_mac_sta_add(struct ieee80211_hw *hw, | ||
706 | struct ieee80211_vif *vif, | ||
707 | struct ieee80211_sta *sta) | ||
708 | { | ||
709 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
710 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
711 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
712 | bool is_ap = vif->type == NL80211_IFTYPE_STATION; | ||
713 | int ret; | ||
714 | u8 sta_id; | ||
715 | |||
716 | IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n", | ||
717 | sta->addr); | ||
718 | sta_priv->sta_id = IWL_INVALID_STATION; | ||
719 | |||
720 | atomic_set(&sta_priv->pending_frames, 0); | ||
721 | if (vif->type == NL80211_IFTYPE_AP) | ||
722 | sta_priv->client = true; | ||
723 | |||
724 | ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr, | ||
725 | is_ap, sta, &sta_id); | ||
726 | if (ret) { | ||
727 | IWL_ERR(priv, "Unable to add station %pM (%d)\n", | ||
728 | sta->addr, ret); | ||
729 | /* Should we return success if return code is EEXIST ? */ | ||
730 | return ret; | ||
731 | } | ||
732 | |||
733 | sta_priv->sta_id = sta_id; | ||
734 | |||
735 | return 0; | ||
736 | } | ||
737 | |||
738 | static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw, | ||
739 | struct ieee80211_vif *vif, | ||
740 | struct ieee80211_sta *sta) | ||
741 | { | ||
742 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
743 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
744 | int ret; | ||
745 | |||
746 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr); | ||
747 | |||
748 | if (vif->type == NL80211_IFTYPE_STATION) { | ||
749 | /* | ||
750 | * Station will be removed from device when the RXON | ||
751 | * is set to unassociated -- just deactivate it here | ||
752 | * to avoid re-programming it. | ||
753 | */ | ||
754 | ret = 0; | ||
755 | iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr); | ||
756 | } else { | ||
757 | ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr); | ||
758 | if (ret) | ||
759 | IWL_DEBUG_QUIET_RFKILL(priv, | ||
760 | "Error removing station %pM\n", sta->addr); | ||
761 | } | ||
762 | return ret; | ||
763 | } | ||
764 | |||
765 | static int iwlagn_mac_sta_state(struct ieee80211_hw *hw, | ||
766 | struct ieee80211_vif *vif, | ||
767 | struct ieee80211_sta *sta, | ||
768 | enum ieee80211_sta_state old_state, | ||
769 | enum ieee80211_sta_state new_state) | ||
770 | { | ||
771 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
772 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
773 | enum { | ||
774 | NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT, | ||
775 | } op = NONE; | ||
776 | int ret; | ||
777 | |||
778 | IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n", | ||
779 | sta->addr, old_state, new_state); | ||
780 | |||
781 | mutex_lock(&priv->mutex); | ||
782 | if (vif->type == NL80211_IFTYPE_STATION) { | ||
783 | if (old_state == IEEE80211_STA_NOTEXIST && | ||
784 | new_state == IEEE80211_STA_NONE) | ||
785 | op = ADD; | ||
786 | else if (old_state == IEEE80211_STA_NONE && | ||
787 | new_state == IEEE80211_STA_NOTEXIST) | ||
788 | op = REMOVE; | ||
789 | else if (old_state == IEEE80211_STA_AUTH && | ||
790 | new_state == IEEE80211_STA_ASSOC) | ||
791 | op = HT_RATE_INIT; | ||
792 | } else { | ||
793 | if (old_state == IEEE80211_STA_AUTH && | ||
794 | new_state == IEEE80211_STA_ASSOC) | ||
795 | op = ADD_RATE_INIT; | ||
796 | else if (old_state == IEEE80211_STA_ASSOC && | ||
797 | new_state == IEEE80211_STA_AUTH) | ||
798 | op = REMOVE; | ||
799 | } | ||
800 | |||
801 | switch (op) { | ||
802 | case ADD: | ||
803 | ret = iwlagn_mac_sta_add(hw, vif, sta); | ||
804 | break; | ||
805 | case REMOVE: | ||
806 | ret = iwlagn_mac_sta_remove(hw, vif, sta); | ||
807 | break; | ||
808 | case ADD_RATE_INIT: | ||
809 | ret = iwlagn_mac_sta_add(hw, vif, sta); | ||
810 | if (ret) | ||
811 | break; | ||
812 | /* Initialize rate scaling */ | ||
813 | IWL_DEBUG_INFO(priv, | ||
814 | "Initializing rate scaling for station %pM\n", | ||
815 | sta->addr); | ||
816 | iwl_rs_rate_init(priv, sta, iwl_sta_id(sta)); | ||
817 | ret = 0; | ||
818 | break; | ||
819 | case HT_RATE_INIT: | ||
820 | /* Initialize rate scaling */ | ||
821 | ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta); | ||
822 | if (ret) | ||
823 | break; | ||
824 | IWL_DEBUG_INFO(priv, | ||
825 | "Initializing rate scaling for station %pM\n", | ||
826 | sta->addr); | ||
827 | iwl_rs_rate_init(priv, sta, iwl_sta_id(sta)); | ||
828 | ret = 0; | ||
829 | break; | ||
830 | default: | ||
831 | ret = 0; | ||
832 | break; | ||
833 | } | ||
834 | |||
835 | /* | ||
836 | * mac80211 might WARN if we fail, but due the way we | ||
837 | * (badly) handle hard rfkill, we might fail here | ||
838 | */ | ||
839 | if (iwl_is_rfkill(priv)) | ||
840 | ret = 0; | ||
841 | |||
842 | mutex_unlock(&priv->mutex); | ||
843 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
844 | |||
845 | return ret; | ||
846 | } | ||
847 | |||
848 | static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw, | ||
849 | struct ieee80211_channel_switch *ch_switch) | ||
850 | { | ||
851 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
852 | struct ieee80211_conf *conf = &hw->conf; | ||
853 | struct ieee80211_channel *channel = ch_switch->channel; | ||
854 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; | ||
855 | /* | ||
856 | * MULTI-FIXME | ||
857 | * When we add support for multiple interfaces, we need to | ||
858 | * revisit this. The channel switch command in the device | ||
859 | * only affects the BSS context, but what does that really | ||
860 | * mean? And what if we get a CSA on the second interface? | ||
861 | * This needs a lot of work. | ||
862 | */ | ||
863 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
864 | u16 ch; | ||
865 | |||
866 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
867 | |||
868 | mutex_lock(&priv->mutex); | ||
869 | |||
870 | if (iwl_is_rfkill(priv)) | ||
871 | goto out; | ||
872 | |||
873 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || | ||
874 | test_bit(STATUS_SCANNING, &priv->status) || | ||
875 | test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) | ||
876 | goto out; | ||
877 | |||
878 | if (!iwl_is_associated_ctx(ctx)) | ||
879 | goto out; | ||
880 | |||
881 | if (!priv->lib->set_channel_switch) | ||
882 | goto out; | ||
883 | |||
884 | ch = channel->hw_value; | ||
885 | if (le16_to_cpu(ctx->active.channel) == ch) | ||
886 | goto out; | ||
887 | |||
888 | priv->current_ht_config.smps = conf->smps_mode; | ||
889 | |||
890 | /* Configure HT40 channels */ | ||
891 | ctx->ht.enabled = conf_is_ht(conf); | ||
892 | if (ctx->ht.enabled) | ||
893 | iwlagn_config_ht40(conf, ctx); | ||
894 | else | ||
895 | ctx->ht.is_40mhz = false; | ||
896 | |||
897 | if ((le16_to_cpu(ctx->staging.channel) != ch)) | ||
898 | ctx->staging.flags = 0; | ||
899 | |||
900 | iwl_set_rxon_channel(priv, channel, ctx); | ||
901 | iwl_set_rxon_ht(priv, ht_conf); | ||
902 | iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif); | ||
903 | |||
904 | /* | ||
905 | * at this point, staging_rxon has the | ||
906 | * configuration for channel switch | ||
907 | */ | ||
908 | set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status); | ||
909 | priv->switch_channel = cpu_to_le16(ch); | ||
910 | if (priv->lib->set_channel_switch(priv, ch_switch)) { | ||
911 | clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status); | ||
912 | priv->switch_channel = 0; | ||
913 | ieee80211_chswitch_done(ctx->vif, false); | ||
914 | } | ||
915 | |||
916 | out: | ||
917 | mutex_unlock(&priv->mutex); | ||
918 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
919 | } | ||
920 | |||
921 | void iwl_chswitch_done(struct iwl_priv *priv, bool is_success) | ||
922 | { | ||
923 | /* | ||
924 | * MULTI-FIXME | ||
925 | * See iwlagn_mac_channel_switch. | ||
926 | */ | ||
927 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
928 | |||
929 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
930 | return; | ||
931 | |||
932 | if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) | ||
933 | ieee80211_chswitch_done(ctx->vif, is_success); | ||
934 | } | ||
935 | |||
936 | static void iwlagn_configure_filter(struct ieee80211_hw *hw, | ||
937 | unsigned int changed_flags, | ||
938 | unsigned int *total_flags, | ||
939 | u64 multicast) | ||
940 | { | ||
941 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
942 | __le32 filter_or = 0, filter_nand = 0; | ||
943 | struct iwl_rxon_context *ctx; | ||
944 | |||
945 | #define CHK(test, flag) do { \ | ||
946 | if (*total_flags & (test)) \ | ||
947 | filter_or |= (flag); \ | ||
948 | else \ | ||
949 | filter_nand |= (flag); \ | ||
950 | } while (0) | ||
951 | |||
952 | IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n", | ||
953 | changed_flags, *total_flags); | ||
954 | |||
955 | CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK); | ||
956 | /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */ | ||
957 | CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK); | ||
958 | CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK); | ||
959 | |||
960 | #undef CHK | ||
961 | |||
962 | mutex_lock(&priv->mutex); | ||
963 | |||
964 | for_each_context(priv, ctx) { | ||
965 | ctx->staging.filter_flags &= ~filter_nand; | ||
966 | ctx->staging.filter_flags |= filter_or; | ||
967 | |||
968 | /* | ||
969 | * Not committing directly because hardware can perform a scan, | ||
970 | * but we'll eventually commit the filter flags change anyway. | ||
971 | */ | ||
972 | } | ||
973 | |||
974 | mutex_unlock(&priv->mutex); | ||
975 | |||
976 | /* | ||
977 | * Receiving all multicast frames is always enabled by the | ||
978 | * default flags setup in iwl_connection_init_rx_config() | ||
979 | * since we currently do not support programming multicast | ||
980 | * filters into the device. | ||
981 | */ | ||
982 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | | ||
983 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; | ||
984 | } | ||
985 | |||
986 | static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop) | ||
987 | { | ||
988 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
989 | |||
990 | mutex_lock(&priv->mutex); | ||
991 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
992 | |||
993 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { | ||
994 | IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n"); | ||
995 | goto done; | ||
996 | } | ||
997 | if (iwl_is_rfkill(priv)) { | ||
998 | IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n"); | ||
999 | goto done; | ||
1000 | } | ||
1001 | |||
1002 | /* | ||
1003 | * mac80211 will not push any more frames for transmit | ||
1004 | * until the flush is completed | ||
1005 | */ | ||
1006 | if (drop) { | ||
1007 | IWL_DEBUG_MAC80211(priv, "send flush command\n"); | ||
1008 | if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) { | ||
1009 | IWL_ERR(priv, "flush request fail\n"); | ||
1010 | goto done; | ||
1011 | } | ||
1012 | } | ||
1013 | IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n"); | ||
1014 | iwl_trans_wait_tx_queue_empty(priv->trans); | ||
1015 | done: | ||
1016 | mutex_unlock(&priv->mutex); | ||
1017 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1018 | } | ||
1019 | |||
1020 | static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw, | ||
1021 | struct ieee80211_channel *channel, | ||
1022 | enum nl80211_channel_type channel_type, | ||
1023 | int duration) | ||
1024 | { | ||
1025 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1026 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN]; | ||
1027 | int err = 0; | ||
1028 | |||
1029 | if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) | ||
1030 | return -EOPNOTSUPP; | ||
1031 | |||
1032 | if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT))) | ||
1033 | return -EOPNOTSUPP; | ||
1034 | |||
1035 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1036 | mutex_lock(&priv->mutex); | ||
1037 | |||
1038 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { | ||
1039 | err = -EBUSY; | ||
1040 | goto out; | ||
1041 | } | ||
1042 | |||
1043 | priv->hw_roc_channel = channel; | ||
1044 | priv->hw_roc_chantype = channel_type; | ||
1045 | /* convert from ms to TU */ | ||
1046 | priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024); | ||
1047 | priv->hw_roc_start_notified = false; | ||
1048 | cancel_delayed_work(&priv->hw_roc_disable_work); | ||
1049 | |||
1050 | if (!ctx->is_active) { | ||
1051 | static const struct iwl_qos_info default_qos_data = { | ||
1052 | .def_qos_parm = { | ||
1053 | .ac[0] = { | ||
1054 | .cw_min = cpu_to_le16(3), | ||
1055 | .cw_max = cpu_to_le16(7), | ||
1056 | .aifsn = 2, | ||
1057 | .edca_txop = cpu_to_le16(1504), | ||
1058 | }, | ||
1059 | .ac[1] = { | ||
1060 | .cw_min = cpu_to_le16(7), | ||
1061 | .cw_max = cpu_to_le16(15), | ||
1062 | .aifsn = 2, | ||
1063 | .edca_txop = cpu_to_le16(3008), | ||
1064 | }, | ||
1065 | .ac[2] = { | ||
1066 | .cw_min = cpu_to_le16(15), | ||
1067 | .cw_max = cpu_to_le16(1023), | ||
1068 | .aifsn = 3, | ||
1069 | }, | ||
1070 | .ac[3] = { | ||
1071 | .cw_min = cpu_to_le16(15), | ||
1072 | .cw_max = cpu_to_le16(1023), | ||
1073 | .aifsn = 7, | ||
1074 | }, | ||
1075 | }, | ||
1076 | }; | ||
1077 | |||
1078 | ctx->is_active = true; | ||
1079 | ctx->qos_data = default_qos_data; | ||
1080 | ctx->staging.dev_type = RXON_DEV_TYPE_P2P; | ||
1081 | memcpy(ctx->staging.node_addr, | ||
1082 | priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr, | ||
1083 | ETH_ALEN); | ||
1084 | memcpy(ctx->staging.bssid_addr, | ||
1085 | priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr, | ||
1086 | ETH_ALEN); | ||
1087 | err = iwlagn_commit_rxon(priv, ctx); | ||
1088 | if (err) | ||
1089 | goto out; | ||
1090 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK | | ||
1091 | RXON_FILTER_PROMISC_MSK | | ||
1092 | RXON_FILTER_CTL2HOST_MSK; | ||
1093 | |||
1094 | err = iwlagn_commit_rxon(priv, ctx); | ||
1095 | if (err) { | ||
1096 | iwlagn_disable_roc(priv); | ||
1097 | goto out; | ||
1098 | } | ||
1099 | priv->hw_roc_setup = true; | ||
1100 | } | ||
1101 | |||
1102 | err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band); | ||
1103 | if (err) | ||
1104 | iwlagn_disable_roc(priv); | ||
1105 | |||
1106 | out: | ||
1107 | mutex_unlock(&priv->mutex); | ||
1108 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1109 | |||
1110 | return err; | ||
1111 | } | ||
1112 | |||
1113 | static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw) | ||
1114 | { | ||
1115 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1116 | |||
1117 | if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) | ||
1118 | return -EOPNOTSUPP; | ||
1119 | |||
1120 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1121 | mutex_lock(&priv->mutex); | ||
1122 | iwl_scan_cancel_timeout(priv, priv->hw_roc_duration); | ||
1123 | iwlagn_disable_roc(priv); | ||
1124 | mutex_unlock(&priv->mutex); | ||
1125 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1126 | |||
1127 | return 0; | ||
1128 | } | ||
1129 | |||
1130 | static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw, | ||
1131 | enum ieee80211_rssi_event rssi_event) | ||
1132 | { | ||
1133 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1134 | |||
1135 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1136 | mutex_lock(&priv->mutex); | ||
1137 | |||
1138 | if (priv->cfg->bt_params && | ||
1139 | priv->cfg->bt_params->advanced_bt_coexist) { | ||
1140 | if (rssi_event == RSSI_EVENT_LOW) | ||
1141 | priv->bt_enable_pspoll = true; | ||
1142 | else if (rssi_event == RSSI_EVENT_HIGH) | ||
1143 | priv->bt_enable_pspoll = false; | ||
1144 | |||
1145 | iwlagn_send_advance_bt_config(priv); | ||
1146 | } else { | ||
1147 | IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled," | ||
1148 | "ignoring RSSI callback\n"); | ||
1149 | } | ||
1150 | |||
1151 | mutex_unlock(&priv->mutex); | ||
1152 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1153 | } | ||
1154 | |||
1155 | static int iwlagn_mac_set_tim(struct ieee80211_hw *hw, | ||
1156 | struct ieee80211_sta *sta, bool set) | ||
1157 | { | ||
1158 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1159 | |||
1160 | queue_work(priv->workqueue, &priv->beacon_update); | ||
1161 | |||
1162 | return 0; | ||
1163 | } | ||
1164 | |||
1165 | static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw, | ||
1166 | struct ieee80211_vif *vif, u16 queue, | ||
1167 | const struct ieee80211_tx_queue_params *params) | ||
1168 | { | ||
1169 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1170 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
1171 | struct iwl_rxon_context *ctx = vif_priv->ctx; | ||
1172 | int q; | ||
1173 | |||
1174 | if (WARN_ON(!ctx)) | ||
1175 | return -EINVAL; | ||
1176 | |||
1177 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1178 | |||
1179 | if (!iwl_is_ready_rf(priv)) { | ||
1180 | IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); | ||
1181 | return -EIO; | ||
1182 | } | ||
1183 | |||
1184 | if (queue >= AC_NUM) { | ||
1185 | IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue); | ||
1186 | return 0; | ||
1187 | } | ||
1188 | |||
1189 | q = AC_NUM - 1 - queue; | ||
1190 | |||
1191 | mutex_lock(&priv->mutex); | ||
1192 | |||
1193 | ctx->qos_data.def_qos_parm.ac[q].cw_min = | ||
1194 | cpu_to_le16(params->cw_min); | ||
1195 | ctx->qos_data.def_qos_parm.ac[q].cw_max = | ||
1196 | cpu_to_le16(params->cw_max); | ||
1197 | ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; | ||
1198 | ctx->qos_data.def_qos_parm.ac[q].edca_txop = | ||
1199 | cpu_to_le16((params->txop * 32)); | ||
1200 | |||
1201 | ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0; | ||
1202 | |||
1203 | mutex_unlock(&priv->mutex); | ||
1204 | |||
1205 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1206 | return 0; | ||
1207 | } | ||
1208 | |||
1209 | static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw) | ||
1210 | { | ||
1211 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1212 | |||
1213 | return priv->ibss_manager == IWL_IBSS_MANAGER; | ||
1214 | } | ||
1215 | |||
1216 | static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
1217 | { | ||
1218 | iwl_connection_init_rx_config(priv, ctx); | ||
1219 | |||
1220 | iwlagn_set_rxon_chain(priv, ctx); | ||
1221 | |||
1222 | return iwlagn_commit_rxon(priv, ctx); | ||
1223 | } | ||
1224 | |||
1225 | static int iwl_setup_interface(struct iwl_priv *priv, | ||
1226 | struct iwl_rxon_context *ctx) | ||
1227 | { | ||
1228 | struct ieee80211_vif *vif = ctx->vif; | ||
1229 | int err, ac; | ||
1230 | |||
1231 | lockdep_assert_held(&priv->mutex); | ||
1232 | |||
1233 | /* | ||
1234 | * This variable will be correct only when there's just | ||
1235 | * a single context, but all code using it is for hardware | ||
1236 | * that supports only one context. | ||
1237 | */ | ||
1238 | priv->iw_mode = vif->type; | ||
1239 | |||
1240 | ctx->is_active = true; | ||
1241 | |||
1242 | err = iwl_set_mode(priv, ctx); | ||
1243 | if (err) { | ||
1244 | if (!ctx->always_active) | ||
1245 | ctx->is_active = false; | ||
1246 | return err; | ||
1247 | } | ||
1248 | |||
1249 | if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist && | ||
1250 | vif->type == NL80211_IFTYPE_ADHOC) { | ||
1251 | /* | ||
1252 | * pretend to have high BT traffic as long as we | ||
1253 | * are operating in IBSS mode, as this will cause | ||
1254 | * the rate scaling etc. to behave as intended. | ||
1255 | */ | ||
1256 | priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH; | ||
1257 | } | ||
1258 | |||
1259 | /* set up queue mappings */ | ||
1260 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) | ||
1261 | vif->hw_queue[ac] = ctx->ac_to_queue[ac]; | ||
1262 | |||
1263 | if (vif->type == NL80211_IFTYPE_AP) | ||
1264 | vif->cab_queue = ctx->mcast_queue; | ||
1265 | else | ||
1266 | vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; | ||
1267 | |||
1268 | return 0; | ||
1269 | } | ||
1270 | |||
1271 | static int iwlagn_mac_add_interface(struct ieee80211_hw *hw, | ||
1272 | struct ieee80211_vif *vif) | ||
1273 | { | ||
1274 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1275 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
1276 | struct iwl_rxon_context *tmp, *ctx = NULL; | ||
1277 | int err; | ||
1278 | enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif); | ||
1279 | bool reset = false; | ||
1280 | |||
1281 | IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n", | ||
1282 | viftype, vif->addr); | ||
1283 | |||
1284 | cancel_delayed_work_sync(&priv->hw_roc_disable_work); | ||
1285 | |||
1286 | mutex_lock(&priv->mutex); | ||
1287 | |||
1288 | iwlagn_disable_roc(priv); | ||
1289 | |||
1290 | if (!iwl_is_ready_rf(priv)) { | ||
1291 | IWL_WARN(priv, "Try to add interface when device not ready\n"); | ||
1292 | err = -EINVAL; | ||
1293 | goto out; | ||
1294 | } | ||
1295 | |||
1296 | for_each_context(priv, tmp) { | ||
1297 | u32 possible_modes = | ||
1298 | tmp->interface_modes | tmp->exclusive_interface_modes; | ||
1299 | |||
1300 | if (tmp->vif) { | ||
1301 | /* On reset we need to add the same interface again */ | ||
1302 | if (tmp->vif == vif) { | ||
1303 | reset = true; | ||
1304 | ctx = tmp; | ||
1305 | break; | ||
1306 | } | ||
1307 | |||
1308 | /* check if this busy context is exclusive */ | ||
1309 | if (tmp->exclusive_interface_modes & | ||
1310 | BIT(tmp->vif->type)) { | ||
1311 | err = -EINVAL; | ||
1312 | goto out; | ||
1313 | } | ||
1314 | continue; | ||
1315 | } | ||
1316 | |||
1317 | if (!(possible_modes & BIT(viftype))) | ||
1318 | continue; | ||
1319 | |||
1320 | /* have maybe usable context w/o interface */ | ||
1321 | ctx = tmp; | ||
1322 | break; | ||
1323 | } | ||
1324 | |||
1325 | if (!ctx) { | ||
1326 | err = -EOPNOTSUPP; | ||
1327 | goto out; | ||
1328 | } | ||
1329 | |||
1330 | vif_priv->ctx = ctx; | ||
1331 | ctx->vif = vif; | ||
1332 | |||
1333 | err = iwl_setup_interface(priv, ctx); | ||
1334 | if (!err || reset) | ||
1335 | goto out; | ||
1336 | |||
1337 | ctx->vif = NULL; | ||
1338 | priv->iw_mode = NL80211_IFTYPE_STATION; | ||
1339 | out: | ||
1340 | mutex_unlock(&priv->mutex); | ||
1341 | |||
1342 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1343 | return err; | ||
1344 | } | ||
1345 | |||
1346 | static void iwl_teardown_interface(struct iwl_priv *priv, | ||
1347 | struct ieee80211_vif *vif, | ||
1348 | bool mode_change) | ||
1349 | { | ||
1350 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | ||
1351 | |||
1352 | lockdep_assert_held(&priv->mutex); | ||
1353 | |||
1354 | if (priv->scan_vif == vif) { | ||
1355 | iwl_scan_cancel_timeout(priv, 200); | ||
1356 | iwl_force_scan_end(priv); | ||
1357 | } | ||
1358 | |||
1359 | if (!mode_change) { | ||
1360 | iwl_set_mode(priv, ctx); | ||
1361 | if (!ctx->always_active) | ||
1362 | ctx->is_active = false; | ||
1363 | } | ||
1364 | |||
1365 | /* | ||
1366 | * When removing the IBSS interface, overwrite the | ||
1367 | * BT traffic load with the stored one from the last | ||
1368 | * notification, if any. If this is a device that | ||
1369 | * doesn't implement this, this has no effect since | ||
1370 | * both values are the same and zero. | ||
1371 | */ | ||
1372 | if (vif->type == NL80211_IFTYPE_ADHOC) | ||
1373 | priv->bt_traffic_load = priv->last_bt_traffic_load; | ||
1374 | } | ||
1375 | |||
1376 | static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw, | ||
1377 | struct ieee80211_vif *vif) | ||
1378 | { | ||
1379 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1380 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | ||
1381 | |||
1382 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1383 | |||
1384 | mutex_lock(&priv->mutex); | ||
1385 | |||
1386 | if (WARN_ON(ctx->vif != vif)) { | ||
1387 | struct iwl_rxon_context *tmp; | ||
1388 | IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif); | ||
1389 | for_each_context(priv, tmp) | ||
1390 | IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n", | ||
1391 | tmp->ctxid, tmp, tmp->vif); | ||
1392 | } | ||
1393 | ctx->vif = NULL; | ||
1394 | |||
1395 | iwl_teardown_interface(priv, vif, false); | ||
1396 | |||
1397 | mutex_unlock(&priv->mutex); | ||
1398 | |||
1399 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1400 | |||
1401 | } | ||
1402 | |||
1403 | static int iwlagn_mac_change_interface(struct ieee80211_hw *hw, | ||
1404 | struct ieee80211_vif *vif, | ||
1405 | enum nl80211_iftype newtype, bool newp2p) | ||
1406 | { | ||
1407 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1408 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | ||
1409 | struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
1410 | struct iwl_rxon_context *tmp; | ||
1411 | enum nl80211_iftype newviftype = newtype; | ||
1412 | u32 interface_modes; | ||
1413 | int err; | ||
1414 | |||
1415 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1416 | |||
1417 | newtype = ieee80211_iftype_p2p(newtype, newp2p); | ||
1418 | |||
1419 | mutex_lock(&priv->mutex); | ||
1420 | |||
1421 | if (!ctx->vif || !iwl_is_ready_rf(priv)) { | ||
1422 | /* | ||
1423 | * Huh? But wait ... this can maybe happen when | ||
1424 | * we're in the middle of a firmware restart! | ||
1425 | */ | ||
1426 | err = -EBUSY; | ||
1427 | goto out; | ||
1428 | } | ||
1429 | |||
1430 | interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes; | ||
1431 | |||
1432 | if (!(interface_modes & BIT(newtype))) { | ||
1433 | err = -EBUSY; | ||
1434 | goto out; | ||
1435 | } | ||
1436 | |||
1437 | /* | ||
1438 | * Refuse a change that should be done by moving from the PAN | ||
1439 | * context to the BSS context instead, if the BSS context is | ||
1440 | * available and can support the new interface type. | ||
1441 | */ | ||
1442 | if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif && | ||
1443 | (bss_ctx->interface_modes & BIT(newtype) || | ||
1444 | bss_ctx->exclusive_interface_modes & BIT(newtype))) { | ||
1445 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | ||
1446 | err = -EBUSY; | ||
1447 | goto out; | ||
1448 | } | ||
1449 | |||
1450 | if (ctx->exclusive_interface_modes & BIT(newtype)) { | ||
1451 | for_each_context(priv, tmp) { | ||
1452 | if (ctx == tmp) | ||
1453 | continue; | ||
1454 | |||
1455 | if (!tmp->vif) | ||
1456 | continue; | ||
1457 | |||
1458 | /* | ||
1459 | * The current mode switch would be exclusive, but | ||
1460 | * another context is active ... refuse the switch. | ||
1461 | */ | ||
1462 | err = -EBUSY; | ||
1463 | goto out; | ||
1464 | } | ||
1465 | } | ||
1466 | |||
1467 | /* success */ | ||
1468 | iwl_teardown_interface(priv, vif, true); | ||
1469 | vif->type = newviftype; | ||
1470 | vif->p2p = newp2p; | ||
1471 | err = iwl_setup_interface(priv, ctx); | ||
1472 | WARN_ON(err); | ||
1473 | /* | ||
1474 | * We've switched internally, but submitting to the | ||
1475 | * device may have failed for some reason. Mask this | ||
1476 | * error, because otherwise mac80211 will not switch | ||
1477 | * (and set the interface type back) and we'll be | ||
1478 | * out of sync with it. | ||
1479 | */ | ||
1480 | err = 0; | ||
1481 | |||
1482 | out: | ||
1483 | mutex_unlock(&priv->mutex); | ||
1484 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1485 | |||
1486 | return err; | ||
1487 | } | ||
1488 | |||
1489 | static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw, | ||
1490 | struct ieee80211_vif *vif, | ||
1491 | struct cfg80211_scan_request *req) | ||
1492 | { | ||
1493 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1494 | int ret; | ||
1495 | |||
1496 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1497 | |||
1498 | if (req->n_channels == 0) | ||
1499 | return -EINVAL; | ||
1500 | |||
1501 | mutex_lock(&priv->mutex); | ||
1502 | |||
1503 | /* | ||
1504 | * If an internal scan is in progress, just set | ||
1505 | * up the scan_request as per above. | ||
1506 | */ | ||
1507 | if (priv->scan_type != IWL_SCAN_NORMAL) { | ||
1508 | IWL_DEBUG_SCAN(priv, | ||
1509 | "SCAN request during internal scan - defer\n"); | ||
1510 | priv->scan_request = req; | ||
1511 | priv->scan_vif = vif; | ||
1512 | ret = 0; | ||
1513 | } else { | ||
1514 | priv->scan_request = req; | ||
1515 | priv->scan_vif = vif; | ||
1516 | /* | ||
1517 | * mac80211 will only ask for one band at a time | ||
1518 | * so using channels[0] here is ok | ||
1519 | */ | ||
1520 | ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL, | ||
1521 | req->channels[0]->band); | ||
1522 | if (ret) { | ||
1523 | priv->scan_request = NULL; | ||
1524 | priv->scan_vif = NULL; | ||
1525 | } | ||
1526 | } | ||
1527 | |||
1528 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1529 | |||
1530 | mutex_unlock(&priv->mutex); | ||
1531 | |||
1532 | return ret; | ||
1533 | } | ||
1534 | |||
1535 | static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) | ||
1536 | { | ||
1537 | struct iwl_addsta_cmd cmd = { | ||
1538 | .mode = STA_CONTROL_MODIFY_MSK, | ||
1539 | .station_flags_msk = STA_FLG_PWR_SAVE_MSK, | ||
1540 | .sta.sta_id = sta_id, | ||
1541 | }; | ||
1542 | |||
1543 | iwl_send_add_sta(priv, &cmd, CMD_ASYNC); | ||
1544 | } | ||
1545 | |||
1546 | static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw, | ||
1547 | struct ieee80211_vif *vif, | ||
1548 | enum sta_notify_cmd cmd, | ||
1549 | struct ieee80211_sta *sta) | ||
1550 | { | ||
1551 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1552 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
1553 | int sta_id; | ||
1554 | |||
1555 | IWL_DEBUG_MAC80211(priv, "enter\n"); | ||
1556 | |||
1557 | switch (cmd) { | ||
1558 | case STA_NOTIFY_SLEEP: | ||
1559 | WARN_ON(!sta_priv->client); | ||
1560 | sta_priv->asleep = true; | ||
1561 | if (atomic_read(&sta_priv->pending_frames) > 0) | ||
1562 | ieee80211_sta_block_awake(hw, sta, true); | ||
1563 | break; | ||
1564 | case STA_NOTIFY_AWAKE: | ||
1565 | WARN_ON(!sta_priv->client); | ||
1566 | if (!sta_priv->asleep) | ||
1567 | break; | ||
1568 | sta_priv->asleep = false; | ||
1569 | sta_id = iwl_sta_id(sta); | ||
1570 | if (sta_id != IWL_INVALID_STATION) | ||
1571 | iwl_sta_modify_ps_wake(priv, sta_id); | ||
1572 | break; | ||
1573 | default: | ||
1574 | break; | ||
1575 | } | ||
1576 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1577 | } | ||
1578 | |||
1579 | struct ieee80211_ops iwlagn_hw_ops = { | ||
1580 | .tx = iwlagn_mac_tx, | ||
1581 | .start = iwlagn_mac_start, | ||
1582 | .stop = iwlagn_mac_stop, | ||
1583 | #ifdef CONFIG_PM_SLEEP | ||
1584 | .suspend = iwlagn_mac_suspend, | ||
1585 | .resume = iwlagn_mac_resume, | ||
1586 | .set_wakeup = iwlagn_mac_set_wakeup, | ||
1587 | #endif | ||
1588 | .add_interface = iwlagn_mac_add_interface, | ||
1589 | .remove_interface = iwlagn_mac_remove_interface, | ||
1590 | .change_interface = iwlagn_mac_change_interface, | ||
1591 | .config = iwlagn_mac_config, | ||
1592 | .configure_filter = iwlagn_configure_filter, | ||
1593 | .set_key = iwlagn_mac_set_key, | ||
1594 | .update_tkip_key = iwlagn_mac_update_tkip_key, | ||
1595 | .set_rekey_data = iwlagn_mac_set_rekey_data, | ||
1596 | .conf_tx = iwlagn_mac_conf_tx, | ||
1597 | .bss_info_changed = iwlagn_bss_info_changed, | ||
1598 | .ampdu_action = iwlagn_mac_ampdu_action, | ||
1599 | .hw_scan = iwlagn_mac_hw_scan, | ||
1600 | .sta_notify = iwlagn_mac_sta_notify, | ||
1601 | .sta_state = iwlagn_mac_sta_state, | ||
1602 | .channel_switch = iwlagn_mac_channel_switch, | ||
1603 | .flush = iwlagn_mac_flush, | ||
1604 | .tx_last_beacon = iwlagn_mac_tx_last_beacon, | ||
1605 | .remain_on_channel = iwlagn_mac_remain_on_channel, | ||
1606 | .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel, | ||
1607 | .rssi_callback = iwlagn_mac_rssi_callback, | ||
1608 | CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd) | ||
1609 | CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump) | ||
1610 | .set_tim = iwlagn_mac_set_tim, | ||
1611 | }; | ||
1612 | |||
1613 | /* This function both allocates and initializes hw and priv. */ | ||
1614 | struct ieee80211_hw *iwl_alloc_all(void) | ||
1615 | { | ||
1616 | struct iwl_priv *priv; | ||
1617 | struct iwl_op_mode *op_mode; | ||
1618 | /* mac80211 allocates memory for this device instance, including | ||
1619 | * space for this driver's private structure */ | ||
1620 | struct ieee80211_hw *hw; | ||
1621 | |||
1622 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) + | ||
1623 | sizeof(struct iwl_op_mode), &iwlagn_hw_ops); | ||
1624 | if (!hw) | ||
1625 | goto out; | ||
1626 | |||
1627 | op_mode = hw->priv; | ||
1628 | priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
1629 | priv->hw = hw; | ||
1630 | |||
1631 | out: | ||
1632 | return hw; | ||
1633 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c new file mode 100644 index 000000000000..1c2d0233a405 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/main.c | |||
@@ -0,0 +1,2215 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 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 | *****************************************************************************/ | ||
29 | |||
30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
31 | |||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/module.h> | ||
34 | #include <linux/init.h> | ||
35 | #include <linux/slab.h> | ||
36 | #include <linux/delay.h> | ||
37 | #include <linux/sched.h> | ||
38 | #include <linux/skbuff.h> | ||
39 | #include <linux/netdevice.h> | ||
40 | #include <linux/etherdevice.h> | ||
41 | #include <linux/if_arp.h> | ||
42 | |||
43 | #include <net/mac80211.h> | ||
44 | |||
45 | #include <asm/div64.h> | ||
46 | |||
47 | #include "iwl-eeprom-read.h" | ||
48 | #include "iwl-eeprom-parse.h" | ||
49 | #include "iwl-io.h" | ||
50 | #include "iwl-trans.h" | ||
51 | #include "iwl-op-mode.h" | ||
52 | #include "iwl-drv.h" | ||
53 | #include "iwl-modparams.h" | ||
54 | |||
55 | #include "dev.h" | ||
56 | #include "calib.h" | ||
57 | #include "agn.h" | ||
58 | |||
59 | /****************************************************************************** | ||
60 | * | ||
61 | * module boiler plate | ||
62 | * | ||
63 | ******************************************************************************/ | ||
64 | |||
65 | /* | ||
66 | * module name, copyright, version, etc. | ||
67 | */ | ||
68 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux" | ||
69 | |||
70 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
71 | #define VD "d" | ||
72 | #else | ||
73 | #define VD | ||
74 | #endif | ||
75 | |||
76 | #define DRV_VERSION IWLWIFI_VERSION VD | ||
77 | |||
78 | |||
79 | MODULE_DESCRIPTION(DRV_DESCRIPTION); | ||
80 | MODULE_VERSION(DRV_VERSION); | ||
81 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); | ||
82 | MODULE_LICENSE("GPL"); | ||
83 | |||
84 | static const struct iwl_op_mode_ops iwl_dvm_ops; | ||
85 | |||
86 | void iwl_update_chain_flags(struct iwl_priv *priv) | ||
87 | { | ||
88 | struct iwl_rxon_context *ctx; | ||
89 | |||
90 | for_each_context(priv, ctx) { | ||
91 | iwlagn_set_rxon_chain(priv, ctx); | ||
92 | if (ctx->active.rx_chain != ctx->staging.rx_chain) | ||
93 | iwlagn_commit_rxon(priv, ctx); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */ | ||
98 | static void iwl_set_beacon_tim(struct iwl_priv *priv, | ||
99 | struct iwl_tx_beacon_cmd *tx_beacon_cmd, | ||
100 | u8 *beacon, u32 frame_size) | ||
101 | { | ||
102 | u16 tim_idx; | ||
103 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon; | ||
104 | |||
105 | /* | ||
106 | * The index is relative to frame start but we start looking at the | ||
107 | * variable-length part of the beacon. | ||
108 | */ | ||
109 | tim_idx = mgmt->u.beacon.variable - beacon; | ||
110 | |||
111 | /* Parse variable-length elements of beacon to find WLAN_EID_TIM */ | ||
112 | while ((tim_idx < (frame_size - 2)) && | ||
113 | (beacon[tim_idx] != WLAN_EID_TIM)) | ||
114 | tim_idx += beacon[tim_idx+1] + 2; | ||
115 | |||
116 | /* If TIM field was found, set variables */ | ||
117 | if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) { | ||
118 | tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx); | ||
119 | tx_beacon_cmd->tim_size = beacon[tim_idx+1]; | ||
120 | } else | ||
121 | IWL_WARN(priv, "Unable to find TIM Element in beacon\n"); | ||
122 | } | ||
123 | |||
124 | int iwlagn_send_beacon_cmd(struct iwl_priv *priv) | ||
125 | { | ||
126 | struct iwl_tx_beacon_cmd *tx_beacon_cmd; | ||
127 | struct iwl_host_cmd cmd = { | ||
128 | .id = REPLY_TX_BEACON, | ||
129 | .flags = CMD_SYNC, | ||
130 | }; | ||
131 | struct ieee80211_tx_info *info; | ||
132 | u32 frame_size; | ||
133 | u32 rate_flags; | ||
134 | u32 rate; | ||
135 | |||
136 | /* | ||
137 | * We have to set up the TX command, the TX Beacon command, and the | ||
138 | * beacon contents. | ||
139 | */ | ||
140 | |||
141 | lockdep_assert_held(&priv->mutex); | ||
142 | |||
143 | if (!priv->beacon_ctx) { | ||
144 | IWL_ERR(priv, "trying to build beacon w/o beacon context!\n"); | ||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | if (WARN_ON(!priv->beacon_skb)) | ||
149 | return -EINVAL; | ||
150 | |||
151 | /* Allocate beacon command */ | ||
152 | if (!priv->beacon_cmd) | ||
153 | priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL); | ||
154 | tx_beacon_cmd = priv->beacon_cmd; | ||
155 | if (!tx_beacon_cmd) | ||
156 | return -ENOMEM; | ||
157 | |||
158 | frame_size = priv->beacon_skb->len; | ||
159 | |||
160 | /* Set up TX command fields */ | ||
161 | tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size); | ||
162 | tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id; | ||
163 | tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; | ||
164 | tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK | | ||
165 | TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK; | ||
166 | |||
167 | /* Set up TX beacon command fields */ | ||
168 | iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data, | ||
169 | frame_size); | ||
170 | |||
171 | /* Set up packet rate and flags */ | ||
172 | info = IEEE80211_SKB_CB(priv->beacon_skb); | ||
173 | |||
174 | /* | ||
175 | * Let's set up the rate at least somewhat correctly; | ||
176 | * it will currently not actually be used by the uCode, | ||
177 | * it uses the broadcast station's rate instead. | ||
178 | */ | ||
179 | if (info->control.rates[0].idx < 0 || | ||
180 | info->control.rates[0].flags & IEEE80211_TX_RC_MCS) | ||
181 | rate = 0; | ||
182 | else | ||
183 | rate = info->control.rates[0].idx; | ||
184 | |||
185 | priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, | ||
186 | priv->eeprom_data->valid_tx_ant); | ||
187 | rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant); | ||
188 | |||
189 | /* In mac80211, rates for 5 GHz start at 0 */ | ||
190 | if (info->band == IEEE80211_BAND_5GHZ) | ||
191 | rate += IWL_FIRST_OFDM_RATE; | ||
192 | else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE) | ||
193 | rate_flags |= RATE_MCS_CCK_MSK; | ||
194 | |||
195 | tx_beacon_cmd->tx.rate_n_flags = | ||
196 | iwl_hw_set_rate_n_flags(rate, rate_flags); | ||
197 | |||
198 | /* Submit command */ | ||
199 | cmd.len[0] = sizeof(*tx_beacon_cmd); | ||
200 | cmd.data[0] = tx_beacon_cmd; | ||
201 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; | ||
202 | cmd.len[1] = frame_size; | ||
203 | cmd.data[1] = priv->beacon_skb->data; | ||
204 | cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY; | ||
205 | |||
206 | return iwl_dvm_send_cmd(priv, &cmd); | ||
207 | } | ||
208 | |||
209 | static void iwl_bg_beacon_update(struct work_struct *work) | ||
210 | { | ||
211 | struct iwl_priv *priv = | ||
212 | container_of(work, struct iwl_priv, beacon_update); | ||
213 | struct sk_buff *beacon; | ||
214 | |||
215 | mutex_lock(&priv->mutex); | ||
216 | if (!priv->beacon_ctx) { | ||
217 | IWL_ERR(priv, "updating beacon w/o beacon context!\n"); | ||
218 | goto out; | ||
219 | } | ||
220 | |||
221 | if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) { | ||
222 | /* | ||
223 | * The ucode will send beacon notifications even in | ||
224 | * IBSS mode, but we don't want to process them. But | ||
225 | * we need to defer the type check to here due to | ||
226 | * requiring locking around the beacon_ctx access. | ||
227 | */ | ||
228 | goto out; | ||
229 | } | ||
230 | |||
231 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ | ||
232 | beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif); | ||
233 | if (!beacon) { | ||
234 | IWL_ERR(priv, "update beacon failed -- keeping old\n"); | ||
235 | goto out; | ||
236 | } | ||
237 | |||
238 | /* new beacon skb is allocated every time; dispose previous.*/ | ||
239 | dev_kfree_skb(priv->beacon_skb); | ||
240 | |||
241 | priv->beacon_skb = beacon; | ||
242 | |||
243 | iwlagn_send_beacon_cmd(priv); | ||
244 | out: | ||
245 | mutex_unlock(&priv->mutex); | ||
246 | } | ||
247 | |||
248 | static void iwl_bg_bt_runtime_config(struct work_struct *work) | ||
249 | { | ||
250 | struct iwl_priv *priv = | ||
251 | container_of(work, struct iwl_priv, bt_runtime_config); | ||
252 | |||
253 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
254 | return; | ||
255 | |||
256 | /* dont send host command if rf-kill is on */ | ||
257 | if (!iwl_is_ready_rf(priv)) | ||
258 | return; | ||
259 | iwlagn_send_advance_bt_config(priv); | ||
260 | } | ||
261 | |||
262 | static void iwl_bg_bt_full_concurrency(struct work_struct *work) | ||
263 | { | ||
264 | struct iwl_priv *priv = | ||
265 | container_of(work, struct iwl_priv, bt_full_concurrency); | ||
266 | struct iwl_rxon_context *ctx; | ||
267 | |||
268 | mutex_lock(&priv->mutex); | ||
269 | |||
270 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
271 | goto out; | ||
272 | |||
273 | /* dont send host command if rf-kill is on */ | ||
274 | if (!iwl_is_ready_rf(priv)) | ||
275 | goto out; | ||
276 | |||
277 | IWL_DEBUG_INFO(priv, "BT coex in %s mode\n", | ||
278 | priv->bt_full_concurrent ? | ||
279 | "full concurrency" : "3-wire"); | ||
280 | |||
281 | /* | ||
282 | * LQ & RXON updated cmds must be sent before BT Config cmd | ||
283 | * to avoid 3-wire collisions | ||
284 | */ | ||
285 | for_each_context(priv, ctx) { | ||
286 | iwlagn_set_rxon_chain(priv, ctx); | ||
287 | iwlagn_commit_rxon(priv, ctx); | ||
288 | } | ||
289 | |||
290 | iwlagn_send_advance_bt_config(priv); | ||
291 | out: | ||
292 | mutex_unlock(&priv->mutex); | ||
293 | } | ||
294 | |||
295 | int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear) | ||
296 | { | ||
297 | struct iwl_statistics_cmd statistics_cmd = { | ||
298 | .configuration_flags = | ||
299 | clear ? IWL_STATS_CONF_CLEAR_STATS : 0, | ||
300 | }; | ||
301 | |||
302 | if (flags & CMD_ASYNC) | ||
303 | return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, | ||
304 | CMD_ASYNC, | ||
305 | sizeof(struct iwl_statistics_cmd), | ||
306 | &statistics_cmd); | ||
307 | else | ||
308 | return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, | ||
309 | CMD_SYNC, | ||
310 | sizeof(struct iwl_statistics_cmd), | ||
311 | &statistics_cmd); | ||
312 | } | ||
313 | |||
314 | /** | ||
315 | * iwl_bg_statistics_periodic - Timer callback to queue statistics | ||
316 | * | ||
317 | * This callback is provided in order to send a statistics request. | ||
318 | * | ||
319 | * This timer function is continually reset to execute within | ||
320 | * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION | ||
321 | * was received. We need to ensure we receive the statistics in order | ||
322 | * to update the temperature used for calibrating the TXPOWER. | ||
323 | */ | ||
324 | static void iwl_bg_statistics_periodic(unsigned long data) | ||
325 | { | ||
326 | struct iwl_priv *priv = (struct iwl_priv *)data; | ||
327 | |||
328 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
329 | return; | ||
330 | |||
331 | /* dont send host command if rf-kill is on */ | ||
332 | if (!iwl_is_ready_rf(priv)) | ||
333 | return; | ||
334 | |||
335 | iwl_send_statistics_request(priv, CMD_ASYNC, false); | ||
336 | } | ||
337 | |||
338 | |||
339 | static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base, | ||
340 | u32 start_idx, u32 num_events, | ||
341 | u32 capacity, u32 mode) | ||
342 | { | ||
343 | u32 i; | ||
344 | u32 ptr; /* SRAM byte address of log data */ | ||
345 | u32 ev, time, data; /* event log data */ | ||
346 | unsigned long reg_flags; | ||
347 | |||
348 | if (mode == 0) | ||
349 | ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32)); | ||
350 | else | ||
351 | ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32)); | ||
352 | |||
353 | /* Make sure device is powered up for SRAM reads */ | ||
354 | spin_lock_irqsave(&priv->trans->reg_lock, reg_flags); | ||
355 | if (unlikely(!iwl_grab_nic_access(priv->trans))) { | ||
356 | spin_unlock_irqrestore(&priv->trans->reg_lock, reg_flags); | ||
357 | return; | ||
358 | } | ||
359 | |||
360 | /* Set starting address; reads will auto-increment */ | ||
361 | iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr); | ||
362 | |||
363 | /* | ||
364 | * Refuse to read more than would have fit into the log from | ||
365 | * the current start_idx. This used to happen due to the race | ||
366 | * described below, but now WARN because the code below should | ||
367 | * prevent it from happening here. | ||
368 | */ | ||
369 | if (WARN_ON(num_events > capacity - start_idx)) | ||
370 | num_events = capacity - start_idx; | ||
371 | |||
372 | /* | ||
373 | * "time" is actually "data" for mode 0 (no timestamp). | ||
374 | * place event id # at far right for easier visual parsing. | ||
375 | */ | ||
376 | for (i = 0; i < num_events; i++) { | ||
377 | ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); | ||
378 | time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); | ||
379 | if (mode == 0) { | ||
380 | trace_iwlwifi_dev_ucode_cont_event( | ||
381 | priv->trans->dev, 0, time, ev); | ||
382 | } else { | ||
383 | data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); | ||
384 | trace_iwlwifi_dev_ucode_cont_event( | ||
385 | priv->trans->dev, time, data, ev); | ||
386 | } | ||
387 | } | ||
388 | /* Allow device to power down */ | ||
389 | iwl_release_nic_access(priv->trans); | ||
390 | spin_unlock_irqrestore(&priv->trans->reg_lock, reg_flags); | ||
391 | } | ||
392 | |||
393 | static void iwl_continuous_event_trace(struct iwl_priv *priv) | ||
394 | { | ||
395 | u32 capacity; /* event log capacity in # entries */ | ||
396 | struct { | ||
397 | u32 capacity; | ||
398 | u32 mode; | ||
399 | u32 wrap_counter; | ||
400 | u32 write_counter; | ||
401 | } __packed read; | ||
402 | u32 base; /* SRAM byte address of event log header */ | ||
403 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ | ||
404 | u32 num_wraps; /* # times uCode wrapped to top of log */ | ||
405 | u32 next_entry; /* index of next entry to be written by uCode */ | ||
406 | |||
407 | base = priv->device_pointers.log_event_table; | ||
408 | if (iwlagn_hw_valid_rtc_data_addr(base)) { | ||
409 | iwl_read_targ_mem_words(priv->trans, base, &read, sizeof(read)); | ||
410 | capacity = read.capacity; | ||
411 | mode = read.mode; | ||
412 | num_wraps = read.wrap_counter; | ||
413 | next_entry = read.write_counter; | ||
414 | } else | ||
415 | return; | ||
416 | |||
417 | /* | ||
418 | * Unfortunately, the uCode doesn't use temporary variables. | ||
419 | * Therefore, it can happen that we read next_entry == capacity, | ||
420 | * which really means next_entry == 0. | ||
421 | */ | ||
422 | if (unlikely(next_entry == capacity)) | ||
423 | next_entry = 0; | ||
424 | /* | ||
425 | * Additionally, the uCode increases the write pointer before | ||
426 | * the wraps counter, so if the write pointer is smaller than | ||
427 | * the old write pointer (wrap occurred) but we read that no | ||
428 | * wrap occurred, we actually read between the next_entry and | ||
429 | * num_wraps update (this does happen in practice!!) -- take | ||
430 | * that into account by increasing num_wraps. | ||
431 | */ | ||
432 | if (unlikely(next_entry < priv->event_log.next_entry && | ||
433 | num_wraps == priv->event_log.num_wraps)) | ||
434 | num_wraps++; | ||
435 | |||
436 | if (num_wraps == priv->event_log.num_wraps) { | ||
437 | iwl_print_cont_event_trace( | ||
438 | priv, base, priv->event_log.next_entry, | ||
439 | next_entry - priv->event_log.next_entry, | ||
440 | capacity, mode); | ||
441 | |||
442 | priv->event_log.non_wraps_count++; | ||
443 | } else { | ||
444 | if (num_wraps - priv->event_log.num_wraps > 1) | ||
445 | priv->event_log.wraps_more_count++; | ||
446 | else | ||
447 | priv->event_log.wraps_once_count++; | ||
448 | |||
449 | trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev, | ||
450 | num_wraps - priv->event_log.num_wraps, | ||
451 | next_entry, priv->event_log.next_entry); | ||
452 | |||
453 | if (next_entry < priv->event_log.next_entry) { | ||
454 | iwl_print_cont_event_trace( | ||
455 | priv, base, priv->event_log.next_entry, | ||
456 | capacity - priv->event_log.next_entry, | ||
457 | capacity, mode); | ||
458 | |||
459 | iwl_print_cont_event_trace( | ||
460 | priv, base, 0, next_entry, capacity, mode); | ||
461 | } else { | ||
462 | iwl_print_cont_event_trace( | ||
463 | priv, base, next_entry, | ||
464 | capacity - next_entry, | ||
465 | capacity, mode); | ||
466 | |||
467 | iwl_print_cont_event_trace( | ||
468 | priv, base, 0, next_entry, capacity, mode); | ||
469 | } | ||
470 | } | ||
471 | |||
472 | priv->event_log.num_wraps = num_wraps; | ||
473 | priv->event_log.next_entry = next_entry; | ||
474 | } | ||
475 | |||
476 | /** | ||
477 | * iwl_bg_ucode_trace - Timer callback to log ucode event | ||
478 | * | ||
479 | * The timer is continually set to execute every | ||
480 | * UCODE_TRACE_PERIOD milliseconds after the last timer expired | ||
481 | * this function is to perform continuous uCode event logging operation | ||
482 | * if enabled | ||
483 | */ | ||
484 | static void iwl_bg_ucode_trace(unsigned long data) | ||
485 | { | ||
486 | struct iwl_priv *priv = (struct iwl_priv *)data; | ||
487 | |||
488 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
489 | return; | ||
490 | |||
491 | if (priv->event_log.ucode_trace) { | ||
492 | iwl_continuous_event_trace(priv); | ||
493 | /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */ | ||
494 | mod_timer(&priv->ucode_trace, | ||
495 | jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD)); | ||
496 | } | ||
497 | } | ||
498 | |||
499 | static void iwl_bg_tx_flush(struct work_struct *work) | ||
500 | { | ||
501 | struct iwl_priv *priv = | ||
502 | container_of(work, struct iwl_priv, tx_flush); | ||
503 | |||
504 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
505 | return; | ||
506 | |||
507 | /* do nothing if rf-kill is on */ | ||
508 | if (!iwl_is_ready_rf(priv)) | ||
509 | return; | ||
510 | |||
511 | IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n"); | ||
512 | iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL); | ||
513 | } | ||
514 | |||
515 | /* | ||
516 | * queue/FIFO/AC mapping definitions | ||
517 | */ | ||
518 | |||
519 | #define IWL_TX_FIFO_BK 0 /* shared */ | ||
520 | #define IWL_TX_FIFO_BE 1 | ||
521 | #define IWL_TX_FIFO_VI 2 /* shared */ | ||
522 | #define IWL_TX_FIFO_VO 3 | ||
523 | #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK | ||
524 | #define IWL_TX_FIFO_BE_IPAN 4 | ||
525 | #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI | ||
526 | #define IWL_TX_FIFO_VO_IPAN 5 | ||
527 | /* re-uses the VO FIFO, uCode will properly flush/schedule */ | ||
528 | #define IWL_TX_FIFO_AUX 5 | ||
529 | #define IWL_TX_FIFO_UNUSED -1 | ||
530 | |||
531 | #define IWLAGN_CMD_FIFO_NUM 7 | ||
532 | |||
533 | /* | ||
534 | * This queue number is required for proper operation | ||
535 | * because the ucode will stop/start the scheduler as | ||
536 | * required. | ||
537 | */ | ||
538 | #define IWL_IPAN_MCAST_QUEUE 8 | ||
539 | |||
540 | static const u8 iwlagn_default_queue_to_tx_fifo[] = { | ||
541 | IWL_TX_FIFO_VO, | ||
542 | IWL_TX_FIFO_VI, | ||
543 | IWL_TX_FIFO_BE, | ||
544 | IWL_TX_FIFO_BK, | ||
545 | IWLAGN_CMD_FIFO_NUM, | ||
546 | }; | ||
547 | |||
548 | static const u8 iwlagn_ipan_queue_to_tx_fifo[] = { | ||
549 | IWL_TX_FIFO_VO, | ||
550 | IWL_TX_FIFO_VI, | ||
551 | IWL_TX_FIFO_BE, | ||
552 | IWL_TX_FIFO_BK, | ||
553 | IWL_TX_FIFO_BK_IPAN, | ||
554 | IWL_TX_FIFO_BE_IPAN, | ||
555 | IWL_TX_FIFO_VI_IPAN, | ||
556 | IWL_TX_FIFO_VO_IPAN, | ||
557 | IWL_TX_FIFO_BE_IPAN, | ||
558 | IWLAGN_CMD_FIFO_NUM, | ||
559 | IWL_TX_FIFO_AUX, | ||
560 | }; | ||
561 | |||
562 | static const u8 iwlagn_bss_ac_to_fifo[] = { | ||
563 | IWL_TX_FIFO_VO, | ||
564 | IWL_TX_FIFO_VI, | ||
565 | IWL_TX_FIFO_BE, | ||
566 | IWL_TX_FIFO_BK, | ||
567 | }; | ||
568 | |||
569 | static const u8 iwlagn_bss_ac_to_queue[] = { | ||
570 | 0, 1, 2, 3, | ||
571 | }; | ||
572 | |||
573 | static const u8 iwlagn_pan_ac_to_fifo[] = { | ||
574 | IWL_TX_FIFO_VO_IPAN, | ||
575 | IWL_TX_FIFO_VI_IPAN, | ||
576 | IWL_TX_FIFO_BE_IPAN, | ||
577 | IWL_TX_FIFO_BK_IPAN, | ||
578 | }; | ||
579 | |||
580 | static const u8 iwlagn_pan_ac_to_queue[] = { | ||
581 | 7, 6, 5, 4, | ||
582 | }; | ||
583 | |||
584 | static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags) | ||
585 | { | ||
586 | int i; | ||
587 | |||
588 | /* | ||
589 | * The default context is always valid, | ||
590 | * the PAN context depends on uCode. | ||
591 | */ | ||
592 | priv->valid_contexts = BIT(IWL_RXON_CTX_BSS); | ||
593 | if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) | ||
594 | priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN); | ||
595 | |||
596 | for (i = 0; i < NUM_IWL_RXON_CTX; i++) | ||
597 | priv->contexts[i].ctxid = i; | ||
598 | |||
599 | priv->contexts[IWL_RXON_CTX_BSS].always_active = true; | ||
600 | priv->contexts[IWL_RXON_CTX_BSS].is_active = true; | ||
601 | priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON; | ||
602 | priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING; | ||
603 | priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC; | ||
604 | priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM; | ||
605 | priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID; | ||
606 | priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY; | ||
607 | priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID; | ||
608 | priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes = | ||
609 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR); | ||
610 | priv->contexts[IWL_RXON_CTX_BSS].interface_modes = | ||
611 | BIT(NL80211_IFTYPE_STATION); | ||
612 | priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP; | ||
613 | priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS; | ||
614 | priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS; | ||
615 | priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS; | ||
616 | memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue, | ||
617 | iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue)); | ||
618 | memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo, | ||
619 | iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo)); | ||
620 | |||
621 | priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON; | ||
622 | priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = | ||
623 | REPLY_WIPAN_RXON_TIMING; | ||
624 | priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = | ||
625 | REPLY_WIPAN_RXON_ASSOC; | ||
626 | priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM; | ||
627 | priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN; | ||
628 | priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY; | ||
629 | priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID; | ||
630 | priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION; | ||
631 | priv->contexts[IWL_RXON_CTX_PAN].interface_modes = | ||
632 | BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP); | ||
633 | |||
634 | if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P) | ||
635 | priv->contexts[IWL_RXON_CTX_PAN].interface_modes |= | ||
636 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | ||
637 | BIT(NL80211_IFTYPE_P2P_GO); | ||
638 | |||
639 | priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP; | ||
640 | priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA; | ||
641 | priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P; | ||
642 | memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue, | ||
643 | iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue)); | ||
644 | memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo, | ||
645 | iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo)); | ||
646 | priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE; | ||
647 | |||
648 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | ||
649 | } | ||
650 | |||
651 | static void iwl_rf_kill_ct_config(struct iwl_priv *priv) | ||
652 | { | ||
653 | struct iwl_ct_kill_config cmd; | ||
654 | struct iwl_ct_kill_throttling_config adv_cmd; | ||
655 | int ret = 0; | ||
656 | |||
657 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, | ||
658 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); | ||
659 | |||
660 | priv->thermal_throttle.ct_kill_toggle = false; | ||
661 | |||
662 | if (priv->cfg->base_params->support_ct_kill_exit) { | ||
663 | adv_cmd.critical_temperature_enter = | ||
664 | cpu_to_le32(priv->hw_params.ct_kill_threshold); | ||
665 | adv_cmd.critical_temperature_exit = | ||
666 | cpu_to_le32(priv->hw_params.ct_kill_exit_threshold); | ||
667 | |||
668 | ret = iwl_dvm_send_cmd_pdu(priv, | ||
669 | REPLY_CT_KILL_CONFIG_CMD, | ||
670 | CMD_SYNC, sizeof(adv_cmd), &adv_cmd); | ||
671 | if (ret) | ||
672 | IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n"); | ||
673 | else | ||
674 | IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD " | ||
675 | "succeeded, critical temperature enter is %d," | ||
676 | "exit is %d\n", | ||
677 | priv->hw_params.ct_kill_threshold, | ||
678 | priv->hw_params.ct_kill_exit_threshold); | ||
679 | } else { | ||
680 | cmd.critical_temperature_R = | ||
681 | cpu_to_le32(priv->hw_params.ct_kill_threshold); | ||
682 | |||
683 | ret = iwl_dvm_send_cmd_pdu(priv, | ||
684 | REPLY_CT_KILL_CONFIG_CMD, | ||
685 | CMD_SYNC, sizeof(cmd), &cmd); | ||
686 | if (ret) | ||
687 | IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n"); | ||
688 | else | ||
689 | IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD " | ||
690 | "succeeded, " | ||
691 | "critical temperature is %d\n", | ||
692 | priv->hw_params.ct_kill_threshold); | ||
693 | } | ||
694 | } | ||
695 | |||
696 | static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg) | ||
697 | { | ||
698 | struct iwl_calib_cfg_cmd calib_cfg_cmd; | ||
699 | struct iwl_host_cmd cmd = { | ||
700 | .id = CALIBRATION_CFG_CMD, | ||
701 | .len = { sizeof(struct iwl_calib_cfg_cmd), }, | ||
702 | .data = { &calib_cfg_cmd, }, | ||
703 | }; | ||
704 | |||
705 | memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd)); | ||
706 | calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL; | ||
707 | calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg); | ||
708 | |||
709 | return iwl_dvm_send_cmd(priv, &cmd); | ||
710 | } | ||
711 | |||
712 | |||
713 | static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant) | ||
714 | { | ||
715 | struct iwl_tx_ant_config_cmd tx_ant_cmd = { | ||
716 | .valid = cpu_to_le32(valid_tx_ant), | ||
717 | }; | ||
718 | |||
719 | if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) { | ||
720 | IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant); | ||
721 | return iwl_dvm_send_cmd_pdu(priv, | ||
722 | TX_ANT_CONFIGURATION_CMD, | ||
723 | CMD_SYNC, | ||
724 | sizeof(struct iwl_tx_ant_config_cmd), | ||
725 | &tx_ant_cmd); | ||
726 | } else { | ||
727 | IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n"); | ||
728 | return -EOPNOTSUPP; | ||
729 | } | ||
730 | } | ||
731 | |||
732 | static void iwl_send_bt_config(struct iwl_priv *priv) | ||
733 | { | ||
734 | struct iwl_bt_cmd bt_cmd = { | ||
735 | .lead_time = BT_LEAD_TIME_DEF, | ||
736 | .max_kill = BT_MAX_KILL_DEF, | ||
737 | .kill_ack_mask = 0, | ||
738 | .kill_cts_mask = 0, | ||
739 | }; | ||
740 | |||
741 | if (!iwlwifi_mod_params.bt_coex_active) | ||
742 | bt_cmd.flags = BT_COEX_DISABLE; | ||
743 | else | ||
744 | bt_cmd.flags = BT_COEX_ENABLE; | ||
745 | |||
746 | priv->bt_enable_flag = bt_cmd.flags; | ||
747 | IWL_DEBUG_INFO(priv, "BT coex %s\n", | ||
748 | (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active"); | ||
749 | |||
750 | if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG, | ||
751 | CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd)) | ||
752 | IWL_ERR(priv, "failed to send BT Coex Config\n"); | ||
753 | } | ||
754 | |||
755 | /** | ||
756 | * iwl_alive_start - called after REPLY_ALIVE notification received | ||
757 | * from protocol/runtime uCode (initialization uCode's | ||
758 | * Alive gets handled by iwl_init_alive_start()). | ||
759 | */ | ||
760 | int iwl_alive_start(struct iwl_priv *priv) | ||
761 | { | ||
762 | int ret = 0; | ||
763 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
764 | |||
765 | IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); | ||
766 | |||
767 | /* After the ALIVE response, we can send host commands to the uCode */ | ||
768 | set_bit(STATUS_ALIVE, &priv->status); | ||
769 | |||
770 | if (iwl_is_rfkill(priv)) | ||
771 | return -ERFKILL; | ||
772 | |||
773 | if (priv->event_log.ucode_trace) { | ||
774 | /* start collecting data now */ | ||
775 | mod_timer(&priv->ucode_trace, jiffies); | ||
776 | } | ||
777 | |||
778 | /* download priority table before any calibration request */ | ||
779 | if (priv->cfg->bt_params && | ||
780 | priv->cfg->bt_params->advanced_bt_coexist) { | ||
781 | /* Configure Bluetooth device coexistence support */ | ||
782 | if (priv->cfg->bt_params->bt_sco_disable) | ||
783 | priv->bt_enable_pspoll = false; | ||
784 | else | ||
785 | priv->bt_enable_pspoll = true; | ||
786 | |||
787 | priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK; | ||
788 | priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT; | ||
789 | priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT; | ||
790 | iwlagn_send_advance_bt_config(priv); | ||
791 | priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS; | ||
792 | priv->cur_rssi_ctx = NULL; | ||
793 | |||
794 | iwl_send_prio_tbl(priv); | ||
795 | |||
796 | /* FIXME: w/a to force change uCode BT state machine */ | ||
797 | ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, | ||
798 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); | ||
799 | if (ret) | ||
800 | return ret; | ||
801 | ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE, | ||
802 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); | ||
803 | if (ret) | ||
804 | return ret; | ||
805 | } else { | ||
806 | /* | ||
807 | * default is 2-wire BT coexexistence support | ||
808 | */ | ||
809 | iwl_send_bt_config(priv); | ||
810 | } | ||
811 | |||
812 | /* | ||
813 | * Perform runtime calibrations, including DC calibration. | ||
814 | */ | ||
815 | iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX); | ||
816 | |||
817 | ieee80211_wake_queues(priv->hw); | ||
818 | |||
819 | /* Configure Tx antenna selection based on H/W config */ | ||
820 | iwlagn_send_tx_ant_config(priv, priv->eeprom_data->valid_tx_ant); | ||
821 | |||
822 | if (iwl_is_associated_ctx(ctx) && !priv->wowlan) { | ||
823 | struct iwl_rxon_cmd *active_rxon = | ||
824 | (struct iwl_rxon_cmd *)&ctx->active; | ||
825 | /* apply any changes in staging */ | ||
826 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; | ||
827 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | ||
828 | } else { | ||
829 | struct iwl_rxon_context *tmp; | ||
830 | /* Initialize our rx_config data */ | ||
831 | for_each_context(priv, tmp) | ||
832 | iwl_connection_init_rx_config(priv, tmp); | ||
833 | |||
834 | iwlagn_set_rxon_chain(priv, ctx); | ||
835 | } | ||
836 | |||
837 | if (!priv->wowlan) { | ||
838 | /* WoWLAN ucode will not reply in the same way, skip it */ | ||
839 | iwl_reset_run_time_calib(priv); | ||
840 | } | ||
841 | |||
842 | set_bit(STATUS_READY, &priv->status); | ||
843 | |||
844 | /* Configure the adapter for unassociated operation */ | ||
845 | ret = iwlagn_commit_rxon(priv, ctx); | ||
846 | if (ret) | ||
847 | return ret; | ||
848 | |||
849 | /* At this point, the NIC is initialized and operational */ | ||
850 | iwl_rf_kill_ct_config(priv); | ||
851 | |||
852 | IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n"); | ||
853 | |||
854 | return iwl_power_update_mode(priv, true); | ||
855 | } | ||
856 | |||
857 | /** | ||
858 | * iwl_clear_driver_stations - clear knowledge of all stations from driver | ||
859 | * @priv: iwl priv struct | ||
860 | * | ||
861 | * This is called during iwl_down() to make sure that in the case | ||
862 | * we're coming there from a hardware restart mac80211 will be | ||
863 | * able to reconfigure stations -- if we're getting there in the | ||
864 | * normal down flow then the stations will already be cleared. | ||
865 | */ | ||
866 | static void iwl_clear_driver_stations(struct iwl_priv *priv) | ||
867 | { | ||
868 | struct iwl_rxon_context *ctx; | ||
869 | |||
870 | spin_lock_bh(&priv->sta_lock); | ||
871 | memset(priv->stations, 0, sizeof(priv->stations)); | ||
872 | priv->num_stations = 0; | ||
873 | |||
874 | priv->ucode_key_table = 0; | ||
875 | |||
876 | for_each_context(priv, ctx) { | ||
877 | /* | ||
878 | * Remove all key information that is not stored as part | ||
879 | * of station information since mac80211 may not have had | ||
880 | * a chance to remove all the keys. When device is | ||
881 | * reconfigured by mac80211 after an error all keys will | ||
882 | * be reconfigured. | ||
883 | */ | ||
884 | memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys)); | ||
885 | ctx->key_mapping_keys = 0; | ||
886 | } | ||
887 | |||
888 | spin_unlock_bh(&priv->sta_lock); | ||
889 | } | ||
890 | |||
891 | void iwl_down(struct iwl_priv *priv) | ||
892 | { | ||
893 | int exit_pending; | ||
894 | |||
895 | IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n"); | ||
896 | |||
897 | lockdep_assert_held(&priv->mutex); | ||
898 | |||
899 | iwl_scan_cancel_timeout(priv, 200); | ||
900 | |||
901 | /* | ||
902 | * If active, scanning won't cancel it, so say it expired. | ||
903 | * No race since we hold the mutex here and a new one | ||
904 | * can't come in at this time. | ||
905 | */ | ||
906 | ieee80211_remain_on_channel_expired(priv->hw); | ||
907 | |||
908 | exit_pending = | ||
909 | test_and_set_bit(STATUS_EXIT_PENDING, &priv->status); | ||
910 | |||
911 | iwl_clear_ucode_stations(priv, NULL); | ||
912 | iwl_dealloc_bcast_stations(priv); | ||
913 | iwl_clear_driver_stations(priv); | ||
914 | |||
915 | /* reset BT coex data */ | ||
916 | priv->bt_status = 0; | ||
917 | priv->cur_rssi_ctx = NULL; | ||
918 | priv->bt_is_sco = 0; | ||
919 | if (priv->cfg->bt_params) | ||
920 | priv->bt_traffic_load = | ||
921 | priv->cfg->bt_params->bt_init_traffic_load; | ||
922 | else | ||
923 | priv->bt_traffic_load = 0; | ||
924 | priv->bt_full_concurrent = false; | ||
925 | priv->bt_ci_compliance = 0; | ||
926 | |||
927 | /* Wipe out the EXIT_PENDING status bit if we are not actually | ||
928 | * exiting the module */ | ||
929 | if (!exit_pending) | ||
930 | clear_bit(STATUS_EXIT_PENDING, &priv->status); | ||
931 | |||
932 | if (priv->mac80211_registered) | ||
933 | ieee80211_stop_queues(priv->hw); | ||
934 | |||
935 | priv->ucode_loaded = false; | ||
936 | iwl_trans_stop_device(priv->trans); | ||
937 | |||
938 | /* Set num_aux_in_flight must be done after the transport is stopped */ | ||
939 | atomic_set(&priv->num_aux_in_flight, 0); | ||
940 | |||
941 | /* Clear out all status bits but a few that are stable across reset */ | ||
942 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << | ||
943 | STATUS_RF_KILL_HW | | ||
944 | test_bit(STATUS_FW_ERROR, &priv->status) << | ||
945 | STATUS_FW_ERROR | | ||
946 | test_bit(STATUS_EXIT_PENDING, &priv->status) << | ||
947 | STATUS_EXIT_PENDING; | ||
948 | |||
949 | dev_kfree_skb(priv->beacon_skb); | ||
950 | priv->beacon_skb = NULL; | ||
951 | } | ||
952 | |||
953 | /***************************************************************************** | ||
954 | * | ||
955 | * Workqueue callbacks | ||
956 | * | ||
957 | *****************************************************************************/ | ||
958 | |||
959 | static void iwl_bg_run_time_calib_work(struct work_struct *work) | ||
960 | { | ||
961 | struct iwl_priv *priv = container_of(work, struct iwl_priv, | ||
962 | run_time_calib_work); | ||
963 | |||
964 | mutex_lock(&priv->mutex); | ||
965 | |||
966 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || | ||
967 | test_bit(STATUS_SCANNING, &priv->status)) { | ||
968 | mutex_unlock(&priv->mutex); | ||
969 | return; | ||
970 | } | ||
971 | |||
972 | if (priv->start_calib) { | ||
973 | iwl_chain_noise_calibration(priv); | ||
974 | iwl_sensitivity_calibration(priv); | ||
975 | } | ||
976 | |||
977 | mutex_unlock(&priv->mutex); | ||
978 | } | ||
979 | |||
980 | void iwlagn_prepare_restart(struct iwl_priv *priv) | ||
981 | { | ||
982 | bool bt_full_concurrent; | ||
983 | u8 bt_ci_compliance; | ||
984 | u8 bt_load; | ||
985 | u8 bt_status; | ||
986 | bool bt_is_sco; | ||
987 | int i; | ||
988 | |||
989 | lockdep_assert_held(&priv->mutex); | ||
990 | |||
991 | priv->is_open = 0; | ||
992 | |||
993 | /* | ||
994 | * __iwl_down() will clear the BT status variables, | ||
995 | * which is correct, but when we restart we really | ||
996 | * want to keep them so restore them afterwards. | ||
997 | * | ||
998 | * The restart process will later pick them up and | ||
999 | * re-configure the hw when we reconfigure the BT | ||
1000 | * command. | ||
1001 | */ | ||
1002 | bt_full_concurrent = priv->bt_full_concurrent; | ||
1003 | bt_ci_compliance = priv->bt_ci_compliance; | ||
1004 | bt_load = priv->bt_traffic_load; | ||
1005 | bt_status = priv->bt_status; | ||
1006 | bt_is_sco = priv->bt_is_sco; | ||
1007 | |||
1008 | iwl_down(priv); | ||
1009 | |||
1010 | priv->bt_full_concurrent = bt_full_concurrent; | ||
1011 | priv->bt_ci_compliance = bt_ci_compliance; | ||
1012 | priv->bt_traffic_load = bt_load; | ||
1013 | priv->bt_status = bt_status; | ||
1014 | priv->bt_is_sco = bt_is_sco; | ||
1015 | |||
1016 | /* reset aggregation queues */ | ||
1017 | for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++) | ||
1018 | priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE; | ||
1019 | /* and stop counts */ | ||
1020 | for (i = 0; i < IWL_MAX_HW_QUEUES; i++) | ||
1021 | atomic_set(&priv->queue_stop_count[i], 0); | ||
1022 | |||
1023 | memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc)); | ||
1024 | } | ||
1025 | |||
1026 | static void iwl_bg_restart(struct work_struct *data) | ||
1027 | { | ||
1028 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); | ||
1029 | |||
1030 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
1031 | return; | ||
1032 | |||
1033 | if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) { | ||
1034 | mutex_lock(&priv->mutex); | ||
1035 | iwlagn_prepare_restart(priv); | ||
1036 | mutex_unlock(&priv->mutex); | ||
1037 | iwl_cancel_deferred_work(priv); | ||
1038 | ieee80211_restart_hw(priv->hw); | ||
1039 | } else { | ||
1040 | WARN_ON(1); | ||
1041 | } | ||
1042 | } | ||
1043 | |||
1044 | |||
1045 | |||
1046 | |||
1047 | void iwlagn_disable_roc(struct iwl_priv *priv) | ||
1048 | { | ||
1049 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN]; | ||
1050 | |||
1051 | lockdep_assert_held(&priv->mutex); | ||
1052 | |||
1053 | if (!priv->hw_roc_setup) | ||
1054 | return; | ||
1055 | |||
1056 | ctx->staging.dev_type = RXON_DEV_TYPE_P2P; | ||
1057 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | ||
1058 | |||
1059 | priv->hw_roc_channel = NULL; | ||
1060 | |||
1061 | memset(ctx->staging.node_addr, 0, ETH_ALEN); | ||
1062 | |||
1063 | iwlagn_commit_rxon(priv, ctx); | ||
1064 | |||
1065 | ctx->is_active = false; | ||
1066 | priv->hw_roc_setup = false; | ||
1067 | } | ||
1068 | |||
1069 | static void iwlagn_disable_roc_work(struct work_struct *work) | ||
1070 | { | ||
1071 | struct iwl_priv *priv = container_of(work, struct iwl_priv, | ||
1072 | hw_roc_disable_work.work); | ||
1073 | |||
1074 | mutex_lock(&priv->mutex); | ||
1075 | iwlagn_disable_roc(priv); | ||
1076 | mutex_unlock(&priv->mutex); | ||
1077 | } | ||
1078 | |||
1079 | /***************************************************************************** | ||
1080 | * | ||
1081 | * driver setup and teardown | ||
1082 | * | ||
1083 | *****************************************************************************/ | ||
1084 | |||
1085 | static void iwl_setup_deferred_work(struct iwl_priv *priv) | ||
1086 | { | ||
1087 | priv->workqueue = create_singlethread_workqueue(DRV_NAME); | ||
1088 | |||
1089 | INIT_WORK(&priv->restart, iwl_bg_restart); | ||
1090 | INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update); | ||
1091 | INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work); | ||
1092 | INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush); | ||
1093 | INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency); | ||
1094 | INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config); | ||
1095 | INIT_DELAYED_WORK(&priv->hw_roc_disable_work, | ||
1096 | iwlagn_disable_roc_work); | ||
1097 | |||
1098 | iwl_setup_scan_deferred_work(priv); | ||
1099 | |||
1100 | if (priv->cfg->bt_params) | ||
1101 | iwlagn_bt_setup_deferred_work(priv); | ||
1102 | |||
1103 | init_timer(&priv->statistics_periodic); | ||
1104 | priv->statistics_periodic.data = (unsigned long)priv; | ||
1105 | priv->statistics_periodic.function = iwl_bg_statistics_periodic; | ||
1106 | |||
1107 | init_timer(&priv->ucode_trace); | ||
1108 | priv->ucode_trace.data = (unsigned long)priv; | ||
1109 | priv->ucode_trace.function = iwl_bg_ucode_trace; | ||
1110 | } | ||
1111 | |||
1112 | void iwl_cancel_deferred_work(struct iwl_priv *priv) | ||
1113 | { | ||
1114 | if (priv->cfg->bt_params) | ||
1115 | iwlagn_bt_cancel_deferred_work(priv); | ||
1116 | |||
1117 | cancel_work_sync(&priv->run_time_calib_work); | ||
1118 | cancel_work_sync(&priv->beacon_update); | ||
1119 | |||
1120 | iwl_cancel_scan_deferred_work(priv); | ||
1121 | |||
1122 | cancel_work_sync(&priv->bt_full_concurrency); | ||
1123 | cancel_work_sync(&priv->bt_runtime_config); | ||
1124 | cancel_delayed_work_sync(&priv->hw_roc_disable_work); | ||
1125 | |||
1126 | del_timer_sync(&priv->statistics_periodic); | ||
1127 | del_timer_sync(&priv->ucode_trace); | ||
1128 | } | ||
1129 | |||
1130 | static int iwl_init_drv(struct iwl_priv *priv) | ||
1131 | { | ||
1132 | spin_lock_init(&priv->sta_lock); | ||
1133 | |||
1134 | mutex_init(&priv->mutex); | ||
1135 | |||
1136 | INIT_LIST_HEAD(&priv->calib_results); | ||
1137 | |||
1138 | priv->band = IEEE80211_BAND_2GHZ; | ||
1139 | |||
1140 | priv->plcp_delta_threshold = | ||
1141 | priv->cfg->base_params->plcp_delta_threshold; | ||
1142 | |||
1143 | priv->iw_mode = NL80211_IFTYPE_STATION; | ||
1144 | priv->current_ht_config.smps = IEEE80211_SMPS_STATIC; | ||
1145 | priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF; | ||
1146 | priv->agg_tids_count = 0; | ||
1147 | |||
1148 | priv->ucode_owner = IWL_OWNERSHIP_DRIVER; | ||
1149 | |||
1150 | priv->rx_statistics_jiffies = jiffies; | ||
1151 | |||
1152 | /* Choose which receivers/antennas to use */ | ||
1153 | iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]); | ||
1154 | |||
1155 | iwl_init_scan_params(priv); | ||
1156 | |||
1157 | /* init bt coex */ | ||
1158 | if (priv->cfg->bt_params && | ||
1159 | priv->cfg->bt_params->advanced_bt_coexist) { | ||
1160 | priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT; | ||
1161 | priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT; | ||
1162 | priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK; | ||
1163 | priv->bt_on_thresh = BT_ON_THRESHOLD_DEF; | ||
1164 | priv->bt_duration = BT_DURATION_LIMIT_DEF; | ||
1165 | priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF; | ||
1166 | } | ||
1167 | |||
1168 | return 0; | ||
1169 | } | ||
1170 | |||
1171 | static void iwl_uninit_drv(struct iwl_priv *priv) | ||
1172 | { | ||
1173 | kfree(priv->scan_cmd); | ||
1174 | kfree(priv->beacon_cmd); | ||
1175 | kfree(rcu_dereference_raw(priv->noa_data)); | ||
1176 | iwl_calib_free_results(priv); | ||
1177 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
1178 | kfree(priv->wowlan_sram); | ||
1179 | #endif | ||
1180 | } | ||
1181 | |||
1182 | static void iwl_set_hw_params(struct iwl_priv *priv) | ||
1183 | { | ||
1184 | if (priv->cfg->ht_params) | ||
1185 | priv->hw_params.use_rts_for_aggregation = | ||
1186 | priv->cfg->ht_params->use_rts_for_aggregation; | ||
1187 | |||
1188 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL) | ||
1189 | priv->hw_params.sku &= ~EEPROM_SKU_CAP_11N_ENABLE; | ||
1190 | |||
1191 | /* Device-specific setup */ | ||
1192 | priv->lib->set_hw_params(priv); | ||
1193 | } | ||
1194 | |||
1195 | |||
1196 | |||
1197 | /* show what optional capabilities we have */ | ||
1198 | static void iwl_option_config(struct iwl_priv *priv) | ||
1199 | { | ||
1200 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
1201 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n"); | ||
1202 | #else | ||
1203 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n"); | ||
1204 | #endif | ||
1205 | |||
1206 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
1207 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n"); | ||
1208 | #else | ||
1209 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n"); | ||
1210 | #endif | ||
1211 | |||
1212 | #ifdef CONFIG_IWLWIFI_DEVICE_TRACING | ||
1213 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n"); | ||
1214 | #else | ||
1215 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n"); | ||
1216 | #endif | ||
1217 | |||
1218 | #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE | ||
1219 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TESTMODE enabled\n"); | ||
1220 | #else | ||
1221 | IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TESTMODE disabled\n"); | ||
1222 | #endif | ||
1223 | |||
1224 | #ifdef CONFIG_IWLWIFI_P2P | ||
1225 | IWL_INFO(priv, "CONFIG_IWLWIFI_P2P enabled\n"); | ||
1226 | #else | ||
1227 | IWL_INFO(priv, "CONFIG_IWLWIFI_P2P disabled\n"); | ||
1228 | #endif | ||
1229 | } | ||
1230 | |||
1231 | static int iwl_eeprom_init_hw_params(struct iwl_priv *priv) | ||
1232 | { | ||
1233 | u16 radio_cfg; | ||
1234 | |||
1235 | priv->hw_params.sku = priv->eeprom_data->sku; | ||
1236 | |||
1237 | if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE && | ||
1238 | !priv->cfg->ht_params) { | ||
1239 | IWL_ERR(priv, "Invalid 11n configuration\n"); | ||
1240 | return -EINVAL; | ||
1241 | } | ||
1242 | |||
1243 | if (!priv->hw_params.sku) { | ||
1244 | IWL_ERR(priv, "Invalid device sku\n"); | ||
1245 | return -EINVAL; | ||
1246 | } | ||
1247 | |||
1248 | IWL_INFO(priv, "Device SKU: 0x%X\n", priv->hw_params.sku); | ||
1249 | |||
1250 | radio_cfg = priv->eeprom_data->radio_cfg; | ||
1251 | |||
1252 | priv->hw_params.tx_chains_num = | ||
1253 | num_of_ant(priv->eeprom_data->valid_tx_ant); | ||
1254 | if (priv->cfg->rx_with_siso_diversity) | ||
1255 | priv->hw_params.rx_chains_num = 1; | ||
1256 | else | ||
1257 | priv->hw_params.rx_chains_num = | ||
1258 | num_of_ant(priv->eeprom_data->valid_rx_ant); | ||
1259 | |||
1260 | IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n", | ||
1261 | priv->eeprom_data->valid_tx_ant, | ||
1262 | priv->eeprom_data->valid_rx_ant); | ||
1263 | |||
1264 | return 0; | ||
1265 | } | ||
1266 | |||
1267 | static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans, | ||
1268 | const struct iwl_cfg *cfg, | ||
1269 | const struct iwl_fw *fw) | ||
1270 | { | ||
1271 | struct iwl_priv *priv; | ||
1272 | struct ieee80211_hw *hw; | ||
1273 | struct iwl_op_mode *op_mode; | ||
1274 | u16 num_mac; | ||
1275 | u32 ucode_flags; | ||
1276 | struct iwl_trans_config trans_cfg; | ||
1277 | static const u8 no_reclaim_cmds[] = { | ||
1278 | REPLY_RX_PHY_CMD, | ||
1279 | REPLY_RX, | ||
1280 | REPLY_RX_MPDU_CMD, | ||
1281 | REPLY_COMPRESSED_BA, | ||
1282 | STATISTICS_NOTIFICATION, | ||
1283 | REPLY_TX, | ||
1284 | }; | ||
1285 | int i; | ||
1286 | |||
1287 | /************************ | ||
1288 | * 1. Allocating HW data | ||
1289 | ************************/ | ||
1290 | hw = iwl_alloc_all(); | ||
1291 | if (!hw) { | ||
1292 | pr_err("%s: Cannot allocate network device\n", cfg->name); | ||
1293 | goto out; | ||
1294 | } | ||
1295 | |||
1296 | op_mode = hw->priv; | ||
1297 | op_mode->ops = &iwl_dvm_ops; | ||
1298 | priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
1299 | priv->trans = trans; | ||
1300 | priv->dev = trans->dev; | ||
1301 | priv->cfg = cfg; | ||
1302 | priv->fw = fw; | ||
1303 | |||
1304 | switch (priv->cfg->device_family) { | ||
1305 | case IWL_DEVICE_FAMILY_1000: | ||
1306 | case IWL_DEVICE_FAMILY_100: | ||
1307 | priv->lib = &iwl1000_lib; | ||
1308 | break; | ||
1309 | case IWL_DEVICE_FAMILY_2000: | ||
1310 | case IWL_DEVICE_FAMILY_105: | ||
1311 | priv->lib = &iwl2000_lib; | ||
1312 | break; | ||
1313 | case IWL_DEVICE_FAMILY_2030: | ||
1314 | case IWL_DEVICE_FAMILY_135: | ||
1315 | priv->lib = &iwl2030_lib; | ||
1316 | break; | ||
1317 | case IWL_DEVICE_FAMILY_5000: | ||
1318 | priv->lib = &iwl5000_lib; | ||
1319 | break; | ||
1320 | case IWL_DEVICE_FAMILY_5150: | ||
1321 | priv->lib = &iwl5150_lib; | ||
1322 | break; | ||
1323 | case IWL_DEVICE_FAMILY_6000: | ||
1324 | case IWL_DEVICE_FAMILY_6005: | ||
1325 | case IWL_DEVICE_FAMILY_6000i: | ||
1326 | case IWL_DEVICE_FAMILY_6050: | ||
1327 | case IWL_DEVICE_FAMILY_6150: | ||
1328 | priv->lib = &iwl6000_lib; | ||
1329 | break; | ||
1330 | case IWL_DEVICE_FAMILY_6030: | ||
1331 | priv->lib = &iwl6030_lib; | ||
1332 | break; | ||
1333 | default: | ||
1334 | break; | ||
1335 | } | ||
1336 | |||
1337 | if (WARN_ON(!priv->lib)) | ||
1338 | goto out_free_hw; | ||
1339 | |||
1340 | /* | ||
1341 | * Populate the state variables that the transport layer needs | ||
1342 | * to know about. | ||
1343 | */ | ||
1344 | trans_cfg.op_mode = op_mode; | ||
1345 | trans_cfg.no_reclaim_cmds = no_reclaim_cmds; | ||
1346 | trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds); | ||
1347 | trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K; | ||
1348 | if (!iwlwifi_mod_params.wd_disable) | ||
1349 | trans_cfg.queue_watchdog_timeout = | ||
1350 | priv->cfg->base_params->wd_timeout; | ||
1351 | else | ||
1352 | trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED; | ||
1353 | trans_cfg.command_names = iwl_dvm_cmd_strings; | ||
1354 | |||
1355 | ucode_flags = fw->ucode_capa.flags; | ||
1356 | |||
1357 | #ifndef CONFIG_IWLWIFI_P2P | ||
1358 | ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P; | ||
1359 | #endif | ||
1360 | |||
1361 | if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) { | ||
1362 | priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN; | ||
1363 | trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM; | ||
1364 | trans_cfg.queue_to_fifo = iwlagn_ipan_queue_to_tx_fifo; | ||
1365 | trans_cfg.n_queue_to_fifo = | ||
1366 | ARRAY_SIZE(iwlagn_ipan_queue_to_tx_fifo); | ||
1367 | } else { | ||
1368 | priv->sta_key_max_num = STA_KEY_MAX_NUM; | ||
1369 | trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM; | ||
1370 | trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo; | ||
1371 | trans_cfg.n_queue_to_fifo = | ||
1372 | ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo); | ||
1373 | } | ||
1374 | |||
1375 | /* Configure transport layer */ | ||
1376 | iwl_trans_configure(priv->trans, &trans_cfg); | ||
1377 | |||
1378 | /* At this point both hw and priv are allocated. */ | ||
1379 | |||
1380 | SET_IEEE80211_DEV(priv->hw, priv->trans->dev); | ||
1381 | |||
1382 | iwl_option_config(priv); | ||
1383 | |||
1384 | IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); | ||
1385 | |||
1386 | /* is antenna coupling more than 35dB ? */ | ||
1387 | priv->bt_ant_couple_ok = | ||
1388 | (iwlwifi_mod_params.ant_coupling > | ||
1389 | IWL_BT_ANTENNA_COUPLING_THRESHOLD) ? | ||
1390 | true : false; | ||
1391 | |||
1392 | /* enable/disable bt channel inhibition */ | ||
1393 | priv->bt_ch_announce = iwlwifi_mod_params.bt_ch_announce; | ||
1394 | IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n", | ||
1395 | (priv->bt_ch_announce) ? "On" : "Off"); | ||
1396 | |||
1397 | /* these spin locks will be used in apm_ops.init and EEPROM access | ||
1398 | * we should init now | ||
1399 | */ | ||
1400 | spin_lock_init(&priv->statistics.lock); | ||
1401 | |||
1402 | /*********************** | ||
1403 | * 2. Read REV register | ||
1404 | ***********************/ | ||
1405 | IWL_INFO(priv, "Detected %s, REV=0x%X\n", | ||
1406 | priv->cfg->name, priv->trans->hw_rev); | ||
1407 | |||
1408 | if (iwl_trans_start_hw(priv->trans)) | ||
1409 | goto out_free_hw; | ||
1410 | |||
1411 | /* Read the EEPROM */ | ||
1412 | if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob, | ||
1413 | &priv->eeprom_blob_size)) { | ||
1414 | IWL_ERR(priv, "Unable to init EEPROM\n"); | ||
1415 | goto out_free_hw; | ||
1416 | } | ||
1417 | |||
1418 | /* Reset chip to save power until we load uCode during "up". */ | ||
1419 | iwl_trans_stop_hw(priv->trans, false); | ||
1420 | |||
1421 | priv->eeprom_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg, | ||
1422 | priv->eeprom_blob, | ||
1423 | priv->eeprom_blob_size); | ||
1424 | if (!priv->eeprom_data) | ||
1425 | goto out_free_eeprom_blob; | ||
1426 | |||
1427 | if (iwl_eeprom_check_version(priv->eeprom_data, priv->trans)) | ||
1428 | goto out_free_eeprom; | ||
1429 | |||
1430 | if (iwl_eeprom_init_hw_params(priv)) | ||
1431 | goto out_free_eeprom; | ||
1432 | |||
1433 | /* extract MAC Address */ | ||
1434 | memcpy(priv->addresses[0].addr, priv->eeprom_data->hw_addr, ETH_ALEN); | ||
1435 | IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr); | ||
1436 | priv->hw->wiphy->addresses = priv->addresses; | ||
1437 | priv->hw->wiphy->n_addresses = 1; | ||
1438 | num_mac = priv->eeprom_data->n_hw_addrs; | ||
1439 | if (num_mac > 1) { | ||
1440 | memcpy(priv->addresses[1].addr, priv->addresses[0].addr, | ||
1441 | ETH_ALEN); | ||
1442 | priv->addresses[1].addr[5]++; | ||
1443 | priv->hw->wiphy->n_addresses++; | ||
1444 | } | ||
1445 | |||
1446 | /************************ | ||
1447 | * 4. Setup HW constants | ||
1448 | ************************/ | ||
1449 | iwl_set_hw_params(priv); | ||
1450 | |||
1451 | if (!(priv->hw_params.sku & EEPROM_SKU_CAP_IPAN_ENABLE)) { | ||
1452 | IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN"); | ||
1453 | ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN; | ||
1454 | /* | ||
1455 | * if not PAN, then don't support P2P -- might be a uCode | ||
1456 | * packaging bug or due to the eeprom check above | ||
1457 | */ | ||
1458 | ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P; | ||
1459 | priv->sta_key_max_num = STA_KEY_MAX_NUM; | ||
1460 | trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM; | ||
1461 | trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo; | ||
1462 | trans_cfg.n_queue_to_fifo = | ||
1463 | ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo); | ||
1464 | |||
1465 | /* Configure transport layer again*/ | ||
1466 | iwl_trans_configure(priv->trans, &trans_cfg); | ||
1467 | } | ||
1468 | |||
1469 | /******************* | ||
1470 | * 5. Setup priv | ||
1471 | *******************/ | ||
1472 | for (i = 0; i < IWL_MAX_HW_QUEUES; i++) { | ||
1473 | priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE; | ||
1474 | if (i < IWLAGN_FIRST_AMPDU_QUEUE && | ||
1475 | i != IWL_DEFAULT_CMD_QUEUE_NUM && | ||
1476 | i != IWL_IPAN_CMD_QUEUE_NUM) | ||
1477 | priv->queue_to_mac80211[i] = i; | ||
1478 | atomic_set(&priv->queue_stop_count[i], 0); | ||
1479 | } | ||
1480 | |||
1481 | WARN_ON(trans_cfg.queue_to_fifo[trans_cfg.cmd_queue] != | ||
1482 | IWLAGN_CMD_FIFO_NUM); | ||
1483 | |||
1484 | if (iwl_init_drv(priv)) | ||
1485 | goto out_free_eeprom; | ||
1486 | |||
1487 | /* At this point both hw and priv are initialized. */ | ||
1488 | |||
1489 | /******************** | ||
1490 | * 6. Setup services | ||
1491 | ********************/ | ||
1492 | iwl_setup_deferred_work(priv); | ||
1493 | iwl_setup_rx_handlers(priv); | ||
1494 | iwl_testmode_init(priv); | ||
1495 | |||
1496 | iwl_power_initialize(priv); | ||
1497 | iwl_tt_initialize(priv); | ||
1498 | |||
1499 | snprintf(priv->hw->wiphy->fw_version, | ||
1500 | sizeof(priv->hw->wiphy->fw_version), | ||
1501 | "%s", fw->fw_version); | ||
1502 | |||
1503 | priv->new_scan_threshold_behaviour = | ||
1504 | !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN); | ||
1505 | |||
1506 | priv->phy_calib_chain_noise_reset_cmd = | ||
1507 | fw->ucode_capa.standard_phy_calibration_size; | ||
1508 | priv->phy_calib_chain_noise_gain_cmd = | ||
1509 | fw->ucode_capa.standard_phy_calibration_size + 1; | ||
1510 | |||
1511 | /* initialize all valid contexts */ | ||
1512 | iwl_init_context(priv, ucode_flags); | ||
1513 | |||
1514 | /************************************************** | ||
1515 | * This is still part of probe() in a sense... | ||
1516 | * | ||
1517 | * 7. Setup and register with mac80211 and debugfs | ||
1518 | **************************************************/ | ||
1519 | if (iwlagn_mac_setup_register(priv, &fw->ucode_capa)) | ||
1520 | goto out_destroy_workqueue; | ||
1521 | |||
1522 | if (iwl_dbgfs_register(priv, DRV_NAME)) | ||
1523 | IWL_ERR(priv, | ||
1524 | "failed to create debugfs files. Ignoring error\n"); | ||
1525 | |||
1526 | return op_mode; | ||
1527 | |||
1528 | out_destroy_workqueue: | ||
1529 | destroy_workqueue(priv->workqueue); | ||
1530 | priv->workqueue = NULL; | ||
1531 | iwl_uninit_drv(priv); | ||
1532 | out_free_eeprom_blob: | ||
1533 | kfree(priv->eeprom_blob); | ||
1534 | out_free_eeprom: | ||
1535 | iwl_free_eeprom_data(priv->eeprom_data); | ||
1536 | out_free_hw: | ||
1537 | ieee80211_free_hw(priv->hw); | ||
1538 | out: | ||
1539 | op_mode = NULL; | ||
1540 | return op_mode; | ||
1541 | } | ||
1542 | |||
1543 | static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode) | ||
1544 | { | ||
1545 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
1546 | |||
1547 | IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n"); | ||
1548 | |||
1549 | iwl_dbgfs_unregister(priv); | ||
1550 | |||
1551 | iwl_testmode_cleanup(priv); | ||
1552 | iwlagn_mac_unregister(priv); | ||
1553 | |||
1554 | iwl_tt_exit(priv); | ||
1555 | |||
1556 | /*This will stop the queues, move the device to low power state */ | ||
1557 | priv->ucode_loaded = false; | ||
1558 | iwl_trans_stop_device(priv->trans); | ||
1559 | |||
1560 | kfree(priv->eeprom_blob); | ||
1561 | iwl_free_eeprom_data(priv->eeprom_data); | ||
1562 | |||
1563 | /*netif_stop_queue(dev); */ | ||
1564 | flush_workqueue(priv->workqueue); | ||
1565 | |||
1566 | /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes | ||
1567 | * priv->workqueue... so we can't take down the workqueue | ||
1568 | * until now... */ | ||
1569 | destroy_workqueue(priv->workqueue); | ||
1570 | priv->workqueue = NULL; | ||
1571 | |||
1572 | iwl_uninit_drv(priv); | ||
1573 | |||
1574 | dev_kfree_skb(priv->beacon_skb); | ||
1575 | |||
1576 | iwl_trans_stop_hw(priv->trans, true); | ||
1577 | ieee80211_free_hw(priv->hw); | ||
1578 | } | ||
1579 | |||
1580 | static const char * const desc_lookup_text[] = { | ||
1581 | "OK", | ||
1582 | "FAIL", | ||
1583 | "BAD_PARAM", | ||
1584 | "BAD_CHECKSUM", | ||
1585 | "NMI_INTERRUPT_WDG", | ||
1586 | "SYSASSERT", | ||
1587 | "FATAL_ERROR", | ||
1588 | "BAD_COMMAND", | ||
1589 | "HW_ERROR_TUNE_LOCK", | ||
1590 | "HW_ERROR_TEMPERATURE", | ||
1591 | "ILLEGAL_CHAN_FREQ", | ||
1592 | "VCC_NOT_STABLE", | ||
1593 | "FH_ERROR", | ||
1594 | "NMI_INTERRUPT_HOST", | ||
1595 | "NMI_INTERRUPT_ACTION_PT", | ||
1596 | "NMI_INTERRUPT_UNKNOWN", | ||
1597 | "UCODE_VERSION_MISMATCH", | ||
1598 | "HW_ERROR_ABS_LOCK", | ||
1599 | "HW_ERROR_CAL_LOCK_FAIL", | ||
1600 | "NMI_INTERRUPT_INST_ACTION_PT", | ||
1601 | "NMI_INTERRUPT_DATA_ACTION_PT", | ||
1602 | "NMI_TRM_HW_ER", | ||
1603 | "NMI_INTERRUPT_TRM", | ||
1604 | "NMI_INTERRUPT_BREAK_POINT", | ||
1605 | "DEBUG_0", | ||
1606 | "DEBUG_1", | ||
1607 | "DEBUG_2", | ||
1608 | "DEBUG_3", | ||
1609 | }; | ||
1610 | |||
1611 | static struct { char *name; u8 num; } advanced_lookup[] = { | ||
1612 | { "NMI_INTERRUPT_WDG", 0x34 }, | ||
1613 | { "SYSASSERT", 0x35 }, | ||
1614 | { "UCODE_VERSION_MISMATCH", 0x37 }, | ||
1615 | { "BAD_COMMAND", 0x38 }, | ||
1616 | { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C }, | ||
1617 | { "FATAL_ERROR", 0x3D }, | ||
1618 | { "NMI_TRM_HW_ERR", 0x46 }, | ||
1619 | { "NMI_INTERRUPT_TRM", 0x4C }, | ||
1620 | { "NMI_INTERRUPT_BREAK_POINT", 0x54 }, | ||
1621 | { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C }, | ||
1622 | { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 }, | ||
1623 | { "NMI_INTERRUPT_HOST", 0x66 }, | ||
1624 | { "NMI_INTERRUPT_ACTION_PT", 0x7C }, | ||
1625 | { "NMI_INTERRUPT_UNKNOWN", 0x84 }, | ||
1626 | { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 }, | ||
1627 | { "ADVANCED_SYSASSERT", 0 }, | ||
1628 | }; | ||
1629 | |||
1630 | static const char *desc_lookup(u32 num) | ||
1631 | { | ||
1632 | int i; | ||
1633 | int max = ARRAY_SIZE(desc_lookup_text); | ||
1634 | |||
1635 | if (num < max) | ||
1636 | return desc_lookup_text[num]; | ||
1637 | |||
1638 | max = ARRAY_SIZE(advanced_lookup) - 1; | ||
1639 | for (i = 0; i < max; i++) { | ||
1640 | if (advanced_lookup[i].num == num) | ||
1641 | break; | ||
1642 | } | ||
1643 | return advanced_lookup[i].name; | ||
1644 | } | ||
1645 | |||
1646 | #define ERROR_START_OFFSET (1 * sizeof(u32)) | ||
1647 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) | ||
1648 | |||
1649 | static void iwl_dump_nic_error_log(struct iwl_priv *priv) | ||
1650 | { | ||
1651 | struct iwl_trans *trans = priv->trans; | ||
1652 | u32 base; | ||
1653 | struct iwl_error_event_table table; | ||
1654 | |||
1655 | base = priv->device_pointers.error_event_table; | ||
1656 | if (priv->cur_ucode == IWL_UCODE_INIT) { | ||
1657 | if (!base) | ||
1658 | base = priv->fw->init_errlog_ptr; | ||
1659 | } else { | ||
1660 | if (!base) | ||
1661 | base = priv->fw->inst_errlog_ptr; | ||
1662 | } | ||
1663 | |||
1664 | if (!iwlagn_hw_valid_rtc_data_addr(base)) { | ||
1665 | IWL_ERR(priv, | ||
1666 | "Not valid error log pointer 0x%08X for %s uCode\n", | ||
1667 | base, | ||
1668 | (priv->cur_ucode == IWL_UCODE_INIT) | ||
1669 | ? "Init" : "RT"); | ||
1670 | return; | ||
1671 | } | ||
1672 | |||
1673 | /*TODO: Update dbgfs with ISR error stats obtained below */ | ||
1674 | iwl_read_targ_mem_words(trans, base, &table, sizeof(table)); | ||
1675 | |||
1676 | if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) { | ||
1677 | IWL_ERR(trans, "Start IWL Error Log Dump:\n"); | ||
1678 | IWL_ERR(trans, "Status: 0x%08lX, count: %d\n", | ||
1679 | priv->status, table.valid); | ||
1680 | } | ||
1681 | |||
1682 | trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low, | ||
1683 | table.data1, table.data2, table.line, | ||
1684 | table.blink1, table.blink2, table.ilink1, | ||
1685 | table.ilink2, table.bcon_time, table.gp1, | ||
1686 | table.gp2, table.gp3, table.ucode_ver, | ||
1687 | table.hw_ver, table.brd_ver); | ||
1688 | IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id, | ||
1689 | desc_lookup(table.error_id)); | ||
1690 | IWL_ERR(priv, "0x%08X | uPc\n", table.pc); | ||
1691 | IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1); | ||
1692 | IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2); | ||
1693 | IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1); | ||
1694 | IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2); | ||
1695 | IWL_ERR(priv, "0x%08X | data1\n", table.data1); | ||
1696 | IWL_ERR(priv, "0x%08X | data2\n", table.data2); | ||
1697 | IWL_ERR(priv, "0x%08X | line\n", table.line); | ||
1698 | IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time); | ||
1699 | IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low); | ||
1700 | IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi); | ||
1701 | IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1); | ||
1702 | IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2); | ||
1703 | IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3); | ||
1704 | IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver); | ||
1705 | IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver); | ||
1706 | IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver); | ||
1707 | IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd); | ||
1708 | IWL_ERR(priv, "0x%08X | isr0\n", table.isr0); | ||
1709 | IWL_ERR(priv, "0x%08X | isr1\n", table.isr1); | ||
1710 | IWL_ERR(priv, "0x%08X | isr2\n", table.isr2); | ||
1711 | IWL_ERR(priv, "0x%08X | isr3\n", table.isr3); | ||
1712 | IWL_ERR(priv, "0x%08X | isr4\n", table.isr4); | ||
1713 | IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref); | ||
1714 | IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event); | ||
1715 | IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control); | ||
1716 | IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration); | ||
1717 | IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid); | ||
1718 | IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match); | ||
1719 | IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel); | ||
1720 | IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp); | ||
1721 | IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler); | ||
1722 | } | ||
1723 | |||
1724 | #define EVENT_START_OFFSET (4 * sizeof(u32)) | ||
1725 | |||
1726 | /** | ||
1727 | * iwl_print_event_log - Dump error event log to syslog | ||
1728 | * | ||
1729 | */ | ||
1730 | static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, | ||
1731 | u32 num_events, u32 mode, | ||
1732 | int pos, char **buf, size_t bufsz) | ||
1733 | { | ||
1734 | u32 i; | ||
1735 | u32 base; /* SRAM byte address of event log header */ | ||
1736 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ | ||
1737 | u32 ptr; /* SRAM byte address of log data */ | ||
1738 | u32 ev, time, data; /* event log data */ | ||
1739 | unsigned long reg_flags; | ||
1740 | |||
1741 | struct iwl_trans *trans = priv->trans; | ||
1742 | |||
1743 | if (num_events == 0) | ||
1744 | return pos; | ||
1745 | |||
1746 | base = priv->device_pointers.log_event_table; | ||
1747 | if (priv->cur_ucode == IWL_UCODE_INIT) { | ||
1748 | if (!base) | ||
1749 | base = priv->fw->init_evtlog_ptr; | ||
1750 | } else { | ||
1751 | if (!base) | ||
1752 | base = priv->fw->inst_evtlog_ptr; | ||
1753 | } | ||
1754 | |||
1755 | if (mode == 0) | ||
1756 | event_size = 2 * sizeof(u32); | ||
1757 | else | ||
1758 | event_size = 3 * sizeof(u32); | ||
1759 | |||
1760 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); | ||
1761 | |||
1762 | /* Make sure device is powered up for SRAM reads */ | ||
1763 | spin_lock_irqsave(&trans->reg_lock, reg_flags); | ||
1764 | if (unlikely(!iwl_grab_nic_access(trans))) | ||
1765 | goto out_unlock; | ||
1766 | |||
1767 | /* Set starting address; reads will auto-increment */ | ||
1768 | iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr); | ||
1769 | |||
1770 | /* "time" is actually "data" for mode 0 (no timestamp). | ||
1771 | * place event id # at far right for easier visual parsing. */ | ||
1772 | for (i = 0; i < num_events; i++) { | ||
1773 | ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT); | ||
1774 | time = iwl_read32(trans, HBUS_TARG_MEM_RDAT); | ||
1775 | if (mode == 0) { | ||
1776 | /* data, ev */ | ||
1777 | if (bufsz) { | ||
1778 | pos += scnprintf(*buf + pos, bufsz - pos, | ||
1779 | "EVT_LOG:0x%08x:%04u\n", | ||
1780 | time, ev); | ||
1781 | } else { | ||
1782 | trace_iwlwifi_dev_ucode_event(trans->dev, 0, | ||
1783 | time, ev); | ||
1784 | IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", | ||
1785 | time, ev); | ||
1786 | } | ||
1787 | } else { | ||
1788 | data = iwl_read32(trans, HBUS_TARG_MEM_RDAT); | ||
1789 | if (bufsz) { | ||
1790 | pos += scnprintf(*buf + pos, bufsz - pos, | ||
1791 | "EVT_LOGT:%010u:0x%08x:%04u\n", | ||
1792 | time, data, ev); | ||
1793 | } else { | ||
1794 | IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n", | ||
1795 | time, data, ev); | ||
1796 | trace_iwlwifi_dev_ucode_event(trans->dev, time, | ||
1797 | data, ev); | ||
1798 | } | ||
1799 | } | ||
1800 | } | ||
1801 | |||
1802 | /* Allow device to power down */ | ||
1803 | iwl_release_nic_access(trans); | ||
1804 | out_unlock: | ||
1805 | spin_unlock_irqrestore(&trans->reg_lock, reg_flags); | ||
1806 | return pos; | ||
1807 | } | ||
1808 | |||
1809 | /** | ||
1810 | * iwl_print_last_event_logs - Dump the newest # of event log to syslog | ||
1811 | */ | ||
1812 | static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity, | ||
1813 | u32 num_wraps, u32 next_entry, | ||
1814 | u32 size, u32 mode, | ||
1815 | int pos, char **buf, size_t bufsz) | ||
1816 | { | ||
1817 | /* | ||
1818 | * display the newest DEFAULT_LOG_ENTRIES entries | ||
1819 | * i.e the entries just before the next ont that uCode would fill. | ||
1820 | */ | ||
1821 | if (num_wraps) { | ||
1822 | if (next_entry < size) { | ||
1823 | pos = iwl_print_event_log(priv, | ||
1824 | capacity - (size - next_entry), | ||
1825 | size - next_entry, mode, | ||
1826 | pos, buf, bufsz); | ||
1827 | pos = iwl_print_event_log(priv, 0, | ||
1828 | next_entry, mode, | ||
1829 | pos, buf, bufsz); | ||
1830 | } else | ||
1831 | pos = iwl_print_event_log(priv, next_entry - size, | ||
1832 | size, mode, pos, buf, bufsz); | ||
1833 | } else { | ||
1834 | if (next_entry < size) { | ||
1835 | pos = iwl_print_event_log(priv, 0, next_entry, | ||
1836 | mode, pos, buf, bufsz); | ||
1837 | } else { | ||
1838 | pos = iwl_print_event_log(priv, next_entry - size, | ||
1839 | size, mode, pos, buf, bufsz); | ||
1840 | } | ||
1841 | } | ||
1842 | return pos; | ||
1843 | } | ||
1844 | |||
1845 | #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20) | ||
1846 | |||
1847 | int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log, | ||
1848 | char **buf, bool display) | ||
1849 | { | ||
1850 | u32 base; /* SRAM byte address of event log header */ | ||
1851 | u32 capacity; /* event log capacity in # entries */ | ||
1852 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ | ||
1853 | u32 num_wraps; /* # times uCode wrapped to top of log */ | ||
1854 | u32 next_entry; /* index of next entry to be written by uCode */ | ||
1855 | u32 size; /* # entries that we'll print */ | ||
1856 | u32 logsize; | ||
1857 | int pos = 0; | ||
1858 | size_t bufsz = 0; | ||
1859 | struct iwl_trans *trans = priv->trans; | ||
1860 | |||
1861 | base = priv->device_pointers.log_event_table; | ||
1862 | if (priv->cur_ucode == IWL_UCODE_INIT) { | ||
1863 | logsize = priv->fw->init_evtlog_size; | ||
1864 | if (!base) | ||
1865 | base = priv->fw->init_evtlog_ptr; | ||
1866 | } else { | ||
1867 | logsize = priv->fw->inst_evtlog_size; | ||
1868 | if (!base) | ||
1869 | base = priv->fw->inst_evtlog_ptr; | ||
1870 | } | ||
1871 | |||
1872 | if (!iwlagn_hw_valid_rtc_data_addr(base)) { | ||
1873 | IWL_ERR(priv, | ||
1874 | "Invalid event log pointer 0x%08X for %s uCode\n", | ||
1875 | base, | ||
1876 | (priv->cur_ucode == IWL_UCODE_INIT) | ||
1877 | ? "Init" : "RT"); | ||
1878 | return -EINVAL; | ||
1879 | } | ||
1880 | |||
1881 | /* event log header */ | ||
1882 | capacity = iwl_read_targ_mem(trans, base); | ||
1883 | mode = iwl_read_targ_mem(trans, base + (1 * sizeof(u32))); | ||
1884 | num_wraps = iwl_read_targ_mem(trans, base + (2 * sizeof(u32))); | ||
1885 | next_entry = iwl_read_targ_mem(trans, base + (3 * sizeof(u32))); | ||
1886 | |||
1887 | if (capacity > logsize) { | ||
1888 | IWL_ERR(priv, "Log capacity %d is bogus, limit to %d " | ||
1889 | "entries\n", capacity, logsize); | ||
1890 | capacity = logsize; | ||
1891 | } | ||
1892 | |||
1893 | if (next_entry > logsize) { | ||
1894 | IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n", | ||
1895 | next_entry, logsize); | ||
1896 | next_entry = logsize; | ||
1897 | } | ||
1898 | |||
1899 | size = num_wraps ? capacity : next_entry; | ||
1900 | |||
1901 | /* bail out if nothing in log */ | ||
1902 | if (size == 0) { | ||
1903 | IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n"); | ||
1904 | return pos; | ||
1905 | } | ||
1906 | |||
1907 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
1908 | if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log) | ||
1909 | size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES) | ||
1910 | ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size; | ||
1911 | #else | ||
1912 | size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES) | ||
1913 | ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size; | ||
1914 | #endif | ||
1915 | IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n", | ||
1916 | size); | ||
1917 | |||
1918 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
1919 | if (display) { | ||
1920 | if (full_log) | ||
1921 | bufsz = capacity * 48; | ||
1922 | else | ||
1923 | bufsz = size * 48; | ||
1924 | *buf = kmalloc(bufsz, GFP_KERNEL); | ||
1925 | if (!*buf) | ||
1926 | return -ENOMEM; | ||
1927 | } | ||
1928 | if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) { | ||
1929 | /* | ||
1930 | * if uCode has wrapped back to top of log, | ||
1931 | * start at the oldest entry, | ||
1932 | * i.e the next one that uCode would fill. | ||
1933 | */ | ||
1934 | if (num_wraps) | ||
1935 | pos = iwl_print_event_log(priv, next_entry, | ||
1936 | capacity - next_entry, mode, | ||
1937 | pos, buf, bufsz); | ||
1938 | /* (then/else) start at top of log */ | ||
1939 | pos = iwl_print_event_log(priv, 0, | ||
1940 | next_entry, mode, pos, buf, bufsz); | ||
1941 | } else | ||
1942 | pos = iwl_print_last_event_logs(priv, capacity, num_wraps, | ||
1943 | next_entry, size, mode, | ||
1944 | pos, buf, bufsz); | ||
1945 | #else | ||
1946 | pos = iwl_print_last_event_logs(priv, capacity, num_wraps, | ||
1947 | next_entry, size, mode, | ||
1948 | pos, buf, bufsz); | ||
1949 | #endif | ||
1950 | return pos; | ||
1951 | } | ||
1952 | |||
1953 | static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand) | ||
1954 | { | ||
1955 | unsigned int reload_msec; | ||
1956 | unsigned long reload_jiffies; | ||
1957 | |||
1958 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
1959 | if (iwl_have_debug_level(IWL_DL_FW_ERRORS)) | ||
1960 | iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS); | ||
1961 | #endif | ||
1962 | |||
1963 | /* uCode is no longer loaded. */ | ||
1964 | priv->ucode_loaded = false; | ||
1965 | |||
1966 | /* Set the FW error flag -- cleared on iwl_down */ | ||
1967 | set_bit(STATUS_FW_ERROR, &priv->status); | ||
1968 | |||
1969 | iwl_abort_notification_waits(&priv->notif_wait); | ||
1970 | |||
1971 | /* Keep the restart process from trying to send host | ||
1972 | * commands by clearing the ready bit */ | ||
1973 | clear_bit(STATUS_READY, &priv->status); | ||
1974 | |||
1975 | wake_up(&priv->trans->wait_command_queue); | ||
1976 | |||
1977 | if (!ondemand) { | ||
1978 | /* | ||
1979 | * If firmware keep reloading, then it indicate something | ||
1980 | * serious wrong and firmware having problem to recover | ||
1981 | * from it. Instead of keep trying which will fill the syslog | ||
1982 | * and hang the system, let's just stop it | ||
1983 | */ | ||
1984 | reload_jiffies = jiffies; | ||
1985 | reload_msec = jiffies_to_msecs((long) reload_jiffies - | ||
1986 | (long) priv->reload_jiffies); | ||
1987 | priv->reload_jiffies = reload_jiffies; | ||
1988 | if (reload_msec <= IWL_MIN_RELOAD_DURATION) { | ||
1989 | priv->reload_count++; | ||
1990 | if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) { | ||
1991 | IWL_ERR(priv, "BUG_ON, Stop restarting\n"); | ||
1992 | return; | ||
1993 | } | ||
1994 | } else | ||
1995 | priv->reload_count = 0; | ||
1996 | } | ||
1997 | |||
1998 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { | ||
1999 | if (iwlwifi_mod_params.restart_fw) { | ||
2000 | IWL_DEBUG_FW_ERRORS(priv, | ||
2001 | "Restarting adapter due to uCode error.\n"); | ||
2002 | queue_work(priv->workqueue, &priv->restart); | ||
2003 | } else | ||
2004 | IWL_DEBUG_FW_ERRORS(priv, | ||
2005 | "Detected FW error, but not restarting\n"); | ||
2006 | } | ||
2007 | } | ||
2008 | |||
2009 | static void iwl_nic_error(struct iwl_op_mode *op_mode) | ||
2010 | { | ||
2011 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2012 | |||
2013 | IWL_ERR(priv, "Loaded firmware version: %s\n", | ||
2014 | priv->fw->fw_version); | ||
2015 | |||
2016 | iwl_dump_nic_error_log(priv); | ||
2017 | iwl_dump_nic_event_log(priv, false, NULL, false); | ||
2018 | |||
2019 | iwlagn_fw_error(priv, false); | ||
2020 | } | ||
2021 | |||
2022 | static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode) | ||
2023 | { | ||
2024 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2025 | |||
2026 | if (!iwl_check_for_ct_kill(priv)) { | ||
2027 | IWL_ERR(priv, "Restarting adapter queue is full\n"); | ||
2028 | iwlagn_fw_error(priv, false); | ||
2029 | } | ||
2030 | } | ||
2031 | |||
2032 | #define EEPROM_RF_CONFIG_TYPE_MAX 0x3 | ||
2033 | |||
2034 | static void iwl_nic_config(struct iwl_op_mode *op_mode) | ||
2035 | { | ||
2036 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2037 | u16 radio_cfg = priv->eeprom_data->radio_cfg; | ||
2038 | |||
2039 | /* SKU Control */ | ||
2040 | iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG, | ||
2041 | CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH | | ||
2042 | CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP, | ||
2043 | (CSR_HW_REV_STEP(priv->trans->hw_rev) << | ||
2044 | CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) | | ||
2045 | (CSR_HW_REV_DASH(priv->trans->hw_rev) << | ||
2046 | CSR_HW_IF_CONFIG_REG_POS_MAC_DASH)); | ||
2047 | |||
2048 | /* write radio config values to register */ | ||
2049 | if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX) { | ||
2050 | u32 reg_val = | ||
2051 | EEPROM_RF_CFG_TYPE_MSK(radio_cfg) << | ||
2052 | CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE | | ||
2053 | EEPROM_RF_CFG_STEP_MSK(radio_cfg) << | ||
2054 | CSR_HW_IF_CONFIG_REG_POS_PHY_STEP | | ||
2055 | EEPROM_RF_CFG_DASH_MSK(radio_cfg) << | ||
2056 | CSR_HW_IF_CONFIG_REG_POS_PHY_DASH; | ||
2057 | |||
2058 | iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG, | ||
2059 | CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE | | ||
2060 | CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP | | ||
2061 | CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH, reg_val); | ||
2062 | |||
2063 | IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n", | ||
2064 | EEPROM_RF_CFG_TYPE_MSK(radio_cfg), | ||
2065 | EEPROM_RF_CFG_STEP_MSK(radio_cfg), | ||
2066 | EEPROM_RF_CFG_DASH_MSK(radio_cfg)); | ||
2067 | } else { | ||
2068 | WARN_ON(1); | ||
2069 | } | ||
2070 | |||
2071 | /* set CSR_HW_CONFIG_REG for uCode use */ | ||
2072 | iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG, | ||
2073 | CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | | ||
2074 | CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); | ||
2075 | |||
2076 | priv->lib->nic_config(priv); | ||
2077 | } | ||
2078 | |||
2079 | static void iwl_wimax_active(struct iwl_op_mode *op_mode) | ||
2080 | { | ||
2081 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2082 | |||
2083 | clear_bit(STATUS_READY, &priv->status); | ||
2084 | IWL_ERR(priv, "RF is used by WiMAX\n"); | ||
2085 | } | ||
2086 | |||
2087 | static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue) | ||
2088 | { | ||
2089 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2090 | int mq = priv->queue_to_mac80211[queue]; | ||
2091 | |||
2092 | if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE)) | ||
2093 | return; | ||
2094 | |||
2095 | if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) { | ||
2096 | IWL_DEBUG_TX_QUEUES(priv, | ||
2097 | "queue %d (mac80211 %d) already stopped\n", | ||
2098 | queue, mq); | ||
2099 | return; | ||
2100 | } | ||
2101 | |||
2102 | set_bit(mq, &priv->transport_queue_stop); | ||
2103 | ieee80211_stop_queue(priv->hw, mq); | ||
2104 | } | ||
2105 | |||
2106 | static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue) | ||
2107 | { | ||
2108 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2109 | int mq = priv->queue_to_mac80211[queue]; | ||
2110 | |||
2111 | if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE)) | ||
2112 | return; | ||
2113 | |||
2114 | if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) { | ||
2115 | IWL_DEBUG_TX_QUEUES(priv, | ||
2116 | "queue %d (mac80211 %d) already awake\n", | ||
2117 | queue, mq); | ||
2118 | return; | ||
2119 | } | ||
2120 | |||
2121 | clear_bit(mq, &priv->transport_queue_stop); | ||
2122 | |||
2123 | if (!priv->passive_no_rx) | ||
2124 | ieee80211_wake_queue(priv->hw, mq); | ||
2125 | } | ||
2126 | |||
2127 | void iwlagn_lift_passive_no_rx(struct iwl_priv *priv) | ||
2128 | { | ||
2129 | int mq; | ||
2130 | |||
2131 | if (!priv->passive_no_rx) | ||
2132 | return; | ||
2133 | |||
2134 | for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) { | ||
2135 | if (!test_bit(mq, &priv->transport_queue_stop)) { | ||
2136 | IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d", mq); | ||
2137 | ieee80211_wake_queue(priv->hw, mq); | ||
2138 | } else { | ||
2139 | IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d", mq); | ||
2140 | } | ||
2141 | } | ||
2142 | |||
2143 | priv->passive_no_rx = false; | ||
2144 | } | ||
2145 | |||
2146 | static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb) | ||
2147 | { | ||
2148 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2149 | struct ieee80211_tx_info *info; | ||
2150 | |||
2151 | info = IEEE80211_SKB_CB(skb); | ||
2152 | iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]); | ||
2153 | dev_kfree_skb_any(skb); | ||
2154 | } | ||
2155 | |||
2156 | static void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state) | ||
2157 | { | ||
2158 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
2159 | |||
2160 | if (state) | ||
2161 | set_bit(STATUS_RF_KILL_HW, &priv->status); | ||
2162 | else | ||
2163 | clear_bit(STATUS_RF_KILL_HW, &priv->status); | ||
2164 | |||
2165 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, state); | ||
2166 | } | ||
2167 | |||
2168 | static const struct iwl_op_mode_ops iwl_dvm_ops = { | ||
2169 | .start = iwl_op_mode_dvm_start, | ||
2170 | .stop = iwl_op_mode_dvm_stop, | ||
2171 | .rx = iwl_rx_dispatch, | ||
2172 | .queue_full = iwl_stop_sw_queue, | ||
2173 | .queue_not_full = iwl_wake_sw_queue, | ||
2174 | .hw_rf_kill = iwl_set_hw_rfkill_state, | ||
2175 | .free_skb = iwl_free_skb, | ||
2176 | .nic_error = iwl_nic_error, | ||
2177 | .cmd_queue_full = iwl_cmd_queue_full, | ||
2178 | .nic_config = iwl_nic_config, | ||
2179 | .wimax_active = iwl_wimax_active, | ||
2180 | }; | ||
2181 | |||
2182 | /***************************************************************************** | ||
2183 | * | ||
2184 | * driver and module entry point | ||
2185 | * | ||
2186 | *****************************************************************************/ | ||
2187 | static int __init iwl_init(void) | ||
2188 | { | ||
2189 | |||
2190 | int ret; | ||
2191 | pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n"); | ||
2192 | pr_info(DRV_COPYRIGHT "\n"); | ||
2193 | |||
2194 | ret = iwlagn_rate_control_register(); | ||
2195 | if (ret) { | ||
2196 | pr_err("Unable to register rate control algorithm: %d\n", ret); | ||
2197 | return ret; | ||
2198 | } | ||
2199 | |||
2200 | ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops); | ||
2201 | if (ret) { | ||
2202 | pr_err("Unable to register op_mode: %d\n", ret); | ||
2203 | iwlagn_rate_control_unregister(); | ||
2204 | } | ||
2205 | |||
2206 | return ret; | ||
2207 | } | ||
2208 | module_init(iwl_init); | ||
2209 | |||
2210 | static void __exit iwl_exit(void) | ||
2211 | { | ||
2212 | iwl_opmode_deregister("iwldvm"); | ||
2213 | iwlagn_rate_control_unregister(); | ||
2214 | } | ||
2215 | module_exit(iwl_exit); | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/power.c b/drivers/net/wireless/iwlwifi/dvm/power.c new file mode 100644 index 000000000000..518cf3715809 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/power.c | |||
@@ -0,0 +1,387 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2007 - 2012 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 | |||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include <linux/init.h> | ||
34 | #include <net/mac80211.h> | ||
35 | #include "iwl-io.h" | ||
36 | #include "iwl-debug.h" | ||
37 | #include "iwl-trans.h" | ||
38 | #include "iwl-modparams.h" | ||
39 | #include "dev.h" | ||
40 | #include "agn.h" | ||
41 | #include "commands.h" | ||
42 | #include "power.h" | ||
43 | |||
44 | /* | ||
45 | * Setting power level allows the card to go to sleep when not busy. | ||
46 | * | ||
47 | * We calculate a sleep command based on the required latency, which | ||
48 | * we get from mac80211. In order to handle thermal throttling, we can | ||
49 | * also use pre-defined power levels. | ||
50 | */ | ||
51 | |||
52 | /* | ||
53 | * This defines the old power levels. They are still used by default | ||
54 | * (level 1) and for thermal throttle (levels 3 through 5) | ||
55 | */ | ||
56 | |||
57 | struct iwl_power_vec_entry { | ||
58 | struct iwl_powertable_cmd cmd; | ||
59 | u8 no_dtim; /* number of skip dtim */ | ||
60 | }; | ||
61 | |||
62 | #define IWL_DTIM_RANGE_0_MAX 2 | ||
63 | #define IWL_DTIM_RANGE_1_MAX 10 | ||
64 | |||
65 | #define NOSLP cpu_to_le16(0), 0, 0 | ||
66 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 | ||
67 | #define ASLP (IWL_POWER_POWER_SAVE_ENA_MSK | \ | ||
68 | IWL_POWER_POWER_MANAGEMENT_ENA_MSK | \ | ||
69 | IWL_POWER_ADVANCE_PM_ENA_MSK) | ||
70 | #define ASLP_TOUT(T) cpu_to_le32(T) | ||
71 | #define TU_TO_USEC 1024 | ||
72 | #define SLP_TOUT(T) cpu_to_le32((T) * TU_TO_USEC) | ||
73 | #define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \ | ||
74 | cpu_to_le32(X1), \ | ||
75 | cpu_to_le32(X2), \ | ||
76 | cpu_to_le32(X3), \ | ||
77 | cpu_to_le32(X4)} | ||
78 | /* default power management (not Tx power) table values */ | ||
79 | /* for DTIM period 0 through IWL_DTIM_RANGE_0_MAX */ | ||
80 | /* DTIM 0 - 2 */ | ||
81 | static const struct iwl_power_vec_entry range_0[IWL_POWER_NUM] = { | ||
82 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 1, 2, 2, 0xFF)}, 0}, | ||
83 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, | ||
84 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0}, | ||
85 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1}, | ||
86 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2} | ||
87 | }; | ||
88 | |||
89 | |||
90 | /* for DTIM period IWL_DTIM_RANGE_0_MAX + 1 through IWL_DTIM_RANGE_1_MAX */ | ||
91 | /* DTIM 3 - 10 */ | ||
92 | static const struct iwl_power_vec_entry range_1[IWL_POWER_NUM] = { | ||
93 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, | ||
94 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0}, | ||
95 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0}, | ||
96 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1}, | ||
97 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 6, 10, 10)}, 2} | ||
98 | }; | ||
99 | |||
100 | /* for DTIM period > IWL_DTIM_RANGE_1_MAX */ | ||
101 | /* DTIM 11 - */ | ||
102 | static const struct iwl_power_vec_entry range_2[IWL_POWER_NUM] = { | ||
103 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, | ||
104 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, | ||
105 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, | ||
106 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, | ||
107 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} | ||
108 | }; | ||
109 | |||
110 | /* advance power management */ | ||
111 | /* DTIM 0 - 2 */ | ||
112 | static const struct iwl_power_vec_entry apm_range_0[IWL_POWER_NUM] = { | ||
113 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
114 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
115 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
116 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
117 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
118 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
119 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
120 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
121 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
122 | SLP_VEC(1, 2, 6, 8, 0xFF), ASLP_TOUT(2)}, 2} | ||
123 | }; | ||
124 | |||
125 | |||
126 | /* for DTIM period IWL_DTIM_RANGE_0_MAX + 1 through IWL_DTIM_RANGE_1_MAX */ | ||
127 | /* DTIM 3 - 10 */ | ||
128 | static const struct iwl_power_vec_entry apm_range_1[IWL_POWER_NUM] = { | ||
129 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
130 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
131 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
132 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
133 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
134 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
135 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
136 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
137 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
138 | SLP_VEC(1, 2, 6, 8, 0xFF), 0}, 2} | ||
139 | }; | ||
140 | |||
141 | /* for DTIM period > IWL_DTIM_RANGE_1_MAX */ | ||
142 | /* DTIM 11 - */ | ||
143 | static const struct iwl_power_vec_entry apm_range_2[IWL_POWER_NUM] = { | ||
144 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
145 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
146 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
147 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
148 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
149 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
150 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
151 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
152 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
153 | SLP_VEC(1, 2, 6, 8, 0xFF), ASLP_TOUT(2)}, 2} | ||
154 | }; | ||
155 | |||
156 | static void iwl_static_sleep_cmd(struct iwl_priv *priv, | ||
157 | struct iwl_powertable_cmd *cmd, | ||
158 | enum iwl_power_level lvl, int period) | ||
159 | { | ||
160 | const struct iwl_power_vec_entry *table; | ||
161 | int max_sleep[IWL_POWER_VEC_SIZE] = { 0 }; | ||
162 | int i; | ||
163 | u8 skip; | ||
164 | u32 slp_itrvl; | ||
165 | |||
166 | if (priv->cfg->adv_pm) { | ||
167 | table = apm_range_2; | ||
168 | if (period <= IWL_DTIM_RANGE_1_MAX) | ||
169 | table = apm_range_1; | ||
170 | if (period <= IWL_DTIM_RANGE_0_MAX) | ||
171 | table = apm_range_0; | ||
172 | } else { | ||
173 | table = range_2; | ||
174 | if (period <= IWL_DTIM_RANGE_1_MAX) | ||
175 | table = range_1; | ||
176 | if (period <= IWL_DTIM_RANGE_0_MAX) | ||
177 | table = range_0; | ||
178 | } | ||
179 | |||
180 | if (WARN_ON(lvl < 0 || lvl >= IWL_POWER_NUM)) | ||
181 | memset(cmd, 0, sizeof(*cmd)); | ||
182 | else | ||
183 | *cmd = table[lvl].cmd; | ||
184 | |||
185 | if (period == 0) { | ||
186 | skip = 0; | ||
187 | period = 1; | ||
188 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) | ||
189 | max_sleep[i] = 1; | ||
190 | |||
191 | } else { | ||
192 | skip = table[lvl].no_dtim; | ||
193 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) | ||
194 | max_sleep[i] = le32_to_cpu(cmd->sleep_interval[i]); | ||
195 | max_sleep[IWL_POWER_VEC_SIZE - 1] = skip + 1; | ||
196 | } | ||
197 | |||
198 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); | ||
199 | /* figure out the listen interval based on dtim period and skip */ | ||
200 | if (slp_itrvl == 0xFF) | ||
201 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = | ||
202 | cpu_to_le32(period * (skip + 1)); | ||
203 | |||
204 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); | ||
205 | if (slp_itrvl > period) | ||
206 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = | ||
207 | cpu_to_le32((slp_itrvl / period) * period); | ||
208 | |||
209 | if (skip) | ||
210 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; | ||
211 | else | ||
212 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; | ||
213 | |||
214 | if (priv->cfg->base_params->shadow_reg_enable) | ||
215 | cmd->flags |= IWL_POWER_SHADOW_REG_ENA; | ||
216 | else | ||
217 | cmd->flags &= ~IWL_POWER_SHADOW_REG_ENA; | ||
218 | |||
219 | if (iwl_advanced_bt_coexist(priv)) { | ||
220 | if (!priv->cfg->bt_params->bt_sco_disable) | ||
221 | cmd->flags |= IWL_POWER_BT_SCO_ENA; | ||
222 | else | ||
223 | cmd->flags &= ~IWL_POWER_BT_SCO_ENA; | ||
224 | } | ||
225 | |||
226 | |||
227 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); | ||
228 | if (slp_itrvl > IWL_CONN_MAX_LISTEN_INTERVAL) | ||
229 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = | ||
230 | cpu_to_le32(IWL_CONN_MAX_LISTEN_INTERVAL); | ||
231 | |||
232 | /* enforce max sleep interval */ | ||
233 | for (i = IWL_POWER_VEC_SIZE - 1; i >= 0 ; i--) { | ||
234 | if (le32_to_cpu(cmd->sleep_interval[i]) > | ||
235 | (max_sleep[i] * period)) | ||
236 | cmd->sleep_interval[i] = | ||
237 | cpu_to_le32(max_sleep[i] * period); | ||
238 | if (i != (IWL_POWER_VEC_SIZE - 1)) { | ||
239 | if (le32_to_cpu(cmd->sleep_interval[i]) > | ||
240 | le32_to_cpu(cmd->sleep_interval[i+1])) | ||
241 | cmd->sleep_interval[i] = | ||
242 | cmd->sleep_interval[i+1]; | ||
243 | } | ||
244 | } | ||
245 | |||
246 | if (priv->power_data.bus_pm) | ||
247 | cmd->flags |= IWL_POWER_PCI_PM_MSK; | ||
248 | else | ||
249 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; | ||
250 | |||
251 | IWL_DEBUG_POWER(priv, "numSkipDtim = %u, dtimPeriod = %d\n", | ||
252 | skip, period); | ||
253 | /* The power level here is 0-4 (used as array index), but user expects | ||
254 | to see 1-5 (according to spec). */ | ||
255 | IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1); | ||
256 | } | ||
257 | |||
258 | static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv, | ||
259 | struct iwl_powertable_cmd *cmd) | ||
260 | { | ||
261 | memset(cmd, 0, sizeof(*cmd)); | ||
262 | |||
263 | if (priv->power_data.bus_pm) | ||
264 | cmd->flags |= IWL_POWER_PCI_PM_MSK; | ||
265 | |||
266 | IWL_DEBUG_POWER(priv, "Sleep command for CAM\n"); | ||
267 | } | ||
268 | |||
269 | static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd) | ||
270 | { | ||
271 | IWL_DEBUG_POWER(priv, "Sending power/sleep command\n"); | ||
272 | IWL_DEBUG_POWER(priv, "Flags value = 0x%08X\n", cmd->flags); | ||
273 | IWL_DEBUG_POWER(priv, "Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); | ||
274 | IWL_DEBUG_POWER(priv, "Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); | ||
275 | IWL_DEBUG_POWER(priv, "Sleep interval vector = { %d , %d , %d , %d , %d }\n", | ||
276 | le32_to_cpu(cmd->sleep_interval[0]), | ||
277 | le32_to_cpu(cmd->sleep_interval[1]), | ||
278 | le32_to_cpu(cmd->sleep_interval[2]), | ||
279 | le32_to_cpu(cmd->sleep_interval[3]), | ||
280 | le32_to_cpu(cmd->sleep_interval[4])); | ||
281 | |||
282 | return iwl_dvm_send_cmd_pdu(priv, POWER_TABLE_CMD, CMD_SYNC, | ||
283 | sizeof(struct iwl_powertable_cmd), cmd); | ||
284 | } | ||
285 | |||
286 | static void iwl_power_build_cmd(struct iwl_priv *priv, | ||
287 | struct iwl_powertable_cmd *cmd) | ||
288 | { | ||
289 | bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS; | ||
290 | int dtimper; | ||
291 | |||
292 | dtimper = priv->hw->conf.ps_dtim_period ?: 1; | ||
293 | |||
294 | if (priv->wowlan) | ||
295 | iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_5, dtimper); | ||
296 | else if (!priv->cfg->base_params->no_idle_support && | ||
297 | priv->hw->conf.flags & IEEE80211_CONF_IDLE) | ||
298 | iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_5, 20); | ||
299 | else if (iwl_tt_is_low_power_state(priv)) { | ||
300 | /* in thermal throttling low power state */ | ||
301 | iwl_static_sleep_cmd(priv, cmd, | ||
302 | iwl_tt_current_power_mode(priv), dtimper); | ||
303 | } else if (!enabled) | ||
304 | iwl_power_sleep_cam_cmd(priv, cmd); | ||
305 | else if (priv->power_data.debug_sleep_level_override >= 0) | ||
306 | iwl_static_sleep_cmd(priv, cmd, | ||
307 | priv->power_data.debug_sleep_level_override, | ||
308 | dtimper); | ||
309 | else { | ||
310 | /* Note that the user parameter is 1-5 (according to spec), | ||
311 | but we pass 0-4 because it acts as an array index. */ | ||
312 | if (iwlwifi_mod_params.power_level > IWL_POWER_INDEX_1 && | ||
313 | iwlwifi_mod_params.power_level <= IWL_POWER_NUM) | ||
314 | iwl_static_sleep_cmd(priv, cmd, | ||
315 | iwlwifi_mod_params.power_level - 1, dtimper); | ||
316 | else | ||
317 | iwl_static_sleep_cmd(priv, cmd, | ||
318 | IWL_POWER_INDEX_1, dtimper); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | int iwl_power_set_mode(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd, | ||
323 | bool force) | ||
324 | { | ||
325 | int ret; | ||
326 | bool update_chains; | ||
327 | |||
328 | lockdep_assert_held(&priv->mutex); | ||
329 | |||
330 | /* Don't update the RX chain when chain noise calibration is running */ | ||
331 | update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE || | ||
332 | priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE; | ||
333 | |||
334 | if (!memcmp(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd)) && !force) | ||
335 | return 0; | ||
336 | |||
337 | if (!iwl_is_ready_rf(priv)) | ||
338 | return -EIO; | ||
339 | |||
340 | /* scan complete use sleep_power_next, need to be updated */ | ||
341 | memcpy(&priv->power_data.sleep_cmd_next, cmd, sizeof(*cmd)); | ||
342 | if (test_bit(STATUS_SCANNING, &priv->status) && !force) { | ||
343 | IWL_DEBUG_INFO(priv, "Defer power set mode while scanning\n"); | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | if (cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK) | ||
348 | iwl_dvm_set_pmi(priv, true); | ||
349 | |||
350 | ret = iwl_set_power(priv, cmd); | ||
351 | if (!ret) { | ||
352 | if (!(cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK)) | ||
353 | iwl_dvm_set_pmi(priv, false); | ||
354 | |||
355 | if (update_chains) | ||
356 | iwl_update_chain_flags(priv); | ||
357 | else | ||
358 | IWL_DEBUG_POWER(priv, | ||
359 | "Cannot update the power, chain noise " | ||
360 | "calibration running: %d\n", | ||
361 | priv->chain_noise_data.state); | ||
362 | |||
363 | memcpy(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd)); | ||
364 | } else | ||
365 | IWL_ERR(priv, "set power fail, ret = %d", ret); | ||
366 | |||
367 | return ret; | ||
368 | } | ||
369 | |||
370 | int iwl_power_update_mode(struct iwl_priv *priv, bool force) | ||
371 | { | ||
372 | struct iwl_powertable_cmd cmd; | ||
373 | |||
374 | iwl_power_build_cmd(priv, &cmd); | ||
375 | return iwl_power_set_mode(priv, &cmd, force); | ||
376 | } | ||
377 | |||
378 | /* initialize to default */ | ||
379 | void iwl_power_initialize(struct iwl_priv *priv) | ||
380 | { | ||
381 | priv->power_data.bus_pm = priv->trans->pm_support; | ||
382 | |||
383 | priv->power_data.debug_sleep_level_override = -1; | ||
384 | |||
385 | memset(&priv->power_data.sleep_cmd, 0, | ||
386 | sizeof(priv->power_data.sleep_cmd)); | ||
387 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/power.h b/drivers/net/wireless/iwlwifi/dvm/power.h new file mode 100644 index 000000000000..a2cee7f04848 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/power.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2007 - 2012 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_power_setting_h__ | ||
29 | #define __iwl_power_setting_h__ | ||
30 | |||
31 | #include "commands.h" | ||
32 | |||
33 | struct iwl_power_mgr { | ||
34 | struct iwl_powertable_cmd sleep_cmd; | ||
35 | struct iwl_powertable_cmd sleep_cmd_next; | ||
36 | int debug_sleep_level_override; | ||
37 | bool bus_pm; | ||
38 | }; | ||
39 | |||
40 | int iwl_power_set_mode(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd, | ||
41 | bool force); | ||
42 | int iwl_power_update_mode(struct iwl_priv *priv, bool force); | ||
43 | void iwl_power_initialize(struct iwl_priv *priv); | ||
44 | |||
45 | extern bool no_sleep_autoadjust; | ||
46 | |||
47 | #endif /* __iwl_power_setting_h__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/rs.c b/drivers/net/wireless/iwlwifi/dvm/rs.c new file mode 100644 index 000000000000..6fddd2785e6e --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/rs.c | |||
@@ -0,0 +1,3367 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of version 2 of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/skbuff.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <net/mac80211.h> | ||
31 | |||
32 | #include <linux/netdevice.h> | ||
33 | #include <linux/etherdevice.h> | ||
34 | #include <linux/delay.h> | ||
35 | |||
36 | #include <linux/workqueue.h> | ||
37 | |||
38 | #include "dev.h" | ||
39 | #include "agn.h" | ||
40 | |||
41 | #define RS_NAME "iwl-agn-rs" | ||
42 | |||
43 | #define NUM_TRY_BEFORE_ANT_TOGGLE 1 | ||
44 | #define IWL_NUMBER_TRY 1 | ||
45 | #define IWL_HT_NUMBER_TRY 3 | ||
46 | |||
47 | #define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */ | ||
48 | #define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */ | ||
49 | #define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */ | ||
50 | |||
51 | /* max allowed rate miss before sync LQ cmd */ | ||
52 | #define IWL_MISSED_RATE_MAX 15 | ||
53 | /* max time to accum history 2 seconds */ | ||
54 | #define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ) | ||
55 | |||
56 | static u8 rs_ht_to_legacy[] = { | ||
57 | IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, | ||
58 | IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, | ||
59 | IWL_RATE_6M_INDEX, | ||
60 | IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX, | ||
61 | IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX, | ||
62 | IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX, | ||
63 | IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX | ||
64 | }; | ||
65 | |||
66 | static const u8 ant_toggle_lookup[] = { | ||
67 | /*ANT_NONE -> */ ANT_NONE, | ||
68 | /*ANT_A -> */ ANT_B, | ||
69 | /*ANT_B -> */ ANT_C, | ||
70 | /*ANT_AB -> */ ANT_BC, | ||
71 | /*ANT_C -> */ ANT_A, | ||
72 | /*ANT_AC -> */ ANT_AB, | ||
73 | /*ANT_BC -> */ ANT_AC, | ||
74 | /*ANT_ABC -> */ ANT_ABC, | ||
75 | }; | ||
76 | |||
77 | #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \ | ||
78 | [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ | ||
79 | IWL_RATE_SISO_##s##M_PLCP, \ | ||
80 | IWL_RATE_MIMO2_##s##M_PLCP,\ | ||
81 | IWL_RATE_MIMO3_##s##M_PLCP,\ | ||
82 | IWL_RATE_##r##M_IEEE, \ | ||
83 | IWL_RATE_##ip##M_INDEX, \ | ||
84 | IWL_RATE_##in##M_INDEX, \ | ||
85 | IWL_RATE_##rp##M_INDEX, \ | ||
86 | IWL_RATE_##rn##M_INDEX, \ | ||
87 | IWL_RATE_##pp##M_INDEX, \ | ||
88 | IWL_RATE_##np##M_INDEX } | ||
89 | |||
90 | /* | ||
91 | * Parameter order: | ||
92 | * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate | ||
93 | * | ||
94 | * If there isn't a valid next or previous rate then INV is used which | ||
95 | * maps to IWL_RATE_INVALID | ||
96 | * | ||
97 | */ | ||
98 | const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = { | ||
99 | IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */ | ||
100 | IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */ | ||
101 | IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */ | ||
102 | IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */ | ||
103 | IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */ | ||
104 | IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */ | ||
105 | IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */ | ||
106 | IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */ | ||
107 | IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */ | ||
108 | IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */ | ||
109 | IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */ | ||
110 | IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */ | ||
111 | IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */ | ||
112 | /* FIXME:RS: ^^ should be INV (legacy) */ | ||
113 | }; | ||
114 | |||
115 | static inline u8 rs_extract_rate(u32 rate_n_flags) | ||
116 | { | ||
117 | return (u8)(rate_n_flags & RATE_MCS_RATE_MSK); | ||
118 | } | ||
119 | |||
120 | static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags) | ||
121 | { | ||
122 | int idx = 0; | ||
123 | |||
124 | /* HT rate format */ | ||
125 | if (rate_n_flags & RATE_MCS_HT_MSK) { | ||
126 | idx = rs_extract_rate(rate_n_flags); | ||
127 | |||
128 | if (idx >= IWL_RATE_MIMO3_6M_PLCP) | ||
129 | idx = idx - IWL_RATE_MIMO3_6M_PLCP; | ||
130 | else if (idx >= IWL_RATE_MIMO2_6M_PLCP) | ||
131 | idx = idx - IWL_RATE_MIMO2_6M_PLCP; | ||
132 | |||
133 | idx += IWL_FIRST_OFDM_RATE; | ||
134 | /* skip 9M not supported in ht*/ | ||
135 | if (idx >= IWL_RATE_9M_INDEX) | ||
136 | idx += 1; | ||
137 | if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE)) | ||
138 | return idx; | ||
139 | |||
140 | /* legacy rate format, search for match in table */ | ||
141 | } else { | ||
142 | for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++) | ||
143 | if (iwl_rates[idx].plcp == | ||
144 | rs_extract_rate(rate_n_flags)) | ||
145 | return idx; | ||
146 | } | ||
147 | |||
148 | return -1; | ||
149 | } | ||
150 | |||
151 | static void rs_rate_scale_perform(struct iwl_priv *priv, | ||
152 | struct sk_buff *skb, | ||
153 | struct ieee80211_sta *sta, | ||
154 | struct iwl_lq_sta *lq_sta); | ||
155 | static void rs_fill_link_cmd(struct iwl_priv *priv, | ||
156 | struct iwl_lq_sta *lq_sta, u32 rate_n_flags); | ||
157 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search); | ||
158 | |||
159 | |||
160 | #ifdef CONFIG_MAC80211_DEBUGFS | ||
161 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, | ||
162 | u32 *rate_n_flags, int index); | ||
163 | #else | ||
164 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, | ||
165 | u32 *rate_n_flags, int index) | ||
166 | {} | ||
167 | #endif | ||
168 | |||
169 | /** | ||
170 | * The following tables contain the expected throughput metrics for all rates | ||
171 | * | ||
172 | * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits | ||
173 | * | ||
174 | * where invalid entries are zeros. | ||
175 | * | ||
176 | * CCK rates are only valid in legacy table and will only be used in G | ||
177 | * (2.4 GHz) band. | ||
178 | */ | ||
179 | |||
180 | static s32 expected_tpt_legacy[IWL_RATE_COUNT] = { | ||
181 | 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0 | ||
182 | }; | ||
183 | |||
184 | static s32 expected_tpt_siso20MHz[4][IWL_RATE_COUNT] = { | ||
185 | {0, 0, 0, 0, 42, 0, 76, 102, 124, 159, 183, 193, 202}, /* Norm */ | ||
186 | {0, 0, 0, 0, 46, 0, 82, 110, 132, 168, 192, 202, 210}, /* SGI */ | ||
187 | {0, 0, 0, 0, 47, 0, 91, 133, 171, 242, 305, 334, 362}, /* AGG */ | ||
188 | {0, 0, 0, 0, 52, 0, 101, 145, 187, 264, 330, 361, 390}, /* AGG+SGI */ | ||
189 | }; | ||
190 | |||
191 | static s32 expected_tpt_siso40MHz[4][IWL_RATE_COUNT] = { | ||
192 | {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257}, /* Norm */ | ||
193 | {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264}, /* SGI */ | ||
194 | {0, 0, 0, 0, 94, 0, 177, 249, 313, 423, 512, 550, 586}, /* AGG */ | ||
195 | {0, 0, 0, 0, 104, 0, 193, 270, 338, 454, 545, 584, 620}, /* AGG+SGI */ | ||
196 | }; | ||
197 | |||
198 | static s32 expected_tpt_mimo2_20MHz[4][IWL_RATE_COUNT] = { | ||
199 | {0, 0, 0, 0, 74, 0, 123, 155, 179, 214, 236, 244, 251}, /* Norm */ | ||
200 | {0, 0, 0, 0, 81, 0, 131, 164, 188, 223, 243, 251, 257}, /* SGI */ | ||
201 | {0, 0, 0, 0, 89, 0, 167, 235, 296, 402, 488, 526, 560}, /* AGG */ | ||
202 | {0, 0, 0, 0, 97, 0, 182, 255, 320, 431, 520, 558, 593}, /* AGG+SGI*/ | ||
203 | }; | ||
204 | |||
205 | static s32 expected_tpt_mimo2_40MHz[4][IWL_RATE_COUNT] = { | ||
206 | {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289}, /* Norm */ | ||
207 | {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293}, /* SGI */ | ||
208 | {0, 0, 0, 0, 171, 0, 305, 410, 496, 634, 731, 771, 805}, /* AGG */ | ||
209 | {0, 0, 0, 0, 186, 0, 329, 439, 527, 667, 764, 803, 838}, /* AGG+SGI */ | ||
210 | }; | ||
211 | |||
212 | static s32 expected_tpt_mimo3_20MHz[4][IWL_RATE_COUNT] = { | ||
213 | {0, 0, 0, 0, 99, 0, 153, 186, 208, 239, 256, 263, 268}, /* Norm */ | ||
214 | {0, 0, 0, 0, 106, 0, 162, 194, 215, 246, 262, 268, 273}, /* SGI */ | ||
215 | {0, 0, 0, 0, 134, 0, 249, 346, 431, 574, 685, 732, 775}, /* AGG */ | ||
216 | {0, 0, 0, 0, 148, 0, 272, 376, 465, 614, 727, 775, 818}, /* AGG+SGI */ | ||
217 | }; | ||
218 | |||
219 | static s32 expected_tpt_mimo3_40MHz[4][IWL_RATE_COUNT] = { | ||
220 | {0, 0, 0, 0, 152, 0, 211, 239, 255, 279, 290, 294, 297}, /* Norm */ | ||
221 | {0, 0, 0, 0, 160, 0, 219, 245, 261, 284, 294, 297, 300}, /* SGI */ | ||
222 | {0, 0, 0, 0, 254, 0, 443, 584, 695, 868, 984, 1030, 1070}, /* AGG */ | ||
223 | {0, 0, 0, 0, 277, 0, 478, 624, 737, 911, 1026, 1070, 1109}, /* AGG+SGI */ | ||
224 | }; | ||
225 | |||
226 | /* mbps, mcs */ | ||
227 | static const struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = { | ||
228 | { "1", "BPSK DSSS"}, | ||
229 | { "2", "QPSK DSSS"}, | ||
230 | {"5.5", "BPSK CCK"}, | ||
231 | { "11", "QPSK CCK"}, | ||
232 | { "6", "BPSK 1/2"}, | ||
233 | { "9", "BPSK 1/2"}, | ||
234 | { "12", "QPSK 1/2"}, | ||
235 | { "18", "QPSK 3/4"}, | ||
236 | { "24", "16QAM 1/2"}, | ||
237 | { "36", "16QAM 3/4"}, | ||
238 | { "48", "64QAM 2/3"}, | ||
239 | { "54", "64QAM 3/4"}, | ||
240 | { "60", "64QAM 5/6"}, | ||
241 | }; | ||
242 | |||
243 | #define MCS_INDEX_PER_STREAM (8) | ||
244 | |||
245 | static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) | ||
246 | { | ||
247 | window->data = 0; | ||
248 | window->success_counter = 0; | ||
249 | window->success_ratio = IWL_INVALID_VALUE; | ||
250 | window->counter = 0; | ||
251 | window->average_tpt = IWL_INVALID_VALUE; | ||
252 | window->stamp = 0; | ||
253 | } | ||
254 | |||
255 | static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type) | ||
256 | { | ||
257 | return (ant_type & valid_antenna) == ant_type; | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | * removes the old data from the statistics. All data that is older than | ||
262 | * TID_MAX_TIME_DIFF, will be deleted. | ||
263 | */ | ||
264 | static void rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time) | ||
265 | { | ||
266 | /* The oldest age we want to keep */ | ||
267 | u32 oldest_time = curr_time - TID_MAX_TIME_DIFF; | ||
268 | |||
269 | while (tl->queue_count && | ||
270 | (tl->time_stamp < oldest_time)) { | ||
271 | tl->total -= tl->packet_count[tl->head]; | ||
272 | tl->packet_count[tl->head] = 0; | ||
273 | tl->time_stamp += TID_QUEUE_CELL_SPACING; | ||
274 | tl->queue_count--; | ||
275 | tl->head++; | ||
276 | if (tl->head >= TID_QUEUE_MAX_SIZE) | ||
277 | tl->head = 0; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | /* | ||
282 | * increment traffic load value for tid and also remove | ||
283 | * any old values if passed the certain time period | ||
284 | */ | ||
285 | static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data, | ||
286 | struct ieee80211_hdr *hdr) | ||
287 | { | ||
288 | u32 curr_time = jiffies_to_msecs(jiffies); | ||
289 | u32 time_diff; | ||
290 | s32 index; | ||
291 | struct iwl_traffic_load *tl = NULL; | ||
292 | u8 tid; | ||
293 | |||
294 | if (ieee80211_is_data_qos(hdr->frame_control)) { | ||
295 | u8 *qc = ieee80211_get_qos_ctl(hdr); | ||
296 | tid = qc[0] & 0xf; | ||
297 | } else | ||
298 | return IWL_MAX_TID_COUNT; | ||
299 | |||
300 | if (unlikely(tid >= IWL_MAX_TID_COUNT)) | ||
301 | return IWL_MAX_TID_COUNT; | ||
302 | |||
303 | tl = &lq_data->load[tid]; | ||
304 | |||
305 | curr_time -= curr_time % TID_ROUND_VALUE; | ||
306 | |||
307 | /* Happens only for the first packet. Initialize the data */ | ||
308 | if (!(tl->queue_count)) { | ||
309 | tl->total = 1; | ||
310 | tl->time_stamp = curr_time; | ||
311 | tl->queue_count = 1; | ||
312 | tl->head = 0; | ||
313 | tl->packet_count[0] = 1; | ||
314 | return IWL_MAX_TID_COUNT; | ||
315 | } | ||
316 | |||
317 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); | ||
318 | index = time_diff / TID_QUEUE_CELL_SPACING; | ||
319 | |||
320 | /* The history is too long: remove data that is older than */ | ||
321 | /* TID_MAX_TIME_DIFF */ | ||
322 | if (index >= TID_QUEUE_MAX_SIZE) | ||
323 | rs_tl_rm_old_stats(tl, curr_time); | ||
324 | |||
325 | index = (tl->head + index) % TID_QUEUE_MAX_SIZE; | ||
326 | tl->packet_count[index] = tl->packet_count[index] + 1; | ||
327 | tl->total = tl->total + 1; | ||
328 | |||
329 | if ((index + 1) > tl->queue_count) | ||
330 | tl->queue_count = index + 1; | ||
331 | |||
332 | return tid; | ||
333 | } | ||
334 | |||
335 | #ifdef CONFIG_MAC80211_DEBUGFS | ||
336 | /** | ||
337 | * Program the device to use fixed rate for frame transmit | ||
338 | * This is for debugging/testing only | ||
339 | * once the device start use fixed rate, we need to reload the module | ||
340 | * to being back the normal operation. | ||
341 | */ | ||
342 | static void rs_program_fix_rate(struct iwl_priv *priv, | ||
343 | struct iwl_lq_sta *lq_sta) | ||
344 | { | ||
345 | struct iwl_station_priv *sta_priv = | ||
346 | container_of(lq_sta, struct iwl_station_priv, lq_sta); | ||
347 | struct iwl_rxon_context *ctx = sta_priv->ctx; | ||
348 | |||
349 | lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ | ||
350 | lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ | ||
351 | lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ | ||
352 | lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ | ||
353 | |||
354 | #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE | ||
355 | /* testmode has higher priority to overwirte the fixed rate */ | ||
356 | if (priv->tm_fixed_rate) | ||
357 | lq_sta->dbg_fixed_rate = priv->tm_fixed_rate; | ||
358 | #endif | ||
359 | |||
360 | IWL_DEBUG_RATE(priv, "sta_id %d rate 0x%X\n", | ||
361 | lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate); | ||
362 | |||
363 | if (lq_sta->dbg_fixed_rate) { | ||
364 | rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate); | ||
365 | iwl_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC, | ||
366 | false); | ||
367 | } | ||
368 | } | ||
369 | #endif | ||
370 | |||
371 | /* | ||
372 | get the traffic load value for tid | ||
373 | */ | ||
374 | static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid) | ||
375 | { | ||
376 | u32 curr_time = jiffies_to_msecs(jiffies); | ||
377 | u32 time_diff; | ||
378 | s32 index; | ||
379 | struct iwl_traffic_load *tl = NULL; | ||
380 | |||
381 | if (tid >= IWL_MAX_TID_COUNT) | ||
382 | return 0; | ||
383 | |||
384 | tl = &(lq_data->load[tid]); | ||
385 | |||
386 | curr_time -= curr_time % TID_ROUND_VALUE; | ||
387 | |||
388 | if (!(tl->queue_count)) | ||
389 | return 0; | ||
390 | |||
391 | time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); | ||
392 | index = time_diff / TID_QUEUE_CELL_SPACING; | ||
393 | |||
394 | /* The history is too long: remove data that is older than */ | ||
395 | /* TID_MAX_TIME_DIFF */ | ||
396 | if (index >= TID_QUEUE_MAX_SIZE) | ||
397 | rs_tl_rm_old_stats(tl, curr_time); | ||
398 | |||
399 | return tl->total; | ||
400 | } | ||
401 | |||
402 | static int rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv, | ||
403 | struct iwl_lq_sta *lq_data, u8 tid, | ||
404 | struct ieee80211_sta *sta) | ||
405 | { | ||
406 | int ret = -EAGAIN; | ||
407 | u32 load; | ||
408 | |||
409 | /* | ||
410 | * Don't create TX aggregation sessions when in high | ||
411 | * BT traffic, as they would just be disrupted by BT. | ||
412 | */ | ||
413 | if (priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) { | ||
414 | IWL_ERR(priv, "BT traffic (%d), no aggregation allowed\n", | ||
415 | priv->bt_traffic_load); | ||
416 | return ret; | ||
417 | } | ||
418 | |||
419 | load = rs_tl_get_load(lq_data, tid); | ||
420 | |||
421 | if ((iwlwifi_mod_params.auto_agg) || (load > IWL_AGG_LOAD_THRESHOLD)) { | ||
422 | IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n", | ||
423 | sta->addr, tid); | ||
424 | ret = ieee80211_start_tx_ba_session(sta, tid, 5000); | ||
425 | if (ret == -EAGAIN) { | ||
426 | /* | ||
427 | * driver and mac80211 is out of sync | ||
428 | * this might be cause by reloading firmware | ||
429 | * stop the tx ba session here | ||
430 | */ | ||
431 | IWL_ERR(priv, "Fail start Tx agg on tid: %d\n", | ||
432 | tid); | ||
433 | ieee80211_stop_tx_ba_session(sta, tid); | ||
434 | } | ||
435 | } else { | ||
436 | IWL_DEBUG_HT(priv, "Aggregation not enabled for tid %d " | ||
437 | "because load = %u\n", tid, load); | ||
438 | } | ||
439 | return ret; | ||
440 | } | ||
441 | |||
442 | static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid, | ||
443 | struct iwl_lq_sta *lq_data, | ||
444 | struct ieee80211_sta *sta) | ||
445 | { | ||
446 | if (tid < IWL_MAX_TID_COUNT) | ||
447 | rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta); | ||
448 | else | ||
449 | IWL_ERR(priv, "tid exceeds max TID count: %d/%d\n", | ||
450 | tid, IWL_MAX_TID_COUNT); | ||
451 | } | ||
452 | |||
453 | static inline int get_num_of_ant_from_rate(u32 rate_n_flags) | ||
454 | { | ||
455 | return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) + | ||
456 | !!(rate_n_flags & RATE_MCS_ANT_B_MSK) + | ||
457 | !!(rate_n_flags & RATE_MCS_ANT_C_MSK); | ||
458 | } | ||
459 | |||
460 | /* | ||
461 | * Static function to get the expected throughput from an iwl_scale_tbl_info | ||
462 | * that wraps a NULL pointer check | ||
463 | */ | ||
464 | static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index) | ||
465 | { | ||
466 | if (tbl->expected_tpt) | ||
467 | return tbl->expected_tpt[rs_index]; | ||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * rs_collect_tx_data - Update the success/failure sliding window | ||
473 | * | ||
474 | * We keep a sliding window of the last 62 packets transmitted | ||
475 | * at this rate. window->data contains the bitmask of successful | ||
476 | * packets. | ||
477 | */ | ||
478 | static int rs_collect_tx_data(struct iwl_scale_tbl_info *tbl, | ||
479 | int scale_index, int attempts, int successes) | ||
480 | { | ||
481 | struct iwl_rate_scale_data *window = NULL; | ||
482 | static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1)); | ||
483 | s32 fail_count, tpt; | ||
484 | |||
485 | if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) | ||
486 | return -EINVAL; | ||
487 | |||
488 | /* Select window for current tx bit rate */ | ||
489 | window = &(tbl->win[scale_index]); | ||
490 | |||
491 | /* Get expected throughput */ | ||
492 | tpt = get_expected_tpt(tbl, scale_index); | ||
493 | |||
494 | /* | ||
495 | * Keep track of only the latest 62 tx frame attempts in this rate's | ||
496 | * history window; anything older isn't really relevant any more. | ||
497 | * If we have filled up the sliding window, drop the oldest attempt; | ||
498 | * if the oldest attempt (highest bit in bitmap) shows "success", | ||
499 | * subtract "1" from the success counter (this is the main reason | ||
500 | * we keep these bitmaps!). | ||
501 | */ | ||
502 | while (attempts > 0) { | ||
503 | if (window->counter >= IWL_RATE_MAX_WINDOW) { | ||
504 | |||
505 | /* remove earliest */ | ||
506 | window->counter = IWL_RATE_MAX_WINDOW - 1; | ||
507 | |||
508 | if (window->data & mask) { | ||
509 | window->data &= ~mask; | ||
510 | window->success_counter--; | ||
511 | } | ||
512 | } | ||
513 | |||
514 | /* Increment frames-attempted counter */ | ||
515 | window->counter++; | ||
516 | |||
517 | /* Shift bitmap by one frame to throw away oldest history */ | ||
518 | window->data <<= 1; | ||
519 | |||
520 | /* Mark the most recent #successes attempts as successful */ | ||
521 | if (successes > 0) { | ||
522 | window->success_counter++; | ||
523 | window->data |= 0x1; | ||
524 | successes--; | ||
525 | } | ||
526 | |||
527 | attempts--; | ||
528 | } | ||
529 | |||
530 | /* Calculate current success ratio, avoid divide-by-0! */ | ||
531 | if (window->counter > 0) | ||
532 | window->success_ratio = 128 * (100 * window->success_counter) | ||
533 | / window->counter; | ||
534 | else | ||
535 | window->success_ratio = IWL_INVALID_VALUE; | ||
536 | |||
537 | fail_count = window->counter - window->success_counter; | ||
538 | |||
539 | /* Calculate average throughput, if we have enough history. */ | ||
540 | if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) || | ||
541 | (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH)) | ||
542 | window->average_tpt = (window->success_ratio * tpt + 64) / 128; | ||
543 | else | ||
544 | window->average_tpt = IWL_INVALID_VALUE; | ||
545 | |||
546 | /* Tag this window as having been updated */ | ||
547 | window->stamp = jiffies; | ||
548 | |||
549 | return 0; | ||
550 | } | ||
551 | |||
552 | /* | ||
553 | * Fill uCode API rate_n_flags field, based on "search" or "active" table. | ||
554 | */ | ||
555 | /* FIXME:RS:remove this function and put the flags statically in the table */ | ||
556 | static u32 rate_n_flags_from_tbl(struct iwl_priv *priv, | ||
557 | struct iwl_scale_tbl_info *tbl, | ||
558 | int index, u8 use_green) | ||
559 | { | ||
560 | u32 rate_n_flags = 0; | ||
561 | |||
562 | if (is_legacy(tbl->lq_type)) { | ||
563 | rate_n_flags = iwl_rates[index].plcp; | ||
564 | if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) | ||
565 | rate_n_flags |= RATE_MCS_CCK_MSK; | ||
566 | |||
567 | } else if (is_Ht(tbl->lq_type)) { | ||
568 | if (index > IWL_LAST_OFDM_RATE) { | ||
569 | IWL_ERR(priv, "Invalid HT rate index %d\n", index); | ||
570 | index = IWL_LAST_OFDM_RATE; | ||
571 | } | ||
572 | rate_n_flags = RATE_MCS_HT_MSK; | ||
573 | |||
574 | if (is_siso(tbl->lq_type)) | ||
575 | rate_n_flags |= iwl_rates[index].plcp_siso; | ||
576 | else if (is_mimo2(tbl->lq_type)) | ||
577 | rate_n_flags |= iwl_rates[index].plcp_mimo2; | ||
578 | else | ||
579 | rate_n_flags |= iwl_rates[index].plcp_mimo3; | ||
580 | } else { | ||
581 | IWL_ERR(priv, "Invalid tbl->lq_type %d\n", tbl->lq_type); | ||
582 | } | ||
583 | |||
584 | rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) & | ||
585 | RATE_MCS_ANT_ABC_MSK); | ||
586 | |||
587 | if (is_Ht(tbl->lq_type)) { | ||
588 | if (tbl->is_ht40) { | ||
589 | if (tbl->is_dup) | ||
590 | rate_n_flags |= RATE_MCS_DUP_MSK; | ||
591 | else | ||
592 | rate_n_flags |= RATE_MCS_HT40_MSK; | ||
593 | } | ||
594 | if (tbl->is_SGI) | ||
595 | rate_n_flags |= RATE_MCS_SGI_MSK; | ||
596 | |||
597 | if (use_green) { | ||
598 | rate_n_flags |= RATE_MCS_GF_MSK; | ||
599 | if (is_siso(tbl->lq_type) && tbl->is_SGI) { | ||
600 | rate_n_flags &= ~RATE_MCS_SGI_MSK; | ||
601 | IWL_ERR(priv, "GF was set with SGI:SISO\n"); | ||
602 | } | ||
603 | } | ||
604 | } | ||
605 | return rate_n_flags; | ||
606 | } | ||
607 | |||
608 | /* | ||
609 | * Interpret uCode API's rate_n_flags format, | ||
610 | * fill "search" or "active" tx mode table. | ||
611 | */ | ||
612 | static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags, | ||
613 | enum ieee80211_band band, | ||
614 | struct iwl_scale_tbl_info *tbl, | ||
615 | int *rate_idx) | ||
616 | { | ||
617 | u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK); | ||
618 | u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags); | ||
619 | u8 mcs; | ||
620 | |||
621 | memset(tbl, 0, sizeof(struct iwl_scale_tbl_info)); | ||
622 | *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags); | ||
623 | |||
624 | if (*rate_idx == IWL_RATE_INVALID) { | ||
625 | *rate_idx = -1; | ||
626 | return -EINVAL; | ||
627 | } | ||
628 | tbl->is_SGI = 0; /* default legacy setup */ | ||
629 | tbl->is_ht40 = 0; | ||
630 | tbl->is_dup = 0; | ||
631 | tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS); | ||
632 | tbl->lq_type = LQ_NONE; | ||
633 | tbl->max_search = IWL_MAX_SEARCH; | ||
634 | |||
635 | /* legacy rate format */ | ||
636 | if (!(rate_n_flags & RATE_MCS_HT_MSK)) { | ||
637 | if (num_of_ant == 1) { | ||
638 | if (band == IEEE80211_BAND_5GHZ) | ||
639 | tbl->lq_type = LQ_A; | ||
640 | else | ||
641 | tbl->lq_type = LQ_G; | ||
642 | } | ||
643 | /* HT rate format */ | ||
644 | } else { | ||
645 | if (rate_n_flags & RATE_MCS_SGI_MSK) | ||
646 | tbl->is_SGI = 1; | ||
647 | |||
648 | if ((rate_n_flags & RATE_MCS_HT40_MSK) || | ||
649 | (rate_n_flags & RATE_MCS_DUP_MSK)) | ||
650 | tbl->is_ht40 = 1; | ||
651 | |||
652 | if (rate_n_flags & RATE_MCS_DUP_MSK) | ||
653 | tbl->is_dup = 1; | ||
654 | |||
655 | mcs = rs_extract_rate(rate_n_flags); | ||
656 | |||
657 | /* SISO */ | ||
658 | if (mcs <= IWL_RATE_SISO_60M_PLCP) { | ||
659 | if (num_of_ant == 1) | ||
660 | tbl->lq_type = LQ_SISO; /*else NONE*/ | ||
661 | /* MIMO2 */ | ||
662 | } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) { | ||
663 | if (num_of_ant == 2) | ||
664 | tbl->lq_type = LQ_MIMO2; | ||
665 | /* MIMO3 */ | ||
666 | } else { | ||
667 | if (num_of_ant == 3) { | ||
668 | tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH; | ||
669 | tbl->lq_type = LQ_MIMO3; | ||
670 | } | ||
671 | } | ||
672 | } | ||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | /* switch to another antenna/antennas and return 1 */ | ||
677 | /* if no other valid antenna found, return 0 */ | ||
678 | static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags, | ||
679 | struct iwl_scale_tbl_info *tbl) | ||
680 | { | ||
681 | u8 new_ant_type; | ||
682 | |||
683 | if (!tbl->ant_type || tbl->ant_type > ANT_ABC) | ||
684 | return 0; | ||
685 | |||
686 | if (!rs_is_valid_ant(valid_ant, tbl->ant_type)) | ||
687 | return 0; | ||
688 | |||
689 | new_ant_type = ant_toggle_lookup[tbl->ant_type]; | ||
690 | |||
691 | while ((new_ant_type != tbl->ant_type) && | ||
692 | !rs_is_valid_ant(valid_ant, new_ant_type)) | ||
693 | new_ant_type = ant_toggle_lookup[new_ant_type]; | ||
694 | |||
695 | if (new_ant_type == tbl->ant_type) | ||
696 | return 0; | ||
697 | |||
698 | tbl->ant_type = new_ant_type; | ||
699 | *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK; | ||
700 | *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS; | ||
701 | return 1; | ||
702 | } | ||
703 | |||
704 | /** | ||
705 | * Green-field mode is valid if the station supports it and | ||
706 | * there are no non-GF stations present in the BSS. | ||
707 | */ | ||
708 | static bool rs_use_green(struct ieee80211_sta *sta) | ||
709 | { | ||
710 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
711 | struct iwl_rxon_context *ctx = sta_priv->ctx; | ||
712 | |||
713 | return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) && | ||
714 | !(ctx->ht.non_gf_sta_present); | ||
715 | } | ||
716 | |||
717 | /** | ||
718 | * rs_get_supported_rates - get the available rates | ||
719 | * | ||
720 | * if management frame or broadcast frame only return | ||
721 | * basic available rates. | ||
722 | * | ||
723 | */ | ||
724 | static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta, | ||
725 | struct ieee80211_hdr *hdr, | ||
726 | enum iwl_table_type rate_type) | ||
727 | { | ||
728 | if (is_legacy(rate_type)) { | ||
729 | return lq_sta->active_legacy_rate; | ||
730 | } else { | ||
731 | if (is_siso(rate_type)) | ||
732 | return lq_sta->active_siso_rate; | ||
733 | else if (is_mimo2(rate_type)) | ||
734 | return lq_sta->active_mimo2_rate; | ||
735 | else | ||
736 | return lq_sta->active_mimo3_rate; | ||
737 | } | ||
738 | } | ||
739 | |||
740 | static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask, | ||
741 | int rate_type) | ||
742 | { | ||
743 | u8 high = IWL_RATE_INVALID; | ||
744 | u8 low = IWL_RATE_INVALID; | ||
745 | |||
746 | /* 802.11A or ht walks to the next literal adjacent rate in | ||
747 | * the rate table */ | ||
748 | if (is_a_band(rate_type) || !is_legacy(rate_type)) { | ||
749 | int i; | ||
750 | u32 mask; | ||
751 | |||
752 | /* Find the previous rate that is in the rate mask */ | ||
753 | i = index - 1; | ||
754 | for (mask = (1 << i); i >= 0; i--, mask >>= 1) { | ||
755 | if (rate_mask & mask) { | ||
756 | low = i; | ||
757 | break; | ||
758 | } | ||
759 | } | ||
760 | |||
761 | /* Find the next rate that is in the rate mask */ | ||
762 | i = index + 1; | ||
763 | for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) { | ||
764 | if (rate_mask & mask) { | ||
765 | high = i; | ||
766 | break; | ||
767 | } | ||
768 | } | ||
769 | |||
770 | return (high << 8) | low; | ||
771 | } | ||
772 | |||
773 | low = index; | ||
774 | while (low != IWL_RATE_INVALID) { | ||
775 | low = iwl_rates[low].prev_rs; | ||
776 | if (low == IWL_RATE_INVALID) | ||
777 | break; | ||
778 | if (rate_mask & (1 << low)) | ||
779 | break; | ||
780 | IWL_DEBUG_RATE(priv, "Skipping masked lower rate: %d\n", low); | ||
781 | } | ||
782 | |||
783 | high = index; | ||
784 | while (high != IWL_RATE_INVALID) { | ||
785 | high = iwl_rates[high].next_rs; | ||
786 | if (high == IWL_RATE_INVALID) | ||
787 | break; | ||
788 | if (rate_mask & (1 << high)) | ||
789 | break; | ||
790 | IWL_DEBUG_RATE(priv, "Skipping masked higher rate: %d\n", high); | ||
791 | } | ||
792 | |||
793 | return (high << 8) | low; | ||
794 | } | ||
795 | |||
796 | static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta, | ||
797 | struct iwl_scale_tbl_info *tbl, | ||
798 | u8 scale_index, u8 ht_possible) | ||
799 | { | ||
800 | s32 low; | ||
801 | u16 rate_mask; | ||
802 | u16 high_low; | ||
803 | u8 switch_to_legacy = 0; | ||
804 | u8 is_green = lq_sta->is_green; | ||
805 | struct iwl_priv *priv = lq_sta->drv; | ||
806 | |||
807 | /* check if we need to switch from HT to legacy rates. | ||
808 | * assumption is that mandatory rates (1Mbps or 6Mbps) | ||
809 | * are always supported (spec demand) */ | ||
810 | if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) { | ||
811 | switch_to_legacy = 1; | ||
812 | scale_index = rs_ht_to_legacy[scale_index]; | ||
813 | if (lq_sta->band == IEEE80211_BAND_5GHZ) | ||
814 | tbl->lq_type = LQ_A; | ||
815 | else | ||
816 | tbl->lq_type = LQ_G; | ||
817 | |||
818 | if (num_of_ant(tbl->ant_type) > 1) | ||
819 | tbl->ant_type = | ||
820 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
821 | |||
822 | tbl->is_ht40 = 0; | ||
823 | tbl->is_SGI = 0; | ||
824 | tbl->max_search = IWL_MAX_SEARCH; | ||
825 | } | ||
826 | |||
827 | rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type); | ||
828 | |||
829 | /* Mask with station rate restriction */ | ||
830 | if (is_legacy(tbl->lq_type)) { | ||
831 | /* supp_rates has no CCK bits in A mode */ | ||
832 | if (lq_sta->band == IEEE80211_BAND_5GHZ) | ||
833 | rate_mask = (u16)(rate_mask & | ||
834 | (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); | ||
835 | else | ||
836 | rate_mask = (u16)(rate_mask & lq_sta->supp_rates); | ||
837 | } | ||
838 | |||
839 | /* If we switched from HT to legacy, check current rate */ | ||
840 | if (switch_to_legacy && (rate_mask & (1 << scale_index))) { | ||
841 | low = scale_index; | ||
842 | goto out; | ||
843 | } | ||
844 | |||
845 | high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask, | ||
846 | tbl->lq_type); | ||
847 | low = high_low & 0xff; | ||
848 | |||
849 | if (low == IWL_RATE_INVALID) | ||
850 | low = scale_index; | ||
851 | |||
852 | out: | ||
853 | return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green); | ||
854 | } | ||
855 | |||
856 | /* | ||
857 | * Simple function to compare two rate scale table types | ||
858 | */ | ||
859 | static bool table_type_matches(struct iwl_scale_tbl_info *a, | ||
860 | struct iwl_scale_tbl_info *b) | ||
861 | { | ||
862 | return (a->lq_type == b->lq_type) && (a->ant_type == b->ant_type) && | ||
863 | (a->is_SGI == b->is_SGI); | ||
864 | } | ||
865 | |||
866 | static void rs_bt_update_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
867 | struct iwl_lq_sta *lq_sta) | ||
868 | { | ||
869 | struct iwl_scale_tbl_info *tbl; | ||
870 | bool full_concurrent = priv->bt_full_concurrent; | ||
871 | |||
872 | if (priv->bt_ant_couple_ok) { | ||
873 | /* | ||
874 | * Is there a need to switch between | ||
875 | * full concurrency and 3-wire? | ||
876 | */ | ||
877 | if (priv->bt_ci_compliance && priv->bt_ant_couple_ok) | ||
878 | full_concurrent = true; | ||
879 | else | ||
880 | full_concurrent = false; | ||
881 | } | ||
882 | if ((priv->bt_traffic_load != priv->last_bt_traffic_load) || | ||
883 | (priv->bt_full_concurrent != full_concurrent)) { | ||
884 | priv->bt_full_concurrent = full_concurrent; | ||
885 | priv->last_bt_traffic_load = priv->bt_traffic_load; | ||
886 | |||
887 | /* Update uCode's rate table. */ | ||
888 | tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
889 | rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); | ||
890 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); | ||
891 | |||
892 | queue_work(priv->workqueue, &priv->bt_full_concurrency); | ||
893 | } | ||
894 | } | ||
895 | |||
896 | /* | ||
897 | * mac80211 sends us Tx status | ||
898 | */ | ||
899 | static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband, | ||
900 | struct ieee80211_sta *sta, void *priv_sta, | ||
901 | struct sk_buff *skb) | ||
902 | { | ||
903 | int legacy_success; | ||
904 | int retries; | ||
905 | int rs_index, mac_index, i; | ||
906 | struct iwl_lq_sta *lq_sta = priv_sta; | ||
907 | struct iwl_link_quality_cmd *table; | ||
908 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | ||
909 | struct iwl_op_mode *op_mode = (struct iwl_op_mode *)priv_r; | ||
910 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
911 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | ||
912 | enum mac80211_rate_control_flags mac_flags; | ||
913 | u32 tx_rate; | ||
914 | struct iwl_scale_tbl_info tbl_type; | ||
915 | struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl; | ||
916 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
917 | struct iwl_rxon_context *ctx = sta_priv->ctx; | ||
918 | |||
919 | IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); | ||
920 | |||
921 | /* Treat uninitialized rate scaling data same as non-existing. */ | ||
922 | if (!lq_sta) { | ||
923 | IWL_DEBUG_RATE(priv, "Station rate scaling not created yet.\n"); | ||
924 | return; | ||
925 | } else if (!lq_sta->drv) { | ||
926 | IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n"); | ||
927 | return; | ||
928 | } | ||
929 | |||
930 | if (!ieee80211_is_data(hdr->frame_control) || | ||
931 | info->flags & IEEE80211_TX_CTL_NO_ACK) | ||
932 | return; | ||
933 | |||
934 | /* This packet was aggregated but doesn't carry status info */ | ||
935 | if ((info->flags & IEEE80211_TX_CTL_AMPDU) && | ||
936 | !(info->flags & IEEE80211_TX_STAT_AMPDU)) | ||
937 | return; | ||
938 | |||
939 | /* | ||
940 | * Ignore this Tx frame response if its initial rate doesn't match | ||
941 | * that of latest Link Quality command. There may be stragglers | ||
942 | * from a previous Link Quality command, but we're no longer interested | ||
943 | * in those; they're either from the "active" mode while we're trying | ||
944 | * to check "search" mode, or a prior "search" mode after we've moved | ||
945 | * to a new "search" mode (which might become the new "active" mode). | ||
946 | */ | ||
947 | table = &lq_sta->lq; | ||
948 | tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags); | ||
949 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); | ||
950 | if (priv->band == IEEE80211_BAND_5GHZ) | ||
951 | rs_index -= IWL_FIRST_OFDM_RATE; | ||
952 | mac_flags = info->status.rates[0].flags; | ||
953 | mac_index = info->status.rates[0].idx; | ||
954 | /* For HT packets, map MCS to PLCP */ | ||
955 | if (mac_flags & IEEE80211_TX_RC_MCS) { | ||
956 | mac_index &= RATE_MCS_CODE_MSK; /* Remove # of streams */ | ||
957 | if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE)) | ||
958 | mac_index++; | ||
959 | /* | ||
960 | * mac80211 HT index is always zero-indexed; we need to move | ||
961 | * HT OFDM rates after CCK rates in 2.4 GHz band | ||
962 | */ | ||
963 | if (priv->band == IEEE80211_BAND_2GHZ) | ||
964 | mac_index += IWL_FIRST_OFDM_RATE; | ||
965 | } | ||
966 | /* Here we actually compare this rate to the latest LQ command */ | ||
967 | if ((mac_index < 0) || | ||
968 | (tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) || | ||
969 | (tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) || | ||
970 | (tbl_type.is_dup != !!(mac_flags & IEEE80211_TX_RC_DUP_DATA)) || | ||
971 | (tbl_type.ant_type != info->status.antenna) || | ||
972 | (!!(tx_rate & RATE_MCS_HT_MSK) != !!(mac_flags & IEEE80211_TX_RC_MCS)) || | ||
973 | (!!(tx_rate & RATE_MCS_GF_MSK) != !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) || | ||
974 | (rs_index != mac_index)) { | ||
975 | IWL_DEBUG_RATE(priv, "initial rate %d does not match %d (0x%x)\n", mac_index, rs_index, tx_rate); | ||
976 | /* | ||
977 | * Since rates mis-match, the last LQ command may have failed. | ||
978 | * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with | ||
979 | * ... driver. | ||
980 | */ | ||
981 | lq_sta->missed_rate_counter++; | ||
982 | if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) { | ||
983 | lq_sta->missed_rate_counter = 0; | ||
984 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); | ||
985 | } | ||
986 | /* Regardless, ignore this status info for outdated rate */ | ||
987 | return; | ||
988 | } else | ||
989 | /* Rate did match, so reset the missed_rate_counter */ | ||
990 | lq_sta->missed_rate_counter = 0; | ||
991 | |||
992 | /* Figure out if rate scale algorithm is in active or search table */ | ||
993 | if (table_type_matches(&tbl_type, | ||
994 | &(lq_sta->lq_info[lq_sta->active_tbl]))) { | ||
995 | curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
996 | other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); | ||
997 | } else if (table_type_matches(&tbl_type, | ||
998 | &lq_sta->lq_info[1 - lq_sta->active_tbl])) { | ||
999 | curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); | ||
1000 | other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
1001 | } else { | ||
1002 | IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n"); | ||
1003 | tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
1004 | IWL_DEBUG_RATE(priv, "active- lq:%x, ant:%x, SGI:%d\n", | ||
1005 | tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI); | ||
1006 | tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]); | ||
1007 | IWL_DEBUG_RATE(priv, "search- lq:%x, ant:%x, SGI:%d\n", | ||
1008 | tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI); | ||
1009 | IWL_DEBUG_RATE(priv, "actual- lq:%x, ant:%x, SGI:%d\n", | ||
1010 | tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI); | ||
1011 | /* | ||
1012 | * no matching table found, let's by-pass the data collection | ||
1013 | * and continue to perform rate scale to find the rate table | ||
1014 | */ | ||
1015 | rs_stay_in_table(lq_sta, true); | ||
1016 | goto done; | ||
1017 | } | ||
1018 | |||
1019 | /* | ||
1020 | * Updating the frame history depends on whether packets were | ||
1021 | * aggregated. | ||
1022 | * | ||
1023 | * For aggregation, all packets were transmitted at the same rate, the | ||
1024 | * first index into rate scale table. | ||
1025 | */ | ||
1026 | if (info->flags & IEEE80211_TX_STAT_AMPDU) { | ||
1027 | tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags); | ||
1028 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, | ||
1029 | &rs_index); | ||
1030 | rs_collect_tx_data(curr_tbl, rs_index, | ||
1031 | info->status.ampdu_len, | ||
1032 | info->status.ampdu_ack_len); | ||
1033 | |||
1034 | /* Update success/fail counts if not searching for new mode */ | ||
1035 | if (lq_sta->stay_in_tbl) { | ||
1036 | lq_sta->total_success += info->status.ampdu_ack_len; | ||
1037 | lq_sta->total_failed += (info->status.ampdu_len - | ||
1038 | info->status.ampdu_ack_len); | ||
1039 | } | ||
1040 | } else { | ||
1041 | /* | ||
1042 | * For legacy, update frame history with for each Tx retry. | ||
1043 | */ | ||
1044 | retries = info->status.rates[0].count - 1; | ||
1045 | /* HW doesn't send more than 15 retries */ | ||
1046 | retries = min(retries, 15); | ||
1047 | |||
1048 | /* The last transmission may have been successful */ | ||
1049 | legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK); | ||
1050 | /* Collect data for each rate used during failed TX attempts */ | ||
1051 | for (i = 0; i <= retries; ++i) { | ||
1052 | tx_rate = le32_to_cpu(table->rs_table[i].rate_n_flags); | ||
1053 | rs_get_tbl_info_from_mcs(tx_rate, priv->band, | ||
1054 | &tbl_type, &rs_index); | ||
1055 | /* | ||
1056 | * Only collect stats if retried rate is in the same RS | ||
1057 | * table as active/search. | ||
1058 | */ | ||
1059 | if (table_type_matches(&tbl_type, curr_tbl)) | ||
1060 | tmp_tbl = curr_tbl; | ||
1061 | else if (table_type_matches(&tbl_type, other_tbl)) | ||
1062 | tmp_tbl = other_tbl; | ||
1063 | else | ||
1064 | continue; | ||
1065 | rs_collect_tx_data(tmp_tbl, rs_index, 1, | ||
1066 | i < retries ? 0 : legacy_success); | ||
1067 | } | ||
1068 | |||
1069 | /* Update success/fail counts if not searching for new mode */ | ||
1070 | if (lq_sta->stay_in_tbl) { | ||
1071 | lq_sta->total_success += legacy_success; | ||
1072 | lq_sta->total_failed += retries + (1 - legacy_success); | ||
1073 | } | ||
1074 | } | ||
1075 | /* The last TX rate is cached in lq_sta; it's set in if/else above */ | ||
1076 | lq_sta->last_rate_n_flags = tx_rate; | ||
1077 | done: | ||
1078 | /* See if there's a better rate or modulation mode to try. */ | ||
1079 | if (sta && sta->supp_rates[sband->band]) | ||
1080 | rs_rate_scale_perform(priv, skb, sta, lq_sta); | ||
1081 | |||
1082 | #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_IWLWIFI_DEVICE_TESTMODE) | ||
1083 | if ((priv->tm_fixed_rate) && | ||
1084 | (priv->tm_fixed_rate != lq_sta->dbg_fixed_rate)) | ||
1085 | rs_program_fix_rate(priv, lq_sta); | ||
1086 | #endif | ||
1087 | if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist) | ||
1088 | rs_bt_update_lq(priv, ctx, lq_sta); | ||
1089 | } | ||
1090 | |||
1091 | /* | ||
1092 | * Begin a period of staying with a selected modulation mode. | ||
1093 | * Set "stay_in_tbl" flag to prevent any mode switches. | ||
1094 | * Set frame tx success limits according to legacy vs. high-throughput, | ||
1095 | * and reset overall (spanning all rates) tx success history statistics. | ||
1096 | * These control how long we stay using same modulation mode before | ||
1097 | * searching for a new mode. | ||
1098 | */ | ||
1099 | static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy, | ||
1100 | struct iwl_lq_sta *lq_sta) | ||
1101 | { | ||
1102 | IWL_DEBUG_RATE(priv, "we are staying in the same table\n"); | ||
1103 | lq_sta->stay_in_tbl = 1; /* only place this gets set */ | ||
1104 | if (is_legacy) { | ||
1105 | lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT; | ||
1106 | lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT; | ||
1107 | lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT; | ||
1108 | } else { | ||
1109 | lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT; | ||
1110 | lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT; | ||
1111 | lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT; | ||
1112 | } | ||
1113 | lq_sta->table_count = 0; | ||
1114 | lq_sta->total_failed = 0; | ||
1115 | lq_sta->total_success = 0; | ||
1116 | lq_sta->flush_timer = jiffies; | ||
1117 | lq_sta->action_counter = 0; | ||
1118 | } | ||
1119 | |||
1120 | /* | ||
1121 | * Find correct throughput table for given mode of modulation | ||
1122 | */ | ||
1123 | static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta, | ||
1124 | struct iwl_scale_tbl_info *tbl) | ||
1125 | { | ||
1126 | /* Used to choose among HT tables */ | ||
1127 | s32 (*ht_tbl_pointer)[IWL_RATE_COUNT]; | ||
1128 | |||
1129 | /* Check for invalid LQ type */ | ||
1130 | if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) { | ||
1131 | tbl->expected_tpt = expected_tpt_legacy; | ||
1132 | return; | ||
1133 | } | ||
1134 | |||
1135 | /* Legacy rates have only one table */ | ||
1136 | if (is_legacy(tbl->lq_type)) { | ||
1137 | tbl->expected_tpt = expected_tpt_legacy; | ||
1138 | return; | ||
1139 | } | ||
1140 | |||
1141 | /* Choose among many HT tables depending on number of streams | ||
1142 | * (SISO/MIMO2/MIMO3), channel width (20/40), SGI, and aggregation | ||
1143 | * status */ | ||
1144 | if (is_siso(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup)) | ||
1145 | ht_tbl_pointer = expected_tpt_siso20MHz; | ||
1146 | else if (is_siso(tbl->lq_type)) | ||
1147 | ht_tbl_pointer = expected_tpt_siso40MHz; | ||
1148 | else if (is_mimo2(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup)) | ||
1149 | ht_tbl_pointer = expected_tpt_mimo2_20MHz; | ||
1150 | else if (is_mimo2(tbl->lq_type)) | ||
1151 | ht_tbl_pointer = expected_tpt_mimo2_40MHz; | ||
1152 | else if (is_mimo3(tbl->lq_type) && (!tbl->is_ht40 || lq_sta->is_dup)) | ||
1153 | ht_tbl_pointer = expected_tpt_mimo3_20MHz; | ||
1154 | else /* if (is_mimo3(tbl->lq_type)) <-- must be true */ | ||
1155 | ht_tbl_pointer = expected_tpt_mimo3_40MHz; | ||
1156 | |||
1157 | if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */ | ||
1158 | tbl->expected_tpt = ht_tbl_pointer[0]; | ||
1159 | else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */ | ||
1160 | tbl->expected_tpt = ht_tbl_pointer[1]; | ||
1161 | else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */ | ||
1162 | tbl->expected_tpt = ht_tbl_pointer[2]; | ||
1163 | else /* AGG+SGI */ | ||
1164 | tbl->expected_tpt = ht_tbl_pointer[3]; | ||
1165 | } | ||
1166 | |||
1167 | /* | ||
1168 | * Find starting rate for new "search" high-throughput mode of modulation. | ||
1169 | * Goal is to find lowest expected rate (under perfect conditions) that is | ||
1170 | * above the current measured throughput of "active" mode, to give new mode | ||
1171 | * a fair chance to prove itself without too many challenges. | ||
1172 | * | ||
1173 | * This gets called when transitioning to more aggressive modulation | ||
1174 | * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive | ||
1175 | * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need | ||
1176 | * to decrease to match "active" throughput. When moving from MIMO to SISO, | ||
1177 | * bit rate will typically need to increase, but not if performance was bad. | ||
1178 | */ | ||
1179 | static s32 rs_get_best_rate(struct iwl_priv *priv, | ||
1180 | struct iwl_lq_sta *lq_sta, | ||
1181 | struct iwl_scale_tbl_info *tbl, /* "search" */ | ||
1182 | u16 rate_mask, s8 index) | ||
1183 | { | ||
1184 | /* "active" values */ | ||
1185 | struct iwl_scale_tbl_info *active_tbl = | ||
1186 | &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
1187 | s32 active_sr = active_tbl->win[index].success_ratio; | ||
1188 | s32 active_tpt = active_tbl->expected_tpt[index]; | ||
1189 | |||
1190 | /* expected "search" throughput */ | ||
1191 | s32 *tpt_tbl = tbl->expected_tpt; | ||
1192 | |||
1193 | s32 new_rate, high, low, start_hi; | ||
1194 | u16 high_low; | ||
1195 | s8 rate = index; | ||
1196 | |||
1197 | new_rate = high = low = start_hi = IWL_RATE_INVALID; | ||
1198 | |||
1199 | for (; ;) { | ||
1200 | high_low = rs_get_adjacent_rate(priv, rate, rate_mask, | ||
1201 | tbl->lq_type); | ||
1202 | |||
1203 | low = high_low & 0xff; | ||
1204 | high = (high_low >> 8) & 0xff; | ||
1205 | |||
1206 | /* | ||
1207 | * Lower the "search" bit rate, to give new "search" mode | ||
1208 | * approximately the same throughput as "active" if: | ||
1209 | * | ||
1210 | * 1) "Active" mode has been working modestly well (but not | ||
1211 | * great), and expected "search" throughput (under perfect | ||
1212 | * conditions) at candidate rate is above the actual | ||
1213 | * measured "active" throughput (but less than expected | ||
1214 | * "active" throughput under perfect conditions). | ||
1215 | * OR | ||
1216 | * 2) "Active" mode has been working perfectly or very well | ||
1217 | * and expected "search" throughput (under perfect | ||
1218 | * conditions) at candidate rate is above expected | ||
1219 | * "active" throughput (under perfect conditions). | ||
1220 | */ | ||
1221 | if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) && | ||
1222 | ((active_sr > IWL_RATE_DECREASE_TH) && | ||
1223 | (active_sr <= IWL_RATE_HIGH_TH) && | ||
1224 | (tpt_tbl[rate] <= active_tpt))) || | ||
1225 | ((active_sr >= IWL_RATE_SCALE_SWITCH) && | ||
1226 | (tpt_tbl[rate] > active_tpt))) { | ||
1227 | |||
1228 | /* (2nd or later pass) | ||
1229 | * If we've already tried to raise the rate, and are | ||
1230 | * now trying to lower it, use the higher rate. */ | ||
1231 | if (start_hi != IWL_RATE_INVALID) { | ||
1232 | new_rate = start_hi; | ||
1233 | break; | ||
1234 | } | ||
1235 | |||
1236 | new_rate = rate; | ||
1237 | |||
1238 | /* Loop again with lower rate */ | ||
1239 | if (low != IWL_RATE_INVALID) | ||
1240 | rate = low; | ||
1241 | |||
1242 | /* Lower rate not available, use the original */ | ||
1243 | else | ||
1244 | break; | ||
1245 | |||
1246 | /* Else try to raise the "search" rate to match "active" */ | ||
1247 | } else { | ||
1248 | /* (2nd or later pass) | ||
1249 | * If we've already tried to lower the rate, and are | ||
1250 | * now trying to raise it, use the lower rate. */ | ||
1251 | if (new_rate != IWL_RATE_INVALID) | ||
1252 | break; | ||
1253 | |||
1254 | /* Loop again with higher rate */ | ||
1255 | else if (high != IWL_RATE_INVALID) { | ||
1256 | start_hi = high; | ||
1257 | rate = high; | ||
1258 | |||
1259 | /* Higher rate not available, use the original */ | ||
1260 | } else { | ||
1261 | new_rate = rate; | ||
1262 | break; | ||
1263 | } | ||
1264 | } | ||
1265 | } | ||
1266 | |||
1267 | return new_rate; | ||
1268 | } | ||
1269 | |||
1270 | /* | ||
1271 | * Set up search table for MIMO2 | ||
1272 | */ | ||
1273 | static int rs_switch_to_mimo2(struct iwl_priv *priv, | ||
1274 | struct iwl_lq_sta *lq_sta, | ||
1275 | struct ieee80211_conf *conf, | ||
1276 | struct ieee80211_sta *sta, | ||
1277 | struct iwl_scale_tbl_info *tbl, int index) | ||
1278 | { | ||
1279 | u16 rate_mask; | ||
1280 | s32 rate; | ||
1281 | s8 is_green = lq_sta->is_green; | ||
1282 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
1283 | struct iwl_rxon_context *ctx = sta_priv->ctx; | ||
1284 | |||
1285 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) | ||
1286 | return -1; | ||
1287 | |||
1288 | if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2) | ||
1289 | == WLAN_HT_CAP_SM_PS_STATIC) | ||
1290 | return -1; | ||
1291 | |||
1292 | /* Need both Tx chains/antennas to support MIMO */ | ||
1293 | if (priv->hw_params.tx_chains_num < 2) | ||
1294 | return -1; | ||
1295 | |||
1296 | IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO2\n"); | ||
1297 | |||
1298 | tbl->lq_type = LQ_MIMO2; | ||
1299 | tbl->is_dup = lq_sta->is_dup; | ||
1300 | tbl->action = 0; | ||
1301 | tbl->max_search = IWL_MAX_SEARCH; | ||
1302 | rate_mask = lq_sta->active_mimo2_rate; | ||
1303 | |||
1304 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) | ||
1305 | tbl->is_ht40 = 1; | ||
1306 | else | ||
1307 | tbl->is_ht40 = 0; | ||
1308 | |||
1309 | rs_set_expected_tpt_table(lq_sta, tbl); | ||
1310 | |||
1311 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); | ||
1312 | |||
1313 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask); | ||
1314 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { | ||
1315 | IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", | ||
1316 | rate, rate_mask); | ||
1317 | return -1; | ||
1318 | } | ||
1319 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); | ||
1320 | |||
1321 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", | ||
1322 | tbl->current_rate, is_green); | ||
1323 | return 0; | ||
1324 | } | ||
1325 | |||
1326 | /* | ||
1327 | * Set up search table for MIMO3 | ||
1328 | */ | ||
1329 | static int rs_switch_to_mimo3(struct iwl_priv *priv, | ||
1330 | struct iwl_lq_sta *lq_sta, | ||
1331 | struct ieee80211_conf *conf, | ||
1332 | struct ieee80211_sta *sta, | ||
1333 | struct iwl_scale_tbl_info *tbl, int index) | ||
1334 | { | ||
1335 | u16 rate_mask; | ||
1336 | s32 rate; | ||
1337 | s8 is_green = lq_sta->is_green; | ||
1338 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
1339 | struct iwl_rxon_context *ctx = sta_priv->ctx; | ||
1340 | |||
1341 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) | ||
1342 | return -1; | ||
1343 | |||
1344 | if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2) | ||
1345 | == WLAN_HT_CAP_SM_PS_STATIC) | ||
1346 | return -1; | ||
1347 | |||
1348 | /* Need both Tx chains/antennas to support MIMO */ | ||
1349 | if (priv->hw_params.tx_chains_num < 3) | ||
1350 | return -1; | ||
1351 | |||
1352 | IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n"); | ||
1353 | |||
1354 | tbl->lq_type = LQ_MIMO3; | ||
1355 | tbl->is_dup = lq_sta->is_dup; | ||
1356 | tbl->action = 0; | ||
1357 | tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH; | ||
1358 | rate_mask = lq_sta->active_mimo3_rate; | ||
1359 | |||
1360 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) | ||
1361 | tbl->is_ht40 = 1; | ||
1362 | else | ||
1363 | tbl->is_ht40 = 0; | ||
1364 | |||
1365 | rs_set_expected_tpt_table(lq_sta, tbl); | ||
1366 | |||
1367 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); | ||
1368 | |||
1369 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n", | ||
1370 | rate, rate_mask); | ||
1371 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { | ||
1372 | IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", | ||
1373 | rate, rate_mask); | ||
1374 | return -1; | ||
1375 | } | ||
1376 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); | ||
1377 | |||
1378 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", | ||
1379 | tbl->current_rate, is_green); | ||
1380 | return 0; | ||
1381 | } | ||
1382 | |||
1383 | /* | ||
1384 | * Set up search table for SISO | ||
1385 | */ | ||
1386 | static int rs_switch_to_siso(struct iwl_priv *priv, | ||
1387 | struct iwl_lq_sta *lq_sta, | ||
1388 | struct ieee80211_conf *conf, | ||
1389 | struct ieee80211_sta *sta, | ||
1390 | struct iwl_scale_tbl_info *tbl, int index) | ||
1391 | { | ||
1392 | u16 rate_mask; | ||
1393 | u8 is_green = lq_sta->is_green; | ||
1394 | s32 rate; | ||
1395 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
1396 | struct iwl_rxon_context *ctx = sta_priv->ctx; | ||
1397 | |||
1398 | if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) | ||
1399 | return -1; | ||
1400 | |||
1401 | IWL_DEBUG_RATE(priv, "LQ: try to switch to SISO\n"); | ||
1402 | |||
1403 | tbl->is_dup = lq_sta->is_dup; | ||
1404 | tbl->lq_type = LQ_SISO; | ||
1405 | tbl->action = 0; | ||
1406 | tbl->max_search = IWL_MAX_SEARCH; | ||
1407 | rate_mask = lq_sta->active_siso_rate; | ||
1408 | |||
1409 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) | ||
1410 | tbl->is_ht40 = 1; | ||
1411 | else | ||
1412 | tbl->is_ht40 = 0; | ||
1413 | |||
1414 | if (is_green) | ||
1415 | tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/ | ||
1416 | |||
1417 | rs_set_expected_tpt_table(lq_sta, tbl); | ||
1418 | rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); | ||
1419 | |||
1420 | IWL_DEBUG_RATE(priv, "LQ: get best rate %d mask %X\n", rate, rate_mask); | ||
1421 | if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { | ||
1422 | IWL_DEBUG_RATE(priv, "can not switch with index %d rate mask %x\n", | ||
1423 | rate, rate_mask); | ||
1424 | return -1; | ||
1425 | } | ||
1426 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green); | ||
1427 | IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n", | ||
1428 | tbl->current_rate, is_green); | ||
1429 | return 0; | ||
1430 | } | ||
1431 | |||
1432 | /* | ||
1433 | * Try to switch to new modulation mode from legacy | ||
1434 | */ | ||
1435 | static int rs_move_legacy_other(struct iwl_priv *priv, | ||
1436 | struct iwl_lq_sta *lq_sta, | ||
1437 | struct ieee80211_conf *conf, | ||
1438 | struct ieee80211_sta *sta, | ||
1439 | int index) | ||
1440 | { | ||
1441 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
1442 | struct iwl_scale_tbl_info *search_tbl = | ||
1443 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | ||
1444 | struct iwl_rate_scale_data *window = &(tbl->win[index]); | ||
1445 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - | ||
1446 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | ||
1447 | u8 start_action; | ||
1448 | u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant; | ||
1449 | u8 tx_chains_num = priv->hw_params.tx_chains_num; | ||
1450 | int ret = 0; | ||
1451 | u8 update_search_tbl_counter = 0; | ||
1452 | |||
1453 | switch (priv->bt_traffic_load) { | ||
1454 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | ||
1455 | /* nothing */ | ||
1456 | break; | ||
1457 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | ||
1458 | /* avoid antenna B unless MIMO */ | ||
1459 | if (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2) | ||
1460 | tbl->action = IWL_LEGACY_SWITCH_SISO; | ||
1461 | break; | ||
1462 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | ||
1463 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | ||
1464 | /* avoid antenna B and MIMO */ | ||
1465 | valid_tx_ant = | ||
1466 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
1467 | if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 && | ||
1468 | tbl->action != IWL_LEGACY_SWITCH_SISO) | ||
1469 | tbl->action = IWL_LEGACY_SWITCH_SISO; | ||
1470 | break; | ||
1471 | default: | ||
1472 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); | ||
1473 | break; | ||
1474 | } | ||
1475 | |||
1476 | if (!iwl_ht_enabled(priv)) | ||
1477 | /* stay in Legacy */ | ||
1478 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; | ||
1479 | else if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE && | ||
1480 | tbl->action > IWL_LEGACY_SWITCH_SISO) | ||
1481 | tbl->action = IWL_LEGACY_SWITCH_SISO; | ||
1482 | |||
1483 | /* configure as 1x1 if bt full concurrency */ | ||
1484 | if (priv->bt_full_concurrent) { | ||
1485 | if (!iwl_ht_enabled(priv)) | ||
1486 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; | ||
1487 | else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2) | ||
1488 | tbl->action = IWL_LEGACY_SWITCH_SISO; | ||
1489 | valid_tx_ant = | ||
1490 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
1491 | } | ||
1492 | |||
1493 | start_action = tbl->action; | ||
1494 | for (; ;) { | ||
1495 | lq_sta->action_counter++; | ||
1496 | switch (tbl->action) { | ||
1497 | case IWL_LEGACY_SWITCH_ANTENNA1: | ||
1498 | case IWL_LEGACY_SWITCH_ANTENNA2: | ||
1499 | IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n"); | ||
1500 | |||
1501 | if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 && | ||
1502 | tx_chains_num <= 1) || | ||
1503 | (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 && | ||
1504 | tx_chains_num <= 2)) | ||
1505 | break; | ||
1506 | |||
1507 | /* Don't change antenna if success has been great */ | ||
1508 | if (window->success_ratio >= IWL_RS_GOOD_RATIO && | ||
1509 | !priv->bt_full_concurrent && | ||
1510 | priv->bt_traffic_load == | ||
1511 | IWL_BT_COEX_TRAFFIC_LOAD_NONE) | ||
1512 | break; | ||
1513 | |||
1514 | /* Set up search table to try other antenna */ | ||
1515 | memcpy(search_tbl, tbl, sz); | ||
1516 | |||
1517 | if (rs_toggle_antenna(valid_tx_ant, | ||
1518 | &search_tbl->current_rate, search_tbl)) { | ||
1519 | update_search_tbl_counter = 1; | ||
1520 | rs_set_expected_tpt_table(lq_sta, search_tbl); | ||
1521 | goto out; | ||
1522 | } | ||
1523 | break; | ||
1524 | case IWL_LEGACY_SWITCH_SISO: | ||
1525 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to SISO\n"); | ||
1526 | |||
1527 | /* Set up search table to try SISO */ | ||
1528 | memcpy(search_tbl, tbl, sz); | ||
1529 | search_tbl->is_SGI = 0; | ||
1530 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, | ||
1531 | search_tbl, index); | ||
1532 | if (!ret) { | ||
1533 | lq_sta->action_counter = 0; | ||
1534 | goto out; | ||
1535 | } | ||
1536 | |||
1537 | break; | ||
1538 | case IWL_LEGACY_SWITCH_MIMO2_AB: | ||
1539 | case IWL_LEGACY_SWITCH_MIMO2_AC: | ||
1540 | case IWL_LEGACY_SWITCH_MIMO2_BC: | ||
1541 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO2\n"); | ||
1542 | |||
1543 | /* Set up search table to try MIMO */ | ||
1544 | memcpy(search_tbl, tbl, sz); | ||
1545 | search_tbl->is_SGI = 0; | ||
1546 | |||
1547 | if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB) | ||
1548 | search_tbl->ant_type = ANT_AB; | ||
1549 | else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC) | ||
1550 | search_tbl->ant_type = ANT_AC; | ||
1551 | else | ||
1552 | search_tbl->ant_type = ANT_BC; | ||
1553 | |||
1554 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
1555 | break; | ||
1556 | |||
1557 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, | ||
1558 | search_tbl, index); | ||
1559 | if (!ret) { | ||
1560 | lq_sta->action_counter = 0; | ||
1561 | goto out; | ||
1562 | } | ||
1563 | break; | ||
1564 | |||
1565 | case IWL_LEGACY_SWITCH_MIMO3_ABC: | ||
1566 | IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n"); | ||
1567 | |||
1568 | /* Set up search table to try MIMO3 */ | ||
1569 | memcpy(search_tbl, tbl, sz); | ||
1570 | search_tbl->is_SGI = 0; | ||
1571 | |||
1572 | search_tbl->ant_type = ANT_ABC; | ||
1573 | |||
1574 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
1575 | break; | ||
1576 | |||
1577 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, | ||
1578 | search_tbl, index); | ||
1579 | if (!ret) { | ||
1580 | lq_sta->action_counter = 0; | ||
1581 | goto out; | ||
1582 | } | ||
1583 | break; | ||
1584 | } | ||
1585 | tbl->action++; | ||
1586 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) | ||
1587 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; | ||
1588 | |||
1589 | if (tbl->action == start_action) | ||
1590 | break; | ||
1591 | |||
1592 | } | ||
1593 | search_tbl->lq_type = LQ_NONE; | ||
1594 | return 0; | ||
1595 | |||
1596 | out: | ||
1597 | lq_sta->search_better_tbl = 1; | ||
1598 | tbl->action++; | ||
1599 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) | ||
1600 | tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; | ||
1601 | if (update_search_tbl_counter) | ||
1602 | search_tbl->action = tbl->action; | ||
1603 | return 0; | ||
1604 | |||
1605 | } | ||
1606 | |||
1607 | /* | ||
1608 | * Try to switch to new modulation mode from SISO | ||
1609 | */ | ||
1610 | static int rs_move_siso_to_other(struct iwl_priv *priv, | ||
1611 | struct iwl_lq_sta *lq_sta, | ||
1612 | struct ieee80211_conf *conf, | ||
1613 | struct ieee80211_sta *sta, int index) | ||
1614 | { | ||
1615 | u8 is_green = lq_sta->is_green; | ||
1616 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
1617 | struct iwl_scale_tbl_info *search_tbl = | ||
1618 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | ||
1619 | struct iwl_rate_scale_data *window = &(tbl->win[index]); | ||
1620 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | ||
1621 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - | ||
1622 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | ||
1623 | u8 start_action; | ||
1624 | u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant; | ||
1625 | u8 tx_chains_num = priv->hw_params.tx_chains_num; | ||
1626 | u8 update_search_tbl_counter = 0; | ||
1627 | int ret; | ||
1628 | |||
1629 | switch (priv->bt_traffic_load) { | ||
1630 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | ||
1631 | /* nothing */ | ||
1632 | break; | ||
1633 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | ||
1634 | /* avoid antenna B unless MIMO */ | ||
1635 | if (tbl->action == IWL_SISO_SWITCH_ANTENNA2) | ||
1636 | tbl->action = IWL_SISO_SWITCH_MIMO2_AB; | ||
1637 | break; | ||
1638 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | ||
1639 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | ||
1640 | /* avoid antenna B and MIMO */ | ||
1641 | valid_tx_ant = | ||
1642 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
1643 | if (tbl->action != IWL_SISO_SWITCH_ANTENNA1) | ||
1644 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; | ||
1645 | break; | ||
1646 | default: | ||
1647 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); | ||
1648 | break; | ||
1649 | } | ||
1650 | |||
1651 | if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE && | ||
1652 | tbl->action > IWL_SISO_SWITCH_ANTENNA2) { | ||
1653 | /* stay in SISO */ | ||
1654 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; | ||
1655 | } | ||
1656 | |||
1657 | /* configure as 1x1 if bt full concurrency */ | ||
1658 | if (priv->bt_full_concurrent) { | ||
1659 | valid_tx_ant = | ||
1660 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
1661 | if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2) | ||
1662 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; | ||
1663 | } | ||
1664 | |||
1665 | start_action = tbl->action; | ||
1666 | for (;;) { | ||
1667 | lq_sta->action_counter++; | ||
1668 | switch (tbl->action) { | ||
1669 | case IWL_SISO_SWITCH_ANTENNA1: | ||
1670 | case IWL_SISO_SWITCH_ANTENNA2: | ||
1671 | IWL_DEBUG_RATE(priv, "LQ: SISO toggle Antenna\n"); | ||
1672 | if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 && | ||
1673 | tx_chains_num <= 1) || | ||
1674 | (tbl->action == IWL_SISO_SWITCH_ANTENNA2 && | ||
1675 | tx_chains_num <= 2)) | ||
1676 | break; | ||
1677 | |||
1678 | if (window->success_ratio >= IWL_RS_GOOD_RATIO && | ||
1679 | !priv->bt_full_concurrent && | ||
1680 | priv->bt_traffic_load == | ||
1681 | IWL_BT_COEX_TRAFFIC_LOAD_NONE) | ||
1682 | break; | ||
1683 | |||
1684 | memcpy(search_tbl, tbl, sz); | ||
1685 | if (rs_toggle_antenna(valid_tx_ant, | ||
1686 | &search_tbl->current_rate, search_tbl)) { | ||
1687 | update_search_tbl_counter = 1; | ||
1688 | goto out; | ||
1689 | } | ||
1690 | break; | ||
1691 | case IWL_SISO_SWITCH_MIMO2_AB: | ||
1692 | case IWL_SISO_SWITCH_MIMO2_AC: | ||
1693 | case IWL_SISO_SWITCH_MIMO2_BC: | ||
1694 | IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO2\n"); | ||
1695 | memcpy(search_tbl, tbl, sz); | ||
1696 | search_tbl->is_SGI = 0; | ||
1697 | |||
1698 | if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB) | ||
1699 | search_tbl->ant_type = ANT_AB; | ||
1700 | else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC) | ||
1701 | search_tbl->ant_type = ANT_AC; | ||
1702 | else | ||
1703 | search_tbl->ant_type = ANT_BC; | ||
1704 | |||
1705 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
1706 | break; | ||
1707 | |||
1708 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, | ||
1709 | search_tbl, index); | ||
1710 | if (!ret) | ||
1711 | goto out; | ||
1712 | break; | ||
1713 | case IWL_SISO_SWITCH_GI: | ||
1714 | if (!tbl->is_ht40 && !(ht_cap->cap & | ||
1715 | IEEE80211_HT_CAP_SGI_20)) | ||
1716 | break; | ||
1717 | if (tbl->is_ht40 && !(ht_cap->cap & | ||
1718 | IEEE80211_HT_CAP_SGI_40)) | ||
1719 | break; | ||
1720 | |||
1721 | IWL_DEBUG_RATE(priv, "LQ: SISO toggle SGI/NGI\n"); | ||
1722 | |||
1723 | memcpy(search_tbl, tbl, sz); | ||
1724 | if (is_green) { | ||
1725 | if (!tbl->is_SGI) | ||
1726 | break; | ||
1727 | else | ||
1728 | IWL_ERR(priv, | ||
1729 | "SGI was set in GF+SISO\n"); | ||
1730 | } | ||
1731 | search_tbl->is_SGI = !tbl->is_SGI; | ||
1732 | rs_set_expected_tpt_table(lq_sta, search_tbl); | ||
1733 | if (tbl->is_SGI) { | ||
1734 | s32 tpt = lq_sta->last_tpt / 100; | ||
1735 | if (tpt >= search_tbl->expected_tpt[index]) | ||
1736 | break; | ||
1737 | } | ||
1738 | search_tbl->current_rate = | ||
1739 | rate_n_flags_from_tbl(priv, search_tbl, | ||
1740 | index, is_green); | ||
1741 | update_search_tbl_counter = 1; | ||
1742 | goto out; | ||
1743 | case IWL_SISO_SWITCH_MIMO3_ABC: | ||
1744 | IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n"); | ||
1745 | memcpy(search_tbl, tbl, sz); | ||
1746 | search_tbl->is_SGI = 0; | ||
1747 | search_tbl->ant_type = ANT_ABC; | ||
1748 | |||
1749 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
1750 | break; | ||
1751 | |||
1752 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, | ||
1753 | search_tbl, index); | ||
1754 | if (!ret) | ||
1755 | goto out; | ||
1756 | break; | ||
1757 | } | ||
1758 | tbl->action++; | ||
1759 | if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC) | ||
1760 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; | ||
1761 | |||
1762 | if (tbl->action == start_action) | ||
1763 | break; | ||
1764 | } | ||
1765 | search_tbl->lq_type = LQ_NONE; | ||
1766 | return 0; | ||
1767 | |||
1768 | out: | ||
1769 | lq_sta->search_better_tbl = 1; | ||
1770 | tbl->action++; | ||
1771 | if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC) | ||
1772 | tbl->action = IWL_SISO_SWITCH_ANTENNA1; | ||
1773 | if (update_search_tbl_counter) | ||
1774 | search_tbl->action = tbl->action; | ||
1775 | |||
1776 | return 0; | ||
1777 | } | ||
1778 | |||
1779 | /* | ||
1780 | * Try to switch to new modulation mode from MIMO2 | ||
1781 | */ | ||
1782 | static int rs_move_mimo2_to_other(struct iwl_priv *priv, | ||
1783 | struct iwl_lq_sta *lq_sta, | ||
1784 | struct ieee80211_conf *conf, | ||
1785 | struct ieee80211_sta *sta, int index) | ||
1786 | { | ||
1787 | s8 is_green = lq_sta->is_green; | ||
1788 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
1789 | struct iwl_scale_tbl_info *search_tbl = | ||
1790 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | ||
1791 | struct iwl_rate_scale_data *window = &(tbl->win[index]); | ||
1792 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | ||
1793 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - | ||
1794 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | ||
1795 | u8 start_action; | ||
1796 | u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant; | ||
1797 | u8 tx_chains_num = priv->hw_params.tx_chains_num; | ||
1798 | u8 update_search_tbl_counter = 0; | ||
1799 | int ret; | ||
1800 | |||
1801 | switch (priv->bt_traffic_load) { | ||
1802 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | ||
1803 | /* nothing */ | ||
1804 | break; | ||
1805 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | ||
1806 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | ||
1807 | /* avoid antenna B and MIMO */ | ||
1808 | if (tbl->action != IWL_MIMO2_SWITCH_SISO_A) | ||
1809 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; | ||
1810 | break; | ||
1811 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | ||
1812 | /* avoid antenna B unless MIMO */ | ||
1813 | if (tbl->action == IWL_MIMO2_SWITCH_SISO_B || | ||
1814 | tbl->action == IWL_MIMO2_SWITCH_SISO_C) | ||
1815 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; | ||
1816 | break; | ||
1817 | default: | ||
1818 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); | ||
1819 | break; | ||
1820 | } | ||
1821 | |||
1822 | if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) && | ||
1823 | (tbl->action < IWL_MIMO2_SWITCH_SISO_A || | ||
1824 | tbl->action > IWL_MIMO2_SWITCH_SISO_C)) { | ||
1825 | /* switch in SISO */ | ||
1826 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; | ||
1827 | } | ||
1828 | |||
1829 | /* configure as 1x1 if bt full concurrency */ | ||
1830 | if (priv->bt_full_concurrent && | ||
1831 | (tbl->action < IWL_MIMO2_SWITCH_SISO_A || | ||
1832 | tbl->action > IWL_MIMO2_SWITCH_SISO_C)) | ||
1833 | tbl->action = IWL_MIMO2_SWITCH_SISO_A; | ||
1834 | |||
1835 | start_action = tbl->action; | ||
1836 | for (;;) { | ||
1837 | lq_sta->action_counter++; | ||
1838 | switch (tbl->action) { | ||
1839 | case IWL_MIMO2_SWITCH_ANTENNA1: | ||
1840 | case IWL_MIMO2_SWITCH_ANTENNA2: | ||
1841 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n"); | ||
1842 | |||
1843 | if (tx_chains_num <= 2) | ||
1844 | break; | ||
1845 | |||
1846 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) | ||
1847 | break; | ||
1848 | |||
1849 | memcpy(search_tbl, tbl, sz); | ||
1850 | if (rs_toggle_antenna(valid_tx_ant, | ||
1851 | &search_tbl->current_rate, search_tbl)) { | ||
1852 | update_search_tbl_counter = 1; | ||
1853 | goto out; | ||
1854 | } | ||
1855 | break; | ||
1856 | case IWL_MIMO2_SWITCH_SISO_A: | ||
1857 | case IWL_MIMO2_SWITCH_SISO_B: | ||
1858 | case IWL_MIMO2_SWITCH_SISO_C: | ||
1859 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to SISO\n"); | ||
1860 | |||
1861 | /* Set up new search table for SISO */ | ||
1862 | memcpy(search_tbl, tbl, sz); | ||
1863 | |||
1864 | if (tbl->action == IWL_MIMO2_SWITCH_SISO_A) | ||
1865 | search_tbl->ant_type = ANT_A; | ||
1866 | else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B) | ||
1867 | search_tbl->ant_type = ANT_B; | ||
1868 | else | ||
1869 | search_tbl->ant_type = ANT_C; | ||
1870 | |||
1871 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
1872 | break; | ||
1873 | |||
1874 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, | ||
1875 | search_tbl, index); | ||
1876 | if (!ret) | ||
1877 | goto out; | ||
1878 | |||
1879 | break; | ||
1880 | |||
1881 | case IWL_MIMO2_SWITCH_GI: | ||
1882 | if (!tbl->is_ht40 && !(ht_cap->cap & | ||
1883 | IEEE80211_HT_CAP_SGI_20)) | ||
1884 | break; | ||
1885 | if (tbl->is_ht40 && !(ht_cap->cap & | ||
1886 | IEEE80211_HT_CAP_SGI_40)) | ||
1887 | break; | ||
1888 | |||
1889 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n"); | ||
1890 | |||
1891 | /* Set up new search table for MIMO2 */ | ||
1892 | memcpy(search_tbl, tbl, sz); | ||
1893 | search_tbl->is_SGI = !tbl->is_SGI; | ||
1894 | rs_set_expected_tpt_table(lq_sta, search_tbl); | ||
1895 | /* | ||
1896 | * If active table already uses the fastest possible | ||
1897 | * modulation (dual stream with short guard interval), | ||
1898 | * and it's working well, there's no need to look | ||
1899 | * for a better type of modulation! | ||
1900 | */ | ||
1901 | if (tbl->is_SGI) { | ||
1902 | s32 tpt = lq_sta->last_tpt / 100; | ||
1903 | if (tpt >= search_tbl->expected_tpt[index]) | ||
1904 | break; | ||
1905 | } | ||
1906 | search_tbl->current_rate = | ||
1907 | rate_n_flags_from_tbl(priv, search_tbl, | ||
1908 | index, is_green); | ||
1909 | update_search_tbl_counter = 1; | ||
1910 | goto out; | ||
1911 | |||
1912 | case IWL_MIMO2_SWITCH_MIMO3_ABC: | ||
1913 | IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n"); | ||
1914 | memcpy(search_tbl, tbl, sz); | ||
1915 | search_tbl->is_SGI = 0; | ||
1916 | search_tbl->ant_type = ANT_ABC; | ||
1917 | |||
1918 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
1919 | break; | ||
1920 | |||
1921 | ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta, | ||
1922 | search_tbl, index); | ||
1923 | if (!ret) | ||
1924 | goto out; | ||
1925 | |||
1926 | break; | ||
1927 | } | ||
1928 | tbl->action++; | ||
1929 | if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC) | ||
1930 | tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; | ||
1931 | |||
1932 | if (tbl->action == start_action) | ||
1933 | break; | ||
1934 | } | ||
1935 | search_tbl->lq_type = LQ_NONE; | ||
1936 | return 0; | ||
1937 | out: | ||
1938 | lq_sta->search_better_tbl = 1; | ||
1939 | tbl->action++; | ||
1940 | if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC) | ||
1941 | tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; | ||
1942 | if (update_search_tbl_counter) | ||
1943 | search_tbl->action = tbl->action; | ||
1944 | |||
1945 | return 0; | ||
1946 | |||
1947 | } | ||
1948 | |||
1949 | /* | ||
1950 | * Try to switch to new modulation mode from MIMO3 | ||
1951 | */ | ||
1952 | static int rs_move_mimo3_to_other(struct iwl_priv *priv, | ||
1953 | struct iwl_lq_sta *lq_sta, | ||
1954 | struct ieee80211_conf *conf, | ||
1955 | struct ieee80211_sta *sta, int index) | ||
1956 | { | ||
1957 | s8 is_green = lq_sta->is_green; | ||
1958 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
1959 | struct iwl_scale_tbl_info *search_tbl = | ||
1960 | &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | ||
1961 | struct iwl_rate_scale_data *window = &(tbl->win[index]); | ||
1962 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | ||
1963 | u32 sz = (sizeof(struct iwl_scale_tbl_info) - | ||
1964 | (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); | ||
1965 | u8 start_action; | ||
1966 | u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant; | ||
1967 | u8 tx_chains_num = priv->hw_params.tx_chains_num; | ||
1968 | int ret; | ||
1969 | u8 update_search_tbl_counter = 0; | ||
1970 | |||
1971 | switch (priv->bt_traffic_load) { | ||
1972 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | ||
1973 | /* nothing */ | ||
1974 | break; | ||
1975 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | ||
1976 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | ||
1977 | /* avoid antenna B and MIMO */ | ||
1978 | if (tbl->action != IWL_MIMO3_SWITCH_SISO_A) | ||
1979 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; | ||
1980 | break; | ||
1981 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | ||
1982 | /* avoid antenna B unless MIMO */ | ||
1983 | if (tbl->action == IWL_MIMO3_SWITCH_SISO_B || | ||
1984 | tbl->action == IWL_MIMO3_SWITCH_SISO_C) | ||
1985 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; | ||
1986 | break; | ||
1987 | default: | ||
1988 | IWL_ERR(priv, "Invalid BT load %d", priv->bt_traffic_load); | ||
1989 | break; | ||
1990 | } | ||
1991 | |||
1992 | if ((iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE) && | ||
1993 | (tbl->action < IWL_MIMO3_SWITCH_SISO_A || | ||
1994 | tbl->action > IWL_MIMO3_SWITCH_SISO_C)) { | ||
1995 | /* switch in SISO */ | ||
1996 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; | ||
1997 | } | ||
1998 | |||
1999 | /* configure as 1x1 if bt full concurrency */ | ||
2000 | if (priv->bt_full_concurrent && | ||
2001 | (tbl->action < IWL_MIMO3_SWITCH_SISO_A || | ||
2002 | tbl->action > IWL_MIMO3_SWITCH_SISO_C)) | ||
2003 | tbl->action = IWL_MIMO3_SWITCH_SISO_A; | ||
2004 | |||
2005 | start_action = tbl->action; | ||
2006 | for (;;) { | ||
2007 | lq_sta->action_counter++; | ||
2008 | switch (tbl->action) { | ||
2009 | case IWL_MIMO3_SWITCH_ANTENNA1: | ||
2010 | case IWL_MIMO3_SWITCH_ANTENNA2: | ||
2011 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n"); | ||
2012 | |||
2013 | if (tx_chains_num <= 3) | ||
2014 | break; | ||
2015 | |||
2016 | if (window->success_ratio >= IWL_RS_GOOD_RATIO) | ||
2017 | break; | ||
2018 | |||
2019 | memcpy(search_tbl, tbl, sz); | ||
2020 | if (rs_toggle_antenna(valid_tx_ant, | ||
2021 | &search_tbl->current_rate, search_tbl)) | ||
2022 | goto out; | ||
2023 | break; | ||
2024 | case IWL_MIMO3_SWITCH_SISO_A: | ||
2025 | case IWL_MIMO3_SWITCH_SISO_B: | ||
2026 | case IWL_MIMO3_SWITCH_SISO_C: | ||
2027 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n"); | ||
2028 | |||
2029 | /* Set up new search table for SISO */ | ||
2030 | memcpy(search_tbl, tbl, sz); | ||
2031 | |||
2032 | if (tbl->action == IWL_MIMO3_SWITCH_SISO_A) | ||
2033 | search_tbl->ant_type = ANT_A; | ||
2034 | else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B) | ||
2035 | search_tbl->ant_type = ANT_B; | ||
2036 | else | ||
2037 | search_tbl->ant_type = ANT_C; | ||
2038 | |||
2039 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
2040 | break; | ||
2041 | |||
2042 | ret = rs_switch_to_siso(priv, lq_sta, conf, sta, | ||
2043 | search_tbl, index); | ||
2044 | if (!ret) | ||
2045 | goto out; | ||
2046 | |||
2047 | break; | ||
2048 | |||
2049 | case IWL_MIMO3_SWITCH_MIMO2_AB: | ||
2050 | case IWL_MIMO3_SWITCH_MIMO2_AC: | ||
2051 | case IWL_MIMO3_SWITCH_MIMO2_BC: | ||
2052 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n"); | ||
2053 | |||
2054 | memcpy(search_tbl, tbl, sz); | ||
2055 | search_tbl->is_SGI = 0; | ||
2056 | if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB) | ||
2057 | search_tbl->ant_type = ANT_AB; | ||
2058 | else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC) | ||
2059 | search_tbl->ant_type = ANT_AC; | ||
2060 | else | ||
2061 | search_tbl->ant_type = ANT_BC; | ||
2062 | |||
2063 | if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type)) | ||
2064 | break; | ||
2065 | |||
2066 | ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta, | ||
2067 | search_tbl, index); | ||
2068 | if (!ret) | ||
2069 | goto out; | ||
2070 | |||
2071 | break; | ||
2072 | |||
2073 | case IWL_MIMO3_SWITCH_GI: | ||
2074 | if (!tbl->is_ht40 && !(ht_cap->cap & | ||
2075 | IEEE80211_HT_CAP_SGI_20)) | ||
2076 | break; | ||
2077 | if (tbl->is_ht40 && !(ht_cap->cap & | ||
2078 | IEEE80211_HT_CAP_SGI_40)) | ||
2079 | break; | ||
2080 | |||
2081 | IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n"); | ||
2082 | |||
2083 | /* Set up new search table for MIMO */ | ||
2084 | memcpy(search_tbl, tbl, sz); | ||
2085 | search_tbl->is_SGI = !tbl->is_SGI; | ||
2086 | rs_set_expected_tpt_table(lq_sta, search_tbl); | ||
2087 | /* | ||
2088 | * If active table already uses the fastest possible | ||
2089 | * modulation (dual stream with short guard interval), | ||
2090 | * and it's working well, there's no need to look | ||
2091 | * for a better type of modulation! | ||
2092 | */ | ||
2093 | if (tbl->is_SGI) { | ||
2094 | s32 tpt = lq_sta->last_tpt / 100; | ||
2095 | if (tpt >= search_tbl->expected_tpt[index]) | ||
2096 | break; | ||
2097 | } | ||
2098 | search_tbl->current_rate = | ||
2099 | rate_n_flags_from_tbl(priv, search_tbl, | ||
2100 | index, is_green); | ||
2101 | update_search_tbl_counter = 1; | ||
2102 | goto out; | ||
2103 | } | ||
2104 | tbl->action++; | ||
2105 | if (tbl->action > IWL_MIMO3_SWITCH_GI) | ||
2106 | tbl->action = IWL_MIMO3_SWITCH_ANTENNA1; | ||
2107 | |||
2108 | if (tbl->action == start_action) | ||
2109 | break; | ||
2110 | } | ||
2111 | search_tbl->lq_type = LQ_NONE; | ||
2112 | return 0; | ||
2113 | out: | ||
2114 | lq_sta->search_better_tbl = 1; | ||
2115 | tbl->action++; | ||
2116 | if (tbl->action > IWL_MIMO3_SWITCH_GI) | ||
2117 | tbl->action = IWL_MIMO3_SWITCH_ANTENNA1; | ||
2118 | if (update_search_tbl_counter) | ||
2119 | search_tbl->action = tbl->action; | ||
2120 | |||
2121 | return 0; | ||
2122 | |||
2123 | } | ||
2124 | |||
2125 | /* | ||
2126 | * Check whether we should continue using same modulation mode, or | ||
2127 | * begin search for a new mode, based on: | ||
2128 | * 1) # tx successes or failures while using this mode | ||
2129 | * 2) # times calling this function | ||
2130 | * 3) elapsed time in this mode (not used, for now) | ||
2131 | */ | ||
2132 | static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search) | ||
2133 | { | ||
2134 | struct iwl_scale_tbl_info *tbl; | ||
2135 | int i; | ||
2136 | int active_tbl; | ||
2137 | int flush_interval_passed = 0; | ||
2138 | struct iwl_priv *priv; | ||
2139 | |||
2140 | priv = lq_sta->drv; | ||
2141 | active_tbl = lq_sta->active_tbl; | ||
2142 | |||
2143 | tbl = &(lq_sta->lq_info[active_tbl]); | ||
2144 | |||
2145 | /* If we've been disallowing search, see if we should now allow it */ | ||
2146 | if (lq_sta->stay_in_tbl) { | ||
2147 | |||
2148 | /* Elapsed time using current modulation mode */ | ||
2149 | if (lq_sta->flush_timer) | ||
2150 | flush_interval_passed = | ||
2151 | time_after(jiffies, | ||
2152 | (unsigned long)(lq_sta->flush_timer + | ||
2153 | IWL_RATE_SCALE_FLUSH_INTVL)); | ||
2154 | |||
2155 | /* | ||
2156 | * Check if we should allow search for new modulation mode. | ||
2157 | * If many frames have failed or succeeded, or we've used | ||
2158 | * this same modulation for a long time, allow search, and | ||
2159 | * reset history stats that keep track of whether we should | ||
2160 | * allow a new search. Also (below) reset all bitmaps and | ||
2161 | * stats in active history. | ||
2162 | */ | ||
2163 | if (force_search || | ||
2164 | (lq_sta->total_failed > lq_sta->max_failure_limit) || | ||
2165 | (lq_sta->total_success > lq_sta->max_success_limit) || | ||
2166 | ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer) | ||
2167 | && (flush_interval_passed))) { | ||
2168 | IWL_DEBUG_RATE(priv, "LQ: stay is expired %d %d %d\n", | ||
2169 | lq_sta->total_failed, | ||
2170 | lq_sta->total_success, | ||
2171 | flush_interval_passed); | ||
2172 | |||
2173 | /* Allow search for new mode */ | ||
2174 | lq_sta->stay_in_tbl = 0; /* only place reset */ | ||
2175 | lq_sta->total_failed = 0; | ||
2176 | lq_sta->total_success = 0; | ||
2177 | lq_sta->flush_timer = 0; | ||
2178 | |||
2179 | /* | ||
2180 | * Else if we've used this modulation mode enough repetitions | ||
2181 | * (regardless of elapsed time or success/failure), reset | ||
2182 | * history bitmaps and rate-specific stats for all rates in | ||
2183 | * active table. | ||
2184 | */ | ||
2185 | } else { | ||
2186 | lq_sta->table_count++; | ||
2187 | if (lq_sta->table_count >= | ||
2188 | lq_sta->table_count_limit) { | ||
2189 | lq_sta->table_count = 0; | ||
2190 | |||
2191 | IWL_DEBUG_RATE(priv, "LQ: stay in table clear win\n"); | ||
2192 | for (i = 0; i < IWL_RATE_COUNT; i++) | ||
2193 | rs_rate_scale_clear_window( | ||
2194 | &(tbl->win[i])); | ||
2195 | } | ||
2196 | } | ||
2197 | |||
2198 | /* If transitioning to allow "search", reset all history | ||
2199 | * bitmaps and stats in active table (this will become the new | ||
2200 | * "search" table). */ | ||
2201 | if (!lq_sta->stay_in_tbl) { | ||
2202 | for (i = 0; i < IWL_RATE_COUNT; i++) | ||
2203 | rs_rate_scale_clear_window(&(tbl->win[i])); | ||
2204 | } | ||
2205 | } | ||
2206 | } | ||
2207 | |||
2208 | /* | ||
2209 | * setup rate table in uCode | ||
2210 | */ | ||
2211 | static void rs_update_rate_tbl(struct iwl_priv *priv, | ||
2212 | struct iwl_rxon_context *ctx, | ||
2213 | struct iwl_lq_sta *lq_sta, | ||
2214 | struct iwl_scale_tbl_info *tbl, | ||
2215 | int index, u8 is_green) | ||
2216 | { | ||
2217 | u32 rate; | ||
2218 | |||
2219 | /* Update uCode's rate table. */ | ||
2220 | rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); | ||
2221 | rs_fill_link_cmd(priv, lq_sta, rate); | ||
2222 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); | ||
2223 | } | ||
2224 | |||
2225 | /* | ||
2226 | * Do rate scaling and search for new modulation mode. | ||
2227 | */ | ||
2228 | static void rs_rate_scale_perform(struct iwl_priv *priv, | ||
2229 | struct sk_buff *skb, | ||
2230 | struct ieee80211_sta *sta, | ||
2231 | struct iwl_lq_sta *lq_sta) | ||
2232 | { | ||
2233 | struct ieee80211_hw *hw = priv->hw; | ||
2234 | struct ieee80211_conf *conf = &hw->conf; | ||
2235 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | ||
2236 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | ||
2237 | int low = IWL_RATE_INVALID; | ||
2238 | int high = IWL_RATE_INVALID; | ||
2239 | int index; | ||
2240 | int i; | ||
2241 | struct iwl_rate_scale_data *window = NULL; | ||
2242 | int current_tpt = IWL_INVALID_VALUE; | ||
2243 | int low_tpt = IWL_INVALID_VALUE; | ||
2244 | int high_tpt = IWL_INVALID_VALUE; | ||
2245 | u32 fail_count; | ||
2246 | s8 scale_action = 0; | ||
2247 | u16 rate_mask; | ||
2248 | u8 update_lq = 0; | ||
2249 | struct iwl_scale_tbl_info *tbl, *tbl1; | ||
2250 | u16 rate_scale_index_msk = 0; | ||
2251 | u8 is_green = 0; | ||
2252 | u8 active_tbl = 0; | ||
2253 | u8 done_search = 0; | ||
2254 | u16 high_low; | ||
2255 | s32 sr; | ||
2256 | u8 tid = IWL_MAX_TID_COUNT; | ||
2257 | struct iwl_tid_data *tid_data; | ||
2258 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
2259 | struct iwl_rxon_context *ctx = sta_priv->ctx; | ||
2260 | |||
2261 | IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n"); | ||
2262 | |||
2263 | /* Send management frames and NO_ACK data using lowest rate. */ | ||
2264 | /* TODO: this could probably be improved.. */ | ||
2265 | if (!ieee80211_is_data(hdr->frame_control) || | ||
2266 | info->flags & IEEE80211_TX_CTL_NO_ACK) | ||
2267 | return; | ||
2268 | |||
2269 | lq_sta->supp_rates = sta->supp_rates[lq_sta->band]; | ||
2270 | |||
2271 | tid = rs_tl_add_packet(lq_sta, hdr); | ||
2272 | if ((tid != IWL_MAX_TID_COUNT) && | ||
2273 | (lq_sta->tx_agg_tid_en & (1 << tid))) { | ||
2274 | tid_data = &priv->tid_data[lq_sta->lq.sta_id][tid]; | ||
2275 | if (tid_data->agg.state == IWL_AGG_OFF) | ||
2276 | lq_sta->is_agg = 0; | ||
2277 | else | ||
2278 | lq_sta->is_agg = 1; | ||
2279 | } else | ||
2280 | lq_sta->is_agg = 0; | ||
2281 | |||
2282 | /* | ||
2283 | * Select rate-scale / modulation-mode table to work with in | ||
2284 | * the rest of this function: "search" if searching for better | ||
2285 | * modulation mode, or "active" if doing rate scaling within a mode. | ||
2286 | */ | ||
2287 | if (!lq_sta->search_better_tbl) | ||
2288 | active_tbl = lq_sta->active_tbl; | ||
2289 | else | ||
2290 | active_tbl = 1 - lq_sta->active_tbl; | ||
2291 | |||
2292 | tbl = &(lq_sta->lq_info[active_tbl]); | ||
2293 | if (is_legacy(tbl->lq_type)) | ||
2294 | lq_sta->is_green = 0; | ||
2295 | else | ||
2296 | lq_sta->is_green = rs_use_green(sta); | ||
2297 | is_green = lq_sta->is_green; | ||
2298 | |||
2299 | /* current tx rate */ | ||
2300 | index = lq_sta->last_txrate_idx; | ||
2301 | |||
2302 | IWL_DEBUG_RATE(priv, "Rate scale index %d for type %d\n", index, | ||
2303 | tbl->lq_type); | ||
2304 | |||
2305 | /* rates available for this association, and for modulation mode */ | ||
2306 | rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type); | ||
2307 | |||
2308 | IWL_DEBUG_RATE(priv, "mask 0x%04X\n", rate_mask); | ||
2309 | |||
2310 | /* mask with station rate restriction */ | ||
2311 | if (is_legacy(tbl->lq_type)) { | ||
2312 | if (lq_sta->band == IEEE80211_BAND_5GHZ) | ||
2313 | /* supp_rates has no CCK bits in A mode */ | ||
2314 | rate_scale_index_msk = (u16) (rate_mask & | ||
2315 | (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); | ||
2316 | else | ||
2317 | rate_scale_index_msk = (u16) (rate_mask & | ||
2318 | lq_sta->supp_rates); | ||
2319 | |||
2320 | } else | ||
2321 | rate_scale_index_msk = rate_mask; | ||
2322 | |||
2323 | if (!rate_scale_index_msk) | ||
2324 | rate_scale_index_msk = rate_mask; | ||
2325 | |||
2326 | if (!((1 << index) & rate_scale_index_msk)) { | ||
2327 | IWL_ERR(priv, "Current Rate is not valid\n"); | ||
2328 | if (lq_sta->search_better_tbl) { | ||
2329 | /* revert to active table if search table is not valid*/ | ||
2330 | tbl->lq_type = LQ_NONE; | ||
2331 | lq_sta->search_better_tbl = 0; | ||
2332 | tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
2333 | /* get "active" rate info */ | ||
2334 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); | ||
2335 | rs_update_rate_tbl(priv, ctx, lq_sta, tbl, | ||
2336 | index, is_green); | ||
2337 | } | ||
2338 | return; | ||
2339 | } | ||
2340 | |||
2341 | /* Get expected throughput table and history window for current rate */ | ||
2342 | if (!tbl->expected_tpt) { | ||
2343 | IWL_ERR(priv, "tbl->expected_tpt is NULL\n"); | ||
2344 | return; | ||
2345 | } | ||
2346 | |||
2347 | /* force user max rate if set by user */ | ||
2348 | if ((lq_sta->max_rate_idx != -1) && | ||
2349 | (lq_sta->max_rate_idx < index)) { | ||
2350 | index = lq_sta->max_rate_idx; | ||
2351 | update_lq = 1; | ||
2352 | window = &(tbl->win[index]); | ||
2353 | goto lq_update; | ||
2354 | } | ||
2355 | |||
2356 | window = &(tbl->win[index]); | ||
2357 | |||
2358 | /* | ||
2359 | * If there is not enough history to calculate actual average | ||
2360 | * throughput, keep analyzing results of more tx frames, without | ||
2361 | * changing rate or mode (bypass most of the rest of this function). | ||
2362 | * Set up new rate table in uCode only if old rate is not supported | ||
2363 | * in current association (use new rate found above). | ||
2364 | */ | ||
2365 | fail_count = window->counter - window->success_counter; | ||
2366 | if ((fail_count < IWL_RATE_MIN_FAILURE_TH) && | ||
2367 | (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) { | ||
2368 | IWL_DEBUG_RATE(priv, "LQ: still below TH. succ=%d total=%d " | ||
2369 | "for index %d\n", | ||
2370 | window->success_counter, window->counter, index); | ||
2371 | |||
2372 | /* Can't calculate this yet; not enough history */ | ||
2373 | window->average_tpt = IWL_INVALID_VALUE; | ||
2374 | |||
2375 | /* Should we stay with this modulation mode, | ||
2376 | * or search for a new one? */ | ||
2377 | rs_stay_in_table(lq_sta, false); | ||
2378 | |||
2379 | goto out; | ||
2380 | } | ||
2381 | /* Else we have enough samples; calculate estimate of | ||
2382 | * actual average throughput */ | ||
2383 | if (window->average_tpt != ((window->success_ratio * | ||
2384 | tbl->expected_tpt[index] + 64) / 128)) { | ||
2385 | IWL_ERR(priv, "expected_tpt should have been calculated by now\n"); | ||
2386 | window->average_tpt = ((window->success_ratio * | ||
2387 | tbl->expected_tpt[index] + 64) / 128); | ||
2388 | } | ||
2389 | |||
2390 | /* If we are searching for better modulation mode, check success. */ | ||
2391 | if (lq_sta->search_better_tbl && | ||
2392 | (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI)) { | ||
2393 | /* If good success, continue using the "search" mode; | ||
2394 | * no need to send new link quality command, since we're | ||
2395 | * continuing to use the setup that we've been trying. */ | ||
2396 | if (window->average_tpt > lq_sta->last_tpt) { | ||
2397 | |||
2398 | IWL_DEBUG_RATE(priv, "LQ: SWITCHING TO NEW TABLE " | ||
2399 | "suc=%d cur-tpt=%d old-tpt=%d\n", | ||
2400 | window->success_ratio, | ||
2401 | window->average_tpt, | ||
2402 | lq_sta->last_tpt); | ||
2403 | |||
2404 | if (!is_legacy(tbl->lq_type)) | ||
2405 | lq_sta->enable_counter = 1; | ||
2406 | |||
2407 | /* Swap tables; "search" becomes "active" */ | ||
2408 | lq_sta->active_tbl = active_tbl; | ||
2409 | current_tpt = window->average_tpt; | ||
2410 | |||
2411 | /* Else poor success; go back to mode in "active" table */ | ||
2412 | } else { | ||
2413 | |||
2414 | IWL_DEBUG_RATE(priv, "LQ: GOING BACK TO THE OLD TABLE " | ||
2415 | "suc=%d cur-tpt=%d old-tpt=%d\n", | ||
2416 | window->success_ratio, | ||
2417 | window->average_tpt, | ||
2418 | lq_sta->last_tpt); | ||
2419 | |||
2420 | /* Nullify "search" table */ | ||
2421 | tbl->lq_type = LQ_NONE; | ||
2422 | |||
2423 | /* Revert to "active" table */ | ||
2424 | active_tbl = lq_sta->active_tbl; | ||
2425 | tbl = &(lq_sta->lq_info[active_tbl]); | ||
2426 | |||
2427 | /* Revert to "active" rate and throughput info */ | ||
2428 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); | ||
2429 | current_tpt = lq_sta->last_tpt; | ||
2430 | |||
2431 | /* Need to set up a new rate table in uCode */ | ||
2432 | update_lq = 1; | ||
2433 | } | ||
2434 | |||
2435 | /* Either way, we've made a decision; modulation mode | ||
2436 | * search is done, allow rate adjustment next time. */ | ||
2437 | lq_sta->search_better_tbl = 0; | ||
2438 | done_search = 1; /* Don't switch modes below! */ | ||
2439 | goto lq_update; | ||
2440 | } | ||
2441 | |||
2442 | /* (Else) not in search of better modulation mode, try for better | ||
2443 | * starting rate, while staying in this mode. */ | ||
2444 | high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk, | ||
2445 | tbl->lq_type); | ||
2446 | low = high_low & 0xff; | ||
2447 | high = (high_low >> 8) & 0xff; | ||
2448 | |||
2449 | /* If user set max rate, dont allow higher than user constrain */ | ||
2450 | if ((lq_sta->max_rate_idx != -1) && | ||
2451 | (lq_sta->max_rate_idx < high)) | ||
2452 | high = IWL_RATE_INVALID; | ||
2453 | |||
2454 | sr = window->success_ratio; | ||
2455 | |||
2456 | /* Collect measured throughputs for current and adjacent rates */ | ||
2457 | current_tpt = window->average_tpt; | ||
2458 | if (low != IWL_RATE_INVALID) | ||
2459 | low_tpt = tbl->win[low].average_tpt; | ||
2460 | if (high != IWL_RATE_INVALID) | ||
2461 | high_tpt = tbl->win[high].average_tpt; | ||
2462 | |||
2463 | scale_action = 0; | ||
2464 | |||
2465 | /* Too many failures, decrease rate */ | ||
2466 | if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) { | ||
2467 | IWL_DEBUG_RATE(priv, "decrease rate because of low success_ratio\n"); | ||
2468 | scale_action = -1; | ||
2469 | |||
2470 | /* No throughput measured yet for adjacent rates; try increase. */ | ||
2471 | } else if ((low_tpt == IWL_INVALID_VALUE) && | ||
2472 | (high_tpt == IWL_INVALID_VALUE)) { | ||
2473 | |||
2474 | if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH) | ||
2475 | scale_action = 1; | ||
2476 | else if (low != IWL_RATE_INVALID) | ||
2477 | scale_action = 0; | ||
2478 | } | ||
2479 | |||
2480 | /* Both adjacent throughputs are measured, but neither one has better | ||
2481 | * throughput; we're using the best rate, don't change it! */ | ||
2482 | else if ((low_tpt != IWL_INVALID_VALUE) && | ||
2483 | (high_tpt != IWL_INVALID_VALUE) && | ||
2484 | (low_tpt < current_tpt) && | ||
2485 | (high_tpt < current_tpt)) | ||
2486 | scale_action = 0; | ||
2487 | |||
2488 | /* At least one adjacent rate's throughput is measured, | ||
2489 | * and may have better performance. */ | ||
2490 | else { | ||
2491 | /* Higher adjacent rate's throughput is measured */ | ||
2492 | if (high_tpt != IWL_INVALID_VALUE) { | ||
2493 | /* Higher rate has better throughput */ | ||
2494 | if (high_tpt > current_tpt && | ||
2495 | sr >= IWL_RATE_INCREASE_TH) { | ||
2496 | scale_action = 1; | ||
2497 | } else { | ||
2498 | scale_action = 0; | ||
2499 | } | ||
2500 | |||
2501 | /* Lower adjacent rate's throughput is measured */ | ||
2502 | } else if (low_tpt != IWL_INVALID_VALUE) { | ||
2503 | /* Lower rate has better throughput */ | ||
2504 | if (low_tpt > current_tpt) { | ||
2505 | IWL_DEBUG_RATE(priv, | ||
2506 | "decrease rate because of low tpt\n"); | ||
2507 | scale_action = -1; | ||
2508 | } else if (sr >= IWL_RATE_INCREASE_TH) { | ||
2509 | scale_action = 1; | ||
2510 | } | ||
2511 | } | ||
2512 | } | ||
2513 | |||
2514 | /* Sanity check; asked for decrease, but success rate or throughput | ||
2515 | * has been good at old rate. Don't change it. */ | ||
2516 | if ((scale_action == -1) && (low != IWL_RATE_INVALID) && | ||
2517 | ((sr > IWL_RATE_HIGH_TH) || | ||
2518 | (current_tpt > (100 * tbl->expected_tpt[low])))) | ||
2519 | scale_action = 0; | ||
2520 | if (!iwl_ht_enabled(priv) && !is_legacy(tbl->lq_type)) | ||
2521 | scale_action = -1; | ||
2522 | if (iwl_tx_ant_restriction(priv) != IWL_ANT_OK_MULTI && | ||
2523 | (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) | ||
2524 | scale_action = -1; | ||
2525 | |||
2526 | if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) && | ||
2527 | (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) { | ||
2528 | if (lq_sta->last_bt_traffic > priv->bt_traffic_load) { | ||
2529 | /* | ||
2530 | * don't set scale_action, don't want to scale up if | ||
2531 | * the rate scale doesn't otherwise think that is a | ||
2532 | * good idea. | ||
2533 | */ | ||
2534 | } else if (lq_sta->last_bt_traffic <= priv->bt_traffic_load) { | ||
2535 | scale_action = -1; | ||
2536 | } | ||
2537 | } | ||
2538 | lq_sta->last_bt_traffic = priv->bt_traffic_load; | ||
2539 | |||
2540 | if ((priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) && | ||
2541 | (is_mimo2(tbl->lq_type) || is_mimo3(tbl->lq_type))) { | ||
2542 | /* search for a new modulation */ | ||
2543 | rs_stay_in_table(lq_sta, true); | ||
2544 | goto lq_update; | ||
2545 | } | ||
2546 | |||
2547 | switch (scale_action) { | ||
2548 | case -1: | ||
2549 | /* Decrease starting rate, update uCode's rate table */ | ||
2550 | if (low != IWL_RATE_INVALID) { | ||
2551 | update_lq = 1; | ||
2552 | index = low; | ||
2553 | } | ||
2554 | |||
2555 | break; | ||
2556 | case 1: | ||
2557 | /* Increase starting rate, update uCode's rate table */ | ||
2558 | if (high != IWL_RATE_INVALID) { | ||
2559 | update_lq = 1; | ||
2560 | index = high; | ||
2561 | } | ||
2562 | |||
2563 | break; | ||
2564 | case 0: | ||
2565 | /* No change */ | ||
2566 | default: | ||
2567 | break; | ||
2568 | } | ||
2569 | |||
2570 | IWL_DEBUG_RATE(priv, "choose rate scale index %d action %d low %d " | ||
2571 | "high %d type %d\n", | ||
2572 | index, scale_action, low, high, tbl->lq_type); | ||
2573 | |||
2574 | lq_update: | ||
2575 | /* Replace uCode's rate table for the destination station. */ | ||
2576 | if (update_lq) | ||
2577 | rs_update_rate_tbl(priv, ctx, lq_sta, tbl, index, is_green); | ||
2578 | |||
2579 | if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) { | ||
2580 | /* Should we stay with this modulation mode, | ||
2581 | * or search for a new one? */ | ||
2582 | rs_stay_in_table(lq_sta, false); | ||
2583 | } | ||
2584 | /* | ||
2585 | * Search for new modulation mode if we're: | ||
2586 | * 1) Not changing rates right now | ||
2587 | * 2) Not just finishing up a search | ||
2588 | * 3) Allowing a new search | ||
2589 | */ | ||
2590 | if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) { | ||
2591 | /* Save current throughput to compare with "search" throughput*/ | ||
2592 | lq_sta->last_tpt = current_tpt; | ||
2593 | |||
2594 | /* Select a new "search" modulation mode to try. | ||
2595 | * If one is found, set up the new "search" table. */ | ||
2596 | if (is_legacy(tbl->lq_type)) | ||
2597 | rs_move_legacy_other(priv, lq_sta, conf, sta, index); | ||
2598 | else if (is_siso(tbl->lq_type)) | ||
2599 | rs_move_siso_to_other(priv, lq_sta, conf, sta, index); | ||
2600 | else if (is_mimo2(tbl->lq_type)) | ||
2601 | rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index); | ||
2602 | else | ||
2603 | rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index); | ||
2604 | |||
2605 | /* If new "search" mode was selected, set up in uCode table */ | ||
2606 | if (lq_sta->search_better_tbl) { | ||
2607 | /* Access the "search" table, clear its history. */ | ||
2608 | tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); | ||
2609 | for (i = 0; i < IWL_RATE_COUNT; i++) | ||
2610 | rs_rate_scale_clear_window(&(tbl->win[i])); | ||
2611 | |||
2612 | /* Use new "search" start rate */ | ||
2613 | index = iwl_hwrate_to_plcp_idx(tbl->current_rate); | ||
2614 | |||
2615 | IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n", | ||
2616 | tbl->current_rate, index); | ||
2617 | rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); | ||
2618 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false); | ||
2619 | } else | ||
2620 | done_search = 1; | ||
2621 | } | ||
2622 | |||
2623 | if (done_search && !lq_sta->stay_in_tbl) { | ||
2624 | /* If the "active" (non-search) mode was legacy, | ||
2625 | * and we've tried switching antennas, | ||
2626 | * but we haven't been able to try HT modes (not available), | ||
2627 | * stay with best antenna legacy modulation for a while | ||
2628 | * before next round of mode comparisons. */ | ||
2629 | tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
2630 | if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) && | ||
2631 | lq_sta->action_counter > tbl1->max_search) { | ||
2632 | IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n"); | ||
2633 | rs_set_stay_in_table(priv, 1, lq_sta); | ||
2634 | } | ||
2635 | |||
2636 | /* If we're in an HT mode, and all 3 mode switch actions | ||
2637 | * have been tried and compared, stay in this best modulation | ||
2638 | * mode for a while before next round of mode comparisons. */ | ||
2639 | if (lq_sta->enable_counter && | ||
2640 | (lq_sta->action_counter >= tbl1->max_search) && | ||
2641 | iwl_ht_enabled(priv)) { | ||
2642 | if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && | ||
2643 | (lq_sta->tx_agg_tid_en & (1 << tid)) && | ||
2644 | (tid != IWL_MAX_TID_COUNT)) { | ||
2645 | u8 sta_id = lq_sta->lq.sta_id; | ||
2646 | tid_data = &priv->tid_data[sta_id][tid]; | ||
2647 | if (tid_data->agg.state == IWL_AGG_OFF) { | ||
2648 | IWL_DEBUG_RATE(priv, | ||
2649 | "try to aggregate tid %d\n", | ||
2650 | tid); | ||
2651 | rs_tl_turn_on_agg(priv, tid, | ||
2652 | lq_sta, sta); | ||
2653 | } | ||
2654 | } | ||
2655 | rs_set_stay_in_table(priv, 0, lq_sta); | ||
2656 | } | ||
2657 | } | ||
2658 | |||
2659 | out: | ||
2660 | tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); | ||
2661 | lq_sta->last_txrate_idx = index; | ||
2662 | } | ||
2663 | |||
2664 | /** | ||
2665 | * rs_initialize_lq - Initialize a station's hardware rate table | ||
2666 | * | ||
2667 | * The uCode's station table contains a table of fallback rates | ||
2668 | * for automatic fallback during transmission. | ||
2669 | * | ||
2670 | * NOTE: This sets up a default set of values. These will be replaced later | ||
2671 | * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of | ||
2672 | * rc80211_simple. | ||
2673 | * | ||
2674 | * NOTE: Run REPLY_ADD_STA command to set up station table entry, before | ||
2675 | * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, | ||
2676 | * which requires station table entry to exist). | ||
2677 | */ | ||
2678 | static void rs_initialize_lq(struct iwl_priv *priv, | ||
2679 | struct ieee80211_sta *sta, | ||
2680 | struct iwl_lq_sta *lq_sta) | ||
2681 | { | ||
2682 | struct iwl_scale_tbl_info *tbl; | ||
2683 | int rate_idx; | ||
2684 | int i; | ||
2685 | u32 rate; | ||
2686 | u8 use_green = rs_use_green(sta); | ||
2687 | u8 active_tbl = 0; | ||
2688 | u8 valid_tx_ant; | ||
2689 | struct iwl_station_priv *sta_priv; | ||
2690 | struct iwl_rxon_context *ctx; | ||
2691 | |||
2692 | if (!sta || !lq_sta) | ||
2693 | return; | ||
2694 | |||
2695 | sta_priv = (void *)sta->drv_priv; | ||
2696 | ctx = sta_priv->ctx; | ||
2697 | |||
2698 | i = lq_sta->last_txrate_idx; | ||
2699 | |||
2700 | valid_tx_ant = priv->eeprom_data->valid_tx_ant; | ||
2701 | |||
2702 | if (!lq_sta->search_better_tbl) | ||
2703 | active_tbl = lq_sta->active_tbl; | ||
2704 | else | ||
2705 | active_tbl = 1 - lq_sta->active_tbl; | ||
2706 | |||
2707 | tbl = &(lq_sta->lq_info[active_tbl]); | ||
2708 | |||
2709 | if ((i < 0) || (i >= IWL_RATE_COUNT)) | ||
2710 | i = 0; | ||
2711 | |||
2712 | rate = iwl_rates[i].plcp; | ||
2713 | tbl->ant_type = first_antenna(valid_tx_ant); | ||
2714 | rate |= tbl->ant_type << RATE_MCS_ANT_POS; | ||
2715 | |||
2716 | if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE) | ||
2717 | rate |= RATE_MCS_CCK_MSK; | ||
2718 | |||
2719 | rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx); | ||
2720 | if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type)) | ||
2721 | rs_toggle_antenna(valid_tx_ant, &rate, tbl); | ||
2722 | |||
2723 | rate = rate_n_flags_from_tbl(priv, tbl, rate_idx, use_green); | ||
2724 | tbl->current_rate = rate; | ||
2725 | rs_set_expected_tpt_table(lq_sta, tbl); | ||
2726 | rs_fill_link_cmd(NULL, lq_sta, rate); | ||
2727 | priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq; | ||
2728 | iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_SYNC, true); | ||
2729 | } | ||
2730 | |||
2731 | static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta, | ||
2732 | struct ieee80211_tx_rate_control *txrc) | ||
2733 | { | ||
2734 | |||
2735 | struct sk_buff *skb = txrc->skb; | ||
2736 | struct ieee80211_supported_band *sband = txrc->sband; | ||
2737 | struct iwl_op_mode *op_mode __maybe_unused = | ||
2738 | (struct iwl_op_mode *)priv_r; | ||
2739 | struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode); | ||
2740 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | ||
2741 | struct iwl_lq_sta *lq_sta = priv_sta; | ||
2742 | int rate_idx; | ||
2743 | |||
2744 | IWL_DEBUG_RATE_LIMIT(priv, "rate scale calculate new rate for skb\n"); | ||
2745 | |||
2746 | /* Get max rate if user set max rate */ | ||
2747 | if (lq_sta) { | ||
2748 | lq_sta->max_rate_idx = txrc->max_rate_idx; | ||
2749 | if ((sband->band == IEEE80211_BAND_5GHZ) && | ||
2750 | (lq_sta->max_rate_idx != -1)) | ||
2751 | lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE; | ||
2752 | if ((lq_sta->max_rate_idx < 0) || | ||
2753 | (lq_sta->max_rate_idx >= IWL_RATE_COUNT)) | ||
2754 | lq_sta->max_rate_idx = -1; | ||
2755 | } | ||
2756 | |||
2757 | /* Treat uninitialized rate scaling data same as non-existing. */ | ||
2758 | if (lq_sta && !lq_sta->drv) { | ||
2759 | IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n"); | ||
2760 | priv_sta = NULL; | ||
2761 | } | ||
2762 | |||
2763 | /* Send management frames and NO_ACK data using lowest rate. */ | ||
2764 | if (rate_control_send_low(sta, priv_sta, txrc)) | ||
2765 | return; | ||
2766 | |||
2767 | rate_idx = lq_sta->last_txrate_idx; | ||
2768 | |||
2769 | if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) { | ||
2770 | rate_idx -= IWL_FIRST_OFDM_RATE; | ||
2771 | /* 6M and 9M shared same MCS index */ | ||
2772 | rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0; | ||
2773 | if (rs_extract_rate(lq_sta->last_rate_n_flags) >= | ||
2774 | IWL_RATE_MIMO3_6M_PLCP) | ||
2775 | rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM); | ||
2776 | else if (rs_extract_rate(lq_sta->last_rate_n_flags) >= | ||
2777 | IWL_RATE_MIMO2_6M_PLCP) | ||
2778 | rate_idx = rate_idx + MCS_INDEX_PER_STREAM; | ||
2779 | info->control.rates[0].flags = IEEE80211_TX_RC_MCS; | ||
2780 | if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK) | ||
2781 | info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI; | ||
2782 | if (lq_sta->last_rate_n_flags & RATE_MCS_DUP_MSK) | ||
2783 | info->control.rates[0].flags |= IEEE80211_TX_RC_DUP_DATA; | ||
2784 | if (lq_sta->last_rate_n_flags & RATE_MCS_HT40_MSK) | ||
2785 | info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; | ||
2786 | if (lq_sta->last_rate_n_flags & RATE_MCS_GF_MSK) | ||
2787 | info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD; | ||
2788 | } else { | ||
2789 | /* Check for invalid rates */ | ||
2790 | if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) || | ||
2791 | ((sband->band == IEEE80211_BAND_5GHZ) && | ||
2792 | (rate_idx < IWL_FIRST_OFDM_RATE))) | ||
2793 | rate_idx = rate_lowest_index(sband, sta); | ||
2794 | /* On valid 5 GHz rate, adjust index */ | ||
2795 | else if (sband->band == IEEE80211_BAND_5GHZ) | ||
2796 | rate_idx -= IWL_FIRST_OFDM_RATE; | ||
2797 | info->control.rates[0].flags = 0; | ||
2798 | } | ||
2799 | info->control.rates[0].idx = rate_idx; | ||
2800 | |||
2801 | } | ||
2802 | |||
2803 | static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta, | ||
2804 | gfp_t gfp) | ||
2805 | { | ||
2806 | struct iwl_station_priv *sta_priv = (struct iwl_station_priv *) sta->drv_priv; | ||
2807 | struct iwl_op_mode *op_mode __maybe_unused = | ||
2808 | (struct iwl_op_mode *)priv_rate; | ||
2809 | struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode); | ||
2810 | |||
2811 | IWL_DEBUG_RATE(priv, "create station rate scale window\n"); | ||
2812 | |||
2813 | return &sta_priv->lq_sta; | ||
2814 | } | ||
2815 | |||
2816 | /* | ||
2817 | * Called after adding a new station to initialize rate scaling | ||
2818 | */ | ||
2819 | void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_id) | ||
2820 | { | ||
2821 | int i, j; | ||
2822 | struct ieee80211_hw *hw = priv->hw; | ||
2823 | struct ieee80211_conf *conf = &priv->hw->conf; | ||
2824 | struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | ||
2825 | struct iwl_station_priv *sta_priv; | ||
2826 | struct iwl_lq_sta *lq_sta; | ||
2827 | struct ieee80211_supported_band *sband; | ||
2828 | unsigned long supp; /* must be unsigned long for for_each_set_bit */ | ||
2829 | |||
2830 | sta_priv = (struct iwl_station_priv *) sta->drv_priv; | ||
2831 | lq_sta = &sta_priv->lq_sta; | ||
2832 | sband = hw->wiphy->bands[conf->channel->band]; | ||
2833 | |||
2834 | |||
2835 | lq_sta->lq.sta_id = sta_id; | ||
2836 | |||
2837 | for (j = 0; j < LQ_SIZE; j++) | ||
2838 | for (i = 0; i < IWL_RATE_COUNT; i++) | ||
2839 | rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); | ||
2840 | |||
2841 | lq_sta->flush_timer = 0; | ||
2842 | lq_sta->supp_rates = sta->supp_rates[sband->band]; | ||
2843 | for (j = 0; j < LQ_SIZE; j++) | ||
2844 | for (i = 0; i < IWL_RATE_COUNT; i++) | ||
2845 | rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); | ||
2846 | |||
2847 | IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init for station %d ***\n", | ||
2848 | sta_id); | ||
2849 | /* TODO: what is a good starting rate for STA? About middle? Maybe not | ||
2850 | * the lowest or the highest rate.. Could consider using RSSI from | ||
2851 | * previous packets? Need to have IEEE 802.1X auth succeed immediately | ||
2852 | * after assoc.. */ | ||
2853 | |||
2854 | lq_sta->is_dup = 0; | ||
2855 | lq_sta->max_rate_idx = -1; | ||
2856 | lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX; | ||
2857 | lq_sta->is_green = rs_use_green(sta); | ||
2858 | lq_sta->band = sband->band; | ||
2859 | /* | ||
2860 | * active legacy rates as per supported rates bitmap | ||
2861 | */ | ||
2862 | supp = sta->supp_rates[sband->band]; | ||
2863 | lq_sta->active_legacy_rate = 0; | ||
2864 | for_each_set_bit(i, &supp, BITS_PER_LONG) | ||
2865 | lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value); | ||
2866 | |||
2867 | /* | ||
2868 | * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3), | ||
2869 | * supp_rates[] does not; shift to convert format, force 9 MBits off. | ||
2870 | */ | ||
2871 | lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1; | ||
2872 | lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1; | ||
2873 | lq_sta->active_siso_rate &= ~((u16)0x2); | ||
2874 | lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE; | ||
2875 | |||
2876 | /* Same here */ | ||
2877 | lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1; | ||
2878 | lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1; | ||
2879 | lq_sta->active_mimo2_rate &= ~((u16)0x2); | ||
2880 | lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE; | ||
2881 | |||
2882 | lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1; | ||
2883 | lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1; | ||
2884 | lq_sta->active_mimo3_rate &= ~((u16)0x2); | ||
2885 | lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE; | ||
2886 | |||
2887 | IWL_DEBUG_RATE(priv, "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n", | ||
2888 | lq_sta->active_siso_rate, | ||
2889 | lq_sta->active_mimo2_rate, | ||
2890 | lq_sta->active_mimo3_rate); | ||
2891 | |||
2892 | /* These values will be overridden later */ | ||
2893 | lq_sta->lq.general_params.single_stream_ant_msk = | ||
2894 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
2895 | lq_sta->lq.general_params.dual_stream_ant_msk = | ||
2896 | priv->eeprom_data->valid_tx_ant & | ||
2897 | ~first_antenna(priv->eeprom_data->valid_tx_ant); | ||
2898 | if (!lq_sta->lq.general_params.dual_stream_ant_msk) { | ||
2899 | lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB; | ||
2900 | } else if (num_of_ant(priv->eeprom_data->valid_tx_ant) == 2) { | ||
2901 | lq_sta->lq.general_params.dual_stream_ant_msk = | ||
2902 | priv->eeprom_data->valid_tx_ant; | ||
2903 | } | ||
2904 | |||
2905 | /* as default allow aggregation for all tids */ | ||
2906 | lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID; | ||
2907 | lq_sta->drv = priv; | ||
2908 | |||
2909 | /* Set last_txrate_idx to lowest rate */ | ||
2910 | lq_sta->last_txrate_idx = rate_lowest_index(sband, sta); | ||
2911 | if (sband->band == IEEE80211_BAND_5GHZ) | ||
2912 | lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE; | ||
2913 | lq_sta->is_agg = 0; | ||
2914 | #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE | ||
2915 | priv->tm_fixed_rate = 0; | ||
2916 | #endif | ||
2917 | #ifdef CONFIG_MAC80211_DEBUGFS | ||
2918 | lq_sta->dbg_fixed_rate = 0; | ||
2919 | #endif | ||
2920 | |||
2921 | rs_initialize_lq(priv, sta, lq_sta); | ||
2922 | } | ||
2923 | |||
2924 | static void rs_fill_link_cmd(struct iwl_priv *priv, | ||
2925 | struct iwl_lq_sta *lq_sta, u32 new_rate) | ||
2926 | { | ||
2927 | struct iwl_scale_tbl_info tbl_type; | ||
2928 | int index = 0; | ||
2929 | int rate_idx; | ||
2930 | int repeat_rate = 0; | ||
2931 | u8 ant_toggle_cnt = 0; | ||
2932 | u8 use_ht_possible = 1; | ||
2933 | u8 valid_tx_ant = 0; | ||
2934 | struct iwl_station_priv *sta_priv = | ||
2935 | container_of(lq_sta, struct iwl_station_priv, lq_sta); | ||
2936 | struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq; | ||
2937 | |||
2938 | /* Override starting rate (index 0) if needed for debug purposes */ | ||
2939 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); | ||
2940 | |||
2941 | /* Interpret new_rate (rate_n_flags) */ | ||
2942 | rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, | ||
2943 | &tbl_type, &rate_idx); | ||
2944 | |||
2945 | if (priv && priv->bt_full_concurrent) { | ||
2946 | /* 1x1 only */ | ||
2947 | tbl_type.ant_type = | ||
2948 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
2949 | } | ||
2950 | |||
2951 | /* How many times should we repeat the initial rate? */ | ||
2952 | if (is_legacy(tbl_type.lq_type)) { | ||
2953 | ant_toggle_cnt = 1; | ||
2954 | repeat_rate = IWL_NUMBER_TRY; | ||
2955 | } else { | ||
2956 | repeat_rate = min(IWL_HT_NUMBER_TRY, | ||
2957 | LINK_QUAL_AGG_DISABLE_START_DEF - 1); | ||
2958 | } | ||
2959 | |||
2960 | lq_cmd->general_params.mimo_delimiter = | ||
2961 | is_mimo(tbl_type.lq_type) ? 1 : 0; | ||
2962 | |||
2963 | /* Fill 1st table entry (index 0) */ | ||
2964 | lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate); | ||
2965 | |||
2966 | if (num_of_ant(tbl_type.ant_type) == 1) { | ||
2967 | lq_cmd->general_params.single_stream_ant_msk = | ||
2968 | tbl_type.ant_type; | ||
2969 | } else if (num_of_ant(tbl_type.ant_type) == 2) { | ||
2970 | lq_cmd->general_params.dual_stream_ant_msk = | ||
2971 | tbl_type.ant_type; | ||
2972 | } /* otherwise we don't modify the existing value */ | ||
2973 | |||
2974 | index++; | ||
2975 | repeat_rate--; | ||
2976 | if (priv) { | ||
2977 | if (priv->bt_full_concurrent) | ||
2978 | valid_tx_ant = ANT_A; | ||
2979 | else | ||
2980 | valid_tx_ant = priv->eeprom_data->valid_tx_ant; | ||
2981 | } | ||
2982 | |||
2983 | /* Fill rest of rate table */ | ||
2984 | while (index < LINK_QUAL_MAX_RETRY_NUM) { | ||
2985 | /* Repeat initial/next rate. | ||
2986 | * For legacy IWL_NUMBER_TRY == 1, this loop will not execute. | ||
2987 | * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */ | ||
2988 | while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) { | ||
2989 | if (is_legacy(tbl_type.lq_type)) { | ||
2990 | if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE) | ||
2991 | ant_toggle_cnt++; | ||
2992 | else if (priv && | ||
2993 | rs_toggle_antenna(valid_tx_ant, | ||
2994 | &new_rate, &tbl_type)) | ||
2995 | ant_toggle_cnt = 1; | ||
2996 | } | ||
2997 | |||
2998 | /* Override next rate if needed for debug purposes */ | ||
2999 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); | ||
3000 | |||
3001 | /* Fill next table entry */ | ||
3002 | lq_cmd->rs_table[index].rate_n_flags = | ||
3003 | cpu_to_le32(new_rate); | ||
3004 | repeat_rate--; | ||
3005 | index++; | ||
3006 | } | ||
3007 | |||
3008 | rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type, | ||
3009 | &rate_idx); | ||
3010 | |||
3011 | if (priv && priv->bt_full_concurrent) { | ||
3012 | /* 1x1 only */ | ||
3013 | tbl_type.ant_type = | ||
3014 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
3015 | } | ||
3016 | |||
3017 | /* Indicate to uCode which entries might be MIMO. | ||
3018 | * If initial rate was MIMO, this will finally end up | ||
3019 | * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */ | ||
3020 | if (is_mimo(tbl_type.lq_type)) | ||
3021 | lq_cmd->general_params.mimo_delimiter = index; | ||
3022 | |||
3023 | /* Get next rate */ | ||
3024 | new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx, | ||
3025 | use_ht_possible); | ||
3026 | |||
3027 | /* How many times should we repeat the next rate? */ | ||
3028 | if (is_legacy(tbl_type.lq_type)) { | ||
3029 | if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE) | ||
3030 | ant_toggle_cnt++; | ||
3031 | else if (priv && | ||
3032 | rs_toggle_antenna(valid_tx_ant, | ||
3033 | &new_rate, &tbl_type)) | ||
3034 | ant_toggle_cnt = 1; | ||
3035 | |||
3036 | repeat_rate = IWL_NUMBER_TRY; | ||
3037 | } else { | ||
3038 | repeat_rate = IWL_HT_NUMBER_TRY; | ||
3039 | } | ||
3040 | |||
3041 | /* Don't allow HT rates after next pass. | ||
3042 | * rs_get_lower_rate() will change type to LQ_A or LQ_G. */ | ||
3043 | use_ht_possible = 0; | ||
3044 | |||
3045 | /* Override next rate if needed for debug purposes */ | ||
3046 | rs_dbgfs_set_mcs(lq_sta, &new_rate, index); | ||
3047 | |||
3048 | /* Fill next table entry */ | ||
3049 | lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate); | ||
3050 | |||
3051 | index++; | ||
3052 | repeat_rate--; | ||
3053 | } | ||
3054 | |||
3055 | lq_cmd->agg_params.agg_frame_cnt_limit = | ||
3056 | sta_priv->max_agg_bufsize ?: LINK_QUAL_AGG_FRAME_LIMIT_DEF; | ||
3057 | lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; | ||
3058 | |||
3059 | lq_cmd->agg_params.agg_time_limit = | ||
3060 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); | ||
3061 | /* | ||
3062 | * overwrite if needed, pass aggregation time limit | ||
3063 | * to uCode in uSec | ||
3064 | */ | ||
3065 | if (priv && priv->cfg->bt_params && | ||
3066 | priv->cfg->bt_params->agg_time_limit && | ||
3067 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) | ||
3068 | lq_cmd->agg_params.agg_time_limit = | ||
3069 | cpu_to_le16(priv->cfg->bt_params->agg_time_limit); | ||
3070 | } | ||
3071 | |||
3072 | static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) | ||
3073 | { | ||
3074 | return hw->priv; | ||
3075 | } | ||
3076 | /* rate scale requires free function to be implemented */ | ||
3077 | static void rs_free(void *priv_rate) | ||
3078 | { | ||
3079 | return; | ||
3080 | } | ||
3081 | |||
3082 | static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta, | ||
3083 | void *priv_sta) | ||
3084 | { | ||
3085 | struct iwl_op_mode *op_mode __maybe_unused = priv_r; | ||
3086 | struct iwl_priv *priv __maybe_unused = IWL_OP_MODE_GET_DVM(op_mode); | ||
3087 | |||
3088 | IWL_DEBUG_RATE(priv, "enter\n"); | ||
3089 | IWL_DEBUG_RATE(priv, "leave\n"); | ||
3090 | } | ||
3091 | |||
3092 | #ifdef CONFIG_MAC80211_DEBUGFS | ||
3093 | static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta, | ||
3094 | u32 *rate_n_flags, int index) | ||
3095 | { | ||
3096 | struct iwl_priv *priv; | ||
3097 | u8 valid_tx_ant; | ||
3098 | u8 ant_sel_tx; | ||
3099 | |||
3100 | priv = lq_sta->drv; | ||
3101 | valid_tx_ant = priv->eeprom_data->valid_tx_ant; | ||
3102 | if (lq_sta->dbg_fixed_rate) { | ||
3103 | ant_sel_tx = | ||
3104 | ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK) | ||
3105 | >> RATE_MCS_ANT_POS); | ||
3106 | if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) { | ||
3107 | *rate_n_flags = lq_sta->dbg_fixed_rate; | ||
3108 | IWL_DEBUG_RATE(priv, "Fixed rate ON\n"); | ||
3109 | } else { | ||
3110 | lq_sta->dbg_fixed_rate = 0; | ||
3111 | IWL_ERR(priv, | ||
3112 | "Invalid antenna selection 0x%X, Valid is 0x%X\n", | ||
3113 | ant_sel_tx, valid_tx_ant); | ||
3114 | IWL_DEBUG_RATE(priv, "Fixed rate OFF\n"); | ||
3115 | } | ||
3116 | } else { | ||
3117 | IWL_DEBUG_RATE(priv, "Fixed rate OFF\n"); | ||
3118 | } | ||
3119 | } | ||
3120 | |||
3121 | static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, | ||
3122 | const char __user *user_buf, size_t count, loff_t *ppos) | ||
3123 | { | ||
3124 | struct iwl_lq_sta *lq_sta = file->private_data; | ||
3125 | struct iwl_priv *priv; | ||
3126 | char buf[64]; | ||
3127 | size_t buf_size; | ||
3128 | u32 parsed_rate; | ||
3129 | |||
3130 | |||
3131 | priv = lq_sta->drv; | ||
3132 | memset(buf, 0, sizeof(buf)); | ||
3133 | buf_size = min(count, sizeof(buf) - 1); | ||
3134 | if (copy_from_user(buf, user_buf, buf_size)) | ||
3135 | return -EFAULT; | ||
3136 | |||
3137 | if (sscanf(buf, "%x", &parsed_rate) == 1) | ||
3138 | lq_sta->dbg_fixed_rate = parsed_rate; | ||
3139 | else | ||
3140 | lq_sta->dbg_fixed_rate = 0; | ||
3141 | |||
3142 | rs_program_fix_rate(priv, lq_sta); | ||
3143 | |||
3144 | return count; | ||
3145 | } | ||
3146 | |||
3147 | static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file, | ||
3148 | char __user *user_buf, size_t count, loff_t *ppos) | ||
3149 | { | ||
3150 | char *buff; | ||
3151 | int desc = 0; | ||
3152 | int i = 0; | ||
3153 | int index = 0; | ||
3154 | ssize_t ret; | ||
3155 | |||
3156 | struct iwl_lq_sta *lq_sta = file->private_data; | ||
3157 | struct iwl_priv *priv; | ||
3158 | struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); | ||
3159 | |||
3160 | priv = lq_sta->drv; | ||
3161 | buff = kmalloc(1024, GFP_KERNEL); | ||
3162 | if (!buff) | ||
3163 | return -ENOMEM; | ||
3164 | |||
3165 | desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id); | ||
3166 | desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n", | ||
3167 | lq_sta->total_failed, lq_sta->total_success, | ||
3168 | lq_sta->active_legacy_rate); | ||
3169 | desc += sprintf(buff+desc, "fixed rate 0x%X\n", | ||
3170 | lq_sta->dbg_fixed_rate); | ||
3171 | desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n", | ||
3172 | (priv->eeprom_data->valid_tx_ant & ANT_A) ? "ANT_A," : "", | ||
3173 | (priv->eeprom_data->valid_tx_ant & ANT_B) ? "ANT_B," : "", | ||
3174 | (priv->eeprom_data->valid_tx_ant & ANT_C) ? "ANT_C" : ""); | ||
3175 | desc += sprintf(buff+desc, "lq type %s\n", | ||
3176 | (is_legacy(tbl->lq_type)) ? "legacy" : "HT"); | ||
3177 | if (is_Ht(tbl->lq_type)) { | ||
3178 | desc += sprintf(buff+desc, " %s", | ||
3179 | (is_siso(tbl->lq_type)) ? "SISO" : | ||
3180 | ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3")); | ||
3181 | desc += sprintf(buff+desc, " %s", | ||
3182 | (tbl->is_ht40) ? "40MHz" : "20MHz"); | ||
3183 | desc += sprintf(buff+desc, " %s %s %s\n", (tbl->is_SGI) ? "SGI" : "", | ||
3184 | (lq_sta->is_green) ? "GF enabled" : "", | ||
3185 | (lq_sta->is_agg) ? "AGG on" : ""); | ||
3186 | } | ||
3187 | desc += sprintf(buff+desc, "last tx rate=0x%X\n", | ||
3188 | lq_sta->last_rate_n_flags); | ||
3189 | desc += sprintf(buff+desc, "general:" | ||
3190 | "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", | ||
3191 | lq_sta->lq.general_params.flags, | ||
3192 | lq_sta->lq.general_params.mimo_delimiter, | ||
3193 | lq_sta->lq.general_params.single_stream_ant_msk, | ||
3194 | lq_sta->lq.general_params.dual_stream_ant_msk); | ||
3195 | |||
3196 | desc += sprintf(buff+desc, "agg:" | ||
3197 | "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n", | ||
3198 | le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit), | ||
3199 | lq_sta->lq.agg_params.agg_dis_start_th, | ||
3200 | lq_sta->lq.agg_params.agg_frame_cnt_limit); | ||
3201 | |||
3202 | desc += sprintf(buff+desc, | ||
3203 | "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n", | ||
3204 | lq_sta->lq.general_params.start_rate_index[0], | ||
3205 | lq_sta->lq.general_params.start_rate_index[1], | ||
3206 | lq_sta->lq.general_params.start_rate_index[2], | ||
3207 | lq_sta->lq.general_params.start_rate_index[3]); | ||
3208 | |||
3209 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { | ||
3210 | index = iwl_hwrate_to_plcp_idx( | ||
3211 | le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags)); | ||
3212 | if (is_legacy(tbl->lq_type)) { | ||
3213 | desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n", | ||
3214 | i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), | ||
3215 | iwl_rate_mcs[index].mbps); | ||
3216 | } else { | ||
3217 | desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n", | ||
3218 | i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags), | ||
3219 | iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs); | ||
3220 | } | ||
3221 | } | ||
3222 | |||
3223 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); | ||
3224 | kfree(buff); | ||
3225 | return ret; | ||
3226 | } | ||
3227 | |||
3228 | static const struct file_operations rs_sta_dbgfs_scale_table_ops = { | ||
3229 | .write = rs_sta_dbgfs_scale_table_write, | ||
3230 | .read = rs_sta_dbgfs_scale_table_read, | ||
3231 | .open = simple_open, | ||
3232 | .llseek = default_llseek, | ||
3233 | }; | ||
3234 | static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file, | ||
3235 | char __user *user_buf, size_t count, loff_t *ppos) | ||
3236 | { | ||
3237 | char *buff; | ||
3238 | int desc = 0; | ||
3239 | int i, j; | ||
3240 | ssize_t ret; | ||
3241 | |||
3242 | struct iwl_lq_sta *lq_sta = file->private_data; | ||
3243 | |||
3244 | buff = kmalloc(1024, GFP_KERNEL); | ||
3245 | if (!buff) | ||
3246 | return -ENOMEM; | ||
3247 | |||
3248 | for (i = 0; i < LQ_SIZE; i++) { | ||
3249 | desc += sprintf(buff+desc, | ||
3250 | "%s type=%d SGI=%d HT40=%d DUP=%d GF=%d\n" | ||
3251 | "rate=0x%X\n", | ||
3252 | lq_sta->active_tbl == i ? "*" : "x", | ||
3253 | lq_sta->lq_info[i].lq_type, | ||
3254 | lq_sta->lq_info[i].is_SGI, | ||
3255 | lq_sta->lq_info[i].is_ht40, | ||
3256 | lq_sta->lq_info[i].is_dup, | ||
3257 | lq_sta->is_green, | ||
3258 | lq_sta->lq_info[i].current_rate); | ||
3259 | for (j = 0; j < IWL_RATE_COUNT; j++) { | ||
3260 | desc += sprintf(buff+desc, | ||
3261 | "counter=%d success=%d %%=%d\n", | ||
3262 | lq_sta->lq_info[i].win[j].counter, | ||
3263 | lq_sta->lq_info[i].win[j].success_counter, | ||
3264 | lq_sta->lq_info[i].win[j].success_ratio); | ||
3265 | } | ||
3266 | } | ||
3267 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); | ||
3268 | kfree(buff); | ||
3269 | return ret; | ||
3270 | } | ||
3271 | |||
3272 | static const struct file_operations rs_sta_dbgfs_stats_table_ops = { | ||
3273 | .read = rs_sta_dbgfs_stats_table_read, | ||
3274 | .open = simple_open, | ||
3275 | .llseek = default_llseek, | ||
3276 | }; | ||
3277 | |||
3278 | static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file, | ||
3279 | char __user *user_buf, size_t count, loff_t *ppos) | ||
3280 | { | ||
3281 | struct iwl_lq_sta *lq_sta = file->private_data; | ||
3282 | struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl]; | ||
3283 | char buff[120]; | ||
3284 | int desc = 0; | ||
3285 | |||
3286 | if (is_Ht(tbl->lq_type)) | ||
3287 | desc += sprintf(buff+desc, | ||
3288 | "Bit Rate= %d Mb/s\n", | ||
3289 | tbl->expected_tpt[lq_sta->last_txrate_idx]); | ||
3290 | else | ||
3291 | desc += sprintf(buff+desc, | ||
3292 | "Bit Rate= %d Mb/s\n", | ||
3293 | iwl_rates[lq_sta->last_txrate_idx].ieee >> 1); | ||
3294 | |||
3295 | return simple_read_from_buffer(user_buf, count, ppos, buff, desc); | ||
3296 | } | ||
3297 | |||
3298 | static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = { | ||
3299 | .read = rs_sta_dbgfs_rate_scale_data_read, | ||
3300 | .open = simple_open, | ||
3301 | .llseek = default_llseek, | ||
3302 | }; | ||
3303 | |||
3304 | static void rs_add_debugfs(void *priv, void *priv_sta, | ||
3305 | struct dentry *dir) | ||
3306 | { | ||
3307 | struct iwl_lq_sta *lq_sta = priv_sta; | ||
3308 | lq_sta->rs_sta_dbgfs_scale_table_file = | ||
3309 | debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir, | ||
3310 | lq_sta, &rs_sta_dbgfs_scale_table_ops); | ||
3311 | lq_sta->rs_sta_dbgfs_stats_table_file = | ||
3312 | debugfs_create_file("rate_stats_table", S_IRUSR, dir, | ||
3313 | lq_sta, &rs_sta_dbgfs_stats_table_ops); | ||
3314 | lq_sta->rs_sta_dbgfs_rate_scale_data_file = | ||
3315 | debugfs_create_file("rate_scale_data", S_IRUSR, dir, | ||
3316 | lq_sta, &rs_sta_dbgfs_rate_scale_data_ops); | ||
3317 | lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file = | ||
3318 | debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir, | ||
3319 | &lq_sta->tx_agg_tid_en); | ||
3320 | |||
3321 | } | ||
3322 | |||
3323 | static void rs_remove_debugfs(void *priv, void *priv_sta) | ||
3324 | { | ||
3325 | struct iwl_lq_sta *lq_sta = priv_sta; | ||
3326 | debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); | ||
3327 | debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); | ||
3328 | debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file); | ||
3329 | debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file); | ||
3330 | } | ||
3331 | #endif | ||
3332 | |||
3333 | /* | ||
3334 | * Initialization of rate scaling information is done by driver after | ||
3335 | * the station is added. Since mac80211 calls this function before a | ||
3336 | * station is added we ignore it. | ||
3337 | */ | ||
3338 | static void rs_rate_init_stub(void *priv_r, struct ieee80211_supported_band *sband, | ||
3339 | struct ieee80211_sta *sta, void *priv_sta) | ||
3340 | { | ||
3341 | } | ||
3342 | static struct rate_control_ops rs_ops = { | ||
3343 | .module = NULL, | ||
3344 | .name = RS_NAME, | ||
3345 | .tx_status = rs_tx_status, | ||
3346 | .get_rate = rs_get_rate, | ||
3347 | .rate_init = rs_rate_init_stub, | ||
3348 | .alloc = rs_alloc, | ||
3349 | .free = rs_free, | ||
3350 | .alloc_sta = rs_alloc_sta, | ||
3351 | .free_sta = rs_free_sta, | ||
3352 | #ifdef CONFIG_MAC80211_DEBUGFS | ||
3353 | .add_sta_debugfs = rs_add_debugfs, | ||
3354 | .remove_sta_debugfs = rs_remove_debugfs, | ||
3355 | #endif | ||
3356 | }; | ||
3357 | |||
3358 | int iwlagn_rate_control_register(void) | ||
3359 | { | ||
3360 | return ieee80211_rate_control_register(&rs_ops); | ||
3361 | } | ||
3362 | |||
3363 | void iwlagn_rate_control_unregister(void) | ||
3364 | { | ||
3365 | ieee80211_rate_control_unregister(&rs_ops); | ||
3366 | } | ||
3367 | |||
diff --git a/drivers/net/wireless/iwlwifi/dvm/rs.h b/drivers/net/wireless/iwlwifi/dvm/rs.h new file mode 100644 index 000000000000..ad3aea8f626a --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/rs.h | |||
@@ -0,0 +1,433 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of version 2 of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | |||
27 | #ifndef __iwl_agn_rs_h__ | ||
28 | #define __iwl_agn_rs_h__ | ||
29 | |||
30 | #include <net/mac80211.h> | ||
31 | |||
32 | #include "iwl-config.h" | ||
33 | |||
34 | #include "commands.h" | ||
35 | |||
36 | struct iwl_rate_info { | ||
37 | u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ | ||
38 | u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ | ||
39 | u8 plcp_mimo2; /* uCode API: IWL_RATE_MIMO2_6M_PLCP, etc. */ | ||
40 | u8 plcp_mimo3; /* uCode API: IWL_RATE_MIMO3_6M_PLCP, etc. */ | ||
41 | u8 ieee; /* MAC header: IWL_RATE_6M_IEEE, etc. */ | ||
42 | u8 prev_ieee; /* previous rate in IEEE speeds */ | ||
43 | u8 next_ieee; /* next rate in IEEE speeds */ | ||
44 | u8 prev_rs; /* previous rate used in rs algo */ | ||
45 | u8 next_rs; /* next rate used in rs algo */ | ||
46 | u8 prev_rs_tgg; /* previous rate used in TGG rs algo */ | ||
47 | u8 next_rs_tgg; /* next rate used in TGG rs algo */ | ||
48 | }; | ||
49 | |||
50 | /* | ||
51 | * These serve as indexes into | ||
52 | * struct iwl_rate_info iwl_rates[IWL_RATE_COUNT]; | ||
53 | */ | ||
54 | enum { | ||
55 | IWL_RATE_1M_INDEX = 0, | ||
56 | IWL_RATE_2M_INDEX, | ||
57 | IWL_RATE_5M_INDEX, | ||
58 | IWL_RATE_11M_INDEX, | ||
59 | IWL_RATE_6M_INDEX, | ||
60 | IWL_RATE_9M_INDEX, | ||
61 | IWL_RATE_12M_INDEX, | ||
62 | IWL_RATE_18M_INDEX, | ||
63 | IWL_RATE_24M_INDEX, | ||
64 | IWL_RATE_36M_INDEX, | ||
65 | IWL_RATE_48M_INDEX, | ||
66 | IWL_RATE_54M_INDEX, | ||
67 | IWL_RATE_60M_INDEX, | ||
68 | IWL_RATE_COUNT, /*FIXME:RS:change to IWL_RATE_INDEX_COUNT,*/ | ||
69 | IWL_RATE_COUNT_LEGACY = IWL_RATE_COUNT - 1, /* Excluding 60M */ | ||
70 | IWL_RATE_INVM_INDEX = IWL_RATE_COUNT, | ||
71 | IWL_RATE_INVALID = IWL_RATE_COUNT, | ||
72 | }; | ||
73 | |||
74 | enum { | ||
75 | IWL_RATE_6M_INDEX_TABLE = 0, | ||
76 | IWL_RATE_9M_INDEX_TABLE, | ||
77 | IWL_RATE_12M_INDEX_TABLE, | ||
78 | IWL_RATE_18M_INDEX_TABLE, | ||
79 | IWL_RATE_24M_INDEX_TABLE, | ||
80 | IWL_RATE_36M_INDEX_TABLE, | ||
81 | IWL_RATE_48M_INDEX_TABLE, | ||
82 | IWL_RATE_54M_INDEX_TABLE, | ||
83 | IWL_RATE_1M_INDEX_TABLE, | ||
84 | IWL_RATE_2M_INDEX_TABLE, | ||
85 | IWL_RATE_5M_INDEX_TABLE, | ||
86 | IWL_RATE_11M_INDEX_TABLE, | ||
87 | IWL_RATE_INVM_INDEX_TABLE = IWL_RATE_INVM_INDEX - 1, | ||
88 | }; | ||
89 | |||
90 | enum { | ||
91 | IWL_FIRST_OFDM_RATE = IWL_RATE_6M_INDEX, | ||
92 | IWL_LAST_OFDM_RATE = IWL_RATE_60M_INDEX, | ||
93 | IWL_FIRST_CCK_RATE = IWL_RATE_1M_INDEX, | ||
94 | IWL_LAST_CCK_RATE = IWL_RATE_11M_INDEX, | ||
95 | }; | ||
96 | |||
97 | /* #define vs. enum to keep from defaulting to 'large integer' */ | ||
98 | #define IWL_RATE_6M_MASK (1 << IWL_RATE_6M_INDEX) | ||
99 | #define IWL_RATE_9M_MASK (1 << IWL_RATE_9M_INDEX) | ||
100 | #define IWL_RATE_12M_MASK (1 << IWL_RATE_12M_INDEX) | ||
101 | #define IWL_RATE_18M_MASK (1 << IWL_RATE_18M_INDEX) | ||
102 | #define IWL_RATE_24M_MASK (1 << IWL_RATE_24M_INDEX) | ||
103 | #define IWL_RATE_36M_MASK (1 << IWL_RATE_36M_INDEX) | ||
104 | #define IWL_RATE_48M_MASK (1 << IWL_RATE_48M_INDEX) | ||
105 | #define IWL_RATE_54M_MASK (1 << IWL_RATE_54M_INDEX) | ||
106 | #define IWL_RATE_60M_MASK (1 << IWL_RATE_60M_INDEX) | ||
107 | #define IWL_RATE_1M_MASK (1 << IWL_RATE_1M_INDEX) | ||
108 | #define IWL_RATE_2M_MASK (1 << IWL_RATE_2M_INDEX) | ||
109 | #define IWL_RATE_5M_MASK (1 << IWL_RATE_5M_INDEX) | ||
110 | #define IWL_RATE_11M_MASK (1 << IWL_RATE_11M_INDEX) | ||
111 | |||
112 | /* uCode API values for legacy bit rates, both OFDM and CCK */ | ||
113 | enum { | ||
114 | IWL_RATE_6M_PLCP = 13, | ||
115 | IWL_RATE_9M_PLCP = 15, | ||
116 | IWL_RATE_12M_PLCP = 5, | ||
117 | IWL_RATE_18M_PLCP = 7, | ||
118 | IWL_RATE_24M_PLCP = 9, | ||
119 | IWL_RATE_36M_PLCP = 11, | ||
120 | IWL_RATE_48M_PLCP = 1, | ||
121 | IWL_RATE_54M_PLCP = 3, | ||
122 | IWL_RATE_60M_PLCP = 3,/*FIXME:RS:should be removed*/ | ||
123 | IWL_RATE_1M_PLCP = 10, | ||
124 | IWL_RATE_2M_PLCP = 20, | ||
125 | IWL_RATE_5M_PLCP = 55, | ||
126 | IWL_RATE_11M_PLCP = 110, | ||
127 | /*FIXME:RS:change to IWL_RATE_LEGACY_??M_PLCP */ | ||
128 | /*FIXME:RS:add IWL_RATE_LEGACY_INVM_PLCP = 0,*/ | ||
129 | }; | ||
130 | |||
131 | /* uCode API values for OFDM high-throughput (HT) bit rates */ | ||
132 | enum { | ||
133 | IWL_RATE_SISO_6M_PLCP = 0, | ||
134 | IWL_RATE_SISO_12M_PLCP = 1, | ||
135 | IWL_RATE_SISO_18M_PLCP = 2, | ||
136 | IWL_RATE_SISO_24M_PLCP = 3, | ||
137 | IWL_RATE_SISO_36M_PLCP = 4, | ||
138 | IWL_RATE_SISO_48M_PLCP = 5, | ||
139 | IWL_RATE_SISO_54M_PLCP = 6, | ||
140 | IWL_RATE_SISO_60M_PLCP = 7, | ||
141 | IWL_RATE_MIMO2_6M_PLCP = 0x8, | ||
142 | IWL_RATE_MIMO2_12M_PLCP = 0x9, | ||
143 | IWL_RATE_MIMO2_18M_PLCP = 0xa, | ||
144 | IWL_RATE_MIMO2_24M_PLCP = 0xb, | ||
145 | IWL_RATE_MIMO2_36M_PLCP = 0xc, | ||
146 | IWL_RATE_MIMO2_48M_PLCP = 0xd, | ||
147 | IWL_RATE_MIMO2_54M_PLCP = 0xe, | ||
148 | IWL_RATE_MIMO2_60M_PLCP = 0xf, | ||
149 | IWL_RATE_MIMO3_6M_PLCP = 0x10, | ||
150 | IWL_RATE_MIMO3_12M_PLCP = 0x11, | ||
151 | IWL_RATE_MIMO3_18M_PLCP = 0x12, | ||
152 | IWL_RATE_MIMO3_24M_PLCP = 0x13, | ||
153 | IWL_RATE_MIMO3_36M_PLCP = 0x14, | ||
154 | IWL_RATE_MIMO3_48M_PLCP = 0x15, | ||
155 | IWL_RATE_MIMO3_54M_PLCP = 0x16, | ||
156 | IWL_RATE_MIMO3_60M_PLCP = 0x17, | ||
157 | IWL_RATE_SISO_INVM_PLCP, | ||
158 | IWL_RATE_MIMO2_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP, | ||
159 | IWL_RATE_MIMO3_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP, | ||
160 | }; | ||
161 | |||
162 | /* MAC header values for bit rates */ | ||
163 | enum { | ||
164 | IWL_RATE_6M_IEEE = 12, | ||
165 | IWL_RATE_9M_IEEE = 18, | ||
166 | IWL_RATE_12M_IEEE = 24, | ||
167 | IWL_RATE_18M_IEEE = 36, | ||
168 | IWL_RATE_24M_IEEE = 48, | ||
169 | IWL_RATE_36M_IEEE = 72, | ||
170 | IWL_RATE_48M_IEEE = 96, | ||
171 | IWL_RATE_54M_IEEE = 108, | ||
172 | IWL_RATE_60M_IEEE = 120, | ||
173 | IWL_RATE_1M_IEEE = 2, | ||
174 | IWL_RATE_2M_IEEE = 4, | ||
175 | IWL_RATE_5M_IEEE = 11, | ||
176 | IWL_RATE_11M_IEEE = 22, | ||
177 | }; | ||
178 | |||
179 | #define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1) | ||
180 | |||
181 | #define IWL_INVALID_VALUE -1 | ||
182 | |||
183 | #define IWL_MIN_RSSI_VAL -100 | ||
184 | #define IWL_MAX_RSSI_VAL 0 | ||
185 | |||
186 | /* These values specify how many Tx frame attempts before | ||
187 | * searching for a new modulation mode */ | ||
188 | #define IWL_LEGACY_FAILURE_LIMIT 160 | ||
189 | #define IWL_LEGACY_SUCCESS_LIMIT 480 | ||
190 | #define IWL_LEGACY_TABLE_COUNT 160 | ||
191 | |||
192 | #define IWL_NONE_LEGACY_FAILURE_LIMIT 400 | ||
193 | #define IWL_NONE_LEGACY_SUCCESS_LIMIT 4500 | ||
194 | #define IWL_NONE_LEGACY_TABLE_COUNT 1500 | ||
195 | |||
196 | /* Success ratio (ACKed / attempted tx frames) values (perfect is 128 * 100) */ | ||
197 | #define IWL_RS_GOOD_RATIO 12800 /* 100% */ | ||
198 | #define IWL_RATE_SCALE_SWITCH 10880 /* 85% */ | ||
199 | #define IWL_RATE_HIGH_TH 10880 /* 85% */ | ||
200 | #define IWL_RATE_INCREASE_TH 6400 /* 50% */ | ||
201 | #define IWL_RATE_DECREASE_TH 1920 /* 15% */ | ||
202 | |||
203 | /* possible actions when in legacy mode */ | ||
204 | #define IWL_LEGACY_SWITCH_ANTENNA1 0 | ||
205 | #define IWL_LEGACY_SWITCH_ANTENNA2 1 | ||
206 | #define IWL_LEGACY_SWITCH_SISO 2 | ||
207 | #define IWL_LEGACY_SWITCH_MIMO2_AB 3 | ||
208 | #define IWL_LEGACY_SWITCH_MIMO2_AC 4 | ||
209 | #define IWL_LEGACY_SWITCH_MIMO2_BC 5 | ||
210 | #define IWL_LEGACY_SWITCH_MIMO3_ABC 6 | ||
211 | |||
212 | /* possible actions when in siso mode */ | ||
213 | #define IWL_SISO_SWITCH_ANTENNA1 0 | ||
214 | #define IWL_SISO_SWITCH_ANTENNA2 1 | ||
215 | #define IWL_SISO_SWITCH_MIMO2_AB 2 | ||
216 | #define IWL_SISO_SWITCH_MIMO2_AC 3 | ||
217 | #define IWL_SISO_SWITCH_MIMO2_BC 4 | ||
218 | #define IWL_SISO_SWITCH_GI 5 | ||
219 | #define IWL_SISO_SWITCH_MIMO3_ABC 6 | ||
220 | |||
221 | |||
222 | /* possible actions when in mimo mode */ | ||
223 | #define IWL_MIMO2_SWITCH_ANTENNA1 0 | ||
224 | #define IWL_MIMO2_SWITCH_ANTENNA2 1 | ||
225 | #define IWL_MIMO2_SWITCH_SISO_A 2 | ||
226 | #define IWL_MIMO2_SWITCH_SISO_B 3 | ||
227 | #define IWL_MIMO2_SWITCH_SISO_C 4 | ||
228 | #define IWL_MIMO2_SWITCH_GI 5 | ||
229 | #define IWL_MIMO2_SWITCH_MIMO3_ABC 6 | ||
230 | |||
231 | |||
232 | /* possible actions when in mimo3 mode */ | ||
233 | #define IWL_MIMO3_SWITCH_ANTENNA1 0 | ||
234 | #define IWL_MIMO3_SWITCH_ANTENNA2 1 | ||
235 | #define IWL_MIMO3_SWITCH_SISO_A 2 | ||
236 | #define IWL_MIMO3_SWITCH_SISO_B 3 | ||
237 | #define IWL_MIMO3_SWITCH_SISO_C 4 | ||
238 | #define IWL_MIMO3_SWITCH_MIMO2_AB 5 | ||
239 | #define IWL_MIMO3_SWITCH_MIMO2_AC 6 | ||
240 | #define IWL_MIMO3_SWITCH_MIMO2_BC 7 | ||
241 | #define IWL_MIMO3_SWITCH_GI 8 | ||
242 | |||
243 | |||
244 | #define IWL_MAX_11N_MIMO3_SEARCH IWL_MIMO3_SWITCH_GI | ||
245 | #define IWL_MAX_SEARCH IWL_MIMO2_SWITCH_MIMO3_ABC | ||
246 | |||
247 | /*FIXME:RS:add possible actions for MIMO3*/ | ||
248 | |||
249 | #define IWL_ACTION_LIMIT 3 /* # possible actions */ | ||
250 | |||
251 | #define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */ | ||
252 | |||
253 | /* load per tid defines for A-MPDU activation */ | ||
254 | #define IWL_AGG_TPT_THREHOLD 0 | ||
255 | #define IWL_AGG_LOAD_THRESHOLD 10 | ||
256 | #define IWL_AGG_ALL_TID 0xff | ||
257 | #define TID_QUEUE_CELL_SPACING 50 /*mS */ | ||
258 | #define TID_QUEUE_MAX_SIZE 20 | ||
259 | #define TID_ROUND_VALUE 5 /* mS */ | ||
260 | |||
261 | #define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING) | ||
262 | #define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y)) | ||
263 | |||
264 | extern const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT]; | ||
265 | |||
266 | enum iwl_table_type { | ||
267 | LQ_NONE, | ||
268 | LQ_G, /* legacy types */ | ||
269 | LQ_A, | ||
270 | LQ_SISO, /* high-throughput types */ | ||
271 | LQ_MIMO2, | ||
272 | LQ_MIMO3, | ||
273 | LQ_MAX, | ||
274 | }; | ||
275 | |||
276 | #define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A)) | ||
277 | #define is_siso(tbl) ((tbl) == LQ_SISO) | ||
278 | #define is_mimo2(tbl) ((tbl) == LQ_MIMO2) | ||
279 | #define is_mimo3(tbl) ((tbl) == LQ_MIMO3) | ||
280 | #define is_mimo(tbl) (is_mimo2(tbl) || is_mimo3(tbl)) | ||
281 | #define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl)) | ||
282 | #define is_a_band(tbl) ((tbl) == LQ_A) | ||
283 | #define is_g_and(tbl) ((tbl) == LQ_G) | ||
284 | |||
285 | #define IWL_MAX_MCS_DISPLAY_SIZE 12 | ||
286 | |||
287 | struct iwl_rate_mcs_info { | ||
288 | char mbps[IWL_MAX_MCS_DISPLAY_SIZE]; | ||
289 | char mcs[IWL_MAX_MCS_DISPLAY_SIZE]; | ||
290 | }; | ||
291 | |||
292 | /** | ||
293 | * struct iwl_rate_scale_data -- tx success history for one rate | ||
294 | */ | ||
295 | struct iwl_rate_scale_data { | ||
296 | u64 data; /* bitmap of successful frames */ | ||
297 | s32 success_counter; /* number of frames successful */ | ||
298 | s32 success_ratio; /* per-cent * 128 */ | ||
299 | s32 counter; /* number of frames attempted */ | ||
300 | s32 average_tpt; /* success ratio * expected throughput */ | ||
301 | unsigned long stamp; | ||
302 | }; | ||
303 | |||
304 | /** | ||
305 | * struct iwl_scale_tbl_info -- tx params and success history for all rates | ||
306 | * | ||
307 | * There are two of these in struct iwl_lq_sta, | ||
308 | * one for "active", and one for "search". | ||
309 | */ | ||
310 | struct iwl_scale_tbl_info { | ||
311 | enum iwl_table_type lq_type; | ||
312 | u8 ant_type; | ||
313 | u8 is_SGI; /* 1 = short guard interval */ | ||
314 | u8 is_ht40; /* 1 = 40 MHz channel width */ | ||
315 | u8 is_dup; /* 1 = duplicated data streams */ | ||
316 | u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ | ||
317 | u8 max_search; /* maximun number of tables we can search */ | ||
318 | s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ | ||
319 | u32 current_rate; /* rate_n_flags, uCode API format */ | ||
320 | struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ | ||
321 | }; | ||
322 | |||
323 | struct iwl_traffic_load { | ||
324 | unsigned long time_stamp; /* age of the oldest statistics */ | ||
325 | u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time | ||
326 | * slice */ | ||
327 | u32 total; /* total num of packets during the | ||
328 | * last TID_MAX_TIME_DIFF */ | ||
329 | u8 queue_count; /* number of queues that has | ||
330 | * been used since the last cleanup */ | ||
331 | u8 head; /* start of the circular buffer */ | ||
332 | }; | ||
333 | |||
334 | /** | ||
335 | * struct iwl_lq_sta -- driver's rate scaling private structure | ||
336 | * | ||
337 | * Pointer to this gets passed back and forth between driver and mac80211. | ||
338 | */ | ||
339 | struct iwl_lq_sta { | ||
340 | u8 active_tbl; /* index of active table, range 0-1 */ | ||
341 | u8 enable_counter; /* indicates HT mode */ | ||
342 | u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */ | ||
343 | u8 search_better_tbl; /* 1: currently trying alternate mode */ | ||
344 | s32 last_tpt; | ||
345 | |||
346 | /* The following determine when to search for a new mode */ | ||
347 | u32 table_count_limit; | ||
348 | u32 max_failure_limit; /* # failed frames before new search */ | ||
349 | u32 max_success_limit; /* # successful frames before new search */ | ||
350 | u32 table_count; | ||
351 | u32 total_failed; /* total failed frames, any/all rates */ | ||
352 | u32 total_success; /* total successful frames, any/all rates */ | ||
353 | u64 flush_timer; /* time staying in mode before new search */ | ||
354 | |||
355 | u8 action_counter; /* # mode-switch actions tried */ | ||
356 | u8 is_green; | ||
357 | u8 is_dup; | ||
358 | enum ieee80211_band band; | ||
359 | |||
360 | /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ | ||
361 | u32 supp_rates; | ||
362 | u16 active_legacy_rate; | ||
363 | u16 active_siso_rate; | ||
364 | u16 active_mimo2_rate; | ||
365 | u16 active_mimo3_rate; | ||
366 | s8 max_rate_idx; /* Max rate set by user */ | ||
367 | u8 missed_rate_counter; | ||
368 | |||
369 | struct iwl_link_quality_cmd lq; | ||
370 | struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */ | ||
371 | struct iwl_traffic_load load[IWL_MAX_TID_COUNT]; | ||
372 | u8 tx_agg_tid_en; | ||
373 | #ifdef CONFIG_MAC80211_DEBUGFS | ||
374 | struct dentry *rs_sta_dbgfs_scale_table_file; | ||
375 | struct dentry *rs_sta_dbgfs_stats_table_file; | ||
376 | struct dentry *rs_sta_dbgfs_rate_scale_data_file; | ||
377 | struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file; | ||
378 | u32 dbg_fixed_rate; | ||
379 | #endif | ||
380 | struct iwl_priv *drv; | ||
381 | |||
382 | /* used to be in sta_info */ | ||
383 | int last_txrate_idx; | ||
384 | /* last tx rate_n_flags */ | ||
385 | u32 last_rate_n_flags; | ||
386 | /* packets destined for this STA are aggregated */ | ||
387 | u8 is_agg; | ||
388 | /* BT traffic this sta was last updated in */ | ||
389 | u8 last_bt_traffic; | ||
390 | }; | ||
391 | |||
392 | static inline u8 num_of_ant(u8 mask) | ||
393 | { | ||
394 | return !!((mask) & ANT_A) + | ||
395 | !!((mask) & ANT_B) + | ||
396 | !!((mask) & ANT_C); | ||
397 | } | ||
398 | |||
399 | static inline u8 first_antenna(u8 mask) | ||
400 | { | ||
401 | if (mask & ANT_A) | ||
402 | return ANT_A; | ||
403 | if (mask & ANT_B) | ||
404 | return ANT_B; | ||
405 | return ANT_C; | ||
406 | } | ||
407 | |||
408 | |||
409 | /* Initialize station's rate scaling information after adding station */ | ||
410 | extern void iwl_rs_rate_init(struct iwl_priv *priv, | ||
411 | struct ieee80211_sta *sta, u8 sta_id); | ||
412 | |||
413 | /** | ||
414 | * iwl_rate_control_register - Register the rate control algorithm callbacks | ||
415 | * | ||
416 | * Since the rate control algorithm is hardware specific, there is no need | ||
417 | * or reason to place it as a stand alone module. The driver can call | ||
418 | * iwl_rate_control_register in order to register the rate control callbacks | ||
419 | * with the mac80211 subsystem. This should be performed prior to calling | ||
420 | * ieee80211_register_hw | ||
421 | * | ||
422 | */ | ||
423 | extern int iwlagn_rate_control_register(void); | ||
424 | |||
425 | /** | ||
426 | * iwl_rate_control_unregister - Unregister the rate control callbacks | ||
427 | * | ||
428 | * This should be called after calling ieee80211_unregister_hw, but before | ||
429 | * the driver is unloaded. | ||
430 | */ | ||
431 | extern void iwlagn_rate_control_unregister(void); | ||
432 | |||
433 | #endif /* __iwl_agn__rs__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/rx.c b/drivers/net/wireless/iwlwifi/dvm/rx.c new file mode 100644 index 000000000000..0ed90bb8b56a --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/rx.c | |||
@@ -0,0 +1,1166 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * Portions of this file are derived from the ipw3945 project, as well | ||
6 | * as portionhelp 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 | *****************************************************************************/ | ||
29 | |||
30 | #include <linux/etherdevice.h> | ||
31 | #include <linux/slab.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <net/mac80211.h> | ||
34 | #include <asm/unaligned.h> | ||
35 | #include "iwl-io.h" | ||
36 | #include "dev.h" | ||
37 | #include "calib.h" | ||
38 | #include "agn.h" | ||
39 | |||
40 | #define IWL_CMD_ENTRY(x) [x] = #x | ||
41 | |||
42 | const char *iwl_dvm_cmd_strings[REPLY_MAX] = { | ||
43 | IWL_CMD_ENTRY(REPLY_ALIVE), | ||
44 | IWL_CMD_ENTRY(REPLY_ERROR), | ||
45 | IWL_CMD_ENTRY(REPLY_ECHO), | ||
46 | IWL_CMD_ENTRY(REPLY_RXON), | ||
47 | IWL_CMD_ENTRY(REPLY_RXON_ASSOC), | ||
48 | IWL_CMD_ENTRY(REPLY_QOS_PARAM), | ||
49 | IWL_CMD_ENTRY(REPLY_RXON_TIMING), | ||
50 | IWL_CMD_ENTRY(REPLY_ADD_STA), | ||
51 | IWL_CMD_ENTRY(REPLY_REMOVE_STA), | ||
52 | IWL_CMD_ENTRY(REPLY_REMOVE_ALL_STA), | ||
53 | IWL_CMD_ENTRY(REPLY_TXFIFO_FLUSH), | ||
54 | IWL_CMD_ENTRY(REPLY_WEPKEY), | ||
55 | IWL_CMD_ENTRY(REPLY_TX), | ||
56 | IWL_CMD_ENTRY(REPLY_LEDS_CMD), | ||
57 | IWL_CMD_ENTRY(REPLY_TX_LINK_QUALITY_CMD), | ||
58 | IWL_CMD_ENTRY(COEX_PRIORITY_TABLE_CMD), | ||
59 | IWL_CMD_ENTRY(COEX_MEDIUM_NOTIFICATION), | ||
60 | IWL_CMD_ENTRY(COEX_EVENT_CMD), | ||
61 | IWL_CMD_ENTRY(REPLY_QUIET_CMD), | ||
62 | IWL_CMD_ENTRY(REPLY_CHANNEL_SWITCH), | ||
63 | IWL_CMD_ENTRY(CHANNEL_SWITCH_NOTIFICATION), | ||
64 | IWL_CMD_ENTRY(REPLY_SPECTRUM_MEASUREMENT_CMD), | ||
65 | IWL_CMD_ENTRY(SPECTRUM_MEASURE_NOTIFICATION), | ||
66 | IWL_CMD_ENTRY(POWER_TABLE_CMD), | ||
67 | IWL_CMD_ENTRY(PM_SLEEP_NOTIFICATION), | ||
68 | IWL_CMD_ENTRY(PM_DEBUG_STATISTIC_NOTIFIC), | ||
69 | IWL_CMD_ENTRY(REPLY_SCAN_CMD), | ||
70 | IWL_CMD_ENTRY(REPLY_SCAN_ABORT_CMD), | ||
71 | IWL_CMD_ENTRY(SCAN_START_NOTIFICATION), | ||
72 | IWL_CMD_ENTRY(SCAN_RESULTS_NOTIFICATION), | ||
73 | IWL_CMD_ENTRY(SCAN_COMPLETE_NOTIFICATION), | ||
74 | IWL_CMD_ENTRY(BEACON_NOTIFICATION), | ||
75 | IWL_CMD_ENTRY(REPLY_TX_BEACON), | ||
76 | IWL_CMD_ENTRY(WHO_IS_AWAKE_NOTIFICATION), | ||
77 | IWL_CMD_ENTRY(QUIET_NOTIFICATION), | ||
78 | IWL_CMD_ENTRY(REPLY_TX_PWR_TABLE_CMD), | ||
79 | IWL_CMD_ENTRY(MEASURE_ABORT_NOTIFICATION), | ||
80 | IWL_CMD_ENTRY(REPLY_BT_CONFIG), | ||
81 | IWL_CMD_ENTRY(REPLY_STATISTICS_CMD), | ||
82 | IWL_CMD_ENTRY(STATISTICS_NOTIFICATION), | ||
83 | IWL_CMD_ENTRY(REPLY_CARD_STATE_CMD), | ||
84 | IWL_CMD_ENTRY(CARD_STATE_NOTIFICATION), | ||
85 | IWL_CMD_ENTRY(MISSED_BEACONS_NOTIFICATION), | ||
86 | IWL_CMD_ENTRY(REPLY_CT_KILL_CONFIG_CMD), | ||
87 | IWL_CMD_ENTRY(SENSITIVITY_CMD), | ||
88 | IWL_CMD_ENTRY(REPLY_PHY_CALIBRATION_CMD), | ||
89 | IWL_CMD_ENTRY(REPLY_RX_PHY_CMD), | ||
90 | IWL_CMD_ENTRY(REPLY_RX_MPDU_CMD), | ||
91 | IWL_CMD_ENTRY(REPLY_RX), | ||
92 | IWL_CMD_ENTRY(REPLY_COMPRESSED_BA), | ||
93 | IWL_CMD_ENTRY(CALIBRATION_CFG_CMD), | ||
94 | IWL_CMD_ENTRY(CALIBRATION_RES_NOTIFICATION), | ||
95 | IWL_CMD_ENTRY(CALIBRATION_COMPLETE_NOTIFICATION), | ||
96 | IWL_CMD_ENTRY(REPLY_TX_POWER_DBM_CMD), | ||
97 | IWL_CMD_ENTRY(TEMPERATURE_NOTIFICATION), | ||
98 | IWL_CMD_ENTRY(TX_ANT_CONFIGURATION_CMD), | ||
99 | IWL_CMD_ENTRY(REPLY_BT_COEX_PROFILE_NOTIF), | ||
100 | IWL_CMD_ENTRY(REPLY_BT_COEX_PRIO_TABLE), | ||
101 | IWL_CMD_ENTRY(REPLY_BT_COEX_PROT_ENV), | ||
102 | IWL_CMD_ENTRY(REPLY_WIPAN_PARAMS), | ||
103 | IWL_CMD_ENTRY(REPLY_WIPAN_RXON), | ||
104 | IWL_CMD_ENTRY(REPLY_WIPAN_RXON_TIMING), | ||
105 | IWL_CMD_ENTRY(REPLY_WIPAN_RXON_ASSOC), | ||
106 | IWL_CMD_ENTRY(REPLY_WIPAN_QOS_PARAM), | ||
107 | IWL_CMD_ENTRY(REPLY_WIPAN_WEPKEY), | ||
108 | IWL_CMD_ENTRY(REPLY_WIPAN_P2P_CHANNEL_SWITCH), | ||
109 | IWL_CMD_ENTRY(REPLY_WIPAN_NOA_NOTIFICATION), | ||
110 | IWL_CMD_ENTRY(REPLY_WIPAN_DEACTIVATION_COMPLETE), | ||
111 | IWL_CMD_ENTRY(REPLY_WOWLAN_PATTERNS), | ||
112 | IWL_CMD_ENTRY(REPLY_WOWLAN_WAKEUP_FILTER), | ||
113 | IWL_CMD_ENTRY(REPLY_WOWLAN_TSC_RSC_PARAMS), | ||
114 | IWL_CMD_ENTRY(REPLY_WOWLAN_TKIP_PARAMS), | ||
115 | IWL_CMD_ENTRY(REPLY_WOWLAN_KEK_KCK_MATERIAL), | ||
116 | IWL_CMD_ENTRY(REPLY_WOWLAN_GET_STATUS), | ||
117 | IWL_CMD_ENTRY(REPLY_D3_CONFIG), | ||
118 | }; | ||
119 | #undef IWL_CMD_ENTRY | ||
120 | |||
121 | /****************************************************************************** | ||
122 | * | ||
123 | * Generic RX handler implementations | ||
124 | * | ||
125 | ******************************************************************************/ | ||
126 | |||
127 | static int iwlagn_rx_reply_error(struct iwl_priv *priv, | ||
128 | struct iwl_rx_cmd_buffer *rxb, | ||
129 | struct iwl_device_cmd *cmd) | ||
130 | { | ||
131 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
132 | struct iwl_error_resp *err_resp = (void *)pkt->data; | ||
133 | |||
134 | IWL_ERR(priv, "Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) " | ||
135 | "seq 0x%04X ser 0x%08X\n", | ||
136 | le32_to_cpu(err_resp->error_type), | ||
137 | err_resp->cmd_id, | ||
138 | le16_to_cpu(err_resp->bad_cmd_seq_num), | ||
139 | le32_to_cpu(err_resp->error_info)); | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static int iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, | ||
144 | struct iwl_device_cmd *cmd) | ||
145 | { | ||
146 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
147 | struct iwl_csa_notification *csa = (void *)pkt->data; | ||
148 | /* | ||
149 | * MULTI-FIXME | ||
150 | * See iwlagn_mac_channel_switch. | ||
151 | */ | ||
152 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
153 | struct iwl_rxon_cmd *rxon = (void *)&ctx->active; | ||
154 | |||
155 | if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) | ||
156 | return 0; | ||
157 | |||
158 | if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) { | ||
159 | rxon->channel = csa->channel; | ||
160 | ctx->staging.channel = csa->channel; | ||
161 | IWL_DEBUG_11H(priv, "CSA notif: channel %d\n", | ||
162 | le16_to_cpu(csa->channel)); | ||
163 | iwl_chswitch_done(priv, true); | ||
164 | } else { | ||
165 | IWL_ERR(priv, "CSA notif (fail) : channel %d\n", | ||
166 | le16_to_cpu(csa->channel)); | ||
167 | iwl_chswitch_done(priv, false); | ||
168 | } | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | |||
173 | static int iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv, | ||
174 | struct iwl_rx_cmd_buffer *rxb, | ||
175 | struct iwl_device_cmd *cmd) | ||
176 | { | ||
177 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
178 | struct iwl_spectrum_notification *report = (void *)pkt->data; | ||
179 | |||
180 | if (!report->state) { | ||
181 | IWL_DEBUG_11H(priv, | ||
182 | "Spectrum Measure Notification: Start\n"); | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | memcpy(&priv->measure_report, report, sizeof(*report)); | ||
187 | priv->measurement_status |= MEASUREMENT_READY; | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static int iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv, | ||
192 | struct iwl_rx_cmd_buffer *rxb, | ||
193 | struct iwl_device_cmd *cmd) | ||
194 | { | ||
195 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
196 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
197 | struct iwl_sleep_notification *sleep = (void *)pkt->data; | ||
198 | IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", | ||
199 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); | ||
200 | #endif | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv, | ||
205 | struct iwl_rx_cmd_buffer *rxb, | ||
206 | struct iwl_device_cmd *cmd) | ||
207 | { | ||
208 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
209 | u32 __maybe_unused len = | ||
210 | le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | ||
211 | IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " | ||
212 | "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len); | ||
213 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len); | ||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | static int iwlagn_rx_beacon_notif(struct iwl_priv *priv, | ||
218 | struct iwl_rx_cmd_buffer *rxb, | ||
219 | struct iwl_device_cmd *cmd) | ||
220 | { | ||
221 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
222 | struct iwlagn_beacon_notif *beacon = (void *)pkt->data; | ||
223 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
224 | u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status); | ||
225 | u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); | ||
226 | |||
227 | IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d " | ||
228 | "tsf:0x%.8x%.8x rate:%d\n", | ||
229 | status & TX_STATUS_MSK, | ||
230 | beacon->beacon_notify_hdr.failure_frame, | ||
231 | le32_to_cpu(beacon->ibss_mgr_status), | ||
232 | le32_to_cpu(beacon->high_tsf), | ||
233 | le32_to_cpu(beacon->low_tsf), rate); | ||
234 | #endif | ||
235 | |||
236 | priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); | ||
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * iwl_good_plcp_health - checks for plcp error. | ||
243 | * | ||
244 | * When the plcp error is exceeding the thresholds, reset the radio | ||
245 | * to improve the throughput. | ||
246 | */ | ||
247 | static bool iwlagn_good_plcp_health(struct iwl_priv *priv, | ||
248 | struct statistics_rx_phy *cur_ofdm, | ||
249 | struct statistics_rx_ht_phy *cur_ofdm_ht, | ||
250 | unsigned int msecs) | ||
251 | { | ||
252 | int delta; | ||
253 | int threshold = priv->plcp_delta_threshold; | ||
254 | |||
255 | if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) { | ||
256 | IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n"); | ||
257 | return true; | ||
258 | } | ||
259 | |||
260 | delta = le32_to_cpu(cur_ofdm->plcp_err) - | ||
261 | le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) + | ||
262 | le32_to_cpu(cur_ofdm_ht->plcp_err) - | ||
263 | le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err); | ||
264 | |||
265 | /* Can be negative if firmware reset statistics */ | ||
266 | if (delta <= 0) | ||
267 | return true; | ||
268 | |||
269 | if ((delta * 100 / msecs) > threshold) { | ||
270 | IWL_DEBUG_RADIO(priv, | ||
271 | "plcp health threshold %u delta %d msecs %u\n", | ||
272 | threshold, delta, msecs); | ||
273 | return false; | ||
274 | } | ||
275 | |||
276 | return true; | ||
277 | } | ||
278 | |||
279 | int iwl_force_rf_reset(struct iwl_priv *priv, bool external) | ||
280 | { | ||
281 | struct iwl_rf_reset *rf_reset; | ||
282 | |||
283 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
284 | return -EAGAIN; | ||
285 | |||
286 | if (!iwl_is_any_associated(priv)) { | ||
287 | IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n"); | ||
288 | return -ENOLINK; | ||
289 | } | ||
290 | |||
291 | rf_reset = &priv->rf_reset; | ||
292 | rf_reset->reset_request_count++; | ||
293 | if (!external && rf_reset->last_reset_jiffies && | ||
294 | time_after(rf_reset->last_reset_jiffies + | ||
295 | IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) { | ||
296 | IWL_DEBUG_INFO(priv, "RF reset rejected\n"); | ||
297 | rf_reset->reset_reject_count++; | ||
298 | return -EAGAIN; | ||
299 | } | ||
300 | rf_reset->reset_success_count++; | ||
301 | rf_reset->last_reset_jiffies = jiffies; | ||
302 | |||
303 | /* | ||
304 | * There is no easy and better way to force reset the radio, | ||
305 | * the only known method is switching channel which will force to | ||
306 | * reset and tune the radio. | ||
307 | * Use internal short scan (single channel) operation to should | ||
308 | * achieve this objective. | ||
309 | * Driver should reset the radio when number of consecutive missed | ||
310 | * beacon, or any other uCode error condition detected. | ||
311 | */ | ||
312 | IWL_DEBUG_INFO(priv, "perform radio reset.\n"); | ||
313 | iwl_internal_short_hw_scan(priv); | ||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | |||
318 | static void iwlagn_recover_from_statistics(struct iwl_priv *priv, | ||
319 | struct statistics_rx_phy *cur_ofdm, | ||
320 | struct statistics_rx_ht_phy *cur_ofdm_ht, | ||
321 | struct statistics_tx *tx, | ||
322 | unsigned long stamp) | ||
323 | { | ||
324 | unsigned int msecs; | ||
325 | |||
326 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
327 | return; | ||
328 | |||
329 | msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies); | ||
330 | |||
331 | /* Only gather statistics and update time stamp when not associated */ | ||
332 | if (!iwl_is_any_associated(priv)) | ||
333 | return; | ||
334 | |||
335 | /* Do not check/recover when do not have enough statistics data */ | ||
336 | if (msecs < 99) | ||
337 | return; | ||
338 | |||
339 | if (iwlwifi_mod_params.plcp_check && | ||
340 | !iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs)) | ||
341 | iwl_force_rf_reset(priv, false); | ||
342 | } | ||
343 | |||
344 | /* Calculate noise level, based on measurements during network silence just | ||
345 | * before arriving beacon. This measurement can be done only if we know | ||
346 | * exactly when to expect beacons, therefore only when we're associated. */ | ||
347 | static void iwlagn_rx_calc_noise(struct iwl_priv *priv) | ||
348 | { | ||
349 | struct statistics_rx_non_phy *rx_info; | ||
350 | int num_active_rx = 0; | ||
351 | int total_silence = 0; | ||
352 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; | ||
353 | int last_rx_noise; | ||
354 | |||
355 | rx_info = &priv->statistics.rx_non_phy; | ||
356 | |||
357 | bcn_silence_a = | ||
358 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; | ||
359 | bcn_silence_b = | ||
360 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; | ||
361 | bcn_silence_c = | ||
362 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; | ||
363 | |||
364 | if (bcn_silence_a) { | ||
365 | total_silence += bcn_silence_a; | ||
366 | num_active_rx++; | ||
367 | } | ||
368 | if (bcn_silence_b) { | ||
369 | total_silence += bcn_silence_b; | ||
370 | num_active_rx++; | ||
371 | } | ||
372 | if (bcn_silence_c) { | ||
373 | total_silence += bcn_silence_c; | ||
374 | num_active_rx++; | ||
375 | } | ||
376 | |||
377 | /* Average among active antennas */ | ||
378 | if (num_active_rx) | ||
379 | last_rx_noise = (total_silence / num_active_rx) - 107; | ||
380 | else | ||
381 | last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; | ||
382 | |||
383 | IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n", | ||
384 | bcn_silence_a, bcn_silence_b, bcn_silence_c, | ||
385 | last_rx_noise); | ||
386 | } | ||
387 | |||
388 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
389 | /* | ||
390 | * based on the assumption of all statistics counter are in DWORD | ||
391 | * FIXME: This function is for debugging, do not deal with | ||
392 | * the case of counters roll-over. | ||
393 | */ | ||
394 | static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta, | ||
395 | __le32 *max_delta, __le32 *accum, int size) | ||
396 | { | ||
397 | int i; | ||
398 | |||
399 | for (i = 0; | ||
400 | i < size / sizeof(__le32); | ||
401 | i++, prev++, cur++, delta++, max_delta++, accum++) { | ||
402 | if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) { | ||
403 | *delta = cpu_to_le32( | ||
404 | le32_to_cpu(*cur) - le32_to_cpu(*prev)); | ||
405 | le32_add_cpu(accum, le32_to_cpu(*delta)); | ||
406 | if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta)) | ||
407 | *max_delta = *delta; | ||
408 | } | ||
409 | } | ||
410 | } | ||
411 | |||
412 | static void | ||
413 | iwlagn_accumulative_statistics(struct iwl_priv *priv, | ||
414 | struct statistics_general_common *common, | ||
415 | struct statistics_rx_non_phy *rx_non_phy, | ||
416 | struct statistics_rx_phy *rx_ofdm, | ||
417 | struct statistics_rx_ht_phy *rx_ofdm_ht, | ||
418 | struct statistics_rx_phy *rx_cck, | ||
419 | struct statistics_tx *tx, | ||
420 | struct statistics_bt_activity *bt_activity) | ||
421 | { | ||
422 | #define ACCUM(_name) \ | ||
423 | accum_stats((__le32 *)&priv->statistics._name, \ | ||
424 | (__le32 *)_name, \ | ||
425 | (__le32 *)&priv->delta_stats._name, \ | ||
426 | (__le32 *)&priv->max_delta_stats._name, \ | ||
427 | (__le32 *)&priv->accum_stats._name, \ | ||
428 | sizeof(*_name)); | ||
429 | |||
430 | ACCUM(common); | ||
431 | ACCUM(rx_non_phy); | ||
432 | ACCUM(rx_ofdm); | ||
433 | ACCUM(rx_ofdm_ht); | ||
434 | ACCUM(rx_cck); | ||
435 | ACCUM(tx); | ||
436 | if (bt_activity) | ||
437 | ACCUM(bt_activity); | ||
438 | #undef ACCUM | ||
439 | } | ||
440 | #else | ||
441 | static inline void | ||
442 | iwlagn_accumulative_statistics(struct iwl_priv *priv, | ||
443 | struct statistics_general_common *common, | ||
444 | struct statistics_rx_non_phy *rx_non_phy, | ||
445 | struct statistics_rx_phy *rx_ofdm, | ||
446 | struct statistics_rx_ht_phy *rx_ofdm_ht, | ||
447 | struct statistics_rx_phy *rx_cck, | ||
448 | struct statistics_tx *tx, | ||
449 | struct statistics_bt_activity *bt_activity) | ||
450 | { | ||
451 | } | ||
452 | #endif | ||
453 | |||
454 | static int iwlagn_rx_statistics(struct iwl_priv *priv, | ||
455 | struct iwl_rx_cmd_buffer *rxb, | ||
456 | struct iwl_device_cmd *cmd) | ||
457 | { | ||
458 | unsigned long stamp = jiffies; | ||
459 | const int reg_recalib_period = 60; | ||
460 | int change; | ||
461 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
462 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | ||
463 | __le32 *flag; | ||
464 | struct statistics_general_common *common; | ||
465 | struct statistics_rx_non_phy *rx_non_phy; | ||
466 | struct statistics_rx_phy *rx_ofdm; | ||
467 | struct statistics_rx_ht_phy *rx_ofdm_ht; | ||
468 | struct statistics_rx_phy *rx_cck; | ||
469 | struct statistics_tx *tx; | ||
470 | struct statistics_bt_activity *bt_activity; | ||
471 | |||
472 | len -= sizeof(struct iwl_cmd_header); /* skip header */ | ||
473 | |||
474 | IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n", | ||
475 | len); | ||
476 | |||
477 | spin_lock(&priv->statistics.lock); | ||
478 | |||
479 | if (len == sizeof(struct iwl_bt_notif_statistics)) { | ||
480 | struct iwl_bt_notif_statistics *stats; | ||
481 | stats = (void *)&pkt->data; | ||
482 | flag = &stats->flag; | ||
483 | common = &stats->general.common; | ||
484 | rx_non_phy = &stats->rx.general.common; | ||
485 | rx_ofdm = &stats->rx.ofdm; | ||
486 | rx_ofdm_ht = &stats->rx.ofdm_ht; | ||
487 | rx_cck = &stats->rx.cck; | ||
488 | tx = &stats->tx; | ||
489 | bt_activity = &stats->general.activity; | ||
490 | |||
491 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
492 | /* handle this exception directly */ | ||
493 | priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills; | ||
494 | le32_add_cpu(&priv->statistics.accum_num_bt_kills, | ||
495 | le32_to_cpu(stats->rx.general.num_bt_kills)); | ||
496 | #endif | ||
497 | } else if (len == sizeof(struct iwl_notif_statistics)) { | ||
498 | struct iwl_notif_statistics *stats; | ||
499 | stats = (void *)&pkt->data; | ||
500 | flag = &stats->flag; | ||
501 | common = &stats->general.common; | ||
502 | rx_non_phy = &stats->rx.general; | ||
503 | rx_ofdm = &stats->rx.ofdm; | ||
504 | rx_ofdm_ht = &stats->rx.ofdm_ht; | ||
505 | rx_cck = &stats->rx.cck; | ||
506 | tx = &stats->tx; | ||
507 | bt_activity = NULL; | ||
508 | } else { | ||
509 | WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n", | ||
510 | len, sizeof(struct iwl_bt_notif_statistics), | ||
511 | sizeof(struct iwl_notif_statistics)); | ||
512 | spin_unlock(&priv->statistics.lock); | ||
513 | return 0; | ||
514 | } | ||
515 | |||
516 | change = common->temperature != priv->statistics.common.temperature || | ||
517 | (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) != | ||
518 | (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK); | ||
519 | |||
520 | iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm, | ||
521 | rx_ofdm_ht, rx_cck, tx, bt_activity); | ||
522 | |||
523 | iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp); | ||
524 | |||
525 | priv->statistics.flag = *flag; | ||
526 | memcpy(&priv->statistics.common, common, sizeof(*common)); | ||
527 | memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy)); | ||
528 | memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm)); | ||
529 | memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht)); | ||
530 | memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck)); | ||
531 | memcpy(&priv->statistics.tx, tx, sizeof(*tx)); | ||
532 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
533 | if (bt_activity) | ||
534 | memcpy(&priv->statistics.bt_activity, bt_activity, | ||
535 | sizeof(*bt_activity)); | ||
536 | #endif | ||
537 | |||
538 | priv->rx_statistics_jiffies = stamp; | ||
539 | |||
540 | set_bit(STATUS_STATISTICS, &priv->status); | ||
541 | |||
542 | /* Reschedule the statistics timer to occur in | ||
543 | * reg_recalib_period seconds to ensure we get a | ||
544 | * thermal update even if the uCode doesn't give | ||
545 | * us one */ | ||
546 | mod_timer(&priv->statistics_periodic, jiffies + | ||
547 | msecs_to_jiffies(reg_recalib_period * 1000)); | ||
548 | |||
549 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && | ||
550 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { | ||
551 | iwlagn_rx_calc_noise(priv); | ||
552 | queue_work(priv->workqueue, &priv->run_time_calib_work); | ||
553 | } | ||
554 | if (priv->lib->temperature && change) | ||
555 | priv->lib->temperature(priv); | ||
556 | |||
557 | spin_unlock(&priv->statistics.lock); | ||
558 | |||
559 | return 0; | ||
560 | } | ||
561 | |||
562 | static int iwlagn_rx_reply_statistics(struct iwl_priv *priv, | ||
563 | struct iwl_rx_cmd_buffer *rxb, | ||
564 | struct iwl_device_cmd *cmd) | ||
565 | { | ||
566 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
567 | struct iwl_notif_statistics *stats = (void *)pkt->data; | ||
568 | |||
569 | if (le32_to_cpu(stats->flag) & UCODE_STATISTICS_CLEAR_MSK) { | ||
570 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
571 | memset(&priv->accum_stats, 0, | ||
572 | sizeof(priv->accum_stats)); | ||
573 | memset(&priv->delta_stats, 0, | ||
574 | sizeof(priv->delta_stats)); | ||
575 | memset(&priv->max_delta_stats, 0, | ||
576 | sizeof(priv->max_delta_stats)); | ||
577 | #endif | ||
578 | IWL_DEBUG_RX(priv, "Statistics have been cleared\n"); | ||
579 | } | ||
580 | iwlagn_rx_statistics(priv, rxb, cmd); | ||
581 | return 0; | ||
582 | } | ||
583 | |||
584 | /* Handle notification from uCode that card's power state is changing | ||
585 | * due to software, hardware, or critical temperature RFKILL */ | ||
586 | static int iwlagn_rx_card_state_notif(struct iwl_priv *priv, | ||
587 | struct iwl_rx_cmd_buffer *rxb, | ||
588 | struct iwl_device_cmd *cmd) | ||
589 | { | ||
590 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
591 | struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; | ||
592 | u32 flags = le32_to_cpu(card_state_notif->flags); | ||
593 | unsigned long status = priv->status; | ||
594 | |||
595 | IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n", | ||
596 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", | ||
597 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", | ||
598 | (flags & CT_CARD_DISABLED) ? | ||
599 | "Reached" : "Not reached"); | ||
600 | |||
601 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | | ||
602 | CT_CARD_DISABLED)) { | ||
603 | |||
604 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, | ||
605 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); | ||
606 | |||
607 | iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, | ||
608 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); | ||
609 | |||
610 | if (!(flags & RXON_CARD_DISABLED)) { | ||
611 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, | ||
612 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); | ||
613 | iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, | ||
614 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); | ||
615 | } | ||
616 | if (flags & CT_CARD_DISABLED) | ||
617 | iwl_tt_enter_ct_kill(priv); | ||
618 | } | ||
619 | if (!(flags & CT_CARD_DISABLED)) | ||
620 | iwl_tt_exit_ct_kill(priv); | ||
621 | |||
622 | if (flags & HW_CARD_DISABLED) | ||
623 | set_bit(STATUS_RF_KILL_HW, &priv->status); | ||
624 | else | ||
625 | clear_bit(STATUS_RF_KILL_HW, &priv->status); | ||
626 | |||
627 | |||
628 | if (!(flags & RXON_CARD_DISABLED)) | ||
629 | iwl_scan_cancel(priv); | ||
630 | |||
631 | if ((test_bit(STATUS_RF_KILL_HW, &status) != | ||
632 | test_bit(STATUS_RF_KILL_HW, &priv->status))) | ||
633 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, | ||
634 | test_bit(STATUS_RF_KILL_HW, &priv->status)); | ||
635 | else | ||
636 | wake_up(&priv->trans->wait_command_queue); | ||
637 | return 0; | ||
638 | } | ||
639 | |||
640 | static int iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv, | ||
641 | struct iwl_rx_cmd_buffer *rxb, | ||
642 | struct iwl_device_cmd *cmd) | ||
643 | |||
644 | { | ||
645 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
646 | struct iwl_missed_beacon_notif *missed_beacon = (void *)pkt->data; | ||
647 | |||
648 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > | ||
649 | priv->missed_beacon_threshold) { | ||
650 | IWL_DEBUG_CALIB(priv, | ||
651 | "missed bcn cnsq %d totl %d rcd %d expctd %d\n", | ||
652 | le32_to_cpu(missed_beacon->consecutive_missed_beacons), | ||
653 | le32_to_cpu(missed_beacon->total_missed_becons), | ||
654 | le32_to_cpu(missed_beacon->num_recvd_beacons), | ||
655 | le32_to_cpu(missed_beacon->num_expected_beacons)); | ||
656 | if (!test_bit(STATUS_SCANNING, &priv->status)) | ||
657 | iwl_init_sensitivity(priv); | ||
658 | } | ||
659 | return 0; | ||
660 | } | ||
661 | |||
662 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). | ||
663 | * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ | ||
664 | static int iwlagn_rx_reply_rx_phy(struct iwl_priv *priv, | ||
665 | struct iwl_rx_cmd_buffer *rxb, | ||
666 | struct iwl_device_cmd *cmd) | ||
667 | { | ||
668 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
669 | |||
670 | priv->last_phy_res_valid = true; | ||
671 | memcpy(&priv->last_phy_res, pkt->data, | ||
672 | sizeof(struct iwl_rx_phy_res)); | ||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | /* | ||
677 | * returns non-zero if packet should be dropped | ||
678 | */ | ||
679 | static int iwlagn_set_decrypted_flag(struct iwl_priv *priv, | ||
680 | struct ieee80211_hdr *hdr, | ||
681 | u32 decrypt_res, | ||
682 | struct ieee80211_rx_status *stats) | ||
683 | { | ||
684 | u16 fc = le16_to_cpu(hdr->frame_control); | ||
685 | |||
686 | /* | ||
687 | * All contexts have the same setting here due to it being | ||
688 | * a module parameter, so OK to check any context. | ||
689 | */ | ||
690 | if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags & | ||
691 | RXON_FILTER_DIS_DECRYPT_MSK) | ||
692 | return 0; | ||
693 | |||
694 | if (!(fc & IEEE80211_FCTL_PROTECTED)) | ||
695 | return 0; | ||
696 | |||
697 | IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res); | ||
698 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { | ||
699 | case RX_RES_STATUS_SEC_TYPE_TKIP: | ||
700 | /* The uCode has got a bad phase 1 Key, pushes the packet. | ||
701 | * Decryption will be done in SW. */ | ||
702 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | ||
703 | RX_RES_STATUS_BAD_KEY_TTAK) | ||
704 | break; | ||
705 | |||
706 | case RX_RES_STATUS_SEC_TYPE_WEP: | ||
707 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | ||
708 | RX_RES_STATUS_BAD_ICV_MIC) { | ||
709 | /* bad ICV, the packet is destroyed since the | ||
710 | * decryption is inplace, drop it */ | ||
711 | IWL_DEBUG_RX(priv, "Packet destroyed\n"); | ||
712 | return -1; | ||
713 | } | ||
714 | case RX_RES_STATUS_SEC_TYPE_CCMP: | ||
715 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | ||
716 | RX_RES_STATUS_DECRYPT_OK) { | ||
717 | IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n"); | ||
718 | stats->flag |= RX_FLAG_DECRYPTED; | ||
719 | } | ||
720 | break; | ||
721 | |||
722 | default: | ||
723 | break; | ||
724 | } | ||
725 | return 0; | ||
726 | } | ||
727 | |||
728 | static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv, | ||
729 | struct ieee80211_hdr *hdr, | ||
730 | u16 len, | ||
731 | u32 ampdu_status, | ||
732 | struct iwl_rx_cmd_buffer *rxb, | ||
733 | struct ieee80211_rx_status *stats) | ||
734 | { | ||
735 | struct sk_buff *skb; | ||
736 | __le16 fc = hdr->frame_control; | ||
737 | struct iwl_rxon_context *ctx; | ||
738 | unsigned int hdrlen, fraglen; | ||
739 | |||
740 | /* We only process data packets if the interface is open */ | ||
741 | if (unlikely(!priv->is_open)) { | ||
742 | IWL_DEBUG_DROP_LIMIT(priv, | ||
743 | "Dropping packet while interface is not open.\n"); | ||
744 | return; | ||
745 | } | ||
746 | |||
747 | /* In case of HW accelerated crypto and bad decryption, drop */ | ||
748 | if (!iwlwifi_mod_params.sw_crypto && | ||
749 | iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats)) | ||
750 | return; | ||
751 | |||
752 | /* Dont use dev_alloc_skb(), we'll have enough headroom once | ||
753 | * ieee80211_hdr pulled. | ||
754 | */ | ||
755 | skb = alloc_skb(128, GFP_ATOMIC); | ||
756 | if (!skb) { | ||
757 | IWL_ERR(priv, "alloc_skb failed\n"); | ||
758 | return; | ||
759 | } | ||
760 | /* If frame is small enough to fit in skb->head, pull it completely. | ||
761 | * If not, only pull ieee80211_hdr so that splice() or TCP coalesce | ||
762 | * are more efficient. | ||
763 | */ | ||
764 | hdrlen = (len <= skb_tailroom(skb)) ? len : sizeof(*hdr); | ||
765 | |||
766 | memcpy(skb_put(skb, hdrlen), hdr, hdrlen); | ||
767 | fraglen = len - hdrlen; | ||
768 | |||
769 | if (fraglen) { | ||
770 | int offset = (void *)hdr + hdrlen - | ||
771 | rxb_addr(rxb) + rxb_offset(rxb); | ||
772 | |||
773 | skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, | ||
774 | fraglen, rxb->truesize); | ||
775 | } | ||
776 | |||
777 | /* | ||
778 | * Wake any queues that were stopped due to a passive channel tx | ||
779 | * failure. This can happen because the regulatory enforcement in | ||
780 | * the device waits for a beacon before allowing transmission, | ||
781 | * sometimes even after already having transmitted frames for the | ||
782 | * association because the new RXON may reset the information. | ||
783 | */ | ||
784 | if (unlikely(ieee80211_is_beacon(fc) && priv->passive_no_rx)) { | ||
785 | for_each_context(priv, ctx) { | ||
786 | if (!ether_addr_equal(hdr->addr3, | ||
787 | ctx->active.bssid_addr)) | ||
788 | continue; | ||
789 | iwlagn_lift_passive_no_rx(priv); | ||
790 | } | ||
791 | } | ||
792 | |||
793 | memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); | ||
794 | |||
795 | ieee80211_rx(priv->hw, skb); | ||
796 | } | ||
797 | |||
798 | static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in) | ||
799 | { | ||
800 | u32 decrypt_out = 0; | ||
801 | |||
802 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == | ||
803 | RX_RES_STATUS_STATION_FOUND) | ||
804 | decrypt_out |= (RX_RES_STATUS_STATION_FOUND | | ||
805 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); | ||
806 | |||
807 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); | ||
808 | |||
809 | /* packet was not encrypted */ | ||
810 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | ||
811 | RX_RES_STATUS_SEC_TYPE_NONE) | ||
812 | return decrypt_out; | ||
813 | |||
814 | /* packet was encrypted with unknown alg */ | ||
815 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | ||
816 | RX_RES_STATUS_SEC_TYPE_ERR) | ||
817 | return decrypt_out; | ||
818 | |||
819 | /* decryption was not done in HW */ | ||
820 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != | ||
821 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) | ||
822 | return decrypt_out; | ||
823 | |||
824 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { | ||
825 | |||
826 | case RX_RES_STATUS_SEC_TYPE_CCMP: | ||
827 | /* alg is CCM: check MIC only */ | ||
828 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) | ||
829 | /* Bad MIC */ | ||
830 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | ||
831 | else | ||
832 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | ||
833 | |||
834 | break; | ||
835 | |||
836 | case RX_RES_STATUS_SEC_TYPE_TKIP: | ||
837 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { | ||
838 | /* Bad TTAK */ | ||
839 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; | ||
840 | break; | ||
841 | } | ||
842 | /* fall through if TTAK OK */ | ||
843 | default: | ||
844 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) | ||
845 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | ||
846 | else | ||
847 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | ||
848 | break; | ||
849 | } | ||
850 | |||
851 | IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n", | ||
852 | decrypt_in, decrypt_out); | ||
853 | |||
854 | return decrypt_out; | ||
855 | } | ||
856 | |||
857 | /* Calc max signal level (dBm) among 3 possible receivers */ | ||
858 | static int iwlagn_calc_rssi(struct iwl_priv *priv, | ||
859 | struct iwl_rx_phy_res *rx_resp) | ||
860 | { | ||
861 | /* data from PHY/DSP regarding signal strength, etc., | ||
862 | * contents are always there, not configurable by host | ||
863 | */ | ||
864 | struct iwlagn_non_cfg_phy *ncphy = | ||
865 | (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf; | ||
866 | u32 val, rssi_a, rssi_b, rssi_c, max_rssi; | ||
867 | u8 agc; | ||
868 | |||
869 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]); | ||
870 | agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS; | ||
871 | |||
872 | /* Find max rssi among 3 possible receivers. | ||
873 | * These values are measured by the digital signal processor (DSP). | ||
874 | * They should stay fairly constant even as the signal strength varies, | ||
875 | * if the radio's automatic gain control (AGC) is working right. | ||
876 | * AGC value (see below) will provide the "interesting" info. | ||
877 | */ | ||
878 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]); | ||
879 | rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >> | ||
880 | IWLAGN_OFDM_RSSI_A_BIT_POS; | ||
881 | rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >> | ||
882 | IWLAGN_OFDM_RSSI_B_BIT_POS; | ||
883 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]); | ||
884 | rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >> | ||
885 | IWLAGN_OFDM_RSSI_C_BIT_POS; | ||
886 | |||
887 | max_rssi = max_t(u32, rssi_a, rssi_b); | ||
888 | max_rssi = max_t(u32, max_rssi, rssi_c); | ||
889 | |||
890 | IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n", | ||
891 | rssi_a, rssi_b, rssi_c, max_rssi, agc); | ||
892 | |||
893 | /* dBm = max_rssi dB - agc dB - constant. | ||
894 | * Higher AGC (higher radio gain) means lower signal. */ | ||
895 | return max_rssi - agc - IWLAGN_RSSI_OFFSET; | ||
896 | } | ||
897 | |||
898 | /* Called for REPLY_RX (legacy ABG frames), or | ||
899 | * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ | ||
900 | static int iwlagn_rx_reply_rx(struct iwl_priv *priv, | ||
901 | struct iwl_rx_cmd_buffer *rxb, | ||
902 | struct iwl_device_cmd *cmd) | ||
903 | { | ||
904 | struct ieee80211_hdr *header; | ||
905 | struct ieee80211_rx_status rx_status; | ||
906 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
907 | struct iwl_rx_phy_res *phy_res; | ||
908 | __le32 rx_pkt_status; | ||
909 | struct iwl_rx_mpdu_res_start *amsdu; | ||
910 | u32 len; | ||
911 | u32 ampdu_status; | ||
912 | u32 rate_n_flags; | ||
913 | |||
914 | /** | ||
915 | * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently. | ||
916 | * REPLY_RX: physical layer info is in this buffer | ||
917 | * REPLY_RX_MPDU_CMD: physical layer info was sent in separate | ||
918 | * command and cached in priv->last_phy_res | ||
919 | * | ||
920 | * Here we set up local variables depending on which command is | ||
921 | * received. | ||
922 | */ | ||
923 | if (pkt->hdr.cmd == REPLY_RX) { | ||
924 | phy_res = (struct iwl_rx_phy_res *)pkt->data; | ||
925 | header = (struct ieee80211_hdr *)(pkt->data + sizeof(*phy_res) | ||
926 | + phy_res->cfg_phy_cnt); | ||
927 | |||
928 | len = le16_to_cpu(phy_res->byte_count); | ||
929 | rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*phy_res) + | ||
930 | phy_res->cfg_phy_cnt + len); | ||
931 | ampdu_status = le32_to_cpu(rx_pkt_status); | ||
932 | } else { | ||
933 | if (!priv->last_phy_res_valid) { | ||
934 | IWL_ERR(priv, "MPDU frame without cached PHY data\n"); | ||
935 | return 0; | ||
936 | } | ||
937 | phy_res = &priv->last_phy_res; | ||
938 | amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data; | ||
939 | header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu)); | ||
940 | len = le16_to_cpu(amsdu->byte_count); | ||
941 | rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*amsdu) + len); | ||
942 | ampdu_status = iwlagn_translate_rx_status(priv, | ||
943 | le32_to_cpu(rx_pkt_status)); | ||
944 | } | ||
945 | |||
946 | if ((unlikely(phy_res->cfg_phy_cnt > 20))) { | ||
947 | IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d\n", | ||
948 | phy_res->cfg_phy_cnt); | ||
949 | return 0; | ||
950 | } | ||
951 | |||
952 | if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) || | ||
953 | !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) { | ||
954 | IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n", | ||
955 | le32_to_cpu(rx_pkt_status)); | ||
956 | return 0; | ||
957 | } | ||
958 | |||
959 | /* This will be used in several places later */ | ||
960 | rate_n_flags = le32_to_cpu(phy_res->rate_n_flags); | ||
961 | |||
962 | /* rx_status carries information about the packet to mac80211 */ | ||
963 | rx_status.mactime = le64_to_cpu(phy_res->timestamp); | ||
964 | rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? | ||
965 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; | ||
966 | rx_status.freq = | ||
967 | ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel), | ||
968 | rx_status.band); | ||
969 | rx_status.rate_idx = | ||
970 | iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band); | ||
971 | rx_status.flag = 0; | ||
972 | |||
973 | /* TSF isn't reliable. In order to allow smooth user experience, | ||
974 | * this W/A doesn't propagate it to the mac80211 */ | ||
975 | /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/ | ||
976 | |||
977 | priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp); | ||
978 | |||
979 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ | ||
980 | rx_status.signal = iwlagn_calc_rssi(priv, phy_res); | ||
981 | |||
982 | IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n", | ||
983 | rx_status.signal, (unsigned long long)rx_status.mactime); | ||
984 | |||
985 | /* | ||
986 | * "antenna number" | ||
987 | * | ||
988 | * It seems that the antenna field in the phy flags value | ||
989 | * is actually a bit field. This is undefined by radiotap, | ||
990 | * it wants an actual antenna number but I always get "7" | ||
991 | * for most legacy frames I receive indicating that the | ||
992 | * same frame was received on all three RX chains. | ||
993 | * | ||
994 | * I think this field should be removed in favor of a | ||
995 | * new 802.11n radiotap field "RX chains" that is defined | ||
996 | * as a bitmask. | ||
997 | */ | ||
998 | rx_status.antenna = | ||
999 | (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) | ||
1000 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; | ||
1001 | |||
1002 | /* set the preamble flag if appropriate */ | ||
1003 | if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) | ||
1004 | rx_status.flag |= RX_FLAG_SHORTPRE; | ||
1005 | |||
1006 | /* Set up the HT phy flags */ | ||
1007 | if (rate_n_flags & RATE_MCS_HT_MSK) | ||
1008 | rx_status.flag |= RX_FLAG_HT; | ||
1009 | if (rate_n_flags & RATE_MCS_HT40_MSK) | ||
1010 | rx_status.flag |= RX_FLAG_40MHZ; | ||
1011 | if (rate_n_flags & RATE_MCS_SGI_MSK) | ||
1012 | rx_status.flag |= RX_FLAG_SHORT_GI; | ||
1013 | if (rate_n_flags & RATE_MCS_GF_MSK) | ||
1014 | rx_status.flag |= RX_FLAG_HT_GF; | ||
1015 | |||
1016 | iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status, | ||
1017 | rxb, &rx_status); | ||
1018 | return 0; | ||
1019 | } | ||
1020 | |||
1021 | static int iwlagn_rx_noa_notification(struct iwl_priv *priv, | ||
1022 | struct iwl_rx_cmd_buffer *rxb, | ||
1023 | struct iwl_device_cmd *cmd) | ||
1024 | { | ||
1025 | struct iwl_wipan_noa_data *new_data, *old_data; | ||
1026 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
1027 | struct iwl_wipan_noa_notification *noa_notif = (void *)pkt->data; | ||
1028 | |||
1029 | /* no condition -- we're in softirq */ | ||
1030 | old_data = rcu_dereference_protected(priv->noa_data, true); | ||
1031 | |||
1032 | if (noa_notif->noa_active) { | ||
1033 | u32 len = le16_to_cpu(noa_notif->noa_attribute.length); | ||
1034 | u32 copylen = len; | ||
1035 | |||
1036 | /* EID, len, OUI, subtype */ | ||
1037 | len += 1 + 1 + 3 + 1; | ||
1038 | /* P2P id, P2P length */ | ||
1039 | len += 1 + 2; | ||
1040 | copylen += 1 + 2; | ||
1041 | |||
1042 | new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC); | ||
1043 | if (new_data) { | ||
1044 | new_data->length = len; | ||
1045 | new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC; | ||
1046 | new_data->data[1] = len - 2; /* not counting EID, len */ | ||
1047 | new_data->data[2] = (WLAN_OUI_WFA >> 16) & 0xff; | ||
1048 | new_data->data[3] = (WLAN_OUI_WFA >> 8) & 0xff; | ||
1049 | new_data->data[4] = (WLAN_OUI_WFA >> 0) & 0xff; | ||
1050 | new_data->data[5] = WLAN_OUI_TYPE_WFA_P2P; | ||
1051 | memcpy(&new_data->data[6], &noa_notif->noa_attribute, | ||
1052 | copylen); | ||
1053 | } | ||
1054 | } else | ||
1055 | new_data = NULL; | ||
1056 | |||
1057 | rcu_assign_pointer(priv->noa_data, new_data); | ||
1058 | |||
1059 | if (old_data) | ||
1060 | kfree_rcu(old_data, rcu_head); | ||
1061 | |||
1062 | return 0; | ||
1063 | } | ||
1064 | |||
1065 | /** | ||
1066 | * iwl_setup_rx_handlers - Initialize Rx handler callbacks | ||
1067 | * | ||
1068 | * Setup the RX handlers for each of the reply types sent from the uCode | ||
1069 | * to the host. | ||
1070 | */ | ||
1071 | void iwl_setup_rx_handlers(struct iwl_priv *priv) | ||
1072 | { | ||
1073 | int (**handlers)(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, | ||
1074 | struct iwl_device_cmd *cmd); | ||
1075 | |||
1076 | handlers = priv->rx_handlers; | ||
1077 | |||
1078 | handlers[REPLY_ERROR] = iwlagn_rx_reply_error; | ||
1079 | handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa; | ||
1080 | handlers[SPECTRUM_MEASURE_NOTIFICATION] = | ||
1081 | iwlagn_rx_spectrum_measure_notif; | ||
1082 | handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif; | ||
1083 | handlers[PM_DEBUG_STATISTIC_NOTIFIC] = | ||
1084 | iwlagn_rx_pm_debug_statistics_notif; | ||
1085 | handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif; | ||
1086 | handlers[REPLY_ADD_STA] = iwl_add_sta_callback; | ||
1087 | |||
1088 | handlers[REPLY_WIPAN_NOA_NOTIFICATION] = iwlagn_rx_noa_notification; | ||
1089 | |||
1090 | /* | ||
1091 | * The same handler is used for both the REPLY to a discrete | ||
1092 | * statistics request from the host as well as for the periodic | ||
1093 | * statistics notifications (after received beacons) from the uCode. | ||
1094 | */ | ||
1095 | handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics; | ||
1096 | handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics; | ||
1097 | |||
1098 | iwl_setup_rx_scan_handlers(priv); | ||
1099 | |||
1100 | handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif; | ||
1101 | handlers[MISSED_BEACONS_NOTIFICATION] = | ||
1102 | iwlagn_rx_missed_beacon_notif; | ||
1103 | |||
1104 | /* Rx handlers */ | ||
1105 | handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy; | ||
1106 | handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx; | ||
1107 | |||
1108 | /* block ack */ | ||
1109 | handlers[REPLY_COMPRESSED_BA] = | ||
1110 | iwlagn_rx_reply_compressed_ba; | ||
1111 | |||
1112 | priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx; | ||
1113 | |||
1114 | /* set up notification wait support */ | ||
1115 | iwl_notification_wait_init(&priv->notif_wait); | ||
1116 | |||
1117 | /* Set up BT Rx handlers */ | ||
1118 | if (priv->cfg->bt_params) | ||
1119 | iwlagn_bt_rx_handler_setup(priv); | ||
1120 | } | ||
1121 | |||
1122 | int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb, | ||
1123 | struct iwl_device_cmd *cmd) | ||
1124 | { | ||
1125 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
1126 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); | ||
1127 | void (*pre_rx_handler)(struct iwl_priv *, | ||
1128 | struct iwl_rx_cmd_buffer *); | ||
1129 | int err = 0; | ||
1130 | |||
1131 | /* | ||
1132 | * Do the notification wait before RX handlers so | ||
1133 | * even if the RX handler consumes the RXB we have | ||
1134 | * access to it in the notification wait entry. | ||
1135 | */ | ||
1136 | iwl_notification_wait_notify(&priv->notif_wait, pkt); | ||
1137 | |||
1138 | /* RX data may be forwarded to userspace (using pre_rx_handler) in one | ||
1139 | * of two cases: the first, that the user owns the uCode through | ||
1140 | * testmode - in such case the pre_rx_handler is set and no further | ||
1141 | * processing takes place. The other case is when the user want to | ||
1142 | * monitor the rx w/o affecting the regular flow - the pre_rx_handler | ||
1143 | * will be set but the ownership flag != IWL_OWNERSHIP_TM and the flow | ||
1144 | * continues. | ||
1145 | * We need to use ACCESS_ONCE to prevent a case where the handler | ||
1146 | * changes between the check and the call. | ||
1147 | */ | ||
1148 | pre_rx_handler = ACCESS_ONCE(priv->pre_rx_handler); | ||
1149 | if (pre_rx_handler) | ||
1150 | pre_rx_handler(priv, rxb); | ||
1151 | if (priv->ucode_owner != IWL_OWNERSHIP_TM) { | ||
1152 | /* Based on type of command response or notification, | ||
1153 | * handle those that need handling via function in | ||
1154 | * rx_handlers table. See iwl_setup_rx_handlers() */ | ||
1155 | if (priv->rx_handlers[pkt->hdr.cmd]) { | ||
1156 | priv->rx_handlers_stats[pkt->hdr.cmd]++; | ||
1157 | err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd); | ||
1158 | } else { | ||
1159 | /* No handling needed */ | ||
1160 | IWL_DEBUG_RX(priv, "No handler needed for %s, 0x%02x\n", | ||
1161 | iwl_dvm_get_cmd_string(pkt->hdr.cmd), | ||
1162 | pkt->hdr.cmd); | ||
1163 | } | ||
1164 | } | ||
1165 | return err; | ||
1166 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/rxon.c b/drivers/net/wireless/iwlwifi/dvm/rxon.c new file mode 100644 index 000000000000..6ee940f497f9 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/rxon.c | |||
@@ -0,0 +1,1577 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of version 2 of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | |||
27 | #include <linux/etherdevice.h> | ||
28 | #include "iwl-trans.h" | ||
29 | #include "iwl-modparams.h" | ||
30 | #include "dev.h" | ||
31 | #include "agn.h" | ||
32 | #include "calib.h" | ||
33 | |||
34 | /* | ||
35 | * initialize rxon structure with default values from eeprom | ||
36 | */ | ||
37 | void iwl_connection_init_rx_config(struct iwl_priv *priv, | ||
38 | struct iwl_rxon_context *ctx) | ||
39 | { | ||
40 | memset(&ctx->staging, 0, sizeof(ctx->staging)); | ||
41 | |||
42 | if (!ctx->vif) { | ||
43 | ctx->staging.dev_type = ctx->unused_devtype; | ||
44 | } else | ||
45 | switch (ctx->vif->type) { | ||
46 | case NL80211_IFTYPE_AP: | ||
47 | ctx->staging.dev_type = ctx->ap_devtype; | ||
48 | break; | ||
49 | |||
50 | case NL80211_IFTYPE_STATION: | ||
51 | ctx->staging.dev_type = ctx->station_devtype; | ||
52 | ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; | ||
53 | break; | ||
54 | |||
55 | case NL80211_IFTYPE_ADHOC: | ||
56 | ctx->staging.dev_type = ctx->ibss_devtype; | ||
57 | ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK; | ||
58 | ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK | | ||
59 | RXON_FILTER_ACCEPT_GRP_MSK; | ||
60 | break; | ||
61 | |||
62 | case NL80211_IFTYPE_MONITOR: | ||
63 | ctx->staging.dev_type = RXON_DEV_TYPE_SNIFFER; | ||
64 | break; | ||
65 | |||
66 | default: | ||
67 | IWL_ERR(priv, "Unsupported interface type %d\n", | ||
68 | ctx->vif->type); | ||
69 | break; | ||
70 | } | ||
71 | |||
72 | #if 0 | ||
73 | /* TODO: Figure out when short_preamble would be set and cache from | ||
74 | * that */ | ||
75 | if (!hw_to_local(priv->hw)->short_preamble) | ||
76 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | ||
77 | else | ||
78 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; | ||
79 | #endif | ||
80 | |||
81 | ctx->staging.channel = cpu_to_le16(priv->hw->conf.channel->hw_value); | ||
82 | priv->band = priv->hw->conf.channel->band; | ||
83 | |||
84 | iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif); | ||
85 | |||
86 | /* clear both MIX and PURE40 mode flag */ | ||
87 | ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED | | ||
88 | RXON_FLG_CHANNEL_MODE_PURE_40); | ||
89 | if (ctx->vif) | ||
90 | memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN); | ||
91 | |||
92 | ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff; | ||
93 | ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff; | ||
94 | ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff; | ||
95 | } | ||
96 | |||
97 | static int iwlagn_disable_bss(struct iwl_priv *priv, | ||
98 | struct iwl_rxon_context *ctx, | ||
99 | struct iwl_rxon_cmd *send) | ||
100 | { | ||
101 | __le32 old_filter = send->filter_flags; | ||
102 | int ret; | ||
103 | |||
104 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | ||
105 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, | ||
106 | CMD_SYNC, sizeof(*send), send); | ||
107 | |||
108 | send->filter_flags = old_filter; | ||
109 | |||
110 | if (ret) | ||
111 | IWL_DEBUG_QUIET_RFKILL(priv, | ||
112 | "Error clearing ASSOC_MSK on BSS (%d)\n", ret); | ||
113 | |||
114 | return ret; | ||
115 | } | ||
116 | |||
117 | static int iwlagn_disable_pan(struct iwl_priv *priv, | ||
118 | struct iwl_rxon_context *ctx, | ||
119 | struct iwl_rxon_cmd *send) | ||
120 | { | ||
121 | struct iwl_notification_wait disable_wait; | ||
122 | __le32 old_filter = send->filter_flags; | ||
123 | u8 old_dev_type = send->dev_type; | ||
124 | int ret; | ||
125 | static const u8 deactivate_cmd[] = { | ||
126 | REPLY_WIPAN_DEACTIVATION_COMPLETE | ||
127 | }; | ||
128 | |||
129 | iwl_init_notification_wait(&priv->notif_wait, &disable_wait, | ||
130 | deactivate_cmd, ARRAY_SIZE(deactivate_cmd), | ||
131 | NULL, NULL); | ||
132 | |||
133 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | ||
134 | send->dev_type = RXON_DEV_TYPE_P2P; | ||
135 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, | ||
136 | CMD_SYNC, sizeof(*send), send); | ||
137 | |||
138 | send->filter_flags = old_filter; | ||
139 | send->dev_type = old_dev_type; | ||
140 | |||
141 | if (ret) { | ||
142 | IWL_ERR(priv, "Error disabling PAN (%d)\n", ret); | ||
143 | iwl_remove_notification(&priv->notif_wait, &disable_wait); | ||
144 | } else { | ||
145 | ret = iwl_wait_notification(&priv->notif_wait, | ||
146 | &disable_wait, HZ); | ||
147 | if (ret) | ||
148 | IWL_ERR(priv, "Timed out waiting for PAN disable\n"); | ||
149 | } | ||
150 | |||
151 | return ret; | ||
152 | } | ||
153 | |||
154 | static int iwlagn_disconn_pan(struct iwl_priv *priv, | ||
155 | struct iwl_rxon_context *ctx, | ||
156 | struct iwl_rxon_cmd *send) | ||
157 | { | ||
158 | __le32 old_filter = send->filter_flags; | ||
159 | int ret; | ||
160 | |||
161 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | ||
162 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, | ||
163 | sizeof(*send), send); | ||
164 | |||
165 | send->filter_flags = old_filter; | ||
166 | |||
167 | return ret; | ||
168 | } | ||
169 | |||
170 | static void iwlagn_update_qos(struct iwl_priv *priv, | ||
171 | struct iwl_rxon_context *ctx) | ||
172 | { | ||
173 | int ret; | ||
174 | |||
175 | if (!ctx->is_active) | ||
176 | return; | ||
177 | |||
178 | ctx->qos_data.def_qos_parm.qos_flags = 0; | ||
179 | |||
180 | if (ctx->qos_data.qos_active) | ||
181 | ctx->qos_data.def_qos_parm.qos_flags |= | ||
182 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; | ||
183 | |||
184 | if (ctx->ht.enabled) | ||
185 | ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; | ||
186 | |||
187 | IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", | ||
188 | ctx->qos_data.qos_active, | ||
189 | ctx->qos_data.def_qos_parm.qos_flags); | ||
190 | |||
191 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC, | ||
192 | sizeof(struct iwl_qosparam_cmd), | ||
193 | &ctx->qos_data.def_qos_parm); | ||
194 | if (ret) | ||
195 | IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n"); | ||
196 | } | ||
197 | |||
198 | static int iwlagn_update_beacon(struct iwl_priv *priv, | ||
199 | struct ieee80211_vif *vif) | ||
200 | { | ||
201 | lockdep_assert_held(&priv->mutex); | ||
202 | |||
203 | dev_kfree_skb(priv->beacon_skb); | ||
204 | priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif); | ||
205 | if (!priv->beacon_skb) | ||
206 | return -ENOMEM; | ||
207 | return iwlagn_send_beacon_cmd(priv); | ||
208 | } | ||
209 | |||
210 | static int iwlagn_send_rxon_assoc(struct iwl_priv *priv, | ||
211 | struct iwl_rxon_context *ctx) | ||
212 | { | ||
213 | int ret = 0; | ||
214 | struct iwl_rxon_assoc_cmd rxon_assoc; | ||
215 | const struct iwl_rxon_cmd *rxon1 = &ctx->staging; | ||
216 | const struct iwl_rxon_cmd *rxon2 = &ctx->active; | ||
217 | |||
218 | if ((rxon1->flags == rxon2->flags) && | ||
219 | (rxon1->filter_flags == rxon2->filter_flags) && | ||
220 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && | ||
221 | (rxon1->ofdm_ht_single_stream_basic_rates == | ||
222 | rxon2->ofdm_ht_single_stream_basic_rates) && | ||
223 | (rxon1->ofdm_ht_dual_stream_basic_rates == | ||
224 | rxon2->ofdm_ht_dual_stream_basic_rates) && | ||
225 | (rxon1->ofdm_ht_triple_stream_basic_rates == | ||
226 | rxon2->ofdm_ht_triple_stream_basic_rates) && | ||
227 | (rxon1->acquisition_data == rxon2->acquisition_data) && | ||
228 | (rxon1->rx_chain == rxon2->rx_chain) && | ||
229 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { | ||
230 | IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n"); | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | rxon_assoc.flags = ctx->staging.flags; | ||
235 | rxon_assoc.filter_flags = ctx->staging.filter_flags; | ||
236 | rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates; | ||
237 | rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates; | ||
238 | rxon_assoc.reserved1 = 0; | ||
239 | rxon_assoc.reserved2 = 0; | ||
240 | rxon_assoc.reserved3 = 0; | ||
241 | rxon_assoc.ofdm_ht_single_stream_basic_rates = | ||
242 | ctx->staging.ofdm_ht_single_stream_basic_rates; | ||
243 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = | ||
244 | ctx->staging.ofdm_ht_dual_stream_basic_rates; | ||
245 | rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain; | ||
246 | rxon_assoc.ofdm_ht_triple_stream_basic_rates = | ||
247 | ctx->staging.ofdm_ht_triple_stream_basic_rates; | ||
248 | rxon_assoc.acquisition_data = ctx->staging.acquisition_data; | ||
249 | |||
250 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd, | ||
251 | CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc); | ||
252 | return ret; | ||
253 | } | ||
254 | |||
255 | static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val) | ||
256 | { | ||
257 | u16 new_val; | ||
258 | u16 beacon_factor; | ||
259 | |||
260 | /* | ||
261 | * If mac80211 hasn't given us a beacon interval, program | ||
262 | * the default into the device (not checking this here | ||
263 | * would cause the adjustment below to return the maximum | ||
264 | * value, which may break PAN.) | ||
265 | */ | ||
266 | if (!beacon_val) | ||
267 | return DEFAULT_BEACON_INTERVAL; | ||
268 | |||
269 | /* | ||
270 | * If the beacon interval we obtained from the peer | ||
271 | * is too large, we'll have to wake up more often | ||
272 | * (and in IBSS case, we'll beacon too much) | ||
273 | * | ||
274 | * For example, if max_beacon_val is 4096, and the | ||
275 | * requested beacon interval is 7000, we'll have to | ||
276 | * use 3500 to be able to wake up on the beacons. | ||
277 | * | ||
278 | * This could badly influence beacon detection stats. | ||
279 | */ | ||
280 | |||
281 | beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val; | ||
282 | new_val = beacon_val / beacon_factor; | ||
283 | |||
284 | if (!new_val) | ||
285 | new_val = max_beacon_val; | ||
286 | |||
287 | return new_val; | ||
288 | } | ||
289 | |||
290 | static int iwl_send_rxon_timing(struct iwl_priv *priv, | ||
291 | struct iwl_rxon_context *ctx) | ||
292 | { | ||
293 | u64 tsf; | ||
294 | s32 interval_tm, rem; | ||
295 | struct ieee80211_conf *conf = NULL; | ||
296 | u16 beacon_int; | ||
297 | struct ieee80211_vif *vif = ctx->vif; | ||
298 | |||
299 | conf = &priv->hw->conf; | ||
300 | |||
301 | lockdep_assert_held(&priv->mutex); | ||
302 | |||
303 | memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd)); | ||
304 | |||
305 | ctx->timing.timestamp = cpu_to_le64(priv->timestamp); | ||
306 | ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval); | ||
307 | |||
308 | beacon_int = vif ? vif->bss_conf.beacon_int : 0; | ||
309 | |||
310 | /* | ||
311 | * TODO: For IBSS we need to get atim_window from mac80211, | ||
312 | * for now just always use 0 | ||
313 | */ | ||
314 | ctx->timing.atim_window = 0; | ||
315 | |||
316 | if (ctx->ctxid == IWL_RXON_CTX_PAN && | ||
317 | (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) && | ||
318 | iwl_is_associated(priv, IWL_RXON_CTX_BSS) && | ||
319 | priv->contexts[IWL_RXON_CTX_BSS].vif && | ||
320 | priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) { | ||
321 | ctx->timing.beacon_interval = | ||
322 | priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval; | ||
323 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); | ||
324 | } else if (ctx->ctxid == IWL_RXON_CTX_BSS && | ||
325 | iwl_is_associated(priv, IWL_RXON_CTX_PAN) && | ||
326 | priv->contexts[IWL_RXON_CTX_PAN].vif && | ||
327 | priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int && | ||
328 | (!iwl_is_associated_ctx(ctx) || !ctx->vif || | ||
329 | !ctx->vif->bss_conf.beacon_int)) { | ||
330 | ctx->timing.beacon_interval = | ||
331 | priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval; | ||
332 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); | ||
333 | } else { | ||
334 | beacon_int = iwl_adjust_beacon_interval(beacon_int, | ||
335 | IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT); | ||
336 | ctx->timing.beacon_interval = cpu_to_le16(beacon_int); | ||
337 | } | ||
338 | |||
339 | ctx->beacon_int = beacon_int; | ||
340 | |||
341 | tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */ | ||
342 | interval_tm = beacon_int * TIME_UNIT; | ||
343 | rem = do_div(tsf, interval_tm); | ||
344 | ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem); | ||
345 | |||
346 | ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1; | ||
347 | |||
348 | IWL_DEBUG_ASSOC(priv, | ||
349 | "beacon interval %d beacon timer %d beacon tim %d\n", | ||
350 | le16_to_cpu(ctx->timing.beacon_interval), | ||
351 | le32_to_cpu(ctx->timing.beacon_init_val), | ||
352 | le16_to_cpu(ctx->timing.atim_window)); | ||
353 | |||
354 | return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd, | ||
355 | CMD_SYNC, sizeof(ctx->timing), &ctx->timing); | ||
356 | } | ||
357 | |||
358 | static int iwlagn_rxon_disconn(struct iwl_priv *priv, | ||
359 | struct iwl_rxon_context *ctx) | ||
360 | { | ||
361 | int ret; | ||
362 | struct iwl_rxon_cmd *active = (void *)&ctx->active; | ||
363 | |||
364 | if (ctx->ctxid == IWL_RXON_CTX_BSS) { | ||
365 | ret = iwlagn_disable_bss(priv, ctx, &ctx->staging); | ||
366 | } else { | ||
367 | ret = iwlagn_disable_pan(priv, ctx, &ctx->staging); | ||
368 | if (ret) | ||
369 | return ret; | ||
370 | if (ctx->vif) { | ||
371 | ret = iwl_send_rxon_timing(priv, ctx); | ||
372 | if (ret) { | ||
373 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); | ||
374 | return ret; | ||
375 | } | ||
376 | ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging); | ||
377 | } | ||
378 | } | ||
379 | if (ret) | ||
380 | return ret; | ||
381 | |||
382 | /* | ||
383 | * Un-assoc RXON clears the station table and WEP | ||
384 | * keys, so we have to restore those afterwards. | ||
385 | */ | ||
386 | iwl_clear_ucode_stations(priv, ctx); | ||
387 | /* update -- might need P2P now */ | ||
388 | iwl_update_bcast_station(priv, ctx); | ||
389 | iwl_restore_stations(priv, ctx); | ||
390 | ret = iwl_restore_default_wep_keys(priv, ctx); | ||
391 | if (ret) { | ||
392 | IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); | ||
393 | return ret; | ||
394 | } | ||
395 | |||
396 | memcpy(active, &ctx->staging, sizeof(*active)); | ||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) | ||
401 | { | ||
402 | int ret; | ||
403 | s8 prev_tx_power; | ||
404 | bool defer; | ||
405 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
406 | |||
407 | if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED) | ||
408 | return 0; | ||
409 | |||
410 | lockdep_assert_held(&priv->mutex); | ||
411 | |||
412 | if (priv->tx_power_user_lmt == tx_power && !force) | ||
413 | return 0; | ||
414 | |||
415 | if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) { | ||
416 | IWL_WARN(priv, | ||
417 | "Requested user TXPOWER %d below lower limit %d.\n", | ||
418 | tx_power, | ||
419 | IWLAGN_TX_POWER_TARGET_POWER_MIN); | ||
420 | return -EINVAL; | ||
421 | } | ||
422 | |||
423 | if (tx_power > DIV_ROUND_UP(priv->eeprom_data->max_tx_pwr_half_dbm, 2)) { | ||
424 | IWL_WARN(priv, | ||
425 | "Requested user TXPOWER %d above upper limit %d.\n", | ||
426 | tx_power, priv->eeprom_data->max_tx_pwr_half_dbm); | ||
427 | return -EINVAL; | ||
428 | } | ||
429 | |||
430 | if (!iwl_is_ready_rf(priv)) | ||
431 | return -EIO; | ||
432 | |||
433 | /* scan complete and commit_rxon use tx_power_next value, | ||
434 | * it always need to be updated for newest request */ | ||
435 | priv->tx_power_next = tx_power; | ||
436 | |||
437 | /* do not set tx power when scanning or channel changing */ | ||
438 | defer = test_bit(STATUS_SCANNING, &priv->status) || | ||
439 | memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)); | ||
440 | if (defer && !force) { | ||
441 | IWL_DEBUG_INFO(priv, "Deferring tx power set\n"); | ||
442 | return 0; | ||
443 | } | ||
444 | |||
445 | prev_tx_power = priv->tx_power_user_lmt; | ||
446 | priv->tx_power_user_lmt = tx_power; | ||
447 | |||
448 | ret = iwlagn_send_tx_power(priv); | ||
449 | |||
450 | /* if fail to set tx_power, restore the orig. tx power */ | ||
451 | if (ret) { | ||
452 | priv->tx_power_user_lmt = prev_tx_power; | ||
453 | priv->tx_power_next = prev_tx_power; | ||
454 | } | ||
455 | return ret; | ||
456 | } | ||
457 | |||
458 | static int iwlagn_rxon_connect(struct iwl_priv *priv, | ||
459 | struct iwl_rxon_context *ctx) | ||
460 | { | ||
461 | int ret; | ||
462 | struct iwl_rxon_cmd *active = (void *)&ctx->active; | ||
463 | |||
464 | /* RXON timing must be before associated RXON */ | ||
465 | if (ctx->ctxid == IWL_RXON_CTX_BSS) { | ||
466 | ret = iwl_send_rxon_timing(priv, ctx); | ||
467 | if (ret) { | ||
468 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); | ||
469 | return ret; | ||
470 | } | ||
471 | } | ||
472 | /* QoS info may be cleared by previous un-assoc RXON */ | ||
473 | iwlagn_update_qos(priv, ctx); | ||
474 | |||
475 | /* | ||
476 | * We'll run into this code path when beaconing is | ||
477 | * enabled, but then we also need to send the beacon | ||
478 | * to the device. | ||
479 | */ | ||
480 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) { | ||
481 | ret = iwlagn_update_beacon(priv, ctx->vif); | ||
482 | if (ret) { | ||
483 | IWL_ERR(priv, | ||
484 | "Error sending required beacon (%d)!\n", | ||
485 | ret); | ||
486 | return ret; | ||
487 | } | ||
488 | } | ||
489 | |||
490 | priv->start_calib = 0; | ||
491 | /* | ||
492 | * Apply the new configuration. | ||
493 | * | ||
494 | * Associated RXON doesn't clear the station table in uCode, | ||
495 | * so we don't need to restore stations etc. after this. | ||
496 | */ | ||
497 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, | ||
498 | sizeof(struct iwl_rxon_cmd), &ctx->staging); | ||
499 | if (ret) { | ||
500 | IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); | ||
501 | return ret; | ||
502 | } | ||
503 | memcpy(active, &ctx->staging, sizeof(*active)); | ||
504 | |||
505 | /* IBSS beacon needs to be sent after setting assoc */ | ||
506 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC)) | ||
507 | if (iwlagn_update_beacon(priv, ctx->vif)) | ||
508 | IWL_ERR(priv, "Error sending IBSS beacon\n"); | ||
509 | iwl_init_sensitivity(priv); | ||
510 | |||
511 | /* | ||
512 | * If we issue a new RXON command which required a tune then | ||
513 | * we must send a new TXPOWER command or we won't be able to | ||
514 | * Tx any frames. | ||
515 | * | ||
516 | * It's expected we set power here if channel is changing. | ||
517 | */ | ||
518 | ret = iwl_set_tx_power(priv, priv->tx_power_next, true); | ||
519 | if (ret) { | ||
520 | IWL_ERR(priv, "Error sending TX power (%d)\n", ret); | ||
521 | return ret; | ||
522 | } | ||
523 | |||
524 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION && | ||
525 | priv->cfg->ht_params && priv->cfg->ht_params->smps_mode) | ||
526 | ieee80211_request_smps(ctx->vif, | ||
527 | priv->cfg->ht_params->smps_mode); | ||
528 | |||
529 | return 0; | ||
530 | } | ||
531 | |||
532 | int iwlagn_set_pan_params(struct iwl_priv *priv) | ||
533 | { | ||
534 | struct iwl_wipan_params_cmd cmd; | ||
535 | struct iwl_rxon_context *ctx_bss, *ctx_pan; | ||
536 | int slot0 = 300, slot1 = 0; | ||
537 | int ret; | ||
538 | |||
539 | if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS)) | ||
540 | return 0; | ||
541 | |||
542 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | ||
543 | |||
544 | lockdep_assert_held(&priv->mutex); | ||
545 | |||
546 | ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
547 | ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN]; | ||
548 | |||
549 | /* | ||
550 | * If the PAN context is inactive, then we don't need | ||
551 | * to update the PAN parameters, the last thing we'll | ||
552 | * have done before it goes inactive is making the PAN | ||
553 | * parameters be WLAN-only. | ||
554 | */ | ||
555 | if (!ctx_pan->is_active) | ||
556 | return 0; | ||
557 | |||
558 | memset(&cmd, 0, sizeof(cmd)); | ||
559 | |||
560 | /* only 2 slots are currently allowed */ | ||
561 | cmd.num_slots = 2; | ||
562 | |||
563 | cmd.slots[0].type = 0; /* BSS */ | ||
564 | cmd.slots[1].type = 1; /* PAN */ | ||
565 | |||
566 | if (priv->hw_roc_setup) { | ||
567 | /* both contexts must be used for this to happen */ | ||
568 | slot1 = IWL_MIN_SLOT_TIME; | ||
569 | slot0 = 3000; | ||
570 | } else if (ctx_bss->vif && ctx_pan->vif) { | ||
571 | int bcnint = ctx_pan->beacon_int; | ||
572 | int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1; | ||
573 | |||
574 | /* should be set, but seems unused?? */ | ||
575 | cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE); | ||
576 | |||
577 | if (ctx_pan->vif->type == NL80211_IFTYPE_AP && | ||
578 | bcnint && | ||
579 | bcnint != ctx_bss->beacon_int) { | ||
580 | IWL_ERR(priv, | ||
581 | "beacon intervals don't match (%d, %d)\n", | ||
582 | ctx_bss->beacon_int, ctx_pan->beacon_int); | ||
583 | } else | ||
584 | bcnint = max_t(int, bcnint, | ||
585 | ctx_bss->beacon_int); | ||
586 | if (!bcnint) | ||
587 | bcnint = DEFAULT_BEACON_INTERVAL; | ||
588 | slot0 = bcnint / 2; | ||
589 | slot1 = bcnint - slot0; | ||
590 | |||
591 | if (test_bit(STATUS_SCAN_HW, &priv->status) || | ||
592 | (!ctx_bss->vif->bss_conf.idle && | ||
593 | !ctx_bss->vif->bss_conf.assoc)) { | ||
594 | slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; | ||
595 | slot1 = IWL_MIN_SLOT_TIME; | ||
596 | } else if (!ctx_pan->vif->bss_conf.idle && | ||
597 | !ctx_pan->vif->bss_conf.assoc) { | ||
598 | slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; | ||
599 | slot0 = IWL_MIN_SLOT_TIME; | ||
600 | } | ||
601 | } else if (ctx_pan->vif) { | ||
602 | slot0 = 0; | ||
603 | slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) * | ||
604 | ctx_pan->beacon_int; | ||
605 | slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1); | ||
606 | |||
607 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { | ||
608 | slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME; | ||
609 | slot1 = IWL_MIN_SLOT_TIME; | ||
610 | } | ||
611 | } | ||
612 | |||
613 | cmd.slots[0].width = cpu_to_le16(slot0); | ||
614 | cmd.slots[1].width = cpu_to_le16(slot1); | ||
615 | |||
616 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC, | ||
617 | sizeof(cmd), &cmd); | ||
618 | if (ret) | ||
619 | IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret); | ||
620 | |||
621 | return ret; | ||
622 | } | ||
623 | |||
624 | static void _iwl_set_rxon_ht(struct iwl_priv *priv, | ||
625 | struct iwl_ht_config *ht_conf, | ||
626 | struct iwl_rxon_context *ctx) | ||
627 | { | ||
628 | struct iwl_rxon_cmd *rxon = &ctx->staging; | ||
629 | |||
630 | if (!ctx->ht.enabled) { | ||
631 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | | ||
632 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | | ||
633 | RXON_FLG_HT40_PROT_MSK | | ||
634 | RXON_FLG_HT_PROT_MSK); | ||
635 | return; | ||
636 | } | ||
637 | |||
638 | /* FIXME: if the definition of ht.protection changed, the "translation" | ||
639 | * will be needed for rxon->flags | ||
640 | */ | ||
641 | rxon->flags |= cpu_to_le32(ctx->ht.protection << | ||
642 | RXON_FLG_HT_OPERATING_MODE_POS); | ||
643 | |||
644 | /* Set up channel bandwidth: | ||
645 | * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */ | ||
646 | /* clear the HT channel mode before set the mode */ | ||
647 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | | ||
648 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); | ||
649 | if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) { | ||
650 | /* pure ht40 */ | ||
651 | if (ctx->ht.protection == | ||
652 | IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) { | ||
653 | rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40; | ||
654 | /* | ||
655 | * Note: control channel is opposite of extension | ||
656 | * channel | ||
657 | */ | ||
658 | switch (ctx->ht.extension_chan_offset) { | ||
659 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | ||
660 | rxon->flags &= | ||
661 | ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; | ||
662 | break; | ||
663 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | ||
664 | rxon->flags |= | ||
665 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; | ||
666 | break; | ||
667 | } | ||
668 | } else { | ||
669 | /* | ||
670 | * Note: control channel is opposite of extension | ||
671 | * channel | ||
672 | */ | ||
673 | switch (ctx->ht.extension_chan_offset) { | ||
674 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | ||
675 | rxon->flags &= | ||
676 | ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); | ||
677 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; | ||
678 | break; | ||
679 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | ||
680 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; | ||
681 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; | ||
682 | break; | ||
683 | case IEEE80211_HT_PARAM_CHA_SEC_NONE: | ||
684 | default: | ||
685 | /* | ||
686 | * channel location only valid if in Mixed | ||
687 | * mode | ||
688 | */ | ||
689 | IWL_ERR(priv, | ||
690 | "invalid extension channel offset\n"); | ||
691 | break; | ||
692 | } | ||
693 | } | ||
694 | } else { | ||
695 | rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY; | ||
696 | } | ||
697 | |||
698 | iwlagn_set_rxon_chain(priv, ctx); | ||
699 | |||
700 | IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X " | ||
701 | "extension channel offset 0x%x\n", | ||
702 | le32_to_cpu(rxon->flags), ctx->ht.protection, | ||
703 | ctx->ht.extension_chan_offset); | ||
704 | } | ||
705 | |||
706 | void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf) | ||
707 | { | ||
708 | struct iwl_rxon_context *ctx; | ||
709 | |||
710 | for_each_context(priv, ctx) | ||
711 | _iwl_set_rxon_ht(priv, ht_conf, ctx); | ||
712 | } | ||
713 | |||
714 | /** | ||
715 | * iwl_set_rxon_channel - Set the band and channel values in staging RXON | ||
716 | * @ch: requested channel as a pointer to struct ieee80211_channel | ||
717 | |||
718 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields | ||
719 | * in the staging RXON flag structure based on the ch->band | ||
720 | */ | ||
721 | void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch, | ||
722 | struct iwl_rxon_context *ctx) | ||
723 | { | ||
724 | enum ieee80211_band band = ch->band; | ||
725 | u16 channel = ch->hw_value; | ||
726 | |||
727 | if ((le16_to_cpu(ctx->staging.channel) == channel) && | ||
728 | (priv->band == band)) | ||
729 | return; | ||
730 | |||
731 | ctx->staging.channel = cpu_to_le16(channel); | ||
732 | if (band == IEEE80211_BAND_5GHZ) | ||
733 | ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK; | ||
734 | else | ||
735 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; | ||
736 | |||
737 | priv->band = band; | ||
738 | |||
739 | IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band); | ||
740 | |||
741 | } | ||
742 | |||
743 | void iwl_set_flags_for_band(struct iwl_priv *priv, | ||
744 | struct iwl_rxon_context *ctx, | ||
745 | enum ieee80211_band band, | ||
746 | struct ieee80211_vif *vif) | ||
747 | { | ||
748 | if (band == IEEE80211_BAND_5GHZ) { | ||
749 | ctx->staging.flags &= | ||
750 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK | ||
751 | | RXON_FLG_CCK_MSK); | ||
752 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; | ||
753 | } else { | ||
754 | /* Copied from iwl_post_associate() */ | ||
755 | if (vif && vif->bss_conf.use_short_slot) | ||
756 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; | ||
757 | else | ||
758 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | ||
759 | |||
760 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; | ||
761 | ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK; | ||
762 | ctx->staging.flags &= ~RXON_FLG_CCK_MSK; | ||
763 | } | ||
764 | } | ||
765 | |||
766 | static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, | ||
767 | struct iwl_rxon_context *ctx, int hw_decrypt) | ||
768 | { | ||
769 | struct iwl_rxon_cmd *rxon = &ctx->staging; | ||
770 | |||
771 | if (hw_decrypt) | ||
772 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; | ||
773 | else | ||
774 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; | ||
775 | |||
776 | } | ||
777 | |||
778 | /* validate RXON structure is valid */ | ||
779 | static int iwl_check_rxon_cmd(struct iwl_priv *priv, | ||
780 | struct iwl_rxon_context *ctx) | ||
781 | { | ||
782 | struct iwl_rxon_cmd *rxon = &ctx->staging; | ||
783 | u32 errors = 0; | ||
784 | |||
785 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { | ||
786 | if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) { | ||
787 | IWL_WARN(priv, "check 2.4G: wrong narrow\n"); | ||
788 | errors |= BIT(0); | ||
789 | } | ||
790 | if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) { | ||
791 | IWL_WARN(priv, "check 2.4G: wrong radar\n"); | ||
792 | errors |= BIT(1); | ||
793 | } | ||
794 | } else { | ||
795 | if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) { | ||
796 | IWL_WARN(priv, "check 5.2G: not short slot!\n"); | ||
797 | errors |= BIT(2); | ||
798 | } | ||
799 | if (rxon->flags & RXON_FLG_CCK_MSK) { | ||
800 | IWL_WARN(priv, "check 5.2G: CCK!\n"); | ||
801 | errors |= BIT(3); | ||
802 | } | ||
803 | } | ||
804 | if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) { | ||
805 | IWL_WARN(priv, "mac/bssid mcast!\n"); | ||
806 | errors |= BIT(4); | ||
807 | } | ||
808 | |||
809 | /* make sure basic rates 6Mbps and 1Mbps are supported */ | ||
810 | if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 && | ||
811 | (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) { | ||
812 | IWL_WARN(priv, "neither 1 nor 6 are basic\n"); | ||
813 | errors |= BIT(5); | ||
814 | } | ||
815 | |||
816 | if (le16_to_cpu(rxon->assoc_id) > 2007) { | ||
817 | IWL_WARN(priv, "aid > 2007\n"); | ||
818 | errors |= BIT(6); | ||
819 | } | ||
820 | |||
821 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) | ||
822 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) { | ||
823 | IWL_WARN(priv, "CCK and short slot\n"); | ||
824 | errors |= BIT(7); | ||
825 | } | ||
826 | |||
827 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) | ||
828 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) { | ||
829 | IWL_WARN(priv, "CCK and auto detect"); | ||
830 | errors |= BIT(8); | ||
831 | } | ||
832 | |||
833 | if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | | ||
834 | RXON_FLG_TGG_PROTECT_MSK)) == | ||
835 | RXON_FLG_TGG_PROTECT_MSK) { | ||
836 | IWL_WARN(priv, "TGg but no auto-detect\n"); | ||
837 | errors |= BIT(9); | ||
838 | } | ||
839 | |||
840 | if (rxon->channel == 0) { | ||
841 | IWL_WARN(priv, "zero channel is invalid\n"); | ||
842 | errors |= BIT(10); | ||
843 | } | ||
844 | |||
845 | WARN(errors, "Invalid RXON (%#x), channel %d", | ||
846 | errors, le16_to_cpu(rxon->channel)); | ||
847 | |||
848 | return errors ? -EINVAL : 0; | ||
849 | } | ||
850 | |||
851 | /** | ||
852 | * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed | ||
853 | * @priv: staging_rxon is compared to active_rxon | ||
854 | * | ||
855 | * If the RXON structure is changing enough to require a new tune, | ||
856 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that | ||
857 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. | ||
858 | */ | ||
859 | static int iwl_full_rxon_required(struct iwl_priv *priv, | ||
860 | struct iwl_rxon_context *ctx) | ||
861 | { | ||
862 | const struct iwl_rxon_cmd *staging = &ctx->staging; | ||
863 | const struct iwl_rxon_cmd *active = &ctx->active; | ||
864 | |||
865 | #define CHK(cond) \ | ||
866 | if ((cond)) { \ | ||
867 | IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \ | ||
868 | return 1; \ | ||
869 | } | ||
870 | |||
871 | #define CHK_NEQ(c1, c2) \ | ||
872 | if ((c1) != (c2)) { \ | ||
873 | IWL_DEBUG_INFO(priv, "need full RXON - " \ | ||
874 | #c1 " != " #c2 " - %d != %d\n", \ | ||
875 | (c1), (c2)); \ | ||
876 | return 1; \ | ||
877 | } | ||
878 | |||
879 | /* These items are only settable from the full RXON command */ | ||
880 | CHK(!iwl_is_associated_ctx(ctx)); | ||
881 | CHK(!ether_addr_equal(staging->bssid_addr, active->bssid_addr)); | ||
882 | CHK(!ether_addr_equal(staging->node_addr, active->node_addr)); | ||
883 | CHK(!ether_addr_equal(staging->wlap_bssid_addr, | ||
884 | active->wlap_bssid_addr)); | ||
885 | CHK_NEQ(staging->dev_type, active->dev_type); | ||
886 | CHK_NEQ(staging->channel, active->channel); | ||
887 | CHK_NEQ(staging->air_propagation, active->air_propagation); | ||
888 | CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates, | ||
889 | active->ofdm_ht_single_stream_basic_rates); | ||
890 | CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates, | ||
891 | active->ofdm_ht_dual_stream_basic_rates); | ||
892 | CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates, | ||
893 | active->ofdm_ht_triple_stream_basic_rates); | ||
894 | CHK_NEQ(staging->assoc_id, active->assoc_id); | ||
895 | |||
896 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can | ||
897 | * be updated with the RXON_ASSOC command -- however only some | ||
898 | * flag transitions are allowed using RXON_ASSOC */ | ||
899 | |||
900 | /* Check if we are not switching bands */ | ||
901 | CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK, | ||
902 | active->flags & RXON_FLG_BAND_24G_MSK); | ||
903 | |||
904 | /* Check if we are switching association toggle */ | ||
905 | CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK, | ||
906 | active->filter_flags & RXON_FILTER_ASSOC_MSK); | ||
907 | |||
908 | #undef CHK | ||
909 | #undef CHK_NEQ | ||
910 | |||
911 | return 0; | ||
912 | } | ||
913 | |||
914 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
915 | void iwl_print_rx_config_cmd(struct iwl_priv *priv, | ||
916 | enum iwl_rxon_context_id ctxid) | ||
917 | { | ||
918 | struct iwl_rxon_context *ctx = &priv->contexts[ctxid]; | ||
919 | struct iwl_rxon_cmd *rxon = &ctx->staging; | ||
920 | |||
921 | IWL_DEBUG_RADIO(priv, "RX CONFIG:\n"); | ||
922 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); | ||
923 | IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", | ||
924 | le16_to_cpu(rxon->channel)); | ||
925 | IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", | ||
926 | le32_to_cpu(rxon->flags)); | ||
927 | IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n", | ||
928 | le32_to_cpu(rxon->filter_flags)); | ||
929 | IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type); | ||
930 | IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n", | ||
931 | rxon->ofdm_basic_rates); | ||
932 | IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", | ||
933 | rxon->cck_basic_rates); | ||
934 | IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr); | ||
935 | IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr); | ||
936 | IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", | ||
937 | le16_to_cpu(rxon->assoc_id)); | ||
938 | } | ||
939 | #endif | ||
940 | |||
941 | static void iwl_calc_basic_rates(struct iwl_priv *priv, | ||
942 | struct iwl_rxon_context *ctx) | ||
943 | { | ||
944 | int lowest_present_ofdm = 100; | ||
945 | int lowest_present_cck = 100; | ||
946 | u8 cck = 0; | ||
947 | u8 ofdm = 0; | ||
948 | |||
949 | if (ctx->vif) { | ||
950 | struct ieee80211_supported_band *sband; | ||
951 | unsigned long basic = ctx->vif->bss_conf.basic_rates; | ||
952 | int i; | ||
953 | |||
954 | sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band]; | ||
955 | |||
956 | for_each_set_bit(i, &basic, BITS_PER_LONG) { | ||
957 | int hw = sband->bitrates[i].hw_value; | ||
958 | if (hw >= IWL_FIRST_OFDM_RATE) { | ||
959 | ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE); | ||
960 | if (lowest_present_ofdm > hw) | ||
961 | lowest_present_ofdm = hw; | ||
962 | } else { | ||
963 | BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0); | ||
964 | |||
965 | cck |= BIT(hw); | ||
966 | if (lowest_present_cck > hw) | ||
967 | lowest_present_cck = hw; | ||
968 | } | ||
969 | } | ||
970 | } | ||
971 | |||
972 | /* | ||
973 | * Now we've got the basic rates as bitmaps in the ofdm and cck | ||
974 | * variables. This isn't sufficient though, as there might not | ||
975 | * be all the right rates in the bitmap. E.g. if the only basic | ||
976 | * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps | ||
977 | * and 6 Mbps because the 802.11-2007 standard says in 9.6: | ||
978 | * | ||
979 | * [...] a STA responding to a received frame shall transmit | ||
980 | * its Control Response frame [...] at the highest rate in the | ||
981 | * BSSBasicRateSet parameter that is less than or equal to the | ||
982 | * rate of the immediately previous frame in the frame exchange | ||
983 | * sequence ([...]) and that is of the same modulation class | ||
984 | * ([...]) as the received frame. If no rate contained in the | ||
985 | * BSSBasicRateSet parameter meets these conditions, then the | ||
986 | * control frame sent in response to a received frame shall be | ||
987 | * transmitted at the highest mandatory rate of the PHY that is | ||
988 | * less than or equal to the rate of the received frame, and | ||
989 | * that is of the same modulation class as the received frame. | ||
990 | * | ||
991 | * As a consequence, we need to add all mandatory rates that are | ||
992 | * lower than all of the basic rates to these bitmaps. | ||
993 | */ | ||
994 | |||
995 | if (IWL_RATE_24M_INDEX < lowest_present_ofdm) | ||
996 | ofdm |= IWL_RATE_24M_MASK >> IWL_FIRST_OFDM_RATE; | ||
997 | if (IWL_RATE_12M_INDEX < lowest_present_ofdm) | ||
998 | ofdm |= IWL_RATE_12M_MASK >> IWL_FIRST_OFDM_RATE; | ||
999 | /* 6M already there or needed so always add */ | ||
1000 | ofdm |= IWL_RATE_6M_MASK >> IWL_FIRST_OFDM_RATE; | ||
1001 | |||
1002 | /* | ||
1003 | * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP. | ||
1004 | * Note, however: | ||
1005 | * - if no CCK rates are basic, it must be ERP since there must | ||
1006 | * be some basic rates at all, so they're OFDM => ERP PHY | ||
1007 | * (or we're in 5 GHz, and the cck bitmap will never be used) | ||
1008 | * - if 11M is a basic rate, it must be ERP as well, so add 5.5M | ||
1009 | * - if 5.5M is basic, 1M and 2M are mandatory | ||
1010 | * - if 2M is basic, 1M is mandatory | ||
1011 | * - if 1M is basic, that's the only valid ACK rate. | ||
1012 | * As a consequence, it's not as complicated as it sounds, just add | ||
1013 | * any lower rates to the ACK rate bitmap. | ||
1014 | */ | ||
1015 | if (IWL_RATE_11M_INDEX < lowest_present_ofdm) | ||
1016 | ofdm |= IWL_RATE_11M_MASK >> IWL_FIRST_CCK_RATE; | ||
1017 | if (IWL_RATE_5M_INDEX < lowest_present_ofdm) | ||
1018 | ofdm |= IWL_RATE_5M_MASK >> IWL_FIRST_CCK_RATE; | ||
1019 | if (IWL_RATE_2M_INDEX < lowest_present_ofdm) | ||
1020 | ofdm |= IWL_RATE_2M_MASK >> IWL_FIRST_CCK_RATE; | ||
1021 | /* 1M already there or needed so always add */ | ||
1022 | cck |= IWL_RATE_1M_MASK >> IWL_FIRST_CCK_RATE; | ||
1023 | |||
1024 | IWL_DEBUG_RATE(priv, "Set basic rates cck:0x%.2x ofdm:0x%.2x\n", | ||
1025 | cck, ofdm); | ||
1026 | |||
1027 | /* "basic_rates" is a misnomer here -- should be called ACK rates */ | ||
1028 | ctx->staging.cck_basic_rates = cck; | ||
1029 | ctx->staging.ofdm_basic_rates = ofdm; | ||
1030 | } | ||
1031 | |||
1032 | /** | ||
1033 | * iwlagn_commit_rxon - commit staging_rxon to hardware | ||
1034 | * | ||
1035 | * The RXON command in staging_rxon is committed to the hardware and | ||
1036 | * the active_rxon structure is updated with the new data. This | ||
1037 | * function correctly transitions out of the RXON_ASSOC_MSK state if | ||
1038 | * a HW tune is required based on the RXON structure changes. | ||
1039 | * | ||
1040 | * The connect/disconnect flow should be as the following: | ||
1041 | * | ||
1042 | * 1. make sure send RXON command with association bit unset if not connect | ||
1043 | * this should include the channel and the band for the candidate | ||
1044 | * to be connected to | ||
1045 | * 2. Add Station before RXON association with the AP | ||
1046 | * 3. RXON_timing has to send before RXON for connection | ||
1047 | * 4. full RXON command - associated bit set | ||
1048 | * 5. use RXON_ASSOC command to update any flags changes | ||
1049 | */ | ||
1050 | int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
1051 | { | ||
1052 | /* cast away the const for active_rxon in this function */ | ||
1053 | struct iwl_rxon_cmd *active = (void *)&ctx->active; | ||
1054 | bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); | ||
1055 | int ret; | ||
1056 | |||
1057 | lockdep_assert_held(&priv->mutex); | ||
1058 | |||
1059 | if (!iwl_is_alive(priv)) | ||
1060 | return -EBUSY; | ||
1061 | |||
1062 | /* This function hardcodes a bunch of dual-mode assumptions */ | ||
1063 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | ||
1064 | |||
1065 | if (!ctx->is_active) | ||
1066 | return 0; | ||
1067 | |||
1068 | /* always get timestamp with Rx frame */ | ||
1069 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; | ||
1070 | |||
1071 | /* recalculate basic rates */ | ||
1072 | iwl_calc_basic_rates(priv, ctx); | ||
1073 | |||
1074 | /* | ||
1075 | * force CTS-to-self frames protection if RTS-CTS is not preferred | ||
1076 | * one aggregation protection method | ||
1077 | */ | ||
1078 | if (!priv->hw_params.use_rts_for_aggregation) | ||
1079 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; | ||
1080 | |||
1081 | if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) || | ||
1082 | !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK)) | ||
1083 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; | ||
1084 | else | ||
1085 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | ||
1086 | |||
1087 | iwl_print_rx_config_cmd(priv, ctx->ctxid); | ||
1088 | ret = iwl_check_rxon_cmd(priv, ctx); | ||
1089 | if (ret) { | ||
1090 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); | ||
1091 | return -EINVAL; | ||
1092 | } | ||
1093 | |||
1094 | /* | ||
1095 | * receive commit_rxon request | ||
1096 | * abort any previous channel switch if still in process | ||
1097 | */ | ||
1098 | if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) && | ||
1099 | (priv->switch_channel != ctx->staging.channel)) { | ||
1100 | IWL_DEBUG_11H(priv, "abort channel switch on %d\n", | ||
1101 | le16_to_cpu(priv->switch_channel)); | ||
1102 | iwl_chswitch_done(priv, false); | ||
1103 | } | ||
1104 | |||
1105 | /* | ||
1106 | * If we don't need to send a full RXON, we can use | ||
1107 | * iwl_rxon_assoc_cmd which is used to reconfigure filter | ||
1108 | * and other flags for the current radio configuration. | ||
1109 | */ | ||
1110 | if (!iwl_full_rxon_required(priv, ctx)) { | ||
1111 | ret = iwlagn_send_rxon_assoc(priv, ctx); | ||
1112 | if (ret) { | ||
1113 | IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret); | ||
1114 | return ret; | ||
1115 | } | ||
1116 | |||
1117 | memcpy(active, &ctx->staging, sizeof(*active)); | ||
1118 | /* | ||
1119 | * We do not commit tx power settings while channel changing, | ||
1120 | * do it now if after settings changed. | ||
1121 | */ | ||
1122 | iwl_set_tx_power(priv, priv->tx_power_next, false); | ||
1123 | |||
1124 | /* make sure we are in the right PS state */ | ||
1125 | iwl_power_update_mode(priv, true); | ||
1126 | |||
1127 | return 0; | ||
1128 | } | ||
1129 | |||
1130 | iwl_set_rxon_hwcrypto(priv, ctx, !iwlwifi_mod_params.sw_crypto); | ||
1131 | |||
1132 | IWL_DEBUG_INFO(priv, | ||
1133 | "Going to commit RXON\n" | ||
1134 | " * with%s RXON_FILTER_ASSOC_MSK\n" | ||
1135 | " * channel = %d\n" | ||
1136 | " * bssid = %pM\n", | ||
1137 | (new_assoc ? "" : "out"), | ||
1138 | le16_to_cpu(ctx->staging.channel), | ||
1139 | ctx->staging.bssid_addr); | ||
1140 | |||
1141 | /* | ||
1142 | * Always clear associated first, but with the correct config. | ||
1143 | * This is required as for example station addition for the | ||
1144 | * AP station must be done after the BSSID is set to correctly | ||
1145 | * set up filters in the device. | ||
1146 | */ | ||
1147 | ret = iwlagn_rxon_disconn(priv, ctx); | ||
1148 | if (ret) | ||
1149 | return ret; | ||
1150 | |||
1151 | ret = iwlagn_set_pan_params(priv); | ||
1152 | if (ret) | ||
1153 | return ret; | ||
1154 | |||
1155 | if (new_assoc) | ||
1156 | return iwlagn_rxon_connect(priv, ctx); | ||
1157 | |||
1158 | return 0; | ||
1159 | } | ||
1160 | |||
1161 | void iwlagn_config_ht40(struct ieee80211_conf *conf, | ||
1162 | struct iwl_rxon_context *ctx) | ||
1163 | { | ||
1164 | if (conf_is_ht40_minus(conf)) { | ||
1165 | ctx->ht.extension_chan_offset = | ||
1166 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; | ||
1167 | ctx->ht.is_40mhz = true; | ||
1168 | } else if (conf_is_ht40_plus(conf)) { | ||
1169 | ctx->ht.extension_chan_offset = | ||
1170 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | ||
1171 | ctx->ht.is_40mhz = true; | ||
1172 | } else { | ||
1173 | ctx->ht.extension_chan_offset = | ||
1174 | IEEE80211_HT_PARAM_CHA_SEC_NONE; | ||
1175 | ctx->ht.is_40mhz = false; | ||
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed) | ||
1180 | { | ||
1181 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1182 | struct iwl_rxon_context *ctx; | ||
1183 | struct ieee80211_conf *conf = &hw->conf; | ||
1184 | struct ieee80211_channel *channel = conf->channel; | ||
1185 | int ret = 0; | ||
1186 | |||
1187 | IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed); | ||
1188 | |||
1189 | mutex_lock(&priv->mutex); | ||
1190 | |||
1191 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { | ||
1192 | IWL_DEBUG_MAC80211(priv, "leave - scanning\n"); | ||
1193 | goto out; | ||
1194 | } | ||
1195 | |||
1196 | if (!iwl_is_ready(priv)) { | ||
1197 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); | ||
1198 | goto out; | ||
1199 | } | ||
1200 | |||
1201 | if (changed & (IEEE80211_CONF_CHANGE_SMPS | | ||
1202 | IEEE80211_CONF_CHANGE_CHANNEL)) { | ||
1203 | /* mac80211 uses static for non-HT which is what we want */ | ||
1204 | priv->current_ht_config.smps = conf->smps_mode; | ||
1205 | |||
1206 | /* | ||
1207 | * Recalculate chain counts. | ||
1208 | * | ||
1209 | * If monitor mode is enabled then mac80211 will | ||
1210 | * set up the SM PS mode to OFF if an HT channel is | ||
1211 | * configured. | ||
1212 | */ | ||
1213 | for_each_context(priv, ctx) | ||
1214 | iwlagn_set_rxon_chain(priv, ctx); | ||
1215 | } | ||
1216 | |||
1217 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { | ||
1218 | for_each_context(priv, ctx) { | ||
1219 | /* Configure HT40 channels */ | ||
1220 | if (ctx->ht.enabled != conf_is_ht(conf)) | ||
1221 | ctx->ht.enabled = conf_is_ht(conf); | ||
1222 | |||
1223 | if (ctx->ht.enabled) { | ||
1224 | /* if HT40 is used, it should not change | ||
1225 | * after associated except channel switch */ | ||
1226 | if (!ctx->ht.is_40mhz || | ||
1227 | !iwl_is_associated_ctx(ctx)) | ||
1228 | iwlagn_config_ht40(conf, ctx); | ||
1229 | } else | ||
1230 | ctx->ht.is_40mhz = false; | ||
1231 | |||
1232 | /* | ||
1233 | * Default to no protection. Protection mode will | ||
1234 | * later be set from BSS config in iwl_ht_conf | ||
1235 | */ | ||
1236 | ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE; | ||
1237 | |||
1238 | /* if we are switching from ht to 2.4 clear flags | ||
1239 | * from any ht related info since 2.4 does not | ||
1240 | * support ht */ | ||
1241 | if (le16_to_cpu(ctx->staging.channel) != | ||
1242 | channel->hw_value) | ||
1243 | ctx->staging.flags = 0; | ||
1244 | |||
1245 | iwl_set_rxon_channel(priv, channel, ctx); | ||
1246 | iwl_set_rxon_ht(priv, &priv->current_ht_config); | ||
1247 | |||
1248 | iwl_set_flags_for_band(priv, ctx, channel->band, | ||
1249 | ctx->vif); | ||
1250 | } | ||
1251 | |||
1252 | iwl_update_bcast_stations(priv); | ||
1253 | } | ||
1254 | |||
1255 | if (changed & (IEEE80211_CONF_CHANGE_PS | | ||
1256 | IEEE80211_CONF_CHANGE_IDLE)) { | ||
1257 | ret = iwl_power_update_mode(priv, false); | ||
1258 | if (ret) | ||
1259 | IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n"); | ||
1260 | } | ||
1261 | |||
1262 | if (changed & IEEE80211_CONF_CHANGE_POWER) { | ||
1263 | IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n", | ||
1264 | priv->tx_power_user_lmt, conf->power_level); | ||
1265 | |||
1266 | iwl_set_tx_power(priv, conf->power_level, false); | ||
1267 | } | ||
1268 | |||
1269 | for_each_context(priv, ctx) { | ||
1270 | if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) | ||
1271 | continue; | ||
1272 | iwlagn_commit_rxon(priv, ctx); | ||
1273 | } | ||
1274 | out: | ||
1275 | mutex_unlock(&priv->mutex); | ||
1276 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
1277 | |||
1278 | return ret; | ||
1279 | } | ||
1280 | |||
1281 | static void iwlagn_check_needed_chains(struct iwl_priv *priv, | ||
1282 | struct iwl_rxon_context *ctx, | ||
1283 | struct ieee80211_bss_conf *bss_conf) | ||
1284 | { | ||
1285 | struct ieee80211_vif *vif = ctx->vif; | ||
1286 | struct iwl_rxon_context *tmp; | ||
1287 | struct ieee80211_sta *sta; | ||
1288 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; | ||
1289 | struct ieee80211_sta_ht_cap *ht_cap; | ||
1290 | bool need_multiple; | ||
1291 | |||
1292 | lockdep_assert_held(&priv->mutex); | ||
1293 | |||
1294 | switch (vif->type) { | ||
1295 | case NL80211_IFTYPE_STATION: | ||
1296 | rcu_read_lock(); | ||
1297 | sta = ieee80211_find_sta(vif, bss_conf->bssid); | ||
1298 | if (!sta) { | ||
1299 | /* | ||
1300 | * If at all, this can only happen through a race | ||
1301 | * when the AP disconnects us while we're still | ||
1302 | * setting up the connection, in that case mac80211 | ||
1303 | * will soon tell us about that. | ||
1304 | */ | ||
1305 | need_multiple = false; | ||
1306 | rcu_read_unlock(); | ||
1307 | break; | ||
1308 | } | ||
1309 | |||
1310 | ht_cap = &sta->ht_cap; | ||
1311 | |||
1312 | need_multiple = true; | ||
1313 | |||
1314 | /* | ||
1315 | * If the peer advertises no support for receiving 2 and 3 | ||
1316 | * stream MCS rates, it can't be transmitting them either. | ||
1317 | */ | ||
1318 | if (ht_cap->mcs.rx_mask[1] == 0 && | ||
1319 | ht_cap->mcs.rx_mask[2] == 0) { | ||
1320 | need_multiple = false; | ||
1321 | } else if (!(ht_cap->mcs.tx_params & | ||
1322 | IEEE80211_HT_MCS_TX_DEFINED)) { | ||
1323 | /* If it can't TX MCS at all ... */ | ||
1324 | need_multiple = false; | ||
1325 | } else if (ht_cap->mcs.tx_params & | ||
1326 | IEEE80211_HT_MCS_TX_RX_DIFF) { | ||
1327 | int maxstreams; | ||
1328 | |||
1329 | /* | ||
1330 | * But if it can receive them, it might still not | ||
1331 | * be able to transmit them, which is what we need | ||
1332 | * to check here -- so check the number of streams | ||
1333 | * it advertises for TX (if different from RX). | ||
1334 | */ | ||
1335 | |||
1336 | maxstreams = (ht_cap->mcs.tx_params & | ||
1337 | IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK); | ||
1338 | maxstreams >>= | ||
1339 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; | ||
1340 | maxstreams += 1; | ||
1341 | |||
1342 | if (maxstreams <= 1) | ||
1343 | need_multiple = false; | ||
1344 | } | ||
1345 | |||
1346 | rcu_read_unlock(); | ||
1347 | break; | ||
1348 | case NL80211_IFTYPE_ADHOC: | ||
1349 | /* currently */ | ||
1350 | need_multiple = false; | ||
1351 | break; | ||
1352 | default: | ||
1353 | /* only AP really */ | ||
1354 | need_multiple = true; | ||
1355 | break; | ||
1356 | } | ||
1357 | |||
1358 | ctx->ht_need_multiple_chains = need_multiple; | ||
1359 | |||
1360 | if (!need_multiple) { | ||
1361 | /* check all contexts */ | ||
1362 | for_each_context(priv, tmp) { | ||
1363 | if (!tmp->vif) | ||
1364 | continue; | ||
1365 | if (tmp->ht_need_multiple_chains) { | ||
1366 | need_multiple = true; | ||
1367 | break; | ||
1368 | } | ||
1369 | } | ||
1370 | } | ||
1371 | |||
1372 | ht_conf->single_chain_sufficient = !need_multiple; | ||
1373 | } | ||
1374 | |||
1375 | static void iwlagn_chain_noise_reset(struct iwl_priv *priv) | ||
1376 | { | ||
1377 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; | ||
1378 | int ret; | ||
1379 | |||
1380 | if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED)) | ||
1381 | return; | ||
1382 | |||
1383 | if ((data->state == IWL_CHAIN_NOISE_ALIVE) && | ||
1384 | iwl_is_any_associated(priv)) { | ||
1385 | struct iwl_calib_chain_noise_reset_cmd cmd; | ||
1386 | |||
1387 | /* clear data for chain noise calibration algorithm */ | ||
1388 | data->chain_noise_a = 0; | ||
1389 | data->chain_noise_b = 0; | ||
1390 | data->chain_noise_c = 0; | ||
1391 | data->chain_signal_a = 0; | ||
1392 | data->chain_signal_b = 0; | ||
1393 | data->chain_signal_c = 0; | ||
1394 | data->beacon_count = 0; | ||
1395 | |||
1396 | memset(&cmd, 0, sizeof(cmd)); | ||
1397 | iwl_set_calib_hdr(&cmd.hdr, | ||
1398 | priv->phy_calib_chain_noise_reset_cmd); | ||
1399 | ret = iwl_dvm_send_cmd_pdu(priv, | ||
1400 | REPLY_PHY_CALIBRATION_CMD, | ||
1401 | CMD_SYNC, sizeof(cmd), &cmd); | ||
1402 | if (ret) | ||
1403 | IWL_ERR(priv, | ||
1404 | "Could not send REPLY_PHY_CALIBRATION_CMD\n"); | ||
1405 | data->state = IWL_CHAIN_NOISE_ACCUMULATE; | ||
1406 | IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n"); | ||
1407 | } | ||
1408 | } | ||
1409 | |||
1410 | void iwlagn_bss_info_changed(struct ieee80211_hw *hw, | ||
1411 | struct ieee80211_vif *vif, | ||
1412 | struct ieee80211_bss_conf *bss_conf, | ||
1413 | u32 changes) | ||
1414 | { | ||
1415 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1416 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | ||
1417 | int ret; | ||
1418 | bool force = false; | ||
1419 | |||
1420 | mutex_lock(&priv->mutex); | ||
1421 | |||
1422 | if (unlikely(!iwl_is_ready(priv))) { | ||
1423 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); | ||
1424 | mutex_unlock(&priv->mutex); | ||
1425 | return; | ||
1426 | } | ||
1427 | |||
1428 | if (unlikely(!ctx->vif)) { | ||
1429 | IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n"); | ||
1430 | mutex_unlock(&priv->mutex); | ||
1431 | return; | ||
1432 | } | ||
1433 | |||
1434 | if (changes & BSS_CHANGED_BEACON_INT) | ||
1435 | force = true; | ||
1436 | |||
1437 | if (changes & BSS_CHANGED_QOS) { | ||
1438 | ctx->qos_data.qos_active = bss_conf->qos; | ||
1439 | iwlagn_update_qos(priv, ctx); | ||
1440 | } | ||
1441 | |||
1442 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); | ||
1443 | if (vif->bss_conf.use_short_preamble) | ||
1444 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; | ||
1445 | else | ||
1446 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | ||
1447 | |||
1448 | if (changes & BSS_CHANGED_ASSOC) { | ||
1449 | if (bss_conf->assoc) { | ||
1450 | priv->timestamp = bss_conf->last_tsf; | ||
1451 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; | ||
1452 | } else { | ||
1453 | /* | ||
1454 | * If we disassociate while there are pending | ||
1455 | * frames, just wake up the queues and let the | ||
1456 | * frames "escape" ... This shouldn't really | ||
1457 | * be happening to start with, but we should | ||
1458 | * not get stuck in this case either since it | ||
1459 | * can happen if userspace gets confused. | ||
1460 | */ | ||
1461 | iwlagn_lift_passive_no_rx(priv); | ||
1462 | |||
1463 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | ||
1464 | |||
1465 | if (ctx->ctxid == IWL_RXON_CTX_BSS) | ||
1466 | priv->have_rekey_data = false; | ||
1467 | } | ||
1468 | |||
1469 | iwlagn_bt_coex_rssi_monitor(priv); | ||
1470 | } | ||
1471 | |||
1472 | if (ctx->ht.enabled) { | ||
1473 | ctx->ht.protection = bss_conf->ht_operation_mode & | ||
1474 | IEEE80211_HT_OP_MODE_PROTECTION; | ||
1475 | ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode & | ||
1476 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); | ||
1477 | iwlagn_check_needed_chains(priv, ctx, bss_conf); | ||
1478 | iwl_set_rxon_ht(priv, &priv->current_ht_config); | ||
1479 | } | ||
1480 | |||
1481 | iwlagn_set_rxon_chain(priv, ctx); | ||
1482 | |||
1483 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) | ||
1484 | ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK; | ||
1485 | else | ||
1486 | ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK; | ||
1487 | |||
1488 | if (bss_conf->use_cts_prot) | ||
1489 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; | ||
1490 | else | ||
1491 | ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN; | ||
1492 | |||
1493 | memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN); | ||
1494 | |||
1495 | if (vif->type == NL80211_IFTYPE_AP || | ||
1496 | vif->type == NL80211_IFTYPE_ADHOC) { | ||
1497 | if (vif->bss_conf.enable_beacon) { | ||
1498 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; | ||
1499 | priv->beacon_ctx = ctx; | ||
1500 | } else { | ||
1501 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | ||
1502 | priv->beacon_ctx = NULL; | ||
1503 | } | ||
1504 | } | ||
1505 | |||
1506 | /* | ||
1507 | * If the ucode decides to do beacon filtering before | ||
1508 | * association, it will lose beacons that are needed | ||
1509 | * before sending frames out on passive channels. This | ||
1510 | * causes association failures on those channels. Enable | ||
1511 | * receiving beacons in such cases. | ||
1512 | */ | ||
1513 | |||
1514 | if (vif->type == NL80211_IFTYPE_STATION) { | ||
1515 | if (!bss_conf->assoc) | ||
1516 | ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK; | ||
1517 | else | ||
1518 | ctx->staging.filter_flags &= | ||
1519 | ~RXON_FILTER_BCON_AWARE_MSK; | ||
1520 | } | ||
1521 | |||
1522 | if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) | ||
1523 | iwlagn_commit_rxon(priv, ctx); | ||
1524 | |||
1525 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { | ||
1526 | /* | ||
1527 | * The chain noise calibration will enable PM upon | ||
1528 | * completion. If calibration has already been run | ||
1529 | * then we need to enable power management here. | ||
1530 | */ | ||
1531 | if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE) | ||
1532 | iwl_power_update_mode(priv, false); | ||
1533 | |||
1534 | /* Enable RX differential gain and sensitivity calibrations */ | ||
1535 | iwlagn_chain_noise_reset(priv); | ||
1536 | priv->start_calib = 1; | ||
1537 | } | ||
1538 | |||
1539 | if (changes & BSS_CHANGED_IBSS) { | ||
1540 | ret = iwlagn_manage_ibss_station(priv, vif, | ||
1541 | bss_conf->ibss_joined); | ||
1542 | if (ret) | ||
1543 | IWL_ERR(priv, "failed to %s IBSS station %pM\n", | ||
1544 | bss_conf->ibss_joined ? "add" : "remove", | ||
1545 | bss_conf->bssid); | ||
1546 | } | ||
1547 | |||
1548 | if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC && | ||
1549 | priv->beacon_ctx) { | ||
1550 | if (iwlagn_update_beacon(priv, vif)) | ||
1551 | IWL_ERR(priv, "Error sending IBSS beacon\n"); | ||
1552 | } | ||
1553 | |||
1554 | mutex_unlock(&priv->mutex); | ||
1555 | } | ||
1556 | |||
1557 | void iwlagn_post_scan(struct iwl_priv *priv) | ||
1558 | { | ||
1559 | struct iwl_rxon_context *ctx; | ||
1560 | |||
1561 | /* | ||
1562 | * We do not commit power settings while scan is pending, | ||
1563 | * do it now if the settings changed. | ||
1564 | */ | ||
1565 | iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false); | ||
1566 | iwl_set_tx_power(priv, priv->tx_power_next, false); | ||
1567 | |||
1568 | /* | ||
1569 | * Since setting the RXON may have been deferred while | ||
1570 | * performing the scan, fire one off if needed | ||
1571 | */ | ||
1572 | for_each_context(priv, ctx) | ||
1573 | if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) | ||
1574 | iwlagn_commit_rxon(priv, ctx); | ||
1575 | |||
1576 | iwlagn_set_pan_params(priv); | ||
1577 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/scan.c b/drivers/net/wireless/iwlwifi/dvm/scan.c new file mode 100644 index 000000000000..2f271c96ed39 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/scan.c | |||
@@ -0,0 +1,1167 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * GPL LICENSE SUMMARY | ||
4 | * | ||
5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of version 2 of the GNU General Public License as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
19 | * USA | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called LICENSE.GPL. | ||
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/slab.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/etherdevice.h> | ||
31 | #include <net/mac80211.h> | ||
32 | |||
33 | #include "dev.h" | ||
34 | #include "agn.h" | ||
35 | |||
36 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after | ||
37 | * sending probe req. This should be set long enough to hear probe responses | ||
38 | * from more than one AP. */ | ||
39 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ | ||
40 | #define IWL_ACTIVE_DWELL_TIME_52 (20) | ||
41 | |||
42 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) | ||
43 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) | ||
44 | |||
45 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. | ||
46 | * Must be set longer than active dwell time. | ||
47 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ | ||
48 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ | ||
49 | #define IWL_PASSIVE_DWELL_TIME_52 (10) | ||
50 | #define IWL_PASSIVE_DWELL_BASE (100) | ||
51 | #define IWL_CHANNEL_TUNE_TIME 5 | ||
52 | #define MAX_SCAN_CHANNEL 50 | ||
53 | |||
54 | static int iwl_send_scan_abort(struct iwl_priv *priv) | ||
55 | { | ||
56 | int ret; | ||
57 | struct iwl_host_cmd cmd = { | ||
58 | .id = REPLY_SCAN_ABORT_CMD, | ||
59 | .flags = CMD_SYNC | CMD_WANT_SKB, | ||
60 | }; | ||
61 | __le32 *status; | ||
62 | |||
63 | /* Exit instantly with error when device is not ready | ||
64 | * to receive scan abort command or it does not perform | ||
65 | * hardware scan currently */ | ||
66 | if (!test_bit(STATUS_READY, &priv->status) || | ||
67 | !test_bit(STATUS_SCAN_HW, &priv->status) || | ||
68 | test_bit(STATUS_FW_ERROR, &priv->status)) | ||
69 | return -EIO; | ||
70 | |||
71 | ret = iwl_dvm_send_cmd(priv, &cmd); | ||
72 | if (ret) | ||
73 | return ret; | ||
74 | |||
75 | status = (void *)cmd.resp_pkt->data; | ||
76 | if (*status != CAN_ABORT_STATUS) { | ||
77 | /* The scan abort will return 1 for success or | ||
78 | * 2 for "failure". A failure condition can be | ||
79 | * due to simply not being in an active scan which | ||
80 | * can occur if we send the scan abort before we | ||
81 | * the microcode has notified us that a scan is | ||
82 | * completed. */ | ||
83 | IWL_DEBUG_SCAN(priv, "SCAN_ABORT ret %d.\n", | ||
84 | le32_to_cpu(*status)); | ||
85 | ret = -EIO; | ||
86 | } | ||
87 | |||
88 | iwl_free_resp(&cmd); | ||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | static void iwl_complete_scan(struct iwl_priv *priv, bool aborted) | ||
93 | { | ||
94 | /* check if scan was requested from mac80211 */ | ||
95 | if (priv->scan_request) { | ||
96 | IWL_DEBUG_SCAN(priv, "Complete scan in mac80211\n"); | ||
97 | ieee80211_scan_completed(priv->hw, aborted); | ||
98 | } | ||
99 | |||
100 | if (priv->scan_type == IWL_SCAN_ROC) | ||
101 | iwl_scan_roc_expired(priv); | ||
102 | |||
103 | priv->scan_type = IWL_SCAN_NORMAL; | ||
104 | priv->scan_vif = NULL; | ||
105 | priv->scan_request = NULL; | ||
106 | } | ||
107 | |||
108 | static void iwl_process_scan_complete(struct iwl_priv *priv) | ||
109 | { | ||
110 | bool aborted; | ||
111 | |||
112 | lockdep_assert_held(&priv->mutex); | ||
113 | |||
114 | if (!test_and_clear_bit(STATUS_SCAN_COMPLETE, &priv->status)) | ||
115 | return; | ||
116 | |||
117 | IWL_DEBUG_SCAN(priv, "Completed scan.\n"); | ||
118 | |||
119 | cancel_delayed_work(&priv->scan_check); | ||
120 | |||
121 | aborted = test_and_clear_bit(STATUS_SCAN_ABORTING, &priv->status); | ||
122 | if (aborted) | ||
123 | IWL_DEBUG_SCAN(priv, "Aborted scan completed.\n"); | ||
124 | |||
125 | if (!test_and_clear_bit(STATUS_SCANNING, &priv->status)) { | ||
126 | IWL_DEBUG_SCAN(priv, "Scan already completed.\n"); | ||
127 | goto out_settings; | ||
128 | } | ||
129 | |||
130 | if (priv->scan_type == IWL_SCAN_ROC) | ||
131 | iwl_scan_roc_expired(priv); | ||
132 | |||
133 | if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) { | ||
134 | int err; | ||
135 | |||
136 | /* Check if mac80211 requested scan during our internal scan */ | ||
137 | if (priv->scan_request == NULL) | ||
138 | goto out_complete; | ||
139 | |||
140 | /* If so request a new scan */ | ||
141 | err = iwl_scan_initiate(priv, priv->scan_vif, IWL_SCAN_NORMAL, | ||
142 | priv->scan_request->channels[0]->band); | ||
143 | if (err) { | ||
144 | IWL_DEBUG_SCAN(priv, | ||
145 | "failed to initiate pending scan: %d\n", err); | ||
146 | aborted = true; | ||
147 | goto out_complete; | ||
148 | } | ||
149 | |||
150 | return; | ||
151 | } | ||
152 | |||
153 | out_complete: | ||
154 | iwl_complete_scan(priv, aborted); | ||
155 | |||
156 | out_settings: | ||
157 | /* Can we still talk to firmware ? */ | ||
158 | if (!iwl_is_ready_rf(priv)) | ||
159 | return; | ||
160 | |||
161 | iwlagn_post_scan(priv); | ||
162 | } | ||
163 | |||
164 | void iwl_force_scan_end(struct iwl_priv *priv) | ||
165 | { | ||
166 | lockdep_assert_held(&priv->mutex); | ||
167 | |||
168 | if (!test_bit(STATUS_SCANNING, &priv->status)) { | ||
169 | IWL_DEBUG_SCAN(priv, "Forcing scan end while not scanning\n"); | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | IWL_DEBUG_SCAN(priv, "Forcing scan end\n"); | ||
174 | clear_bit(STATUS_SCANNING, &priv->status); | ||
175 | clear_bit(STATUS_SCAN_HW, &priv->status); | ||
176 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); | ||
177 | clear_bit(STATUS_SCAN_COMPLETE, &priv->status); | ||
178 | iwl_complete_scan(priv, true); | ||
179 | } | ||
180 | |||
181 | static void iwl_do_scan_abort(struct iwl_priv *priv) | ||
182 | { | ||
183 | int ret; | ||
184 | |||
185 | lockdep_assert_held(&priv->mutex); | ||
186 | |||
187 | if (!test_bit(STATUS_SCANNING, &priv->status)) { | ||
188 | IWL_DEBUG_SCAN(priv, "Not performing scan to abort\n"); | ||
189 | return; | ||
190 | } | ||
191 | |||
192 | if (test_and_set_bit(STATUS_SCAN_ABORTING, &priv->status)) { | ||
193 | IWL_DEBUG_SCAN(priv, "Scan abort in progress\n"); | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | ret = iwl_send_scan_abort(priv); | ||
198 | if (ret) { | ||
199 | IWL_DEBUG_SCAN(priv, "Send scan abort failed %d\n", ret); | ||
200 | iwl_force_scan_end(priv); | ||
201 | } else | ||
202 | IWL_DEBUG_SCAN(priv, "Successfully send scan abort\n"); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * iwl_scan_cancel - Cancel any currently executing HW scan | ||
207 | */ | ||
208 | int iwl_scan_cancel(struct iwl_priv *priv) | ||
209 | { | ||
210 | IWL_DEBUG_SCAN(priv, "Queuing abort scan\n"); | ||
211 | queue_work(priv->workqueue, &priv->abort_scan); | ||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * iwl_scan_cancel_timeout - Cancel any currently executing HW scan | ||
217 | * @ms: amount of time to wait (in milliseconds) for scan to abort | ||
218 | * | ||
219 | */ | ||
220 | void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) | ||
221 | { | ||
222 | unsigned long timeout = jiffies + msecs_to_jiffies(ms); | ||
223 | |||
224 | lockdep_assert_held(&priv->mutex); | ||
225 | |||
226 | IWL_DEBUG_SCAN(priv, "Scan cancel timeout\n"); | ||
227 | |||
228 | iwl_do_scan_abort(priv); | ||
229 | |||
230 | while (time_before_eq(jiffies, timeout)) { | ||
231 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) | ||
232 | goto finished; | ||
233 | msleep(20); | ||
234 | } | ||
235 | |||
236 | return; | ||
237 | |||
238 | finished: | ||
239 | /* | ||
240 | * Now STATUS_SCAN_HW is clear. This means that the | ||
241 | * device finished, but the background work is going | ||
242 | * to execute at best as soon as we release the mutex. | ||
243 | * Since we need to be able to issue a new scan right | ||
244 | * after this function returns, run the complete here. | ||
245 | * The STATUS_SCAN_COMPLETE bit will then be cleared | ||
246 | * and prevent the background work from "completing" | ||
247 | * a possible new scan. | ||
248 | */ | ||
249 | iwl_process_scan_complete(priv); | ||
250 | } | ||
251 | |||
252 | /* Service response to REPLY_SCAN_CMD (0x80) */ | ||
253 | static int iwl_rx_reply_scan(struct iwl_priv *priv, | ||
254 | struct iwl_rx_cmd_buffer *rxb, | ||
255 | struct iwl_device_cmd *cmd) | ||
256 | { | ||
257 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
258 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
259 | struct iwl_scanreq_notification *notif = (void *)pkt->data; | ||
260 | |||
261 | IWL_DEBUG_SCAN(priv, "Scan request status = 0x%x\n", notif->status); | ||
262 | #endif | ||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | /* Service SCAN_START_NOTIFICATION (0x82) */ | ||
267 | static int iwl_rx_scan_start_notif(struct iwl_priv *priv, | ||
268 | struct iwl_rx_cmd_buffer *rxb, | ||
269 | struct iwl_device_cmd *cmd) | ||
270 | { | ||
271 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
272 | struct iwl_scanstart_notification *notif = (void *)pkt->data; | ||
273 | |||
274 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); | ||
275 | IWL_DEBUG_SCAN(priv, "Scan start: " | ||
276 | "%d [802.11%s] " | ||
277 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", | ||
278 | notif->channel, | ||
279 | notif->band ? "bg" : "a", | ||
280 | le32_to_cpu(notif->tsf_high), | ||
281 | le32_to_cpu(notif->tsf_low), | ||
282 | notif->status, notif->beacon_timer); | ||
283 | |||
284 | if (priv->scan_type == IWL_SCAN_ROC && | ||
285 | !priv->hw_roc_start_notified) { | ||
286 | ieee80211_ready_on_channel(priv->hw); | ||
287 | priv->hw_roc_start_notified = true; | ||
288 | } | ||
289 | |||
290 | return 0; | ||
291 | } | ||
292 | |||
293 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ | ||
294 | static int iwl_rx_scan_results_notif(struct iwl_priv *priv, | ||
295 | struct iwl_rx_cmd_buffer *rxb, | ||
296 | struct iwl_device_cmd *cmd) | ||
297 | { | ||
298 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
299 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
300 | struct iwl_scanresults_notification *notif = (void *)pkt->data; | ||
301 | |||
302 | IWL_DEBUG_SCAN(priv, "Scan ch.res: " | ||
303 | "%d [802.11%s] " | ||
304 | "probe status: %u:%u " | ||
305 | "(TSF: 0x%08X:%08X) - %d " | ||
306 | "elapsed=%lu usec\n", | ||
307 | notif->channel, | ||
308 | notif->band ? "bg" : "a", | ||
309 | notif->probe_status, notif->num_probe_not_sent, | ||
310 | le32_to_cpu(notif->tsf_high), | ||
311 | le32_to_cpu(notif->tsf_low), | ||
312 | le32_to_cpu(notif->statistics[0]), | ||
313 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf); | ||
314 | #endif | ||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ | ||
319 | static int iwl_rx_scan_complete_notif(struct iwl_priv *priv, | ||
320 | struct iwl_rx_cmd_buffer *rxb, | ||
321 | struct iwl_device_cmd *cmd) | ||
322 | { | ||
323 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
324 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->data; | ||
325 | |||
326 | IWL_DEBUG_SCAN(priv, "Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", | ||
327 | scan_notif->scanned_channels, | ||
328 | scan_notif->tsf_low, | ||
329 | scan_notif->tsf_high, scan_notif->status); | ||
330 | |||
331 | IWL_DEBUG_SCAN(priv, "Scan on %sGHz took %dms\n", | ||
332 | (priv->scan_band == IEEE80211_BAND_2GHZ) ? "2.4" : "5.2", | ||
333 | jiffies_to_msecs(jiffies - priv->scan_start)); | ||
334 | |||
335 | /* | ||
336 | * When aborting, we run the scan completed background work inline | ||
337 | * and the background work must then do nothing. The SCAN_COMPLETE | ||
338 | * bit helps implement that logic and thus needs to be set before | ||
339 | * queueing the work. Also, since the scan abort waits for SCAN_HW | ||
340 | * to clear, we need to set SCAN_COMPLETE before clearing SCAN_HW | ||
341 | * to avoid a race there. | ||
342 | */ | ||
343 | set_bit(STATUS_SCAN_COMPLETE, &priv->status); | ||
344 | clear_bit(STATUS_SCAN_HW, &priv->status); | ||
345 | queue_work(priv->workqueue, &priv->scan_completed); | ||
346 | |||
347 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC && | ||
348 | iwl_advanced_bt_coexist(priv) && | ||
349 | priv->bt_status != scan_notif->bt_status) { | ||
350 | if (scan_notif->bt_status) { | ||
351 | /* BT on */ | ||
352 | if (!priv->bt_ch_announce) | ||
353 | priv->bt_traffic_load = | ||
354 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH; | ||
355 | /* | ||
356 | * otherwise, no traffic load information provided | ||
357 | * no changes made | ||
358 | */ | ||
359 | } else { | ||
360 | /* BT off */ | ||
361 | priv->bt_traffic_load = | ||
362 | IWL_BT_COEX_TRAFFIC_LOAD_NONE; | ||
363 | } | ||
364 | priv->bt_status = scan_notif->bt_status; | ||
365 | queue_work(priv->workqueue, | ||
366 | &priv->bt_traffic_change_work); | ||
367 | } | ||
368 | return 0; | ||
369 | } | ||
370 | |||
371 | void iwl_setup_rx_scan_handlers(struct iwl_priv *priv) | ||
372 | { | ||
373 | /* scan handlers */ | ||
374 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan; | ||
375 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif; | ||
376 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = | ||
377 | iwl_rx_scan_results_notif; | ||
378 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = | ||
379 | iwl_rx_scan_complete_notif; | ||
380 | } | ||
381 | |||
382 | static u16 iwl_get_active_dwell_time(struct iwl_priv *priv, | ||
383 | enum ieee80211_band band, u8 n_probes) | ||
384 | { | ||
385 | if (band == IEEE80211_BAND_5GHZ) | ||
386 | return IWL_ACTIVE_DWELL_TIME_52 + | ||
387 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); | ||
388 | else | ||
389 | return IWL_ACTIVE_DWELL_TIME_24 + | ||
390 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); | ||
391 | } | ||
392 | |||
393 | static u16 iwl_limit_dwell(struct iwl_priv *priv, u16 dwell_time) | ||
394 | { | ||
395 | struct iwl_rxon_context *ctx; | ||
396 | |||
397 | /* | ||
398 | * If we're associated, we clamp the dwell time 98% | ||
399 | * of the smallest beacon interval (minus 2 * channel | ||
400 | * tune time) | ||
401 | */ | ||
402 | for_each_context(priv, ctx) { | ||
403 | u16 value; | ||
404 | |||
405 | switch (ctx->staging.dev_type) { | ||
406 | case RXON_DEV_TYPE_P2P: | ||
407 | /* no timing constraints */ | ||
408 | continue; | ||
409 | case RXON_DEV_TYPE_ESS: | ||
410 | default: | ||
411 | /* timing constraints if associated */ | ||
412 | if (!iwl_is_associated_ctx(ctx)) | ||
413 | continue; | ||
414 | break; | ||
415 | case RXON_DEV_TYPE_CP: | ||
416 | case RXON_DEV_TYPE_2STA: | ||
417 | /* | ||
418 | * These seem to always have timers for TBTT | ||
419 | * active in uCode even when not associated yet. | ||
420 | */ | ||
421 | break; | ||
422 | } | ||
423 | |||
424 | value = ctx->beacon_int; | ||
425 | if (!value) | ||
426 | value = IWL_PASSIVE_DWELL_BASE; | ||
427 | value = (value * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; | ||
428 | dwell_time = min(value, dwell_time); | ||
429 | } | ||
430 | |||
431 | return dwell_time; | ||
432 | } | ||
433 | |||
434 | static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, | ||
435 | enum ieee80211_band band) | ||
436 | { | ||
437 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? | ||
438 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : | ||
439 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; | ||
440 | |||
441 | return iwl_limit_dwell(priv, passive); | ||
442 | } | ||
443 | |||
444 | /* Return valid, unused, channel for a passive scan to reset the RF */ | ||
445 | static u8 iwl_get_single_channel_number(struct iwl_priv *priv, | ||
446 | enum ieee80211_band band) | ||
447 | { | ||
448 | struct ieee80211_supported_band *sband = priv->hw->wiphy->bands[band]; | ||
449 | struct iwl_rxon_context *ctx; | ||
450 | int i; | ||
451 | |||
452 | for (i = 0; i < sband->n_channels; i++) { | ||
453 | bool busy = false; | ||
454 | |||
455 | for_each_context(priv, ctx) { | ||
456 | busy = sband->channels[i].hw_value == | ||
457 | le16_to_cpu(ctx->staging.channel); | ||
458 | if (busy) | ||
459 | break; | ||
460 | } | ||
461 | |||
462 | if (busy) | ||
463 | continue; | ||
464 | |||
465 | if (!(sband->channels[i].flags & IEEE80211_CHAN_DISABLED)) | ||
466 | return sband->channels[i].hw_value; | ||
467 | } | ||
468 | |||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | static int iwl_get_single_channel_for_scan(struct iwl_priv *priv, | ||
473 | struct ieee80211_vif *vif, | ||
474 | enum ieee80211_band band, | ||
475 | struct iwl_scan_channel *scan_ch) | ||
476 | { | ||
477 | const struct ieee80211_supported_band *sband; | ||
478 | u16 passive_dwell = 0; | ||
479 | u16 active_dwell = 0; | ||
480 | int added = 0; | ||
481 | u16 channel = 0; | ||
482 | |||
483 | sband = iwl_get_hw_mode(priv, band); | ||
484 | if (!sband) { | ||
485 | IWL_ERR(priv, "invalid band\n"); | ||
486 | return added; | ||
487 | } | ||
488 | |||
489 | active_dwell = iwl_get_active_dwell_time(priv, band, 0); | ||
490 | passive_dwell = iwl_get_passive_dwell_time(priv, band); | ||
491 | |||
492 | if (passive_dwell <= active_dwell) | ||
493 | passive_dwell = active_dwell + 1; | ||
494 | |||
495 | channel = iwl_get_single_channel_number(priv, band); | ||
496 | if (channel) { | ||
497 | scan_ch->channel = cpu_to_le16(channel); | ||
498 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; | ||
499 | scan_ch->active_dwell = cpu_to_le16(active_dwell); | ||
500 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); | ||
501 | /* Set txpower levels to defaults */ | ||
502 | scan_ch->dsp_atten = 110; | ||
503 | if (band == IEEE80211_BAND_5GHZ) | ||
504 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; | ||
505 | else | ||
506 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); | ||
507 | added++; | ||
508 | } else | ||
509 | IWL_ERR(priv, "no valid channel found\n"); | ||
510 | return added; | ||
511 | } | ||
512 | |||
513 | static int iwl_get_channels_for_scan(struct iwl_priv *priv, | ||
514 | struct ieee80211_vif *vif, | ||
515 | enum ieee80211_band band, | ||
516 | u8 is_active, u8 n_probes, | ||
517 | struct iwl_scan_channel *scan_ch) | ||
518 | { | ||
519 | struct ieee80211_channel *chan; | ||
520 | const struct ieee80211_supported_band *sband; | ||
521 | u16 passive_dwell = 0; | ||
522 | u16 active_dwell = 0; | ||
523 | int added, i; | ||
524 | u16 channel; | ||
525 | |||
526 | sband = iwl_get_hw_mode(priv, band); | ||
527 | if (!sband) | ||
528 | return 0; | ||
529 | |||
530 | active_dwell = iwl_get_active_dwell_time(priv, band, n_probes); | ||
531 | passive_dwell = iwl_get_passive_dwell_time(priv, band); | ||
532 | |||
533 | if (passive_dwell <= active_dwell) | ||
534 | passive_dwell = active_dwell + 1; | ||
535 | |||
536 | for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) { | ||
537 | chan = priv->scan_request->channels[i]; | ||
538 | |||
539 | if (chan->band != band) | ||
540 | continue; | ||
541 | |||
542 | channel = chan->hw_value; | ||
543 | scan_ch->channel = cpu_to_le16(channel); | ||
544 | |||
545 | if (!is_active || (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) | ||
546 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; | ||
547 | else | ||
548 | scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE; | ||
549 | |||
550 | if (n_probes) | ||
551 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); | ||
552 | |||
553 | scan_ch->active_dwell = cpu_to_le16(active_dwell); | ||
554 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); | ||
555 | |||
556 | /* Set txpower levels to defaults */ | ||
557 | scan_ch->dsp_atten = 110; | ||
558 | |||
559 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use | ||
560 | * power level: | ||
561 | * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3; | ||
562 | */ | ||
563 | if (band == IEEE80211_BAND_5GHZ) | ||
564 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; | ||
565 | else | ||
566 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); | ||
567 | |||
568 | IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n", | ||
569 | channel, le32_to_cpu(scan_ch->type), | ||
570 | (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ? | ||
571 | "ACTIVE" : "PASSIVE", | ||
572 | (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ? | ||
573 | active_dwell : passive_dwell); | ||
574 | |||
575 | scan_ch++; | ||
576 | added++; | ||
577 | } | ||
578 | |||
579 | IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added); | ||
580 | return added; | ||
581 | } | ||
582 | |||
583 | /** | ||
584 | * iwl_fill_probe_req - fill in all required fields and IE for probe request | ||
585 | */ | ||
586 | |||
587 | static u16 iwl_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta, | ||
588 | const u8 *ies, int ie_len, const u8 *ssid, | ||
589 | u8 ssid_len, int left) | ||
590 | { | ||
591 | int len = 0; | ||
592 | u8 *pos = NULL; | ||
593 | |||
594 | /* Make sure there is enough space for the probe request, | ||
595 | * two mandatory IEs and the data */ | ||
596 | left -= 24; | ||
597 | if (left < 0) | ||
598 | return 0; | ||
599 | |||
600 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); | ||
601 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); | ||
602 | memcpy(frame->sa, ta, ETH_ALEN); | ||
603 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); | ||
604 | frame->seq_ctrl = 0; | ||
605 | |||
606 | len += 24; | ||
607 | |||
608 | /* ...next IE... */ | ||
609 | pos = &frame->u.probe_req.variable[0]; | ||
610 | |||
611 | /* fill in our SSID IE */ | ||
612 | left -= ssid_len + 2; | ||
613 | if (left < 0) | ||
614 | return 0; | ||
615 | *pos++ = WLAN_EID_SSID; | ||
616 | *pos++ = ssid_len; | ||
617 | if (ssid && ssid_len) { | ||
618 | memcpy(pos, ssid, ssid_len); | ||
619 | pos += ssid_len; | ||
620 | } | ||
621 | |||
622 | len += ssid_len + 2; | ||
623 | |||
624 | if (WARN_ON(left < ie_len)) | ||
625 | return len; | ||
626 | |||
627 | if (ies && ie_len) { | ||
628 | memcpy(pos, ies, ie_len); | ||
629 | len += ie_len; | ||
630 | } | ||
631 | |||
632 | return (u16)len; | ||
633 | } | ||
634 | |||
635 | static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif) | ||
636 | { | ||
637 | struct iwl_host_cmd cmd = { | ||
638 | .id = REPLY_SCAN_CMD, | ||
639 | .len = { sizeof(struct iwl_scan_cmd), }, | ||
640 | .flags = CMD_SYNC, | ||
641 | }; | ||
642 | struct iwl_scan_cmd *scan; | ||
643 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
644 | u32 rate_flags = 0; | ||
645 | u16 cmd_len = 0; | ||
646 | u16 rx_chain = 0; | ||
647 | enum ieee80211_band band; | ||
648 | u8 n_probes = 0; | ||
649 | u8 rx_ant = priv->eeprom_data->valid_rx_ant; | ||
650 | u8 rate; | ||
651 | bool is_active = false; | ||
652 | int chan_mod; | ||
653 | u8 active_chains; | ||
654 | u8 scan_tx_antennas = priv->eeprom_data->valid_tx_ant; | ||
655 | int ret; | ||
656 | int scan_cmd_size = sizeof(struct iwl_scan_cmd) + | ||
657 | MAX_SCAN_CHANNEL * sizeof(struct iwl_scan_channel) + | ||
658 | priv->fw->ucode_capa.max_probe_length; | ||
659 | const u8 *ssid = NULL; | ||
660 | u8 ssid_len = 0; | ||
661 | |||
662 | if (WARN_ON_ONCE(priv->scan_request && | ||
663 | priv->scan_request->n_channels > MAX_SCAN_CHANNEL)) | ||
664 | return -EINVAL; | ||
665 | |||
666 | lockdep_assert_held(&priv->mutex); | ||
667 | |||
668 | if (vif) | ||
669 | ctx = iwl_rxon_ctx_from_vif(vif); | ||
670 | |||
671 | if (!priv->scan_cmd) { | ||
672 | priv->scan_cmd = kmalloc(scan_cmd_size, GFP_KERNEL); | ||
673 | if (!priv->scan_cmd) { | ||
674 | IWL_DEBUG_SCAN(priv, | ||
675 | "fail to allocate memory for scan\n"); | ||
676 | return -ENOMEM; | ||
677 | } | ||
678 | } | ||
679 | scan = priv->scan_cmd; | ||
680 | memset(scan, 0, scan_cmd_size); | ||
681 | |||
682 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; | ||
683 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; | ||
684 | |||
685 | if (priv->scan_type != IWL_SCAN_ROC && | ||
686 | iwl_is_any_associated(priv)) { | ||
687 | u16 interval = 0; | ||
688 | u32 extra; | ||
689 | u32 suspend_time = 100; | ||
690 | u32 scan_suspend_time = 100; | ||
691 | |||
692 | IWL_DEBUG_INFO(priv, "Scanning while associated...\n"); | ||
693 | switch (priv->scan_type) { | ||
694 | case IWL_SCAN_ROC: | ||
695 | WARN_ON(1); | ||
696 | break; | ||
697 | case IWL_SCAN_RADIO_RESET: | ||
698 | interval = 0; | ||
699 | break; | ||
700 | case IWL_SCAN_NORMAL: | ||
701 | interval = vif->bss_conf.beacon_int; | ||
702 | break; | ||
703 | } | ||
704 | |||
705 | scan->suspend_time = 0; | ||
706 | scan->max_out_time = cpu_to_le32(200 * 1024); | ||
707 | if (!interval) | ||
708 | interval = suspend_time; | ||
709 | |||
710 | extra = (suspend_time / interval) << 22; | ||
711 | scan_suspend_time = (extra | | ||
712 | ((suspend_time % interval) * 1024)); | ||
713 | scan->suspend_time = cpu_to_le32(scan_suspend_time); | ||
714 | IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n", | ||
715 | scan_suspend_time, interval); | ||
716 | } else if (priv->scan_type == IWL_SCAN_ROC) { | ||
717 | scan->suspend_time = 0; | ||
718 | scan->max_out_time = 0; | ||
719 | scan->quiet_time = 0; | ||
720 | scan->quiet_plcp_th = 0; | ||
721 | } | ||
722 | |||
723 | switch (priv->scan_type) { | ||
724 | case IWL_SCAN_RADIO_RESET: | ||
725 | IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n"); | ||
726 | break; | ||
727 | case IWL_SCAN_NORMAL: | ||
728 | if (priv->scan_request->n_ssids) { | ||
729 | int i, p = 0; | ||
730 | IWL_DEBUG_SCAN(priv, "Kicking off active scan\n"); | ||
731 | /* | ||
732 | * The highest priority SSID is inserted to the | ||
733 | * probe request template. | ||
734 | */ | ||
735 | ssid_len = priv->scan_request->ssids[0].ssid_len; | ||
736 | ssid = priv->scan_request->ssids[0].ssid; | ||
737 | |||
738 | /* | ||
739 | * Invert the order of ssids, the firmware will invert | ||
740 | * it back. | ||
741 | */ | ||
742 | for (i = priv->scan_request->n_ssids - 1; i >= 1; i--) { | ||
743 | scan->direct_scan[p].id = WLAN_EID_SSID; | ||
744 | scan->direct_scan[p].len = | ||
745 | priv->scan_request->ssids[i].ssid_len; | ||
746 | memcpy(scan->direct_scan[p].ssid, | ||
747 | priv->scan_request->ssids[i].ssid, | ||
748 | priv->scan_request->ssids[i].ssid_len); | ||
749 | n_probes++; | ||
750 | p++; | ||
751 | } | ||
752 | is_active = true; | ||
753 | } else | ||
754 | IWL_DEBUG_SCAN(priv, "Start passive scan.\n"); | ||
755 | break; | ||
756 | case IWL_SCAN_ROC: | ||
757 | IWL_DEBUG_SCAN(priv, "Start ROC scan.\n"); | ||
758 | break; | ||
759 | } | ||
760 | |||
761 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; | ||
762 | scan->tx_cmd.sta_id = ctx->bcast_sta_id; | ||
763 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; | ||
764 | |||
765 | switch (priv->scan_band) { | ||
766 | case IEEE80211_BAND_2GHZ: | ||
767 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; | ||
768 | chan_mod = le32_to_cpu( | ||
769 | priv->contexts[IWL_RXON_CTX_BSS].active.flags & | ||
770 | RXON_FLG_CHANNEL_MODE_MSK) | ||
771 | >> RXON_FLG_CHANNEL_MODE_POS; | ||
772 | if ((priv->scan_request && priv->scan_request->no_cck) || | ||
773 | chan_mod == CHANNEL_MODE_PURE_40) { | ||
774 | rate = IWL_RATE_6M_PLCP; | ||
775 | } else { | ||
776 | rate = IWL_RATE_1M_PLCP; | ||
777 | rate_flags = RATE_MCS_CCK_MSK; | ||
778 | } | ||
779 | /* | ||
780 | * Internal scans are passive, so we can indiscriminately set | ||
781 | * the BT ignore flag on 2.4 GHz since it applies to TX only. | ||
782 | */ | ||
783 | if (priv->cfg->bt_params && | ||
784 | priv->cfg->bt_params->advanced_bt_coexist) | ||
785 | scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT; | ||
786 | break; | ||
787 | case IEEE80211_BAND_5GHZ: | ||
788 | rate = IWL_RATE_6M_PLCP; | ||
789 | break; | ||
790 | default: | ||
791 | IWL_WARN(priv, "Invalid scan band\n"); | ||
792 | return -EIO; | ||
793 | } | ||
794 | |||
795 | /* | ||
796 | * If active scanning is requested but a certain channel is | ||
797 | * marked passive, we can do active scanning if we detect | ||
798 | * transmissions. | ||
799 | * | ||
800 | * There is an issue with some firmware versions that triggers | ||
801 | * a sysassert on a "good CRC threshold" of zero (== disabled), | ||
802 | * on a radar channel even though this means that we should NOT | ||
803 | * send probes. | ||
804 | * | ||
805 | * The "good CRC threshold" is the number of frames that we | ||
806 | * need to receive during our dwell time on a channel before | ||
807 | * sending out probes -- setting this to a huge value will | ||
808 | * mean we never reach it, but at the same time work around | ||
809 | * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER | ||
810 | * here instead of IWL_GOOD_CRC_TH_DISABLED. | ||
811 | * | ||
812 | * This was fixed in later versions along with some other | ||
813 | * scan changes, and the threshold behaves as a flag in those | ||
814 | * versions. | ||
815 | */ | ||
816 | if (priv->new_scan_threshold_behaviour) | ||
817 | scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT : | ||
818 | IWL_GOOD_CRC_TH_DISABLED; | ||
819 | else | ||
820 | scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT : | ||
821 | IWL_GOOD_CRC_TH_NEVER; | ||
822 | |||
823 | band = priv->scan_band; | ||
824 | |||
825 | if (band == IEEE80211_BAND_2GHZ && | ||
826 | priv->cfg->bt_params && | ||
827 | priv->cfg->bt_params->advanced_bt_coexist) { | ||
828 | /* transmit 2.4 GHz probes only on first antenna */ | ||
829 | scan_tx_antennas = first_antenna(scan_tx_antennas); | ||
830 | } | ||
831 | |||
832 | priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, | ||
833 | priv->scan_tx_ant[band], | ||
834 | scan_tx_antennas); | ||
835 | rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]); | ||
836 | scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags); | ||
837 | |||
838 | /* | ||
839 | * In power save mode while associated use one chain, | ||
840 | * otherwise use all chains | ||
841 | */ | ||
842 | if (test_bit(STATUS_POWER_PMI, &priv->status) && | ||
843 | !(priv->hw->conf.flags & IEEE80211_CONF_IDLE)) { | ||
844 | /* rx_ant has been set to all valid chains previously */ | ||
845 | active_chains = rx_ant & | ||
846 | ((u8)(priv->chain_noise_data.active_chains)); | ||
847 | if (!active_chains) | ||
848 | active_chains = rx_ant; | ||
849 | |||
850 | IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n", | ||
851 | priv->chain_noise_data.active_chains); | ||
852 | |||
853 | rx_ant = first_antenna(active_chains); | ||
854 | } | ||
855 | if (priv->cfg->bt_params && | ||
856 | priv->cfg->bt_params->advanced_bt_coexist && | ||
857 | priv->bt_full_concurrent) { | ||
858 | /* operated as 1x1 in full concurrency mode */ | ||
859 | rx_ant = first_antenna(rx_ant); | ||
860 | } | ||
861 | |||
862 | /* MIMO is not used here, but value is required */ | ||
863 | rx_chain |= | ||
864 | priv->eeprom_data->valid_rx_ant << RXON_RX_CHAIN_VALID_POS; | ||
865 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS; | ||
866 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS; | ||
867 | rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS; | ||
868 | scan->rx_chain = cpu_to_le16(rx_chain); | ||
869 | switch (priv->scan_type) { | ||
870 | case IWL_SCAN_NORMAL: | ||
871 | cmd_len = iwl_fill_probe_req( | ||
872 | (struct ieee80211_mgmt *)scan->data, | ||
873 | vif->addr, | ||
874 | priv->scan_request->ie, | ||
875 | priv->scan_request->ie_len, | ||
876 | ssid, ssid_len, | ||
877 | scan_cmd_size - sizeof(*scan)); | ||
878 | break; | ||
879 | case IWL_SCAN_RADIO_RESET: | ||
880 | case IWL_SCAN_ROC: | ||
881 | /* use bcast addr, will not be transmitted but must be valid */ | ||
882 | cmd_len = iwl_fill_probe_req( | ||
883 | (struct ieee80211_mgmt *)scan->data, | ||
884 | iwl_bcast_addr, NULL, 0, | ||
885 | NULL, 0, | ||
886 | scan_cmd_size - sizeof(*scan)); | ||
887 | break; | ||
888 | default: | ||
889 | BUG(); | ||
890 | } | ||
891 | scan->tx_cmd.len = cpu_to_le16(cmd_len); | ||
892 | |||
893 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | | ||
894 | RXON_FILTER_BCON_AWARE_MSK); | ||
895 | |||
896 | switch (priv->scan_type) { | ||
897 | case IWL_SCAN_RADIO_RESET: | ||
898 | scan->channel_count = | ||
899 | iwl_get_single_channel_for_scan(priv, vif, band, | ||
900 | (void *)&scan->data[cmd_len]); | ||
901 | break; | ||
902 | case IWL_SCAN_NORMAL: | ||
903 | scan->channel_count = | ||
904 | iwl_get_channels_for_scan(priv, vif, band, | ||
905 | is_active, n_probes, | ||
906 | (void *)&scan->data[cmd_len]); | ||
907 | break; | ||
908 | case IWL_SCAN_ROC: { | ||
909 | struct iwl_scan_channel *scan_ch; | ||
910 | int n_chan, i; | ||
911 | u16 dwell; | ||
912 | |||
913 | dwell = iwl_limit_dwell(priv, priv->hw_roc_duration); | ||
914 | n_chan = DIV_ROUND_UP(priv->hw_roc_duration, dwell); | ||
915 | |||
916 | scan->channel_count = n_chan; | ||
917 | |||
918 | scan_ch = (void *)&scan->data[cmd_len]; | ||
919 | |||
920 | for (i = 0; i < n_chan; i++) { | ||
921 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; | ||
922 | scan_ch->channel = | ||
923 | cpu_to_le16(priv->hw_roc_channel->hw_value); | ||
924 | |||
925 | if (i == n_chan - 1) | ||
926 | dwell = priv->hw_roc_duration - i * dwell; | ||
927 | |||
928 | scan_ch->active_dwell = | ||
929 | scan_ch->passive_dwell = cpu_to_le16(dwell); | ||
930 | |||
931 | /* Set txpower levels to defaults */ | ||
932 | scan_ch->dsp_atten = 110; | ||
933 | |||
934 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use | ||
935 | * power level: | ||
936 | * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3; | ||
937 | */ | ||
938 | if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ) | ||
939 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; | ||
940 | else | ||
941 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); | ||
942 | |||
943 | scan_ch++; | ||
944 | } | ||
945 | } | ||
946 | |||
947 | break; | ||
948 | } | ||
949 | |||
950 | if (scan->channel_count == 0) { | ||
951 | IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count); | ||
952 | return -EIO; | ||
953 | } | ||
954 | |||
955 | cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) + | ||
956 | scan->channel_count * sizeof(struct iwl_scan_channel); | ||
957 | cmd.data[0] = scan; | ||
958 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; | ||
959 | scan->len = cpu_to_le16(cmd.len[0]); | ||
960 | |||
961 | /* set scan bit here for PAN params */ | ||
962 | set_bit(STATUS_SCAN_HW, &priv->status); | ||
963 | |||
964 | ret = iwlagn_set_pan_params(priv); | ||
965 | if (ret) { | ||
966 | clear_bit(STATUS_SCAN_HW, &priv->status); | ||
967 | return ret; | ||
968 | } | ||
969 | |||
970 | ret = iwl_dvm_send_cmd(priv, &cmd); | ||
971 | if (ret) { | ||
972 | clear_bit(STATUS_SCAN_HW, &priv->status); | ||
973 | iwlagn_set_pan_params(priv); | ||
974 | } | ||
975 | |||
976 | return ret; | ||
977 | } | ||
978 | |||
979 | void iwl_init_scan_params(struct iwl_priv *priv) | ||
980 | { | ||
981 | u8 ant_idx = fls(priv->eeprom_data->valid_tx_ant) - 1; | ||
982 | if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ]) | ||
983 | priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx; | ||
984 | if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ]) | ||
985 | priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx; | ||
986 | } | ||
987 | |||
988 | int __must_check iwl_scan_initiate(struct iwl_priv *priv, | ||
989 | struct ieee80211_vif *vif, | ||
990 | enum iwl_scan_type scan_type, | ||
991 | enum ieee80211_band band) | ||
992 | { | ||
993 | int ret; | ||
994 | |||
995 | lockdep_assert_held(&priv->mutex); | ||
996 | |||
997 | cancel_delayed_work(&priv->scan_check); | ||
998 | |||
999 | if (!iwl_is_ready_rf(priv)) { | ||
1000 | IWL_WARN(priv, "Request scan called when driver not ready.\n"); | ||
1001 | return -EIO; | ||
1002 | } | ||
1003 | |||
1004 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { | ||
1005 | IWL_DEBUG_SCAN(priv, | ||
1006 | "Multiple concurrent scan requests in parallel.\n"); | ||
1007 | return -EBUSY; | ||
1008 | } | ||
1009 | |||
1010 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { | ||
1011 | IWL_DEBUG_SCAN(priv, "Scan request while abort pending.\n"); | ||
1012 | return -EBUSY; | ||
1013 | } | ||
1014 | |||
1015 | IWL_DEBUG_SCAN(priv, "Starting %sscan...\n", | ||
1016 | scan_type == IWL_SCAN_NORMAL ? "" : | ||
1017 | scan_type == IWL_SCAN_ROC ? "remain-on-channel " : | ||
1018 | "internal short "); | ||
1019 | |||
1020 | set_bit(STATUS_SCANNING, &priv->status); | ||
1021 | priv->scan_type = scan_type; | ||
1022 | priv->scan_start = jiffies; | ||
1023 | priv->scan_band = band; | ||
1024 | |||
1025 | ret = iwlagn_request_scan(priv, vif); | ||
1026 | if (ret) { | ||
1027 | clear_bit(STATUS_SCANNING, &priv->status); | ||
1028 | priv->scan_type = IWL_SCAN_NORMAL; | ||
1029 | return ret; | ||
1030 | } | ||
1031 | |||
1032 | queue_delayed_work(priv->workqueue, &priv->scan_check, | ||
1033 | IWL_SCAN_CHECK_WATCHDOG); | ||
1034 | |||
1035 | return 0; | ||
1036 | } | ||
1037 | |||
1038 | |||
1039 | /* | ||
1040 | * internal short scan, this function should only been called while associated. | ||
1041 | * It will reset and tune the radio to prevent possible RF related problem | ||
1042 | */ | ||
1043 | void iwl_internal_short_hw_scan(struct iwl_priv *priv) | ||
1044 | { | ||
1045 | queue_work(priv->workqueue, &priv->start_internal_scan); | ||
1046 | } | ||
1047 | |||
1048 | static void iwl_bg_start_internal_scan(struct work_struct *work) | ||
1049 | { | ||
1050 | struct iwl_priv *priv = | ||
1051 | container_of(work, struct iwl_priv, start_internal_scan); | ||
1052 | |||
1053 | IWL_DEBUG_SCAN(priv, "Start internal scan\n"); | ||
1054 | |||
1055 | mutex_lock(&priv->mutex); | ||
1056 | |||
1057 | if (priv->scan_type == IWL_SCAN_RADIO_RESET) { | ||
1058 | IWL_DEBUG_SCAN(priv, "Internal scan already in progress\n"); | ||
1059 | goto unlock; | ||
1060 | } | ||
1061 | |||
1062 | if (test_bit(STATUS_SCANNING, &priv->status)) { | ||
1063 | IWL_DEBUG_SCAN(priv, "Scan already in progress.\n"); | ||
1064 | goto unlock; | ||
1065 | } | ||
1066 | |||
1067 | if (iwl_scan_initiate(priv, NULL, IWL_SCAN_RADIO_RESET, priv->band)) | ||
1068 | IWL_DEBUG_SCAN(priv, "failed to start internal short scan\n"); | ||
1069 | unlock: | ||
1070 | mutex_unlock(&priv->mutex); | ||
1071 | } | ||
1072 | |||
1073 | static void iwl_bg_scan_check(struct work_struct *data) | ||
1074 | { | ||
1075 | struct iwl_priv *priv = | ||
1076 | container_of(data, struct iwl_priv, scan_check.work); | ||
1077 | |||
1078 | IWL_DEBUG_SCAN(priv, "Scan check work\n"); | ||
1079 | |||
1080 | /* Since we are here firmware does not finish scan and | ||
1081 | * most likely is in bad shape, so we don't bother to | ||
1082 | * send abort command, just force scan complete to mac80211 */ | ||
1083 | mutex_lock(&priv->mutex); | ||
1084 | iwl_force_scan_end(priv); | ||
1085 | mutex_unlock(&priv->mutex); | ||
1086 | } | ||
1087 | |||
1088 | static void iwl_bg_abort_scan(struct work_struct *work) | ||
1089 | { | ||
1090 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); | ||
1091 | |||
1092 | IWL_DEBUG_SCAN(priv, "Abort scan work\n"); | ||
1093 | |||
1094 | /* We keep scan_check work queued in case when firmware will not | ||
1095 | * report back scan completed notification */ | ||
1096 | mutex_lock(&priv->mutex); | ||
1097 | iwl_scan_cancel_timeout(priv, 200); | ||
1098 | mutex_unlock(&priv->mutex); | ||
1099 | } | ||
1100 | |||
1101 | static void iwl_bg_scan_completed(struct work_struct *work) | ||
1102 | { | ||
1103 | struct iwl_priv *priv = | ||
1104 | container_of(work, struct iwl_priv, scan_completed); | ||
1105 | |||
1106 | mutex_lock(&priv->mutex); | ||
1107 | iwl_process_scan_complete(priv); | ||
1108 | mutex_unlock(&priv->mutex); | ||
1109 | } | ||
1110 | |||
1111 | void iwl_setup_scan_deferred_work(struct iwl_priv *priv) | ||
1112 | { | ||
1113 | INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); | ||
1114 | INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); | ||
1115 | INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan); | ||
1116 | INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); | ||
1117 | } | ||
1118 | |||
1119 | void iwl_cancel_scan_deferred_work(struct iwl_priv *priv) | ||
1120 | { | ||
1121 | cancel_work_sync(&priv->start_internal_scan); | ||
1122 | cancel_work_sync(&priv->abort_scan); | ||
1123 | cancel_work_sync(&priv->scan_completed); | ||
1124 | |||
1125 | if (cancel_delayed_work_sync(&priv->scan_check)) { | ||
1126 | mutex_lock(&priv->mutex); | ||
1127 | iwl_force_scan_end(priv); | ||
1128 | mutex_unlock(&priv->mutex); | ||
1129 | } | ||
1130 | } | ||
1131 | |||
1132 | void iwl_scan_roc_expired(struct iwl_priv *priv) | ||
1133 | { | ||
1134 | /* | ||
1135 | * The status bit should be set here, to prevent a race | ||
1136 | * where the atomic_read returns 1, but before the execution continues | ||
1137 | * iwl_scan_offchannel_skb_status() checks if the status bit is set | ||
1138 | */ | ||
1139 | set_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status); | ||
1140 | |||
1141 | if (atomic_read(&priv->num_aux_in_flight) == 0) { | ||
1142 | ieee80211_remain_on_channel_expired(priv->hw); | ||
1143 | priv->hw_roc_channel = NULL; | ||
1144 | schedule_delayed_work(&priv->hw_roc_disable_work, | ||
1145 | 10 * HZ); | ||
1146 | |||
1147 | clear_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status); | ||
1148 | } else { | ||
1149 | IWL_DEBUG_SCAN(priv, "ROC done with %d frames in aux\n", | ||
1150 | atomic_read(&priv->num_aux_in_flight)); | ||
1151 | } | ||
1152 | } | ||
1153 | |||
1154 | void iwl_scan_offchannel_skb(struct iwl_priv *priv) | ||
1155 | { | ||
1156 | WARN_ON(!priv->hw_roc_start_notified); | ||
1157 | atomic_inc(&priv->num_aux_in_flight); | ||
1158 | } | ||
1159 | |||
1160 | void iwl_scan_offchannel_skb_status(struct iwl_priv *priv) | ||
1161 | { | ||
1162 | if (atomic_dec_return(&priv->num_aux_in_flight) == 0 && | ||
1163 | test_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status)) { | ||
1164 | IWL_DEBUG_SCAN(priv, "0 aux frames. Calling ROC expired\n"); | ||
1165 | iwl_scan_roc_expired(priv); | ||
1166 | } | ||
1167 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/sta.c b/drivers/net/wireless/iwlwifi/dvm/sta.c new file mode 100644 index 000000000000..286ce4e18068 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/sta.c | |||
@@ -0,0 +1,1485 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2012 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 | *****************************************************************************/ | ||
29 | #include <linux/etherdevice.h> | ||
30 | #include <net/mac80211.h> | ||
31 | #include "iwl-trans.h" | ||
32 | #include "dev.h" | ||
33 | #include "agn.h" | ||
34 | |||
35 | const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; | ||
36 | |||
37 | static int iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) | ||
38 | { | ||
39 | lockdep_assert_held(&priv->sta_lock); | ||
40 | |||
41 | if (sta_id >= IWLAGN_STATION_COUNT) { | ||
42 | IWL_ERR(priv, "invalid sta_id %u", sta_id); | ||
43 | return -EINVAL; | ||
44 | } | ||
45 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) | ||
46 | IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u " | ||
47 | "addr %pM\n", | ||
48 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
49 | |||
50 | if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) { | ||
51 | IWL_DEBUG_ASSOC(priv, | ||
52 | "STA id %u addr %pM already present in uCode " | ||
53 | "(according to driver)\n", | ||
54 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
55 | } else { | ||
56 | priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE; | ||
57 | IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n", | ||
58 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
59 | } | ||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | static int iwl_process_add_sta_resp(struct iwl_priv *priv, | ||
64 | struct iwl_addsta_cmd *addsta, | ||
65 | struct iwl_rx_packet *pkt) | ||
66 | { | ||
67 | struct iwl_add_sta_resp *add_sta_resp = (void *)pkt->data; | ||
68 | u8 sta_id = addsta->sta.sta_id; | ||
69 | int ret = -EIO; | ||
70 | |||
71 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | ||
72 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", | ||
73 | pkt->hdr.flags); | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", | ||
78 | sta_id); | ||
79 | |||
80 | spin_lock(&priv->sta_lock); | ||
81 | |||
82 | switch (add_sta_resp->status) { | ||
83 | case ADD_STA_SUCCESS_MSK: | ||
84 | IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n"); | ||
85 | ret = iwl_sta_ucode_activate(priv, sta_id); | ||
86 | break; | ||
87 | case ADD_STA_NO_ROOM_IN_TABLE: | ||
88 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", | ||
89 | sta_id); | ||
90 | break; | ||
91 | case ADD_STA_NO_BLOCK_ACK_RESOURCE: | ||
92 | IWL_ERR(priv, "Adding station %d failed, no block ack " | ||
93 | "resource.\n", sta_id); | ||
94 | break; | ||
95 | case ADD_STA_MODIFY_NON_EXIST_STA: | ||
96 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", | ||
97 | sta_id); | ||
98 | break; | ||
99 | default: | ||
100 | IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n", | ||
101 | add_sta_resp->status); | ||
102 | break; | ||
103 | } | ||
104 | |||
105 | IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n", | ||
106 | priv->stations[sta_id].sta.mode == | ||
107 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", | ||
108 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
109 | |||
110 | /* | ||
111 | * XXX: The MAC address in the command buffer is often changed from | ||
112 | * the original sent to the device. That is, the MAC address | ||
113 | * written to the command buffer often is not the same MAC address | ||
114 | * read from the command buffer when the command returns. This | ||
115 | * issue has not yet been resolved and this debugging is left to | ||
116 | * observe the problem. | ||
117 | */ | ||
118 | IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n", | ||
119 | priv->stations[sta_id].sta.mode == | ||
120 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", | ||
121 | addsta->sta.addr); | ||
122 | spin_unlock(&priv->sta_lock); | ||
123 | |||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, | ||
128 | struct iwl_device_cmd *cmd) | ||
129 | { | ||
130 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
131 | struct iwl_addsta_cmd *addsta = | ||
132 | (struct iwl_addsta_cmd *) cmd->payload; | ||
133 | |||
134 | return iwl_process_add_sta_resp(priv, addsta, pkt); | ||
135 | } | ||
136 | |||
137 | int iwl_send_add_sta(struct iwl_priv *priv, | ||
138 | struct iwl_addsta_cmd *sta, u8 flags) | ||
139 | { | ||
140 | int ret = 0; | ||
141 | struct iwl_host_cmd cmd = { | ||
142 | .id = REPLY_ADD_STA, | ||
143 | .flags = flags, | ||
144 | .data = { sta, }, | ||
145 | .len = { sizeof(*sta), }, | ||
146 | }; | ||
147 | u8 sta_id __maybe_unused = sta->sta.sta_id; | ||
148 | |||
149 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", | ||
150 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); | ||
151 | |||
152 | if (!(flags & CMD_ASYNC)) { | ||
153 | cmd.flags |= CMD_WANT_SKB; | ||
154 | might_sleep(); | ||
155 | } | ||
156 | |||
157 | ret = iwl_dvm_send_cmd(priv, &cmd); | ||
158 | |||
159 | if (ret || (flags & CMD_ASYNC)) | ||
160 | return ret; | ||
161 | /*else the command was successfully sent in SYNC mode, need to free | ||
162 | * the reply page */ | ||
163 | |||
164 | iwl_free_resp(&cmd); | ||
165 | |||
166 | if (cmd.handler_status) | ||
167 | IWL_ERR(priv, "%s - error in the CMD response %d", __func__, | ||
168 | cmd.handler_status); | ||
169 | |||
170 | return cmd.handler_status; | ||
171 | } | ||
172 | |||
173 | bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv, | ||
174 | struct iwl_rxon_context *ctx, | ||
175 | struct ieee80211_sta_ht_cap *ht_cap) | ||
176 | { | ||
177 | if (!ctx->ht.enabled || !ctx->ht.is_40mhz) | ||
178 | return false; | ||
179 | |||
180 | #ifdef CONFIG_IWLWIFI_DEBUGFS | ||
181 | if (priv->disable_ht40) | ||
182 | return false; | ||
183 | #endif | ||
184 | |||
185 | /* | ||
186 | * Remainder of this function checks ht_cap, but if it's | ||
187 | * NULL then we can do HT40 (special case for RXON) | ||
188 | */ | ||
189 | if (!ht_cap) | ||
190 | return true; | ||
191 | |||
192 | if (!ht_cap->ht_supported) | ||
193 | return false; | ||
194 | |||
195 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) | ||
196 | return false; | ||
197 | |||
198 | return true; | ||
199 | } | ||
200 | |||
201 | static void iwl_sta_calc_ht_flags(struct iwl_priv *priv, | ||
202 | struct ieee80211_sta *sta, | ||
203 | struct iwl_rxon_context *ctx, | ||
204 | __le32 *flags, __le32 *mask) | ||
205 | { | ||
206 | struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap; | ||
207 | u8 mimo_ps_mode; | ||
208 | |||
209 | *mask = STA_FLG_RTS_MIMO_PROT_MSK | | ||
210 | STA_FLG_MIMO_DIS_MSK | | ||
211 | STA_FLG_HT40_EN_MSK | | ||
212 | STA_FLG_MAX_AGG_SIZE_MSK | | ||
213 | STA_FLG_AGG_MPDU_DENSITY_MSK; | ||
214 | *flags = 0; | ||
215 | |||
216 | if (!sta || !sta_ht_inf->ht_supported) | ||
217 | return; | ||
218 | |||
219 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; | ||
220 | |||
221 | IWL_DEBUG_INFO(priv, "STA %pM SM PS mode: %s\n", | ||
222 | sta->addr, | ||
223 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ? | ||
224 | "static" : | ||
225 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ? | ||
226 | "dynamic" : "disabled"); | ||
227 | |||
228 | switch (mimo_ps_mode) { | ||
229 | case WLAN_HT_CAP_SM_PS_STATIC: | ||
230 | *flags |= STA_FLG_MIMO_DIS_MSK; | ||
231 | break; | ||
232 | case WLAN_HT_CAP_SM_PS_DYNAMIC: | ||
233 | *flags |= STA_FLG_RTS_MIMO_PROT_MSK; | ||
234 | break; | ||
235 | case WLAN_HT_CAP_SM_PS_DISABLED: | ||
236 | break; | ||
237 | default: | ||
238 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode); | ||
239 | break; | ||
240 | } | ||
241 | |||
242 | *flags |= cpu_to_le32( | ||
243 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); | ||
244 | |||
245 | *flags |= cpu_to_le32( | ||
246 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); | ||
247 | |||
248 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) | ||
249 | *flags |= STA_FLG_HT40_EN_MSK; | ||
250 | } | ||
251 | |||
252 | int iwl_sta_update_ht(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
253 | struct ieee80211_sta *sta) | ||
254 | { | ||
255 | u8 sta_id = iwl_sta_id(sta); | ||
256 | __le32 flags, mask; | ||
257 | struct iwl_addsta_cmd cmd; | ||
258 | |||
259 | if (WARN_ON_ONCE(sta_id == IWL_INVALID_STATION)) | ||
260 | return -EINVAL; | ||
261 | |||
262 | iwl_sta_calc_ht_flags(priv, sta, ctx, &flags, &mask); | ||
263 | |||
264 | spin_lock_bh(&priv->sta_lock); | ||
265 | priv->stations[sta_id].sta.station_flags &= ~mask; | ||
266 | priv->stations[sta_id].sta.station_flags |= flags; | ||
267 | spin_unlock_bh(&priv->sta_lock); | ||
268 | |||
269 | memset(&cmd, 0, sizeof(cmd)); | ||
270 | cmd.mode = STA_CONTROL_MODIFY_MSK; | ||
271 | cmd.station_flags_msk = mask; | ||
272 | cmd.station_flags = flags; | ||
273 | cmd.sta.sta_id = sta_id; | ||
274 | |||
275 | return iwl_send_add_sta(priv, &cmd, CMD_SYNC); | ||
276 | } | ||
277 | |||
278 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, | ||
279 | struct ieee80211_sta *sta, | ||
280 | struct iwl_rxon_context *ctx) | ||
281 | { | ||
282 | __le32 flags, mask; | ||
283 | |||
284 | iwl_sta_calc_ht_flags(priv, sta, ctx, &flags, &mask); | ||
285 | |||
286 | lockdep_assert_held(&priv->sta_lock); | ||
287 | priv->stations[index].sta.station_flags &= ~mask; | ||
288 | priv->stations[index].sta.station_flags |= flags; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * iwl_prep_station - Prepare station information for addition | ||
293 | * | ||
294 | * should be called with sta_lock held | ||
295 | */ | ||
296 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
297 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta) | ||
298 | { | ||
299 | struct iwl_station_entry *station; | ||
300 | int i; | ||
301 | u8 sta_id = IWL_INVALID_STATION; | ||
302 | |||
303 | if (is_ap) | ||
304 | sta_id = ctx->ap_sta_id; | ||
305 | else if (is_broadcast_ether_addr(addr)) | ||
306 | sta_id = ctx->bcast_sta_id; | ||
307 | else | ||
308 | for (i = IWL_STA_ID; i < IWLAGN_STATION_COUNT; i++) { | ||
309 | if (ether_addr_equal(priv->stations[i].sta.sta.addr, | ||
310 | addr)) { | ||
311 | sta_id = i; | ||
312 | break; | ||
313 | } | ||
314 | |||
315 | if (!priv->stations[i].used && | ||
316 | sta_id == IWL_INVALID_STATION) | ||
317 | sta_id = i; | ||
318 | } | ||
319 | |||
320 | /* | ||
321 | * These two conditions have the same outcome, but keep them | ||
322 | * separate | ||
323 | */ | ||
324 | if (unlikely(sta_id == IWL_INVALID_STATION)) | ||
325 | return sta_id; | ||
326 | |||
327 | /* | ||
328 | * uCode is not able to deal with multiple requests to add a | ||
329 | * station. Keep track if one is in progress so that we do not send | ||
330 | * another. | ||
331 | */ | ||
332 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { | ||
333 | IWL_DEBUG_INFO(priv, "STA %d already in process of being " | ||
334 | "added.\n", sta_id); | ||
335 | return sta_id; | ||
336 | } | ||
337 | |||
338 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && | ||
339 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && | ||
340 | ether_addr_equal(priv->stations[sta_id].sta.sta.addr, addr)) { | ||
341 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not " | ||
342 | "adding again.\n", sta_id, addr); | ||
343 | return sta_id; | ||
344 | } | ||
345 | |||
346 | station = &priv->stations[sta_id]; | ||
347 | station->used = IWL_STA_DRIVER_ACTIVE; | ||
348 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", | ||
349 | sta_id, addr); | ||
350 | priv->num_stations++; | ||
351 | |||
352 | /* Set up the REPLY_ADD_STA command to send to device */ | ||
353 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); | ||
354 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); | ||
355 | station->sta.mode = 0; | ||
356 | station->sta.sta.sta_id = sta_id; | ||
357 | station->sta.station_flags = ctx->station_flags; | ||
358 | station->ctxid = ctx->ctxid; | ||
359 | |||
360 | if (sta) { | ||
361 | struct iwl_station_priv *sta_priv; | ||
362 | |||
363 | sta_priv = (void *)sta->drv_priv; | ||
364 | sta_priv->ctx = ctx; | ||
365 | } | ||
366 | |||
367 | /* | ||
368 | * OK to call unconditionally, since local stations (IBSS BSSID | ||
369 | * STA and broadcast STA) pass in a NULL sta, and mac80211 | ||
370 | * doesn't allow HT IBSS. | ||
371 | */ | ||
372 | iwl_set_ht_add_station(priv, sta_id, sta, ctx); | ||
373 | |||
374 | return sta_id; | ||
375 | |||
376 | } | ||
377 | |||
378 | #define STA_WAIT_TIMEOUT (HZ/2) | ||
379 | |||
380 | /** | ||
381 | * iwl_add_station_common - | ||
382 | */ | ||
383 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
384 | const u8 *addr, bool is_ap, | ||
385 | struct ieee80211_sta *sta, u8 *sta_id_r) | ||
386 | { | ||
387 | int ret = 0; | ||
388 | u8 sta_id; | ||
389 | struct iwl_addsta_cmd sta_cmd; | ||
390 | |||
391 | *sta_id_r = 0; | ||
392 | spin_lock_bh(&priv->sta_lock); | ||
393 | sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta); | ||
394 | if (sta_id == IWL_INVALID_STATION) { | ||
395 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", | ||
396 | addr); | ||
397 | spin_unlock_bh(&priv->sta_lock); | ||
398 | return -EINVAL; | ||
399 | } | ||
400 | |||
401 | /* | ||
402 | * uCode is not able to deal with multiple requests to add a | ||
403 | * station. Keep track if one is in progress so that we do not send | ||
404 | * another. | ||
405 | */ | ||
406 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { | ||
407 | IWL_DEBUG_INFO(priv, "STA %d already in process of being " | ||
408 | "added.\n", sta_id); | ||
409 | spin_unlock_bh(&priv->sta_lock); | ||
410 | return -EEXIST; | ||
411 | } | ||
412 | |||
413 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && | ||
414 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | ||
415 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not " | ||
416 | "adding again.\n", sta_id, addr); | ||
417 | spin_unlock_bh(&priv->sta_lock); | ||
418 | return -EEXIST; | ||
419 | } | ||
420 | |||
421 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; | ||
422 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, | ||
423 | sizeof(struct iwl_addsta_cmd)); | ||
424 | spin_unlock_bh(&priv->sta_lock); | ||
425 | |||
426 | /* Add station to device's station table */ | ||
427 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
428 | if (ret) { | ||
429 | spin_lock_bh(&priv->sta_lock); | ||
430 | IWL_ERR(priv, "Adding station %pM failed.\n", | ||
431 | priv->stations[sta_id].sta.sta.addr); | ||
432 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
433 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
434 | spin_unlock_bh(&priv->sta_lock); | ||
435 | } | ||
436 | *sta_id_r = sta_id; | ||
437 | return ret; | ||
438 | } | ||
439 | |||
440 | /** | ||
441 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station | ||
442 | */ | ||
443 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) | ||
444 | { | ||
445 | lockdep_assert_held(&priv->sta_lock); | ||
446 | |||
447 | /* Ucode must be active and driver must be non active */ | ||
448 | if ((priv->stations[sta_id].used & | ||
449 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != | ||
450 | IWL_STA_UCODE_ACTIVE) | ||
451 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); | ||
452 | |||
453 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; | ||
454 | |||
455 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); | ||
456 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); | ||
457 | } | ||
458 | |||
459 | static int iwl_send_remove_station(struct iwl_priv *priv, | ||
460 | const u8 *addr, int sta_id, | ||
461 | bool temporary) | ||
462 | { | ||
463 | struct iwl_rx_packet *pkt; | ||
464 | int ret; | ||
465 | struct iwl_rem_sta_cmd rm_sta_cmd; | ||
466 | |||
467 | struct iwl_host_cmd cmd = { | ||
468 | .id = REPLY_REMOVE_STA, | ||
469 | .len = { sizeof(struct iwl_rem_sta_cmd), }, | ||
470 | .flags = CMD_SYNC, | ||
471 | .data = { &rm_sta_cmd, }, | ||
472 | }; | ||
473 | |||
474 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); | ||
475 | rm_sta_cmd.num_sta = 1; | ||
476 | memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN); | ||
477 | |||
478 | cmd.flags |= CMD_WANT_SKB; | ||
479 | |||
480 | ret = iwl_dvm_send_cmd(priv, &cmd); | ||
481 | |||
482 | if (ret) | ||
483 | return ret; | ||
484 | |||
485 | pkt = cmd.resp_pkt; | ||
486 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | ||
487 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", | ||
488 | pkt->hdr.flags); | ||
489 | ret = -EIO; | ||
490 | } | ||
491 | |||
492 | if (!ret) { | ||
493 | struct iwl_rem_sta_resp *rem_sta_resp = (void *)pkt->data; | ||
494 | switch (rem_sta_resp->status) { | ||
495 | case REM_STA_SUCCESS_MSK: | ||
496 | if (!temporary) { | ||
497 | spin_lock_bh(&priv->sta_lock); | ||
498 | iwl_sta_ucode_deactivate(priv, sta_id); | ||
499 | spin_unlock_bh(&priv->sta_lock); | ||
500 | } | ||
501 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); | ||
502 | break; | ||
503 | default: | ||
504 | ret = -EIO; | ||
505 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); | ||
506 | break; | ||
507 | } | ||
508 | } | ||
509 | iwl_free_resp(&cmd); | ||
510 | |||
511 | return ret; | ||
512 | } | ||
513 | |||
514 | /** | ||
515 | * iwl_remove_station - Remove driver's knowledge of station. | ||
516 | */ | ||
517 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, | ||
518 | const u8 *addr) | ||
519 | { | ||
520 | u8 tid; | ||
521 | |||
522 | if (!iwl_is_ready(priv)) { | ||
523 | IWL_DEBUG_INFO(priv, | ||
524 | "Unable to remove station %pM, device not ready.\n", | ||
525 | addr); | ||
526 | /* | ||
527 | * It is typical for stations to be removed when we are | ||
528 | * going down. Return success since device will be down | ||
529 | * soon anyway | ||
530 | */ | ||
531 | return 0; | ||
532 | } | ||
533 | |||
534 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", | ||
535 | sta_id, addr); | ||
536 | |||
537 | if (WARN_ON(sta_id == IWL_INVALID_STATION)) | ||
538 | return -EINVAL; | ||
539 | |||
540 | spin_lock_bh(&priv->sta_lock); | ||
541 | |||
542 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
543 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", | ||
544 | addr); | ||
545 | goto out_err; | ||
546 | } | ||
547 | |||
548 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | ||
549 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", | ||
550 | addr); | ||
551 | goto out_err; | ||
552 | } | ||
553 | |||
554 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { | ||
555 | kfree(priv->stations[sta_id].lq); | ||
556 | priv->stations[sta_id].lq = NULL; | ||
557 | } | ||
558 | |||
559 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) | ||
560 | memset(&priv->tid_data[sta_id][tid], 0, | ||
561 | sizeof(priv->tid_data[sta_id][tid])); | ||
562 | |||
563 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
564 | |||
565 | priv->num_stations--; | ||
566 | |||
567 | if (WARN_ON(priv->num_stations < 0)) | ||
568 | priv->num_stations = 0; | ||
569 | |||
570 | spin_unlock_bh(&priv->sta_lock); | ||
571 | |||
572 | return iwl_send_remove_station(priv, addr, sta_id, false); | ||
573 | out_err: | ||
574 | spin_unlock_bh(&priv->sta_lock); | ||
575 | return -EINVAL; | ||
576 | } | ||
577 | |||
578 | void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id, | ||
579 | const u8 *addr) | ||
580 | { | ||
581 | u8 tid; | ||
582 | |||
583 | if (!iwl_is_ready(priv)) { | ||
584 | IWL_DEBUG_INFO(priv, | ||
585 | "Unable to remove station %pM, device not ready.\n", | ||
586 | addr); | ||
587 | return; | ||
588 | } | ||
589 | |||
590 | IWL_DEBUG_ASSOC(priv, "Deactivating STA: %pM (%d)\n", addr, sta_id); | ||
591 | |||
592 | if (WARN_ON_ONCE(sta_id == IWL_INVALID_STATION)) | ||
593 | return; | ||
594 | |||
595 | spin_lock_bh(&priv->sta_lock); | ||
596 | |||
597 | WARN_ON_ONCE(!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)); | ||
598 | |||
599 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) | ||
600 | memset(&priv->tid_data[sta_id][tid], 0, | ||
601 | sizeof(priv->tid_data[sta_id][tid])); | ||
602 | |||
603 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
604 | |||
605 | priv->num_stations--; | ||
606 | |||
607 | if (WARN_ON_ONCE(priv->num_stations < 0)) | ||
608 | priv->num_stations = 0; | ||
609 | |||
610 | spin_unlock_bh(&priv->sta_lock); | ||
611 | } | ||
612 | |||
613 | static void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
614 | u8 sta_id, struct iwl_link_quality_cmd *link_cmd) | ||
615 | { | ||
616 | int i, r; | ||
617 | u32 rate_flags = 0; | ||
618 | __le32 rate_n_flags; | ||
619 | |||
620 | lockdep_assert_held(&priv->mutex); | ||
621 | |||
622 | memset(link_cmd, 0, sizeof(*link_cmd)); | ||
623 | |||
624 | /* Set up the rate scaling to start at selected rate, fall back | ||
625 | * all the way down to 1M in IEEE order, and then spin on 1M */ | ||
626 | if (priv->band == IEEE80211_BAND_5GHZ) | ||
627 | r = IWL_RATE_6M_INDEX; | ||
628 | else if (ctx && ctx->vif && ctx->vif->p2p) | ||
629 | r = IWL_RATE_6M_INDEX; | ||
630 | else | ||
631 | r = IWL_RATE_1M_INDEX; | ||
632 | |||
633 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) | ||
634 | rate_flags |= RATE_MCS_CCK_MSK; | ||
635 | |||
636 | rate_flags |= first_antenna(priv->eeprom_data->valid_tx_ant) << | ||
637 | RATE_MCS_ANT_POS; | ||
638 | rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); | ||
639 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) | ||
640 | link_cmd->rs_table[i].rate_n_flags = rate_n_flags; | ||
641 | |||
642 | link_cmd->general_params.single_stream_ant_msk = | ||
643 | first_antenna(priv->eeprom_data->valid_tx_ant); | ||
644 | |||
645 | link_cmd->general_params.dual_stream_ant_msk = | ||
646 | priv->eeprom_data->valid_tx_ant & | ||
647 | ~first_antenna(priv->eeprom_data->valid_tx_ant); | ||
648 | if (!link_cmd->general_params.dual_stream_ant_msk) { | ||
649 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; | ||
650 | } else if (num_of_ant(priv->eeprom_data->valid_tx_ant) == 2) { | ||
651 | link_cmd->general_params.dual_stream_ant_msk = | ||
652 | priv->eeprom_data->valid_tx_ant; | ||
653 | } | ||
654 | |||
655 | link_cmd->agg_params.agg_dis_start_th = | ||
656 | LINK_QUAL_AGG_DISABLE_START_DEF; | ||
657 | link_cmd->agg_params.agg_time_limit = | ||
658 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); | ||
659 | |||
660 | link_cmd->sta_id = sta_id; | ||
661 | } | ||
662 | |||
663 | /** | ||
664 | * iwl_clear_ucode_stations - clear ucode station table bits | ||
665 | * | ||
666 | * This function clears all the bits in the driver indicating | ||
667 | * which stations are active in the ucode. Call when something | ||
668 | * other than explicit station management would cause this in | ||
669 | * the ucode, e.g. unassociated RXON. | ||
670 | */ | ||
671 | void iwl_clear_ucode_stations(struct iwl_priv *priv, | ||
672 | struct iwl_rxon_context *ctx) | ||
673 | { | ||
674 | int i; | ||
675 | bool cleared = false; | ||
676 | |||
677 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n"); | ||
678 | |||
679 | spin_lock_bh(&priv->sta_lock); | ||
680 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
681 | if (ctx && ctx->ctxid != priv->stations[i].ctxid) | ||
682 | continue; | ||
683 | |||
684 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { | ||
685 | IWL_DEBUG_INFO(priv, | ||
686 | "Clearing ucode active for station %d\n", i); | ||
687 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | ||
688 | cleared = true; | ||
689 | } | ||
690 | } | ||
691 | spin_unlock_bh(&priv->sta_lock); | ||
692 | |||
693 | if (!cleared) | ||
694 | IWL_DEBUG_INFO(priv, | ||
695 | "No active stations found to be cleared\n"); | ||
696 | } | ||
697 | |||
698 | /** | ||
699 | * iwl_restore_stations() - Restore driver known stations to device | ||
700 | * | ||
701 | * All stations considered active by driver, but not present in ucode, is | ||
702 | * restored. | ||
703 | * | ||
704 | * Function sleeps. | ||
705 | */ | ||
706 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
707 | { | ||
708 | struct iwl_addsta_cmd sta_cmd; | ||
709 | struct iwl_link_quality_cmd lq; | ||
710 | int i; | ||
711 | bool found = false; | ||
712 | int ret; | ||
713 | bool send_lq; | ||
714 | |||
715 | if (!iwl_is_ready(priv)) { | ||
716 | IWL_DEBUG_INFO(priv, | ||
717 | "Not ready yet, not restoring any stations.\n"); | ||
718 | return; | ||
719 | } | ||
720 | |||
721 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); | ||
722 | spin_lock_bh(&priv->sta_lock); | ||
723 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
724 | if (ctx->ctxid != priv->stations[i].ctxid) | ||
725 | continue; | ||
726 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && | ||
727 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { | ||
728 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", | ||
729 | priv->stations[i].sta.sta.addr); | ||
730 | priv->stations[i].sta.mode = 0; | ||
731 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; | ||
732 | found = true; | ||
733 | } | ||
734 | } | ||
735 | |||
736 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
737 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { | ||
738 | memcpy(&sta_cmd, &priv->stations[i].sta, | ||
739 | sizeof(struct iwl_addsta_cmd)); | ||
740 | send_lq = false; | ||
741 | if (priv->stations[i].lq) { | ||
742 | if (priv->wowlan) | ||
743 | iwl_sta_fill_lq(priv, ctx, i, &lq); | ||
744 | else | ||
745 | memcpy(&lq, priv->stations[i].lq, | ||
746 | sizeof(struct iwl_link_quality_cmd)); | ||
747 | send_lq = true; | ||
748 | } | ||
749 | spin_unlock_bh(&priv->sta_lock); | ||
750 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
751 | if (ret) { | ||
752 | spin_lock_bh(&priv->sta_lock); | ||
753 | IWL_ERR(priv, "Adding station %pM failed.\n", | ||
754 | priv->stations[i].sta.sta.addr); | ||
755 | priv->stations[i].used &= | ||
756 | ~IWL_STA_DRIVER_ACTIVE; | ||
757 | priv->stations[i].used &= | ||
758 | ~IWL_STA_UCODE_INPROGRESS; | ||
759 | continue; | ||
760 | } | ||
761 | /* | ||
762 | * Rate scaling has already been initialized, send | ||
763 | * current LQ command | ||
764 | */ | ||
765 | if (send_lq) | ||
766 | iwl_send_lq_cmd(priv, ctx, &lq, | ||
767 | CMD_SYNC, true); | ||
768 | spin_lock_bh(&priv->sta_lock); | ||
769 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
770 | } | ||
771 | } | ||
772 | |||
773 | spin_unlock_bh(&priv->sta_lock); | ||
774 | if (!found) | ||
775 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... " | ||
776 | "no stations to be restored.\n"); | ||
777 | else | ||
778 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... " | ||
779 | "complete.\n"); | ||
780 | } | ||
781 | |||
782 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv) | ||
783 | { | ||
784 | int i; | ||
785 | |||
786 | for (i = 0; i < priv->sta_key_max_num; i++) | ||
787 | if (!test_and_set_bit(i, &priv->ucode_key_table)) | ||
788 | return i; | ||
789 | |||
790 | return WEP_INVALID_OFFSET; | ||
791 | } | ||
792 | |||
793 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv) | ||
794 | { | ||
795 | int i; | ||
796 | |||
797 | spin_lock_bh(&priv->sta_lock); | ||
798 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
799 | if (!(priv->stations[i].used & IWL_STA_BCAST)) | ||
800 | continue; | ||
801 | |||
802 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | ||
803 | priv->num_stations--; | ||
804 | if (WARN_ON(priv->num_stations < 0)) | ||
805 | priv->num_stations = 0; | ||
806 | kfree(priv->stations[i].lq); | ||
807 | priv->stations[i].lq = NULL; | ||
808 | } | ||
809 | spin_unlock_bh(&priv->sta_lock); | ||
810 | } | ||
811 | |||
812 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
813 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, | ||
814 | struct iwl_link_quality_cmd *lq) | ||
815 | { | ||
816 | int i; | ||
817 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); | ||
818 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", | ||
819 | lq->general_params.single_stream_ant_msk, | ||
820 | lq->general_params.dual_stream_ant_msk); | ||
821 | |||
822 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) | ||
823 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", | ||
824 | i, lq->rs_table[i].rate_n_flags); | ||
825 | } | ||
826 | #else | ||
827 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, | ||
828 | struct iwl_link_quality_cmd *lq) | ||
829 | { | ||
830 | } | ||
831 | #endif | ||
832 | |||
833 | /** | ||
834 | * is_lq_table_valid() - Test one aspect of LQ cmd for validity | ||
835 | * | ||
836 | * It sometimes happens when a HT rate has been in use and we | ||
837 | * loose connectivity with AP then mac80211 will first tell us that the | ||
838 | * current channel is not HT anymore before removing the station. In such a | ||
839 | * scenario the RXON flags will be updated to indicate we are not | ||
840 | * communicating HT anymore, but the LQ command may still contain HT rates. | ||
841 | * Test for this to prevent driver from sending LQ command between the time | ||
842 | * RXON flags are updated and when LQ command is updated. | ||
843 | */ | ||
844 | static bool is_lq_table_valid(struct iwl_priv *priv, | ||
845 | struct iwl_rxon_context *ctx, | ||
846 | struct iwl_link_quality_cmd *lq) | ||
847 | { | ||
848 | int i; | ||
849 | |||
850 | if (ctx->ht.enabled) | ||
851 | return true; | ||
852 | |||
853 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", | ||
854 | ctx->active.channel); | ||
855 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { | ||
856 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & | ||
857 | RATE_MCS_HT_MSK) { | ||
858 | IWL_DEBUG_INFO(priv, | ||
859 | "index %d of LQ expects HT channel\n", | ||
860 | i); | ||
861 | return false; | ||
862 | } | ||
863 | } | ||
864 | return true; | ||
865 | } | ||
866 | |||
867 | /** | ||
868 | * iwl_send_lq_cmd() - Send link quality command | ||
869 | * @init: This command is sent as part of station initialization right | ||
870 | * after station has been added. | ||
871 | * | ||
872 | * The link quality command is sent as the last step of station creation. | ||
873 | * This is the special case in which init is set and we call a callback in | ||
874 | * this case to clear the state indicating that station creation is in | ||
875 | * progress. | ||
876 | */ | ||
877 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
878 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) | ||
879 | { | ||
880 | int ret = 0; | ||
881 | struct iwl_host_cmd cmd = { | ||
882 | .id = REPLY_TX_LINK_QUALITY_CMD, | ||
883 | .len = { sizeof(struct iwl_link_quality_cmd), }, | ||
884 | .flags = flags, | ||
885 | .data = { lq, }, | ||
886 | }; | ||
887 | |||
888 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) | ||
889 | return -EINVAL; | ||
890 | |||
891 | |||
892 | spin_lock_bh(&priv->sta_lock); | ||
893 | if (!(priv->stations[lq->sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
894 | spin_unlock_bh(&priv->sta_lock); | ||
895 | return -EINVAL; | ||
896 | } | ||
897 | spin_unlock_bh(&priv->sta_lock); | ||
898 | |||
899 | iwl_dump_lq_cmd(priv, lq); | ||
900 | if (WARN_ON(init && (cmd.flags & CMD_ASYNC))) | ||
901 | return -EINVAL; | ||
902 | |||
903 | if (is_lq_table_valid(priv, ctx, lq)) | ||
904 | ret = iwl_dvm_send_cmd(priv, &cmd); | ||
905 | else | ||
906 | ret = -EINVAL; | ||
907 | |||
908 | if (cmd.flags & CMD_ASYNC) | ||
909 | return ret; | ||
910 | |||
911 | if (init) { | ||
912 | IWL_DEBUG_INFO(priv, "init LQ command complete, " | ||
913 | "clearing sta addition status for sta %d\n", | ||
914 | lq->sta_id); | ||
915 | spin_lock_bh(&priv->sta_lock); | ||
916 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
917 | spin_unlock_bh(&priv->sta_lock); | ||
918 | } | ||
919 | return ret; | ||
920 | } | ||
921 | |||
922 | |||
923 | static struct iwl_link_quality_cmd * | ||
924 | iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
925 | u8 sta_id) | ||
926 | { | ||
927 | struct iwl_link_quality_cmd *link_cmd; | ||
928 | |||
929 | link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL); | ||
930 | if (!link_cmd) { | ||
931 | IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n"); | ||
932 | return NULL; | ||
933 | } | ||
934 | |||
935 | iwl_sta_fill_lq(priv, ctx, sta_id, link_cmd); | ||
936 | |||
937 | return link_cmd; | ||
938 | } | ||
939 | |||
940 | /* | ||
941 | * iwlagn_add_bssid_station - Add the special IBSS BSSID station | ||
942 | * | ||
943 | * Function sleeps. | ||
944 | */ | ||
945 | int iwlagn_add_bssid_station(struct iwl_priv *priv, | ||
946 | struct iwl_rxon_context *ctx, | ||
947 | const u8 *addr, u8 *sta_id_r) | ||
948 | { | ||
949 | int ret; | ||
950 | u8 sta_id; | ||
951 | struct iwl_link_quality_cmd *link_cmd; | ||
952 | |||
953 | if (sta_id_r) | ||
954 | *sta_id_r = IWL_INVALID_STATION; | ||
955 | |||
956 | ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id); | ||
957 | if (ret) { | ||
958 | IWL_ERR(priv, "Unable to add station %pM\n", addr); | ||
959 | return ret; | ||
960 | } | ||
961 | |||
962 | if (sta_id_r) | ||
963 | *sta_id_r = sta_id; | ||
964 | |||
965 | spin_lock_bh(&priv->sta_lock); | ||
966 | priv->stations[sta_id].used |= IWL_STA_LOCAL; | ||
967 | spin_unlock_bh(&priv->sta_lock); | ||
968 | |||
969 | /* Set up default rate scaling table in device's station table */ | ||
970 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); | ||
971 | if (!link_cmd) { | ||
972 | IWL_ERR(priv, | ||
973 | "Unable to initialize rate scaling for station %pM.\n", | ||
974 | addr); | ||
975 | return -ENOMEM; | ||
976 | } | ||
977 | |||
978 | ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true); | ||
979 | if (ret) | ||
980 | IWL_ERR(priv, "Link quality command failed (%d)\n", ret); | ||
981 | |||
982 | spin_lock_bh(&priv->sta_lock); | ||
983 | priv->stations[sta_id].lq = link_cmd; | ||
984 | spin_unlock_bh(&priv->sta_lock); | ||
985 | |||
986 | return 0; | ||
987 | } | ||
988 | |||
989 | /* | ||
990 | * static WEP keys | ||
991 | * | ||
992 | * For each context, the device has a table of 4 static WEP keys | ||
993 | * (one for each key index) that is updated with the following | ||
994 | * commands. | ||
995 | */ | ||
996 | |||
997 | static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, | ||
998 | struct iwl_rxon_context *ctx, | ||
999 | bool send_if_empty) | ||
1000 | { | ||
1001 | int i, not_empty = 0; | ||
1002 | u8 buff[sizeof(struct iwl_wep_cmd) + | ||
1003 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; | ||
1004 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; | ||
1005 | size_t cmd_size = sizeof(struct iwl_wep_cmd); | ||
1006 | struct iwl_host_cmd cmd = { | ||
1007 | .id = ctx->wep_key_cmd, | ||
1008 | .data = { wep_cmd, }, | ||
1009 | .flags = CMD_SYNC, | ||
1010 | }; | ||
1011 | |||
1012 | might_sleep(); | ||
1013 | |||
1014 | memset(wep_cmd, 0, cmd_size + | ||
1015 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); | ||
1016 | |||
1017 | for (i = 0; i < WEP_KEYS_MAX ; i++) { | ||
1018 | wep_cmd->key[i].key_index = i; | ||
1019 | if (ctx->wep_keys[i].key_size) { | ||
1020 | wep_cmd->key[i].key_offset = i; | ||
1021 | not_empty = 1; | ||
1022 | } else { | ||
1023 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; | ||
1024 | } | ||
1025 | |||
1026 | wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size; | ||
1027 | memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key, | ||
1028 | ctx->wep_keys[i].key_size); | ||
1029 | } | ||
1030 | |||
1031 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; | ||
1032 | wep_cmd->num_keys = WEP_KEYS_MAX; | ||
1033 | |||
1034 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; | ||
1035 | |||
1036 | cmd.len[0] = cmd_size; | ||
1037 | |||
1038 | if (not_empty || send_if_empty) | ||
1039 | return iwl_dvm_send_cmd(priv, &cmd); | ||
1040 | else | ||
1041 | return 0; | ||
1042 | } | ||
1043 | |||
1044 | int iwl_restore_default_wep_keys(struct iwl_priv *priv, | ||
1045 | struct iwl_rxon_context *ctx) | ||
1046 | { | ||
1047 | lockdep_assert_held(&priv->mutex); | ||
1048 | |||
1049 | return iwl_send_static_wepkey_cmd(priv, ctx, false); | ||
1050 | } | ||
1051 | |||
1052 | int iwl_remove_default_wep_key(struct iwl_priv *priv, | ||
1053 | struct iwl_rxon_context *ctx, | ||
1054 | struct ieee80211_key_conf *keyconf) | ||
1055 | { | ||
1056 | int ret; | ||
1057 | |||
1058 | lockdep_assert_held(&priv->mutex); | ||
1059 | |||
1060 | IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", | ||
1061 | keyconf->keyidx); | ||
1062 | |||
1063 | memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0])); | ||
1064 | if (iwl_is_rfkill(priv)) { | ||
1065 | IWL_DEBUG_WEP(priv, | ||
1066 | "Not sending REPLY_WEPKEY command due to RFKILL.\n"); | ||
1067 | /* but keys in device are clear anyway so return success */ | ||
1068 | return 0; | ||
1069 | } | ||
1070 | ret = iwl_send_static_wepkey_cmd(priv, ctx, 1); | ||
1071 | IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", | ||
1072 | keyconf->keyidx, ret); | ||
1073 | |||
1074 | return ret; | ||
1075 | } | ||
1076 | |||
1077 | int iwl_set_default_wep_key(struct iwl_priv *priv, | ||
1078 | struct iwl_rxon_context *ctx, | ||
1079 | struct ieee80211_key_conf *keyconf) | ||
1080 | { | ||
1081 | int ret; | ||
1082 | |||
1083 | lockdep_assert_held(&priv->mutex); | ||
1084 | |||
1085 | if (keyconf->keylen != WEP_KEY_LEN_128 && | ||
1086 | keyconf->keylen != WEP_KEY_LEN_64) { | ||
1087 | IWL_DEBUG_WEP(priv, | ||
1088 | "Bad WEP key length %d\n", keyconf->keylen); | ||
1089 | return -EINVAL; | ||
1090 | } | ||
1091 | |||
1092 | keyconf->hw_key_idx = IWLAGN_HW_KEY_DEFAULT; | ||
1093 | |||
1094 | ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; | ||
1095 | memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key, | ||
1096 | keyconf->keylen); | ||
1097 | |||
1098 | ret = iwl_send_static_wepkey_cmd(priv, ctx, false); | ||
1099 | IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", | ||
1100 | keyconf->keylen, keyconf->keyidx, ret); | ||
1101 | |||
1102 | return ret; | ||
1103 | } | ||
1104 | |||
1105 | /* | ||
1106 | * dynamic (per-station) keys | ||
1107 | * | ||
1108 | * The dynamic keys are a little more complicated. The device has | ||
1109 | * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys. | ||
1110 | * These are linked to stations by a table that contains an index | ||
1111 | * into the key table for each station/key index/{mcast,unicast}, | ||
1112 | * i.e. it's basically an array of pointers like this: | ||
1113 | * key_offset_t key_mapping[NUM_STATIONS][4][2]; | ||
1114 | * (it really works differently, but you can think of it as such) | ||
1115 | * | ||
1116 | * The key uploading and linking happens in the same command, the | ||
1117 | * add station command with STA_MODIFY_KEY_MASK. | ||
1118 | */ | ||
1119 | |||
1120 | static u8 iwlagn_key_sta_id(struct iwl_priv *priv, | ||
1121 | struct ieee80211_vif *vif, | ||
1122 | struct ieee80211_sta *sta) | ||
1123 | { | ||
1124 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; | ||
1125 | |||
1126 | if (sta) | ||
1127 | return iwl_sta_id(sta); | ||
1128 | |||
1129 | /* | ||
1130 | * The device expects GTKs for station interfaces to be | ||
1131 | * installed as GTKs for the AP station. If we have no | ||
1132 | * station ID, then use the ap_sta_id in that case. | ||
1133 | */ | ||
1134 | if (vif->type == NL80211_IFTYPE_STATION && vif_priv->ctx) | ||
1135 | return vif_priv->ctx->ap_sta_id; | ||
1136 | |||
1137 | return IWL_INVALID_STATION; | ||
1138 | } | ||
1139 | |||
1140 | static int iwlagn_send_sta_key(struct iwl_priv *priv, | ||
1141 | struct ieee80211_key_conf *keyconf, | ||
1142 | u8 sta_id, u32 tkip_iv32, u16 *tkip_p1k, | ||
1143 | u32 cmd_flags) | ||
1144 | { | ||
1145 | __le16 key_flags; | ||
1146 | struct iwl_addsta_cmd sta_cmd; | ||
1147 | int i; | ||
1148 | |||
1149 | spin_lock_bh(&priv->sta_lock); | ||
1150 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); | ||
1151 | spin_unlock_bh(&priv->sta_lock); | ||
1152 | |||
1153 | key_flags = cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | ||
1154 | key_flags |= STA_KEY_FLG_MAP_KEY_MSK; | ||
1155 | |||
1156 | switch (keyconf->cipher) { | ||
1157 | case WLAN_CIPHER_SUITE_CCMP: | ||
1158 | key_flags |= STA_KEY_FLG_CCMP; | ||
1159 | memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen); | ||
1160 | break; | ||
1161 | case WLAN_CIPHER_SUITE_TKIP: | ||
1162 | key_flags |= STA_KEY_FLG_TKIP; | ||
1163 | sta_cmd.key.tkip_rx_tsc_byte2 = tkip_iv32; | ||
1164 | for (i = 0; i < 5; i++) | ||
1165 | sta_cmd.key.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); | ||
1166 | memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen); | ||
1167 | break; | ||
1168 | case WLAN_CIPHER_SUITE_WEP104: | ||
1169 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; | ||
1170 | /* fall through */ | ||
1171 | case WLAN_CIPHER_SUITE_WEP40: | ||
1172 | key_flags |= STA_KEY_FLG_WEP; | ||
1173 | memcpy(&sta_cmd.key.key[3], keyconf->key, keyconf->keylen); | ||
1174 | break; | ||
1175 | default: | ||
1176 | WARN_ON(1); | ||
1177 | return -EINVAL; | ||
1178 | } | ||
1179 | |||
1180 | if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) | ||
1181 | key_flags |= STA_KEY_MULTICAST_MSK; | ||
1182 | |||
1183 | /* key pointer (offset) */ | ||
1184 | sta_cmd.key.key_offset = keyconf->hw_key_idx; | ||
1185 | |||
1186 | sta_cmd.key.key_flags = key_flags; | ||
1187 | sta_cmd.mode = STA_CONTROL_MODIFY_MSK; | ||
1188 | sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK; | ||
1189 | |||
1190 | return iwl_send_add_sta(priv, &sta_cmd, cmd_flags); | ||
1191 | } | ||
1192 | |||
1193 | void iwl_update_tkip_key(struct iwl_priv *priv, | ||
1194 | struct ieee80211_vif *vif, | ||
1195 | struct ieee80211_key_conf *keyconf, | ||
1196 | struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) | ||
1197 | { | ||
1198 | u8 sta_id = iwlagn_key_sta_id(priv, vif, sta); | ||
1199 | |||
1200 | if (sta_id == IWL_INVALID_STATION) | ||
1201 | return; | ||
1202 | |||
1203 | if (iwl_scan_cancel(priv)) { | ||
1204 | /* cancel scan failed, just live w/ bad key and rely | ||
1205 | briefly on SW decryption */ | ||
1206 | return; | ||
1207 | } | ||
1208 | |||
1209 | iwlagn_send_sta_key(priv, keyconf, sta_id, | ||
1210 | iv32, phase1key, CMD_ASYNC); | ||
1211 | } | ||
1212 | |||
1213 | int iwl_remove_dynamic_key(struct iwl_priv *priv, | ||
1214 | struct iwl_rxon_context *ctx, | ||
1215 | struct ieee80211_key_conf *keyconf, | ||
1216 | struct ieee80211_sta *sta) | ||
1217 | { | ||
1218 | struct iwl_addsta_cmd sta_cmd; | ||
1219 | u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta); | ||
1220 | __le16 key_flags; | ||
1221 | |||
1222 | /* if station isn't there, neither is the key */ | ||
1223 | if (sta_id == IWL_INVALID_STATION) | ||
1224 | return -ENOENT; | ||
1225 | |||
1226 | spin_lock_bh(&priv->sta_lock); | ||
1227 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); | ||
1228 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) | ||
1229 | sta_id = IWL_INVALID_STATION; | ||
1230 | spin_unlock_bh(&priv->sta_lock); | ||
1231 | |||
1232 | if (sta_id == IWL_INVALID_STATION) | ||
1233 | return 0; | ||
1234 | |||
1235 | lockdep_assert_held(&priv->mutex); | ||
1236 | |||
1237 | ctx->key_mapping_keys--; | ||
1238 | |||
1239 | IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n", | ||
1240 | keyconf->keyidx, sta_id); | ||
1241 | |||
1242 | if (!test_and_clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table)) | ||
1243 | IWL_ERR(priv, "offset %d not used in uCode key table.\n", | ||
1244 | keyconf->hw_key_idx); | ||
1245 | |||
1246 | key_flags = cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | ||
1247 | key_flags |= STA_KEY_FLG_MAP_KEY_MSK | STA_KEY_FLG_NO_ENC | | ||
1248 | STA_KEY_FLG_INVALID; | ||
1249 | |||
1250 | if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) | ||
1251 | key_flags |= STA_KEY_MULTICAST_MSK; | ||
1252 | |||
1253 | sta_cmd.key.key_flags = key_flags; | ||
1254 | sta_cmd.key.key_offset = WEP_INVALID_OFFSET; | ||
1255 | sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK; | ||
1256 | sta_cmd.mode = STA_CONTROL_MODIFY_MSK; | ||
1257 | |||
1258 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1259 | } | ||
1260 | |||
1261 | int iwl_set_dynamic_key(struct iwl_priv *priv, | ||
1262 | struct iwl_rxon_context *ctx, | ||
1263 | struct ieee80211_key_conf *keyconf, | ||
1264 | struct ieee80211_sta *sta) | ||
1265 | { | ||
1266 | struct ieee80211_key_seq seq; | ||
1267 | u16 p1k[5]; | ||
1268 | int ret; | ||
1269 | u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta); | ||
1270 | const u8 *addr; | ||
1271 | |||
1272 | if (sta_id == IWL_INVALID_STATION) | ||
1273 | return -EINVAL; | ||
1274 | |||
1275 | lockdep_assert_held(&priv->mutex); | ||
1276 | |||
1277 | keyconf->hw_key_idx = iwl_get_free_ucode_key_offset(priv); | ||
1278 | if (keyconf->hw_key_idx == WEP_INVALID_OFFSET) | ||
1279 | return -ENOSPC; | ||
1280 | |||
1281 | ctx->key_mapping_keys++; | ||
1282 | |||
1283 | switch (keyconf->cipher) { | ||
1284 | case WLAN_CIPHER_SUITE_TKIP: | ||
1285 | if (sta) | ||
1286 | addr = sta->addr; | ||
1287 | else /* station mode case only */ | ||
1288 | addr = ctx->active.bssid_addr; | ||
1289 | |||
1290 | /* pre-fill phase 1 key into device cache */ | ||
1291 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); | ||
1292 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); | ||
1293 | ret = iwlagn_send_sta_key(priv, keyconf, sta_id, | ||
1294 | seq.tkip.iv32, p1k, CMD_SYNC); | ||
1295 | break; | ||
1296 | case WLAN_CIPHER_SUITE_CCMP: | ||
1297 | case WLAN_CIPHER_SUITE_WEP40: | ||
1298 | case WLAN_CIPHER_SUITE_WEP104: | ||
1299 | ret = iwlagn_send_sta_key(priv, keyconf, sta_id, | ||
1300 | 0, NULL, CMD_SYNC); | ||
1301 | break; | ||
1302 | default: | ||
1303 | IWL_ERR(priv, "Unknown cipher %x\n", keyconf->cipher); | ||
1304 | ret = -EINVAL; | ||
1305 | } | ||
1306 | |||
1307 | if (ret) { | ||
1308 | ctx->key_mapping_keys--; | ||
1309 | clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table); | ||
1310 | } | ||
1311 | |||
1312 | IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", | ||
1313 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, | ||
1314 | sta ? sta->addr : NULL, ret); | ||
1315 | |||
1316 | return ret; | ||
1317 | } | ||
1318 | |||
1319 | /** | ||
1320 | * iwlagn_alloc_bcast_station - add broadcast station into driver's station table. | ||
1321 | * | ||
1322 | * This adds the broadcast station into the driver's station table | ||
1323 | * and marks it driver active, so that it will be restored to the | ||
1324 | * device at the next best time. | ||
1325 | */ | ||
1326 | int iwlagn_alloc_bcast_station(struct iwl_priv *priv, | ||
1327 | struct iwl_rxon_context *ctx) | ||
1328 | { | ||
1329 | struct iwl_link_quality_cmd *link_cmd; | ||
1330 | u8 sta_id; | ||
1331 | |||
1332 | spin_lock_bh(&priv->sta_lock); | ||
1333 | sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL); | ||
1334 | if (sta_id == IWL_INVALID_STATION) { | ||
1335 | IWL_ERR(priv, "Unable to prepare broadcast station\n"); | ||
1336 | spin_unlock_bh(&priv->sta_lock); | ||
1337 | |||
1338 | return -EINVAL; | ||
1339 | } | ||
1340 | |||
1341 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; | ||
1342 | priv->stations[sta_id].used |= IWL_STA_BCAST; | ||
1343 | spin_unlock_bh(&priv->sta_lock); | ||
1344 | |||
1345 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); | ||
1346 | if (!link_cmd) { | ||
1347 | IWL_ERR(priv, | ||
1348 | "Unable to initialize rate scaling for bcast station.\n"); | ||
1349 | return -ENOMEM; | ||
1350 | } | ||
1351 | |||
1352 | spin_lock_bh(&priv->sta_lock); | ||
1353 | priv->stations[sta_id].lq = link_cmd; | ||
1354 | spin_unlock_bh(&priv->sta_lock); | ||
1355 | |||
1356 | return 0; | ||
1357 | } | ||
1358 | |||
1359 | /** | ||
1360 | * iwl_update_bcast_station - update broadcast station's LQ command | ||
1361 | * | ||
1362 | * Only used by iwlagn. Placed here to have all bcast station management | ||
1363 | * code together. | ||
1364 | */ | ||
1365 | int iwl_update_bcast_station(struct iwl_priv *priv, | ||
1366 | struct iwl_rxon_context *ctx) | ||
1367 | { | ||
1368 | struct iwl_link_quality_cmd *link_cmd; | ||
1369 | u8 sta_id = ctx->bcast_sta_id; | ||
1370 | |||
1371 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); | ||
1372 | if (!link_cmd) { | ||
1373 | IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n"); | ||
1374 | return -ENOMEM; | ||
1375 | } | ||
1376 | |||
1377 | spin_lock_bh(&priv->sta_lock); | ||
1378 | if (priv->stations[sta_id].lq) | ||
1379 | kfree(priv->stations[sta_id].lq); | ||
1380 | else | ||
1381 | IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n"); | ||
1382 | priv->stations[sta_id].lq = link_cmd; | ||
1383 | spin_unlock_bh(&priv->sta_lock); | ||
1384 | |||
1385 | return 0; | ||
1386 | } | ||
1387 | |||
1388 | int iwl_update_bcast_stations(struct iwl_priv *priv) | ||
1389 | { | ||
1390 | struct iwl_rxon_context *ctx; | ||
1391 | int ret = 0; | ||
1392 | |||
1393 | for_each_context(priv, ctx) { | ||
1394 | ret = iwl_update_bcast_station(priv, ctx); | ||
1395 | if (ret) | ||
1396 | break; | ||
1397 | } | ||
1398 | |||
1399 | return ret; | ||
1400 | } | ||
1401 | |||
1402 | /** | ||
1403 | * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table | ||
1404 | */ | ||
1405 | int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid) | ||
1406 | { | ||
1407 | struct iwl_addsta_cmd sta_cmd; | ||
1408 | |||
1409 | lockdep_assert_held(&priv->mutex); | ||
1410 | |||
1411 | /* Remove "disable" flag, to enable Tx for this TID */ | ||
1412 | spin_lock_bh(&priv->sta_lock); | ||
1413 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; | ||
1414 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); | ||
1415 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1416 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
1417 | spin_unlock_bh(&priv->sta_lock); | ||
1418 | |||
1419 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1420 | } | ||
1421 | |||
1422 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, | ||
1423 | int tid, u16 ssn) | ||
1424 | { | ||
1425 | int sta_id; | ||
1426 | struct iwl_addsta_cmd sta_cmd; | ||
1427 | |||
1428 | lockdep_assert_held(&priv->mutex); | ||
1429 | |||
1430 | sta_id = iwl_sta_id(sta); | ||
1431 | if (sta_id == IWL_INVALID_STATION) | ||
1432 | return -ENXIO; | ||
1433 | |||
1434 | spin_lock_bh(&priv->sta_lock); | ||
1435 | priv->stations[sta_id].sta.station_flags_msk = 0; | ||
1436 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; | ||
1437 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; | ||
1438 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); | ||
1439 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1440 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
1441 | spin_unlock_bh(&priv->sta_lock); | ||
1442 | |||
1443 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1444 | } | ||
1445 | |||
1446 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, | ||
1447 | int tid) | ||
1448 | { | ||
1449 | int sta_id; | ||
1450 | struct iwl_addsta_cmd sta_cmd; | ||
1451 | |||
1452 | lockdep_assert_held(&priv->mutex); | ||
1453 | |||
1454 | sta_id = iwl_sta_id(sta); | ||
1455 | if (sta_id == IWL_INVALID_STATION) { | ||
1456 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); | ||
1457 | return -ENXIO; | ||
1458 | } | ||
1459 | |||
1460 | spin_lock_bh(&priv->sta_lock); | ||
1461 | priv->stations[sta_id].sta.station_flags_msk = 0; | ||
1462 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; | ||
1463 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; | ||
1464 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1465 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
1466 | spin_unlock_bh(&priv->sta_lock); | ||
1467 | |||
1468 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1469 | } | ||
1470 | |||
1471 | |||
1472 | |||
1473 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt) | ||
1474 | { | ||
1475 | struct iwl_addsta_cmd cmd = { | ||
1476 | .mode = STA_CONTROL_MODIFY_MSK, | ||
1477 | .station_flags = STA_FLG_PWR_SAVE_MSK, | ||
1478 | .station_flags_msk = STA_FLG_PWR_SAVE_MSK, | ||
1479 | .sta.sta_id = sta_id, | ||
1480 | .sta.modify_mask = STA_MODIFY_SLEEP_TX_COUNT_MSK, | ||
1481 | .sleep_tx_count = cpu_to_le16(cnt), | ||
1482 | }; | ||
1483 | |||
1484 | iwl_send_add_sta(priv, &cmd, CMD_ASYNC); | ||
1485 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/testmode.c b/drivers/net/wireless/iwlwifi/dvm/testmode.c new file mode 100644 index 000000000000..e08b1a383594 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/testmode.c | |||
@@ -0,0 +1,1113 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
4 | * redistributing this file, you may do so under either license. | ||
5 | * | ||
6 | * GPL LICENSE SUMMARY | ||
7 | * | ||
8 | * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of version 2 of the GNU General Public License as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
22 | * USA | ||
23 | * | ||
24 | * The full GNU General Public License is included in this distribution | ||
25 | * in the file called LICENSE.GPL. | ||
26 | * | ||
27 | * Contact Information: | ||
28 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
30 | * | ||
31 | * BSD LICENSE | ||
32 | * | ||
33 | * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved. | ||
34 | * All rights reserved. | ||
35 | * | ||
36 | * Redistribution and use in source and binary forms, with or without | ||
37 | * modification, are permitted provided that the following conditions | ||
38 | * are met: | ||
39 | * | ||
40 | * * Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * * Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in | ||
44 | * the documentation and/or other materials provided with the | ||
45 | * distribution. | ||
46 | * * Neither the name Intel Corporation nor the names of its | ||
47 | * contributors may be used to endorse or promote products derived | ||
48 | * from this software without specific prior written permission. | ||
49 | * | ||
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
61 | * | ||
62 | *****************************************************************************/ | ||
63 | #include <linux/init.h> | ||
64 | #include <linux/kernel.h> | ||
65 | #include <linux/module.h> | ||
66 | #include <linux/dma-mapping.h> | ||
67 | #include <net/net_namespace.h> | ||
68 | #include <linux/netdevice.h> | ||
69 | #include <net/cfg80211.h> | ||
70 | #include <net/mac80211.h> | ||
71 | #include <net/netlink.h> | ||
72 | #include "iwl-debug.h" | ||
73 | #include "iwl-io.h" | ||
74 | #include "iwl-trans.h" | ||
75 | #include "iwl-fh.h" | ||
76 | #include "iwl-prph.h" | ||
77 | #include "dev.h" | ||
78 | #include "agn.h" | ||
79 | #include "testmode.h" | ||
80 | |||
81 | |||
82 | /* Periphery registers absolute lower bound. This is used in order to | ||
83 | * differentiate registery access through HBUS_TARG_PRPH_* and | ||
84 | * HBUS_TARG_MEM_* accesses. | ||
85 | */ | ||
86 | #define IWL_TM_ABS_PRPH_START (0xA00000) | ||
87 | |||
88 | /* The TLVs used in the gnl message policy between the kernel module and | ||
89 | * user space application. iwl_testmode_gnl_msg_policy is to be carried | ||
90 | * through the NL80211_CMD_TESTMODE channel regulated by nl80211. | ||
91 | * See testmode.h | ||
92 | */ | ||
93 | static | ||
94 | struct nla_policy iwl_testmode_gnl_msg_policy[IWL_TM_ATTR_MAX] = { | ||
95 | [IWL_TM_ATTR_COMMAND] = { .type = NLA_U32, }, | ||
96 | |||
97 | [IWL_TM_ATTR_UCODE_CMD_ID] = { .type = NLA_U8, }, | ||
98 | [IWL_TM_ATTR_UCODE_CMD_DATA] = { .type = NLA_UNSPEC, }, | ||
99 | |||
100 | [IWL_TM_ATTR_REG_OFFSET] = { .type = NLA_U32, }, | ||
101 | [IWL_TM_ATTR_REG_VALUE8] = { .type = NLA_U8, }, | ||
102 | [IWL_TM_ATTR_REG_VALUE32] = { .type = NLA_U32, }, | ||
103 | |||
104 | [IWL_TM_ATTR_SYNC_RSP] = { .type = NLA_UNSPEC, }, | ||
105 | [IWL_TM_ATTR_UCODE_RX_PKT] = { .type = NLA_UNSPEC, }, | ||
106 | |||
107 | [IWL_TM_ATTR_EEPROM] = { .type = NLA_UNSPEC, }, | ||
108 | |||
109 | [IWL_TM_ATTR_TRACE_ADDR] = { .type = NLA_UNSPEC, }, | ||
110 | [IWL_TM_ATTR_TRACE_DUMP] = { .type = NLA_UNSPEC, }, | ||
111 | [IWL_TM_ATTR_TRACE_SIZE] = { .type = NLA_U32, }, | ||
112 | |||
113 | [IWL_TM_ATTR_FIXRATE] = { .type = NLA_U32, }, | ||
114 | |||
115 | [IWL_TM_ATTR_UCODE_OWNER] = { .type = NLA_U8, }, | ||
116 | |||
117 | [IWL_TM_ATTR_MEM_ADDR] = { .type = NLA_U32, }, | ||
118 | [IWL_TM_ATTR_BUFFER_SIZE] = { .type = NLA_U32, }, | ||
119 | [IWL_TM_ATTR_BUFFER_DUMP] = { .type = NLA_UNSPEC, }, | ||
120 | |||
121 | [IWL_TM_ATTR_FW_VERSION] = { .type = NLA_U32, }, | ||
122 | [IWL_TM_ATTR_DEVICE_ID] = { .type = NLA_U32, }, | ||
123 | [IWL_TM_ATTR_FW_TYPE] = { .type = NLA_U32, }, | ||
124 | [IWL_TM_ATTR_FW_INST_SIZE] = { .type = NLA_U32, }, | ||
125 | [IWL_TM_ATTR_FW_DATA_SIZE] = { .type = NLA_U32, }, | ||
126 | |||
127 | [IWL_TM_ATTR_ENABLE_NOTIFICATION] = {.type = NLA_FLAG, }, | ||
128 | }; | ||
129 | |||
130 | /* | ||
131 | * See the struct iwl_rx_packet in commands.h for the format of the | ||
132 | * received events from the device | ||
133 | */ | ||
134 | static inline int get_event_length(struct iwl_rx_cmd_buffer *rxb) | ||
135 | { | ||
136 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
137 | if (pkt) | ||
138 | return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | ||
139 | else | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | |||
144 | /* | ||
145 | * This function multicasts the spontaneous messages from the device to the | ||
146 | * user space. It is invoked whenever there is a received messages | ||
147 | * from the device. This function is called within the ISR of the rx handlers | ||
148 | * in iwlagn driver. | ||
149 | * | ||
150 | * The parsing of the message content is left to the user space application, | ||
151 | * The message content is treated as unattacked raw data and is encapsulated | ||
152 | * with IWL_TM_ATTR_UCODE_RX_PKT multicasting to the user space. | ||
153 | * | ||
154 | * @priv: the instance of iwlwifi device | ||
155 | * @rxb: pointer to rx data content received by the ISR | ||
156 | * | ||
157 | * See the message policies and TLVs in iwl_testmode_gnl_msg_policy[]. | ||
158 | * For the messages multicasting to the user application, the mandatory | ||
159 | * TLV fields are : | ||
160 | * IWL_TM_ATTR_COMMAND must be IWL_TM_CMD_DEV2APP_UCODE_RX_PKT | ||
161 | * IWL_TM_ATTR_UCODE_RX_PKT for carrying the message content | ||
162 | */ | ||
163 | |||
164 | static void iwl_testmode_ucode_rx_pkt(struct iwl_priv *priv, | ||
165 | struct iwl_rx_cmd_buffer *rxb) | ||
166 | { | ||
167 | struct ieee80211_hw *hw = priv->hw; | ||
168 | struct sk_buff *skb; | ||
169 | void *data; | ||
170 | int length; | ||
171 | |||
172 | data = rxb_addr(rxb); | ||
173 | length = get_event_length(rxb); | ||
174 | |||
175 | if (!data || length == 0) | ||
176 | return; | ||
177 | |||
178 | skb = cfg80211_testmode_alloc_event_skb(hw->wiphy, 20 + length, | ||
179 | GFP_ATOMIC); | ||
180 | if (skb == NULL) { | ||
181 | IWL_ERR(priv, | ||
182 | "Run out of memory for messages to user space ?\n"); | ||
183 | return; | ||
184 | } | ||
185 | if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) || | ||
186 | /* the length doesn't include len_n_flags field, so add it manually */ | ||
187 | nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, length + sizeof(__le32), data)) | ||
188 | goto nla_put_failure; | ||
189 | cfg80211_testmode_event(skb, GFP_ATOMIC); | ||
190 | return; | ||
191 | |||
192 | nla_put_failure: | ||
193 | kfree_skb(skb); | ||
194 | IWL_ERR(priv, "Ouch, overran buffer, check allocation!\n"); | ||
195 | } | ||
196 | |||
197 | void iwl_testmode_init(struct iwl_priv *priv) | ||
198 | { | ||
199 | priv->pre_rx_handler = NULL; | ||
200 | priv->testmode_trace.trace_enabled = false; | ||
201 | priv->testmode_mem.read_in_progress = false; | ||
202 | } | ||
203 | |||
204 | static void iwl_mem_cleanup(struct iwl_priv *priv) | ||
205 | { | ||
206 | if (priv->testmode_mem.read_in_progress) { | ||
207 | kfree(priv->testmode_mem.buff_addr); | ||
208 | priv->testmode_mem.buff_addr = NULL; | ||
209 | priv->testmode_mem.buff_size = 0; | ||
210 | priv->testmode_mem.num_chunks = 0; | ||
211 | priv->testmode_mem.read_in_progress = false; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | static void iwl_trace_cleanup(struct iwl_priv *priv) | ||
216 | { | ||
217 | if (priv->testmode_trace.trace_enabled) { | ||
218 | if (priv->testmode_trace.cpu_addr && | ||
219 | priv->testmode_trace.dma_addr) | ||
220 | dma_free_coherent(priv->trans->dev, | ||
221 | priv->testmode_trace.total_size, | ||
222 | priv->testmode_trace.cpu_addr, | ||
223 | priv->testmode_trace.dma_addr); | ||
224 | priv->testmode_trace.trace_enabled = false; | ||
225 | priv->testmode_trace.cpu_addr = NULL; | ||
226 | priv->testmode_trace.trace_addr = NULL; | ||
227 | priv->testmode_trace.dma_addr = 0; | ||
228 | priv->testmode_trace.buff_size = 0; | ||
229 | priv->testmode_trace.total_size = 0; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | |||
234 | void iwl_testmode_cleanup(struct iwl_priv *priv) | ||
235 | { | ||
236 | iwl_trace_cleanup(priv); | ||
237 | iwl_mem_cleanup(priv); | ||
238 | } | ||
239 | |||
240 | |||
241 | /* | ||
242 | * This function handles the user application commands to the ucode. | ||
243 | * | ||
244 | * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_CMD_ID and | ||
245 | * IWL_TM_ATTR_UCODE_CMD_DATA and calls to the handler to send the | ||
246 | * host command to the ucode. | ||
247 | * | ||
248 | * If any mandatory field is missing, -ENOMSG is replied to the user space | ||
249 | * application; otherwise, waits for the host command to be sent and checks | ||
250 | * the return code. In case or error, it is returned, otherwise a reply is | ||
251 | * allocated and the reply RX packet | ||
252 | * is returned. | ||
253 | * | ||
254 | * @hw: ieee80211_hw object that represents the device | ||
255 | * @tb: gnl message fields from the user space | ||
256 | */ | ||
257 | static int iwl_testmode_ucode(struct ieee80211_hw *hw, struct nlattr **tb) | ||
258 | { | ||
259 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
260 | struct iwl_host_cmd cmd; | ||
261 | struct iwl_rx_packet *pkt; | ||
262 | struct sk_buff *skb; | ||
263 | void *reply_buf; | ||
264 | u32 reply_len; | ||
265 | int ret; | ||
266 | bool cmd_want_skb; | ||
267 | |||
268 | memset(&cmd, 0, sizeof(struct iwl_host_cmd)); | ||
269 | |||
270 | if (!tb[IWL_TM_ATTR_UCODE_CMD_ID] || | ||
271 | !tb[IWL_TM_ATTR_UCODE_CMD_DATA]) { | ||
272 | IWL_ERR(priv, "Missing ucode command mandatory fields\n"); | ||
273 | return -ENOMSG; | ||
274 | } | ||
275 | |||
276 | cmd.flags = CMD_ON_DEMAND | CMD_SYNC; | ||
277 | cmd_want_skb = nla_get_flag(tb[IWL_TM_ATTR_UCODE_CMD_SKB]); | ||
278 | if (cmd_want_skb) | ||
279 | cmd.flags |= CMD_WANT_SKB; | ||
280 | |||
281 | cmd.id = nla_get_u8(tb[IWL_TM_ATTR_UCODE_CMD_ID]); | ||
282 | cmd.data[0] = nla_data(tb[IWL_TM_ATTR_UCODE_CMD_DATA]); | ||
283 | cmd.len[0] = nla_len(tb[IWL_TM_ATTR_UCODE_CMD_DATA]); | ||
284 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; | ||
285 | IWL_DEBUG_INFO(priv, "testmode ucode command ID 0x%x, flags 0x%x," | ||
286 | " len %d\n", cmd.id, cmd.flags, cmd.len[0]); | ||
287 | |||
288 | ret = iwl_dvm_send_cmd(priv, &cmd); | ||
289 | if (ret) { | ||
290 | IWL_ERR(priv, "Failed to send hcmd\n"); | ||
291 | return ret; | ||
292 | } | ||
293 | if (!cmd_want_skb) | ||
294 | return ret; | ||
295 | |||
296 | /* Handling return of SKB to the user */ | ||
297 | pkt = cmd.resp_pkt; | ||
298 | if (!pkt) { | ||
299 | IWL_ERR(priv, "HCMD received a null response packet\n"); | ||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | reply_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | ||
304 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, reply_len + 20); | ||
305 | reply_buf = kmalloc(reply_len, GFP_KERNEL); | ||
306 | if (!skb || !reply_buf) { | ||
307 | kfree_skb(skb); | ||
308 | kfree(reply_buf); | ||
309 | return -ENOMEM; | ||
310 | } | ||
311 | |||
312 | /* The reply is in a page, that we cannot send to user space. */ | ||
313 | memcpy(reply_buf, &(pkt->hdr), reply_len); | ||
314 | iwl_free_resp(&cmd); | ||
315 | |||
316 | if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) || | ||
317 | nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, reply_len, reply_buf)) | ||
318 | goto nla_put_failure; | ||
319 | return cfg80211_testmode_reply(skb); | ||
320 | |||
321 | nla_put_failure: | ||
322 | IWL_DEBUG_INFO(priv, "Failed creating NL attributes\n"); | ||
323 | return -ENOMSG; | ||
324 | } | ||
325 | |||
326 | |||
327 | /* | ||
328 | * This function handles the user application commands for register access. | ||
329 | * | ||
330 | * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the | ||
331 | * handlers respectively. | ||
332 | * | ||
333 | * If it's an unknown commdn ID, -ENOSYS is returned; or -ENOMSG if the | ||
334 | * mandatory fields(IWL_TM_ATTR_REG_OFFSET,IWL_TM_ATTR_REG_VALUE32, | ||
335 | * IWL_TM_ATTR_REG_VALUE8) are missing; Otherwise 0 is replied indicating | ||
336 | * the success of the command execution. | ||
337 | * | ||
338 | * If IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_REG_READ32, the register read | ||
339 | * value is returned with IWL_TM_ATTR_REG_VALUE32. | ||
340 | * | ||
341 | * @hw: ieee80211_hw object that represents the device | ||
342 | * @tb: gnl message fields from the user space | ||
343 | */ | ||
344 | static int iwl_testmode_reg(struct ieee80211_hw *hw, struct nlattr **tb) | ||
345 | { | ||
346 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
347 | u32 ofs, val32, cmd; | ||
348 | u8 val8; | ||
349 | struct sk_buff *skb; | ||
350 | int status = 0; | ||
351 | |||
352 | if (!tb[IWL_TM_ATTR_REG_OFFSET]) { | ||
353 | IWL_ERR(priv, "Missing register offset\n"); | ||
354 | return -ENOMSG; | ||
355 | } | ||
356 | ofs = nla_get_u32(tb[IWL_TM_ATTR_REG_OFFSET]); | ||
357 | IWL_INFO(priv, "testmode register access command offset 0x%x\n", ofs); | ||
358 | |||
359 | /* Allow access only to FH/CSR/HBUS in direct mode. | ||
360 | Since we don't have the upper bounds for the CSR and HBUS segments, | ||
361 | we will use only the upper bound of FH for sanity check. */ | ||
362 | cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]); | ||
363 | if ((cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32 || | ||
364 | cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32 || | ||
365 | cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8) && | ||
366 | (ofs >= FH_MEM_UPPER_BOUND)) { | ||
367 | IWL_ERR(priv, "offset out of segment (0x0 - 0x%x)\n", | ||
368 | FH_MEM_UPPER_BOUND); | ||
369 | return -EINVAL; | ||
370 | } | ||
371 | |||
372 | switch (cmd) { | ||
373 | case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32: | ||
374 | val32 = iwl_read_direct32(priv->trans, ofs); | ||
375 | IWL_INFO(priv, "32bit value to read 0x%x\n", val32); | ||
376 | |||
377 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20); | ||
378 | if (!skb) { | ||
379 | IWL_ERR(priv, "Memory allocation fail\n"); | ||
380 | return -ENOMEM; | ||
381 | } | ||
382 | if (nla_put_u32(skb, IWL_TM_ATTR_REG_VALUE32, val32)) | ||
383 | goto nla_put_failure; | ||
384 | status = cfg80211_testmode_reply(skb); | ||
385 | if (status < 0) | ||
386 | IWL_ERR(priv, "Error sending msg : %d\n", status); | ||
387 | break; | ||
388 | case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32: | ||
389 | if (!tb[IWL_TM_ATTR_REG_VALUE32]) { | ||
390 | IWL_ERR(priv, "Missing value to write\n"); | ||
391 | return -ENOMSG; | ||
392 | } else { | ||
393 | val32 = nla_get_u32(tb[IWL_TM_ATTR_REG_VALUE32]); | ||
394 | IWL_INFO(priv, "32bit value to write 0x%x\n", val32); | ||
395 | iwl_write_direct32(priv->trans, ofs, val32); | ||
396 | } | ||
397 | break; | ||
398 | case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8: | ||
399 | if (!tb[IWL_TM_ATTR_REG_VALUE8]) { | ||
400 | IWL_ERR(priv, "Missing value to write\n"); | ||
401 | return -ENOMSG; | ||
402 | } else { | ||
403 | val8 = nla_get_u8(tb[IWL_TM_ATTR_REG_VALUE8]); | ||
404 | IWL_INFO(priv, "8bit value to write 0x%x\n", val8); | ||
405 | iwl_write8(priv->trans, ofs, val8); | ||
406 | } | ||
407 | break; | ||
408 | default: | ||
409 | IWL_ERR(priv, "Unknown testmode register command ID\n"); | ||
410 | return -ENOSYS; | ||
411 | } | ||
412 | |||
413 | return status; | ||
414 | |||
415 | nla_put_failure: | ||
416 | kfree_skb(skb); | ||
417 | return -EMSGSIZE; | ||
418 | } | ||
419 | |||
420 | |||
421 | static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv) | ||
422 | { | ||
423 | struct iwl_notification_wait calib_wait; | ||
424 | static const u8 calib_complete[] = { | ||
425 | CALIBRATION_COMPLETE_NOTIFICATION | ||
426 | }; | ||
427 | int ret; | ||
428 | |||
429 | iwl_init_notification_wait(&priv->notif_wait, &calib_wait, | ||
430 | calib_complete, ARRAY_SIZE(calib_complete), | ||
431 | NULL, NULL); | ||
432 | ret = iwl_init_alive_start(priv); | ||
433 | if (ret) { | ||
434 | IWL_ERR(priv, "Fail init calibration: %d\n", ret); | ||
435 | goto cfg_init_calib_error; | ||
436 | } | ||
437 | |||
438 | ret = iwl_wait_notification(&priv->notif_wait, &calib_wait, 2 * HZ); | ||
439 | if (ret) | ||
440 | IWL_ERR(priv, "Error detecting" | ||
441 | " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret); | ||
442 | return ret; | ||
443 | |||
444 | cfg_init_calib_error: | ||
445 | iwl_remove_notification(&priv->notif_wait, &calib_wait); | ||
446 | return ret; | ||
447 | } | ||
448 | |||
449 | /* | ||
450 | * This function handles the user application commands for driver. | ||
451 | * | ||
452 | * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the | ||
453 | * handlers respectively. | ||
454 | * | ||
455 | * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned | ||
456 | * value of the actual command execution is replied to the user application. | ||
457 | * | ||
458 | * If there's any message responding to the user space, IWL_TM_ATTR_SYNC_RSP | ||
459 | * is used for carry the message while IWL_TM_ATTR_COMMAND must set to | ||
460 | * IWL_TM_CMD_DEV2APP_SYNC_RSP. | ||
461 | * | ||
462 | * @hw: ieee80211_hw object that represents the device | ||
463 | * @tb: gnl message fields from the user space | ||
464 | */ | ||
465 | static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb) | ||
466 | { | ||
467 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
468 | struct iwl_trans *trans = priv->trans; | ||
469 | struct sk_buff *skb; | ||
470 | unsigned char *rsp_data_ptr = NULL; | ||
471 | int status = 0, rsp_data_len = 0; | ||
472 | u32 devid, inst_size = 0, data_size = 0; | ||
473 | const struct fw_img *img; | ||
474 | |||
475 | switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) { | ||
476 | case IWL_TM_CMD_APP2DEV_GET_DEVICENAME: | ||
477 | rsp_data_ptr = (unsigned char *)priv->cfg->name; | ||
478 | rsp_data_len = strlen(priv->cfg->name); | ||
479 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, | ||
480 | rsp_data_len + 20); | ||
481 | if (!skb) { | ||
482 | IWL_ERR(priv, "Memory allocation fail\n"); | ||
483 | return -ENOMEM; | ||
484 | } | ||
485 | if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND, | ||
486 | IWL_TM_CMD_DEV2APP_SYNC_RSP) || | ||
487 | nla_put(skb, IWL_TM_ATTR_SYNC_RSP, | ||
488 | rsp_data_len, rsp_data_ptr)) | ||
489 | goto nla_put_failure; | ||
490 | status = cfg80211_testmode_reply(skb); | ||
491 | if (status < 0) | ||
492 | IWL_ERR(priv, "Error sending msg : %d\n", status); | ||
493 | break; | ||
494 | |||
495 | case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW: | ||
496 | status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT); | ||
497 | if (status) | ||
498 | IWL_ERR(priv, "Error loading init ucode: %d\n", status); | ||
499 | break; | ||
500 | |||
501 | case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB: | ||
502 | iwl_testmode_cfg_init_calib(priv); | ||
503 | priv->ucode_loaded = false; | ||
504 | iwl_trans_stop_device(trans); | ||
505 | break; | ||
506 | |||
507 | case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW: | ||
508 | status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR); | ||
509 | if (status) { | ||
510 | IWL_ERR(priv, | ||
511 | "Error loading runtime ucode: %d\n", status); | ||
512 | break; | ||
513 | } | ||
514 | status = iwl_alive_start(priv); | ||
515 | if (status) | ||
516 | IWL_ERR(priv, | ||
517 | "Error starting the device: %d\n", status); | ||
518 | break; | ||
519 | |||
520 | case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW: | ||
521 | iwl_scan_cancel_timeout(priv, 200); | ||
522 | priv->ucode_loaded = false; | ||
523 | iwl_trans_stop_device(trans); | ||
524 | status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN); | ||
525 | if (status) { | ||
526 | IWL_ERR(priv, | ||
527 | "Error loading WOWLAN ucode: %d\n", status); | ||
528 | break; | ||
529 | } | ||
530 | status = iwl_alive_start(priv); | ||
531 | if (status) | ||
532 | IWL_ERR(priv, | ||
533 | "Error starting the device: %d\n", status); | ||
534 | break; | ||
535 | |||
536 | case IWL_TM_CMD_APP2DEV_GET_EEPROM: | ||
537 | if (priv->eeprom_blob) { | ||
538 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, | ||
539 | priv->eeprom_blob_size + 20); | ||
540 | if (!skb) { | ||
541 | IWL_ERR(priv, "Memory allocation fail\n"); | ||
542 | return -ENOMEM; | ||
543 | } | ||
544 | if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND, | ||
545 | IWL_TM_CMD_DEV2APP_EEPROM_RSP) || | ||
546 | nla_put(skb, IWL_TM_ATTR_EEPROM, | ||
547 | priv->eeprom_blob_size, | ||
548 | priv->eeprom_blob)) | ||
549 | goto nla_put_failure; | ||
550 | status = cfg80211_testmode_reply(skb); | ||
551 | if (status < 0) | ||
552 | IWL_ERR(priv, "Error sending msg : %d\n", | ||
553 | status); | ||
554 | } else | ||
555 | return -ENODATA; | ||
556 | break; | ||
557 | |||
558 | case IWL_TM_CMD_APP2DEV_FIXRATE_REQ: | ||
559 | if (!tb[IWL_TM_ATTR_FIXRATE]) { | ||
560 | IWL_ERR(priv, "Missing fixrate setting\n"); | ||
561 | return -ENOMSG; | ||
562 | } | ||
563 | priv->tm_fixed_rate = nla_get_u32(tb[IWL_TM_ATTR_FIXRATE]); | ||
564 | break; | ||
565 | |||
566 | case IWL_TM_CMD_APP2DEV_GET_FW_VERSION: | ||
567 | IWL_INFO(priv, "uCode version raw: 0x%x\n", | ||
568 | priv->fw->ucode_ver); | ||
569 | |||
570 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20); | ||
571 | if (!skb) { | ||
572 | IWL_ERR(priv, "Memory allocation fail\n"); | ||
573 | return -ENOMEM; | ||
574 | } | ||
575 | if (nla_put_u32(skb, IWL_TM_ATTR_FW_VERSION, | ||
576 | priv->fw->ucode_ver)) | ||
577 | goto nla_put_failure; | ||
578 | status = cfg80211_testmode_reply(skb); | ||
579 | if (status < 0) | ||
580 | IWL_ERR(priv, "Error sending msg : %d\n", status); | ||
581 | break; | ||
582 | |||
583 | case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID: | ||
584 | devid = priv->trans->hw_id; | ||
585 | IWL_INFO(priv, "hw version: 0x%x\n", devid); | ||
586 | |||
587 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20); | ||
588 | if (!skb) { | ||
589 | IWL_ERR(priv, "Memory allocation fail\n"); | ||
590 | return -ENOMEM; | ||
591 | } | ||
592 | if (nla_put_u32(skb, IWL_TM_ATTR_DEVICE_ID, devid)) | ||
593 | goto nla_put_failure; | ||
594 | status = cfg80211_testmode_reply(skb); | ||
595 | if (status < 0) | ||
596 | IWL_ERR(priv, "Error sending msg : %d\n", status); | ||
597 | break; | ||
598 | |||
599 | case IWL_TM_CMD_APP2DEV_GET_FW_INFO: | ||
600 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20 + 8); | ||
601 | if (!skb) { | ||
602 | IWL_ERR(priv, "Memory allocation fail\n"); | ||
603 | return -ENOMEM; | ||
604 | } | ||
605 | if (!priv->ucode_loaded) { | ||
606 | IWL_ERR(priv, "No uCode has not been loaded\n"); | ||
607 | return -EINVAL; | ||
608 | } else { | ||
609 | img = &priv->fw->img[priv->cur_ucode]; | ||
610 | inst_size = img->sec[IWL_UCODE_SECTION_INST].len; | ||
611 | data_size = img->sec[IWL_UCODE_SECTION_DATA].len; | ||
612 | } | ||
613 | if (nla_put_u32(skb, IWL_TM_ATTR_FW_TYPE, priv->cur_ucode) || | ||
614 | nla_put_u32(skb, IWL_TM_ATTR_FW_INST_SIZE, inst_size) || | ||
615 | nla_put_u32(skb, IWL_TM_ATTR_FW_DATA_SIZE, data_size)) | ||
616 | goto nla_put_failure; | ||
617 | status = cfg80211_testmode_reply(skb); | ||
618 | if (status < 0) | ||
619 | IWL_ERR(priv, "Error sending msg : %d\n", status); | ||
620 | break; | ||
621 | |||
622 | default: | ||
623 | IWL_ERR(priv, "Unknown testmode driver command ID\n"); | ||
624 | return -ENOSYS; | ||
625 | } | ||
626 | return status; | ||
627 | |||
628 | nla_put_failure: | ||
629 | kfree_skb(skb); | ||
630 | return -EMSGSIZE; | ||
631 | } | ||
632 | |||
633 | |||
634 | /* | ||
635 | * This function handles the user application commands for uCode trace | ||
636 | * | ||
637 | * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the | ||
638 | * handlers respectively. | ||
639 | * | ||
640 | * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned | ||
641 | * value of the actual command execution is replied to the user application. | ||
642 | * | ||
643 | * @hw: ieee80211_hw object that represents the device | ||
644 | * @tb: gnl message fields from the user space | ||
645 | */ | ||
646 | static int iwl_testmode_trace(struct ieee80211_hw *hw, struct nlattr **tb) | ||
647 | { | ||
648 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
649 | struct sk_buff *skb; | ||
650 | int status = 0; | ||
651 | struct device *dev = priv->trans->dev; | ||
652 | |||
653 | switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) { | ||
654 | case IWL_TM_CMD_APP2DEV_BEGIN_TRACE: | ||
655 | if (priv->testmode_trace.trace_enabled) | ||
656 | return -EBUSY; | ||
657 | |||
658 | if (!tb[IWL_TM_ATTR_TRACE_SIZE]) | ||
659 | priv->testmode_trace.buff_size = TRACE_BUFF_SIZE_DEF; | ||
660 | else | ||
661 | priv->testmode_trace.buff_size = | ||
662 | nla_get_u32(tb[IWL_TM_ATTR_TRACE_SIZE]); | ||
663 | if (!priv->testmode_trace.buff_size) | ||
664 | return -EINVAL; | ||
665 | if (priv->testmode_trace.buff_size < TRACE_BUFF_SIZE_MIN || | ||
666 | priv->testmode_trace.buff_size > TRACE_BUFF_SIZE_MAX) | ||
667 | return -EINVAL; | ||
668 | |||
669 | priv->testmode_trace.total_size = | ||
670 | priv->testmode_trace.buff_size + TRACE_BUFF_PADD; | ||
671 | priv->testmode_trace.cpu_addr = | ||
672 | dma_alloc_coherent(dev, | ||
673 | priv->testmode_trace.total_size, | ||
674 | &priv->testmode_trace.dma_addr, | ||
675 | GFP_KERNEL); | ||
676 | if (!priv->testmode_trace.cpu_addr) | ||
677 | return -ENOMEM; | ||
678 | priv->testmode_trace.trace_enabled = true; | ||
679 | priv->testmode_trace.trace_addr = (u8 *)PTR_ALIGN( | ||
680 | priv->testmode_trace.cpu_addr, 0x100); | ||
681 | memset(priv->testmode_trace.trace_addr, 0x03B, | ||
682 | priv->testmode_trace.buff_size); | ||
683 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, | ||
684 | sizeof(priv->testmode_trace.dma_addr) + 20); | ||
685 | if (!skb) { | ||
686 | IWL_ERR(priv, "Memory allocation fail\n"); | ||
687 | iwl_trace_cleanup(priv); | ||
688 | return -ENOMEM; | ||
689 | } | ||
690 | if (nla_put(skb, IWL_TM_ATTR_TRACE_ADDR, | ||
691 | sizeof(priv->testmode_trace.dma_addr), | ||
692 | (u64 *)&priv->testmode_trace.dma_addr)) | ||
693 | goto nla_put_failure; | ||
694 | status = cfg80211_testmode_reply(skb); | ||
695 | if (status < 0) { | ||
696 | IWL_ERR(priv, "Error sending msg : %d\n", status); | ||
697 | } | ||
698 | priv->testmode_trace.num_chunks = | ||
699 | DIV_ROUND_UP(priv->testmode_trace.buff_size, | ||
700 | DUMP_CHUNK_SIZE); | ||
701 | break; | ||
702 | |||
703 | case IWL_TM_CMD_APP2DEV_END_TRACE: | ||
704 | iwl_trace_cleanup(priv); | ||
705 | break; | ||
706 | default: | ||
707 | IWL_ERR(priv, "Unknown testmode mem command ID\n"); | ||
708 | return -ENOSYS; | ||
709 | } | ||
710 | return status; | ||
711 | |||
712 | nla_put_failure: | ||
713 | kfree_skb(skb); | ||
714 | if (nla_get_u32(tb[IWL_TM_ATTR_COMMAND]) == | ||
715 | IWL_TM_CMD_APP2DEV_BEGIN_TRACE) | ||
716 | iwl_trace_cleanup(priv); | ||
717 | return -EMSGSIZE; | ||
718 | } | ||
719 | |||
720 | static int iwl_testmode_trace_dump(struct ieee80211_hw *hw, | ||
721 | struct sk_buff *skb, | ||
722 | struct netlink_callback *cb) | ||
723 | { | ||
724 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
725 | int idx, length; | ||
726 | |||
727 | if (priv->testmode_trace.trace_enabled && | ||
728 | priv->testmode_trace.trace_addr) { | ||
729 | idx = cb->args[4]; | ||
730 | if (idx >= priv->testmode_trace.num_chunks) | ||
731 | return -ENOENT; | ||
732 | length = DUMP_CHUNK_SIZE; | ||
733 | if (((idx + 1) == priv->testmode_trace.num_chunks) && | ||
734 | (priv->testmode_trace.buff_size % DUMP_CHUNK_SIZE)) | ||
735 | length = priv->testmode_trace.buff_size % | ||
736 | DUMP_CHUNK_SIZE; | ||
737 | |||
738 | if (nla_put(skb, IWL_TM_ATTR_TRACE_DUMP, length, | ||
739 | priv->testmode_trace.trace_addr + | ||
740 | (DUMP_CHUNK_SIZE * idx))) | ||
741 | goto nla_put_failure; | ||
742 | idx++; | ||
743 | cb->args[4] = idx; | ||
744 | return 0; | ||
745 | } else | ||
746 | return -EFAULT; | ||
747 | |||
748 | nla_put_failure: | ||
749 | return -ENOBUFS; | ||
750 | } | ||
751 | |||
752 | /* | ||
753 | * This function handles the user application switch ucode ownership. | ||
754 | * | ||
755 | * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_OWNER and | ||
756 | * decide who the current owner of the uCode | ||
757 | * | ||
758 | * If the current owner is OWNERSHIP_TM, then the only host command | ||
759 | * can deliver to uCode is from testmode, all the other host commands | ||
760 | * will dropped. | ||
761 | * | ||
762 | * default driver is the owner of uCode in normal operational mode | ||
763 | * | ||
764 | * @hw: ieee80211_hw object that represents the device | ||
765 | * @tb: gnl message fields from the user space | ||
766 | */ | ||
767 | static int iwl_testmode_ownership(struct ieee80211_hw *hw, struct nlattr **tb) | ||
768 | { | ||
769 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
770 | u8 owner; | ||
771 | |||
772 | if (!tb[IWL_TM_ATTR_UCODE_OWNER]) { | ||
773 | IWL_ERR(priv, "Missing ucode owner\n"); | ||
774 | return -ENOMSG; | ||
775 | } | ||
776 | |||
777 | owner = nla_get_u8(tb[IWL_TM_ATTR_UCODE_OWNER]); | ||
778 | if (owner == IWL_OWNERSHIP_DRIVER) { | ||
779 | priv->ucode_owner = owner; | ||
780 | priv->pre_rx_handler = NULL; | ||
781 | } else if (owner == IWL_OWNERSHIP_TM) { | ||
782 | priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt; | ||
783 | priv->ucode_owner = owner; | ||
784 | } else { | ||
785 | IWL_ERR(priv, "Invalid owner\n"); | ||
786 | return -EINVAL; | ||
787 | } | ||
788 | return 0; | ||
789 | } | ||
790 | |||
791 | static int iwl_testmode_indirect_read(struct iwl_priv *priv, u32 addr, u32 size) | ||
792 | { | ||
793 | struct iwl_trans *trans = priv->trans; | ||
794 | unsigned long flags; | ||
795 | int i; | ||
796 | |||
797 | if (size & 0x3) | ||
798 | return -EINVAL; | ||
799 | priv->testmode_mem.buff_size = size; | ||
800 | priv->testmode_mem.buff_addr = | ||
801 | kmalloc(priv->testmode_mem.buff_size, GFP_KERNEL); | ||
802 | if (priv->testmode_mem.buff_addr == NULL) | ||
803 | return -ENOMEM; | ||
804 | |||
805 | /* Hard-coded periphery absolute address */ | ||
806 | if (IWL_TM_ABS_PRPH_START <= addr && | ||
807 | addr < IWL_TM_ABS_PRPH_START + PRPH_END) { | ||
808 | spin_lock_irqsave(&trans->reg_lock, flags); | ||
809 | iwl_grab_nic_access(trans); | ||
810 | iwl_write32(trans, HBUS_TARG_PRPH_RADDR, | ||
811 | addr | (3 << 24)); | ||
812 | for (i = 0; i < size; i += 4) | ||
813 | *(u32 *)(priv->testmode_mem.buff_addr + i) = | ||
814 | iwl_read32(trans, HBUS_TARG_PRPH_RDAT); | ||
815 | iwl_release_nic_access(trans); | ||
816 | spin_unlock_irqrestore(&trans->reg_lock, flags); | ||
817 | } else { /* target memory (SRAM) */ | ||
818 | _iwl_read_targ_mem_words(trans, addr, | ||
819 | priv->testmode_mem.buff_addr, | ||
820 | priv->testmode_mem.buff_size / 4); | ||
821 | } | ||
822 | |||
823 | priv->testmode_mem.num_chunks = | ||
824 | DIV_ROUND_UP(priv->testmode_mem.buff_size, DUMP_CHUNK_SIZE); | ||
825 | priv->testmode_mem.read_in_progress = true; | ||
826 | return 0; | ||
827 | |||
828 | } | ||
829 | |||
830 | static int iwl_testmode_indirect_write(struct iwl_priv *priv, u32 addr, | ||
831 | u32 size, unsigned char *buf) | ||
832 | { | ||
833 | struct iwl_trans *trans = priv->trans; | ||
834 | u32 val, i; | ||
835 | unsigned long flags; | ||
836 | |||
837 | if (IWL_TM_ABS_PRPH_START <= addr && | ||
838 | addr < IWL_TM_ABS_PRPH_START + PRPH_END) { | ||
839 | /* Periphery writes can be 1-3 bytes long, or DWORDs */ | ||
840 | if (size < 4) { | ||
841 | memcpy(&val, buf, size); | ||
842 | spin_lock_irqsave(&trans->reg_lock, flags); | ||
843 | iwl_grab_nic_access(trans); | ||
844 | iwl_write32(trans, HBUS_TARG_PRPH_WADDR, | ||
845 | (addr & 0x0000FFFF) | | ||
846 | ((size - 1) << 24)); | ||
847 | iwl_write32(trans, HBUS_TARG_PRPH_WDAT, val); | ||
848 | iwl_release_nic_access(trans); | ||
849 | /* needed after consecutive writes w/o read */ | ||
850 | mmiowb(); | ||
851 | spin_unlock_irqrestore(&trans->reg_lock, flags); | ||
852 | } else { | ||
853 | if (size % 4) | ||
854 | return -EINVAL; | ||
855 | for (i = 0; i < size; i += 4) | ||
856 | iwl_write_prph(trans, addr+i, | ||
857 | *(u32 *)(buf+i)); | ||
858 | } | ||
859 | } else if (iwlagn_hw_valid_rtc_data_addr(addr) || | ||
860 | (IWLAGN_RTC_INST_LOWER_BOUND <= addr && | ||
861 | addr < IWLAGN_RTC_INST_UPPER_BOUND)) { | ||
862 | _iwl_write_targ_mem_words(trans, addr, buf, size/4); | ||
863 | } else | ||
864 | return -EINVAL; | ||
865 | return 0; | ||
866 | } | ||
867 | |||
868 | /* | ||
869 | * This function handles the user application commands for SRAM data dump | ||
870 | * | ||
871 | * It retrieves the mandatory fields IWL_TM_ATTR_SRAM_ADDR and | ||
872 | * IWL_TM_ATTR_SRAM_SIZE to decide the memory area for SRAM data reading | ||
873 | * | ||
874 | * Several error will be retured, -EBUSY if the SRAM data retrieved by | ||
875 | * previous command has not been delivered to userspace, or -ENOMSG if | ||
876 | * the mandatory fields (IWL_TM_ATTR_SRAM_ADDR,IWL_TM_ATTR_SRAM_SIZE) | ||
877 | * are missing, or -ENOMEM if the buffer allocation fails. | ||
878 | * | ||
879 | * Otherwise 0 is replied indicating the success of the SRAM reading. | ||
880 | * | ||
881 | * @hw: ieee80211_hw object that represents the device | ||
882 | * @tb: gnl message fields from the user space | ||
883 | */ | ||
884 | static int iwl_testmode_indirect_mem(struct ieee80211_hw *hw, | ||
885 | struct nlattr **tb) | ||
886 | { | ||
887 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
888 | u32 addr, size, cmd; | ||
889 | unsigned char *buf; | ||
890 | |||
891 | /* Both read and write should be blocked, for atomicity */ | ||
892 | if (priv->testmode_mem.read_in_progress) | ||
893 | return -EBUSY; | ||
894 | |||
895 | cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]); | ||
896 | if (!tb[IWL_TM_ATTR_MEM_ADDR]) { | ||
897 | IWL_ERR(priv, "Error finding memory offset address\n"); | ||
898 | return -ENOMSG; | ||
899 | } | ||
900 | addr = nla_get_u32(tb[IWL_TM_ATTR_MEM_ADDR]); | ||
901 | if (!tb[IWL_TM_ATTR_BUFFER_SIZE]) { | ||
902 | IWL_ERR(priv, "Error finding size for memory reading\n"); | ||
903 | return -ENOMSG; | ||
904 | } | ||
905 | size = nla_get_u32(tb[IWL_TM_ATTR_BUFFER_SIZE]); | ||
906 | |||
907 | if (cmd == IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ) | ||
908 | return iwl_testmode_indirect_read(priv, addr, size); | ||
909 | else { | ||
910 | if (!tb[IWL_TM_ATTR_BUFFER_DUMP]) | ||
911 | return -EINVAL; | ||
912 | buf = (unsigned char *) nla_data(tb[IWL_TM_ATTR_BUFFER_DUMP]); | ||
913 | return iwl_testmode_indirect_write(priv, addr, size, buf); | ||
914 | } | ||
915 | } | ||
916 | |||
917 | static int iwl_testmode_buffer_dump(struct ieee80211_hw *hw, | ||
918 | struct sk_buff *skb, | ||
919 | struct netlink_callback *cb) | ||
920 | { | ||
921 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
922 | int idx, length; | ||
923 | |||
924 | if (priv->testmode_mem.read_in_progress) { | ||
925 | idx = cb->args[4]; | ||
926 | if (idx >= priv->testmode_mem.num_chunks) { | ||
927 | iwl_mem_cleanup(priv); | ||
928 | return -ENOENT; | ||
929 | } | ||
930 | length = DUMP_CHUNK_SIZE; | ||
931 | if (((idx + 1) == priv->testmode_mem.num_chunks) && | ||
932 | (priv->testmode_mem.buff_size % DUMP_CHUNK_SIZE)) | ||
933 | length = priv->testmode_mem.buff_size % | ||
934 | DUMP_CHUNK_SIZE; | ||
935 | |||
936 | if (nla_put(skb, IWL_TM_ATTR_BUFFER_DUMP, length, | ||
937 | priv->testmode_mem.buff_addr + | ||
938 | (DUMP_CHUNK_SIZE * idx))) | ||
939 | goto nla_put_failure; | ||
940 | idx++; | ||
941 | cb->args[4] = idx; | ||
942 | return 0; | ||
943 | } else | ||
944 | return -EFAULT; | ||
945 | |||
946 | nla_put_failure: | ||
947 | return -ENOBUFS; | ||
948 | } | ||
949 | |||
950 | static int iwl_testmode_notifications(struct ieee80211_hw *hw, | ||
951 | struct nlattr **tb) | ||
952 | { | ||
953 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
954 | bool enable; | ||
955 | |||
956 | enable = nla_get_flag(tb[IWL_TM_ATTR_ENABLE_NOTIFICATION]); | ||
957 | if (enable) | ||
958 | priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt; | ||
959 | else | ||
960 | priv->pre_rx_handler = NULL; | ||
961 | return 0; | ||
962 | } | ||
963 | |||
964 | |||
965 | /* The testmode gnl message handler that takes the gnl message from the | ||
966 | * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then | ||
967 | * invoke the corresponding handlers. | ||
968 | * | ||
969 | * This function is invoked when there is user space application sending | ||
970 | * gnl message through the testmode tunnel NL80211_CMD_TESTMODE regulated | ||
971 | * by nl80211. | ||
972 | * | ||
973 | * It retrieves the mandatory field, IWL_TM_ATTR_COMMAND, before | ||
974 | * dispatching it to the corresponding handler. | ||
975 | * | ||
976 | * If IWL_TM_ATTR_COMMAND is missing, -ENOMSG is replied to user application; | ||
977 | * -ENOSYS is replied to the user application if the command is unknown; | ||
978 | * Otherwise, the command is dispatched to the respective handler. | ||
979 | * | ||
980 | * @hw: ieee80211_hw object that represents the device | ||
981 | * @data: pointer to user space message | ||
982 | * @len: length in byte of @data | ||
983 | */ | ||
984 | int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len) | ||
985 | { | ||
986 | struct nlattr *tb[IWL_TM_ATTR_MAX]; | ||
987 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
988 | int result; | ||
989 | |||
990 | result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len, | ||
991 | iwl_testmode_gnl_msg_policy); | ||
992 | if (result != 0) { | ||
993 | IWL_ERR(priv, "Error parsing the gnl message : %d\n", result); | ||
994 | return result; | ||
995 | } | ||
996 | |||
997 | /* IWL_TM_ATTR_COMMAND is absolutely mandatory */ | ||
998 | if (!tb[IWL_TM_ATTR_COMMAND]) { | ||
999 | IWL_ERR(priv, "Missing testmode command type\n"); | ||
1000 | return -ENOMSG; | ||
1001 | } | ||
1002 | /* in case multiple accesses to the device happens */ | ||
1003 | mutex_lock(&priv->mutex); | ||
1004 | |||
1005 | switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) { | ||
1006 | case IWL_TM_CMD_APP2DEV_UCODE: | ||
1007 | IWL_DEBUG_INFO(priv, "testmode cmd to uCode\n"); | ||
1008 | result = iwl_testmode_ucode(hw, tb); | ||
1009 | break; | ||
1010 | case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32: | ||
1011 | case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32: | ||
1012 | case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8: | ||
1013 | IWL_DEBUG_INFO(priv, "testmode cmd to register\n"); | ||
1014 | result = iwl_testmode_reg(hw, tb); | ||
1015 | break; | ||
1016 | case IWL_TM_CMD_APP2DEV_GET_DEVICENAME: | ||
1017 | case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW: | ||
1018 | case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB: | ||
1019 | case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW: | ||
1020 | case IWL_TM_CMD_APP2DEV_GET_EEPROM: | ||
1021 | case IWL_TM_CMD_APP2DEV_FIXRATE_REQ: | ||
1022 | case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW: | ||
1023 | case IWL_TM_CMD_APP2DEV_GET_FW_VERSION: | ||
1024 | case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID: | ||
1025 | case IWL_TM_CMD_APP2DEV_GET_FW_INFO: | ||
1026 | IWL_DEBUG_INFO(priv, "testmode cmd to driver\n"); | ||
1027 | result = iwl_testmode_driver(hw, tb); | ||
1028 | break; | ||
1029 | |||
1030 | case IWL_TM_CMD_APP2DEV_BEGIN_TRACE: | ||
1031 | case IWL_TM_CMD_APP2DEV_END_TRACE: | ||
1032 | case IWL_TM_CMD_APP2DEV_READ_TRACE: | ||
1033 | IWL_DEBUG_INFO(priv, "testmode uCode trace cmd to driver\n"); | ||
1034 | result = iwl_testmode_trace(hw, tb); | ||
1035 | break; | ||
1036 | |||
1037 | case IWL_TM_CMD_APP2DEV_OWNERSHIP: | ||
1038 | IWL_DEBUG_INFO(priv, "testmode change uCode ownership\n"); | ||
1039 | result = iwl_testmode_ownership(hw, tb); | ||
1040 | break; | ||
1041 | |||
1042 | case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ: | ||
1043 | case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE: | ||
1044 | IWL_DEBUG_INFO(priv, "testmode indirect memory cmd " | ||
1045 | "to driver\n"); | ||
1046 | result = iwl_testmode_indirect_mem(hw, tb); | ||
1047 | break; | ||
1048 | |||
1049 | case IWL_TM_CMD_APP2DEV_NOTIFICATIONS: | ||
1050 | IWL_DEBUG_INFO(priv, "testmode notifications cmd " | ||
1051 | "to driver\n"); | ||
1052 | result = iwl_testmode_notifications(hw, tb); | ||
1053 | break; | ||
1054 | |||
1055 | default: | ||
1056 | IWL_ERR(priv, "Unknown testmode command\n"); | ||
1057 | result = -ENOSYS; | ||
1058 | break; | ||
1059 | } | ||
1060 | |||
1061 | mutex_unlock(&priv->mutex); | ||
1062 | return result; | ||
1063 | } | ||
1064 | |||
1065 | int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb, | ||
1066 | struct netlink_callback *cb, | ||
1067 | void *data, int len) | ||
1068 | { | ||
1069 | struct nlattr *tb[IWL_TM_ATTR_MAX]; | ||
1070 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); | ||
1071 | int result; | ||
1072 | u32 cmd; | ||
1073 | |||
1074 | if (cb->args[3]) { | ||
1075 | /* offset by 1 since commands start at 0 */ | ||
1076 | cmd = cb->args[3] - 1; | ||
1077 | } else { | ||
1078 | result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len, | ||
1079 | iwl_testmode_gnl_msg_policy); | ||
1080 | if (result) { | ||
1081 | IWL_ERR(priv, | ||
1082 | "Error parsing the gnl message : %d\n", result); | ||
1083 | return result; | ||
1084 | } | ||
1085 | |||
1086 | /* IWL_TM_ATTR_COMMAND is absolutely mandatory */ | ||
1087 | if (!tb[IWL_TM_ATTR_COMMAND]) { | ||
1088 | IWL_ERR(priv, "Missing testmode command type\n"); | ||
1089 | return -ENOMSG; | ||
1090 | } | ||
1091 | cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]); | ||
1092 | cb->args[3] = cmd + 1; | ||
1093 | } | ||
1094 | |||
1095 | /* in case multiple accesses to the device happens */ | ||
1096 | mutex_lock(&priv->mutex); | ||
1097 | switch (cmd) { | ||
1098 | case IWL_TM_CMD_APP2DEV_READ_TRACE: | ||
1099 | IWL_DEBUG_INFO(priv, "uCode trace cmd to driver\n"); | ||
1100 | result = iwl_testmode_trace_dump(hw, skb, cb); | ||
1101 | break; | ||
1102 | case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP: | ||
1103 | IWL_DEBUG_INFO(priv, "testmode sram dump cmd to driver\n"); | ||
1104 | result = iwl_testmode_buffer_dump(hw, skb, cb); | ||
1105 | break; | ||
1106 | default: | ||
1107 | result = -EINVAL; | ||
1108 | break; | ||
1109 | } | ||
1110 | |||
1111 | mutex_unlock(&priv->mutex); | ||
1112 | return result; | ||
1113 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/testmode.h b/drivers/net/wireless/iwlwifi/dvm/testmode.h new file mode 100644 index 000000000000..6ba211b09426 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/testmode.h | |||
@@ -0,0 +1,309 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
4 | * redistributing this file, you may do so under either license. | ||
5 | * | ||
6 | * GPL LICENSE SUMMARY | ||
7 | * | ||
8 | * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of version 2 of the GNU General Public License as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
22 | * USA | ||
23 | * | ||
24 | * The full GNU General Public License is included in this distribution | ||
25 | * in the file called LICENSE.GPL. | ||
26 | * | ||
27 | * Contact Information: | ||
28 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
30 | * | ||
31 | * BSD LICENSE | ||
32 | * | ||
33 | * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved. | ||
34 | * All rights reserved. | ||
35 | * | ||
36 | * Redistribution and use in source and binary forms, with or without | ||
37 | * modification, are permitted provided that the following conditions | ||
38 | * are met: | ||
39 | * | ||
40 | * * Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * * Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in | ||
44 | * the documentation and/or other materials provided with the | ||
45 | * distribution. | ||
46 | * * Neither the name Intel Corporation nor the names of its | ||
47 | * contributors may be used to endorse or promote products derived | ||
48 | * from this software without specific prior written permission. | ||
49 | * | ||
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
61 | * | ||
62 | *****************************************************************************/ | ||
63 | #ifndef __IWL_TESTMODE_H__ | ||
64 | #define __IWL_TESTMODE_H__ | ||
65 | |||
66 | #include <linux/types.h> | ||
67 | |||
68 | |||
69 | /* | ||
70 | * Commands from user space to kernel space(IWL_TM_CMD_ID_APP2DEV_XX) and | ||
71 | * from and kernel space to user space(IWL_TM_CMD_ID_DEV2APP_XX). | ||
72 | * The command ID is carried with IWL_TM_ATTR_COMMAND. | ||
73 | * | ||
74 | * @IWL_TM_CMD_APP2DEV_UCODE: | ||
75 | * commands from user application to the uCode, | ||
76 | * the actual uCode host command ID is carried with | ||
77 | * IWL_TM_ATTR_UCODE_CMD_ID | ||
78 | * | ||
79 | * @IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32: | ||
80 | * @IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32: | ||
81 | * @IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8: | ||
82 | * commands from user applicaiton to access register | ||
83 | * | ||
84 | * @IWL_TM_CMD_APP2DEV_GET_DEVICENAME: retrieve device name | ||
85 | * @IWL_TM_CMD_APP2DEV_LOAD_INIT_FW: load initial uCode image | ||
86 | * @IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB: perform calibration | ||
87 | * @IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW: load runtime uCode image | ||
88 | * @IWL_TM_CMD_APP2DEV_GET_EEPROM: request EEPROM data | ||
89 | * @IWL_TM_CMD_APP2DEV_FIXRATE_REQ: set fix MCS | ||
90 | * commands fom user space for pure driver level operations | ||
91 | * | ||
92 | * @IWL_TM_CMD_APP2DEV_BEGIN_TRACE: | ||
93 | * @IWL_TM_CMD_APP2DEV_END_TRACE: | ||
94 | * @IWL_TM_CMD_APP2DEV_READ_TRACE: | ||
95 | * commands fom user space for uCode trace operations | ||
96 | * | ||
97 | * @IWL_TM_CMD_DEV2APP_SYNC_RSP: | ||
98 | * commands from kernel space to carry the synchronous response | ||
99 | * to user application | ||
100 | * @IWL_TM_CMD_DEV2APP_UCODE_RX_PKT: | ||
101 | * commands from kernel space to multicast the spontaneous messages | ||
102 | * to user application, or reply of host commands | ||
103 | * @IWL_TM_CMD_DEV2APP_EEPROM_RSP: | ||
104 | * commands from kernel space to carry the eeprom response | ||
105 | * to user application | ||
106 | * | ||
107 | * @IWL_TM_CMD_APP2DEV_OWNERSHIP: | ||
108 | * commands from user application to own change the ownership of the uCode | ||
109 | * if application has the ownership, the only host command from | ||
110 | * testmode will deliver to uCode. Default owner is driver | ||
111 | * | ||
112 | * @IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW: load Wake On Wireless LAN uCode image | ||
113 | * @IWL_TM_CMD_APP2DEV_GET_FW_VERSION: retrieve uCode version | ||
114 | * @IWL_TM_CMD_APP2DEV_GET_DEVICE_ID: retrieve ID information in device | ||
115 | * @IWL_TM_CMD_APP2DEV_GET_FW_INFO: | ||
116 | * retrieve information of existing loaded uCode image | ||
117 | * | ||
118 | * @IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ: | ||
119 | * @IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP: | ||
120 | * @IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE: | ||
121 | * Commands to read/write data from periphery or SRAM memory ranges. | ||
122 | * Fore reading, a READ command is sent from the userspace and the data | ||
123 | * is returned when the user calls a DUMP command. | ||
124 | * For writing, only a WRITE command is used. | ||
125 | * @IWL_TM_CMD_APP2DEV_NOTIFICATIONS: | ||
126 | * Command to enable/disable notifications (currently RX packets) from the | ||
127 | * driver to userspace. | ||
128 | */ | ||
129 | enum iwl_tm_cmd_t { | ||
130 | IWL_TM_CMD_APP2DEV_UCODE = 1, | ||
131 | IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32 = 2, | ||
132 | IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32 = 3, | ||
133 | IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8 = 4, | ||
134 | IWL_TM_CMD_APP2DEV_GET_DEVICENAME = 5, | ||
135 | IWL_TM_CMD_APP2DEV_LOAD_INIT_FW = 6, | ||
136 | IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB = 7, | ||
137 | IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW = 8, | ||
138 | IWL_TM_CMD_APP2DEV_GET_EEPROM = 9, | ||
139 | IWL_TM_CMD_APP2DEV_FIXRATE_REQ = 10, | ||
140 | IWL_TM_CMD_APP2DEV_BEGIN_TRACE = 11, | ||
141 | IWL_TM_CMD_APP2DEV_END_TRACE = 12, | ||
142 | IWL_TM_CMD_APP2DEV_READ_TRACE = 13, | ||
143 | IWL_TM_CMD_DEV2APP_SYNC_RSP = 14, | ||
144 | IWL_TM_CMD_DEV2APP_UCODE_RX_PKT = 15, | ||
145 | IWL_TM_CMD_DEV2APP_EEPROM_RSP = 16, | ||
146 | IWL_TM_CMD_APP2DEV_OWNERSHIP = 17, | ||
147 | RESERVED_18 = 18, | ||
148 | RESERVED_19 = 19, | ||
149 | RESERVED_20 = 20, | ||
150 | RESERVED_21 = 21, | ||
151 | IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW = 22, | ||
152 | IWL_TM_CMD_APP2DEV_GET_FW_VERSION = 23, | ||
153 | IWL_TM_CMD_APP2DEV_GET_DEVICE_ID = 24, | ||
154 | IWL_TM_CMD_APP2DEV_GET_FW_INFO = 25, | ||
155 | IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ = 26, | ||
156 | IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP = 27, | ||
157 | IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE = 28, | ||
158 | IWL_TM_CMD_APP2DEV_NOTIFICATIONS = 29, | ||
159 | IWL_TM_CMD_MAX = 30, | ||
160 | }; | ||
161 | |||
162 | /* | ||
163 | * Atrribute filed in testmode command | ||
164 | * See enum iwl_tm_cmd_t. | ||
165 | * | ||
166 | * @IWL_TM_ATTR_NOT_APPLICABLE: | ||
167 | * The attribute is not applicable or invalid | ||
168 | * @IWL_TM_ATTR_COMMAND: | ||
169 | * From user space to kernel space: | ||
170 | * the command either destines to ucode, driver, or register; | ||
171 | * From kernel space to user space: | ||
172 | * the command either carries synchronous response, | ||
173 | * or the spontaneous message multicast from the device; | ||
174 | * | ||
175 | * @IWL_TM_ATTR_UCODE_CMD_ID: | ||
176 | * @IWL_TM_ATTR_UCODE_CMD_DATA: | ||
177 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_UCODE, | ||
178 | * The mandatory fields are : | ||
179 | * IWL_TM_ATTR_UCODE_CMD_ID for recognizable command ID; | ||
180 | * IWL_TM_ATTR_UCODE_CMD_DATA for the actual command payload | ||
181 | * to the ucode | ||
182 | * | ||
183 | * @IWL_TM_ATTR_REG_OFFSET: | ||
184 | * @IWL_TM_ATTR_REG_VALUE8: | ||
185 | * @IWL_TM_ATTR_REG_VALUE32: | ||
186 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_REG_XXX, | ||
187 | * The mandatory fields are: | ||
188 | * IWL_TM_ATTR_REG_OFFSET for the offset of the target register; | ||
189 | * IWL_TM_ATTR_REG_VALUE8 or IWL_TM_ATTR_REG_VALUE32 for value | ||
190 | * | ||
191 | * @IWL_TM_ATTR_SYNC_RSP: | ||
192 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_DEV2APP_SYNC_RSP, | ||
193 | * The mandatory fields are: | ||
194 | * IWL_TM_ATTR_SYNC_RSP for the data content responding to the user | ||
195 | * application command | ||
196 | * | ||
197 | * @IWL_TM_ATTR_UCODE_RX_PKT: | ||
198 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_DEV2APP_UCODE_RX_PKT, | ||
199 | * The mandatory fields are: | ||
200 | * IWL_TM_ATTR_UCODE_RX_PKT for the data content multicast to the user | ||
201 | * application | ||
202 | * | ||
203 | * @IWL_TM_ATTR_EEPROM: | ||
204 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_DEV2APP_EEPROM, | ||
205 | * The mandatory fields are: | ||
206 | * IWL_TM_ATTR_EEPROM for the data content responging to the user | ||
207 | * application | ||
208 | * | ||
209 | * @IWL_TM_ATTR_TRACE_ADDR: | ||
210 | * @IWL_TM_ATTR_TRACE_SIZE: | ||
211 | * @IWL_TM_ATTR_TRACE_DUMP: | ||
212 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_XXX_TRACE, | ||
213 | * The mandatory fields are: | ||
214 | * IWL_TM_ATTR_MEM_TRACE_ADDR for the trace address | ||
215 | * IWL_TM_ATTR_MEM_TRACE_SIZE for the trace buffer size | ||
216 | * IWL_TM_ATTR_MEM_TRACE_DUMP for the trace dump | ||
217 | * | ||
218 | * @IWL_TM_ATTR_FIXRATE: | ||
219 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_FIXRATE_REQ, | ||
220 | * The mandatory fields are: | ||
221 | * IWL_TM_ATTR_FIXRATE for the fixed rate | ||
222 | * | ||
223 | * @IWL_TM_ATTR_UCODE_OWNER: | ||
224 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_OWNERSHIP, | ||
225 | * The mandatory fields are: | ||
226 | * IWL_TM_ATTR_UCODE_OWNER for the new owner | ||
227 | * | ||
228 | * @IWL_TM_ATTR_MEM_ADDR: | ||
229 | * @IWL_TM_ATTR_BUFFER_SIZE: | ||
230 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ | ||
231 | * or IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE. | ||
232 | * The mandatory fields are: | ||
233 | * IWL_TM_ATTR_MEM_ADDR for the address in SRAM/periphery to read/write | ||
234 | * IWL_TM_ATTR_BUFFER_SIZE for the buffer size of data to read/write. | ||
235 | * | ||
236 | * @IWL_TM_ATTR_BUFFER_DUMP: | ||
237 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP, | ||
238 | * IWL_TM_ATTR_BUFFER_DUMP is used for the data that was read. | ||
239 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE, | ||
240 | * this attribute contains the data to write. | ||
241 | * | ||
242 | * @IWL_TM_ATTR_FW_VERSION: | ||
243 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_GET_FW_VERSION, | ||
244 | * IWL_TM_ATTR_FW_VERSION for the uCode version | ||
245 | * | ||
246 | * @IWL_TM_ATTR_DEVICE_ID: | ||
247 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_GET_DEVICE_ID, | ||
248 | * IWL_TM_ATTR_DEVICE_ID for the device ID information | ||
249 | * | ||
250 | * @IWL_TM_ATTR_FW_TYPE: | ||
251 | * @IWL_TM_ATTR_FW_INST_SIZE: | ||
252 | * @IWL_TM_ATTR_FW_DATA_SIZE: | ||
253 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_GET_FW_INFO, | ||
254 | * The mandatory fields are: | ||
255 | * IWL_TM_ATTR_FW_TYPE for the uCode type (INIT/RUNTIME/...) | ||
256 | * IWL_TM_ATTR_FW_INST_SIZE for the size of instruction section | ||
257 | * IWL_TM_ATTR_FW_DATA_SIZE for the size of data section | ||
258 | * | ||
259 | * @IWL_TM_ATTR_UCODE_CMD_SKB: | ||
260 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_UCODE this flag | ||
261 | * indicates that the user wants to receive the response of the command | ||
262 | * in a reply SKB. If it's not present, the response is not returned. | ||
263 | * @IWL_TM_ATTR_ENABLE_NOTIFICATIONS: | ||
264 | * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_NOTIFICATIONS, this | ||
265 | * flag enables (if present) or disables (if not) the forwarding | ||
266 | * to userspace. | ||
267 | */ | ||
268 | enum iwl_tm_attr_t { | ||
269 | IWL_TM_ATTR_NOT_APPLICABLE = 0, | ||
270 | IWL_TM_ATTR_COMMAND = 1, | ||
271 | IWL_TM_ATTR_UCODE_CMD_ID = 2, | ||
272 | IWL_TM_ATTR_UCODE_CMD_DATA = 3, | ||
273 | IWL_TM_ATTR_REG_OFFSET = 4, | ||
274 | IWL_TM_ATTR_REG_VALUE8 = 5, | ||
275 | IWL_TM_ATTR_REG_VALUE32 = 6, | ||
276 | IWL_TM_ATTR_SYNC_RSP = 7, | ||
277 | IWL_TM_ATTR_UCODE_RX_PKT = 8, | ||
278 | IWL_TM_ATTR_EEPROM = 9, | ||
279 | IWL_TM_ATTR_TRACE_ADDR = 10, | ||
280 | IWL_TM_ATTR_TRACE_SIZE = 11, | ||
281 | IWL_TM_ATTR_TRACE_DUMP = 12, | ||
282 | IWL_TM_ATTR_FIXRATE = 13, | ||
283 | IWL_TM_ATTR_UCODE_OWNER = 14, | ||
284 | IWL_TM_ATTR_MEM_ADDR = 15, | ||
285 | IWL_TM_ATTR_BUFFER_SIZE = 16, | ||
286 | IWL_TM_ATTR_BUFFER_DUMP = 17, | ||
287 | IWL_TM_ATTR_FW_VERSION = 18, | ||
288 | IWL_TM_ATTR_DEVICE_ID = 19, | ||
289 | IWL_TM_ATTR_FW_TYPE = 20, | ||
290 | IWL_TM_ATTR_FW_INST_SIZE = 21, | ||
291 | IWL_TM_ATTR_FW_DATA_SIZE = 22, | ||
292 | IWL_TM_ATTR_UCODE_CMD_SKB = 23, | ||
293 | IWL_TM_ATTR_ENABLE_NOTIFICATION = 24, | ||
294 | IWL_TM_ATTR_MAX = 25, | ||
295 | }; | ||
296 | |||
297 | /* uCode trace buffer */ | ||
298 | #define TRACE_BUFF_SIZE_MAX 0x200000 | ||
299 | #define TRACE_BUFF_SIZE_MIN 0x20000 | ||
300 | #define TRACE_BUFF_SIZE_DEF TRACE_BUFF_SIZE_MIN | ||
301 | #define TRACE_BUFF_PADD 0x2000 | ||
302 | |||
303 | /* Maximum data size of each dump it packet */ | ||
304 | #define DUMP_CHUNK_SIZE (PAGE_SIZE - 1024) | ||
305 | |||
306 | /* Address offset of data segment in SRAM */ | ||
307 | #define SRAM_DATA_SEG_OFFSET 0x800000 | ||
308 | |||
309 | #endif | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/tt.c b/drivers/net/wireless/iwlwifi/dvm/tt.c new file mode 100644 index 000000000000..eb864433e59d --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/tt.c | |||
@@ -0,0 +1,693 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2007 - 2012 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 | |||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include <linux/init.h> | ||
34 | #include <net/mac80211.h> | ||
35 | #include "iwl-io.h" | ||
36 | #include "iwl-modparams.h" | ||
37 | #include "iwl-debug.h" | ||
38 | #include "agn.h" | ||
39 | #include "dev.h" | ||
40 | #include "commands.h" | ||
41 | #include "tt.h" | ||
42 | |||
43 | /* default Thermal Throttling transaction table | ||
44 | * Current state | Throttling Down | Throttling Up | ||
45 | *============================================================================= | ||
46 | * Condition Nxt State Condition Nxt State Condition Nxt State | ||
47 | *----------------------------------------------------------------------------- | ||
48 | * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A | ||
49 | * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0 | ||
50 | * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1 | ||
51 | * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0 | ||
52 | *============================================================================= | ||
53 | */ | ||
54 | static const struct iwl_tt_trans tt_range_0[IWL_TI_STATE_MAX - 1] = { | ||
55 | {IWL_TI_0, IWL_ABSOLUTE_ZERO, 104}, | ||
56 | {IWL_TI_1, 105, CT_KILL_THRESHOLD - 1}, | ||
57 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX} | ||
58 | }; | ||
59 | static const struct iwl_tt_trans tt_range_1[IWL_TI_STATE_MAX - 1] = { | ||
60 | {IWL_TI_0, IWL_ABSOLUTE_ZERO, 95}, | ||
61 | {IWL_TI_2, 110, CT_KILL_THRESHOLD - 1}, | ||
62 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX} | ||
63 | }; | ||
64 | static const struct iwl_tt_trans tt_range_2[IWL_TI_STATE_MAX - 1] = { | ||
65 | {IWL_TI_1, IWL_ABSOLUTE_ZERO, 100}, | ||
66 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}, | ||
67 | {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX} | ||
68 | }; | ||
69 | static const struct iwl_tt_trans tt_range_3[IWL_TI_STATE_MAX - 1] = { | ||
70 | {IWL_TI_0, IWL_ABSOLUTE_ZERO, CT_KILL_EXIT_THRESHOLD}, | ||
71 | {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX}, | ||
72 | {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX} | ||
73 | }; | ||
74 | |||
75 | /* Advance Thermal Throttling default restriction table */ | ||
76 | static const struct iwl_tt_restriction restriction_range[IWL_TI_STATE_MAX] = { | ||
77 | {IWL_ANT_OK_MULTI, IWL_ANT_OK_MULTI, true }, | ||
78 | {IWL_ANT_OK_SINGLE, IWL_ANT_OK_MULTI, true }, | ||
79 | {IWL_ANT_OK_SINGLE, IWL_ANT_OK_SINGLE, false }, | ||
80 | {IWL_ANT_OK_NONE, IWL_ANT_OK_NONE, false } | ||
81 | }; | ||
82 | |||
83 | bool iwl_tt_is_low_power_state(struct iwl_priv *priv) | ||
84 | { | ||
85 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
86 | |||
87 | if (tt->state >= IWL_TI_1) | ||
88 | return true; | ||
89 | return false; | ||
90 | } | ||
91 | |||
92 | u8 iwl_tt_current_power_mode(struct iwl_priv *priv) | ||
93 | { | ||
94 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
95 | |||
96 | return tt->tt_power_mode; | ||
97 | } | ||
98 | |||
99 | bool iwl_ht_enabled(struct iwl_priv *priv) | ||
100 | { | ||
101 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
102 | struct iwl_tt_restriction *restriction; | ||
103 | |||
104 | if (!priv->thermal_throttle.advanced_tt) | ||
105 | return true; | ||
106 | restriction = tt->restriction + tt->state; | ||
107 | return restriction->is_ht; | ||
108 | } | ||
109 | |||
110 | static bool iwl_within_ct_kill_margin(struct iwl_priv *priv) | ||
111 | { | ||
112 | s32 temp = priv->temperature; /* degrees CELSIUS except specified */ | ||
113 | bool within_margin = false; | ||
114 | |||
115 | if (!priv->thermal_throttle.advanced_tt) | ||
116 | within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >= | ||
117 | CT_KILL_THRESHOLD_LEGACY) ? true : false; | ||
118 | else | ||
119 | within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >= | ||
120 | CT_KILL_THRESHOLD) ? true : false; | ||
121 | return within_margin; | ||
122 | } | ||
123 | |||
124 | bool iwl_check_for_ct_kill(struct iwl_priv *priv) | ||
125 | { | ||
126 | bool is_ct_kill = false; | ||
127 | |||
128 | if (iwl_within_ct_kill_margin(priv)) { | ||
129 | iwl_tt_enter_ct_kill(priv); | ||
130 | is_ct_kill = true; | ||
131 | } | ||
132 | return is_ct_kill; | ||
133 | } | ||
134 | |||
135 | enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv) | ||
136 | { | ||
137 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
138 | struct iwl_tt_restriction *restriction; | ||
139 | |||
140 | if (!priv->thermal_throttle.advanced_tt) | ||
141 | return IWL_ANT_OK_MULTI; | ||
142 | restriction = tt->restriction + tt->state; | ||
143 | return restriction->tx_stream; | ||
144 | } | ||
145 | |||
146 | enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv) | ||
147 | { | ||
148 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
149 | struct iwl_tt_restriction *restriction; | ||
150 | |||
151 | if (!priv->thermal_throttle.advanced_tt) | ||
152 | return IWL_ANT_OK_MULTI; | ||
153 | restriction = tt->restriction + tt->state; | ||
154 | return restriction->rx_stream; | ||
155 | } | ||
156 | |||
157 | #define CT_KILL_EXIT_DURATION (5) /* 5 seconds duration */ | ||
158 | #define CT_KILL_WAITING_DURATION (300) /* 300ms duration */ | ||
159 | |||
160 | /* | ||
161 | * toggle the bit to wake up uCode and check the temperature | ||
162 | * if the temperature is below CT, uCode will stay awake and send card | ||
163 | * state notification with CT_KILL bit clear to inform Thermal Throttling | ||
164 | * Management to change state. Otherwise, uCode will go back to sleep | ||
165 | * without doing anything, driver should continue the 5 seconds timer | ||
166 | * to wake up uCode for temperature check until temperature drop below CT | ||
167 | */ | ||
168 | static void iwl_tt_check_exit_ct_kill(unsigned long data) | ||
169 | { | ||
170 | struct iwl_priv *priv = (struct iwl_priv *)data; | ||
171 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
172 | unsigned long flags; | ||
173 | |||
174 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
175 | return; | ||
176 | |||
177 | if (tt->state == IWL_TI_CT_KILL) { | ||
178 | if (priv->thermal_throttle.ct_kill_toggle) { | ||
179 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, | ||
180 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); | ||
181 | priv->thermal_throttle.ct_kill_toggle = false; | ||
182 | } else { | ||
183 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, | ||
184 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); | ||
185 | priv->thermal_throttle.ct_kill_toggle = true; | ||
186 | } | ||
187 | iwl_read32(priv->trans, CSR_UCODE_DRV_GP1); | ||
188 | spin_lock_irqsave(&priv->trans->reg_lock, flags); | ||
189 | if (likely(iwl_grab_nic_access(priv->trans))) | ||
190 | iwl_release_nic_access(priv->trans); | ||
191 | spin_unlock_irqrestore(&priv->trans->reg_lock, flags); | ||
192 | |||
193 | /* Reschedule the ct_kill timer to occur in | ||
194 | * CT_KILL_EXIT_DURATION seconds to ensure we get a | ||
195 | * thermal update */ | ||
196 | IWL_DEBUG_TEMP(priv, "schedule ct_kill exit timer\n"); | ||
197 | mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, | ||
198 | jiffies + CT_KILL_EXIT_DURATION * HZ); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | static void iwl_perform_ct_kill_task(struct iwl_priv *priv, | ||
203 | bool stop) | ||
204 | { | ||
205 | if (stop) { | ||
206 | IWL_DEBUG_TEMP(priv, "Stop all queues\n"); | ||
207 | if (priv->mac80211_registered) | ||
208 | ieee80211_stop_queues(priv->hw); | ||
209 | IWL_DEBUG_TEMP(priv, | ||
210 | "Schedule 5 seconds CT_KILL Timer\n"); | ||
211 | mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, | ||
212 | jiffies + CT_KILL_EXIT_DURATION * HZ); | ||
213 | } else { | ||
214 | IWL_DEBUG_TEMP(priv, "Wake all queues\n"); | ||
215 | if (priv->mac80211_registered) | ||
216 | ieee80211_wake_queues(priv->hw); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | static void iwl_tt_ready_for_ct_kill(unsigned long data) | ||
221 | { | ||
222 | struct iwl_priv *priv = (struct iwl_priv *)data; | ||
223 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
224 | |||
225 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
226 | return; | ||
227 | |||
228 | /* temperature timer expired, ready to go into CT_KILL state */ | ||
229 | if (tt->state != IWL_TI_CT_KILL) { | ||
230 | IWL_DEBUG_TEMP(priv, "entering CT_KILL state when " | ||
231 | "temperature timer expired\n"); | ||
232 | tt->state = IWL_TI_CT_KILL; | ||
233 | set_bit(STATUS_CT_KILL, &priv->status); | ||
234 | iwl_perform_ct_kill_task(priv, true); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | static void iwl_prepare_ct_kill_task(struct iwl_priv *priv) | ||
239 | { | ||
240 | IWL_DEBUG_TEMP(priv, "Prepare to enter IWL_TI_CT_KILL\n"); | ||
241 | /* make request to retrieve statistics information */ | ||
242 | iwl_send_statistics_request(priv, CMD_SYNC, false); | ||
243 | /* Reschedule the ct_kill wait timer */ | ||
244 | mod_timer(&priv->thermal_throttle.ct_kill_waiting_tm, | ||
245 | jiffies + msecs_to_jiffies(CT_KILL_WAITING_DURATION)); | ||
246 | } | ||
247 | |||
248 | #define IWL_MINIMAL_POWER_THRESHOLD (CT_KILL_THRESHOLD_LEGACY) | ||
249 | #define IWL_REDUCED_PERFORMANCE_THRESHOLD_2 (100) | ||
250 | #define IWL_REDUCED_PERFORMANCE_THRESHOLD_1 (90) | ||
251 | |||
252 | /* | ||
253 | * Legacy thermal throttling | ||
254 | * 1) Avoid NIC destruction due to high temperatures | ||
255 | * Chip will identify dangerously high temperatures that can | ||
256 | * harm the device and will power down | ||
257 | * 2) Avoid the NIC power down due to high temperature | ||
258 | * Throttle early enough to lower the power consumption before | ||
259 | * drastic steps are needed | ||
260 | */ | ||
261 | static void iwl_legacy_tt_handler(struct iwl_priv *priv, s32 temp, bool force) | ||
262 | { | ||
263 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
264 | enum iwl_tt_state old_state; | ||
265 | |||
266 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
267 | if ((tt->tt_previous_temp) && | ||
268 | (temp > tt->tt_previous_temp) && | ||
269 | ((temp - tt->tt_previous_temp) > | ||
270 | IWL_TT_INCREASE_MARGIN)) { | ||
271 | IWL_DEBUG_TEMP(priv, | ||
272 | "Temperature increase %d degree Celsius\n", | ||
273 | (temp - tt->tt_previous_temp)); | ||
274 | } | ||
275 | #endif | ||
276 | old_state = tt->state; | ||
277 | /* in Celsius */ | ||
278 | if (temp >= IWL_MINIMAL_POWER_THRESHOLD) | ||
279 | tt->state = IWL_TI_CT_KILL; | ||
280 | else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_2) | ||
281 | tt->state = IWL_TI_2; | ||
282 | else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_1) | ||
283 | tt->state = IWL_TI_1; | ||
284 | else | ||
285 | tt->state = IWL_TI_0; | ||
286 | |||
287 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
288 | tt->tt_previous_temp = temp; | ||
289 | #endif | ||
290 | /* stop ct_kill_waiting_tm timer */ | ||
291 | del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm); | ||
292 | if (tt->state != old_state) { | ||
293 | switch (tt->state) { | ||
294 | case IWL_TI_0: | ||
295 | /* | ||
296 | * When the system is ready to go back to IWL_TI_0 | ||
297 | * we only have to call iwl_power_update_mode() to | ||
298 | * do so. | ||
299 | */ | ||
300 | break; | ||
301 | case IWL_TI_1: | ||
302 | tt->tt_power_mode = IWL_POWER_INDEX_3; | ||
303 | break; | ||
304 | case IWL_TI_2: | ||
305 | tt->tt_power_mode = IWL_POWER_INDEX_4; | ||
306 | break; | ||
307 | default: | ||
308 | tt->tt_power_mode = IWL_POWER_INDEX_5; | ||
309 | break; | ||
310 | } | ||
311 | mutex_lock(&priv->mutex); | ||
312 | if (old_state == IWL_TI_CT_KILL) | ||
313 | clear_bit(STATUS_CT_KILL, &priv->status); | ||
314 | if (tt->state != IWL_TI_CT_KILL && | ||
315 | iwl_power_update_mode(priv, true)) { | ||
316 | /* TT state not updated | ||
317 | * try again during next temperature read | ||
318 | */ | ||
319 | if (old_state == IWL_TI_CT_KILL) | ||
320 | set_bit(STATUS_CT_KILL, &priv->status); | ||
321 | tt->state = old_state; | ||
322 | IWL_ERR(priv, "Cannot update power mode, " | ||
323 | "TT state not updated\n"); | ||
324 | } else { | ||
325 | if (tt->state == IWL_TI_CT_KILL) { | ||
326 | if (force) { | ||
327 | set_bit(STATUS_CT_KILL, &priv->status); | ||
328 | iwl_perform_ct_kill_task(priv, true); | ||
329 | } else { | ||
330 | iwl_prepare_ct_kill_task(priv); | ||
331 | tt->state = old_state; | ||
332 | } | ||
333 | } else if (old_state == IWL_TI_CT_KILL && | ||
334 | tt->state != IWL_TI_CT_KILL) | ||
335 | iwl_perform_ct_kill_task(priv, false); | ||
336 | IWL_DEBUG_TEMP(priv, "Temperature state changed %u\n", | ||
337 | tt->state); | ||
338 | IWL_DEBUG_TEMP(priv, "Power Index change to %u\n", | ||
339 | tt->tt_power_mode); | ||
340 | } | ||
341 | mutex_unlock(&priv->mutex); | ||
342 | } | ||
343 | } | ||
344 | |||
345 | /* | ||
346 | * Advance thermal throttling | ||
347 | * 1) Avoid NIC destruction due to high temperatures | ||
348 | * Chip will identify dangerously high temperatures that can | ||
349 | * harm the device and will power down | ||
350 | * 2) Avoid the NIC power down due to high temperature | ||
351 | * Throttle early enough to lower the power consumption before | ||
352 | * drastic steps are needed | ||
353 | * Actions include relaxing the power down sleep thresholds and | ||
354 | * decreasing the number of TX streams | ||
355 | * 3) Avoid throughput performance impact as much as possible | ||
356 | * | ||
357 | *============================================================================= | ||
358 | * Condition Nxt State Condition Nxt State Condition Nxt State | ||
359 | *----------------------------------------------------------------------------- | ||
360 | * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A | ||
361 | * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0 | ||
362 | * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1 | ||
363 | * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0 | ||
364 | *============================================================================= | ||
365 | */ | ||
366 | static void iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp, bool force) | ||
367 | { | ||
368 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
369 | int i; | ||
370 | bool changed = false; | ||
371 | enum iwl_tt_state old_state; | ||
372 | struct iwl_tt_trans *transaction; | ||
373 | |||
374 | old_state = tt->state; | ||
375 | for (i = 0; i < IWL_TI_STATE_MAX - 1; i++) { | ||
376 | /* based on the current TT state, | ||
377 | * find the curresponding transaction table | ||
378 | * each table has (IWL_TI_STATE_MAX - 1) entries | ||
379 | * tt->transaction + ((old_state * (IWL_TI_STATE_MAX - 1)) | ||
380 | * will advance to the correct table. | ||
381 | * then based on the current temperature | ||
382 | * find the next state need to transaction to | ||
383 | * go through all the possible (IWL_TI_STATE_MAX - 1) entries | ||
384 | * in the current table to see if transaction is needed | ||
385 | */ | ||
386 | transaction = tt->transaction + | ||
387 | ((old_state * (IWL_TI_STATE_MAX - 1)) + i); | ||
388 | if (temp >= transaction->tt_low && | ||
389 | temp <= transaction->tt_high) { | ||
390 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
391 | if ((tt->tt_previous_temp) && | ||
392 | (temp > tt->tt_previous_temp) && | ||
393 | ((temp - tt->tt_previous_temp) > | ||
394 | IWL_TT_INCREASE_MARGIN)) { | ||
395 | IWL_DEBUG_TEMP(priv, | ||
396 | "Temperature increase %d " | ||
397 | "degree Celsius\n", | ||
398 | (temp - tt->tt_previous_temp)); | ||
399 | } | ||
400 | tt->tt_previous_temp = temp; | ||
401 | #endif | ||
402 | if (old_state != | ||
403 | transaction->next_state) { | ||
404 | changed = true; | ||
405 | tt->state = | ||
406 | transaction->next_state; | ||
407 | } | ||
408 | break; | ||
409 | } | ||
410 | } | ||
411 | /* stop ct_kill_waiting_tm timer */ | ||
412 | del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm); | ||
413 | if (changed) { | ||
414 | if (tt->state >= IWL_TI_1) { | ||
415 | /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */ | ||
416 | tt->tt_power_mode = IWL_POWER_INDEX_5; | ||
417 | |||
418 | if (!iwl_ht_enabled(priv)) { | ||
419 | struct iwl_rxon_context *ctx; | ||
420 | |||
421 | for_each_context(priv, ctx) { | ||
422 | struct iwl_rxon_cmd *rxon; | ||
423 | |||
424 | rxon = &ctx->staging; | ||
425 | |||
426 | /* disable HT */ | ||
427 | rxon->flags &= ~( | ||
428 | RXON_FLG_CHANNEL_MODE_MSK | | ||
429 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | | ||
430 | RXON_FLG_HT40_PROT_MSK | | ||
431 | RXON_FLG_HT_PROT_MSK); | ||
432 | } | ||
433 | } else { | ||
434 | /* check HT capability and set | ||
435 | * according to the system HT capability | ||
436 | * in case get disabled before */ | ||
437 | iwl_set_rxon_ht(priv, &priv->current_ht_config); | ||
438 | } | ||
439 | |||
440 | } else { | ||
441 | /* | ||
442 | * restore system power setting -- it will be | ||
443 | * recalculated automatically. | ||
444 | */ | ||
445 | |||
446 | /* check HT capability and set | ||
447 | * according to the system HT capability | ||
448 | * in case get disabled before */ | ||
449 | iwl_set_rxon_ht(priv, &priv->current_ht_config); | ||
450 | } | ||
451 | mutex_lock(&priv->mutex); | ||
452 | if (old_state == IWL_TI_CT_KILL) | ||
453 | clear_bit(STATUS_CT_KILL, &priv->status); | ||
454 | if (tt->state != IWL_TI_CT_KILL && | ||
455 | iwl_power_update_mode(priv, true)) { | ||
456 | /* TT state not updated | ||
457 | * try again during next temperature read | ||
458 | */ | ||
459 | IWL_ERR(priv, "Cannot update power mode, " | ||
460 | "TT state not updated\n"); | ||
461 | if (old_state == IWL_TI_CT_KILL) | ||
462 | set_bit(STATUS_CT_KILL, &priv->status); | ||
463 | tt->state = old_state; | ||
464 | } else { | ||
465 | IWL_DEBUG_TEMP(priv, | ||
466 | "Thermal Throttling to new state: %u\n", | ||
467 | tt->state); | ||
468 | if (old_state != IWL_TI_CT_KILL && | ||
469 | tt->state == IWL_TI_CT_KILL) { | ||
470 | if (force) { | ||
471 | IWL_DEBUG_TEMP(priv, | ||
472 | "Enter IWL_TI_CT_KILL\n"); | ||
473 | set_bit(STATUS_CT_KILL, &priv->status); | ||
474 | iwl_perform_ct_kill_task(priv, true); | ||
475 | } else { | ||
476 | iwl_prepare_ct_kill_task(priv); | ||
477 | tt->state = old_state; | ||
478 | } | ||
479 | } else if (old_state == IWL_TI_CT_KILL && | ||
480 | tt->state != IWL_TI_CT_KILL) { | ||
481 | IWL_DEBUG_TEMP(priv, "Exit IWL_TI_CT_KILL\n"); | ||
482 | iwl_perform_ct_kill_task(priv, false); | ||
483 | } | ||
484 | } | ||
485 | mutex_unlock(&priv->mutex); | ||
486 | } | ||
487 | } | ||
488 | |||
489 | /* Card State Notification indicated reach critical temperature | ||
490 | * if PSP not enable, no Thermal Throttling function will be performed | ||
491 | * just set the GP1 bit to acknowledge the event | ||
492 | * otherwise, go into IWL_TI_CT_KILL state | ||
493 | * since Card State Notification will not provide any temperature reading | ||
494 | * for Legacy mode | ||
495 | * so just pass the CT_KILL temperature to iwl_legacy_tt_handler() | ||
496 | * for advance mode | ||
497 | * pass CT_KILL_THRESHOLD+1 to make sure move into IWL_TI_CT_KILL state | ||
498 | */ | ||
499 | static void iwl_bg_ct_enter(struct work_struct *work) | ||
500 | { | ||
501 | struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_enter); | ||
502 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
503 | |||
504 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
505 | return; | ||
506 | |||
507 | if (!iwl_is_ready(priv)) | ||
508 | return; | ||
509 | |||
510 | if (tt->state != IWL_TI_CT_KILL) { | ||
511 | IWL_ERR(priv, "Device reached critical temperature " | ||
512 | "- ucode going to sleep!\n"); | ||
513 | if (!priv->thermal_throttle.advanced_tt) | ||
514 | iwl_legacy_tt_handler(priv, | ||
515 | IWL_MINIMAL_POWER_THRESHOLD, | ||
516 | true); | ||
517 | else | ||
518 | iwl_advance_tt_handler(priv, | ||
519 | CT_KILL_THRESHOLD + 1, true); | ||
520 | } | ||
521 | } | ||
522 | |||
523 | /* Card State Notification indicated out of critical temperature | ||
524 | * since Card State Notification will not provide any temperature reading | ||
525 | * so pass the IWL_REDUCED_PERFORMANCE_THRESHOLD_2 temperature | ||
526 | * to iwl_legacy_tt_handler() to get out of IWL_CT_KILL state | ||
527 | */ | ||
528 | static void iwl_bg_ct_exit(struct work_struct *work) | ||
529 | { | ||
530 | struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_exit); | ||
531 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
532 | |||
533 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
534 | return; | ||
535 | |||
536 | if (!iwl_is_ready(priv)) | ||
537 | return; | ||
538 | |||
539 | /* stop ct_kill_exit_tm timer */ | ||
540 | del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm); | ||
541 | |||
542 | if (tt->state == IWL_TI_CT_KILL) { | ||
543 | IWL_ERR(priv, | ||
544 | "Device temperature below critical" | ||
545 | "- ucode awake!\n"); | ||
546 | /* | ||
547 | * exit from CT_KILL state | ||
548 | * reset the current temperature reading | ||
549 | */ | ||
550 | priv->temperature = 0; | ||
551 | if (!priv->thermal_throttle.advanced_tt) | ||
552 | iwl_legacy_tt_handler(priv, | ||
553 | IWL_REDUCED_PERFORMANCE_THRESHOLD_2, | ||
554 | true); | ||
555 | else | ||
556 | iwl_advance_tt_handler(priv, CT_KILL_EXIT_THRESHOLD, | ||
557 | true); | ||
558 | } | ||
559 | } | ||
560 | |||
561 | void iwl_tt_enter_ct_kill(struct iwl_priv *priv) | ||
562 | { | ||
563 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
564 | return; | ||
565 | |||
566 | IWL_DEBUG_TEMP(priv, "Queueing critical temperature enter.\n"); | ||
567 | queue_work(priv->workqueue, &priv->ct_enter); | ||
568 | } | ||
569 | |||
570 | void iwl_tt_exit_ct_kill(struct iwl_priv *priv) | ||
571 | { | ||
572 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
573 | return; | ||
574 | |||
575 | IWL_DEBUG_TEMP(priv, "Queueing critical temperature exit.\n"); | ||
576 | queue_work(priv->workqueue, &priv->ct_exit); | ||
577 | } | ||
578 | |||
579 | static void iwl_bg_tt_work(struct work_struct *work) | ||
580 | { | ||
581 | struct iwl_priv *priv = container_of(work, struct iwl_priv, tt_work); | ||
582 | s32 temp = priv->temperature; /* degrees CELSIUS except specified */ | ||
583 | |||
584 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
585 | return; | ||
586 | |||
587 | if (!priv->thermal_throttle.advanced_tt) | ||
588 | iwl_legacy_tt_handler(priv, temp, false); | ||
589 | else | ||
590 | iwl_advance_tt_handler(priv, temp, false); | ||
591 | } | ||
592 | |||
593 | void iwl_tt_handler(struct iwl_priv *priv) | ||
594 | { | ||
595 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
596 | return; | ||
597 | |||
598 | IWL_DEBUG_TEMP(priv, "Queueing thermal throttling work.\n"); | ||
599 | queue_work(priv->workqueue, &priv->tt_work); | ||
600 | } | ||
601 | |||
602 | /* Thermal throttling initialization | ||
603 | * For advance thermal throttling: | ||
604 | * Initialize Thermal Index and temperature threshold table | ||
605 | * Initialize thermal throttling restriction table | ||
606 | */ | ||
607 | void iwl_tt_initialize(struct iwl_priv *priv) | ||
608 | { | ||
609 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
610 | int size = sizeof(struct iwl_tt_trans) * (IWL_TI_STATE_MAX - 1); | ||
611 | struct iwl_tt_trans *transaction; | ||
612 | |||
613 | IWL_DEBUG_TEMP(priv, "Initialize Thermal Throttling\n"); | ||
614 | |||
615 | memset(tt, 0, sizeof(struct iwl_tt_mgmt)); | ||
616 | |||
617 | tt->state = IWL_TI_0; | ||
618 | init_timer(&priv->thermal_throttle.ct_kill_exit_tm); | ||
619 | priv->thermal_throttle.ct_kill_exit_tm.data = (unsigned long)priv; | ||
620 | priv->thermal_throttle.ct_kill_exit_tm.function = | ||
621 | iwl_tt_check_exit_ct_kill; | ||
622 | init_timer(&priv->thermal_throttle.ct_kill_waiting_tm); | ||
623 | priv->thermal_throttle.ct_kill_waiting_tm.data = | ||
624 | (unsigned long)priv; | ||
625 | priv->thermal_throttle.ct_kill_waiting_tm.function = | ||
626 | iwl_tt_ready_for_ct_kill; | ||
627 | /* setup deferred ct kill work */ | ||
628 | INIT_WORK(&priv->tt_work, iwl_bg_tt_work); | ||
629 | INIT_WORK(&priv->ct_enter, iwl_bg_ct_enter); | ||
630 | INIT_WORK(&priv->ct_exit, iwl_bg_ct_exit); | ||
631 | |||
632 | if (priv->cfg->base_params->adv_thermal_throttle) { | ||
633 | IWL_DEBUG_TEMP(priv, "Advanced Thermal Throttling\n"); | ||
634 | tt->restriction = kcalloc(IWL_TI_STATE_MAX, | ||
635 | sizeof(struct iwl_tt_restriction), | ||
636 | GFP_KERNEL); | ||
637 | tt->transaction = kcalloc(IWL_TI_STATE_MAX * | ||
638 | (IWL_TI_STATE_MAX - 1), | ||
639 | sizeof(struct iwl_tt_trans), | ||
640 | GFP_KERNEL); | ||
641 | if (!tt->restriction || !tt->transaction) { | ||
642 | IWL_ERR(priv, "Fallback to Legacy Throttling\n"); | ||
643 | priv->thermal_throttle.advanced_tt = false; | ||
644 | kfree(tt->restriction); | ||
645 | tt->restriction = NULL; | ||
646 | kfree(tt->transaction); | ||
647 | tt->transaction = NULL; | ||
648 | } else { | ||
649 | transaction = tt->transaction + | ||
650 | (IWL_TI_0 * (IWL_TI_STATE_MAX - 1)); | ||
651 | memcpy(transaction, &tt_range_0[0], size); | ||
652 | transaction = tt->transaction + | ||
653 | (IWL_TI_1 * (IWL_TI_STATE_MAX - 1)); | ||
654 | memcpy(transaction, &tt_range_1[0], size); | ||
655 | transaction = tt->transaction + | ||
656 | (IWL_TI_2 * (IWL_TI_STATE_MAX - 1)); | ||
657 | memcpy(transaction, &tt_range_2[0], size); | ||
658 | transaction = tt->transaction + | ||
659 | (IWL_TI_CT_KILL * (IWL_TI_STATE_MAX - 1)); | ||
660 | memcpy(transaction, &tt_range_3[0], size); | ||
661 | size = sizeof(struct iwl_tt_restriction) * | ||
662 | IWL_TI_STATE_MAX; | ||
663 | memcpy(tt->restriction, | ||
664 | &restriction_range[0], size); | ||
665 | priv->thermal_throttle.advanced_tt = true; | ||
666 | } | ||
667 | } else { | ||
668 | IWL_DEBUG_TEMP(priv, "Legacy Thermal Throttling\n"); | ||
669 | priv->thermal_throttle.advanced_tt = false; | ||
670 | } | ||
671 | } | ||
672 | |||
673 | /* cleanup thermal throttling management related memory and timer */ | ||
674 | void iwl_tt_exit(struct iwl_priv *priv) | ||
675 | { | ||
676 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
677 | |||
678 | /* stop ct_kill_exit_tm timer if activated */ | ||
679 | del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm); | ||
680 | /* stop ct_kill_waiting_tm timer if activated */ | ||
681 | del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm); | ||
682 | cancel_work_sync(&priv->tt_work); | ||
683 | cancel_work_sync(&priv->ct_enter); | ||
684 | cancel_work_sync(&priv->ct_exit); | ||
685 | |||
686 | if (priv->thermal_throttle.advanced_tt) { | ||
687 | /* free advance thermal throttling memory */ | ||
688 | kfree(tt->restriction); | ||
689 | tt->restriction = NULL; | ||
690 | kfree(tt->transaction); | ||
691 | tt->transaction = NULL; | ||
692 | } | ||
693 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/tt.h b/drivers/net/wireless/iwlwifi/dvm/tt.h new file mode 100644 index 000000000000..44c7c8f30a2d --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/tt.h | |||
@@ -0,0 +1,128 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2007 - 2012 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_tt_setting_h__ | ||
29 | #define __iwl_tt_setting_h__ | ||
30 | |||
31 | #include "commands.h" | ||
32 | |||
33 | #define IWL_ABSOLUTE_ZERO 0 | ||
34 | #define IWL_ABSOLUTE_MAX 0xFFFFFFFF | ||
35 | #define IWL_TT_INCREASE_MARGIN 5 | ||
36 | #define IWL_TT_CT_KILL_MARGIN 3 | ||
37 | |||
38 | enum iwl_antenna_ok { | ||
39 | IWL_ANT_OK_NONE, | ||
40 | IWL_ANT_OK_SINGLE, | ||
41 | IWL_ANT_OK_MULTI, | ||
42 | }; | ||
43 | |||
44 | /* Thermal Throttling State Machine states */ | ||
45 | enum iwl_tt_state { | ||
46 | IWL_TI_0, /* normal temperature, system power state */ | ||
47 | IWL_TI_1, /* high temperature detect, low power state */ | ||
48 | IWL_TI_2, /* higher temperature detected, lower power state */ | ||
49 | IWL_TI_CT_KILL, /* critical temperature detected, lowest power state */ | ||
50 | IWL_TI_STATE_MAX | ||
51 | }; | ||
52 | |||
53 | /** | ||
54 | * struct iwl_tt_restriction - Thermal Throttling restriction table | ||
55 | * @tx_stream: number of tx stream allowed | ||
56 | * @is_ht: ht enable/disable | ||
57 | * @rx_stream: number of rx stream allowed | ||
58 | * | ||
59 | * This table is used by advance thermal throttling management | ||
60 | * based on the current thermal throttling state, and determines | ||
61 | * the number of tx/rx streams and the status of HT operation. | ||
62 | */ | ||
63 | struct iwl_tt_restriction { | ||
64 | enum iwl_antenna_ok tx_stream; | ||
65 | enum iwl_antenna_ok rx_stream; | ||
66 | bool is_ht; | ||
67 | }; | ||
68 | |||
69 | /** | ||
70 | * struct iwl_tt_trans - Thermal Throttling transaction table | ||
71 | * @next_state: next thermal throttling mode | ||
72 | * @tt_low: low temperature threshold to change state | ||
73 | * @tt_high: high temperature threshold to change state | ||
74 | * | ||
75 | * This is used by the advanced thermal throttling algorithm | ||
76 | * to determine the next thermal state to go based on the | ||
77 | * current temperature. | ||
78 | */ | ||
79 | struct iwl_tt_trans { | ||
80 | enum iwl_tt_state next_state; | ||
81 | u32 tt_low; | ||
82 | u32 tt_high; | ||
83 | }; | ||
84 | |||
85 | /** | ||
86 | * struct iwl_tt_mgnt - Thermal Throttling Management structure | ||
87 | * @advanced_tt: advanced thermal throttle required | ||
88 | * @state: current Thermal Throttling state | ||
89 | * @tt_power_mode: Thermal Throttling power mode index | ||
90 | * being used to set power level when | ||
91 | * when thermal throttling state != IWL_TI_0 | ||
92 | * the tt_power_mode should set to different | ||
93 | * power mode based on the current tt state | ||
94 | * @tt_previous_temperature: last measured temperature | ||
95 | * @iwl_tt_restriction: ptr to restriction tbl, used by advance | ||
96 | * thermal throttling to determine how many tx/rx streams | ||
97 | * should be used in tt state; and can HT be enabled or not | ||
98 | * @iwl_tt_trans: ptr to adv trans table, used by advance thermal throttling | ||
99 | * state transaction | ||
100 | * @ct_kill_toggle: used to toggle the CSR bit when checking uCode temperature | ||
101 | * @ct_kill_exit_tm: timer to exit thermal kill | ||
102 | */ | ||
103 | struct iwl_tt_mgmt { | ||
104 | enum iwl_tt_state state; | ||
105 | bool advanced_tt; | ||
106 | u8 tt_power_mode; | ||
107 | bool ct_kill_toggle; | ||
108 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
109 | s32 tt_previous_temp; | ||
110 | #endif | ||
111 | struct iwl_tt_restriction *restriction; | ||
112 | struct iwl_tt_trans *transaction; | ||
113 | struct timer_list ct_kill_exit_tm; | ||
114 | struct timer_list ct_kill_waiting_tm; | ||
115 | }; | ||
116 | |||
117 | u8 iwl_tt_current_power_mode(struct iwl_priv *priv); | ||
118 | bool iwl_tt_is_low_power_state(struct iwl_priv *priv); | ||
119 | bool iwl_ht_enabled(struct iwl_priv *priv); | ||
120 | enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv); | ||
121 | enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv); | ||
122 | void iwl_tt_enter_ct_kill(struct iwl_priv *priv); | ||
123 | void iwl_tt_exit_ct_kill(struct iwl_priv *priv); | ||
124 | void iwl_tt_handler(struct iwl_priv *priv); | ||
125 | void iwl_tt_initialize(struct iwl_priv *priv); | ||
126 | void iwl_tt_exit(struct iwl_priv *priv); | ||
127 | |||
128 | #endif /* __iwl_tt_setting_h__ */ | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/tx.c b/drivers/net/wireless/iwlwifi/dvm/tx.c new file mode 100644 index 000000000000..0dfaf649b257 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/tx.c | |||
@@ -0,0 +1,1386 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * GPL LICENSE SUMMARY | ||
4 | * | ||
5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of version 2 of the GNU General Public License as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
19 | * USA | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called LICENSE.GPL. | ||
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 | *****************************************************************************/ | ||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/sched.h> | ||
34 | #include <linux/ieee80211.h> | ||
35 | #include "iwl-io.h" | ||
36 | #include "iwl-trans.h" | ||
37 | #include "iwl-agn-hw.h" | ||
38 | #include "dev.h" | ||
39 | #include "agn.h" | ||
40 | |||
41 | static const u8 tid_to_ac[] = { | ||
42 | IEEE80211_AC_BE, | ||
43 | IEEE80211_AC_BK, | ||
44 | IEEE80211_AC_BK, | ||
45 | IEEE80211_AC_BE, | ||
46 | IEEE80211_AC_VI, | ||
47 | IEEE80211_AC_VI, | ||
48 | IEEE80211_AC_VO, | ||
49 | IEEE80211_AC_VO, | ||
50 | }; | ||
51 | |||
52 | static void iwlagn_tx_cmd_protection(struct iwl_priv *priv, | ||
53 | struct ieee80211_tx_info *info, | ||
54 | __le16 fc, __le32 *tx_flags) | ||
55 | { | ||
56 | if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS || | ||
57 | info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT || | ||
58 | info->flags & IEEE80211_TX_CTL_AMPDU) | ||
59 | *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK; | ||
60 | } | ||
61 | |||
62 | /* | ||
63 | * handle build REPLY_TX command notification. | ||
64 | */ | ||
65 | static void iwlagn_tx_cmd_build_basic(struct iwl_priv *priv, | ||
66 | struct sk_buff *skb, | ||
67 | struct iwl_tx_cmd *tx_cmd, | ||
68 | struct ieee80211_tx_info *info, | ||
69 | struct ieee80211_hdr *hdr, u8 sta_id) | ||
70 | { | ||
71 | __le16 fc = hdr->frame_control; | ||
72 | __le32 tx_flags = tx_cmd->tx_flags; | ||
73 | |||
74 | tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; | ||
75 | |||
76 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) | ||
77 | tx_flags |= TX_CMD_FLG_ACK_MSK; | ||
78 | else | ||
79 | tx_flags &= ~TX_CMD_FLG_ACK_MSK; | ||
80 | |||
81 | if (ieee80211_is_probe_resp(fc)) | ||
82 | tx_flags |= TX_CMD_FLG_TSF_MSK; | ||
83 | else if (ieee80211_is_back_req(fc)) | ||
84 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; | ||
85 | else if (info->band == IEEE80211_BAND_2GHZ && | ||
86 | priv->cfg->bt_params && | ||
87 | priv->cfg->bt_params->advanced_bt_coexist && | ||
88 | (ieee80211_is_auth(fc) || ieee80211_is_assoc_req(fc) || | ||
89 | ieee80211_is_reassoc_req(fc) || | ||
90 | skb->protocol == cpu_to_be16(ETH_P_PAE))) | ||
91 | tx_flags |= TX_CMD_FLG_IGNORE_BT; | ||
92 | |||
93 | |||
94 | tx_cmd->sta_id = sta_id; | ||
95 | if (ieee80211_has_morefrags(fc)) | ||
96 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; | ||
97 | |||
98 | if (ieee80211_is_data_qos(fc)) { | ||
99 | u8 *qc = ieee80211_get_qos_ctl(hdr); | ||
100 | tx_cmd->tid_tspec = qc[0] & 0xf; | ||
101 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; | ||
102 | } else { | ||
103 | tx_cmd->tid_tspec = IWL_TID_NON_QOS; | ||
104 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) | ||
105 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; | ||
106 | else | ||
107 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; | ||
108 | } | ||
109 | |||
110 | iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags); | ||
111 | |||
112 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); | ||
113 | if (ieee80211_is_mgmt(fc)) { | ||
114 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) | ||
115 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3); | ||
116 | else | ||
117 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2); | ||
118 | } else { | ||
119 | tx_cmd->timeout.pm_frame_timeout = 0; | ||
120 | } | ||
121 | |||
122 | tx_cmd->driver_txop = 0; | ||
123 | tx_cmd->tx_flags = tx_flags; | ||
124 | tx_cmd->next_frame_len = 0; | ||
125 | } | ||
126 | |||
127 | static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv, | ||
128 | struct iwl_tx_cmd *tx_cmd, | ||
129 | struct ieee80211_tx_info *info, | ||
130 | __le16 fc) | ||
131 | { | ||
132 | u32 rate_flags; | ||
133 | int rate_idx; | ||
134 | u8 rts_retry_limit; | ||
135 | u8 data_retry_limit; | ||
136 | u8 rate_plcp; | ||
137 | |||
138 | if (priv->wowlan) { | ||
139 | rts_retry_limit = IWLAGN_LOW_RETRY_LIMIT; | ||
140 | data_retry_limit = IWLAGN_LOW_RETRY_LIMIT; | ||
141 | } else { | ||
142 | /* Set retry limit on RTS packets */ | ||
143 | rts_retry_limit = IWLAGN_RTS_DFAULT_RETRY_LIMIT; | ||
144 | |||
145 | /* Set retry limit on DATA packets and Probe Responses*/ | ||
146 | if (ieee80211_is_probe_resp(fc)) { | ||
147 | data_retry_limit = IWLAGN_MGMT_DFAULT_RETRY_LIMIT; | ||
148 | rts_retry_limit = | ||
149 | min(data_retry_limit, rts_retry_limit); | ||
150 | } else if (ieee80211_is_back_req(fc)) | ||
151 | data_retry_limit = IWLAGN_BAR_DFAULT_RETRY_LIMIT; | ||
152 | else | ||
153 | data_retry_limit = IWLAGN_DEFAULT_TX_RETRY; | ||
154 | } | ||
155 | |||
156 | tx_cmd->data_retry_limit = data_retry_limit; | ||
157 | tx_cmd->rts_retry_limit = rts_retry_limit; | ||
158 | |||
159 | /* DATA packets will use the uCode station table for rate/antenna | ||
160 | * selection */ | ||
161 | if (ieee80211_is_data(fc)) { | ||
162 | tx_cmd->initial_rate_index = 0; | ||
163 | tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; | ||
164 | #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE | ||
165 | if (priv->tm_fixed_rate) { | ||
166 | /* | ||
167 | * rate overwrite by testmode | ||
168 | * we not only send lq command to change rate | ||
169 | * we also re-enforce per data pkt base. | ||
170 | */ | ||
171 | tx_cmd->tx_flags &= ~TX_CMD_FLG_STA_RATE_MSK; | ||
172 | memcpy(&tx_cmd->rate_n_flags, &priv->tm_fixed_rate, | ||
173 | sizeof(tx_cmd->rate_n_flags)); | ||
174 | } | ||
175 | #endif | ||
176 | return; | ||
177 | } else if (ieee80211_is_back_req(fc)) | ||
178 | tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; | ||
179 | |||
180 | /** | ||
181 | * If the current TX rate stored in mac80211 has the MCS bit set, it's | ||
182 | * not really a TX rate. Thus, we use the lowest supported rate for | ||
183 | * this band. Also use the lowest supported rate if the stored rate | ||
184 | * index is invalid. | ||
185 | */ | ||
186 | rate_idx = info->control.rates[0].idx; | ||
187 | if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS || | ||
188 | (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY)) | ||
189 | rate_idx = rate_lowest_index( | ||
190 | &priv->eeprom_data->bands[info->band], | ||
191 | info->control.sta); | ||
192 | /* For 5 GHZ band, remap mac80211 rate indices into driver indices */ | ||
193 | if (info->band == IEEE80211_BAND_5GHZ) | ||
194 | rate_idx += IWL_FIRST_OFDM_RATE; | ||
195 | /* Get PLCP rate for tx_cmd->rate_n_flags */ | ||
196 | rate_plcp = iwl_rates[rate_idx].plcp; | ||
197 | /* Zero out flags for this packet */ | ||
198 | rate_flags = 0; | ||
199 | |||
200 | /* Set CCK flag as needed */ | ||
201 | if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) | ||
202 | rate_flags |= RATE_MCS_CCK_MSK; | ||
203 | |||
204 | /* Set up antennas */ | ||
205 | if (priv->cfg->bt_params && | ||
206 | priv->cfg->bt_params->advanced_bt_coexist && | ||
207 | priv->bt_full_concurrent) { | ||
208 | /* operated as 1x1 in full concurrency mode */ | ||
209 | priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, | ||
210 | first_antenna(priv->eeprom_data->valid_tx_ant)); | ||
211 | } else | ||
212 | priv->mgmt_tx_ant = iwl_toggle_tx_ant( | ||
213 | priv, priv->mgmt_tx_ant, | ||
214 | priv->eeprom_data->valid_tx_ant); | ||
215 | rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant); | ||
216 | |||
217 | /* Set the rate in the TX cmd */ | ||
218 | tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags); | ||
219 | } | ||
220 | |||
221 | static void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv, | ||
222 | struct ieee80211_tx_info *info, | ||
223 | struct iwl_tx_cmd *tx_cmd, | ||
224 | struct sk_buff *skb_frag) | ||
225 | { | ||
226 | struct ieee80211_key_conf *keyconf = info->control.hw_key; | ||
227 | |||
228 | switch (keyconf->cipher) { | ||
229 | case WLAN_CIPHER_SUITE_CCMP: | ||
230 | tx_cmd->sec_ctl = TX_CMD_SEC_CCM; | ||
231 | memcpy(tx_cmd->key, keyconf->key, keyconf->keylen); | ||
232 | if (info->flags & IEEE80211_TX_CTL_AMPDU) | ||
233 | tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; | ||
234 | IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n"); | ||
235 | break; | ||
236 | |||
237 | case WLAN_CIPHER_SUITE_TKIP: | ||
238 | tx_cmd->sec_ctl = TX_CMD_SEC_TKIP; | ||
239 | ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key); | ||
240 | IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n"); | ||
241 | break; | ||
242 | |||
243 | case WLAN_CIPHER_SUITE_WEP104: | ||
244 | tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128; | ||
245 | /* fall through */ | ||
246 | case WLAN_CIPHER_SUITE_WEP40: | ||
247 | tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP | | ||
248 | (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT); | ||
249 | |||
250 | memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen); | ||
251 | |||
252 | IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption " | ||
253 | "with key %d\n", keyconf->keyidx); | ||
254 | break; | ||
255 | |||
256 | default: | ||
257 | IWL_ERR(priv, "Unknown encode cipher %x\n", keyconf->cipher); | ||
258 | break; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | /** | ||
263 | * iwl_sta_id_or_broadcast - return sta_id or broadcast sta | ||
264 | * @context: the current context | ||
265 | * @sta: mac80211 station | ||
266 | * | ||
267 | * In certain circumstances mac80211 passes a station pointer | ||
268 | * that may be %NULL, for example during TX or key setup. In | ||
269 | * that case, we need to use the broadcast station, so this | ||
270 | * inline wraps that pattern. | ||
271 | */ | ||
272 | static int iwl_sta_id_or_broadcast(struct iwl_rxon_context *context, | ||
273 | struct ieee80211_sta *sta) | ||
274 | { | ||
275 | int sta_id; | ||
276 | |||
277 | if (!sta) | ||
278 | return context->bcast_sta_id; | ||
279 | |||
280 | sta_id = iwl_sta_id(sta); | ||
281 | |||
282 | /* | ||
283 | * mac80211 should not be passing a partially | ||
284 | * initialised station! | ||
285 | */ | ||
286 | WARN_ON(sta_id == IWL_INVALID_STATION); | ||
287 | |||
288 | return sta_id; | ||
289 | } | ||
290 | |||
291 | /* | ||
292 | * start REPLY_TX command process | ||
293 | */ | ||
294 | int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb) | ||
295 | { | ||
296 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | ||
297 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | ||
298 | struct iwl_station_priv *sta_priv = NULL; | ||
299 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | ||
300 | struct iwl_device_cmd *dev_cmd; | ||
301 | struct iwl_tx_cmd *tx_cmd; | ||
302 | __le16 fc; | ||
303 | u8 hdr_len; | ||
304 | u16 len, seq_number = 0; | ||
305 | u8 sta_id, tid = IWL_MAX_TID_COUNT; | ||
306 | bool is_agg = false; | ||
307 | int txq_id; | ||
308 | |||
309 | if (info->control.vif) | ||
310 | ctx = iwl_rxon_ctx_from_vif(info->control.vif); | ||
311 | |||
312 | if (iwl_is_rfkill(priv)) { | ||
313 | IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n"); | ||
314 | goto drop_unlock_priv; | ||
315 | } | ||
316 | |||
317 | fc = hdr->frame_control; | ||
318 | |||
319 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
320 | if (ieee80211_is_auth(fc)) | ||
321 | IWL_DEBUG_TX(priv, "Sending AUTH frame\n"); | ||
322 | else if (ieee80211_is_assoc_req(fc)) | ||
323 | IWL_DEBUG_TX(priv, "Sending ASSOC frame\n"); | ||
324 | else if (ieee80211_is_reassoc_req(fc)) | ||
325 | IWL_DEBUG_TX(priv, "Sending REASSOC frame\n"); | ||
326 | #endif | ||
327 | |||
328 | if (unlikely(ieee80211_is_probe_resp(fc))) { | ||
329 | struct iwl_wipan_noa_data *noa_data = | ||
330 | rcu_dereference(priv->noa_data); | ||
331 | |||
332 | if (noa_data && | ||
333 | pskb_expand_head(skb, 0, noa_data->length, | ||
334 | GFP_ATOMIC) == 0) { | ||
335 | memcpy(skb_put(skb, noa_data->length), | ||
336 | noa_data->data, noa_data->length); | ||
337 | hdr = (struct ieee80211_hdr *)skb->data; | ||
338 | } | ||
339 | } | ||
340 | |||
341 | hdr_len = ieee80211_hdrlen(fc); | ||
342 | |||
343 | /* For management frames use broadcast id to do not break aggregation */ | ||
344 | if (!ieee80211_is_data(fc)) | ||
345 | sta_id = ctx->bcast_sta_id; | ||
346 | else { | ||
347 | /* Find index into station table for destination station */ | ||
348 | sta_id = iwl_sta_id_or_broadcast(ctx, info->control.sta); | ||
349 | if (sta_id == IWL_INVALID_STATION) { | ||
350 | IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", | ||
351 | hdr->addr1); | ||
352 | goto drop_unlock_priv; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | IWL_DEBUG_TX(priv, "station Id %d\n", sta_id); | ||
357 | |||
358 | if (info->control.sta) | ||
359 | sta_priv = (void *)info->control.sta->drv_priv; | ||
360 | |||
361 | if (sta_priv && sta_priv->asleep && | ||
362 | (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)) { | ||
363 | /* | ||
364 | * This sends an asynchronous command to the device, | ||
365 | * but we can rely on it being processed before the | ||
366 | * next frame is processed -- and the next frame to | ||
367 | * this station is the one that will consume this | ||
368 | * counter. | ||
369 | * For now set the counter to just 1 since we do not | ||
370 | * support uAPSD yet. | ||
371 | * | ||
372 | * FIXME: If we get two non-bufferable frames one | ||
373 | * after the other, we might only send out one of | ||
374 | * them because this is racy. | ||
375 | */ | ||
376 | iwl_sta_modify_sleep_tx_count(priv, sta_id, 1); | ||
377 | } | ||
378 | |||
379 | if (info->flags & IEEE80211_TX_CTL_AMPDU) | ||
380 | is_agg = true; | ||
381 | |||
382 | dev_cmd = iwl_trans_alloc_tx_cmd(priv->trans); | ||
383 | |||
384 | if (unlikely(!dev_cmd)) | ||
385 | goto drop_unlock_priv; | ||
386 | |||
387 | memset(dev_cmd, 0, sizeof(*dev_cmd)); | ||
388 | tx_cmd = (struct iwl_tx_cmd *) dev_cmd->payload; | ||
389 | |||
390 | /* Total # bytes to be transmitted */ | ||
391 | len = (u16)skb->len; | ||
392 | tx_cmd->len = cpu_to_le16(len); | ||
393 | |||
394 | if (info->control.hw_key) | ||
395 | iwlagn_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb); | ||
396 | |||
397 | /* TODO need this for burst mode later on */ | ||
398 | iwlagn_tx_cmd_build_basic(priv, skb, tx_cmd, info, hdr, sta_id); | ||
399 | |||
400 | iwlagn_tx_cmd_build_rate(priv, tx_cmd, info, fc); | ||
401 | |||
402 | memset(&info->status, 0, sizeof(info->status)); | ||
403 | |||
404 | info->driver_data[0] = ctx; | ||
405 | info->driver_data[1] = dev_cmd; | ||
406 | |||
407 | spin_lock(&priv->sta_lock); | ||
408 | |||
409 | if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) { | ||
410 | u8 *qc = NULL; | ||
411 | struct iwl_tid_data *tid_data; | ||
412 | qc = ieee80211_get_qos_ctl(hdr); | ||
413 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; | ||
414 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) | ||
415 | goto drop_unlock_sta; | ||
416 | tid_data = &priv->tid_data[sta_id][tid]; | ||
417 | |||
418 | /* aggregation is on for this <sta,tid> */ | ||
419 | if (info->flags & IEEE80211_TX_CTL_AMPDU && | ||
420 | tid_data->agg.state != IWL_AGG_ON) { | ||
421 | IWL_ERR(priv, "TX_CTL_AMPDU while not in AGG:" | ||
422 | " Tx flags = 0x%08x, agg.state = %d", | ||
423 | info->flags, tid_data->agg.state); | ||
424 | IWL_ERR(priv, "sta_id = %d, tid = %d seq_num = %d", | ||
425 | sta_id, tid, SEQ_TO_SN(tid_data->seq_number)); | ||
426 | goto drop_unlock_sta; | ||
427 | } | ||
428 | |||
429 | /* We can receive packets from the stack in IWL_AGG_{ON,OFF} | ||
430 | * only. Check this here. | ||
431 | */ | ||
432 | if (WARN_ONCE(tid_data->agg.state != IWL_AGG_ON && | ||
433 | tid_data->agg.state != IWL_AGG_OFF, | ||
434 | "Tx while agg.state = %d", tid_data->agg.state)) | ||
435 | goto drop_unlock_sta; | ||
436 | |||
437 | seq_number = tid_data->seq_number; | ||
438 | seq_number &= IEEE80211_SCTL_SEQ; | ||
439 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); | ||
440 | hdr->seq_ctrl |= cpu_to_le16(seq_number); | ||
441 | seq_number += 0x10; | ||
442 | } | ||
443 | |||
444 | /* Copy MAC header from skb into command buffer */ | ||
445 | memcpy(tx_cmd->hdr, hdr, hdr_len); | ||
446 | |||
447 | if (is_agg) | ||
448 | txq_id = priv->tid_data[sta_id][tid].agg.txq_id; | ||
449 | else if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) { | ||
450 | /* | ||
451 | * Send this frame after DTIM -- there's a special queue | ||
452 | * reserved for this for contexts that support AP mode. | ||
453 | */ | ||
454 | txq_id = ctx->mcast_queue; | ||
455 | |||
456 | /* | ||
457 | * The microcode will clear the more data | ||
458 | * bit in the last frame it transmits. | ||
459 | */ | ||
460 | hdr->frame_control |= | ||
461 | cpu_to_le16(IEEE80211_FCTL_MOREDATA); | ||
462 | } else if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) | ||
463 | txq_id = IWL_AUX_QUEUE; | ||
464 | else | ||
465 | txq_id = ctx->ac_to_queue[skb_get_queue_mapping(skb)]; | ||
466 | |||
467 | WARN_ON_ONCE(!is_agg && txq_id != info->hw_queue); | ||
468 | WARN_ON_ONCE(is_agg && | ||
469 | priv->queue_to_mac80211[txq_id] != info->hw_queue); | ||
470 | |||
471 | if (iwl_trans_tx(priv->trans, skb, dev_cmd, txq_id)) | ||
472 | goto drop_unlock_sta; | ||
473 | |||
474 | if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc) && | ||
475 | !ieee80211_has_morefrags(fc)) | ||
476 | priv->tid_data[sta_id][tid].seq_number = seq_number; | ||
477 | |||
478 | spin_unlock(&priv->sta_lock); | ||
479 | |||
480 | /* | ||
481 | * Avoid atomic ops if it isn't an associated client. | ||
482 | * Also, if this is a packet for aggregation, don't | ||
483 | * increase the counter because the ucode will stop | ||
484 | * aggregation queues when their respective station | ||
485 | * goes to sleep. | ||
486 | */ | ||
487 | if (sta_priv && sta_priv->client && !is_agg) | ||
488 | atomic_inc(&sta_priv->pending_frames); | ||
489 | |||
490 | if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) | ||
491 | iwl_scan_offchannel_skb(priv); | ||
492 | |||
493 | return 0; | ||
494 | |||
495 | drop_unlock_sta: | ||
496 | if (dev_cmd) | ||
497 | iwl_trans_free_tx_cmd(priv->trans, dev_cmd); | ||
498 | spin_unlock(&priv->sta_lock); | ||
499 | drop_unlock_priv: | ||
500 | return -1; | ||
501 | } | ||
502 | |||
503 | static int iwlagn_alloc_agg_txq(struct iwl_priv *priv, int mq) | ||
504 | { | ||
505 | int q; | ||
506 | |||
507 | for (q = IWLAGN_FIRST_AMPDU_QUEUE; | ||
508 | q < priv->cfg->base_params->num_of_queues; q++) { | ||
509 | if (!test_and_set_bit(q, priv->agg_q_alloc)) { | ||
510 | priv->queue_to_mac80211[q] = mq; | ||
511 | return q; | ||
512 | } | ||
513 | } | ||
514 | |||
515 | return -ENOSPC; | ||
516 | } | ||
517 | |||
518 | static void iwlagn_dealloc_agg_txq(struct iwl_priv *priv, int q) | ||
519 | { | ||
520 | clear_bit(q, priv->agg_q_alloc); | ||
521 | priv->queue_to_mac80211[q] = IWL_INVALID_MAC80211_QUEUE; | ||
522 | } | ||
523 | |||
524 | int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif, | ||
525 | struct ieee80211_sta *sta, u16 tid) | ||
526 | { | ||
527 | struct iwl_tid_data *tid_data; | ||
528 | int sta_id, txq_id; | ||
529 | enum iwl_agg_state agg_state; | ||
530 | |||
531 | sta_id = iwl_sta_id(sta); | ||
532 | |||
533 | if (sta_id == IWL_INVALID_STATION) { | ||
534 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); | ||
535 | return -ENXIO; | ||
536 | } | ||
537 | |||
538 | spin_lock_bh(&priv->sta_lock); | ||
539 | |||
540 | tid_data = &priv->tid_data[sta_id][tid]; | ||
541 | txq_id = priv->tid_data[sta_id][tid].agg.txq_id; | ||
542 | |||
543 | switch (priv->tid_data[sta_id][tid].agg.state) { | ||
544 | case IWL_EMPTYING_HW_QUEUE_ADDBA: | ||
545 | /* | ||
546 | * This can happen if the peer stops aggregation | ||
547 | * again before we've had a chance to drain the | ||
548 | * queue we selected previously, i.e. before the | ||
549 | * session was really started completely. | ||
550 | */ | ||
551 | IWL_DEBUG_HT(priv, "AGG stop before setup done\n"); | ||
552 | goto turn_off; | ||
553 | case IWL_AGG_STARTING: | ||
554 | /* | ||
555 | * This can happen when the session is stopped before | ||
556 | * we receive ADDBA response | ||
557 | */ | ||
558 | IWL_DEBUG_HT(priv, "AGG stop before AGG became operational\n"); | ||
559 | goto turn_off; | ||
560 | case IWL_AGG_ON: | ||
561 | break; | ||
562 | default: | ||
563 | IWL_WARN(priv, "Stopping AGG while state not ON " | ||
564 | "or starting for %d on %d (%d)\n", sta_id, tid, | ||
565 | priv->tid_data[sta_id][tid].agg.state); | ||
566 | spin_unlock_bh(&priv->sta_lock); | ||
567 | return 0; | ||
568 | } | ||
569 | |||
570 | tid_data->agg.ssn = SEQ_TO_SN(tid_data->seq_number); | ||
571 | |||
572 | /* There are still packets for this RA / TID in the HW */ | ||
573 | if (!test_bit(txq_id, priv->agg_q_alloc)) { | ||
574 | IWL_DEBUG_TX_QUEUES(priv, | ||
575 | "stopping AGG on STA/TID %d/%d but hwq %d not used\n", | ||
576 | sta_id, tid, txq_id); | ||
577 | } else if (tid_data->agg.ssn != tid_data->next_reclaimed) { | ||
578 | IWL_DEBUG_TX_QUEUES(priv, "Can't proceed: ssn %d, " | ||
579 | "next_recl = %d\n", | ||
580 | tid_data->agg.ssn, | ||
581 | tid_data->next_reclaimed); | ||
582 | priv->tid_data[sta_id][tid].agg.state = | ||
583 | IWL_EMPTYING_HW_QUEUE_DELBA; | ||
584 | spin_unlock_bh(&priv->sta_lock); | ||
585 | return 0; | ||
586 | } | ||
587 | |||
588 | IWL_DEBUG_TX_QUEUES(priv, "Can proceed: ssn = next_recl = %d\n", | ||
589 | tid_data->agg.ssn); | ||
590 | turn_off: | ||
591 | agg_state = priv->tid_data[sta_id][tid].agg.state; | ||
592 | priv->tid_data[sta_id][tid].agg.state = IWL_AGG_OFF; | ||
593 | |||
594 | spin_unlock_bh(&priv->sta_lock); | ||
595 | |||
596 | if (test_bit(txq_id, priv->agg_q_alloc)) { | ||
597 | /* | ||
598 | * If the transport didn't know that we wanted to start | ||
599 | * agreggation, don't tell it that we want to stop them. | ||
600 | * This can happen when we don't get the addBA response on | ||
601 | * time, or we hadn't time to drain the AC queues. | ||
602 | */ | ||
603 | if (agg_state == IWL_AGG_ON) | ||
604 | iwl_trans_txq_disable(priv->trans, txq_id); | ||
605 | else | ||
606 | IWL_DEBUG_TX_QUEUES(priv, "Don't disable tx agg: %d\n", | ||
607 | agg_state); | ||
608 | iwlagn_dealloc_agg_txq(priv, txq_id); | ||
609 | } | ||
610 | |||
611 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | ||
612 | |||
613 | return 0; | ||
614 | } | ||
615 | |||
616 | int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif, | ||
617 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) | ||
618 | { | ||
619 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | ||
620 | struct iwl_tid_data *tid_data; | ||
621 | int sta_id, txq_id, ret; | ||
622 | |||
623 | IWL_DEBUG_HT(priv, "TX AGG request on ra = %pM tid = %d\n", | ||
624 | sta->addr, tid); | ||
625 | |||
626 | sta_id = iwl_sta_id(sta); | ||
627 | if (sta_id == IWL_INVALID_STATION) { | ||
628 | IWL_ERR(priv, "Start AGG on invalid station\n"); | ||
629 | return -ENXIO; | ||
630 | } | ||
631 | if (unlikely(tid >= IWL_MAX_TID_COUNT)) | ||
632 | return -EINVAL; | ||
633 | |||
634 | if (priv->tid_data[sta_id][tid].agg.state != IWL_AGG_OFF) { | ||
635 | IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n"); | ||
636 | return -ENXIO; | ||
637 | } | ||
638 | |||
639 | txq_id = iwlagn_alloc_agg_txq(priv, ctx->ac_to_queue[tid_to_ac[tid]]); | ||
640 | if (txq_id < 0) { | ||
641 | IWL_DEBUG_TX_QUEUES(priv, | ||
642 | "No free aggregation queue for %pM/%d\n", | ||
643 | sta->addr, tid); | ||
644 | return txq_id; | ||
645 | } | ||
646 | |||
647 | ret = iwl_sta_tx_modify_enable_tid(priv, sta_id, tid); | ||
648 | if (ret) | ||
649 | return ret; | ||
650 | |||
651 | spin_lock_bh(&priv->sta_lock); | ||
652 | tid_data = &priv->tid_data[sta_id][tid]; | ||
653 | tid_data->agg.ssn = SEQ_TO_SN(tid_data->seq_number); | ||
654 | tid_data->agg.txq_id = txq_id; | ||
655 | |||
656 | *ssn = tid_data->agg.ssn; | ||
657 | |||
658 | if (*ssn == tid_data->next_reclaimed) { | ||
659 | IWL_DEBUG_TX_QUEUES(priv, "Can proceed: ssn = next_recl = %d\n", | ||
660 | tid_data->agg.ssn); | ||
661 | tid_data->agg.state = IWL_AGG_STARTING; | ||
662 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); | ||
663 | } else { | ||
664 | IWL_DEBUG_TX_QUEUES(priv, "Can't proceed: ssn %d, " | ||
665 | "next_reclaimed = %d\n", | ||
666 | tid_data->agg.ssn, | ||
667 | tid_data->next_reclaimed); | ||
668 | tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA; | ||
669 | } | ||
670 | spin_unlock_bh(&priv->sta_lock); | ||
671 | |||
672 | return ret; | ||
673 | } | ||
674 | |||
675 | int iwlagn_tx_agg_oper(struct iwl_priv *priv, struct ieee80211_vif *vif, | ||
676 | struct ieee80211_sta *sta, u16 tid, u8 buf_size) | ||
677 | { | ||
678 | struct iwl_station_priv *sta_priv = (void *) sta->drv_priv; | ||
679 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | ||
680 | int q, fifo; | ||
681 | u16 ssn; | ||
682 | |||
683 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); | ||
684 | |||
685 | spin_lock_bh(&priv->sta_lock); | ||
686 | ssn = priv->tid_data[sta_priv->sta_id][tid].agg.ssn; | ||
687 | q = priv->tid_data[sta_priv->sta_id][tid].agg.txq_id; | ||
688 | priv->tid_data[sta_priv->sta_id][tid].agg.state = IWL_AGG_ON; | ||
689 | spin_unlock_bh(&priv->sta_lock); | ||
690 | |||
691 | fifo = ctx->ac_to_fifo[tid_to_ac[tid]]; | ||
692 | |||
693 | iwl_trans_txq_enable(priv->trans, q, fifo, sta_priv->sta_id, tid, | ||
694 | buf_size, ssn); | ||
695 | |||
696 | /* | ||
697 | * If the limit is 0, then it wasn't initialised yet, | ||
698 | * use the default. We can do that since we take the | ||
699 | * minimum below, and we don't want to go above our | ||
700 | * default due to hardware restrictions. | ||
701 | */ | ||
702 | if (sta_priv->max_agg_bufsize == 0) | ||
703 | sta_priv->max_agg_bufsize = | ||
704 | LINK_QUAL_AGG_FRAME_LIMIT_DEF; | ||
705 | |||
706 | /* | ||
707 | * Even though in theory the peer could have different | ||
708 | * aggregation reorder buffer sizes for different sessions, | ||
709 | * our ucode doesn't allow for that and has a global limit | ||
710 | * for each station. Therefore, use the minimum of all the | ||
711 | * aggregation sessions and our default value. | ||
712 | */ | ||
713 | sta_priv->max_agg_bufsize = | ||
714 | min(sta_priv->max_agg_bufsize, buf_size); | ||
715 | |||
716 | if (priv->hw_params.use_rts_for_aggregation) { | ||
717 | /* | ||
718 | * switch to RTS/CTS if it is the prefer protection | ||
719 | * method for HT traffic | ||
720 | */ | ||
721 | |||
722 | sta_priv->lq_sta.lq.general_params.flags |= | ||
723 | LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; | ||
724 | } | ||
725 | priv->agg_tids_count++; | ||
726 | IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n", | ||
727 | priv->agg_tids_count); | ||
728 | |||
729 | sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit = | ||
730 | sta_priv->max_agg_bufsize; | ||
731 | |||
732 | IWL_DEBUG_HT(priv, "Tx aggregation enabled on ra = %pM tid = %d\n", | ||
733 | sta->addr, tid); | ||
734 | |||
735 | return iwl_send_lq_cmd(priv, ctx, | ||
736 | &sta_priv->lq_sta.lq, CMD_ASYNC, false); | ||
737 | } | ||
738 | |||
739 | static void iwlagn_check_ratid_empty(struct iwl_priv *priv, int sta_id, u8 tid) | ||
740 | { | ||
741 | struct iwl_tid_data *tid_data = &priv->tid_data[sta_id][tid]; | ||
742 | enum iwl_rxon_context_id ctx; | ||
743 | struct ieee80211_vif *vif; | ||
744 | u8 *addr; | ||
745 | |||
746 | lockdep_assert_held(&priv->sta_lock); | ||
747 | |||
748 | addr = priv->stations[sta_id].sta.sta.addr; | ||
749 | ctx = priv->stations[sta_id].ctxid; | ||
750 | vif = priv->contexts[ctx].vif; | ||
751 | |||
752 | switch (priv->tid_data[sta_id][tid].agg.state) { | ||
753 | case IWL_EMPTYING_HW_QUEUE_DELBA: | ||
754 | /* There are no packets for this RA / TID in the HW any more */ | ||
755 | if (tid_data->agg.ssn == tid_data->next_reclaimed) { | ||
756 | IWL_DEBUG_TX_QUEUES(priv, | ||
757 | "Can continue DELBA flow ssn = next_recl =" | ||
758 | " %d", tid_data->next_reclaimed); | ||
759 | iwl_trans_txq_disable(priv->trans, | ||
760 | tid_data->agg.txq_id); | ||
761 | iwlagn_dealloc_agg_txq(priv, tid_data->agg.txq_id); | ||
762 | tid_data->agg.state = IWL_AGG_OFF; | ||
763 | ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid); | ||
764 | } | ||
765 | break; | ||
766 | case IWL_EMPTYING_HW_QUEUE_ADDBA: | ||
767 | /* There are no packets for this RA / TID in the HW any more */ | ||
768 | if (tid_data->agg.ssn == tid_data->next_reclaimed) { | ||
769 | IWL_DEBUG_TX_QUEUES(priv, | ||
770 | "Can continue ADDBA flow ssn = next_recl =" | ||
771 | " %d", tid_data->next_reclaimed); | ||
772 | tid_data->agg.state = IWL_AGG_STARTING; | ||
773 | ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid); | ||
774 | } | ||
775 | break; | ||
776 | default: | ||
777 | break; | ||
778 | } | ||
779 | } | ||
780 | |||
781 | static void iwlagn_non_agg_tx_status(struct iwl_priv *priv, | ||
782 | struct iwl_rxon_context *ctx, | ||
783 | const u8 *addr1) | ||
784 | { | ||
785 | struct ieee80211_sta *sta; | ||
786 | struct iwl_station_priv *sta_priv; | ||
787 | |||
788 | rcu_read_lock(); | ||
789 | sta = ieee80211_find_sta(ctx->vif, addr1); | ||
790 | if (sta) { | ||
791 | sta_priv = (void *)sta->drv_priv; | ||
792 | /* avoid atomic ops if this isn't a client */ | ||
793 | if (sta_priv->client && | ||
794 | atomic_dec_return(&sta_priv->pending_frames) == 0) | ||
795 | ieee80211_sta_block_awake(priv->hw, sta, false); | ||
796 | } | ||
797 | rcu_read_unlock(); | ||
798 | } | ||
799 | |||
800 | /** | ||
801 | * translate ucode response to mac80211 tx status control values | ||
802 | */ | ||
803 | static void iwlagn_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags, | ||
804 | struct ieee80211_tx_info *info) | ||
805 | { | ||
806 | struct ieee80211_tx_rate *r = &info->status.rates[0]; | ||
807 | |||
808 | info->status.antenna = | ||
809 | ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); | ||
810 | if (rate_n_flags & RATE_MCS_HT_MSK) | ||
811 | r->flags |= IEEE80211_TX_RC_MCS; | ||
812 | if (rate_n_flags & RATE_MCS_GF_MSK) | ||
813 | r->flags |= IEEE80211_TX_RC_GREEN_FIELD; | ||
814 | if (rate_n_flags & RATE_MCS_HT40_MSK) | ||
815 | r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; | ||
816 | if (rate_n_flags & RATE_MCS_DUP_MSK) | ||
817 | r->flags |= IEEE80211_TX_RC_DUP_DATA; | ||
818 | if (rate_n_flags & RATE_MCS_SGI_MSK) | ||
819 | r->flags |= IEEE80211_TX_RC_SHORT_GI; | ||
820 | r->idx = iwlagn_hwrate_to_mac80211_idx(rate_n_flags, info->band); | ||
821 | } | ||
822 | |||
823 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
824 | const char *iwl_get_tx_fail_reason(u32 status) | ||
825 | { | ||
826 | #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x | ||
827 | #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x | ||
828 | |||
829 | switch (status & TX_STATUS_MSK) { | ||
830 | case TX_STATUS_SUCCESS: | ||
831 | return "SUCCESS"; | ||
832 | TX_STATUS_POSTPONE(DELAY); | ||
833 | TX_STATUS_POSTPONE(FEW_BYTES); | ||
834 | TX_STATUS_POSTPONE(BT_PRIO); | ||
835 | TX_STATUS_POSTPONE(QUIET_PERIOD); | ||
836 | TX_STATUS_POSTPONE(CALC_TTAK); | ||
837 | TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY); | ||
838 | TX_STATUS_FAIL(SHORT_LIMIT); | ||
839 | TX_STATUS_FAIL(LONG_LIMIT); | ||
840 | TX_STATUS_FAIL(FIFO_UNDERRUN); | ||
841 | TX_STATUS_FAIL(DRAIN_FLOW); | ||
842 | TX_STATUS_FAIL(RFKILL_FLUSH); | ||
843 | TX_STATUS_FAIL(LIFE_EXPIRE); | ||
844 | TX_STATUS_FAIL(DEST_PS); | ||
845 | TX_STATUS_FAIL(HOST_ABORTED); | ||
846 | TX_STATUS_FAIL(BT_RETRY); | ||
847 | TX_STATUS_FAIL(STA_INVALID); | ||
848 | TX_STATUS_FAIL(FRAG_DROPPED); | ||
849 | TX_STATUS_FAIL(TID_DISABLE); | ||
850 | TX_STATUS_FAIL(FIFO_FLUSHED); | ||
851 | TX_STATUS_FAIL(INSUFFICIENT_CF_POLL); | ||
852 | TX_STATUS_FAIL(PASSIVE_NO_RX); | ||
853 | TX_STATUS_FAIL(NO_BEACON_ON_RADAR); | ||
854 | } | ||
855 | |||
856 | return "UNKNOWN"; | ||
857 | |||
858 | #undef TX_STATUS_FAIL | ||
859 | #undef TX_STATUS_POSTPONE | ||
860 | } | ||
861 | #endif /* CONFIG_IWLWIFI_DEBUG */ | ||
862 | |||
863 | static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status) | ||
864 | { | ||
865 | status &= AGG_TX_STATUS_MSK; | ||
866 | |||
867 | switch (status) { | ||
868 | case AGG_TX_STATE_UNDERRUN_MSK: | ||
869 | priv->reply_agg_tx_stats.underrun++; | ||
870 | break; | ||
871 | case AGG_TX_STATE_BT_PRIO_MSK: | ||
872 | priv->reply_agg_tx_stats.bt_prio++; | ||
873 | break; | ||
874 | case AGG_TX_STATE_FEW_BYTES_MSK: | ||
875 | priv->reply_agg_tx_stats.few_bytes++; | ||
876 | break; | ||
877 | case AGG_TX_STATE_ABORT_MSK: | ||
878 | priv->reply_agg_tx_stats.abort++; | ||
879 | break; | ||
880 | case AGG_TX_STATE_LAST_SENT_TTL_MSK: | ||
881 | priv->reply_agg_tx_stats.last_sent_ttl++; | ||
882 | break; | ||
883 | case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK: | ||
884 | priv->reply_agg_tx_stats.last_sent_try++; | ||
885 | break; | ||
886 | case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK: | ||
887 | priv->reply_agg_tx_stats.last_sent_bt_kill++; | ||
888 | break; | ||
889 | case AGG_TX_STATE_SCD_QUERY_MSK: | ||
890 | priv->reply_agg_tx_stats.scd_query++; | ||
891 | break; | ||
892 | case AGG_TX_STATE_TEST_BAD_CRC32_MSK: | ||
893 | priv->reply_agg_tx_stats.bad_crc32++; | ||
894 | break; | ||
895 | case AGG_TX_STATE_RESPONSE_MSK: | ||
896 | priv->reply_agg_tx_stats.response++; | ||
897 | break; | ||
898 | case AGG_TX_STATE_DUMP_TX_MSK: | ||
899 | priv->reply_agg_tx_stats.dump_tx++; | ||
900 | break; | ||
901 | case AGG_TX_STATE_DELAY_TX_MSK: | ||
902 | priv->reply_agg_tx_stats.delay_tx++; | ||
903 | break; | ||
904 | default: | ||
905 | priv->reply_agg_tx_stats.unknown++; | ||
906 | break; | ||
907 | } | ||
908 | } | ||
909 | |||
910 | static void iwl_rx_reply_tx_agg(struct iwl_priv *priv, | ||
911 | struct iwlagn_tx_resp *tx_resp) | ||
912 | { | ||
913 | struct agg_tx_status *frame_status = &tx_resp->status; | ||
914 | int tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >> | ||
915 | IWLAGN_TX_RES_TID_POS; | ||
916 | int sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >> | ||
917 | IWLAGN_TX_RES_RA_POS; | ||
918 | struct iwl_ht_agg *agg = &priv->tid_data[sta_id][tid].agg; | ||
919 | u32 status = le16_to_cpu(tx_resp->status.status); | ||
920 | int i; | ||
921 | |||
922 | WARN_ON(tid == IWL_TID_NON_QOS); | ||
923 | |||
924 | if (agg->wait_for_ba) | ||
925 | IWL_DEBUG_TX_REPLY(priv, | ||
926 | "got tx response w/o block-ack\n"); | ||
927 | |||
928 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); | ||
929 | agg->wait_for_ba = (tx_resp->frame_count > 1); | ||
930 | |||
931 | /* | ||
932 | * If the BT kill count is non-zero, we'll get this | ||
933 | * notification again. | ||
934 | */ | ||
935 | if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 && | ||
936 | priv->cfg->bt_params && | ||
937 | priv->cfg->bt_params->advanced_bt_coexist) { | ||
938 | IWL_DEBUG_COEX(priv, "receive reply tx w/ bt_kill\n"); | ||
939 | } | ||
940 | |||
941 | if (tx_resp->frame_count == 1) | ||
942 | return; | ||
943 | |||
944 | /* Construct bit-map of pending frames within Tx window */ | ||
945 | for (i = 0; i < tx_resp->frame_count; i++) { | ||
946 | u16 fstatus = le16_to_cpu(frame_status[i].status); | ||
947 | |||
948 | if (status & AGG_TX_STATUS_MSK) | ||
949 | iwlagn_count_agg_tx_err_status(priv, fstatus); | ||
950 | |||
951 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | | ||
952 | AGG_TX_STATE_ABORT_MSK)) | ||
953 | continue; | ||
954 | |||
955 | IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), " | ||
956 | "try-count (0x%08x)\n", | ||
957 | iwl_get_agg_tx_fail_reason(fstatus), | ||
958 | fstatus & AGG_TX_STATUS_MSK, | ||
959 | fstatus & AGG_TX_TRY_MSK); | ||
960 | } | ||
961 | } | ||
962 | |||
963 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
964 | #define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x | ||
965 | |||
966 | const char *iwl_get_agg_tx_fail_reason(u16 status) | ||
967 | { | ||
968 | status &= AGG_TX_STATUS_MSK; | ||
969 | switch (status) { | ||
970 | case AGG_TX_STATE_TRANSMITTED: | ||
971 | return "SUCCESS"; | ||
972 | AGG_TX_STATE_FAIL(UNDERRUN_MSK); | ||
973 | AGG_TX_STATE_FAIL(BT_PRIO_MSK); | ||
974 | AGG_TX_STATE_FAIL(FEW_BYTES_MSK); | ||
975 | AGG_TX_STATE_FAIL(ABORT_MSK); | ||
976 | AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK); | ||
977 | AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK); | ||
978 | AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK); | ||
979 | AGG_TX_STATE_FAIL(SCD_QUERY_MSK); | ||
980 | AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK); | ||
981 | AGG_TX_STATE_FAIL(RESPONSE_MSK); | ||
982 | AGG_TX_STATE_FAIL(DUMP_TX_MSK); | ||
983 | AGG_TX_STATE_FAIL(DELAY_TX_MSK); | ||
984 | } | ||
985 | |||
986 | return "UNKNOWN"; | ||
987 | } | ||
988 | #endif /* CONFIG_IWLWIFI_DEBUG */ | ||
989 | |||
990 | static inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp) | ||
991 | { | ||
992 | return le32_to_cpup((__le32 *)&tx_resp->status + | ||
993 | tx_resp->frame_count) & MAX_SN; | ||
994 | } | ||
995 | |||
996 | static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status) | ||
997 | { | ||
998 | status &= TX_STATUS_MSK; | ||
999 | |||
1000 | switch (status) { | ||
1001 | case TX_STATUS_POSTPONE_DELAY: | ||
1002 | priv->reply_tx_stats.pp_delay++; | ||
1003 | break; | ||
1004 | case TX_STATUS_POSTPONE_FEW_BYTES: | ||
1005 | priv->reply_tx_stats.pp_few_bytes++; | ||
1006 | break; | ||
1007 | case TX_STATUS_POSTPONE_BT_PRIO: | ||
1008 | priv->reply_tx_stats.pp_bt_prio++; | ||
1009 | break; | ||
1010 | case TX_STATUS_POSTPONE_QUIET_PERIOD: | ||
1011 | priv->reply_tx_stats.pp_quiet_period++; | ||
1012 | break; | ||
1013 | case TX_STATUS_POSTPONE_CALC_TTAK: | ||
1014 | priv->reply_tx_stats.pp_calc_ttak++; | ||
1015 | break; | ||
1016 | case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY: | ||
1017 | priv->reply_tx_stats.int_crossed_retry++; | ||
1018 | break; | ||
1019 | case TX_STATUS_FAIL_SHORT_LIMIT: | ||
1020 | priv->reply_tx_stats.short_limit++; | ||
1021 | break; | ||
1022 | case TX_STATUS_FAIL_LONG_LIMIT: | ||
1023 | priv->reply_tx_stats.long_limit++; | ||
1024 | break; | ||
1025 | case TX_STATUS_FAIL_FIFO_UNDERRUN: | ||
1026 | priv->reply_tx_stats.fifo_underrun++; | ||
1027 | break; | ||
1028 | case TX_STATUS_FAIL_DRAIN_FLOW: | ||
1029 | priv->reply_tx_stats.drain_flow++; | ||
1030 | break; | ||
1031 | case TX_STATUS_FAIL_RFKILL_FLUSH: | ||
1032 | priv->reply_tx_stats.rfkill_flush++; | ||
1033 | break; | ||
1034 | case TX_STATUS_FAIL_LIFE_EXPIRE: | ||
1035 | priv->reply_tx_stats.life_expire++; | ||
1036 | break; | ||
1037 | case TX_STATUS_FAIL_DEST_PS: | ||
1038 | priv->reply_tx_stats.dest_ps++; | ||
1039 | break; | ||
1040 | case TX_STATUS_FAIL_HOST_ABORTED: | ||
1041 | priv->reply_tx_stats.host_abort++; | ||
1042 | break; | ||
1043 | case TX_STATUS_FAIL_BT_RETRY: | ||
1044 | priv->reply_tx_stats.bt_retry++; | ||
1045 | break; | ||
1046 | case TX_STATUS_FAIL_STA_INVALID: | ||
1047 | priv->reply_tx_stats.sta_invalid++; | ||
1048 | break; | ||
1049 | case TX_STATUS_FAIL_FRAG_DROPPED: | ||
1050 | priv->reply_tx_stats.frag_drop++; | ||
1051 | break; | ||
1052 | case TX_STATUS_FAIL_TID_DISABLE: | ||
1053 | priv->reply_tx_stats.tid_disable++; | ||
1054 | break; | ||
1055 | case TX_STATUS_FAIL_FIFO_FLUSHED: | ||
1056 | priv->reply_tx_stats.fifo_flush++; | ||
1057 | break; | ||
1058 | case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL: | ||
1059 | priv->reply_tx_stats.insuff_cf_poll++; | ||
1060 | break; | ||
1061 | case TX_STATUS_FAIL_PASSIVE_NO_RX: | ||
1062 | priv->reply_tx_stats.fail_hw_drop++; | ||
1063 | break; | ||
1064 | case TX_STATUS_FAIL_NO_BEACON_ON_RADAR: | ||
1065 | priv->reply_tx_stats.sta_color_mismatch++; | ||
1066 | break; | ||
1067 | default: | ||
1068 | priv->reply_tx_stats.unknown++; | ||
1069 | break; | ||
1070 | } | ||
1071 | } | ||
1072 | |||
1073 | static void iwlagn_set_tx_status(struct iwl_priv *priv, | ||
1074 | struct ieee80211_tx_info *info, | ||
1075 | struct iwlagn_tx_resp *tx_resp, | ||
1076 | bool is_agg) | ||
1077 | { | ||
1078 | u16 status = le16_to_cpu(tx_resp->status.status); | ||
1079 | |||
1080 | info->status.rates[0].count = tx_resp->failure_frame + 1; | ||
1081 | if (is_agg) | ||
1082 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; | ||
1083 | info->flags |= iwl_tx_status_to_mac80211(status); | ||
1084 | iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), | ||
1085 | info); | ||
1086 | if (!iwl_is_tx_success(status)) | ||
1087 | iwlagn_count_tx_err_status(priv, status); | ||
1088 | } | ||
1089 | |||
1090 | static void iwl_check_abort_status(struct iwl_priv *priv, | ||
1091 | u8 frame_count, u32 status) | ||
1092 | { | ||
1093 | if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) { | ||
1094 | IWL_ERR(priv, "Tx flush command to flush out all frames\n"); | ||
1095 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) | ||
1096 | queue_work(priv->workqueue, &priv->tx_flush); | ||
1097 | } | ||
1098 | } | ||
1099 | |||
1100 | static int iwl_reclaim(struct iwl_priv *priv, int sta_id, int tid, | ||
1101 | int txq_id, int ssn, struct sk_buff_head *skbs) | ||
1102 | { | ||
1103 | if (unlikely(txq_id >= IWLAGN_FIRST_AMPDU_QUEUE && | ||
1104 | tid != IWL_TID_NON_QOS && | ||
1105 | txq_id != priv->tid_data[sta_id][tid].agg.txq_id)) { | ||
1106 | /* | ||
1107 | * FIXME: this is a uCode bug which need to be addressed, | ||
1108 | * log the information and return for now. | ||
1109 | * Since it is can possibly happen very often and in order | ||
1110 | * not to fill the syslog, don't use IWL_ERR or IWL_WARN | ||
1111 | */ | ||
1112 | IWL_DEBUG_TX_QUEUES(priv, | ||
1113 | "Bad queue mapping txq_id=%d, agg_txq[sta:%d,tid:%d]=%d\n", | ||
1114 | txq_id, sta_id, tid, | ||
1115 | priv->tid_data[sta_id][tid].agg.txq_id); | ||
1116 | return 1; | ||
1117 | } | ||
1118 | |||
1119 | iwl_trans_reclaim(priv->trans, txq_id, ssn, skbs); | ||
1120 | return 0; | ||
1121 | } | ||
1122 | |||
1123 | int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, | ||
1124 | struct iwl_device_cmd *cmd) | ||
1125 | { | ||
1126 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
1127 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); | ||
1128 | int txq_id = SEQ_TO_QUEUE(sequence); | ||
1129 | int cmd_index __maybe_unused = SEQ_TO_INDEX(sequence); | ||
1130 | struct iwlagn_tx_resp *tx_resp = (void *)pkt->data; | ||
1131 | struct ieee80211_hdr *hdr; | ||
1132 | u32 status = le16_to_cpu(tx_resp->status.status); | ||
1133 | u16 ssn = iwlagn_get_scd_ssn(tx_resp); | ||
1134 | int tid; | ||
1135 | int sta_id; | ||
1136 | int freed; | ||
1137 | struct ieee80211_tx_info *info; | ||
1138 | struct sk_buff_head skbs; | ||
1139 | struct sk_buff *skb; | ||
1140 | struct iwl_rxon_context *ctx; | ||
1141 | bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE); | ||
1142 | bool is_offchannel_skb; | ||
1143 | |||
1144 | tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >> | ||
1145 | IWLAGN_TX_RES_TID_POS; | ||
1146 | sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >> | ||
1147 | IWLAGN_TX_RES_RA_POS; | ||
1148 | |||
1149 | spin_lock(&priv->sta_lock); | ||
1150 | |||
1151 | if (is_agg) | ||
1152 | iwl_rx_reply_tx_agg(priv, tx_resp); | ||
1153 | |||
1154 | __skb_queue_head_init(&skbs); | ||
1155 | |||
1156 | is_offchannel_skb = false; | ||
1157 | |||
1158 | if (tx_resp->frame_count == 1) { | ||
1159 | u16 next_reclaimed = le16_to_cpu(tx_resp->seq_ctl); | ||
1160 | next_reclaimed = SEQ_TO_SN(next_reclaimed + 0x10); | ||
1161 | |||
1162 | if (is_agg) { | ||
1163 | /* If this is an aggregation queue, we can rely on the | ||
1164 | * ssn since the wifi sequence number corresponds to | ||
1165 | * the index in the TFD ring (%256). | ||
1166 | * The seq_ctl is the sequence control of the packet | ||
1167 | * to which this Tx response relates. But if there is a | ||
1168 | * hole in the bitmap of the BA we received, this Tx | ||
1169 | * response may allow to reclaim the hole and all the | ||
1170 | * subsequent packets that were already acked. | ||
1171 | * In that case, seq_ctl != ssn, and the next packet | ||
1172 | * to be reclaimed will be ssn and not seq_ctl. | ||
1173 | */ | ||
1174 | next_reclaimed = ssn; | ||
1175 | } | ||
1176 | |||
1177 | if (tid != IWL_TID_NON_QOS) { | ||
1178 | priv->tid_data[sta_id][tid].next_reclaimed = | ||
1179 | next_reclaimed; | ||
1180 | IWL_DEBUG_TX_REPLY(priv, "Next reclaimed packet:%d\n", | ||
1181 | next_reclaimed); | ||
1182 | } | ||
1183 | |||
1184 | /*we can free until ssn % q.n_bd not inclusive */ | ||
1185 | WARN_ON(iwl_reclaim(priv, sta_id, tid, txq_id, ssn, &skbs)); | ||
1186 | iwlagn_check_ratid_empty(priv, sta_id, tid); | ||
1187 | freed = 0; | ||
1188 | |||
1189 | /* process frames */ | ||
1190 | skb_queue_walk(&skbs, skb) { | ||
1191 | hdr = (struct ieee80211_hdr *)skb->data; | ||
1192 | |||
1193 | if (!ieee80211_is_data_qos(hdr->frame_control)) | ||
1194 | priv->last_seq_ctl = tx_resp->seq_ctl; | ||
1195 | |||
1196 | info = IEEE80211_SKB_CB(skb); | ||
1197 | ctx = info->driver_data[0]; | ||
1198 | iwl_trans_free_tx_cmd(priv->trans, | ||
1199 | info->driver_data[1]); | ||
1200 | |||
1201 | memset(&info->status, 0, sizeof(info->status)); | ||
1202 | |||
1203 | if (status == TX_STATUS_FAIL_PASSIVE_NO_RX && | ||
1204 | iwl_is_associated_ctx(ctx) && ctx->vif && | ||
1205 | ctx->vif->type == NL80211_IFTYPE_STATION) { | ||
1206 | /* block and stop all queues */ | ||
1207 | priv->passive_no_rx = true; | ||
1208 | IWL_DEBUG_TX_QUEUES(priv, "stop all queues: " | ||
1209 | "passive channel"); | ||
1210 | ieee80211_stop_queues(priv->hw); | ||
1211 | |||
1212 | IWL_DEBUG_TX_REPLY(priv, | ||
1213 | "TXQ %d status %s (0x%08x) " | ||
1214 | "rate_n_flags 0x%x retries %d\n", | ||
1215 | txq_id, | ||
1216 | iwl_get_tx_fail_reason(status), | ||
1217 | status, | ||
1218 | le32_to_cpu(tx_resp->rate_n_flags), | ||
1219 | tx_resp->failure_frame); | ||
1220 | |||
1221 | IWL_DEBUG_TX_REPLY(priv, | ||
1222 | "FrameCnt = %d, idx=%d\n", | ||
1223 | tx_resp->frame_count, cmd_index); | ||
1224 | } | ||
1225 | |||
1226 | /* check if BAR is needed */ | ||
1227 | if (is_agg && !iwl_is_tx_success(status)) | ||
1228 | info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; | ||
1229 | iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(skb), | ||
1230 | tx_resp, is_agg); | ||
1231 | if (!is_agg) | ||
1232 | iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1); | ||
1233 | |||
1234 | is_offchannel_skb = | ||
1235 | (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN); | ||
1236 | freed++; | ||
1237 | } | ||
1238 | |||
1239 | WARN_ON(!is_agg && freed != 1); | ||
1240 | |||
1241 | /* | ||
1242 | * An offchannel frame can be send only on the AUX queue, where | ||
1243 | * there is no aggregation (and reordering) so it only is single | ||
1244 | * skb is expected to be processed. | ||
1245 | */ | ||
1246 | WARN_ON(is_offchannel_skb && freed != 1); | ||
1247 | } | ||
1248 | |||
1249 | iwl_check_abort_status(priv, tx_resp->frame_count, status); | ||
1250 | spin_unlock(&priv->sta_lock); | ||
1251 | |||
1252 | while (!skb_queue_empty(&skbs)) { | ||
1253 | skb = __skb_dequeue(&skbs); | ||
1254 | ieee80211_tx_status(priv->hw, skb); | ||
1255 | } | ||
1256 | |||
1257 | if (is_offchannel_skb) | ||
1258 | iwl_scan_offchannel_skb_status(priv); | ||
1259 | |||
1260 | return 0; | ||
1261 | } | ||
1262 | |||
1263 | /** | ||
1264 | * iwlagn_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA | ||
1265 | * | ||
1266 | * Handles block-acknowledge notification from device, which reports success | ||
1267 | * of frames sent via aggregation. | ||
1268 | */ | ||
1269 | int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv, | ||
1270 | struct iwl_rx_cmd_buffer *rxb, | ||
1271 | struct iwl_device_cmd *cmd) | ||
1272 | { | ||
1273 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
1274 | struct iwl_compressed_ba_resp *ba_resp = (void *)pkt->data; | ||
1275 | struct iwl_ht_agg *agg; | ||
1276 | struct sk_buff_head reclaimed_skbs; | ||
1277 | struct ieee80211_tx_info *info; | ||
1278 | struct ieee80211_hdr *hdr; | ||
1279 | struct sk_buff *skb; | ||
1280 | int sta_id; | ||
1281 | int tid; | ||
1282 | int freed; | ||
1283 | |||
1284 | /* "flow" corresponds to Tx queue */ | ||
1285 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); | ||
1286 | |||
1287 | /* "ssn" is start of block-ack Tx window, corresponds to index | ||
1288 | * (in Tx queue's circular buffer) of first TFD/frame in window */ | ||
1289 | u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn); | ||
1290 | |||
1291 | if (scd_flow >= priv->cfg->base_params->num_of_queues) { | ||
1292 | IWL_ERR(priv, | ||
1293 | "BUG_ON scd_flow is bigger than number of queues\n"); | ||
1294 | return 0; | ||
1295 | } | ||
1296 | |||
1297 | sta_id = ba_resp->sta_id; | ||
1298 | tid = ba_resp->tid; | ||
1299 | agg = &priv->tid_data[sta_id][tid].agg; | ||
1300 | |||
1301 | spin_lock(&priv->sta_lock); | ||
1302 | |||
1303 | if (unlikely(!agg->wait_for_ba)) { | ||
1304 | if (unlikely(ba_resp->bitmap)) | ||
1305 | IWL_ERR(priv, "Received BA when not expected\n"); | ||
1306 | spin_unlock(&priv->sta_lock); | ||
1307 | return 0; | ||
1308 | } | ||
1309 | |||
1310 | __skb_queue_head_init(&reclaimed_skbs); | ||
1311 | |||
1312 | /* Release all TFDs before the SSN, i.e. all TFDs in front of | ||
1313 | * block-ack window (we assume that they've been successfully | ||
1314 | * transmitted ... if not, it's too late anyway). */ | ||
1315 | if (iwl_reclaim(priv, sta_id, tid, scd_flow, | ||
1316 | ba_resp_scd_ssn, &reclaimed_skbs)) { | ||
1317 | spin_unlock(&priv->sta_lock); | ||
1318 | return 0; | ||
1319 | } | ||
1320 | |||
1321 | IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, " | ||
1322 | "sta_id = %d\n", | ||
1323 | agg->wait_for_ba, | ||
1324 | (u8 *) &ba_resp->sta_addr_lo32, | ||
1325 | ba_resp->sta_id); | ||
1326 | IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, " | ||
1327 | "scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n", | ||
1328 | ba_resp->tid, le16_to_cpu(ba_resp->seq_ctl), | ||
1329 | (unsigned long long)le64_to_cpu(ba_resp->bitmap), | ||
1330 | scd_flow, ba_resp_scd_ssn, ba_resp->txed, | ||
1331 | ba_resp->txed_2_done); | ||
1332 | |||
1333 | /* Mark that the expected block-ack response arrived */ | ||
1334 | agg->wait_for_ba = false; | ||
1335 | |||
1336 | /* Sanity check values reported by uCode */ | ||
1337 | if (ba_resp->txed_2_done > ba_resp->txed) { | ||
1338 | IWL_DEBUG_TX_REPLY(priv, | ||
1339 | "bogus sent(%d) and ack(%d) count\n", | ||
1340 | ba_resp->txed, ba_resp->txed_2_done); | ||
1341 | /* | ||
1342 | * set txed_2_done = txed, | ||
1343 | * so it won't impact rate scale | ||
1344 | */ | ||
1345 | ba_resp->txed = ba_resp->txed_2_done; | ||
1346 | } | ||
1347 | |||
1348 | priv->tid_data[sta_id][tid].next_reclaimed = ba_resp_scd_ssn; | ||
1349 | |||
1350 | iwlagn_check_ratid_empty(priv, sta_id, tid); | ||
1351 | freed = 0; | ||
1352 | |||
1353 | skb_queue_walk(&reclaimed_skbs, skb) { | ||
1354 | hdr = (struct ieee80211_hdr *)skb->data; | ||
1355 | |||
1356 | if (ieee80211_is_data_qos(hdr->frame_control)) | ||
1357 | freed++; | ||
1358 | else | ||
1359 | WARN_ON_ONCE(1); | ||
1360 | |||
1361 | info = IEEE80211_SKB_CB(skb); | ||
1362 | iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]); | ||
1363 | |||
1364 | if (freed == 1) { | ||
1365 | /* this is the first skb we deliver in this batch */ | ||
1366 | /* put the rate scaling data there */ | ||
1367 | info = IEEE80211_SKB_CB(skb); | ||
1368 | memset(&info->status, 0, sizeof(info->status)); | ||
1369 | info->flags |= IEEE80211_TX_STAT_ACK; | ||
1370 | info->flags |= IEEE80211_TX_STAT_AMPDU; | ||
1371 | info->status.ampdu_ack_len = ba_resp->txed_2_done; | ||
1372 | info->status.ampdu_len = ba_resp->txed; | ||
1373 | iwlagn_hwrate_to_tx_control(priv, agg->rate_n_flags, | ||
1374 | info); | ||
1375 | } | ||
1376 | } | ||
1377 | |||
1378 | spin_unlock(&priv->sta_lock); | ||
1379 | |||
1380 | while (!skb_queue_empty(&reclaimed_skbs)) { | ||
1381 | skb = __skb_dequeue(&reclaimed_skbs); | ||
1382 | ieee80211_tx_status(priv->hw, skb); | ||
1383 | } | ||
1384 | |||
1385 | return 0; | ||
1386 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/dvm/ucode.c b/drivers/net/wireless/iwlwifi/dvm/ucode.c new file mode 100644 index 000000000000..b3a314ba48c7 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/dvm/ucode.c | |||
@@ -0,0 +1,520 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * GPL LICENSE SUMMARY | ||
4 | * | ||
5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of version 2 of the GNU General Public License as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | ||
19 | * USA | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution | ||
22 | * in the file called LICENSE.GPL. | ||
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 | *****************************************************************************/ | ||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/init.h> | ||
32 | |||
33 | #include "iwl-io.h" | ||
34 | #include "iwl-agn-hw.h" | ||
35 | #include "iwl-trans.h" | ||
36 | #include "iwl-fh.h" | ||
37 | #include "iwl-op-mode.h" | ||
38 | |||
39 | #include "dev.h" | ||
40 | #include "agn.h" | ||
41 | #include "calib.h" | ||
42 | |||
43 | /****************************************************************************** | ||
44 | * | ||
45 | * uCode download functions | ||
46 | * | ||
47 | ******************************************************************************/ | ||
48 | |||
49 | static inline const struct fw_img * | ||
50 | iwl_get_ucode_image(struct iwl_priv *priv, enum iwl_ucode_type ucode_type) | ||
51 | { | ||
52 | if (ucode_type >= IWL_UCODE_TYPE_MAX) | ||
53 | return NULL; | ||
54 | |||
55 | return &priv->fw->img[ucode_type]; | ||
56 | } | ||
57 | |||
58 | /* | ||
59 | * Calibration | ||
60 | */ | ||
61 | static int iwl_set_Xtal_calib(struct iwl_priv *priv) | ||
62 | { | ||
63 | struct iwl_calib_xtal_freq_cmd cmd; | ||
64 | __le16 *xtal_calib = priv->eeprom_data->xtal_calib; | ||
65 | |||
66 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD); | ||
67 | cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]); | ||
68 | cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]); | ||
69 | return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); | ||
70 | } | ||
71 | |||
72 | static int iwl_set_temperature_offset_calib(struct iwl_priv *priv) | ||
73 | { | ||
74 | struct iwl_calib_temperature_offset_cmd cmd; | ||
75 | |||
76 | memset(&cmd, 0, sizeof(cmd)); | ||
77 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); | ||
78 | cmd.radio_sensor_offset = priv->eeprom_data->raw_temperature; | ||
79 | if (!(cmd.radio_sensor_offset)) | ||
80 | cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET; | ||
81 | |||
82 | IWL_DEBUG_CALIB(priv, "Radio sensor offset: %d\n", | ||
83 | le16_to_cpu(cmd.radio_sensor_offset)); | ||
84 | return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); | ||
85 | } | ||
86 | |||
87 | static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv) | ||
88 | { | ||
89 | struct iwl_calib_temperature_offset_v2_cmd cmd; | ||
90 | |||
91 | memset(&cmd, 0, sizeof(cmd)); | ||
92 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); | ||
93 | cmd.radio_sensor_offset_high = priv->eeprom_data->kelvin_temperature; | ||
94 | cmd.radio_sensor_offset_low = priv->eeprom_data->raw_temperature; | ||
95 | if (!cmd.radio_sensor_offset_low) { | ||
96 | IWL_DEBUG_CALIB(priv, "no info in EEPROM, use default\n"); | ||
97 | cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET; | ||
98 | cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET; | ||
99 | } | ||
100 | cmd.burntVoltageRef = priv->eeprom_data->calib_voltage; | ||
101 | |||
102 | IWL_DEBUG_CALIB(priv, "Radio sensor offset high: %d\n", | ||
103 | le16_to_cpu(cmd.radio_sensor_offset_high)); | ||
104 | IWL_DEBUG_CALIB(priv, "Radio sensor offset low: %d\n", | ||
105 | le16_to_cpu(cmd.radio_sensor_offset_low)); | ||
106 | IWL_DEBUG_CALIB(priv, "Voltage Ref: %d\n", | ||
107 | le16_to_cpu(cmd.burntVoltageRef)); | ||
108 | |||
109 | return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); | ||
110 | } | ||
111 | |||
112 | static int iwl_send_calib_cfg(struct iwl_priv *priv) | ||
113 | { | ||
114 | struct iwl_calib_cfg_cmd calib_cfg_cmd; | ||
115 | struct iwl_host_cmd cmd = { | ||
116 | .id = CALIBRATION_CFG_CMD, | ||
117 | .len = { sizeof(struct iwl_calib_cfg_cmd), }, | ||
118 | .data = { &calib_cfg_cmd, }, | ||
119 | }; | ||
120 | |||
121 | memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd)); | ||
122 | calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL; | ||
123 | calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL; | ||
124 | calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL; | ||
125 | calib_cfg_cmd.ucd_calib_cfg.flags = | ||
126 | IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK; | ||
127 | |||
128 | return iwl_dvm_send_cmd(priv, &cmd); | ||
129 | } | ||
130 | |||
131 | int iwl_init_alive_start(struct iwl_priv *priv) | ||
132 | { | ||
133 | int ret; | ||
134 | |||
135 | if (priv->cfg->bt_params && | ||
136 | priv->cfg->bt_params->advanced_bt_coexist) { | ||
137 | /* | ||
138 | * Tell uCode we are ready to perform calibration | ||
139 | * need to perform this before any calibration | ||
140 | * no need to close the envlope since we are going | ||
141 | * to load the runtime uCode later. | ||
142 | */ | ||
143 | ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, | ||
144 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); | ||
145 | if (ret) | ||
146 | return ret; | ||
147 | |||
148 | } | ||
149 | |||
150 | ret = iwl_send_calib_cfg(priv); | ||
151 | if (ret) | ||
152 | return ret; | ||
153 | |||
154 | /** | ||
155 | * temperature offset calibration is only needed for runtime ucode, | ||
156 | * so prepare the value now. | ||
157 | */ | ||
158 | if (priv->cfg->need_temp_offset_calib) { | ||
159 | if (priv->cfg->temp_offset_v2) | ||
160 | return iwl_set_temperature_offset_calib_v2(priv); | ||
161 | else | ||
162 | return iwl_set_temperature_offset_calib(priv); | ||
163 | } | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static int iwl_send_wimax_coex(struct iwl_priv *priv) | ||
169 | { | ||
170 | struct iwl_wimax_coex_cmd coex_cmd; | ||
171 | |||
172 | /* coexistence is disabled */ | ||
173 | memset(&coex_cmd, 0, sizeof(coex_cmd)); | ||
174 | |||
175 | return iwl_dvm_send_cmd_pdu(priv, | ||
176 | COEX_PRIORITY_TABLE_CMD, CMD_SYNC, | ||
177 | sizeof(coex_cmd), &coex_cmd); | ||
178 | } | ||
179 | |||
180 | static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = { | ||
181 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
182 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
183 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
184 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
185 | ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
186 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
187 | ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
188 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
189 | ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
190 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
191 | ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
192 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
193 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
194 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
195 | ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
196 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
197 | ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | | ||
198 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), | ||
199 | 0, 0, 0, 0, 0, 0, 0 | ||
200 | }; | ||
201 | |||
202 | void iwl_send_prio_tbl(struct iwl_priv *priv) | ||
203 | { | ||
204 | struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd; | ||
205 | |||
206 | memcpy(prio_tbl_cmd.prio_tbl, iwl_bt_prio_tbl, | ||
207 | sizeof(iwl_bt_prio_tbl)); | ||
208 | if (iwl_dvm_send_cmd_pdu(priv, | ||
209 | REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC, | ||
210 | sizeof(prio_tbl_cmd), &prio_tbl_cmd)) | ||
211 | IWL_ERR(priv, "failed to send BT prio tbl command\n"); | ||
212 | } | ||
213 | |||
214 | int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type) | ||
215 | { | ||
216 | struct iwl_bt_coex_prot_env_cmd env_cmd; | ||
217 | int ret; | ||
218 | |||
219 | env_cmd.action = action; | ||
220 | env_cmd.type = type; | ||
221 | ret = iwl_dvm_send_cmd_pdu(priv, | ||
222 | REPLY_BT_COEX_PROT_ENV, CMD_SYNC, | ||
223 | sizeof(env_cmd), &env_cmd); | ||
224 | if (ret) | ||
225 | IWL_ERR(priv, "failed to send BT env command\n"); | ||
226 | return ret; | ||
227 | } | ||
228 | |||
229 | |||
230 | static int iwl_alive_notify(struct iwl_priv *priv) | ||
231 | { | ||
232 | int ret; | ||
233 | |||
234 | iwl_trans_fw_alive(priv->trans); | ||
235 | |||
236 | priv->passive_no_rx = false; | ||
237 | priv->transport_queue_stop = 0; | ||
238 | |||
239 | ret = iwl_send_wimax_coex(priv); | ||
240 | if (ret) | ||
241 | return ret; | ||
242 | |||
243 | if (!priv->cfg->no_xtal_calib) { | ||
244 | ret = iwl_set_Xtal_calib(priv); | ||
245 | if (ret) | ||
246 | return ret; | ||
247 | } | ||
248 | |||
249 | return iwl_send_calib_results(priv); | ||
250 | } | ||
251 | |||
252 | |||
253 | /** | ||
254 | * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host, | ||
255 | * using sample data 100 bytes apart. If these sample points are good, | ||
256 | * it's a pretty good bet that everything between them is good, too. | ||
257 | */ | ||
258 | static int iwl_verify_sec_sparse(struct iwl_priv *priv, | ||
259 | const struct fw_desc *fw_desc) | ||
260 | { | ||
261 | __le32 *image = (__le32 *)fw_desc->v_addr; | ||
262 | u32 len = fw_desc->len; | ||
263 | u32 val; | ||
264 | u32 i; | ||
265 | |||
266 | IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len); | ||
267 | |||
268 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { | ||
269 | /* read data comes through single port, auto-incr addr */ | ||
270 | /* NOTE: Use the debugless read so we don't flood kernel log | ||
271 | * if IWL_DL_IO is set */ | ||
272 | iwl_write_direct32(priv->trans, HBUS_TARG_MEM_RADDR, | ||
273 | i + fw_desc->offset); | ||
274 | val = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); | ||
275 | if (val != le32_to_cpu(*image)) | ||
276 | return -EIO; | ||
277 | } | ||
278 | |||
279 | return 0; | ||
280 | } | ||
281 | |||
282 | static void iwl_print_mismatch_sec(struct iwl_priv *priv, | ||
283 | const struct fw_desc *fw_desc) | ||
284 | { | ||
285 | __le32 *image = (__le32 *)fw_desc->v_addr; | ||
286 | u32 len = fw_desc->len; | ||
287 | u32 val; | ||
288 | u32 offs; | ||
289 | int errors = 0; | ||
290 | |||
291 | IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len); | ||
292 | |||
293 | iwl_write_direct32(priv->trans, HBUS_TARG_MEM_RADDR, | ||
294 | fw_desc->offset); | ||
295 | |||
296 | for (offs = 0; | ||
297 | offs < len && errors < 20; | ||
298 | offs += sizeof(u32), image++) { | ||
299 | /* read data comes through single port, auto-incr addr */ | ||
300 | val = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); | ||
301 | if (val != le32_to_cpu(*image)) { | ||
302 | IWL_ERR(priv, "uCode INST section at " | ||
303 | "offset 0x%x, is 0x%x, s/b 0x%x\n", | ||
304 | offs, val, le32_to_cpu(*image)); | ||
305 | errors++; | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * iwl_verify_ucode - determine which instruction image is in SRAM, | ||
312 | * and verify its contents | ||
313 | */ | ||
314 | static int iwl_verify_ucode(struct iwl_priv *priv, | ||
315 | enum iwl_ucode_type ucode_type) | ||
316 | { | ||
317 | const struct fw_img *img = iwl_get_ucode_image(priv, ucode_type); | ||
318 | |||
319 | if (!img) { | ||
320 | IWL_ERR(priv, "Invalid ucode requested (%d)\n", ucode_type); | ||
321 | return -EINVAL; | ||
322 | } | ||
323 | |||
324 | if (!iwl_verify_sec_sparse(priv, &img->sec[IWL_UCODE_SECTION_INST])) { | ||
325 | IWL_DEBUG_FW(priv, "uCode is good in inst SRAM\n"); | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | IWL_ERR(priv, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n"); | ||
330 | |||
331 | iwl_print_mismatch_sec(priv, &img->sec[IWL_UCODE_SECTION_INST]); | ||
332 | return -EIO; | ||
333 | } | ||
334 | |||
335 | struct iwl_alive_data { | ||
336 | bool valid; | ||
337 | u8 subtype; | ||
338 | }; | ||
339 | |||
340 | static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait, | ||
341 | struct iwl_rx_packet *pkt, void *data) | ||
342 | { | ||
343 | struct iwl_priv *priv = | ||
344 | container_of(notif_wait, struct iwl_priv, notif_wait); | ||
345 | struct iwl_alive_data *alive_data = data; | ||
346 | struct iwl_alive_resp *palive; | ||
347 | |||
348 | palive = (void *)pkt->data; | ||
349 | |||
350 | IWL_DEBUG_FW(priv, "Alive ucode status 0x%08X revision " | ||
351 | "0x%01X 0x%01X\n", | ||
352 | palive->is_valid, palive->ver_type, | ||
353 | palive->ver_subtype); | ||
354 | |||
355 | priv->device_pointers.error_event_table = | ||
356 | le32_to_cpu(palive->error_event_table_ptr); | ||
357 | priv->device_pointers.log_event_table = | ||
358 | le32_to_cpu(palive->log_event_table_ptr); | ||
359 | |||
360 | alive_data->subtype = palive->ver_subtype; | ||
361 | alive_data->valid = palive->is_valid == UCODE_VALID_OK; | ||
362 | |||
363 | return true; | ||
364 | } | ||
365 | |||
366 | #define UCODE_ALIVE_TIMEOUT HZ | ||
367 | #define UCODE_CALIB_TIMEOUT (2*HZ) | ||
368 | |||
369 | int iwl_load_ucode_wait_alive(struct iwl_priv *priv, | ||
370 | enum iwl_ucode_type ucode_type) | ||
371 | { | ||
372 | struct iwl_notification_wait alive_wait; | ||
373 | struct iwl_alive_data alive_data; | ||
374 | const struct fw_img *fw; | ||
375 | int ret; | ||
376 | enum iwl_ucode_type old_type; | ||
377 | static const u8 alive_cmd[] = { REPLY_ALIVE }; | ||
378 | |||
379 | old_type = priv->cur_ucode; | ||
380 | priv->cur_ucode = ucode_type; | ||
381 | fw = iwl_get_ucode_image(priv, ucode_type); | ||
382 | |||
383 | priv->ucode_loaded = false; | ||
384 | |||
385 | if (!fw) | ||
386 | return -EINVAL; | ||
387 | |||
388 | iwl_init_notification_wait(&priv->notif_wait, &alive_wait, | ||
389 | alive_cmd, ARRAY_SIZE(alive_cmd), | ||
390 | iwl_alive_fn, &alive_data); | ||
391 | |||
392 | ret = iwl_trans_start_fw(priv->trans, fw); | ||
393 | if (ret) { | ||
394 | priv->cur_ucode = old_type; | ||
395 | iwl_remove_notification(&priv->notif_wait, &alive_wait); | ||
396 | return ret; | ||
397 | } | ||
398 | |||
399 | /* | ||
400 | * Some things may run in the background now, but we | ||
401 | * just wait for the ALIVE notification here. | ||
402 | */ | ||
403 | ret = iwl_wait_notification(&priv->notif_wait, &alive_wait, | ||
404 | UCODE_ALIVE_TIMEOUT); | ||
405 | if (ret) { | ||
406 | priv->cur_ucode = old_type; | ||
407 | return ret; | ||
408 | } | ||
409 | |||
410 | if (!alive_data.valid) { | ||
411 | IWL_ERR(priv, "Loaded ucode is not valid!\n"); | ||
412 | priv->cur_ucode = old_type; | ||
413 | return -EIO; | ||
414 | } | ||
415 | |||
416 | /* | ||
417 | * This step takes a long time (60-80ms!!) and | ||
418 | * WoWLAN image should be loaded quickly, so | ||
419 | * skip it for WoWLAN. | ||
420 | */ | ||
421 | if (ucode_type != IWL_UCODE_WOWLAN) { | ||
422 | ret = iwl_verify_ucode(priv, ucode_type); | ||
423 | if (ret) { | ||
424 | priv->cur_ucode = old_type; | ||
425 | return ret; | ||
426 | } | ||
427 | |||
428 | /* delay a bit to give rfkill time to run */ | ||
429 | msleep(5); | ||
430 | } | ||
431 | |||
432 | ret = iwl_alive_notify(priv); | ||
433 | if (ret) { | ||
434 | IWL_WARN(priv, | ||
435 | "Could not complete ALIVE transition: %d\n", ret); | ||
436 | priv->cur_ucode = old_type; | ||
437 | return ret; | ||
438 | } | ||
439 | |||
440 | priv->ucode_loaded = true; | ||
441 | |||
442 | return 0; | ||
443 | } | ||
444 | |||
445 | static bool iwlagn_wait_calib(struct iwl_notif_wait_data *notif_wait, | ||
446 | struct iwl_rx_packet *pkt, void *data) | ||
447 | { | ||
448 | struct iwl_priv *priv = data; | ||
449 | struct iwl_calib_hdr *hdr; | ||
450 | int len; | ||
451 | |||
452 | if (pkt->hdr.cmd != CALIBRATION_RES_NOTIFICATION) { | ||
453 | WARN_ON(pkt->hdr.cmd != CALIBRATION_COMPLETE_NOTIFICATION); | ||
454 | return true; | ||
455 | } | ||
456 | |||
457 | hdr = (struct iwl_calib_hdr *)pkt->data; | ||
458 | len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | ||
459 | |||
460 | /* reduce the size by the length field itself */ | ||
461 | len -= sizeof(__le32); | ||
462 | |||
463 | if (iwl_calib_set(priv, hdr, len)) | ||
464 | IWL_ERR(priv, "Failed to record calibration data %d\n", | ||
465 | hdr->op_code); | ||
466 | |||
467 | return false; | ||
468 | } | ||
469 | |||
470 | int iwl_run_init_ucode(struct iwl_priv *priv) | ||
471 | { | ||
472 | struct iwl_notification_wait calib_wait; | ||
473 | static const u8 calib_complete[] = { | ||
474 | CALIBRATION_RES_NOTIFICATION, | ||
475 | CALIBRATION_COMPLETE_NOTIFICATION | ||
476 | }; | ||
477 | int ret; | ||
478 | |||
479 | lockdep_assert_held(&priv->mutex); | ||
480 | |||
481 | /* No init ucode required? Curious, but maybe ok */ | ||
482 | if (!priv->fw->img[IWL_UCODE_INIT].sec[0].len) | ||
483 | return 0; | ||
484 | |||
485 | if (priv->init_ucode_run) | ||
486 | return 0; | ||
487 | |||
488 | iwl_init_notification_wait(&priv->notif_wait, &calib_wait, | ||
489 | calib_complete, ARRAY_SIZE(calib_complete), | ||
490 | iwlagn_wait_calib, priv); | ||
491 | |||
492 | /* Will also start the device */ | ||
493 | ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT); | ||
494 | if (ret) | ||
495 | goto error; | ||
496 | |||
497 | ret = iwl_init_alive_start(priv); | ||
498 | if (ret) | ||
499 | goto error; | ||
500 | |||
501 | /* | ||
502 | * Some things may run in the background now, but we | ||
503 | * just wait for the calibration complete notification. | ||
504 | */ | ||
505 | ret = iwl_wait_notification(&priv->notif_wait, &calib_wait, | ||
506 | UCODE_CALIB_TIMEOUT); | ||
507 | if (!ret) | ||
508 | priv->init_ucode_run = true; | ||
509 | |||
510 | goto out; | ||
511 | |||
512 | error: | ||
513 | iwl_remove_notification(&priv->notif_wait, &calib_wait); | ||
514 | out: | ||
515 | /* Whatever happened, stop the device */ | ||
516 | iwl_trans_stop_device(priv->trans); | ||
517 | priv->ucode_loaded = false; | ||
518 | |||
519 | return ret; | ||
520 | } | ||