]>
Commit | Line | Data |
---|---|---|
4bc85c13 WYG |
1 | /****************************************************************************** |
2 | * | |
be663ab6 | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. |
4bc85c13 WYG |
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/kernel.h> | |
28 | #include <linux/module.h> | |
29 | #include <linux/init.h> | |
30 | #include <linux/pci.h> | |
31 | #include <linux/dma-mapping.h> | |
32 | #include <linux/delay.h> | |
33 | #include <linux/sched.h> | |
34 | #include <linux/skbuff.h> | |
35 | #include <linux/netdevice.h> | |
4bc85c13 WYG |
36 | #include <net/mac80211.h> |
37 | #include <linux/etherdevice.h> | |
38 | #include <asm/unaligned.h> | |
39 | ||
40 | #include "iwl-eeprom.h" | |
41 | #include "iwl-dev.h" | |
42 | #include "iwl-core.h" | |
43 | #include "iwl-io.h" | |
44 | #include "iwl-helpers.h" | |
be663ab6 | 45 | #include "iwl-4965-calib.h" |
4bc85c13 | 46 | #include "iwl-sta.h" |
be663ab6 WYG |
47 | #include "iwl-4965.h" |
48 | #include "iwl-4965-debugfs.h" | |
4bc85c13 | 49 | |
56e7a8cc SG |
50 | /****************************************************************************** |
51 | * | |
52 | * EEPROM related functions | |
53 | * | |
54 | ******************************************************************************/ | |
55 | ||
56 | /* | |
57 | * The device's EEPROM semaphore prevents conflicts between driver and uCode | |
58 | * when accessing the EEPROM; each access is a series of pulses to/from the | |
59 | * EEPROM chip, not a single event, so even reads could conflict if they | |
60 | * weren't arbitrated by the semaphore. | |
61 | */ | |
62 | int il4965_eeprom_acquire_semaphore(struct il_priv *il) | |
63 | { | |
64 | u16 count; | |
65 | int ret; | |
66 | ||
67 | for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) { | |
68 | /* Request semaphore */ | |
69 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, | |
70 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); | |
71 | ||
72 | /* See if we got it */ | |
73 | ret = _il_poll_bit(il, CSR_HW_IF_CONFIG_REG, | |
74 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, | |
75 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, | |
76 | EEPROM_SEM_TIMEOUT); | |
77 | if (ret >= 0) | |
78 | return ret; | |
79 | } | |
80 | ||
81 | return ret; | |
82 | } | |
83 | ||
84 | void il4965_eeprom_release_semaphore(struct il_priv *il) | |
85 | { | |
86 | il_clear_bit(il, CSR_HW_IF_CONFIG_REG, | |
87 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); | |
88 | ||
89 | } | |
90 | ||
91 | int il4965_eeprom_check_version(struct il_priv *il) | |
92 | { | |
93 | u16 eeprom_ver; | |
94 | u16 calib_ver; | |
95 | ||
96 | eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION); | |
97 | calib_ver = il_eeprom_query16(il, | |
98 | EEPROM_4965_CALIB_VERSION_OFFSET); | |
99 | ||
100 | if (eeprom_ver < il->cfg->eeprom_ver || | |
101 | calib_ver < il->cfg->eeprom_calib_ver) | |
102 | goto err; | |
103 | ||
104 | IL_INFO("device EEPROM VER=0x%x, CALIB=0x%x\n", | |
105 | eeprom_ver, calib_ver); | |
106 | ||
107 | return 0; | |
108 | err: | |
109 | IL_ERR("Unsupported (too old) EEPROM VER=0x%x < 0x%x " | |
110 | "CALIB=0x%x < 0x%x\n", | |
111 | eeprom_ver, il->cfg->eeprom_ver, | |
112 | calib_ver, il->cfg->eeprom_calib_ver); | |
113 | return -EINVAL; | |
114 | ||
115 | } | |
116 | ||
117 | void il4965_eeprom_get_mac(const struct il_priv *il, u8 *mac) | |
118 | { | |
119 | const u8 *addr = il_eeprom_query_addr(il, | |
120 | EEPROM_MAC_ADDRESS); | |
121 | memcpy(mac, addr, ETH_ALEN); | |
122 | } | |
123 | ||
fc19cbde SG |
124 | /* Send led command */ |
125 | static int | |
126 | il4965_send_led_cmd(struct il_priv *il, struct il_led_cmd *led_cmd) | |
127 | { | |
128 | struct il_host_cmd cmd = { | |
129 | .id = REPLY_LEDS_CMD, | |
130 | .len = sizeof(struct il_led_cmd), | |
131 | .data = led_cmd, | |
132 | .flags = CMD_ASYNC, | |
133 | .callback = NULL, | |
134 | }; | |
135 | u32 reg; | |
136 | ||
137 | reg = _il_rd(il, CSR_LED_REG); | |
138 | if (reg != (reg & CSR_LED_BSM_CTRL_MSK)) | |
139 | _il_wr(il, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK); | |
140 | ||
141 | return il_send_cmd(il, &cmd); | |
142 | } | |
143 | ||
144 | /* Set led register off */ | |
145 | void il4965_led_enable(struct il_priv *il) | |
146 | { | |
147 | _il_wr(il, CSR_LED_REG, CSR_LED_REG_TRUN_ON); | |
148 | } | |
149 | ||
150 | const struct il_led_ops il4965_led_ops = { | |
151 | .cmd = il4965_send_led_cmd, | |
152 | }; | |
153 | ||
46bc8d4b SG |
154 | static int il4965_send_tx_power(struct il_priv *il); |
155 | static int il4965_hw_get_temperature(struct il_priv *il); | |
4bc85c13 WYG |
156 | |
157 | /* Highest firmware API version supported */ | |
d3175167 | 158 | #define IL4965_UCODE_API_MAX 2 |
4bc85c13 WYG |
159 | |
160 | /* Lowest firmware API version supported */ | |
d3175167 | 161 | #define IL4965_UCODE_API_MIN 2 |
4bc85c13 | 162 | |
d3175167 SG |
163 | #define IL4965_FW_PRE "iwlwifi-4965-" |
164 | #define _IL4965_MODULE_FIRMWARE(api) IL4965_FW_PRE #api ".ucode" | |
165 | #define IL4965_MODULE_FIRMWARE(api) _IL4965_MODULE_FIRMWARE(api) | |
4bc85c13 WYG |
166 | |
167 | /* check contents of special bootstrap uCode SRAM */ | |
46bc8d4b | 168 | static int il4965_verify_bsm(struct il_priv *il) |
4bc85c13 | 169 | { |
46bc8d4b SG |
170 | __le32 *image = il->ucode_boot.v_addr; |
171 | u32 len = il->ucode_boot.len; | |
4bc85c13 WYG |
172 | u32 reg; |
173 | u32 val; | |
174 | ||
58de00a4 | 175 | D_INFO("Begin verify bsm\n"); |
4bc85c13 WYG |
176 | |
177 | /* verify BSM SRAM contents */ | |
db54eb57 | 178 | val = il_rd_prph(il, BSM_WR_DWCOUNT_REG); |
4bc85c13 WYG |
179 | for (reg = BSM_SRAM_LOWER_BOUND; |
180 | reg < BSM_SRAM_LOWER_BOUND + len; | |
181 | reg += sizeof(u32), image++) { | |
db54eb57 | 182 | val = il_rd_prph(il, reg); |
4bc85c13 | 183 | if (val != le32_to_cpu(*image)) { |
9406f797 | 184 | IL_ERR("BSM uCode verification failed at " |
4bc85c13 WYG |
185 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
186 | BSM_SRAM_LOWER_BOUND, | |
187 | reg - BSM_SRAM_LOWER_BOUND, len, | |
188 | val, le32_to_cpu(*image)); | |
189 | return -EIO; | |
190 | } | |
191 | } | |
192 | ||
58de00a4 | 193 | D_INFO("BSM bootstrap uCode image OK\n"); |
4bc85c13 WYG |
194 | |
195 | return 0; | |
196 | } | |
197 | ||
198 | /** | |
e2ebc833 | 199 | * il4965_load_bsm - Load bootstrap instructions |
4bc85c13 WYG |
200 | * |
201 | * BSM operation: | |
202 | * | |
203 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program | |
204 | * in special SRAM that does not power down during RFKILL. When powering back | |
205 | * up after power-saving sleeps (or during initial uCode load), the BSM loads | |
206 | * the bootstrap program into the on-board processor, and starts it. | |
207 | * | |
208 | * The bootstrap program loads (via DMA) instructions and data for a new | |
209 | * program from host DRAM locations indicated by the host driver in the | |
210 | * BSM_DRAM_* registers. Once the new program is loaded, it starts | |
211 | * automatically. | |
212 | * | |
213 | * When initializing the NIC, the host driver points the BSM to the | |
214 | * "initialize" uCode image. This uCode sets up some internal data, then | |
215 | * notifies host via "initialize alive" that it is complete. | |
216 | * | |
217 | * The host then replaces the BSM_DRAM_* pointer values to point to the | |
218 | * normal runtime uCode instructions and a backup uCode data cache buffer | |
219 | * (filled initially with starting data values for the on-board processor), | |
220 | * then triggers the "initialize" uCode to load and launch the runtime uCode, | |
221 | * which begins normal operation. | |
222 | * | |
223 | * When doing a power-save shutdown, runtime uCode saves data SRAM into | |
224 | * the backup data cache in DRAM before SRAM is powered down. | |
225 | * | |
226 | * When powering back up, the BSM loads the bootstrap program. This reloads | |
227 | * the runtime uCode instructions and the backup data cache into SRAM, | |
228 | * and re-launches the runtime uCode from where it left off. | |
229 | */ | |
46bc8d4b | 230 | static int il4965_load_bsm(struct il_priv *il) |
4bc85c13 | 231 | { |
46bc8d4b SG |
232 | __le32 *image = il->ucode_boot.v_addr; |
233 | u32 len = il->ucode_boot.len; | |
4bc85c13 WYG |
234 | dma_addr_t pinst; |
235 | dma_addr_t pdata; | |
236 | u32 inst_len; | |
237 | u32 data_len; | |
238 | int i; | |
239 | u32 done; | |
240 | u32 reg_offset; | |
241 | int ret; | |
242 | ||
58de00a4 | 243 | D_INFO("Begin load bsm\n"); |
4bc85c13 | 244 | |
46bc8d4b | 245 | il->ucode_type = UCODE_RT; |
4bc85c13 WYG |
246 | |
247 | /* make sure bootstrap program is no larger than BSM's SRAM size */ | |
d3175167 | 248 | if (len > IL49_MAX_BSM_SIZE) |
4bc85c13 WYG |
249 | return -EINVAL; |
250 | ||
251 | /* Tell bootstrap uCode where to find the "Initialize" uCode | |
252 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. | |
e2ebc833 | 253 | * NOTE: il_init_alive_start() will replace these values, |
4bc85c13 WYG |
254 | * after the "initialize" uCode has run, to point to |
255 | * runtime/protocol instructions and backup data cache. | |
256 | */ | |
46bc8d4b SG |
257 | pinst = il->ucode_init.p_addr >> 4; |
258 | pdata = il->ucode_init_data.p_addr >> 4; | |
259 | inst_len = il->ucode_init.len; | |
260 | data_len = il->ucode_init_data.len; | |
4bc85c13 | 261 | |
db54eb57 SG |
262 | il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst); |
263 | il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata); | |
264 | il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); | |
265 | il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); | |
4bc85c13 WYG |
266 | |
267 | /* Fill BSM memory with bootstrap instructions */ | |
268 | for (reg_offset = BSM_SRAM_LOWER_BOUND; | |
269 | reg_offset < BSM_SRAM_LOWER_BOUND + len; | |
270 | reg_offset += sizeof(u32), image++) | |
db54eb57 | 271 | _il_wr_prph(il, reg_offset, le32_to_cpu(*image)); |
4bc85c13 | 272 | |
46bc8d4b | 273 | ret = il4965_verify_bsm(il); |
4bc85c13 WYG |
274 | if (ret) |
275 | return ret; | |
276 | ||
277 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ | |
db54eb57 SG |
278 | il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0); |
279 | il_wr_prph(il, | |
d3175167 | 280 | BSM_WR_MEM_DST_REG, IL49_RTC_INST_LOWER_BOUND); |
db54eb57 | 281 | il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
4bc85c13 WYG |
282 | |
283 | /* Load bootstrap code into instruction SRAM now, | |
284 | * to prepare to load "initialize" uCode */ | |
db54eb57 | 285 | il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START); |
4bc85c13 WYG |
286 | |
287 | /* Wait for load of bootstrap uCode to finish */ | |
288 | for (i = 0; i < 100; i++) { | |
db54eb57 | 289 | done = il_rd_prph(il, BSM_WR_CTRL_REG); |
4bc85c13 WYG |
290 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
291 | break; | |
292 | udelay(10); | |
293 | } | |
294 | if (i < 100) | |
58de00a4 | 295 | D_INFO("BSM write complete, poll %d iterations\n", i); |
4bc85c13 | 296 | else { |
9406f797 | 297 | IL_ERR("BSM write did not complete!\n"); |
4bc85c13 WYG |
298 | return -EIO; |
299 | } | |
300 | ||
301 | /* Enable future boot loads whenever power management unit triggers it | |
302 | * (e.g. when powering back up after power-save shutdown) */ | |
db54eb57 | 303 | il_wr_prph(il, |
be663ab6 | 304 | BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN); |
4bc85c13 WYG |
305 | |
306 | ||
307 | return 0; | |
308 | } | |
309 | ||
310 | /** | |
e2ebc833 | 311 | * il4965_set_ucode_ptrs - Set uCode address location |
4bc85c13 WYG |
312 | * |
313 | * Tell initialization uCode where to find runtime uCode. | |
314 | * | |
315 | * BSM registers initially contain pointers to initialization uCode. | |
316 | * We need to replace them to load runtime uCode inst and data, | |
317 | * and to save runtime data when powering down. | |
318 | */ | |
46bc8d4b | 319 | static int il4965_set_ucode_ptrs(struct il_priv *il) |
4bc85c13 WYG |
320 | { |
321 | dma_addr_t pinst; | |
322 | dma_addr_t pdata; | |
323 | int ret = 0; | |
324 | ||
325 | /* bits 35:4 for 4965 */ | |
46bc8d4b SG |
326 | pinst = il->ucode_code.p_addr >> 4; |
327 | pdata = il->ucode_data_backup.p_addr >> 4; | |
4bc85c13 WYG |
328 | |
329 | /* Tell bootstrap uCode where to find image to load */ | |
db54eb57 SG |
330 | il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst); |
331 | il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata); | |
332 | il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, | |
46bc8d4b | 333 | il->ucode_data.len); |
4bc85c13 WYG |
334 | |
335 | /* Inst byte count must be last to set up, bit 31 signals uCode | |
336 | * that all new ptr/size info is in place */ | |
db54eb57 | 337 | il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, |
46bc8d4b | 338 | il->ucode_code.len | BSM_DRAM_INST_LOAD); |
58de00a4 | 339 | D_INFO("Runtime uCode pointers are set.\n"); |
4bc85c13 WYG |
340 | |
341 | return ret; | |
342 | } | |
343 | ||
344 | /** | |
e2ebc833 | 345 | * il4965_init_alive_start - Called after REPLY_ALIVE notification received |
4bc85c13 WYG |
346 | * |
347 | * Called after REPLY_ALIVE notification received from "initialize" uCode. | |
348 | * | |
349 | * The 4965 "initialize" ALIVE reply contains calibration data for: | |
46bc8d4b | 350 | * Voltage, temperature, and MIMO tx gain correction, now stored in il |
4bc85c13 WYG |
351 | * (3945 does not contain this data). |
352 | * | |
353 | * Tell "initialize" uCode to go ahead and load the runtime uCode. | |
354 | */ | |
46bc8d4b | 355 | static void il4965_init_alive_start(struct il_priv *il) |
4bc85c13 WYG |
356 | { |
357 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. | |
358 | * This is a paranoid check, because we would not have gotten the | |
359 | * "initialize" alive if code weren't properly loaded. */ | |
46bc8d4b | 360 | if (il4965_verify_ucode(il)) { |
4bc85c13 WYG |
361 | /* Runtime instruction load was bad; |
362 | * take it all the way back down so we can try again */ | |
58de00a4 | 363 | D_INFO("Bad \"initialize\" uCode load.\n"); |
4bc85c13 WYG |
364 | goto restart; |
365 | } | |
366 | ||
367 | /* Calculate temperature */ | |
46bc8d4b | 368 | il->temperature = il4965_hw_get_temperature(il); |
4bc85c13 WYG |
369 | |
370 | /* Send pointers to protocol/runtime uCode image ... init code will | |
371 | * load and launch runtime uCode, which will send us another "Alive" | |
372 | * notification. */ | |
58de00a4 | 373 | D_INFO("Initialization Alive received.\n"); |
46bc8d4b | 374 | if (il4965_set_ucode_ptrs(il)) { |
4bc85c13 WYG |
375 | /* Runtime instruction load won't happen; |
376 | * take it all the way back down so we can try again */ | |
58de00a4 | 377 | D_INFO("Couldn't set up uCode pointers.\n"); |
4bc85c13 WYG |
378 | goto restart; |
379 | } | |
380 | return; | |
381 | ||
382 | restart: | |
46bc8d4b | 383 | queue_work(il->workqueue, &il->restart); |
4bc85c13 WYG |
384 | } |
385 | ||
be663ab6 | 386 | static bool iw4965_is_ht40_channel(__le32 rxon_flags) |
4bc85c13 WYG |
387 | { |
388 | int chan_mod = le32_to_cpu(rxon_flags & RXON_FLG_CHANNEL_MODE_MSK) | |
389 | >> RXON_FLG_CHANNEL_MODE_POS; | |
232913b5 SG |
390 | return (chan_mod == CHANNEL_MODE_PURE_40 || |
391 | chan_mod == CHANNEL_MODE_MIXED); | |
4bc85c13 WYG |
392 | } |
393 | ||
46bc8d4b | 394 | static void il4965_nic_config(struct il_priv *il) |
4bc85c13 WYG |
395 | { |
396 | unsigned long flags; | |
397 | u16 radio_cfg; | |
398 | ||
46bc8d4b | 399 | spin_lock_irqsave(&il->lock, flags); |
4bc85c13 | 400 | |
46bc8d4b | 401 | radio_cfg = il_eeprom_query16(il, EEPROM_RADIO_CONFIG); |
4bc85c13 WYG |
402 | |
403 | /* write radio config values to register */ | |
404 | if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX) | |
46bc8d4b | 405 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, |
4bc85c13 WYG |
406 | EEPROM_RF_CFG_TYPE_MSK(radio_cfg) | |
407 | EEPROM_RF_CFG_STEP_MSK(radio_cfg) | | |
408 | EEPROM_RF_CFG_DASH_MSK(radio_cfg)); | |
409 | ||
410 | /* set CSR_HW_CONFIG_REG for uCode use */ | |
46bc8d4b | 411 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, |
4bc85c13 WYG |
412 | CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | |
413 | CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); | |
414 | ||
46bc8d4b SG |
415 | il->calib_info = (struct il_eeprom_calib_info *) |
416 | il_eeprom_query_addr(il, | |
be663ab6 | 417 | EEPROM_4965_CALIB_TXPOWER_OFFSET); |
4bc85c13 | 418 | |
46bc8d4b | 419 | spin_unlock_irqrestore(&il->lock, flags); |
4bc85c13 WYG |
420 | } |
421 | ||
422 | /* Reset differential Rx gains in NIC to prepare for chain noise calibration. | |
423 | * Called after every association, but this runs only once! | |
424 | * ... once chain noise is calibrated the first time, it's good forever. */ | |
46bc8d4b | 425 | static void il4965_chain_noise_reset(struct il_priv *il) |
4bc85c13 | 426 | { |
46bc8d4b | 427 | struct il_chain_noise_data *data = &(il->chain_noise_data); |
4bc85c13 | 428 | |
232913b5 | 429 | if (data->state == IL_CHAIN_NOISE_ALIVE && |
46bc8d4b | 430 | il_is_any_associated(il)) { |
e2ebc833 | 431 | struct il_calib_diff_gain_cmd cmd; |
4bc85c13 WYG |
432 | |
433 | /* clear data for chain noise calibration algorithm */ | |
434 | data->chain_noise_a = 0; | |
435 | data->chain_noise_b = 0; | |
436 | data->chain_noise_c = 0; | |
437 | data->chain_signal_a = 0; | |
438 | data->chain_signal_b = 0; | |
439 | data->chain_signal_c = 0; | |
440 | data->beacon_count = 0; | |
441 | ||
442 | memset(&cmd, 0, sizeof(cmd)); | |
e2ebc833 | 443 | cmd.hdr.op_code = IL_PHY_CALIBRATE_DIFF_GAIN_CMD; |
4bc85c13 WYG |
444 | cmd.diff_gain_a = 0; |
445 | cmd.diff_gain_b = 0; | |
446 | cmd.diff_gain_c = 0; | |
46bc8d4b | 447 | if (il_send_cmd_pdu(il, REPLY_PHY_CALIBRATION_CMD, |
4bc85c13 | 448 | sizeof(cmd), &cmd)) |
9406f797 | 449 | IL_ERR( |
4bc85c13 | 450 | "Could not send REPLY_PHY_CALIBRATION_CMD\n"); |
e2ebc833 | 451 | data->state = IL_CHAIN_NOISE_ACCUMULATE; |
58de00a4 | 452 | D_CALIB("Run chain_noise_calibrate\n"); |
4bc85c13 WYG |
453 | } |
454 | } | |
455 | ||
e2ebc833 | 456 | static struct il_sensitivity_ranges il4965_sensitivity = { |
4bc85c13 WYG |
457 | .min_nrg_cck = 97, |
458 | .max_nrg_cck = 0, /* not used, set to 0 */ | |
459 | ||
460 | .auto_corr_min_ofdm = 85, | |
461 | .auto_corr_min_ofdm_mrc = 170, | |
462 | .auto_corr_min_ofdm_x1 = 105, | |
463 | .auto_corr_min_ofdm_mrc_x1 = 220, | |
464 | ||
465 | .auto_corr_max_ofdm = 120, | |
466 | .auto_corr_max_ofdm_mrc = 210, | |
467 | .auto_corr_max_ofdm_x1 = 140, | |
468 | .auto_corr_max_ofdm_mrc_x1 = 270, | |
469 | ||
470 | .auto_corr_min_cck = 125, | |
471 | .auto_corr_max_cck = 200, | |
472 | .auto_corr_min_cck_mrc = 200, | |
473 | .auto_corr_max_cck_mrc = 400, | |
474 | ||
475 | .nrg_th_cck = 100, | |
476 | .nrg_th_ofdm = 100, | |
477 | ||
478 | .barker_corr_th_min = 190, | |
479 | .barker_corr_th_min_mrc = 390, | |
480 | .nrg_th_cca = 62, | |
481 | }; | |
482 | ||
46bc8d4b | 483 | static void il4965_set_ct_threshold(struct il_priv *il) |
4bc85c13 WYG |
484 | { |
485 | /* want Kelvin */ | |
46bc8d4b | 486 | il->hw_params.ct_kill_threshold = |
4bc85c13 WYG |
487 | CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY); |
488 | } | |
489 | ||
490 | /** | |
e2ebc833 | 491 | * il4965_hw_set_hw_params |
4bc85c13 WYG |
492 | * |
493 | * Called when initializing driver | |
494 | */ | |
46bc8d4b | 495 | static int il4965_hw_set_hw_params(struct il_priv *il) |
4bc85c13 | 496 | { |
46bc8d4b | 497 | if (il->cfg->mod_params->num_of_queues >= IL_MIN_NUM_QUEUES && |
d3175167 | 498 | il->cfg->mod_params->num_of_queues <= IL49_NUM_QUEUES) |
46bc8d4b SG |
499 | il->cfg->base_params->num_of_queues = |
500 | il->cfg->mod_params->num_of_queues; | |
501 | ||
502 | il->hw_params.max_txq_num = il->cfg->base_params->num_of_queues; | |
503 | il->hw_params.dma_chnl_num = FH49_TCSR_CHNL_NUM; | |
504 | il->hw_params.scd_bc_tbls_size = | |
505 | il->cfg->base_params->num_of_queues * | |
e2ebc833 | 506 | sizeof(struct il4965_scd_bc_tbl); |
46bc8d4b | 507 | il->hw_params.tfd_size = sizeof(struct il_tfd); |
d3175167 | 508 | il->hw_params.max_stations = IL4965_STATION_COUNT; |
7c2cde2e | 509 | il->ctx.bcast_sta_id = IL4965_BROADCAST_ID; |
d3175167 SG |
510 | il->hw_params.max_data_size = IL49_RTC_DATA_SIZE; |
511 | il->hw_params.max_inst_size = IL49_RTC_INST_SIZE; | |
46bc8d4b SG |
512 | il->hw_params.max_bsm_size = BSM_SRAM_SIZE; |
513 | il->hw_params.ht40_channel = BIT(IEEE80211_BAND_5GHZ); | |
4bc85c13 | 514 | |
46bc8d4b | 515 | il->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR; |
4bc85c13 | 516 | |
46bc8d4b SG |
517 | il->hw_params.tx_chains_num = il4965_num_of_ant(il->cfg->valid_tx_ant); |
518 | il->hw_params.rx_chains_num = il4965_num_of_ant(il->cfg->valid_rx_ant); | |
519 | il->hw_params.valid_tx_ant = il->cfg->valid_tx_ant; | |
520 | il->hw_params.valid_rx_ant = il->cfg->valid_rx_ant; | |
4bc85c13 | 521 | |
46bc8d4b | 522 | il4965_set_ct_threshold(il); |
4bc85c13 | 523 | |
46bc8d4b | 524 | il->hw_params.sens = &il4965_sensitivity; |
d3175167 | 525 | il->hw_params.beacon_time_tsf_bits = IL4965_EXT_BEACON_TIME_POS; |
4bc85c13 WYG |
526 | |
527 | return 0; | |
528 | } | |
529 | ||
e2ebc833 | 530 | static s32 il4965_math_div_round(s32 num, s32 denom, s32 *res) |
4bc85c13 WYG |
531 | { |
532 | s32 sign = 1; | |
533 | ||
534 | if (num < 0) { | |
535 | sign = -sign; | |
536 | num = -num; | |
537 | } | |
538 | if (denom < 0) { | |
539 | sign = -sign; | |
540 | denom = -denom; | |
541 | } | |
542 | *res = 1; | |
543 | *res = ((num * 2 + denom) / (denom * 2)) * sign; | |
544 | ||
545 | return 1; | |
546 | } | |
547 | ||
548 | /** | |
e2ebc833 | 549 | * il4965_get_voltage_compensation - Power supply voltage comp for txpower |
4bc85c13 WYG |
550 | * |
551 | * Determines power supply voltage compensation for txpower calculations. | |
0c2c8852 | 552 | * Returns number of 1/2-dB steps to subtract from gain table idx, |
4bc85c13 WYG |
553 | * to compensate for difference between power supply voltage during |
554 | * factory measurements, vs. current power supply voltage. | |
555 | * | |
556 | * Voltage indication is higher for lower voltage. | |
0c2c8852 | 557 | * Lower voltage requires more gain (lower gain table idx). |
4bc85c13 | 558 | */ |
e2ebc833 | 559 | static s32 il4965_get_voltage_compensation(s32 eeprom_voltage, |
4bc85c13 WYG |
560 | s32 current_voltage) |
561 | { | |
562 | s32 comp = 0; | |
563 | ||
232913b5 SG |
564 | if (TX_POWER_IL_ILLEGAL_VOLTAGE == eeprom_voltage || |
565 | TX_POWER_IL_ILLEGAL_VOLTAGE == current_voltage) | |
4bc85c13 WYG |
566 | return 0; |
567 | ||
e2ebc833 SG |
568 | il4965_math_div_round(current_voltage - eeprom_voltage, |
569 | TX_POWER_IL_VOLTAGE_CODES_PER_03V, &comp); | |
4bc85c13 WYG |
570 | |
571 | if (current_voltage > eeprom_voltage) | |
572 | comp *= 2; | |
573 | if ((comp < -2) || (comp > 2)) | |
574 | comp = 0; | |
575 | ||
576 | return comp; | |
577 | } | |
578 | ||
e2ebc833 | 579 | static s32 il4965_get_tx_atten_grp(u16 channel) |
4bc85c13 | 580 | { |
e2ebc833 SG |
581 | if (channel >= CALIB_IL_TX_ATTEN_GR5_FCH && |
582 | channel <= CALIB_IL_TX_ATTEN_GR5_LCH) | |
4bc85c13 WYG |
583 | return CALIB_CH_GROUP_5; |
584 | ||
e2ebc833 SG |
585 | if (channel >= CALIB_IL_TX_ATTEN_GR1_FCH && |
586 | channel <= CALIB_IL_TX_ATTEN_GR1_LCH) | |
4bc85c13 WYG |
587 | return CALIB_CH_GROUP_1; |
588 | ||
e2ebc833 SG |
589 | if (channel >= CALIB_IL_TX_ATTEN_GR2_FCH && |
590 | channel <= CALIB_IL_TX_ATTEN_GR2_LCH) | |
4bc85c13 WYG |
591 | return CALIB_CH_GROUP_2; |
592 | ||
e2ebc833 SG |
593 | if (channel >= CALIB_IL_TX_ATTEN_GR3_FCH && |
594 | channel <= CALIB_IL_TX_ATTEN_GR3_LCH) | |
4bc85c13 WYG |
595 | return CALIB_CH_GROUP_3; |
596 | ||
e2ebc833 SG |
597 | if (channel >= CALIB_IL_TX_ATTEN_GR4_FCH && |
598 | channel <= CALIB_IL_TX_ATTEN_GR4_LCH) | |
4bc85c13 WYG |
599 | return CALIB_CH_GROUP_4; |
600 | ||
8e638188 | 601 | return -EINVAL; |
4bc85c13 WYG |
602 | } |
603 | ||
46bc8d4b | 604 | static u32 il4965_get_sub_band(const struct il_priv *il, u32 channel) |
4bc85c13 WYG |
605 | { |
606 | s32 b = -1; | |
607 | ||
608 | for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) { | |
46bc8d4b | 609 | if (il->calib_info->band_info[b].ch_from == 0) |
4bc85c13 WYG |
610 | continue; |
611 | ||
232913b5 SG |
612 | if (channel >= il->calib_info->band_info[b].ch_from && |
613 | channel <= il->calib_info->band_info[b].ch_to) | |
4bc85c13 WYG |
614 | break; |
615 | } | |
616 | ||
617 | return b; | |
618 | } | |
619 | ||
e2ebc833 | 620 | static s32 il4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2) |
4bc85c13 WYG |
621 | { |
622 | s32 val; | |
623 | ||
624 | if (x2 == x1) | |
625 | return y1; | |
626 | else { | |
e2ebc833 | 627 | il4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val); |
4bc85c13 WYG |
628 | return val + y2; |
629 | } | |
630 | } | |
631 | ||
632 | /** | |
e2ebc833 | 633 | * il4965_interpolate_chan - Interpolate factory measurements for one channel |
4bc85c13 WYG |
634 | * |
635 | * Interpolates factory measurements from the two sample channels within a | |
636 | * sub-band, to apply to channel of interest. Interpolation is proportional to | |
637 | * differences in channel frequencies, which is proportional to differences | |
638 | * in channel number. | |
639 | */ | |
46bc8d4b | 640 | static int il4965_interpolate_chan(struct il_priv *il, u32 channel, |
e2ebc833 | 641 | struct il_eeprom_calib_ch_info *chan_info) |
4bc85c13 WYG |
642 | { |
643 | s32 s = -1; | |
644 | u32 c; | |
645 | u32 m; | |
e2ebc833 SG |
646 | const struct il_eeprom_calib_measure *m1; |
647 | const struct il_eeprom_calib_measure *m2; | |
648 | struct il_eeprom_calib_measure *omeas; | |
4bc85c13 WYG |
649 | u32 ch_i1; |
650 | u32 ch_i2; | |
651 | ||
46bc8d4b | 652 | s = il4965_get_sub_band(il, channel); |
4bc85c13 | 653 | if (s >= EEPROM_TX_POWER_BANDS) { |
9406f797 | 654 | IL_ERR("Tx Power can not find channel %d\n", channel); |
4bc85c13 WYG |
655 | return -1; |
656 | } | |
657 | ||
46bc8d4b SG |
658 | ch_i1 = il->calib_info->band_info[s].ch1.ch_num; |
659 | ch_i2 = il->calib_info->band_info[s].ch2.ch_num; | |
4bc85c13 WYG |
660 | chan_info->ch_num = (u8) channel; |
661 | ||
58de00a4 | 662 | D_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", |
4bc85c13 WYG |
663 | channel, s, ch_i1, ch_i2); |
664 | ||
665 | for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) { | |
666 | for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) { | |
46bc8d4b | 667 | m1 = &(il->calib_info->band_info[s].ch1. |
4bc85c13 | 668 | measurements[c][m]); |
46bc8d4b | 669 | m2 = &(il->calib_info->band_info[s].ch2. |
4bc85c13 WYG |
670 | measurements[c][m]); |
671 | omeas = &(chan_info->measurements[c][m]); | |
672 | ||
673 | omeas->actual_pow = | |
e2ebc833 | 674 | (u8) il4965_interpolate_value(channel, ch_i1, |
4bc85c13 WYG |
675 | m1->actual_pow, |
676 | ch_i2, | |
677 | m2->actual_pow); | |
678 | omeas->gain_idx = | |
e2ebc833 | 679 | (u8) il4965_interpolate_value(channel, ch_i1, |
4bc85c13 WYG |
680 | m1->gain_idx, ch_i2, |
681 | m2->gain_idx); | |
682 | omeas->temperature = | |
e2ebc833 | 683 | (u8) il4965_interpolate_value(channel, ch_i1, |
4bc85c13 WYG |
684 | m1->temperature, |
685 | ch_i2, | |
686 | m2->temperature); | |
687 | omeas->pa_det = | |
e2ebc833 | 688 | (s8) il4965_interpolate_value(channel, ch_i1, |
4bc85c13 WYG |
689 | m1->pa_det, ch_i2, |
690 | m2->pa_det); | |
691 | ||
58de00a4 | 692 | D_TXPOWER( |
4bc85c13 WYG |
693 | "chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m, |
694 | m1->actual_pow, m2->actual_pow, omeas->actual_pow); | |
58de00a4 | 695 | D_TXPOWER( |
4bc85c13 WYG |
696 | "chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m, |
697 | m1->gain_idx, m2->gain_idx, omeas->gain_idx); | |
58de00a4 | 698 | D_TXPOWER( |
4bc85c13 WYG |
699 | "chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m, |
700 | m1->pa_det, m2->pa_det, omeas->pa_det); | |
58de00a4 | 701 | D_TXPOWER( |
4bc85c13 WYG |
702 | "chain %d meas %d T1=%d T2=%d T=%d\n", c, m, |
703 | m1->temperature, m2->temperature, | |
704 | omeas->temperature); | |
705 | } | |
706 | } | |
707 | ||
708 | return 0; | |
709 | } | |
710 | ||
711 | /* bit-rate-dependent table to prevent Tx distortion, in half-dB units, | |
712 | * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */ | |
713 | static s32 back_off_table[] = { | |
714 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */ | |
715 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */ | |
716 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */ | |
717 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */ | |
718 | 10 /* CCK */ | |
719 | }; | |
720 | ||
721 | /* Thermal compensation values for txpower for various frequency ranges ... | |
722 | * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */ | |
e2ebc833 | 723 | static struct il4965_txpower_comp_entry { |
4bc85c13 WYG |
724 | s32 degrees_per_05db_a; |
725 | s32 degrees_per_05db_a_denom; | |
726 | } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = { | |
727 | {9, 2}, /* group 0 5.2, ch 34-43 */ | |
728 | {4, 1}, /* group 1 5.2, ch 44-70 */ | |
729 | {4, 1}, /* group 2 5.2, ch 71-124 */ | |
730 | {4, 1}, /* group 3 5.2, ch 125-200 */ | |
731 | {3, 1} /* group 4 2.4, ch all */ | |
732 | }; | |
733 | ||
0c2c8852 | 734 | static s32 get_min_power_idx(s32 rate_power_idx, u32 band) |
4bc85c13 WYG |
735 | { |
736 | if (!band) { | |
0c2c8852 | 737 | if ((rate_power_idx & 7) <= 4) |
2d09b062 | 738 | return MIN_TX_GAIN_IDX_52GHZ_EXT; |
4bc85c13 | 739 | } |
2d09b062 | 740 | return MIN_TX_GAIN_IDX; |
4bc85c13 WYG |
741 | } |
742 | ||
743 | struct gain_entry { | |
744 | u8 dsp; | |
745 | u8 radio; | |
746 | }; | |
747 | ||
748 | static const struct gain_entry gain_table[2][108] = { | |
0c2c8852 | 749 | /* 5.2GHz power gain idx table */ |
4bc85c13 WYG |
750 | { |
751 | {123, 0x3F}, /* highest txpower */ | |
752 | {117, 0x3F}, | |
753 | {110, 0x3F}, | |
754 | {104, 0x3F}, | |
755 | {98, 0x3F}, | |
756 | {110, 0x3E}, | |
757 | {104, 0x3E}, | |
758 | {98, 0x3E}, | |
759 | {110, 0x3D}, | |
760 | {104, 0x3D}, | |
761 | {98, 0x3D}, | |
762 | {110, 0x3C}, | |
763 | {104, 0x3C}, | |
764 | {98, 0x3C}, | |
765 | {110, 0x3B}, | |
766 | {104, 0x3B}, | |
767 | {98, 0x3B}, | |
768 | {110, 0x3A}, | |
769 | {104, 0x3A}, | |
770 | {98, 0x3A}, | |
771 | {110, 0x39}, | |
772 | {104, 0x39}, | |
773 | {98, 0x39}, | |
774 | {110, 0x38}, | |
775 | {104, 0x38}, | |
776 | {98, 0x38}, | |
777 | {110, 0x37}, | |
778 | {104, 0x37}, | |
779 | {98, 0x37}, | |
780 | {110, 0x36}, | |
781 | {104, 0x36}, | |
782 | {98, 0x36}, | |
783 | {110, 0x35}, | |
784 | {104, 0x35}, | |
785 | {98, 0x35}, | |
786 | {110, 0x34}, | |
787 | {104, 0x34}, | |
788 | {98, 0x34}, | |
789 | {110, 0x33}, | |
790 | {104, 0x33}, | |
791 | {98, 0x33}, | |
792 | {110, 0x32}, | |
793 | {104, 0x32}, | |
794 | {98, 0x32}, | |
795 | {110, 0x31}, | |
796 | {104, 0x31}, | |
797 | {98, 0x31}, | |
798 | {110, 0x30}, | |
799 | {104, 0x30}, | |
800 | {98, 0x30}, | |
801 | {110, 0x25}, | |
802 | {104, 0x25}, | |
803 | {98, 0x25}, | |
804 | {110, 0x24}, | |
805 | {104, 0x24}, | |
806 | {98, 0x24}, | |
807 | {110, 0x23}, | |
808 | {104, 0x23}, | |
809 | {98, 0x23}, | |
810 | {110, 0x22}, | |
811 | {104, 0x18}, | |
812 | {98, 0x18}, | |
813 | {110, 0x17}, | |
814 | {104, 0x17}, | |
815 | {98, 0x17}, | |
816 | {110, 0x16}, | |
817 | {104, 0x16}, | |
818 | {98, 0x16}, | |
819 | {110, 0x15}, | |
820 | {104, 0x15}, | |
821 | {98, 0x15}, | |
822 | {110, 0x14}, | |
823 | {104, 0x14}, | |
824 | {98, 0x14}, | |
825 | {110, 0x13}, | |
826 | {104, 0x13}, | |
827 | {98, 0x13}, | |
828 | {110, 0x12}, | |
829 | {104, 0x08}, | |
830 | {98, 0x08}, | |
831 | {110, 0x07}, | |
832 | {104, 0x07}, | |
833 | {98, 0x07}, | |
834 | {110, 0x06}, | |
835 | {104, 0x06}, | |
836 | {98, 0x06}, | |
837 | {110, 0x05}, | |
838 | {104, 0x05}, | |
839 | {98, 0x05}, | |
840 | {110, 0x04}, | |
841 | {104, 0x04}, | |
842 | {98, 0x04}, | |
843 | {110, 0x03}, | |
844 | {104, 0x03}, | |
845 | {98, 0x03}, | |
846 | {110, 0x02}, | |
847 | {104, 0x02}, | |
848 | {98, 0x02}, | |
849 | {110, 0x01}, | |
850 | {104, 0x01}, | |
851 | {98, 0x01}, | |
852 | {110, 0x00}, | |
853 | {104, 0x00}, | |
854 | {98, 0x00}, | |
855 | {93, 0x00}, | |
856 | {88, 0x00}, | |
857 | {83, 0x00}, | |
858 | {78, 0x00}, | |
859 | }, | |
0c2c8852 | 860 | /* 2.4GHz power gain idx table */ |
4bc85c13 WYG |
861 | { |
862 | {110, 0x3f}, /* highest txpower */ | |
863 | {104, 0x3f}, | |
864 | {98, 0x3f}, | |
865 | {110, 0x3e}, | |
866 | {104, 0x3e}, | |
867 | {98, 0x3e}, | |
868 | {110, 0x3d}, | |
869 | {104, 0x3d}, | |
870 | {98, 0x3d}, | |
871 | {110, 0x3c}, | |
872 | {104, 0x3c}, | |
873 | {98, 0x3c}, | |
874 | {110, 0x3b}, | |
875 | {104, 0x3b}, | |
876 | {98, 0x3b}, | |
877 | {110, 0x3a}, | |
878 | {104, 0x3a}, | |
879 | {98, 0x3a}, | |
880 | {110, 0x39}, | |
881 | {104, 0x39}, | |
882 | {98, 0x39}, | |
883 | {110, 0x38}, | |
884 | {104, 0x38}, | |
885 | {98, 0x38}, | |
886 | {110, 0x37}, | |
887 | {104, 0x37}, | |
888 | {98, 0x37}, | |
889 | {110, 0x36}, | |
890 | {104, 0x36}, | |
891 | {98, 0x36}, | |
892 | {110, 0x35}, | |
893 | {104, 0x35}, | |
894 | {98, 0x35}, | |
895 | {110, 0x34}, | |
896 | {104, 0x34}, | |
897 | {98, 0x34}, | |
898 | {110, 0x33}, | |
899 | {104, 0x33}, | |
900 | {98, 0x33}, | |
901 | {110, 0x32}, | |
902 | {104, 0x32}, | |
903 | {98, 0x32}, | |
904 | {110, 0x31}, | |
905 | {104, 0x31}, | |
906 | {98, 0x31}, | |
907 | {110, 0x30}, | |
908 | {104, 0x30}, | |
909 | {98, 0x30}, | |
910 | {110, 0x6}, | |
911 | {104, 0x6}, | |
912 | {98, 0x6}, | |
913 | {110, 0x5}, | |
914 | {104, 0x5}, | |
915 | {98, 0x5}, | |
916 | {110, 0x4}, | |
917 | {104, 0x4}, | |
918 | {98, 0x4}, | |
919 | {110, 0x3}, | |
920 | {104, 0x3}, | |
921 | {98, 0x3}, | |
922 | {110, 0x2}, | |
923 | {104, 0x2}, | |
924 | {98, 0x2}, | |
925 | {110, 0x1}, | |
926 | {104, 0x1}, | |
927 | {98, 0x1}, | |
928 | {110, 0x0}, | |
929 | {104, 0x0}, | |
930 | {98, 0x0}, | |
931 | {97, 0}, | |
932 | {96, 0}, | |
933 | {95, 0}, | |
934 | {94, 0}, | |
935 | {93, 0}, | |
936 | {92, 0}, | |
937 | {91, 0}, | |
938 | {90, 0}, | |
939 | {89, 0}, | |
940 | {88, 0}, | |
941 | {87, 0}, | |
942 | {86, 0}, | |
943 | {85, 0}, | |
944 | {84, 0}, | |
945 | {83, 0}, | |
946 | {82, 0}, | |
947 | {81, 0}, | |
948 | {80, 0}, | |
949 | {79, 0}, | |
950 | {78, 0}, | |
951 | {77, 0}, | |
952 | {76, 0}, | |
953 | {75, 0}, | |
954 | {74, 0}, | |
955 | {73, 0}, | |
956 | {72, 0}, | |
957 | {71, 0}, | |
958 | {70, 0}, | |
959 | {69, 0}, | |
960 | {68, 0}, | |
961 | {67, 0}, | |
962 | {66, 0}, | |
963 | {65, 0}, | |
964 | {64, 0}, | |
965 | {63, 0}, | |
966 | {62, 0}, | |
967 | {61, 0}, | |
968 | {60, 0}, | |
969 | {59, 0}, | |
970 | } | |
971 | }; | |
972 | ||
46bc8d4b | 973 | static int il4965_fill_txpower_tbl(struct il_priv *il, u8 band, u16 channel, |
4bc85c13 | 974 | u8 is_ht40, u8 ctrl_chan_high, |
e2ebc833 | 975 | struct il4965_tx_power_db *tx_power_tbl) |
4bc85c13 WYG |
976 | { |
977 | u8 saturation_power; | |
978 | s32 target_power; | |
979 | s32 user_target_power; | |
980 | s32 power_limit; | |
981 | s32 current_temp; | |
982 | s32 reg_limit; | |
983 | s32 current_regulatory; | |
984 | s32 txatten_grp = CALIB_CH_GROUP_MAX; | |
985 | int i; | |
986 | int c; | |
e2ebc833 SG |
987 | const struct il_channel_info *ch_info = NULL; |
988 | struct il_eeprom_calib_ch_info ch_eeprom_info; | |
989 | const struct il_eeprom_calib_measure *measurement; | |
4bc85c13 WYG |
990 | s16 voltage; |
991 | s32 init_voltage; | |
992 | s32 voltage_compensation; | |
993 | s32 degrees_per_05db_num; | |
994 | s32 degrees_per_05db_denom; | |
995 | s32 factory_temp; | |
996 | s32 temperature_comp[2]; | |
0c2c8852 | 997 | s32 factory_gain_idx[2]; |
4bc85c13 | 998 | s32 factory_actual_pwr[2]; |
0c2c8852 | 999 | s32 power_idx; |
4bc85c13 WYG |
1000 | |
1001 | /* tx_power_user_lmt is in dBm, convert to half-dBm (half-dB units | |
0c2c8852 | 1002 | * are used for idxing into txpower table) */ |
46bc8d4b | 1003 | user_target_power = 2 * il->tx_power_user_lmt; |
4bc85c13 WYG |
1004 | |
1005 | /* Get current (RXON) channel, band, width */ | |
58de00a4 | 1006 | D_TXPOWER("chan %d band %d is_ht40 %d\n", channel, band, |
4bc85c13 WYG |
1007 | is_ht40); |
1008 | ||
46bc8d4b | 1009 | ch_info = il_get_channel_info(il, il->band, channel); |
4bc85c13 | 1010 | |
e2ebc833 | 1011 | if (!il_is_channel_valid(ch_info)) |
4bc85c13 WYG |
1012 | return -EINVAL; |
1013 | ||
1014 | /* get txatten group, used to select 1) thermal txpower adjustment | |
1015 | * and 2) mimo txpower balance between Tx chains. */ | |
e2ebc833 | 1016 | txatten_grp = il4965_get_tx_atten_grp(channel); |
4bc85c13 | 1017 | if (txatten_grp < 0) { |
9406f797 | 1018 | IL_ERR("Can't find txatten group for channel %d.\n", |
4bc85c13 | 1019 | channel); |
5c30c76e | 1020 | return txatten_grp; |
4bc85c13 WYG |
1021 | } |
1022 | ||
58de00a4 | 1023 | D_TXPOWER("channel %d belongs to txatten group %d\n", |
4bc85c13 WYG |
1024 | channel, txatten_grp); |
1025 | ||
1026 | if (is_ht40) { | |
1027 | if (ctrl_chan_high) | |
1028 | channel -= 2; | |
1029 | else | |
1030 | channel += 2; | |
1031 | } | |
1032 | ||
1033 | /* hardware txpower limits ... | |
1034 | * saturation (clipping distortion) txpowers are in half-dBm */ | |
1035 | if (band) | |
46bc8d4b | 1036 | saturation_power = il->calib_info->saturation_power24; |
4bc85c13 | 1037 | else |
46bc8d4b | 1038 | saturation_power = il->calib_info->saturation_power52; |
4bc85c13 | 1039 | |
e2ebc833 SG |
1040 | if (saturation_power < IL_TX_POWER_SATURATION_MIN || |
1041 | saturation_power > IL_TX_POWER_SATURATION_MAX) { | |
4bc85c13 | 1042 | if (band) |
e2ebc833 | 1043 | saturation_power = IL_TX_POWER_DEFAULT_SATURATION_24; |
4bc85c13 | 1044 | else |
e2ebc833 | 1045 | saturation_power = IL_TX_POWER_DEFAULT_SATURATION_52; |
4bc85c13 WYG |
1046 | } |
1047 | ||
1048 | /* regulatory txpower limits ... reg_limit values are in half-dBm, | |
1049 | * max_power_avg values are in dBm, convert * 2 */ | |
1050 | if (is_ht40) | |
1051 | reg_limit = ch_info->ht40_max_power_avg * 2; | |
1052 | else | |
1053 | reg_limit = ch_info->max_power_avg * 2; | |
1054 | ||
e2ebc833 SG |
1055 | if ((reg_limit < IL_TX_POWER_REGULATORY_MIN) || |
1056 | (reg_limit > IL_TX_POWER_REGULATORY_MAX)) { | |
4bc85c13 | 1057 | if (band) |
e2ebc833 | 1058 | reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_24; |
4bc85c13 | 1059 | else |
e2ebc833 | 1060 | reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_52; |
4bc85c13 WYG |
1061 | } |
1062 | ||
1063 | /* Interpolate txpower calibration values for this channel, | |
1064 | * based on factory calibration tests on spaced channels. */ | |
46bc8d4b | 1065 | il4965_interpolate_chan(il, channel, &ch_eeprom_info); |
4bc85c13 WYG |
1066 | |
1067 | /* calculate tx gain adjustment based on power supply voltage */ | |
46bc8d4b SG |
1068 | voltage = le16_to_cpu(il->calib_info->voltage); |
1069 | init_voltage = (s32)le32_to_cpu(il->card_alive_init.voltage); | |
4bc85c13 | 1070 | voltage_compensation = |
e2ebc833 | 1071 | il4965_get_voltage_compensation(voltage, init_voltage); |
4bc85c13 | 1072 | |
58de00a4 | 1073 | D_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n", |
4bc85c13 WYG |
1074 | init_voltage, |
1075 | voltage, voltage_compensation); | |
1076 | ||
1077 | /* get current temperature (Celsius) */ | |
46bc8d4b SG |
1078 | current_temp = max(il->temperature, IL_TX_POWER_TEMPERATURE_MIN); |
1079 | current_temp = min(il->temperature, IL_TX_POWER_TEMPERATURE_MAX); | |
4bc85c13 WYG |
1080 | current_temp = KELVIN_TO_CELSIUS(current_temp); |
1081 | ||
1082 | /* select thermal txpower adjustment params, based on channel group | |
1083 | * (same frequency group used for mimo txatten adjustment) */ | |
1084 | degrees_per_05db_num = | |
1085 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a; | |
1086 | degrees_per_05db_denom = | |
1087 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom; | |
1088 | ||
1089 | /* get per-chain txpower values from factory measurements */ | |
1090 | for (c = 0; c < 2; c++) { | |
1091 | measurement = &ch_eeprom_info.measurements[c][1]; | |
1092 | ||
1093 | /* txgain adjustment (in half-dB steps) based on difference | |
1094 | * between factory and current temperature */ | |
1095 | factory_temp = measurement->temperature; | |
e2ebc833 | 1096 | il4965_math_div_round((current_temp - factory_temp) * |
4bc85c13 WYG |
1097 | degrees_per_05db_denom, |
1098 | degrees_per_05db_num, | |
1099 | &temperature_comp[c]); | |
1100 | ||
0c2c8852 | 1101 | factory_gain_idx[c] = measurement->gain_idx; |
4bc85c13 WYG |
1102 | factory_actual_pwr[c] = measurement->actual_pow; |
1103 | ||
58de00a4 SG |
1104 | D_TXPOWER("chain = %d\n", c); |
1105 | D_TXPOWER("fctry tmp %d, " | |
4bc85c13 WYG |
1106 | "curr tmp %d, comp %d steps\n", |
1107 | factory_temp, current_temp, | |
1108 | temperature_comp[c]); | |
1109 | ||
58de00a4 | 1110 | D_TXPOWER("fctry idx %d, fctry pwr %d\n", |
0c2c8852 | 1111 | factory_gain_idx[c], |
4bc85c13 WYG |
1112 | factory_actual_pwr[c]); |
1113 | } | |
1114 | ||
1115 | /* for each of 33 bit-rates (including 1 for CCK) */ | |
3b98c7f4 | 1116 | for (i = 0; i < POWER_TBL_NUM_ENTRIES; i++) { |
4bc85c13 | 1117 | u8 is_mimo_rate; |
e2ebc833 | 1118 | union il4965_tx_power_dual_stream tx_power; |
4bc85c13 WYG |
1119 | |
1120 | /* for mimo, reduce each chain's txpower by half | |
1121 | * (3dB, 6 steps), so total output power is regulatory | |
1122 | * compliant. */ | |
1123 | if (i & 0x8) { | |
1124 | current_regulatory = reg_limit - | |
e2ebc833 | 1125 | IL_TX_POWER_MIMO_REGULATORY_COMPENSATION; |
4bc85c13 WYG |
1126 | is_mimo_rate = 1; |
1127 | } else { | |
1128 | current_regulatory = reg_limit; | |
1129 | is_mimo_rate = 0; | |
1130 | } | |
1131 | ||
1132 | /* find txpower limit, either hardware or regulatory */ | |
1133 | power_limit = saturation_power - back_off_table[i]; | |
1134 | if (power_limit > current_regulatory) | |
1135 | power_limit = current_regulatory; | |
1136 | ||
1137 | /* reduce user's txpower request if necessary | |
1138 | * for this rate on this channel */ | |
1139 | target_power = user_target_power; | |
1140 | if (target_power > power_limit) | |
1141 | target_power = power_limit; | |
1142 | ||
58de00a4 | 1143 | D_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n", |
4bc85c13 WYG |
1144 | i, saturation_power - back_off_table[i], |
1145 | current_regulatory, user_target_power, | |
1146 | target_power); | |
1147 | ||
1148 | /* for each of 2 Tx chains (radio transmitters) */ | |
1149 | for (c = 0; c < 2; c++) { | |
1150 | s32 atten_value; | |
1151 | ||
1152 | if (is_mimo_rate) | |
1153 | atten_value = | |
46bc8d4b | 1154 | (s32)le32_to_cpu(il->card_alive_init. |
4bc85c13 WYG |
1155 | tx_atten[txatten_grp][c]); |
1156 | else | |
1157 | atten_value = 0; | |
1158 | ||
0c2c8852 SG |
1159 | /* calculate idx; higher idx means lower txpower */ |
1160 | power_idx = (u8) (factory_gain_idx[c] - | |
4bc85c13 WYG |
1161 | (target_power - |
1162 | factory_actual_pwr[c]) - | |
1163 | temperature_comp[c] - | |
1164 | voltage_compensation + | |
1165 | atten_value); | |
1166 | ||
0c2c8852 SG |
1167 | /* D_TXPOWER("calculated txpower idx %d\n", |
1168 | power_idx); */ | |
4bc85c13 | 1169 | |
0c2c8852 SG |
1170 | if (power_idx < get_min_power_idx(i, band)) |
1171 | power_idx = get_min_power_idx(i, band); | |
4bc85c13 | 1172 | |
0c2c8852 | 1173 | /* adjust 5 GHz idx to support negative idxes */ |
4bc85c13 | 1174 | if (!band) |
0c2c8852 | 1175 | power_idx += 9; |
4bc85c13 WYG |
1176 | |
1177 | /* CCK, rate 32, reduce txpower for CCK */ | |
3b98c7f4 | 1178 | if (i == POWER_TBL_CCK_ENTRY) |
0c2c8852 | 1179 | power_idx += |
e2ebc833 | 1180 | IL_TX_POWER_CCK_COMPENSATION_C_STEP; |
4bc85c13 WYG |
1181 | |
1182 | /* stay within the table! */ | |
0c2c8852 SG |
1183 | if (power_idx > 107) { |
1184 | IL_WARN("txpower idx %d > 107\n", | |
1185 | power_idx); | |
1186 | power_idx = 107; | |
4bc85c13 | 1187 | } |
0c2c8852 SG |
1188 | if (power_idx < 0) { |
1189 | IL_WARN("txpower idx %d < 0\n", | |
1190 | power_idx); | |
1191 | power_idx = 0; | |
4bc85c13 WYG |
1192 | } |
1193 | ||
1194 | /* fill txpower command for this rate/chain */ | |
1195 | tx_power.s.radio_tx_gain[c] = | |
0c2c8852 | 1196 | gain_table[band][power_idx].radio; |
4bc85c13 | 1197 | tx_power.s.dsp_predis_atten[c] = |
0c2c8852 | 1198 | gain_table[band][power_idx].dsp; |
4bc85c13 | 1199 | |
0c2c8852 | 1200 | D_TXPOWER("chain %d mimo %d idx %d " |
4bc85c13 | 1201 | "gain 0x%02x dsp %d\n", |
0c2c8852 | 1202 | c, atten_value, power_idx, |
4bc85c13 WYG |
1203 | tx_power.s.radio_tx_gain[c], |
1204 | tx_power.s.dsp_predis_atten[c]); | |
1205 | } /* for each chain */ | |
1206 | ||
1207 | tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw); | |
1208 | ||
1209 | } /* for each rate */ | |
1210 | ||
1211 | return 0; | |
1212 | } | |
1213 | ||
1214 | /** | |
e2ebc833 | 1215 | * il4965_send_tx_power - Configure the TXPOWER level user limit |
4bc85c13 WYG |
1216 | * |
1217 | * Uses the active RXON for channel, band, and characteristics (ht40, high) | |
46bc8d4b | 1218 | * The power limit is taken from il->tx_power_user_lmt. |
4bc85c13 | 1219 | */ |
46bc8d4b | 1220 | static int il4965_send_tx_power(struct il_priv *il) |
4bc85c13 | 1221 | { |
e2ebc833 | 1222 | struct il4965_txpowertable_cmd cmd = { 0 }; |
4bc85c13 WYG |
1223 | int ret; |
1224 | u8 band = 0; | |
1225 | bool is_ht40 = false; | |
1226 | u8 ctrl_chan_high = 0; | |
7c2cde2e | 1227 | struct il_rxon_context *ctx = &il->ctx; |
4bc85c13 | 1228 | |
46bc8d4b | 1229 | if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &il->status), |
4bc85c13 WYG |
1230 | "TX Power requested while scanning!\n")) |
1231 | return -EAGAIN; | |
1232 | ||
46bc8d4b | 1233 | band = il->band == IEEE80211_BAND_2GHZ; |
4bc85c13 | 1234 | |
be663ab6 | 1235 | is_ht40 = iw4965_is_ht40_channel(ctx->active.flags); |
4bc85c13 WYG |
1236 | |
1237 | if (is_ht40 && (ctx->active.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) | |
1238 | ctrl_chan_high = 1; | |
1239 | ||
1240 | cmd.band = band; | |
1241 | cmd.channel = ctx->active.channel; | |
1242 | ||
46bc8d4b | 1243 | ret = il4965_fill_txpower_tbl(il, band, |
4bc85c13 WYG |
1244 | le16_to_cpu(ctx->active.channel), |
1245 | is_ht40, ctrl_chan_high, &cmd.tx_power); | |
1246 | if (ret) | |
1247 | goto out; | |
1248 | ||
46bc8d4b | 1249 | ret = il_send_cmd_pdu(il, |
3b98c7f4 | 1250 | REPLY_TX_PWR_TBL_CMD, sizeof(cmd), &cmd); |
4bc85c13 WYG |
1251 | |
1252 | out: | |
1253 | return ret; | |
1254 | } | |
1255 | ||
46bc8d4b | 1256 | static int il4965_send_rxon_assoc(struct il_priv *il, |
e2ebc833 | 1257 | struct il_rxon_context *ctx) |
4bc85c13 WYG |
1258 | { |
1259 | int ret = 0; | |
e2ebc833 SG |
1260 | struct il4965_rxon_assoc_cmd rxon_assoc; |
1261 | const struct il_rxon_cmd *rxon1 = &ctx->staging; | |
1262 | const struct il_rxon_cmd *rxon2 = &ctx->active; | |
4bc85c13 | 1263 | |
232913b5 SG |
1264 | if (rxon1->flags == rxon2->flags && |
1265 | rxon1->filter_flags == rxon2->filter_flags && | |
1266 | rxon1->cck_basic_rates == rxon2->cck_basic_rates && | |
1267 | rxon1->ofdm_ht_single_stream_basic_rates == | |
1268 | rxon2->ofdm_ht_single_stream_basic_rates && | |
1269 | rxon1->ofdm_ht_dual_stream_basic_rates == | |
1270 | rxon2->ofdm_ht_dual_stream_basic_rates && | |
1271 | rxon1->rx_chain == rxon2->rx_chain && | |
1272 | rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) { | |
58de00a4 | 1273 | D_INFO("Using current RXON_ASSOC. Not resending.\n"); |
4bc85c13 WYG |
1274 | return 0; |
1275 | } | |
1276 | ||
1277 | rxon_assoc.flags = ctx->staging.flags; | |
1278 | rxon_assoc.filter_flags = ctx->staging.filter_flags; | |
1279 | rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates; | |
1280 | rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates; | |
1281 | rxon_assoc.reserved = 0; | |
1282 | rxon_assoc.ofdm_ht_single_stream_basic_rates = | |
1283 | ctx->staging.ofdm_ht_single_stream_basic_rates; | |
1284 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = | |
1285 | ctx->staging.ofdm_ht_dual_stream_basic_rates; | |
1286 | rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain; | |
1287 | ||
46bc8d4b | 1288 | ret = il_send_cmd_pdu_async(il, REPLY_RXON_ASSOC, |
4bc85c13 | 1289 | sizeof(rxon_assoc), &rxon_assoc, NULL); |
4bc85c13 WYG |
1290 | |
1291 | return ret; | |
1292 | } | |
1293 | ||
46bc8d4b | 1294 | static int il4965_commit_rxon(struct il_priv *il, struct il_rxon_context *ctx) |
4bc85c13 WYG |
1295 | { |
1296 | /* cast away the const for active_rxon in this function */ | |
e2ebc833 | 1297 | struct il_rxon_cmd *active_rxon = (void *)&ctx->active; |
4bc85c13 WYG |
1298 | int ret; |
1299 | bool new_assoc = | |
1300 | !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); | |
1301 | ||
46bc8d4b | 1302 | if (!il_is_alive(il)) |
4bc85c13 WYG |
1303 | return -EBUSY; |
1304 | ||
1305 | if (!ctx->is_active) | |
1306 | return 0; | |
1307 | ||
1308 | /* always get timestamp with Rx frame */ | |
1309 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; | |
1310 | ||
46bc8d4b | 1311 | ret = il_check_rxon_cmd(il, ctx); |
4bc85c13 | 1312 | if (ret) { |
9406f797 | 1313 | IL_ERR("Invalid RXON configuration. Not committing.\n"); |
4bc85c13 WYG |
1314 | return -EINVAL; |
1315 | } | |
1316 | ||
1317 | /* | |
1318 | * receive commit_rxon request | |
1319 | * abort any previous channel switch if still in process | |
1320 | */ | |
46bc8d4b | 1321 | if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status) && |
232913b5 | 1322 | il->switch_channel != ctx->staging.channel) { |
58de00a4 | 1323 | D_11H("abort channel switch on %d\n", |
46bc8d4b SG |
1324 | le16_to_cpu(il->switch_channel)); |
1325 | il_chswitch_done(il, false); | |
4bc85c13 WYG |
1326 | } |
1327 | ||
1328 | /* If we don't need to send a full RXON, we can use | |
e2ebc833 | 1329 | * il_rxon_assoc_cmd which is used to reconfigure filter |
4bc85c13 | 1330 | * and other flags for the current radio configuration. */ |
46bc8d4b SG |
1331 | if (!il_full_rxon_required(il, ctx)) { |
1332 | ret = il_send_rxon_assoc(il, ctx); | |
4bc85c13 | 1333 | if (ret) { |
9406f797 | 1334 | IL_ERR("Error setting RXON_ASSOC (%d)\n", ret); |
4bc85c13 WYG |
1335 | return ret; |
1336 | } | |
1337 | ||
1338 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); | |
46bc8d4b | 1339 | il_print_rx_config_cmd(il, ctx); |
17e859a8 SG |
1340 | /* |
1341 | * We do not commit tx power settings while channel changing, | |
1342 | * do it now if tx power changed. | |
1343 | */ | |
46bc8d4b | 1344 | il_set_tx_power(il, il->tx_power_next, false); |
17e859a8 | 1345 | return 0; |
4bc85c13 WYG |
1346 | } |
1347 | ||
1348 | /* If we are currently associated and the new config requires | |
1349 | * an RXON_ASSOC and the new config wants the associated mask enabled, | |
1350 | * we must clear the associated from the active configuration | |
1351 | * before we apply the new config */ | |
e2ebc833 | 1352 | if (il_is_associated_ctx(ctx) && new_assoc) { |
58de00a4 | 1353 | D_INFO("Toggling associated bit on current RXON\n"); |
4bc85c13 WYG |
1354 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
1355 | ||
46bc8d4b | 1356 | ret = il_send_cmd_pdu(il, ctx->rxon_cmd, |
e2ebc833 | 1357 | sizeof(struct il_rxon_cmd), |
4bc85c13 WYG |
1358 | active_rxon); |
1359 | ||
1360 | /* If the mask clearing failed then we set | |
1361 | * active_rxon back to what it was previously */ | |
1362 | if (ret) { | |
1363 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; | |
9406f797 | 1364 | IL_ERR("Error clearing ASSOC_MSK (%d)\n", ret); |
4bc85c13 WYG |
1365 | return ret; |
1366 | } | |
46bc8d4b SG |
1367 | il_clear_ucode_stations(il, ctx); |
1368 | il_restore_stations(il, ctx); | |
1369 | ret = il4965_restore_default_wep_keys(il, ctx); | |
4bc85c13 | 1370 | if (ret) { |
9406f797 | 1371 | IL_ERR("Failed to restore WEP keys (%d)\n", ret); |
4bc85c13 WYG |
1372 | return ret; |
1373 | } | |
1374 | } | |
1375 | ||
58de00a4 | 1376 | D_INFO("Sending RXON\n" |
4bc85c13 WYG |
1377 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
1378 | "* channel = %d\n" | |
1379 | "* bssid = %pM\n", | |
1380 | (new_assoc ? "" : "out"), | |
1381 | le16_to_cpu(ctx->staging.channel), | |
1382 | ctx->staging.bssid_addr); | |
1383 | ||
46bc8d4b SG |
1384 | il_set_rxon_hwcrypto(il, ctx, |
1385 | !il->cfg->mod_params->sw_crypto); | |
4bc85c13 WYG |
1386 | |
1387 | /* Apply the new configuration | |
1388 | * RXON unassoc clears the station table in uCode so restoration of | |
1389 | * stations is needed after it (the RXON command) completes | |
1390 | */ | |
1391 | if (!new_assoc) { | |
46bc8d4b | 1392 | ret = il_send_cmd_pdu(il, ctx->rxon_cmd, |
e2ebc833 | 1393 | sizeof(struct il_rxon_cmd), &ctx->staging); |
4bc85c13 | 1394 | if (ret) { |
9406f797 | 1395 | IL_ERR("Error setting new RXON (%d)\n", ret); |
4bc85c13 WYG |
1396 | return ret; |
1397 | } | |
58de00a4 | 1398 | D_INFO("Return from !new_assoc RXON.\n"); |
4bc85c13 | 1399 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); |
46bc8d4b SG |
1400 | il_clear_ucode_stations(il, ctx); |
1401 | il_restore_stations(il, ctx); | |
1402 | ret = il4965_restore_default_wep_keys(il, ctx); | |
4bc85c13 | 1403 | if (ret) { |
9406f797 | 1404 | IL_ERR("Failed to restore WEP keys (%d)\n", ret); |
4bc85c13 WYG |
1405 | return ret; |
1406 | } | |
1407 | } | |
1408 | if (new_assoc) { | |
46bc8d4b | 1409 | il->start_calib = 0; |
4bc85c13 WYG |
1410 | /* Apply the new configuration |
1411 | * RXON assoc doesn't clear the station table in uCode, | |
1412 | */ | |
46bc8d4b | 1413 | ret = il_send_cmd_pdu(il, ctx->rxon_cmd, |
e2ebc833 | 1414 | sizeof(struct il_rxon_cmd), &ctx->staging); |
4bc85c13 | 1415 | if (ret) { |
9406f797 | 1416 | IL_ERR("Error setting new RXON (%d)\n", ret); |
4bc85c13 WYG |
1417 | return ret; |
1418 | } | |
1419 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); | |
1420 | } | |
46bc8d4b | 1421 | il_print_rx_config_cmd(il, ctx); |
4bc85c13 | 1422 | |
46bc8d4b | 1423 | il4965_init_sensitivity(il); |
4bc85c13 WYG |
1424 | |
1425 | /* If we issue a new RXON command which required a tune then we must | |
1426 | * send a new TXPOWER command or we won't be able to Tx any frames */ | |
46bc8d4b | 1427 | ret = il_set_tx_power(il, il->tx_power_next, true); |
4bc85c13 | 1428 | if (ret) { |
9406f797 | 1429 | IL_ERR("Error sending TX power (%d)\n", ret); |
4bc85c13 WYG |
1430 | return ret; |
1431 | } | |
1432 | ||
1433 | return 0; | |
1434 | } | |
1435 | ||
46bc8d4b | 1436 | static int il4965_hw_channel_switch(struct il_priv *il, |
4bc85c13 WYG |
1437 | struct ieee80211_channel_switch *ch_switch) |
1438 | { | |
7c2cde2e | 1439 | struct il_rxon_context *ctx = &il->ctx; |
4bc85c13 WYG |
1440 | int rc; |
1441 | u8 band = 0; | |
1442 | bool is_ht40 = false; | |
1443 | u8 ctrl_chan_high = 0; | |
e2ebc833 SG |
1444 | struct il4965_channel_switch_cmd cmd; |
1445 | const struct il_channel_info *ch_info; | |
4bc85c13 WYG |
1446 | u32 switch_time_in_usec, ucode_switch_time; |
1447 | u16 ch; | |
1448 | u32 tsf_low; | |
1449 | u8 switch_count; | |
1450 | u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval); | |
1451 | struct ieee80211_vif *vif = ctx->vif; | |
46bc8d4b | 1452 | band = il->band == IEEE80211_BAND_2GHZ; |
4bc85c13 | 1453 | |
be663ab6 | 1454 | is_ht40 = iw4965_is_ht40_channel(ctx->staging.flags); |
4bc85c13 WYG |
1455 | |
1456 | if (is_ht40 && | |
1457 | (ctx->staging.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) | |
1458 | ctrl_chan_high = 1; | |
1459 | ||
1460 | cmd.band = band; | |
1461 | cmd.expect_beacon = 0; | |
1462 | ch = ch_switch->channel->hw_value; | |
1463 | cmd.channel = cpu_to_le16(ch); | |
1464 | cmd.rxon_flags = ctx->staging.flags; | |
1465 | cmd.rxon_filter_flags = ctx->staging.filter_flags; | |
1466 | switch_count = ch_switch->count; | |
1467 | tsf_low = ch_switch->timestamp & 0x0ffffffff; | |
1468 | /* | |
1469 | * calculate the ucode channel switch time | |
1470 | * adding TSF as one of the factor for when to switch | |
1471 | */ | |
232913b5 | 1472 | if (il->ucode_beacon_time > tsf_low && beacon_interval) { |
46bc8d4b | 1473 | if (switch_count > ((il->ucode_beacon_time - tsf_low) / |
4bc85c13 | 1474 | beacon_interval)) { |
46bc8d4b | 1475 | switch_count -= (il->ucode_beacon_time - |
4bc85c13 WYG |
1476 | tsf_low) / beacon_interval; |
1477 | } else | |
1478 | switch_count = 0; | |
1479 | } | |
1480 | if (switch_count <= 1) | |
46bc8d4b | 1481 | cmd.switch_time = cpu_to_le32(il->ucode_beacon_time); |
4bc85c13 WYG |
1482 | else { |
1483 | switch_time_in_usec = | |
1484 | vif->bss_conf.beacon_int * switch_count * TIME_UNIT; | |
46bc8d4b | 1485 | ucode_switch_time = il_usecs_to_beacons(il, |
4bc85c13 WYG |
1486 | switch_time_in_usec, |
1487 | beacon_interval); | |
46bc8d4b SG |
1488 | cmd.switch_time = il_add_beacon_time(il, |
1489 | il->ucode_beacon_time, | |
4bc85c13 WYG |
1490 | ucode_switch_time, |
1491 | beacon_interval); | |
1492 | } | |
58de00a4 | 1493 | D_11H("uCode time for the switch is 0x%x\n", |
4bc85c13 | 1494 | cmd.switch_time); |
46bc8d4b | 1495 | ch_info = il_get_channel_info(il, il->band, ch); |
4bc85c13 | 1496 | if (ch_info) |
e2ebc833 | 1497 | cmd.expect_beacon = il_is_channel_radar(ch_info); |
4bc85c13 | 1498 | else { |
9406f797 | 1499 | IL_ERR("invalid channel switch from %u to %u\n", |
4bc85c13 WYG |
1500 | ctx->active.channel, ch); |
1501 | return -EFAULT; | |
1502 | } | |
1503 | ||
46bc8d4b | 1504 | rc = il4965_fill_txpower_tbl(il, band, ch, is_ht40, |
4bc85c13 WYG |
1505 | ctrl_chan_high, &cmd.tx_power); |
1506 | if (rc) { | |
58de00a4 | 1507 | D_11H("error:%d fill txpower_tbl\n", rc); |
4bc85c13 WYG |
1508 | return rc; |
1509 | } | |
1510 | ||
46bc8d4b | 1511 | return il_send_cmd_pdu(il, |
be663ab6 | 1512 | REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd); |
4bc85c13 WYG |
1513 | } |
1514 | ||
1515 | /** | |
e2ebc833 | 1516 | * il4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array |
4bc85c13 | 1517 | */ |
46bc8d4b | 1518 | static void il4965_txq_update_byte_cnt_tbl(struct il_priv *il, |
e2ebc833 | 1519 | struct il_tx_queue *txq, |
4bc85c13 WYG |
1520 | u16 byte_cnt) |
1521 | { | |
46bc8d4b | 1522 | struct il4965_scd_bc_tbl *scd_bc_tbl = il->scd_bc_tbls.addr; |
4bc85c13 WYG |
1523 | int txq_id = txq->q.id; |
1524 | int write_ptr = txq->q.write_ptr; | |
e2ebc833 | 1525 | int len = byte_cnt + IL_TX_CRC_SIZE + IL_TX_DELIMITER_SIZE; |
4bc85c13 WYG |
1526 | __le16 bc_ent; |
1527 | ||
1528 | WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX); | |
1529 | ||
1530 | bc_ent = cpu_to_le16(len & 0xFFF); | |
1531 | /* Set up byte count within first 256 entries */ | |
1532 | scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent; | |
1533 | ||
1534 | /* If within first 64 entries, duplicate at end */ | |
1535 | if (write_ptr < TFD_QUEUE_SIZE_BC_DUP) | |
1536 | scd_bc_tbl[txq_id]. | |
1537 | tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent; | |
1538 | } | |
1539 | ||
1540 | /** | |
e2ebc833 | 1541 | * il4965_hw_get_temperature - return the calibrated temperature (in Kelvin) |
ebf0d90d | 1542 | * @stats: Provides the temperature reading from the uCode |
4bc85c13 | 1543 | * |
ebf0d90d | 1544 | * A return of <0 indicates bogus data in the stats |
4bc85c13 | 1545 | */ |
46bc8d4b | 1546 | static int il4965_hw_get_temperature(struct il_priv *il) |
4bc85c13 WYG |
1547 | { |
1548 | s32 temperature; | |
1549 | s32 vt; | |
1550 | s32 R1, R2, R3; | |
1551 | u32 R4; | |
1552 | ||
46bc8d4b | 1553 | if (test_bit(STATUS_TEMPERATURE, &il->status) && |
ebf0d90d | 1554 | (il->_4965.stats.flag & |
4bc85c13 | 1555 | STATISTICS_REPLY_FLG_HT40_MODE_MSK)) { |
58de00a4 | 1556 | D_TEMP("Running HT40 temperature calibration\n"); |
46bc8d4b SG |
1557 | R1 = (s32)le32_to_cpu(il->card_alive_init.therm_r1[1]); |
1558 | R2 = (s32)le32_to_cpu(il->card_alive_init.therm_r2[1]); | |
1559 | R3 = (s32)le32_to_cpu(il->card_alive_init.therm_r3[1]); | |
1560 | R4 = le32_to_cpu(il->card_alive_init.therm_r4[1]); | |
4bc85c13 | 1561 | } else { |
58de00a4 | 1562 | D_TEMP("Running temperature calibration\n"); |
46bc8d4b SG |
1563 | R1 = (s32)le32_to_cpu(il->card_alive_init.therm_r1[0]); |
1564 | R2 = (s32)le32_to_cpu(il->card_alive_init.therm_r2[0]); | |
1565 | R3 = (s32)le32_to_cpu(il->card_alive_init.therm_r3[0]); | |
1566 | R4 = le32_to_cpu(il->card_alive_init.therm_r4[0]); | |
4bc85c13 WYG |
1567 | } |
1568 | ||
1569 | /* | |
1570 | * Temperature is only 23 bits, so sign extend out to 32. | |
1571 | * | |
ebf0d90d | 1572 | * NOTE If we haven't received a stats notification yet |
4bc85c13 WYG |
1573 | * with an updated temperature, use R4 provided to us in the |
1574 | * "initialize" ALIVE response. | |
1575 | */ | |
46bc8d4b | 1576 | if (!test_bit(STATUS_TEMPERATURE, &il->status)) |
4bc85c13 WYG |
1577 | vt = sign_extend32(R4, 23); |
1578 | else | |
ebf0d90d | 1579 | vt = sign_extend32(le32_to_cpu(il->_4965.stats. |
4bc85c13 WYG |
1580 | general.common.temperature), 23); |
1581 | ||
58de00a4 | 1582 | D_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt); |
4bc85c13 WYG |
1583 | |
1584 | if (R3 == R1) { | |
9406f797 | 1585 | IL_ERR("Calibration conflict R1 == R3\n"); |
4bc85c13 WYG |
1586 | return -1; |
1587 | } | |
1588 | ||
1589 | /* Calculate temperature in degrees Kelvin, adjust by 97%. | |
1590 | * Add offset to center the adjustment around 0 degrees Centigrade. */ | |
1591 | temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2); | |
1592 | temperature /= (R3 - R1); | |
1593 | temperature = (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET; | |
1594 | ||
58de00a4 | 1595 | D_TEMP("Calibrated temperature: %dK, %dC\n", |
4bc85c13 WYG |
1596 | temperature, KELVIN_TO_CELSIUS(temperature)); |
1597 | ||
1598 | return temperature; | |
1599 | } | |
1600 | ||
1601 | /* Adjust Txpower only if temperature variance is greater than threshold. */ | |
e2ebc833 | 1602 | #define IL_TEMPERATURE_THRESHOLD 3 |
4bc85c13 WYG |
1603 | |
1604 | /** | |
e2ebc833 | 1605 | * il4965_is_temp_calib_needed - determines if new calibration is needed |
4bc85c13 WYG |
1606 | * |
1607 | * If the temperature changed has changed sufficiently, then a recalibration | |
1608 | * is needed. | |
1609 | * | |
46bc8d4b | 1610 | * Assumes caller will replace il->last_temperature once calibration |
4bc85c13 WYG |
1611 | * executed. |
1612 | */ | |
46bc8d4b | 1613 | static int il4965_is_temp_calib_needed(struct il_priv *il) |
4bc85c13 WYG |
1614 | { |
1615 | int temp_diff; | |
1616 | ||
46bc8d4b | 1617 | if (!test_bit(STATUS_STATISTICS, &il->status)) { |
ebf0d90d | 1618 | D_TEMP("Temperature not updated -- no stats.\n"); |
4bc85c13 WYG |
1619 | return 0; |
1620 | } | |
1621 | ||
46bc8d4b | 1622 | temp_diff = il->temperature - il->last_temperature; |
4bc85c13 WYG |
1623 | |
1624 | /* get absolute value */ | |
1625 | if (temp_diff < 0) { | |
58de00a4 | 1626 | D_POWER("Getting cooler, delta %d\n", temp_diff); |
4bc85c13 WYG |
1627 | temp_diff = -temp_diff; |
1628 | } else if (temp_diff == 0) | |
58de00a4 | 1629 | D_POWER("Temperature unchanged\n"); |
4bc85c13 | 1630 | else |
58de00a4 | 1631 | D_POWER("Getting warmer, delta %d\n", temp_diff); |
4bc85c13 | 1632 | |
e2ebc833 | 1633 | if (temp_diff < IL_TEMPERATURE_THRESHOLD) { |
58de00a4 | 1634 | D_POWER(" => thermal txpower calib not needed\n"); |
4bc85c13 WYG |
1635 | return 0; |
1636 | } | |
1637 | ||
58de00a4 | 1638 | D_POWER(" => thermal txpower calib needed\n"); |
4bc85c13 WYG |
1639 | |
1640 | return 1; | |
1641 | } | |
1642 | ||
46bc8d4b | 1643 | static void il4965_temperature_calib(struct il_priv *il) |
4bc85c13 WYG |
1644 | { |
1645 | s32 temp; | |
1646 | ||
46bc8d4b | 1647 | temp = il4965_hw_get_temperature(il); |
e2ebc833 | 1648 | if (IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp)) |
4bc85c13 WYG |
1649 | return; |
1650 | ||
46bc8d4b SG |
1651 | if (il->temperature != temp) { |
1652 | if (il->temperature) | |
58de00a4 | 1653 | D_TEMP("Temperature changed " |
4bc85c13 | 1654 | "from %dC to %dC\n", |
46bc8d4b | 1655 | KELVIN_TO_CELSIUS(il->temperature), |
4bc85c13 WYG |
1656 | KELVIN_TO_CELSIUS(temp)); |
1657 | else | |
58de00a4 | 1658 | D_TEMP("Temperature " |
4bc85c13 WYG |
1659 | "initialized to %dC\n", |
1660 | KELVIN_TO_CELSIUS(temp)); | |
1661 | } | |
1662 | ||
46bc8d4b SG |
1663 | il->temperature = temp; |
1664 | set_bit(STATUS_TEMPERATURE, &il->status); | |
4bc85c13 | 1665 | |
46bc8d4b SG |
1666 | if (!il->disable_tx_power_cal && |
1667 | unlikely(!test_bit(STATUS_SCANNING, &il->status)) && | |
1668 | il4965_is_temp_calib_needed(il)) | |
1669 | queue_work(il->workqueue, &il->txpower_work); | |
4bc85c13 WYG |
1670 | } |
1671 | ||
e2ebc833 | 1672 | static u16 il4965_get_hcmd_size(u8 cmd_id, u16 len) |
4bc85c13 WYG |
1673 | { |
1674 | switch (cmd_id) { | |
1675 | case REPLY_RXON: | |
e2ebc833 | 1676 | return (u16) sizeof(struct il4965_rxon_cmd); |
4bc85c13 WYG |
1677 | default: |
1678 | return len; | |
1679 | } | |
1680 | } | |
1681 | ||
e2ebc833 | 1682 | static u16 il4965_build_addsta_hcmd(const struct il_addsta_cmd *cmd, |
be663ab6 | 1683 | u8 *data) |
4bc85c13 | 1684 | { |
e2ebc833 | 1685 | struct il4965_addsta_cmd *addsta = (struct il4965_addsta_cmd *)data; |
4bc85c13 WYG |
1686 | addsta->mode = cmd->mode; |
1687 | memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify)); | |
e2ebc833 | 1688 | memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo)); |
4bc85c13 WYG |
1689 | addsta->station_flags = cmd->station_flags; |
1690 | addsta->station_flags_msk = cmd->station_flags_msk; | |
1691 | addsta->tid_disable_tx = cmd->tid_disable_tx; | |
1692 | addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid; | |
1693 | addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid; | |
1694 | addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn; | |
1695 | addsta->sleep_tx_count = cmd->sleep_tx_count; | |
1696 | addsta->reserved1 = cpu_to_le16(0); | |
1697 | addsta->reserved2 = cpu_to_le16(0); | |
1698 | ||
e2ebc833 | 1699 | return (u16)sizeof(struct il4965_addsta_cmd); |
4bc85c13 WYG |
1700 | } |
1701 | ||
e2ebc833 | 1702 | static inline u32 il4965_get_scd_ssn(struct il4965_tx_resp *tx_resp) |
4bc85c13 WYG |
1703 | { |
1704 | return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN; | |
1705 | } | |
1706 | ||
1707 | /** | |
e2ebc833 | 1708 | * il4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue |
4bc85c13 | 1709 | */ |
46bc8d4b | 1710 | static int il4965_tx_status_reply_tx(struct il_priv *il, |
e2ebc833 SG |
1711 | struct il_ht_agg *agg, |
1712 | struct il4965_tx_resp *tx_resp, | |
4bc85c13 WYG |
1713 | int txq_id, u16 start_idx) |
1714 | { | |
1715 | u16 status; | |
1716 | struct agg_tx_status *frame_status = tx_resp->u.agg_status; | |
1717 | struct ieee80211_tx_info *info = NULL; | |
1718 | struct ieee80211_hdr *hdr = NULL; | |
1719 | u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); | |
1720 | int i, sh, idx; | |
1721 | u16 seq; | |
1722 | if (agg->wait_for_ba) | |
58de00a4 | 1723 | D_TX_REPLY("got tx response w/o block-ack\n"); |
4bc85c13 WYG |
1724 | |
1725 | agg->frame_count = tx_resp->frame_count; | |
1726 | agg->start_idx = start_idx; | |
1727 | agg->rate_n_flags = rate_n_flags; | |
1728 | agg->bitmap = 0; | |
1729 | ||
1730 | /* num frames attempted by Tx command */ | |
1731 | if (agg->frame_count == 1) { | |
1732 | /* Only one frame was attempted; no block-ack will arrive */ | |
1733 | status = le16_to_cpu(frame_status[0].status); | |
1734 | idx = start_idx; | |
1735 | ||
58de00a4 | 1736 | D_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
4bc85c13 WYG |
1737 | agg->frame_count, agg->start_idx, idx); |
1738 | ||
46bc8d4b | 1739 | info = IEEE80211_SKB_CB(il->txq[txq_id].txb[idx].skb); |
4bc85c13 WYG |
1740 | info->status.rates[0].count = tx_resp->failure_frame + 1; |
1741 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; | |
e2ebc833 | 1742 | info->flags |= il4965_tx_status_to_mac80211(status); |
46bc8d4b | 1743 | il4965_hwrate_to_tx_control(il, rate_n_flags, info); |
4bc85c13 | 1744 | |
58de00a4 | 1745 | D_TX_REPLY("1 Frame 0x%x failure :%d\n", |
4bc85c13 | 1746 | status & 0xff, tx_resp->failure_frame); |
58de00a4 | 1747 | D_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags); |
4bc85c13 WYG |
1748 | |
1749 | agg->wait_for_ba = 0; | |
1750 | } else { | |
1751 | /* Two or more frames were attempted; expect block-ack */ | |
1752 | u64 bitmap = 0; | |
1753 | int start = agg->start_idx; | |
1754 | ||
6ce1dc45 | 1755 | /* Construct bit-map of pending frames within Tx win */ |
4bc85c13 WYG |
1756 | for (i = 0; i < agg->frame_count; i++) { |
1757 | u16 sc; | |
1758 | status = le16_to_cpu(frame_status[i].status); | |
1759 | seq = le16_to_cpu(frame_status[i].sequence); | |
2d09b062 | 1760 | idx = SEQ_TO_IDX(seq); |
4bc85c13 WYG |
1761 | txq_id = SEQ_TO_QUEUE(seq); |
1762 | ||
1763 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | | |
1764 | AGG_TX_STATE_ABORT_MSK)) | |
1765 | continue; | |
1766 | ||
58de00a4 | 1767 | D_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
4bc85c13 WYG |
1768 | agg->frame_count, txq_id, idx); |
1769 | ||
46bc8d4b | 1770 | hdr = il_tx_queue_get_hdr(il, txq_id, idx); |
4bc85c13 | 1771 | if (!hdr) { |
9406f797 | 1772 | IL_ERR( |
4bc85c13 WYG |
1773 | "BUG_ON idx doesn't point to valid skb" |
1774 | " idx=%d, txq_id=%d\n", idx, txq_id); | |
1775 | return -1; | |
1776 | } | |
1777 | ||
1778 | sc = le16_to_cpu(hdr->seq_ctrl); | |
1779 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { | |
9406f797 | 1780 | IL_ERR( |
4bc85c13 WYG |
1781 | "BUG_ON idx doesn't match seq control" |
1782 | " idx=%d, seq_idx=%d, seq=%d\n", | |
1783 | idx, SEQ_TO_SN(sc), hdr->seq_ctrl); | |
1784 | return -1; | |
1785 | } | |
1786 | ||
58de00a4 | 1787 | D_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
4bc85c13 WYG |
1788 | i, idx, SEQ_TO_SN(sc)); |
1789 | ||
1790 | sh = idx - start; | |
1791 | if (sh > 64) { | |
1792 | sh = (start - idx) + 0xff; | |
1793 | bitmap = bitmap << sh; | |
1794 | sh = 0; | |
1795 | start = idx; | |
1796 | } else if (sh < -64) | |
1797 | sh = 0xff - (start - idx); | |
1798 | else if (sh < 0) { | |
1799 | sh = start - idx; | |
1800 | start = idx; | |
1801 | bitmap = bitmap << sh; | |
1802 | sh = 0; | |
1803 | } | |
1804 | bitmap |= 1ULL << sh; | |
58de00a4 | 1805 | D_TX_REPLY("start=%d bitmap=0x%llx\n", |
4bc85c13 WYG |
1806 | start, (unsigned long long)bitmap); |
1807 | } | |
1808 | ||
1809 | agg->bitmap = bitmap; | |
1810 | agg->start_idx = start; | |
58de00a4 | 1811 | D_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n", |
4bc85c13 WYG |
1812 | agg->frame_count, agg->start_idx, |
1813 | (unsigned long long)agg->bitmap); | |
1814 | ||
1815 | if (bitmap) | |
1816 | agg->wait_for_ba = 1; | |
1817 | } | |
1818 | return 0; | |
1819 | } | |
1820 | ||
46bc8d4b | 1821 | static u8 il4965_find_station(struct il_priv *il, const u8 *addr) |
4bc85c13 WYG |
1822 | { |
1823 | int i; | |
1824 | int start = 0; | |
e2ebc833 | 1825 | int ret = IL_INVALID_STATION; |
4bc85c13 WYG |
1826 | unsigned long flags; |
1827 | ||
46bc8d4b | 1828 | if ((il->iw_mode == NL80211_IFTYPE_ADHOC)) |
e2ebc833 | 1829 | start = IL_STA_ID; |
4bc85c13 WYG |
1830 | |
1831 | if (is_broadcast_ether_addr(addr)) | |
7c2cde2e | 1832 | return il->ctx.bcast_sta_id; |
4bc85c13 | 1833 | |
46bc8d4b SG |
1834 | spin_lock_irqsave(&il->sta_lock, flags); |
1835 | for (i = start; i < il->hw_params.max_stations; i++) | |
1836 | if (il->stations[i].used && | |
1837 | (!compare_ether_addr(il->stations[i].sta.sta.addr, | |
4bc85c13 WYG |
1838 | addr))) { |
1839 | ret = i; | |
1840 | goto out; | |
1841 | } | |
1842 | ||
58de00a4 | 1843 | D_ASSOC("can not find STA %pM total %d\n", |
46bc8d4b | 1844 | addr, il->num_stations); |
4bc85c13 WYG |
1845 | |
1846 | out: | |
1847 | /* | |
1848 | * It may be possible that more commands interacting with stations | |
1849 | * arrive before we completed processing the adding of | |
1850 | * station | |
1851 | */ | |
e2ebc833 | 1852 | if (ret != IL_INVALID_STATION && |
46bc8d4b SG |
1853 | (!(il->stations[ret].used & IL_STA_UCODE_ACTIVE) || |
1854 | ((il->stations[ret].used & IL_STA_UCODE_ACTIVE) && | |
1855 | (il->stations[ret].used & IL_STA_UCODE_INPROGRESS)))) { | |
9406f797 | 1856 | IL_ERR("Requested station info for sta %d before ready.\n", |
4bc85c13 | 1857 | ret); |
e2ebc833 | 1858 | ret = IL_INVALID_STATION; |
4bc85c13 | 1859 | } |
46bc8d4b | 1860 | spin_unlock_irqrestore(&il->sta_lock, flags); |
4bc85c13 WYG |
1861 | return ret; |
1862 | } | |
1863 | ||
46bc8d4b | 1864 | static int il4965_get_ra_sta_id(struct il_priv *il, struct ieee80211_hdr *hdr) |
4bc85c13 | 1865 | { |
46bc8d4b | 1866 | if (il->iw_mode == NL80211_IFTYPE_STATION) { |
e2ebc833 | 1867 | return IL_AP_ID; |
4bc85c13 WYG |
1868 | } else { |
1869 | u8 *da = ieee80211_get_DA(hdr); | |
46bc8d4b | 1870 | return il4965_find_station(il, da); |
4bc85c13 WYG |
1871 | } |
1872 | } | |
1873 | ||
1874 | /** | |
e2ebc833 | 1875 | * il4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
4bc85c13 | 1876 | */ |
46bc8d4b | 1877 | static void il4965_rx_reply_tx(struct il_priv *il, |
b73bb5f1 | 1878 | struct il_rx_buf *rxb) |
4bc85c13 | 1879 | { |
dcae1c64 | 1880 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
4bc85c13 WYG |
1881 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
1882 | int txq_id = SEQ_TO_QUEUE(sequence); | |
0c2c8852 | 1883 | int idx = SEQ_TO_IDX(sequence); |
46bc8d4b | 1884 | struct il_tx_queue *txq = &il->txq[txq_id]; |
4bc85c13 WYG |
1885 | struct ieee80211_hdr *hdr; |
1886 | struct ieee80211_tx_info *info; | |
e2ebc833 | 1887 | struct il4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
4bc85c13 WYG |
1888 | u32 status = le32_to_cpu(tx_resp->u.status); |
1889 | int uninitialized_var(tid); | |
1890 | int sta_id; | |
1891 | int freed; | |
1892 | u8 *qc = NULL; | |
1893 | unsigned long flags; | |
1894 | ||
0c2c8852 SG |
1895 | if (idx >= txq->q.n_bd || il_queue_used(&txq->q, idx) == 0) { |
1896 | IL_ERR("Read idx for DMA queue txq_id (%d) idx %d " | |
4bc85c13 | 1897 | "is out of range [0-%d] %d %d\n", txq_id, |
0c2c8852 | 1898 | idx, txq->q.n_bd, txq->q.write_ptr, |
4bc85c13 WYG |
1899 | txq->q.read_ptr); |
1900 | return; | |
1901 | } | |
1902 | ||
1903 | txq->time_stamp = jiffies; | |
1904 | info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb); | |
1905 | memset(&info->status, 0, sizeof(info->status)); | |
1906 | ||
0c2c8852 | 1907 | hdr = il_tx_queue_get_hdr(il, txq_id, idx); |
4bc85c13 WYG |
1908 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
1909 | qc = ieee80211_get_qos_ctl(hdr); | |
1910 | tid = qc[0] & 0xf; | |
1911 | } | |
1912 | ||
46bc8d4b | 1913 | sta_id = il4965_get_ra_sta_id(il, hdr); |
e2ebc833 | 1914 | if (txq->sched_retry && unlikely(sta_id == IL_INVALID_STATION)) { |
9406f797 | 1915 | IL_ERR("Station not known\n"); |
4bc85c13 WYG |
1916 | return; |
1917 | } | |
1918 | ||
46bc8d4b | 1919 | spin_lock_irqsave(&il->sta_lock, flags); |
4bc85c13 | 1920 | if (txq->sched_retry) { |
e2ebc833 SG |
1921 | const u32 scd_ssn = il4965_get_scd_ssn(tx_resp); |
1922 | struct il_ht_agg *agg = NULL; | |
4bc85c13 WYG |
1923 | WARN_ON(!qc); |
1924 | ||
46bc8d4b | 1925 | agg = &il->stations[sta_id].tid[tid].agg; |
4bc85c13 | 1926 | |
0c2c8852 | 1927 | il4965_tx_status_reply_tx(il, agg, tx_resp, txq_id, idx); |
4bc85c13 WYG |
1928 | |
1929 | /* check if BAR is needed */ | |
e2ebc833 | 1930 | if ((tx_resp->frame_count == 1) && !il4965_is_tx_success(status)) |
4bc85c13 WYG |
1931 | info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; |
1932 | ||
1933 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { | |
0c2c8852 | 1934 | idx = il_queue_dec_wrap(scd_ssn & 0xff, |
be663ab6 | 1935 | txq->q.n_bd); |
58de00a4 | 1936 | D_TX_REPLY("Retry scheduler reclaim scd_ssn " |
0c2c8852 SG |
1937 | "%d idx %d\n", scd_ssn , idx); |
1938 | freed = il4965_tx_queue_reclaim(il, txq_id, idx); | |
4bc85c13 | 1939 | if (qc) |
46bc8d4b | 1940 | il4965_free_tfds_in_queue(il, sta_id, |
4bc85c13 WYG |
1941 | tid, freed); |
1942 | ||
46bc8d4b | 1943 | if (il->mac80211_registered && |
232913b5 SG |
1944 | il_queue_space(&txq->q) > txq->q.low_mark && |
1945 | agg->state != IL_EMPTYING_HW_QUEUE_DELBA) | |
46bc8d4b | 1946 | il_wake_queue(il, txq); |
4bc85c13 WYG |
1947 | } |
1948 | } else { | |
1949 | info->status.rates[0].count = tx_resp->failure_frame + 1; | |
e2ebc833 | 1950 | info->flags |= il4965_tx_status_to_mac80211(status); |
46bc8d4b | 1951 | il4965_hwrate_to_tx_control(il, |
4bc85c13 WYG |
1952 | le32_to_cpu(tx_resp->rate_n_flags), |
1953 | info); | |
1954 | ||
58de00a4 | 1955 | D_TX_REPLY("TXQ %d status %s (0x%08x) " |
4bc85c13 WYG |
1956 | "rate_n_flags 0x%x retries %d\n", |
1957 | txq_id, | |
e2ebc833 | 1958 | il4965_get_tx_fail_reason(status), status, |
4bc85c13 WYG |
1959 | le32_to_cpu(tx_resp->rate_n_flags), |
1960 | tx_resp->failure_frame); | |
1961 | ||
0c2c8852 | 1962 | freed = il4965_tx_queue_reclaim(il, txq_id, idx); |
e2ebc833 | 1963 | if (qc && likely(sta_id != IL_INVALID_STATION)) |
46bc8d4b | 1964 | il4965_free_tfds_in_queue(il, sta_id, tid, freed); |
e2ebc833 | 1965 | else if (sta_id == IL_INVALID_STATION) |
58de00a4 | 1966 | D_TX_REPLY("Station not known\n"); |
4bc85c13 | 1967 | |
46bc8d4b | 1968 | if (il->mac80211_registered && |
232913b5 | 1969 | il_queue_space(&txq->q) > txq->q.low_mark) |
46bc8d4b | 1970 | il_wake_queue(il, txq); |
4bc85c13 | 1971 | } |
e2ebc833 | 1972 | if (qc && likely(sta_id != IL_INVALID_STATION)) |
46bc8d4b | 1973 | il4965_txq_check_empty(il, sta_id, tid, txq_id); |
4bc85c13 | 1974 | |
46bc8d4b | 1975 | il4965_check_abort_status(il, tx_resp->frame_count, status); |
4bc85c13 | 1976 | |
46bc8d4b | 1977 | spin_unlock_irqrestore(&il->sta_lock, flags); |
4bc85c13 WYG |
1978 | } |
1979 | ||
46bc8d4b | 1980 | static void il4965_rx_beacon_notif(struct il_priv *il, |
b73bb5f1 | 1981 | struct il_rx_buf *rxb) |
4bc85c13 | 1982 | { |
dcae1c64 | 1983 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
e2ebc833 | 1984 | struct il4965_beacon_notif *beacon = (void *)pkt->u.raw; |
be663ab6 | 1985 | u8 rate __maybe_unused = |
e2ebc833 | 1986 | il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
4bc85c13 | 1987 | |
58de00a4 | 1988 | D_RX("beacon status %#x, retries:%d ibssmgr:%d " |
4bc85c13 WYG |
1989 | "tsf:0x%.8x%.8x rate:%d\n", |
1990 | le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK, | |
1991 | beacon->beacon_notify_hdr.failure_frame, | |
1992 | le32_to_cpu(beacon->ibss_mgr_status), | |
1993 | le32_to_cpu(beacon->high_tsf), | |
1994 | le32_to_cpu(beacon->low_tsf), rate); | |
4bc85c13 | 1995 | |
46bc8d4b | 1996 | il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); |
4bc85c13 WYG |
1997 | } |
1998 | ||
4bc85c13 | 1999 | /* Set up 4965-specific Rx frame reply handlers */ |
46bc8d4b | 2000 | static void il4965_rx_handler_setup(struct il_priv *il) |
4bc85c13 WYG |
2001 | { |
2002 | /* Legacy Rx frames */ | |
46bc8d4b | 2003 | il->rx_handlers[REPLY_RX] = il4965_rx_reply_rx; |
4bc85c13 | 2004 | /* Tx response */ |
46bc8d4b SG |
2005 | il->rx_handlers[REPLY_TX] = il4965_rx_reply_tx; |
2006 | il->rx_handlers[BEACON_NOTIFICATION] = il4965_rx_beacon_notif; | |
4bc85c13 WYG |
2007 | } |
2008 | ||
e2ebc833 SG |
2009 | static struct il_hcmd_ops il4965_hcmd = { |
2010 | .rxon_assoc = il4965_send_rxon_assoc, | |
2011 | .commit_rxon = il4965_commit_rxon, | |
2012 | .set_rxon_chain = il4965_set_rxon_chain, | |
4bc85c13 WYG |
2013 | }; |
2014 | ||
46bc8d4b | 2015 | static void il4965_post_scan(struct il_priv *il) |
4bc85c13 | 2016 | { |
7c2cde2e | 2017 | struct il_rxon_context *ctx = &il->ctx; |
4bc85c13 WYG |
2018 | |
2019 | /* | |
2020 | * Since setting the RXON may have been deferred while | |
2021 | * performing the scan, fire one off if needed | |
2022 | */ | |
2023 | if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) | |
46bc8d4b | 2024 | il_commit_rxon(il, ctx); |
4bc85c13 WYG |
2025 | } |
2026 | ||
46bc8d4b | 2027 | static void il4965_post_associate(struct il_priv *il) |
4bc85c13 | 2028 | { |
7c2cde2e | 2029 | struct il_rxon_context *ctx = &il->ctx; |
4bc85c13 WYG |
2030 | struct ieee80211_vif *vif = ctx->vif; |
2031 | struct ieee80211_conf *conf = NULL; | |
2032 | int ret = 0; | |
2033 | ||
46bc8d4b | 2034 | if (!vif || !il->is_open) |
4bc85c13 WYG |
2035 | return; |
2036 | ||
46bc8d4b | 2037 | if (test_bit(STATUS_EXIT_PENDING, &il->status)) |
4bc85c13 WYG |
2038 | return; |
2039 | ||
46bc8d4b | 2040 | il_scan_cancel_timeout(il, 200); |
4bc85c13 | 2041 | |
46bc8d4b | 2042 | conf = il_ieee80211_get_hw_conf(il->hw); |
4bc85c13 WYG |
2043 | |
2044 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
46bc8d4b | 2045 | il_commit_rxon(il, ctx); |
4bc85c13 | 2046 | |
46bc8d4b | 2047 | ret = il_send_rxon_timing(il, ctx); |
4bc85c13 | 2048 | if (ret) |
9406f797 | 2049 | IL_WARN("RXON timing - " |
4bc85c13 WYG |
2050 | "Attempting to continue.\n"); |
2051 | ||
2052 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; | |
2053 | ||
46bc8d4b | 2054 | il_set_rxon_ht(il, &il->current_ht_config); |
4bc85c13 | 2055 | |
46bc8d4b SG |
2056 | if (il->cfg->ops->hcmd->set_rxon_chain) |
2057 | il->cfg->ops->hcmd->set_rxon_chain(il, ctx); | |
4bc85c13 WYG |
2058 | |
2059 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); | |
2060 | ||
58de00a4 | 2061 | D_ASSOC("assoc id %d beacon interval %d\n", |
4bc85c13 WYG |
2062 | vif->bss_conf.aid, vif->bss_conf.beacon_int); |
2063 | ||
2064 | if (vif->bss_conf.use_short_preamble) | |
2065 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; | |
2066 | else | |
2067 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
2068 | ||
2069 | if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) { | |
2070 | if (vif->bss_conf.use_short_slot) | |
2071 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; | |
2072 | else | |
2073 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | |
2074 | } | |
2075 | ||
46bc8d4b | 2076 | il_commit_rxon(il, ctx); |
4bc85c13 | 2077 | |
58de00a4 | 2078 | D_ASSOC("Associated as %d to: %pM\n", |
4bc85c13 WYG |
2079 | vif->bss_conf.aid, ctx->active.bssid_addr); |
2080 | ||
2081 | switch (vif->type) { | |
2082 | case NL80211_IFTYPE_STATION: | |
2083 | break; | |
2084 | case NL80211_IFTYPE_ADHOC: | |
46bc8d4b | 2085 | il4965_send_beacon_cmd(il); |
4bc85c13 WYG |
2086 | break; |
2087 | default: | |
9406f797 | 2088 | IL_ERR("%s Should not be called in %d mode\n", |
4bc85c13 WYG |
2089 | __func__, vif->type); |
2090 | break; | |
2091 | } | |
2092 | ||
2093 | /* the chain noise calibration will enabled PM upon completion | |
2094 | * If chain noise has already been run, then we need to enable | |
2095 | * power management here */ | |
46bc8d4b SG |
2096 | if (il->chain_noise_data.state == IL_CHAIN_NOISE_DONE) |
2097 | il_power_update_mode(il, false); | |
4bc85c13 WYG |
2098 | |
2099 | /* Enable Rx differential gain and sensitivity calibrations */ | |
46bc8d4b SG |
2100 | il4965_chain_noise_reset(il); |
2101 | il->start_calib = 1; | |
4bc85c13 WYG |
2102 | } |
2103 | ||
46bc8d4b | 2104 | static void il4965_config_ap(struct il_priv *il) |
4bc85c13 | 2105 | { |
7c2cde2e | 2106 | struct il_rxon_context *ctx = &il->ctx; |
4bc85c13 WYG |
2107 | struct ieee80211_vif *vif = ctx->vif; |
2108 | int ret = 0; | |
2109 | ||
46bc8d4b | 2110 | lockdep_assert_held(&il->mutex); |
4bc85c13 | 2111 | |
46bc8d4b | 2112 | if (test_bit(STATUS_EXIT_PENDING, &il->status)) |
4bc85c13 WYG |
2113 | return; |
2114 | ||
2115 | /* The following should be done only at AP bring up */ | |
e2ebc833 | 2116 | if (!il_is_associated_ctx(ctx)) { |
4bc85c13 WYG |
2117 | |
2118 | /* RXON - unassoc (to set timing command) */ | |
2119 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
46bc8d4b | 2120 | il_commit_rxon(il, ctx); |
4bc85c13 WYG |
2121 | |
2122 | /* RXON Timing */ | |
46bc8d4b | 2123 | ret = il_send_rxon_timing(il, ctx); |
4bc85c13 | 2124 | if (ret) |
9406f797 | 2125 | IL_WARN("RXON timing failed - " |
4bc85c13 WYG |
2126 | "Attempting to continue.\n"); |
2127 | ||
2128 | /* AP has all antennas */ | |
46bc8d4b SG |
2129 | il->chain_noise_data.active_chains = |
2130 | il->hw_params.valid_rx_ant; | |
2131 | il_set_rxon_ht(il, &il->current_ht_config); | |
2132 | if (il->cfg->ops->hcmd->set_rxon_chain) | |
2133 | il->cfg->ops->hcmd->set_rxon_chain(il, ctx); | |
4bc85c13 WYG |
2134 | |
2135 | ctx->staging.assoc_id = 0; | |
2136 | ||
2137 | if (vif->bss_conf.use_short_preamble) | |
2138 | ctx->staging.flags |= | |
2139 | RXON_FLG_SHORT_PREAMBLE_MSK; | |
2140 | else | |
2141 | ctx->staging.flags &= | |
2142 | ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
2143 | ||
2144 | if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) { | |
2145 | if (vif->bss_conf.use_short_slot) | |
2146 | ctx->staging.flags |= | |
2147 | RXON_FLG_SHORT_SLOT_MSK; | |
2148 | else | |
2149 | ctx->staging.flags &= | |
2150 | ~RXON_FLG_SHORT_SLOT_MSK; | |
2151 | } | |
2152 | /* need to send beacon cmd before committing assoc RXON! */ | |
46bc8d4b | 2153 | il4965_send_beacon_cmd(il); |
4bc85c13 WYG |
2154 | /* restore RXON assoc */ |
2155 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; | |
46bc8d4b | 2156 | il_commit_rxon(il, ctx); |
4bc85c13 | 2157 | } |
46bc8d4b | 2158 | il4965_send_beacon_cmd(il); |
4bc85c13 WYG |
2159 | } |
2160 | ||
e2ebc833 SG |
2161 | static struct il_hcmd_utils_ops il4965_hcmd_utils = { |
2162 | .get_hcmd_size = il4965_get_hcmd_size, | |
2163 | .build_addsta_hcmd = il4965_build_addsta_hcmd, | |
2164 | .request_scan = il4965_request_scan, | |
2165 | .post_scan = il4965_post_scan, | |
4bc85c13 WYG |
2166 | }; |
2167 | ||
e2ebc833 SG |
2168 | static struct il_lib_ops il4965_lib = { |
2169 | .set_hw_params = il4965_hw_set_hw_params, | |
2170 | .txq_update_byte_cnt_tbl = il4965_txq_update_byte_cnt_tbl, | |
2171 | .txq_attach_buf_to_tfd = il4965_hw_txq_attach_buf_to_tfd, | |
2172 | .txq_free_tfd = il4965_hw_txq_free_tfd, | |
2173 | .txq_init = il4965_hw_tx_queue_init, | |
2174 | .rx_handler_setup = il4965_rx_handler_setup, | |
2175 | .is_valid_rtc_data_addr = il4965_hw_valid_rtc_data_addr, | |
2176 | .init_alive_start = il4965_init_alive_start, | |
2177 | .load_ucode = il4965_load_bsm, | |
2178 | .dump_nic_error_log = il4965_dump_nic_error_log, | |
2179 | .dump_fh = il4965_dump_fh, | |
2180 | .set_channel_switch = il4965_hw_channel_switch, | |
4bc85c13 | 2181 | .apm_ops = { |
e2ebc833 SG |
2182 | .init = il_apm_init, |
2183 | .config = il4965_nic_config, | |
4bc85c13 WYG |
2184 | }, |
2185 | .eeprom_ops = { | |
2186 | .regulatory_bands = { | |
2187 | EEPROM_REGULATORY_BAND_1_CHANNELS, | |
2188 | EEPROM_REGULATORY_BAND_2_CHANNELS, | |
2189 | EEPROM_REGULATORY_BAND_3_CHANNELS, | |
2190 | EEPROM_REGULATORY_BAND_4_CHANNELS, | |
2191 | EEPROM_REGULATORY_BAND_5_CHANNELS, | |
2192 | EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS, | |
2193 | EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS | |
2194 | }, | |
e2ebc833 SG |
2195 | .acquire_semaphore = il4965_eeprom_acquire_semaphore, |
2196 | .release_semaphore = il4965_eeprom_release_semaphore, | |
4bc85c13 | 2197 | }, |
e2ebc833 SG |
2198 | .send_tx_power = il4965_send_tx_power, |
2199 | .update_chain_flags = il4965_update_chain_flags, | |
4bc85c13 | 2200 | .temp_ops = { |
e2ebc833 | 2201 | .temperature = il4965_temperature_calib, |
4bc85c13 WYG |
2202 | }, |
2203 | .debugfs_ops = { | |
e2ebc833 SG |
2204 | .rx_stats_read = il4965_ucode_rx_stats_read, |
2205 | .tx_stats_read = il4965_ucode_tx_stats_read, | |
2206 | .general_stats_read = il4965_ucode_general_stats_read, | |
4bc85c13 | 2207 | }, |
4bc85c13 WYG |
2208 | }; |
2209 | ||
e2ebc833 SG |
2210 | static const struct il_legacy_ops il4965_legacy_ops = { |
2211 | .post_associate = il4965_post_associate, | |
2212 | .config_ap = il4965_config_ap, | |
2213 | .manage_ibss_station = il4965_manage_ibss_station, | |
2214 | .update_bcast_stations = il4965_update_bcast_stations, | |
4bc85c13 WYG |
2215 | }; |
2216 | ||
e2ebc833 SG |
2217 | struct ieee80211_ops il4965_hw_ops = { |
2218 | .tx = il4965_mac_tx, | |
2219 | .start = il4965_mac_start, | |
2220 | .stop = il4965_mac_stop, | |
2221 | .add_interface = il_mac_add_interface, | |
2222 | .remove_interface = il_mac_remove_interface, | |
2223 | .change_interface = il_mac_change_interface, | |
2224 | .config = il_mac_config, | |
2225 | .configure_filter = il4965_configure_filter, | |
2226 | .set_key = il4965_mac_set_key, | |
2227 | .update_tkip_key = il4965_mac_update_tkip_key, | |
2228 | .conf_tx = il_mac_conf_tx, | |
2229 | .reset_tsf = il_mac_reset_tsf, | |
2230 | .bss_info_changed = il_mac_bss_info_changed, | |
2231 | .ampdu_action = il4965_mac_ampdu_action, | |
2232 | .hw_scan = il_mac_hw_scan, | |
2233 | .sta_add = il4965_mac_sta_add, | |
2234 | .sta_remove = il_mac_sta_remove, | |
2235 | .channel_switch = il4965_mac_channel_switch, | |
2236 | .tx_last_beacon = il_mac_tx_last_beacon, | |
4bc85c13 WYG |
2237 | }; |
2238 | ||
e2ebc833 SG |
2239 | static const struct il_ops il4965_ops = { |
2240 | .lib = &il4965_lib, | |
2241 | .hcmd = &il4965_hcmd, | |
2242 | .utils = &il4965_hcmd_utils, | |
2243 | .led = &il4965_led_ops, | |
2244 | .legacy = &il4965_legacy_ops, | |
2245 | .ieee80211_ops = &il4965_hw_ops, | |
4bc85c13 WYG |
2246 | }; |
2247 | ||
e2ebc833 | 2248 | static struct il_base_params il4965_base_params = { |
d3175167 SG |
2249 | .eeprom_size = IL4965_EEPROM_IMG_SIZE, |
2250 | .num_of_queues = IL49_NUM_QUEUES, | |
2251 | .num_of_ampdu_queues = IL49_NUM_AMPDU_QUEUES, | |
4bc85c13 WYG |
2252 | .pll_cfg_val = 0, |
2253 | .set_l0s = true, | |
2254 | .use_bsm = true, | |
4bc85c13 | 2255 | .led_compensation = 61, |
d3175167 | 2256 | .chain_noise_num_beacons = IL4965_CAL_NUM_BEACONS, |
e2ebc833 | 2257 | .wd_timeout = IL_DEF_WD_TIMEOUT, |
4bc85c13 | 2258 | .temperature_kelvin = true, |
4bc85c13 WYG |
2259 | .ucode_tracing = true, |
2260 | .sensitivity_calib_by_driver = true, | |
2261 | .chain_noise_calib_by_driver = true, | |
4bc85c13 WYG |
2262 | }; |
2263 | ||
e2ebc833 | 2264 | struct il_cfg il4965_cfg = { |
4bc85c13 | 2265 | .name = "Intel(R) Wireless WiFi Link 4965AGN", |
d3175167 SG |
2266 | .fw_name_pre = IL4965_FW_PRE, |
2267 | .ucode_api_max = IL4965_UCODE_API_MAX, | |
2268 | .ucode_api_min = IL4965_UCODE_API_MIN, | |
e2ebc833 | 2269 | .sku = IL_SKU_A|IL_SKU_G|IL_SKU_N, |
4bc85c13 WYG |
2270 | .valid_tx_ant = ANT_AB, |
2271 | .valid_rx_ant = ANT_ABC, | |
2272 | .eeprom_ver = EEPROM_4965_EEPROM_VERSION, | |
2273 | .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION, | |
e2ebc833 SG |
2274 | .ops = &il4965_ops, |
2275 | .mod_params = &il4965_mod_params, | |
2276 | .base_params = &il4965_base_params, | |
2277 | .led_mode = IL_LED_BLINK, | |
4bc85c13 WYG |
2278 | /* |
2279 | * Force use of chains B and C for scan RX on 5 GHz band | |
2280 | * because the device has off-channel reception on chain A. | |
2281 | */ | |
2282 | .scan_rx_antennas[IEEE80211_BAND_5GHZ] = ANT_BC, | |
2283 | }; | |
2284 | ||
2285 | /* Module firmware */ | |
d3175167 | 2286 | MODULE_FIRMWARE(IL4965_MODULE_FIRMWARE(IL4965_UCODE_API_MAX)); |