blob: b275b1f234a513090f8affb83f798b1be5cbae0a [file] [log] [blame]
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001 /*
2 * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007 Matthew W. S. Bell <mentor@madwifi.org>
5 * Copyright (c) 2007 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
6 * Copyright (c) 2007 Pavel Roskin <proski@gnu.org>
7 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
8 *
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 */
22
23/*
24 * HW related functions for Atheros Wireless LAN devices.
25 */
26
27#include <linux/pci.h>
28#include <linux/delay.h>
29
30#include "reg.h"
31#include "base.h"
32#include "debug.h"
33
34/*Rate tables*/
35static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
36static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
37static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
38static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
39static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
40
41/*Prototypes*/
42static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
43static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
44static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
45 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
46 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
47 unsigned int, unsigned int);
Jiri Slabyb9887632008-02-15 21:58:52 +010048static int ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
Jiri Slabyfa1c1142007-08-12 17:33:16 +020049 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
50 unsigned int);
51static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
52static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
53 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
54 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
55 unsigned int, unsigned int);
56static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
57static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *, struct ath5k_desc *);
58static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *, struct ath5k_desc *);
59static int ath5k_hw_get_capabilities(struct ath5k_hw *);
60
61static int ath5k_eeprom_init(struct ath5k_hw *);
62static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
63
64static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
65static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
66
67/*
68 * Enable to overwrite the country code (use "00" for debug)
69 */
70#if 0
71#define COUNTRYCODE "00"
72#endif
73
74/*******************\
75 General Functions
76\*******************/
77
78/*
79 * Functions used internaly
80 */
81
82static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
83{
84 return turbo == true ? (usec * 80) : (usec * 40);
85}
86
87static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
88{
89 return turbo == true ? (clock / 80) : (clock / 40);
90}
91
92/*
93 * Check if a register write has been completed
94 */
95int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
96 bool is_set)
97{
98 int i;
99 u32 data;
100
101 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
102 data = ath5k_hw_reg_read(ah, reg);
103 if ((is_set == true) && (data & flag))
104 break;
105 else if ((data & flag) == val)
106 break;
107 udelay(15);
108 }
109
110 return (i <= 0) ? -EAGAIN : 0;
111}
112
113
114/***************************************\
115 Attach/Detach Functions
116\***************************************/
117
118/*
119 * Check if the device is supported and initialize the needed structs
120 */
121struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
122{
123 struct ath5k_hw *ah;
124 u8 mac[ETH_ALEN];
125 int ret;
126 u32 srev;
127
128 /*If we passed the test malloc a ath5k_hw struct*/
129 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
130 if (ah == NULL) {
131 ret = -ENOMEM;
132 ATH5K_ERR(sc, "out of memory\n");
133 goto err;
134 }
135
136 ah->ah_sc = sc;
137 ah->ah_iobase = sc->iobase;
138
139 /*
140 * HW information
141 */
142
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200143 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
144 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
145 ah->ah_turbo = false;
146 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
147 ah->ah_imr = 0;
148 ah->ah_atim_window = 0;
149 ah->ah_aifs = AR5K_TUNE_AIFS;
150 ah->ah_cw_min = AR5K_TUNE_CWMIN;
151 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
152 ah->ah_software_retry = false;
153 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
154
155 /*
156 * Set the mac revision based on the pci id
157 */
158 ah->ah_version = mac_version;
159
160 /*Fill the ath5k_hw struct with the needed functions*/
161 if (ah->ah_version == AR5K_AR5212)
162 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
163 else if (ah->ah_version == AR5K_AR5211)
164 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
165
166 if (ah->ah_version == AR5K_AR5212) {
167 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
168 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
169 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
170 } else {
171 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
172 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
173 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
174 }
175
176 if (ah->ah_version == AR5K_AR5212)
177 ah->ah_proc_rx_desc = ath5k_hw_proc_new_rx_status;
178 else if (ah->ah_version <= AR5K_AR5211)
179 ah->ah_proc_rx_desc = ath5k_hw_proc_old_rx_status;
180
181 /* Bring device out of sleep and reset it's units */
182 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
183 if (ret)
184 goto err_free;
185
186 /* Get MAC, PHY and RADIO revisions */
187 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
188 ah->ah_mac_srev = srev;
189 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
190 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
191 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
192 0xffffffff;
193 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
194 CHANNEL_5GHZ);
195
196 if (ah->ah_version == AR5K_AR5210)
197 ah->ah_radio_2ghz_revision = 0;
198 else
199 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
200 CHANNEL_2GHZ);
201
202 /* Return on unsuported chips (unsupported eeprom etc) */
203 if(srev >= AR5K_SREV_VER_AR5416){
204 ATH5K_ERR(sc, "Device not yet supported.\n");
205 ret = -ENODEV;
206 goto err_free;
207 }
208
209 /* Identify single chip solutions */
210 if((srev <= AR5K_SREV_VER_AR5414) &&
Nick Kossifidis0af22562008-02-28 14:49:05 -0500211 (srev >= AR5K_SREV_VER_AR2413)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200212 ah->ah_single_chip = true;
213 } else {
214 ah->ah_single_chip = false;
215 }
216
217 /* Single chip radio */
218 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
219 ah->ah_radio_2ghz_revision = 0;
220
221 /* Identify the radio chip*/
222 if (ah->ah_version == AR5K_AR5210) {
223 ah->ah_radio = AR5K_RF5110;
224 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
225 ah->ah_radio = AR5K_RF5111;
Nick Kossifidis0af22562008-02-28 14:49:05 -0500226 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
227 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
228
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200229 ah->ah_radio = AR5K_RF5112;
Nick Kossifidis0af22562008-02-28 14:49:05 -0500230
231 if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
232 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
233 } else {
234 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
235 }
236
237 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
238 ah->ah_radio = AR5K_RF2413;
239 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200240 } else {
Nick Kossifidis0af22562008-02-28 14:49:05 -0500241
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200242 ah->ah_radio = AR5K_RF5413;
Nick Kossifidis0af22562008-02-28 14:49:05 -0500243
244 if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 &&
245 ah->ah_mac_srev >= AR5K_SREV_VER_AR2424)
246 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
247 else if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2425)
248 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
249 else
250 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
251
252
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200253 }
254
255 ah->ah_phy = AR5K_PHY(0);
256
257 /*
258 * Get card capabilities, values, ...
259 */
260
261 ret = ath5k_eeprom_init(ah);
262 if (ret) {
263 ATH5K_ERR(sc, "unable to init EEPROM\n");
264 goto err_free;
265 }
266
267 /* Get misc capabilities */
268 ret = ath5k_hw_get_capabilities(ah);
269 if (ret) {
270 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
271 sc->pdev->device);
272 goto err_free;
273 }
274
275 /* Get MAC address */
276 ret = ath5k_eeprom_read_mac(ah, mac);
277 if (ret) {
278 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
279 sc->pdev->device);
280 goto err_free;
281 }
282
283 ath5k_hw_set_lladdr(ah, mac);
284 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
285 memset(ah->ah_bssid, 0xff, ETH_ALEN);
286 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
287 ath5k_hw_set_opmode(ah);
288
289 ath5k_hw_set_rfgain_opt(ah);
290
291 return ah;
292err_free:
293 kfree(ah);
294err:
295 return ERR_PTR(ret);
296}
297
298/*
299 * Bring up MAC + PHY Chips
300 */
301static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
302{
Nick Kossifidis56c90542008-02-28 16:20:52 -0500303 struct pci_dev *pdev = ah->ah_sc->pdev;
304 u32 turbo, mode, clock, bus_flags;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200305 int ret;
306
307 turbo = 0;
308 mode = 0;
309 clock = 0;
310
311 ATH5K_TRACE(ah->ah_sc);
312
313 /* Wakeup the device */
314 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
315 if (ret) {
316 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
317 return ret;
318 }
319
320 if (ah->ah_version != AR5K_AR5210) {
321 /*
322 * Get channel mode flags
323 */
324
325 if (ah->ah_radio >= AR5K_RF5112) {
326 mode = AR5K_PHY_MODE_RAD_RF5112;
327 clock = AR5K_PHY_PLL_RF5112;
328 } else {
329 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
330 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
331 }
332
333 if (flags & CHANNEL_2GHZ) {
334 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
335 clock |= AR5K_PHY_PLL_44MHZ;
336
337 if (flags & CHANNEL_CCK) {
338 mode |= AR5K_PHY_MODE_MOD_CCK;
339 } else if (flags & CHANNEL_OFDM) {
340 /* XXX Dynamic OFDM/CCK is not supported by the
341 * AR5211 so we set MOD_OFDM for plain g (no
342 * CCK headers) operation. We need to test
343 * this, 5211 might support ofdm-only g after
344 * all, there are also initial register values
345 * in the code for g mode (see initvals.c). */
346 if (ah->ah_version == AR5K_AR5211)
347 mode |= AR5K_PHY_MODE_MOD_OFDM;
348 else
349 mode |= AR5K_PHY_MODE_MOD_DYN;
350 } else {
351 ATH5K_ERR(ah->ah_sc,
352 "invalid radio modulation mode\n");
353 return -EINVAL;
354 }
355 } else if (flags & CHANNEL_5GHZ) {
356 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
357 clock |= AR5K_PHY_PLL_40MHZ;
358
359 if (flags & CHANNEL_OFDM)
360 mode |= AR5K_PHY_MODE_MOD_OFDM;
361 else {
362 ATH5K_ERR(ah->ah_sc,
363 "invalid radio modulation mode\n");
364 return -EINVAL;
365 }
366 } else {
367 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
368 return -EINVAL;
369 }
370
371 if (flags & CHANNEL_TURBO)
372 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
373 } else { /* Reset the device */
374
375 /* ...enable Atheros turbo mode if requested */
376 if (flags & CHANNEL_TURBO)
377 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
378 AR5K_PHY_TURBO);
379 }
380
Nick Kossifidis56c90542008-02-28 16:20:52 -0500381 /* reseting PCI on PCI-E cards results card to hang
382 * and always return 0xffff... so we ingore that flag
383 * for PCI-E cards */
384 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
385
386 /* Reset chipset */
387 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
388 AR5K_RESET_CTL_BASEBAND | bus_flags);
389 if (ret) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200390 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip + PCI\n");
391 return -EIO;
392 }
393
394 if (ah->ah_version == AR5K_AR5210)
395 udelay(2300);
396
397 /* ...wakeup again!*/
398 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
399 if (ret) {
400 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
401 return ret;
402 }
403
404 /* ...final warm reset */
405 if (ath5k_hw_nic_reset(ah, 0)) {
406 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
407 return -EIO;
408 }
409
410 if (ah->ah_version != AR5K_AR5210) {
411 /* ...set the PHY operating mode */
412 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
413 udelay(300);
414
415 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
416 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
417 }
418
419 return 0;
420}
421
422/*
423 * Get the rate table for a specific operation mode
424 */
425const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
426 unsigned int mode)
427{
428 ATH5K_TRACE(ah->ah_sc);
429
430 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
431 return NULL;
432
433 /* Get rate tables */
434 switch (mode) {
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500435 case AR5K_MODE_11A:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200436 return &ath5k_rt_11a;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500437 case AR5K_MODE_11A_TURBO:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200438 return &ath5k_rt_turbo;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500439 case AR5K_MODE_11B:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200440 return &ath5k_rt_11b;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500441 case AR5K_MODE_11G:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200442 return &ath5k_rt_11g;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500443 case AR5K_MODE_11G_TURBO:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200444 return &ath5k_rt_xr;
445 }
446
447 return NULL;
448}
449
450/*
451 * Free the ath5k_hw struct
452 */
453void ath5k_hw_detach(struct ath5k_hw *ah)
454{
455 ATH5K_TRACE(ah->ah_sc);
456
457 if (ah->ah_rf_banks != NULL)
458 kfree(ah->ah_rf_banks);
459
460 /* assume interrupts are down */
461 kfree(ah);
462}
463
464/****************************\
465 Reset function and helpers
466\****************************/
467
468/**
469 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
470 *
471 * @ah: the &struct ath5k_hw
472 * @channel: the currently set channel upon reset
473 *
474 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
475 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
476 * depending on the bandwidth of the channel.
477 *
478 */
479static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
480 struct ieee80211_channel *channel)
481{
482 /* Get exponent and mantissa and set it */
483 u32 coef_scaled, coef_exp, coef_man,
484 ds_coef_exp, ds_coef_man, clock;
485
486 if (!(ah->ah_version == AR5K_AR5212) ||
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500487 !(channel->hw_value & CHANNEL_OFDM))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200488 BUG();
489
490 /* Seems there are two PLLs, one for baseband sampling and one
491 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
492 * turbo. */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500493 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200494 coef_scaled = ((5 * (clock << 24)) / 2) /
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500495 channel->center_freq;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200496
497 for (coef_exp = 31; coef_exp > 0; coef_exp--)
498 if ((coef_scaled >> coef_exp) & 0x1)
499 break;
500
501 if (!coef_exp)
502 return -EINVAL;
503
504 coef_exp = 14 - (coef_exp - 24);
505 coef_man = coef_scaled +
506 (1 << (24 - coef_exp - 1));
507 ds_coef_man = coef_man >> (24 - coef_exp);
508 ds_coef_exp = coef_exp - 16;
509
510 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
511 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
512 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
513 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
514
515 return 0;
516}
517
518/**
519 * ath5k_hw_write_rate_duration - set rate duration during hw resets
520 *
521 * @ah: the &struct ath5k_hw
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500522 * @mode: one of enum ath5k_driver_mode
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200523 *
524 * Write the rate duration table for the current mode upon hw reset. This
525 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
526 * an ACK timeout for the hardware for the current mode for each rate. The
527 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
528 * and 11Mbps) have another register for the short preamble ACK timeout
529 * calculation.
530 *
531 */
532static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500533 unsigned int mode)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200534{
535 struct ath5k_softc *sc = ah->ah_sc;
536 const struct ath5k_rate_table *rt;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500537 struct ieee80211_rate srate = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200538 unsigned int i;
539
540 /* Get rate table for the current operating mode */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500541 rt = ath5k_hw_get_rate_table(ah, mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200542
543 /* Write rate duration table */
544 for (i = 0; i < rt->rate_count; i++) {
545 const struct ath5k_rate *rate, *control_rate;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500546
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200547 u32 reg;
548 u16 tx_time;
549
550 rate = &rt->rates[i];
551 control_rate = &rt->rates[rate->control_rate];
552
553 /* Set ACK timeout */
554 reg = AR5K_RATE_DUR(rate->rate_code);
555
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500556 srate.bitrate = control_rate->rate_kbps/100;
557
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200558 /* An ACK frame consists of 10 bytes. If you add the FCS,
559 * which ieee80211_generic_frame_duration() adds,
560 * its 14 bytes. Note we use the control rate and not the
561 * actual rate for this rate. See mac80211 tx.c
562 * ieee80211_duration() for a brief description of
563 * what rate we should choose to TX ACKs. */
Pavel Roskin38c07b42008-02-26 17:59:14 -0500564 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
565 sc->vif, 10, &srate));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200566
567 ath5k_hw_reg_write(ah, tx_time, reg);
568
569 if (!HAS_SHPREAMBLE(i))
570 continue;
571
572 /*
573 * We're not distinguishing short preamble here,
574 * This is true, all we'll get is a longer value here
575 * which is not necessarilly bad. We could use
576 * export ieee80211_frame_duration() but that needs to be
577 * fixed first to be properly used by mac802111 drivers:
578 *
579 * - remove erp stuff and let the routine figure ofdm
580 * erp rates
581 * - remove passing argument ieee80211_local as
582 * drivers don't have access to it
583 * - move drivers using ieee80211_generic_frame_duration()
584 * to this
585 */
586 ath5k_hw_reg_write(ah, tx_time,
587 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
588 }
589}
590
591/*
592 * Main reset function
593 */
594int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
595 struct ieee80211_channel *channel, bool change_channel)
596{
597 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
Nick Kossifidis56c90542008-02-28 16:20:52 -0500598 struct pci_dev *pdev = ah->ah_sc->pdev;
599 u32 data, s_seq, s_ant, s_led[3], dma_size;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500600 unsigned int i, mode, freq, ee_mode, ant[2];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200601 int ret;
602
603 ATH5K_TRACE(ah->ah_sc);
604
605 s_seq = 0;
606 s_ant = 0;
607 ee_mode = 0;
608 freq = 0;
609 mode = 0;
610
611 /*
612 * Save some registers before a reset
613 */
614 /*DCU/Antenna selection not available on 5210*/
615 if (ah->ah_version != AR5K_AR5210) {
616 if (change_channel == true) {
617 /* Seq number for queue 0 -do this for all queues ? */
618 s_seq = ath5k_hw_reg_read(ah,
619 AR5K_QUEUE_DFS_SEQNUM(0));
620 /*Default antenna*/
621 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
622 }
623 }
624
625 /*GPIOs*/
626 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
627 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
628 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
629
630 if (change_channel == true && ah->ah_rf_banks != NULL)
631 ath5k_hw_get_rf_gain(ah);
632
633
634 /*Wakeup the device*/
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500635 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200636 if (ret)
637 return ret;
638
639 /*
640 * Initialize operating mode
641 */
642 ah->ah_op_mode = op_mode;
643
644 /*
645 * 5111/5112 Settings
646 * 5210 only comes with RF5110
647 */
648 if (ah->ah_version != AR5K_AR5210) {
649 if (ah->ah_radio != AR5K_RF5111 &&
650 ah->ah_radio != AR5K_RF5112 &&
Nick Kossifidis903b4742008-02-28 14:50:50 -0500651 ah->ah_radio != AR5K_RF5413 &&
652 ah->ah_radio != AR5K_RF2413) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200653 ATH5K_ERR(ah->ah_sc,
654 "invalid phy radio: %u\n", ah->ah_radio);
655 return -EINVAL;
656 }
657
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500658 switch (channel->hw_value & CHANNEL_MODES) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200659 case CHANNEL_A:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500660 mode = AR5K_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200661 freq = AR5K_INI_RFGAIN_5GHZ;
662 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200663 break;
664 case CHANNEL_G:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500665 mode = AR5K_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200666 freq = AR5K_INI_RFGAIN_2GHZ;
667 ee_mode = AR5K_EEPROM_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200668 break;
669 case CHANNEL_B:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500670 mode = AR5K_MODE_11B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200671 freq = AR5K_INI_RFGAIN_2GHZ;
672 ee_mode = AR5K_EEPROM_MODE_11B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200673 break;
674 case CHANNEL_T:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500675 mode = AR5K_MODE_11A_TURBO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200676 freq = AR5K_INI_RFGAIN_5GHZ;
677 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200678 break;
679 /*Is this ok on 5211 too ?*/
680 case CHANNEL_TG:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500681 mode = AR5K_MODE_11G_TURBO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200682 freq = AR5K_INI_RFGAIN_2GHZ;
683 ee_mode = AR5K_EEPROM_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200684 break;
685 case CHANNEL_XR:
686 if (ah->ah_version == AR5K_AR5211) {
687 ATH5K_ERR(ah->ah_sc,
688 "XR mode not available on 5211");
689 return -EINVAL;
690 }
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500691 mode = AR5K_MODE_XR;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200692 freq = AR5K_INI_RFGAIN_5GHZ;
693 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200694 break;
695 default:
696 ATH5K_ERR(ah->ah_sc,
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500697 "invalid channel: %d\n", channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200698 return -EINVAL;
699 }
700
701 /* PHY access enable */
702 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
703
704 }
705
706 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
707 if (ret)
708 return ret;
709
710 /*
711 * 5211/5212 Specific
712 */
713 if (ah->ah_version != AR5K_AR5210) {
714 /*
715 * Write initial RF gain settings
716 * This should work for both 5111/5112
717 */
718 ret = ath5k_hw_rfgain(ah, freq);
719 if (ret)
720 return ret;
721
722 mdelay(1);
723
724 /*
725 * Write some more initial register settings
726 */
727 if (ah->ah_version > AR5K_AR5211){ /* found on 5213+ */
728 ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
729
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500730 if (channel->hw_value == CHANNEL_G)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200731 ath5k_hw_reg_write(ah, 0x00f80d80, AR5K_PHY(83)); /* 0x00fc0ec0 */
732 else
733 ath5k_hw_reg_write(ah, 0x00000000, AR5K_PHY(83));
734
735 ath5k_hw_reg_write(ah, 0x000001b5, 0xa228); /* 0x000009b5 */
736 ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
737 ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
738 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
739 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
740 }
741
742 /* Fix for first revision of the RF5112 RF chipset */
743 if (ah->ah_radio >= AR5K_RF5112 &&
744 ah->ah_radio_5ghz_revision <
745 AR5K_SREV_RAD_5112A) {
746 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
747 AR5K_PHY_CCKTXCTL);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500748 if (channel->hw_value & CHANNEL_5GHZ)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200749 data = 0xffb81020;
750 else
751 data = 0xffb80d20;
752 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
753 }
754
755 /*
756 * Set TX power (FIXME)
757 */
758 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
759 if (ret)
760 return ret;
761
Luis R. Rodriguez132127e2008-01-04 02:21:05 -0500762 /* Write rate duration table only on AR5212 and if
763 * virtual interface has already been brought up
764 * XXX: rethink this after new mode changes to
765 * mac80211 are integrated */
766 if (ah->ah_version == AR5K_AR5212 &&
767 ah->ah_sc->vif != NULL)
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500768 ath5k_hw_write_rate_duration(ah, mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200769
770 /*
771 * Write RF registers
772 * TODO:Does this work on 5211 (5111) ?
773 */
774 ret = ath5k_hw_rfregs(ah, channel, mode);
775 if (ret)
776 return ret;
777
778 /*
779 * Configure additional registers
780 */
781
782 /* Write OFDM timings on 5212*/
783 if (ah->ah_version == AR5K_AR5212 &&
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500784 channel->hw_value & CHANNEL_OFDM) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200785 ret = ath5k_hw_write_ofdm_timings(ah, channel);
786 if (ret)
787 return ret;
788 }
789
790 /*Enable/disable 802.11b mode on 5111
791 (enable 2111 frequency converter + CCK)*/
792 if (ah->ah_radio == AR5K_RF5111) {
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500793 if (mode == AR5K_MODE_11B)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200794 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
795 AR5K_TXCFG_B_MODE);
796 else
797 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
798 AR5K_TXCFG_B_MODE);
799 }
800
801 /*
802 * Set channel and calibrate the PHY
803 */
804 ret = ath5k_hw_channel(ah, channel);
805 if (ret)
806 return ret;
807
808 /* Set antenna mode */
809 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
810 ah->ah_antenna[ee_mode][0], 0xfffffc06);
811
812 /*
813 * In case a fixed antenna was set as default
814 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
815 * registers.
816 */
817 if (s_ant != 0){
818 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
819 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
820 else /* 2 - Aux */
821 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
822 } else {
823 ant[0] = AR5K_ANT_FIXED_A;
824 ant[1] = AR5K_ANT_FIXED_B;
825 }
826
827 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
828 AR5K_PHY_ANT_SWITCH_TABLE_0);
829 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
830 AR5K_PHY_ANT_SWITCH_TABLE_1);
831
832 /* Commit values from EEPROM */
833 if (ah->ah_radio == AR5K_RF5111)
834 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
835 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
836
837 ath5k_hw_reg_write(ah,
838 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
839 AR5K_PHY(0x5a));
840
841 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
842 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
843 0xffffc07f);
844 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
845 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
846 0xfffc0fff);
847 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
848 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
849 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
850 0xffff0000);
851
852 ath5k_hw_reg_write(ah,
853 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
854 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
855 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
856 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
857
858 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
859 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
860 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
861 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
862 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
863
864 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
865 AR5K_PHY_IQ_CORR_ENABLE |
866 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
867 ee->ee_q_cal[ee_mode]);
868
869 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
870 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
871 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
872 ee->ee_margin_tx_rx[ee_mode]);
873
874 } else {
875 mdelay(1);
876 /* Disable phy and wait */
877 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
878 mdelay(1);
879 }
880
881 /*
882 * Restore saved values
883 */
884 /*DCU/Antenna selection not available on 5210*/
885 if (ah->ah_version != AR5K_AR5210) {
886 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
887 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
888 }
889 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
890 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
891 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
892
893 /*
894 * Misc
895 */
896 /* XXX: add ah->aid once mac80211 gives this to us */
897 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
898
899 ath5k_hw_set_opmode(ah);
900 /*PISR/SISR Not available on 5210*/
901 if (ah->ah_version != AR5K_AR5210) {
902 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
903 /* If we later allow tuning for this, store into sc structure */
904 data = AR5K_TUNE_RSSI_THRES |
905 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
906 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
907 }
908
909 /*
910 * Set Rx/Tx DMA Configuration
Nick Kossifidis56c90542008-02-28 16:20:52 -0500911 *
912 * Set maximum DMA size (512) except for PCI-E cards since
913 * it causes rx overruns and tx errors (tested on 5424 but since
914 * rx overruns also occur on 5416/5418 with madwifi we set 128
915 * for all PCI-E cards to be safe).
916 *
917 * In dumps this is 128 for allchips.
918 *
919 * XXX: need to check 5210 for this
920 * TODO: Check out tx triger level, it's always 64 on dumps but I
921 * guess we can tweak it and see how it goes ;-)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200922 */
Nick Kossifidis56c90542008-02-28 16:20:52 -0500923 dma_size = (pdev->is_pcie) ? AR5K_DMASIZE_128B : AR5K_DMASIZE_512B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200924 if (ah->ah_version != AR5K_AR5210) {
Nick Kossifidis56c90542008-02-28 16:20:52 -0500925 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
926 AR5K_TXCFG_SDMAMR, dma_size);
927 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
928 AR5K_RXCFG_SDMAMW, dma_size);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200929 }
930
931 /*
932 * Enable the PHY and wait until completion
933 */
934 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
935
936 /*
937 * 5111/5112 Specific
938 */
939 if (ah->ah_version != AR5K_AR5210) {
940 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
941 AR5K_PHY_RX_DELAY_M;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500942 data = (channel->hw_value & CHANNEL_CCK) ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200943 ((data << 2) / 22) : (data / 10);
944
945 udelay(100 + data);
946 } else {
947 mdelay(1);
948 }
949
950 /*
951 * Enable calibration and wait until completion
952 */
953 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
954 AR5K_PHY_AGCCTL_CAL);
955
956 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
957 AR5K_PHY_AGCCTL_CAL, 0, false)) {
958 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500959 channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200960 return -EAGAIN;
961 }
962
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500963 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200964 if (ret)
965 return ret;
966
967 ah->ah_calibration = false;
968
969 /* A and G modes can use QAM modulation which requires enabling
970 * I and Q calibration. Don't bother in B mode. */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500971 if (!(mode == AR5K_MODE_11B)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200972 ah->ah_calibration = true;
973 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
974 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
975 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
976 AR5K_PHY_IQ_RUN);
977 }
978
979 /*
980 * Reset queues and start beacon timers at the end of the reset routine
981 */
982 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
983 /*No QCU on 5210*/
984 if (ah->ah_version != AR5K_AR5210)
985 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
986
987 ret = ath5k_hw_reset_tx_queue(ah, i);
988 if (ret) {
989 ATH5K_ERR(ah->ah_sc,
990 "failed to reset TX queue #%d\n", i);
991 return ret;
992 }
993 }
994
995 /* Pre-enable interrupts on 5211/5212*/
996 if (ah->ah_version != AR5K_AR5210)
997 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
998 AR5K_INT_FATAL);
999
1000 /*
1001 * Set RF kill flags if supported by the device (read from the EEPROM)
1002 * Disable gpio_intr for now since it results system hang.
1003 * TODO: Handle this in ath5k_intr
1004 */
1005#if 0
1006 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1007 ath5k_hw_set_gpio_input(ah, 0);
1008 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1009 if (ah->ah_gpio[0] == 0)
1010 ath5k_hw_set_gpio_intr(ah, 0, 1);
1011 else
1012 ath5k_hw_set_gpio_intr(ah, 0, 0);
1013 }
1014#endif
1015
1016 /*
1017 * Set the 32MHz reference clock on 5212 phy clock sleep register
1018 */
1019 if (ah->ah_version == AR5K_AR5212) {
1020 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1021 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1022 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1023 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1024 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
Nick Kossifidis903b4742008-02-28 14:50:50 -05001025 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001026 }
1027
1028 /*
1029 * Disable beacons and reset the register
1030 */
1031 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1032 AR5K_BEACON_RESET_TSF);
1033
1034 return 0;
1035}
1036
1037/*
1038 * Reset chipset
1039 */
1040static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1041{
1042 int ret;
1043 u32 mask = val ? val : ~0U;
1044
1045 ATH5K_TRACE(ah->ah_sc);
1046
1047 /* Read-and-clear RX Descriptor Pointer*/
1048 ath5k_hw_reg_read(ah, AR5K_RXDP);
1049
1050 /*
1051 * Reset the device and wait until success
1052 */
1053 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1054
1055 /* Wait at least 128 PCI clocks */
1056 udelay(15);
1057
1058 if (ah->ah_version == AR5K_AR5210) {
1059 val &= AR5K_RESET_CTL_CHIP;
1060 mask &= AR5K_RESET_CTL_CHIP;
1061 } else {
1062 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1063 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1064 }
1065
1066 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1067
1068 /*
1069 * Reset configuration register (for hw byte-swap). Note that this
1070 * is only set for big endian. We do the necessary magic in
1071 * AR5K_INIT_CFG.
1072 */
1073 if ((val & AR5K_RESET_CTL_PCU) == 0)
1074 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1075
1076 return ret;
1077}
1078
1079/*
1080 * Power management functions
1081 */
1082
1083/*
1084 * Sleep control
1085 */
1086int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1087 bool set_chip, u16 sleep_duration)
1088{
1089 unsigned int i;
1090 u32 staid;
1091
1092 ATH5K_TRACE(ah->ah_sc);
1093 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1094
1095 switch (mode) {
1096 case AR5K_PM_AUTO:
1097 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1098 /* fallthrough */
1099 case AR5K_PM_NETWORK_SLEEP:
1100 if (set_chip == true)
1101 ath5k_hw_reg_write(ah,
1102 AR5K_SLEEP_CTL_SLE | sleep_duration,
1103 AR5K_SLEEP_CTL);
1104
1105 staid |= AR5K_STA_ID1_PWR_SV;
1106 break;
1107
1108 case AR5K_PM_FULL_SLEEP:
1109 if (set_chip == true)
1110 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1111 AR5K_SLEEP_CTL);
1112
1113 staid |= AR5K_STA_ID1_PWR_SV;
1114 break;
1115
1116 case AR5K_PM_AWAKE:
1117 if (set_chip == false)
1118 goto commit;
1119
1120 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1121 AR5K_SLEEP_CTL);
1122
1123 for (i = 5000; i > 0; i--) {
1124 /* Check if the chip did wake up */
1125 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1126 AR5K_PCICFG_SPWR_DN) == 0)
1127 break;
1128
1129 /* Wait a bit and retry */
1130 udelay(200);
1131 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1132 AR5K_SLEEP_CTL);
1133 }
1134
1135 /* Fail if the chip didn't wake up */
1136 if (i <= 0)
1137 return -EIO;
1138
1139 staid &= ~AR5K_STA_ID1_PWR_SV;
1140 break;
1141
1142 default:
1143 return -EINVAL;
1144 }
1145
1146commit:
1147 ah->ah_power_mode = mode;
1148 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1149
1150 return 0;
1151}
1152
1153/***********************\
1154 DMA Related Functions
1155\***********************/
1156
1157/*
1158 * Receive functions
1159 */
1160
1161/*
1162 * Start DMA receive
1163 */
1164void ath5k_hw_start_rx(struct ath5k_hw *ah)
1165{
1166 ATH5K_TRACE(ah->ah_sc);
1167 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1168}
1169
1170/*
1171 * Stop DMA receive
1172 */
1173int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1174{
1175 unsigned int i;
1176
1177 ATH5K_TRACE(ah->ah_sc);
1178 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1179
1180 /*
1181 * It may take some time to disable the DMA receive unit
1182 */
1183 for (i = 2000; i > 0 &&
1184 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1185 i--)
1186 udelay(10);
1187
1188 return i ? 0 : -EBUSY;
1189}
1190
1191/*
1192 * Get the address of the RX Descriptor
1193 */
1194u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1195{
1196 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1197}
1198
1199/*
1200 * Set the address of the RX Descriptor
1201 */
1202void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1203{
1204 ATH5K_TRACE(ah->ah_sc);
1205
1206 /*TODO:Shouldn't we check if RX is enabled first ?*/
1207 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1208}
1209
1210/*
1211 * Transmit functions
1212 */
1213
1214/*
1215 * Start DMA transmit for a specific queue
1216 * (see also QCU/DCU functions)
1217 */
1218int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1219{
1220 u32 tx_queue;
1221
1222 ATH5K_TRACE(ah->ah_sc);
1223 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1224
1225 /* Return if queue is declared inactive */
1226 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1227 return -EIO;
1228
1229 if (ah->ah_version == AR5K_AR5210) {
1230 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1231
1232 /*
1233 * Set the queue by type on 5210
1234 */
1235 switch (ah->ah_txq[queue].tqi_type) {
1236 case AR5K_TX_QUEUE_DATA:
1237 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1238 break;
1239 case AR5K_TX_QUEUE_BEACON:
1240 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1241 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1242 AR5K_BSR);
1243 break;
1244 case AR5K_TX_QUEUE_CAB:
1245 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1246 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1247 AR5K_BCR_BDMAE, AR5K_BSR);
1248 break;
1249 default:
1250 return -EINVAL;
1251 }
1252 /* Start queue */
1253 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1254 } else {
1255 /* Return if queue is disabled */
1256 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1257 return -EIO;
1258
1259 /* Start queue */
1260 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1261 }
1262
1263 return 0;
1264}
1265
1266/*
1267 * Stop DMA transmit for a specific queue
1268 * (see also QCU/DCU functions)
1269 */
1270int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1271{
1272 unsigned int i = 100;
1273 u32 tx_queue, pending;
1274
1275 ATH5K_TRACE(ah->ah_sc);
1276 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1277
1278 /* Return if queue is declared inactive */
1279 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1280 return -EIO;
1281
1282 if (ah->ah_version == AR5K_AR5210) {
1283 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1284
1285 /*
1286 * Set by queue type
1287 */
1288 switch (ah->ah_txq[queue].tqi_type) {
1289 case AR5K_TX_QUEUE_DATA:
1290 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1291 break;
1292 case AR5K_TX_QUEUE_BEACON:
1293 case AR5K_TX_QUEUE_CAB:
1294 /* XXX Fix me... */
1295 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1296 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1297 break;
1298 default:
1299 return -EINVAL;
1300 }
1301
1302 /* Stop queue */
1303 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1304 } else {
1305 /*
1306 * Schedule TX disable and wait until queue is empty
1307 */
1308 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1309
1310 /*Check for pending frames*/
1311 do {
1312 pending = ath5k_hw_reg_read(ah,
1313 AR5K_QUEUE_STATUS(queue)) &
1314 AR5K_QCU_STS_FRMPENDCNT;
1315 udelay(100);
1316 } while (--i && pending);
1317
1318 /* Clear register */
1319 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1320 }
1321
1322 /* TODO: Check for success else return error */
1323 return 0;
1324}
1325
1326/*
1327 * Get the address of the TX Descriptor for a specific queue
1328 * (see also QCU/DCU functions)
1329 */
1330u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1331{
1332 u16 tx_reg;
1333
1334 ATH5K_TRACE(ah->ah_sc);
1335 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1336
1337 /*
1338 * Get the transmit queue descriptor pointer from the selected queue
1339 */
1340 /*5210 doesn't have QCU*/
1341 if (ah->ah_version == AR5K_AR5210) {
1342 switch (ah->ah_txq[queue].tqi_type) {
1343 case AR5K_TX_QUEUE_DATA:
1344 tx_reg = AR5K_NOQCU_TXDP0;
1345 break;
1346 case AR5K_TX_QUEUE_BEACON:
1347 case AR5K_TX_QUEUE_CAB:
1348 tx_reg = AR5K_NOQCU_TXDP1;
1349 break;
1350 default:
1351 return 0xffffffff;
1352 }
1353 } else {
1354 tx_reg = AR5K_QUEUE_TXDP(queue);
1355 }
1356
1357 return ath5k_hw_reg_read(ah, tx_reg);
1358}
1359
1360/*
1361 * Set the address of the TX Descriptor for a specific queue
1362 * (see also QCU/DCU functions)
1363 */
1364int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1365{
1366 u16 tx_reg;
1367
1368 ATH5K_TRACE(ah->ah_sc);
1369 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1370
1371 /*
1372 * Set the transmit queue descriptor pointer register by type
1373 * on 5210
1374 */
1375 if (ah->ah_version == AR5K_AR5210) {
1376 switch (ah->ah_txq[queue].tqi_type) {
1377 case AR5K_TX_QUEUE_DATA:
1378 tx_reg = AR5K_NOQCU_TXDP0;
1379 break;
1380 case AR5K_TX_QUEUE_BEACON:
1381 case AR5K_TX_QUEUE_CAB:
1382 tx_reg = AR5K_NOQCU_TXDP1;
1383 break;
1384 default:
1385 return -EINVAL;
1386 }
1387 } else {
1388 /*
1389 * Set the transmit queue descriptor pointer for
1390 * the selected queue on QCU for 5211+
1391 * (this won't work if the queue is still active)
1392 */
1393 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1394 return -EIO;
1395
1396 tx_reg = AR5K_QUEUE_TXDP(queue);
1397 }
1398
1399 /* Set descriptor pointer */
1400 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1401
1402 return 0;
1403}
1404
1405/*
1406 * Update tx trigger level
1407 */
1408int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1409{
1410 u32 trigger_level, imr;
1411 int ret = -EIO;
1412
1413 ATH5K_TRACE(ah->ah_sc);
1414
1415 /*
1416 * Disable interrupts by setting the mask
1417 */
1418 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1419
1420 /*TODO: Boundary check on trigger_level*/
1421 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1422 AR5K_TXCFG_TXFULL);
1423
1424 if (increase == false) {
1425 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1426 goto done;
1427 } else
1428 trigger_level +=
1429 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1430
1431 /*
1432 * Update trigger level on success
1433 */
1434 if (ah->ah_version == AR5K_AR5210)
1435 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1436 else
1437 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1438 AR5K_TXCFG_TXFULL, trigger_level);
1439
1440 ret = 0;
1441
1442done:
1443 /*
1444 * Restore interrupt mask
1445 */
1446 ath5k_hw_set_intr(ah, imr);
1447
1448 return ret;
1449}
1450
1451/*
1452 * Interrupt handling
1453 */
1454
1455/*
1456 * Check if we have pending interrupts
1457 */
1458bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1459{
1460 ATH5K_TRACE(ah->ah_sc);
1461 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1462}
1463
1464/*
1465 * Get interrupt mask (ISR)
1466 */
1467int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1468{
1469 u32 data;
1470
1471 ATH5K_TRACE(ah->ah_sc);
1472
1473 /*
1474 * Read interrupt status from the Interrupt Status register
1475 * on 5210
1476 */
1477 if (ah->ah_version == AR5K_AR5210) {
1478 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1479 if (unlikely(data == AR5K_INT_NOCARD)) {
1480 *interrupt_mask = data;
1481 return -ENODEV;
1482 }
1483 } else {
1484 /*
1485 * Read interrupt status from the Read-And-Clear shadow register
1486 * Note: PISR/SISR Not available on 5210
1487 */
1488 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1489 }
1490
1491 /*
1492 * Get abstract interrupt mask (driver-compatible)
1493 */
1494 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1495
1496 if (unlikely(data == AR5K_INT_NOCARD))
1497 return -ENODEV;
1498
1499 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1500 *interrupt_mask |= AR5K_INT_RX;
1501
1502 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1503 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1504 *interrupt_mask |= AR5K_INT_TX;
1505
1506 if (ah->ah_version != AR5K_AR5210) {
1507 /*HIU = Host Interface Unit (PCI etc)*/
1508 if (unlikely(data & (AR5K_ISR_HIUERR)))
1509 *interrupt_mask |= AR5K_INT_FATAL;
1510
1511 /*Beacon Not Ready*/
1512 if (unlikely(data & (AR5K_ISR_BNR)))
1513 *interrupt_mask |= AR5K_INT_BNR;
1514 }
1515
1516 /*
1517 * XXX: BMISS interrupts may occur after association.
1518 * I found this on 5210 code but it needs testing. If this is
1519 * true we should disable them before assoc and re-enable them
1520 * after a successfull assoc + some jiffies.
1521 */
1522#if 0
1523 interrupt_mask &= ~AR5K_INT_BMISS;
1524#endif
1525
1526 /*
1527 * In case we didn't handle anything,
1528 * print the register value.
1529 */
1530 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1531 ATH5K_PRINTF("0x%08x\n", data);
1532
1533 return 0;
1534}
1535
1536/*
1537 * Set interrupt mask
1538 */
1539enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1540{
1541 enum ath5k_int old_mask, int_mask;
1542
1543 /*
1544 * Disable card interrupts to prevent any race conditions
1545 * (they will be re-enabled afterwards).
1546 */
1547 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1548
1549 old_mask = ah->ah_imr;
1550
1551 /*
1552 * Add additional, chipset-dependent interrupt mask flags
1553 * and write them to the IMR (interrupt mask register).
1554 */
1555 int_mask = new_mask & AR5K_INT_COMMON;
1556
1557 if (new_mask & AR5K_INT_RX)
1558 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1559 AR5K_IMR_RXDESC;
1560
1561 if (new_mask & AR5K_INT_TX)
1562 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1563 AR5K_IMR_TXURN;
1564
1565 if (ah->ah_version != AR5K_AR5210) {
1566 if (new_mask & AR5K_INT_FATAL) {
1567 int_mask |= AR5K_IMR_HIUERR;
1568 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1569 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1570 }
1571 }
1572
1573 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1574
1575 /* Store new interrupt mask */
1576 ah->ah_imr = new_mask;
1577
1578 /* ..re-enable interrupts */
1579 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1580
1581 return old_mask;
1582}
1583
1584
1585/*************************\
1586 EEPROM access functions
1587\*************************/
1588
1589/*
1590 * Read from eeprom
1591 */
1592static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1593{
1594 u32 status, timeout;
1595
1596 ATH5K_TRACE(ah->ah_sc);
1597 /*
1598 * Initialize EEPROM access
1599 */
1600 if (ah->ah_version == AR5K_AR5210) {
1601 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1602 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1603 } else {
1604 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1605 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1606 AR5K_EEPROM_CMD_READ);
1607 }
1608
1609 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1610 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1611 if (status & AR5K_EEPROM_STAT_RDDONE) {
1612 if (status & AR5K_EEPROM_STAT_RDERR)
1613 return -EIO;
1614 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1615 0xffff);
1616 return 0;
1617 }
1618 udelay(15);
1619 }
1620
1621 return -ETIMEDOUT;
1622}
1623
1624/*
1625 * Write to eeprom - currently disabled, use at your own risk
1626 */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001627#if 0
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001628static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1629{
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001630
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001631 u32 status, timeout;
1632
1633 ATH5K_TRACE(ah->ah_sc);
1634
1635 /*
1636 * Initialize eeprom access
1637 */
1638
1639 if (ah->ah_version == AR5K_AR5210) {
1640 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1641 } else {
1642 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1643 AR5K_EEPROM_CMD_RESET);
1644 }
1645
1646 /*
1647 * Write data to data register
1648 */
1649
1650 if (ah->ah_version == AR5K_AR5210) {
1651 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1652 } else {
1653 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1654 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1655 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1656 AR5K_EEPROM_CMD_WRITE);
1657 }
1658
1659 /*
1660 * Check status
1661 */
1662
1663 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1664 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1665 if (status & AR5K_EEPROM_STAT_WRDONE) {
1666 if (status & AR5K_EEPROM_STAT_WRERR)
1667 return EIO;
1668 return 0;
1669 }
1670 udelay(15);
1671 }
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001672
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001673 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1674 return -EIO;
1675}
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001676#endif
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001677
1678/*
1679 * Translate binary channel representation in EEPROM to frequency
1680 */
1681static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1682{
1683 u16 val;
1684
1685 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1686 return bin;
1687
1688 if (mode == AR5K_EEPROM_MODE_11A) {
1689 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1690 val = (5 * bin) + 4800;
1691 else
1692 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1693 (bin * 10) + 5100;
1694 } else {
1695 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1696 val = bin + 2300;
1697 else
1698 val = bin + 2400;
1699 }
1700
1701 return val;
1702}
1703
1704/*
1705 * Read antenna infos from eeprom
1706 */
1707static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1708 unsigned int mode)
1709{
1710 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1711 u32 o = *offset;
1712 u16 val;
1713 int ret, i = 0;
1714
1715 AR5K_EEPROM_READ(o++, val);
1716 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1717 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1718 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1719
1720 AR5K_EEPROM_READ(o++, val);
1721 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1722 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1723 ee->ee_ant_control[mode][i++] = val & 0x3f;
1724
1725 AR5K_EEPROM_READ(o++, val);
1726 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1727 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1728 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1729
1730 AR5K_EEPROM_READ(o++, val);
1731 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1732 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1733 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1734 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1735
1736 AR5K_EEPROM_READ(o++, val);
1737 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1738 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1739 ee->ee_ant_control[mode][i++] = val & 0x3f;
1740
1741 /* Get antenna modes */
1742 ah->ah_antenna[mode][0] =
1743 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1744 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1745 ee->ee_ant_control[mode][1] |
1746 (ee->ee_ant_control[mode][2] << 6) |
1747 (ee->ee_ant_control[mode][3] << 12) |
1748 (ee->ee_ant_control[mode][4] << 18) |
1749 (ee->ee_ant_control[mode][5] << 24);
1750 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1751 ee->ee_ant_control[mode][6] |
1752 (ee->ee_ant_control[mode][7] << 6) |
1753 (ee->ee_ant_control[mode][8] << 12) |
1754 (ee->ee_ant_control[mode][9] << 18) |
1755 (ee->ee_ant_control[mode][10] << 24);
1756
1757 /* return new offset */
1758 *offset = o;
1759
1760 return 0;
1761}
1762
1763/*
1764 * Read supported modes from eeprom
1765 */
1766static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1767 unsigned int mode)
1768{
1769 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1770 u32 o = *offset;
1771 u16 val;
1772 int ret;
1773
1774 AR5K_EEPROM_READ(o++, val);
1775 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1776 ee->ee_thr_62[mode] = val & 0xff;
1777
1778 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1779 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1780
1781 AR5K_EEPROM_READ(o++, val);
1782 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1783 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1784
1785 AR5K_EEPROM_READ(o++, val);
1786 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1787
1788 if ((val & 0xff) & 0x80)
1789 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1790 else
1791 ee->ee_noise_floor_thr[mode] = val & 0xff;
1792
1793 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1794 ee->ee_noise_floor_thr[mode] =
1795 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1796
1797 AR5K_EEPROM_READ(o++, val);
1798 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1799 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1800 ee->ee_xpd[mode] = val & 0x1;
1801
1802 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1803 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1804
1805 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1806 AR5K_EEPROM_READ(o++, val);
1807 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1808
1809 if (mode == AR5K_EEPROM_MODE_11A)
1810 ee->ee_xr_power[mode] = val & 0x3f;
1811 else {
1812 ee->ee_ob[mode][0] = val & 0x7;
1813 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1814 }
1815 }
1816
1817 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1818 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1819 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1820 } else {
1821 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1822
1823 AR5K_EEPROM_READ(o++, val);
1824 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1825
1826 if (mode == AR5K_EEPROM_MODE_11G)
1827 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1828 }
1829
1830 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1831 mode == AR5K_EEPROM_MODE_11A) {
1832 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1833 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1834 }
1835
1836 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1837 mode == AR5K_EEPROM_MODE_11G)
1838 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1839
1840 /* return new offset */
1841 *offset = o;
1842
1843 return 0;
1844}
1845
1846/*
1847 * Initialize eeprom & capabilities structs
1848 */
1849static int ath5k_eeprom_init(struct ath5k_hw *ah)
1850{
1851 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1852 unsigned int mode, i;
1853 int ret;
1854 u32 offset;
1855 u16 val;
1856
1857 /* Initial TX thermal adjustment values */
1858 ee->ee_tx_clip = 4;
1859 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
1860 ee->ee_gain_select = 1;
1861
1862 /*
1863 * Read values from EEPROM and store them in the capability structure
1864 */
1865 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
1866 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
1867 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
1868 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
1869 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
1870
1871 /* Return if we have an old EEPROM */
1872 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
1873 return 0;
1874
1875#ifdef notyet
1876 /*
1877 * Validate the checksum of the EEPROM date. There are some
1878 * devices with invalid EEPROMs.
1879 */
1880 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
1881 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
1882 cksum ^= val;
1883 }
1884 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
1885 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
1886 return -EIO;
1887 }
1888#endif
1889
1890 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
1891 ee_ant_gain);
1892
1893 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1894 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
1895 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
1896 }
1897
1898 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
1899 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
1900 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
1901 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
1902
1903 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
1904 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
1905 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
1906 }
1907
1908 /*
1909 * Get conformance test limit values
1910 */
1911 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
1912 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
1913
1914 for (i = 0; i < ee->ee_ctls; i++) {
1915 AR5K_EEPROM_READ(offset++, val);
1916 ee->ee_ctl[i] = (val >> 8) & 0xff;
1917 ee->ee_ctl[i + 1] = val & 0xff;
1918 }
1919
1920 /*
1921 * Get values for 802.11a (5GHz)
1922 */
1923 mode = AR5K_EEPROM_MODE_11A;
1924
1925 ee->ee_turbo_max_power[mode] =
1926 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
1927
1928 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
1929
1930 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1931 if (ret)
1932 return ret;
1933
1934 AR5K_EEPROM_READ(offset++, val);
1935 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1936 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
1937 ee->ee_db[mode][3] = (val >> 2) & 0x7;
1938 ee->ee_ob[mode][2] = (val << 1) & 0x7;
1939
1940 AR5K_EEPROM_READ(offset++, val);
1941 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
1942 ee->ee_db[mode][2] = (val >> 12) & 0x7;
1943 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
1944 ee->ee_db[mode][1] = (val >> 6) & 0x7;
1945 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
1946 ee->ee_db[mode][0] = val & 0x7;
1947
1948 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1949 if (ret)
1950 return ret;
1951
1952 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
1953 AR5K_EEPROM_READ(offset++, val);
1954 ee->ee_margin_tx_rx[mode] = val & 0x3f;
1955 }
1956
1957 /*
1958 * Get values for 802.11b (2.4GHz)
1959 */
1960 mode = AR5K_EEPROM_MODE_11B;
1961 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
1962
1963 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1964 if (ret)
1965 return ret;
1966
1967 AR5K_EEPROM_READ(offset++, val);
1968 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1969 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
1970 ee->ee_db[mode][1] = val & 0x7;
1971
1972 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1973 if (ret)
1974 return ret;
1975
1976 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1977 AR5K_EEPROM_READ(offset++, val);
1978 ee->ee_cal_pier[mode][0] =
1979 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1980 ee->ee_cal_pier[mode][1] =
1981 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
1982
1983 AR5K_EEPROM_READ(offset++, val);
1984 ee->ee_cal_pier[mode][2] =
1985 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1986 }
1987
1988 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
1989 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
1990
1991 /*
1992 * Get values for 802.11g (2.4GHz)
1993 */
1994 mode = AR5K_EEPROM_MODE_11G;
1995 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
1996
1997 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1998 if (ret)
1999 return ret;
2000
2001 AR5K_EEPROM_READ(offset++, val);
2002 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2003 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2004 ee->ee_db[mode][1] = val & 0x7;
2005
2006 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2007 if (ret)
2008 return ret;
2009
2010 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2011 AR5K_EEPROM_READ(offset++, val);
2012 ee->ee_cal_pier[mode][0] =
2013 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2014 ee->ee_cal_pier[mode][1] =
2015 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2016
2017 AR5K_EEPROM_READ(offset++, val);
2018 ee->ee_turbo_max_power[mode] = val & 0x7f;
2019 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2020
2021 AR5K_EEPROM_READ(offset++, val);
2022 ee->ee_cal_pier[mode][2] =
2023 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2024
2025 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2026 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2027
2028 AR5K_EEPROM_READ(offset++, val);
2029 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2030 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2031
2032 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2033 AR5K_EEPROM_READ(offset++, val);
2034 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2035 }
2036 }
2037
2038 /*
2039 * Read 5GHz EEPROM channels
2040 */
2041
2042 return 0;
2043}
2044
2045/*
2046 * Read the MAC address from eeprom
2047 */
2048static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2049{
2050 u8 mac_d[ETH_ALEN];
2051 u32 total, offset;
2052 u16 data;
2053 int octet, ret;
2054
2055 memset(mac, 0, ETH_ALEN);
2056 memset(mac_d, 0, ETH_ALEN);
2057
2058 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2059 if (ret)
2060 return ret;
2061
2062 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2063 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2064 if (ret)
2065 return ret;
2066
2067 total += data;
2068 mac_d[octet + 1] = data & 0xff;
2069 mac_d[octet] = data >> 8;
2070 octet += 2;
2071 }
2072
2073 memcpy(mac, mac_d, ETH_ALEN);
2074
2075 if (!total || total == 3 * 0xffff)
2076 return -EINVAL;
2077
2078 return 0;
2079}
2080
2081/*
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002082 * Fill the capabilities struct
2083 */
2084static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2085{
2086 u16 ee_header;
2087
2088 ATH5K_TRACE(ah->ah_sc);
2089 /* Capabilities stored in the EEPROM */
2090 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2091
2092 if (ah->ah_version == AR5K_AR5210) {
2093 /*
2094 * Set radio capabilities
2095 * (The AR5110 only supports the middle 5GHz band)
2096 */
2097 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2098 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2099 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2100 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2101
2102 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002103 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2104 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002105 } else {
2106 /*
2107 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2108 * XXX and from 2312 to 2732GHz. There are problems with the
2109 * XXX current ieee80211 implementation because the IEEE
2110 * XXX channel mapping does not support negative channel
2111 * XXX numbers (2312MHz is channel -19). Of course, this
2112 * XXX doesn't matter because these channels are out of range
2113 * XXX but some regulation domains like MKK (Japan) will
2114 * XXX support frequencies somewhere around 4.8GHz.
2115 */
2116
2117 /*
2118 * Set radio capabilities
2119 */
2120
2121 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2122 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2123 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2124
2125 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002126 __set_bit(AR5K_MODE_11A,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002127 ah->ah_capabilities.cap_mode);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002128 __set_bit(AR5K_MODE_11A_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002129 ah->ah_capabilities.cap_mode);
2130 if (ah->ah_version == AR5K_AR5212)
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002131 __set_bit(AR5K_MODE_11G_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002132 ah->ah_capabilities.cap_mode);
2133 }
2134
2135 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2136 * connected */
2137 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2138 AR5K_EEPROM_HDR_11G(ee_header)) {
2139 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2140 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2141
2142 if (AR5K_EEPROM_HDR_11B(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002143 __set_bit(AR5K_MODE_11B,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002144 ah->ah_capabilities.cap_mode);
2145
2146 if (AR5K_EEPROM_HDR_11G(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002147 __set_bit(AR5K_MODE_11G,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002148 ah->ah_capabilities.cap_mode);
2149 }
2150 }
2151
2152 /* GPIO */
2153 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2154
2155 /* Set number of supported TX queues */
2156 if (ah->ah_version == AR5K_AR5210)
2157 ah->ah_capabilities.cap_queues.q_tx_num =
2158 AR5K_NUM_TX_QUEUES_NOQCU;
2159 else
2160 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2161
2162 return 0;
2163}
2164
2165/*********************************\
2166 Protocol Control Unit Functions
2167\*********************************/
2168
2169/*
2170 * Set Operation mode
2171 */
2172int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2173{
2174 u32 pcu_reg, beacon_reg, low_id, high_id;
2175
2176 pcu_reg = 0;
2177 beacon_reg = 0;
2178
2179 ATH5K_TRACE(ah->ah_sc);
2180
2181 switch (ah->ah_op_mode) {
2182 case IEEE80211_IF_TYPE_IBSS:
2183 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2184 (ah->ah_version == AR5K_AR5210 ?
2185 AR5K_STA_ID1_NO_PSPOLL : 0);
2186 beacon_reg |= AR5K_BCR_ADHOC;
2187 break;
2188
2189 case IEEE80211_IF_TYPE_AP:
2190 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2191 (ah->ah_version == AR5K_AR5210 ?
2192 AR5K_STA_ID1_NO_PSPOLL : 0);
2193 beacon_reg |= AR5K_BCR_AP;
2194 break;
2195
2196 case IEEE80211_IF_TYPE_STA:
2197 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2198 (ah->ah_version == AR5K_AR5210 ?
2199 AR5K_STA_ID1_PWR_SV : 0);
2200 case IEEE80211_IF_TYPE_MNTR:
2201 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2202 (ah->ah_version == AR5K_AR5210 ?
2203 AR5K_STA_ID1_NO_PSPOLL : 0);
2204 break;
2205
2206 default:
2207 return -EINVAL;
2208 }
2209
2210 /*
2211 * Set PCU registers
2212 */
2213 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2214 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2215 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2216 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2217
2218 /*
2219 * Set Beacon Control Register on 5210
2220 */
2221 if (ah->ah_version == AR5K_AR5210)
2222 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2223
2224 return 0;
2225}
2226
2227/*
2228 * BSSID Functions
2229 */
2230
2231/*
2232 * Get station id
2233 */
2234void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2235{
2236 ATH5K_TRACE(ah->ah_sc);
2237 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2238}
2239
2240/*
2241 * Set station id
2242 */
2243int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2244{
2245 u32 low_id, high_id;
2246
2247 ATH5K_TRACE(ah->ah_sc);
2248 /* Set new station ID */
2249 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2250
2251 low_id = AR5K_LOW_ID(mac);
2252 high_id = AR5K_HIGH_ID(mac);
2253
2254 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2255 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2256
2257 return 0;
2258}
2259
2260/*
2261 * Set BSSID
2262 */
2263void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2264{
2265 u32 low_id, high_id;
2266 u16 tim_offset = 0;
2267
2268 /*
2269 * Set simple BSSID mask on 5212
2270 */
2271 if (ah->ah_version == AR5K_AR5212) {
2272 ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM0);
2273 ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM1);
2274 }
2275
2276 /*
2277 * Set BSSID which triggers the "SME Join" operation
2278 */
2279 low_id = AR5K_LOW_ID(bssid);
2280 high_id = AR5K_HIGH_ID(bssid);
2281 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2282 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2283 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2284
2285 if (assoc_id == 0) {
2286 ath5k_hw_disable_pspoll(ah);
2287 return;
2288 }
2289
2290 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2291 tim_offset ? tim_offset + 4 : 0);
2292
2293 ath5k_hw_enable_pspoll(ah, NULL, 0);
2294}
2295/**
2296 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2297 *
2298 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2299 * which bits of the interface's MAC address should be looked at when trying
2300 * to decide which packets to ACK. In station mode every bit matters. In AP
2301 * mode with a single BSS every bit matters as well. In AP mode with
2302 * multiple BSSes not every bit matters.
2303 *
2304 * @ah: the &struct ath5k_hw
2305 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2306 *
2307 * Note that this is a simple filter and *does* not filter out all
2308 * relevant frames. Some non-relevant frames will get through, probability
2309 * jocks are welcomed to compute.
2310 *
2311 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2312 * computing the set of:
2313 *
2314 * ~ ( MAC XOR BSSID )
2315 *
2316 * When you do this you are essentially computing the common bits. Later it
2317 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2318 * to obtain the relevant bits which should match on the destination frame.
2319 *
2320 * Simple example: on your card you have have two BSSes you have created with
2321 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2322 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2323 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2324 *
2325 * \
2326 * MAC: 0001 |
2327 * BSSID-01: 0100 | --> Belongs to us
2328 * BSSID-02: 1001 |
2329 * /
2330 * -------------------
2331 * BSSID-03: 0110 | --> External
2332 * -------------------
2333 *
2334 * Our bssid_mask would then be:
2335 *
2336 * On loop iteration for BSSID-01:
2337 * ~(0001 ^ 0100) -> ~(0101)
2338 * -> 1010
2339 * bssid_mask = 1010
2340 *
2341 * On loop iteration for BSSID-02:
2342 * bssid_mask &= ~(0001 ^ 1001)
2343 * bssid_mask = (1010) & ~(0001 ^ 1001)
2344 * bssid_mask = (1010) & ~(1001)
2345 * bssid_mask = (1010) & (0110)
2346 * bssid_mask = 0010
2347 *
2348 * A bssid_mask of 0010 means "only pay attention to the second least
2349 * significant bit". This is because its the only bit common
2350 * amongst the MAC and all BSSIDs we support. To findout what the real
2351 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2352 * or our MAC address (we assume the hardware uses the MAC address).
2353 *
2354 * Now, suppose there's an incoming frame for BSSID-03:
2355 *
2356 * IFRAME-01: 0110
2357 *
2358 * An easy eye-inspeciton of this already should tell you that this frame
2359 * will not pass our check. This is beacuse the bssid_mask tells the
2360 * hardware to only look at the second least significant bit and the
2361 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2362 * as 1, which does not match 0.
2363 *
2364 * So with IFRAME-01 we *assume* the hardware will do:
2365 *
2366 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2367 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2368 * --> allow = (0010) == 0000 ? 1 : 0;
2369 * --> allow = 0
2370 *
2371 * Lets now test a frame that should work:
2372 *
2373 * IFRAME-02: 0001 (we should allow)
2374 *
2375 * allow = (0001 & 1010) == 1010
2376 *
2377 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2378 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2379 * --> allow = (0010) == (0010)
2380 * --> allow = 1
2381 *
2382 * Other examples:
2383 *
2384 * IFRAME-03: 0100 --> allowed
2385 * IFRAME-04: 1001 --> allowed
2386 * IFRAME-05: 1101 --> allowed but its not for us!!!
2387 *
2388 */
2389int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2390{
2391 u32 low_id, high_id;
2392 ATH5K_TRACE(ah->ah_sc);
2393
2394 if (ah->ah_version == AR5K_AR5212) {
2395 low_id = AR5K_LOW_ID(mask);
2396 high_id = AR5K_HIGH_ID(mask);
2397
2398 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2399 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2400
2401 return 0;
2402 }
2403
2404 return -EIO;
2405}
2406
2407/*
2408 * Receive start/stop functions
2409 */
2410
2411/*
2412 * Start receive on PCU
2413 */
2414void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2415{
2416 ATH5K_TRACE(ah->ah_sc);
2417 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2418}
2419
2420/*
2421 * Stop receive on PCU
2422 */
2423void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2424{
2425 ATH5K_TRACE(ah->ah_sc);
2426 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2427}
2428
2429/*
2430 * RX Filter functions
2431 */
2432
2433/*
2434 * Set multicast filter
2435 */
2436void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2437{
2438 ATH5K_TRACE(ah->ah_sc);
2439 /* Set the multicat filter */
2440 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2441 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2442}
2443
2444/*
2445 * Set multicast filter by index
2446 */
2447int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2448{
2449
2450 ATH5K_TRACE(ah->ah_sc);
2451 if (index >= 64)
2452 return -EINVAL;
2453 else if (index >= 32)
2454 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2455 (1 << (index - 32)));
2456 else
2457 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2458
2459 return 0;
2460}
2461
2462/*
2463 * Clear Multicast filter by index
2464 */
2465int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2466{
2467
2468 ATH5K_TRACE(ah->ah_sc);
2469 if (index >= 64)
2470 return -EINVAL;
2471 else if (index >= 32)
2472 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2473 (1 << (index - 32)));
2474 else
2475 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2476
2477 return 0;
2478}
2479
2480/*
2481 * Get current rx filter
2482 */
2483u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2484{
2485 u32 data, filter = 0;
2486
2487 ATH5K_TRACE(ah->ah_sc);
2488 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2489
2490 /*Radar detection for 5212*/
2491 if (ah->ah_version == AR5K_AR5212) {
2492 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2493
2494 if (data & AR5K_PHY_ERR_FIL_RADAR)
2495 filter |= AR5K_RX_FILTER_RADARERR;
2496 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2497 filter |= AR5K_RX_FILTER_PHYERR;
2498 }
2499
2500 return filter;
2501}
2502
2503/*
2504 * Set rx filter
2505 */
2506void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2507{
2508 u32 data = 0;
2509
2510 ATH5K_TRACE(ah->ah_sc);
2511
2512 /* Set PHY error filter register on 5212*/
2513 if (ah->ah_version == AR5K_AR5212) {
2514 if (filter & AR5K_RX_FILTER_RADARERR)
2515 data |= AR5K_PHY_ERR_FIL_RADAR;
2516 if (filter & AR5K_RX_FILTER_PHYERR)
2517 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2518 }
2519
2520 /*
2521 * The AR5210 uses promiscous mode to detect radar activity
2522 */
2523 if (ah->ah_version == AR5K_AR5210 &&
2524 (filter & AR5K_RX_FILTER_RADARERR)) {
2525 filter &= ~AR5K_RX_FILTER_RADARERR;
2526 filter |= AR5K_RX_FILTER_PROM;
2527 }
2528
2529 /*Zero length DMA*/
2530 if (data)
2531 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2532 else
2533 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2534
2535 /*Write RX Filter register*/
2536 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2537
2538 /*Write PHY error filter register on 5212*/
2539 if (ah->ah_version == AR5K_AR5212)
2540 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2541
2542}
2543
2544/*
2545 * Beacon related functions
2546 */
2547
2548/*
2549 * Get a 32bit TSF
2550 */
2551u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2552{
2553 ATH5K_TRACE(ah->ah_sc);
2554 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2555}
2556
2557/*
2558 * Get the full 64bit TSF
2559 */
2560u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2561{
2562 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2563 ATH5K_TRACE(ah->ah_sc);
2564
2565 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2566}
2567
2568/*
2569 * Force a TSF reset
2570 */
2571void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2572{
2573 ATH5K_TRACE(ah->ah_sc);
2574 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2575}
2576
2577/*
2578 * Initialize beacon timers
2579 */
2580void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2581{
2582 u32 timer1, timer2, timer3;
2583
2584 ATH5K_TRACE(ah->ah_sc);
2585 /*
2586 * Set the additional timers by mode
2587 */
2588 switch (ah->ah_op_mode) {
2589 case IEEE80211_IF_TYPE_STA:
2590 if (ah->ah_version == AR5K_AR5210) {
2591 timer1 = 0xffffffff;
2592 timer2 = 0xffffffff;
2593 } else {
2594 timer1 = 0x0000ffff;
2595 timer2 = 0x0007ffff;
2596 }
2597 break;
2598
2599 default:
Bruno Randolf1008e0f2008-01-18 21:51:19 +09002600 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2601 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002602 }
2603
2604 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2605
2606 /*
2607 * Set the beacon register and enable all timers.
2608 * (next beacon, DMA beacon, software beacon, ATIM window time)
2609 */
2610 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2611 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2612 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2613 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2614
2615 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2616 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2617 AR5K_BEACON);
2618}
2619
2620#if 0
2621/*
2622 * Set beacon timers
2623 */
2624int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2625 const struct ath5k_beacon_state *state)
2626{
2627 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2628
2629 /*
2630 * TODO: should be changed through *state
2631 * review struct ath5k_beacon_state struct
2632 *
2633 * XXX: These are used for cfp period bellow, are they
2634 * ok ? Is it O.K. for tsf here to be 0 or should we use
2635 * get_tsf ?
2636 */
2637 u32 dtim_count = 0; /* XXX */
2638 u32 cfp_count = 0; /* XXX */
2639 u32 tsf = 0; /* XXX */
2640
2641 ATH5K_TRACE(ah->ah_sc);
2642 /* Return on an invalid beacon state */
2643 if (state->bs_interval < 1)
2644 return -EINVAL;
2645
2646 interval = state->bs_interval;
2647 dtim = state->bs_dtim_period;
2648
2649 /*
2650 * PCF support?
2651 */
2652 if (state->bs_cfp_period > 0) {
2653 /*
2654 * Enable PCF mode and set the CFP
2655 * (Contention Free Period) and timer registers
2656 */
2657 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2658 state->bs_interval;
2659 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2660 state->bs_interval;
2661
2662 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2663 AR5K_STA_ID1_DEFAULT_ANTENNA |
2664 AR5K_STA_ID1_PCF);
2665 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2666 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2667 AR5K_CFP_DUR);
2668 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2669 next_cfp)) << 3, AR5K_TIMER2);
2670 } else {
2671 /* Disable PCF mode */
2672 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2673 AR5K_STA_ID1_DEFAULT_ANTENNA |
2674 AR5K_STA_ID1_PCF);
2675 }
2676
2677 /*
2678 * Enable the beacon timer register
2679 */
2680 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2681
2682 /*
2683 * Start the beacon timers
2684 */
2685 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2686 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2687 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2688 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2689 AR5K_BEACON_PERIOD), AR5K_BEACON);
2690
2691 /*
2692 * Write new beacon miss threshold, if it appears to be valid
2693 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2694 * and return if its not in range. We can test this by reading value and
2695 * setting value to a largest value and seeing which values register.
2696 */
2697
2698 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2699 state->bs_bmiss_threshold);
2700
2701 /*
2702 * Set sleep control register
2703 * XXX: Didn't find this in 5210 code but since this register
2704 * exists also in ar5k's 5210 headers i leave it as common code.
2705 */
2706 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2707 (state->bs_sleep_duration - 3) << 3);
2708
2709 /*
2710 * Set enhanced sleep registers on 5212
2711 */
2712 if (ah->ah_version == AR5K_AR5212) {
2713 if (state->bs_sleep_duration > state->bs_interval &&
2714 roundup(state->bs_sleep_duration, interval) ==
2715 state->bs_sleep_duration)
2716 interval = state->bs_sleep_duration;
2717
2718 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2719 roundup(state->bs_sleep_duration, dtim) ==
2720 state->bs_sleep_duration))
2721 dtim = state->bs_sleep_duration;
2722
2723 if (interval > dtim)
2724 return -EINVAL;
2725
2726 next_beacon = interval == dtim ? state->bs_next_dtim :
2727 state->bs_next_beacon;
2728
2729 ath5k_hw_reg_write(ah,
2730 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2731 AR5K_SLEEP0_NEXT_DTIM) |
2732 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2733 AR5K_SLEEP0_ENH_SLEEP_EN |
2734 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2735
2736 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2737 AR5K_SLEEP1_NEXT_TIM) |
2738 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2739
2740 ath5k_hw_reg_write(ah,
2741 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2742 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2743 }
2744
2745 return 0;
2746}
2747
2748/*
2749 * Reset beacon timers
2750 */
2751void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2752{
2753 ATH5K_TRACE(ah->ah_sc);
2754 /*
2755 * Disable beacon timer
2756 */
2757 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2758
2759 /*
2760 * Disable some beacon register values
2761 */
2762 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2763 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2764 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2765}
2766
2767/*
2768 * Wait for beacon queue to finish
2769 */
2770int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2771{
2772 unsigned int i;
2773 int ret;
2774
2775 ATH5K_TRACE(ah->ah_sc);
2776
2777 /* 5210 doesn't have QCU*/
2778 if (ah->ah_version == AR5K_AR5210) {
2779 /*
2780 * Wait for beaconn queue to finish by checking
2781 * Control Register and Beacon Status Register.
2782 */
2783 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2784 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2785 ||
2786 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2787 break;
2788 udelay(10);
2789 }
2790
2791 /* Timeout... */
2792 if (i <= 0) {
2793 /*
2794 * Re-schedule the beacon queue
2795 */
2796 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2797 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2798 AR5K_BCR);
2799
2800 return -EIO;
2801 }
2802 ret = 0;
2803 } else {
2804 /*5211/5212*/
2805 ret = ath5k_hw_register_timeout(ah,
2806 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2807 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2808
2809 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2810 return -EIO;
2811 }
2812
2813 return ret;
2814}
2815#endif
2816
2817/*
2818 * Update mib counters (statistics)
2819 */
2820void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
2821 struct ath5k_mib_stats *statistics)
2822{
2823 ATH5K_TRACE(ah->ah_sc);
2824 /* Read-And-Clear */
2825 statistics->ackrcv_bad += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2826 statistics->rts_bad += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2827 statistics->rts_good += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2828 statistics->fcs_bad += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2829 statistics->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
2830
2831 /* Reset profile count registers on 5212*/
2832 if (ah->ah_version == AR5K_AR5212) {
2833 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2834 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2835 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2836 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2837 }
2838}
2839
2840/** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
2841 *
2842 * @ah: the &struct ath5k_hw
2843 * @high: determines if to use low bit rate or now
2844 */
2845void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
2846{
2847 if (ah->ah_version != AR5K_AR5212)
2848 return;
2849 else {
2850 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
2851 if (high)
2852 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
2853 else
2854 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
2855 }
2856}
2857
2858
2859/*
2860 * ACK/CTS Timeouts
2861 */
2862
2863/*
2864 * Set ACK timeout on PCU
2865 */
2866int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
2867{
2868 ATH5K_TRACE(ah->ah_sc);
2869 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
2870 ah->ah_turbo) <= timeout)
2871 return -EINVAL;
2872
2873 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
2874 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2875
2876 return 0;
2877}
2878
2879/*
2880 * Read the ACK timeout from PCU
2881 */
2882unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
2883{
2884 ATH5K_TRACE(ah->ah_sc);
2885
2886 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2887 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
2888}
2889
2890/*
2891 * Set CTS timeout on PCU
2892 */
2893int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
2894{
2895 ATH5K_TRACE(ah->ah_sc);
2896 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
2897 ah->ah_turbo) <= timeout)
2898 return -EINVAL;
2899
2900 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
2901 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2902
2903 return 0;
2904}
2905
2906/*
2907 * Read CTS timeout from PCU
2908 */
2909unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
2910{
2911 ATH5K_TRACE(ah->ah_sc);
2912 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2913 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
2914}
2915
2916/*
2917 * Key table (WEP) functions
2918 */
2919
2920int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
2921{
2922 unsigned int i;
2923
2924 ATH5K_TRACE(ah->ah_sc);
2925 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2926
2927 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
2928 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
2929
2930 /* Set NULL encryption on non-5210*/
2931 if (ah->ah_version != AR5K_AR5210)
2932 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
2933 AR5K_KEYTABLE_TYPE(entry));
2934
2935 return 0;
2936}
2937
2938int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
2939{
2940 ATH5K_TRACE(ah->ah_sc);
2941 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2942
2943 /* Check the validation flag at the end of the entry */
2944 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
2945 AR5K_KEYTABLE_VALID;
2946}
2947
2948int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
2949 const struct ieee80211_key_conf *key, const u8 *mac)
2950{
2951 unsigned int i;
2952 __le32 key_v[5] = {};
2953 u32 keytype;
2954
2955 ATH5K_TRACE(ah->ah_sc);
2956
2957 /* key->keylen comes in from mac80211 in bytes */
2958
2959 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
2960 return -EOPNOTSUPP;
2961
2962 switch (key->keylen) {
2963 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
2964 case 40 / 8:
2965 memcpy(&key_v[0], key->key, 5);
2966 keytype = AR5K_KEYTABLE_TYPE_40;
2967 break;
2968
2969 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
2970 case 104 / 8:
2971 memcpy(&key_v[0], &key->key[0], 6);
2972 memcpy(&key_v[2], &key->key[6], 6);
2973 memcpy(&key_v[4], &key->key[12], 1);
2974 keytype = AR5K_KEYTABLE_TYPE_104;
2975 break;
2976 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
2977 case 128 / 8:
2978 memcpy(&key_v[0], &key->key[0], 6);
2979 memcpy(&key_v[2], &key->key[6], 6);
2980 memcpy(&key_v[4], &key->key[12], 4);
2981 keytype = AR5K_KEYTABLE_TYPE_128;
2982 break;
2983
2984 default:
2985 return -EINVAL; /* shouldn't happen */
2986 }
2987
2988 for (i = 0; i < ARRAY_SIZE(key_v); i++)
2989 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
2990 AR5K_KEYTABLE_OFF(entry, i));
2991
2992 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
2993
2994 return ath5k_hw_set_key_lladdr(ah, entry, mac);
2995}
2996
2997int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
2998{
2999 u32 low_id, high_id;
3000
3001 ATH5K_TRACE(ah->ah_sc);
3002 /* Invalid entry (key table overflow) */
3003 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3004
3005 /* MAC may be NULL if it's a broadcast key. In this case no need to
3006 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3007 if (unlikely(mac == NULL)) {
3008 low_id = 0xffffffff;
3009 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3010 } else {
3011 low_id = AR5K_LOW_ID(mac);
3012 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3013 }
3014
3015 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3016 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3017
3018 return 0;
3019}
3020
3021
3022/********************************************\
3023Queue Control Unit, DFS Control Unit Functions
3024\********************************************/
3025
3026/*
3027 * Initialize a transmit queue
3028 */
3029int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3030 struct ath5k_txq_info *queue_info)
3031{
3032 unsigned int queue;
3033 int ret;
3034
3035 ATH5K_TRACE(ah->ah_sc);
3036
3037 /*
3038 * Get queue by type
3039 */
3040 /*5210 only has 2 queues*/
3041 if (ah->ah_version == AR5K_AR5210) {
3042 switch (queue_type) {
3043 case AR5K_TX_QUEUE_DATA:
3044 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3045 break;
3046 case AR5K_TX_QUEUE_BEACON:
3047 case AR5K_TX_QUEUE_CAB:
3048 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3049 break;
3050 default:
3051 return -EINVAL;
3052 }
3053 } else {
3054 switch (queue_type) {
3055 case AR5K_TX_QUEUE_DATA:
3056 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3057 ah->ah_txq[queue].tqi_type !=
3058 AR5K_TX_QUEUE_INACTIVE; queue++) {
3059
3060 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3061 return -EINVAL;
3062 }
3063 break;
3064 case AR5K_TX_QUEUE_UAPSD:
3065 queue = AR5K_TX_QUEUE_ID_UAPSD;
3066 break;
3067 case AR5K_TX_QUEUE_BEACON:
3068 queue = AR5K_TX_QUEUE_ID_BEACON;
3069 break;
3070 case AR5K_TX_QUEUE_CAB:
3071 queue = AR5K_TX_QUEUE_ID_CAB;
3072 break;
3073 case AR5K_TX_QUEUE_XR_DATA:
3074 if (ah->ah_version != AR5K_AR5212)
3075 ATH5K_ERR(ah->ah_sc,
3076 "XR data queues only supported in"
3077 " 5212!\n");
3078 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3079 break;
3080 default:
3081 return -EINVAL;
3082 }
3083 }
3084
3085 /*
3086 * Setup internal queue structure
3087 */
3088 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3089 ah->ah_txq[queue].tqi_type = queue_type;
3090
3091 if (queue_info != NULL) {
3092 queue_info->tqi_type = queue_type;
3093 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3094 if (ret)
3095 return ret;
3096 }
3097 /*
3098 * We use ah_txq_status to hold a temp value for
3099 * the Secondary interrupt mask registers on 5211+
3100 * check out ath5k_hw_reset_tx_queue
3101 */
3102 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3103
3104 return queue;
3105}
3106
3107/*
3108 * Setup a transmit queue
3109 */
3110int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3111 const struct ath5k_txq_info *queue_info)
3112{
3113 ATH5K_TRACE(ah->ah_sc);
3114 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3115
3116 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3117 return -EIO;
3118
3119 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3120
3121 /*XXX: Is this supported on 5210 ?*/
3122 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3123 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3124 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3125 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3126 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3127
3128 return 0;
3129}
3130
3131/*
3132 * Get properties for a specific transmit queue
3133 */
3134int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3135 struct ath5k_txq_info *queue_info)
3136{
3137 ATH5K_TRACE(ah->ah_sc);
3138 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3139 return 0;
3140}
3141
3142/*
3143 * Set a transmit queue inactive
3144 */
3145void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3146{
3147 ATH5K_TRACE(ah->ah_sc);
3148 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3149 return;
3150
3151 /* This queue will be skipped in further operations */
3152 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3153 /*For SIMR setup*/
3154 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3155}
3156
3157/*
3158 * Set DFS params for a transmit queue
3159 */
3160int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3161{
3162 u32 cw_min, cw_max, retry_lg, retry_sh;
3163 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3164
3165 ATH5K_TRACE(ah->ah_sc);
3166 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3167
3168 tq = &ah->ah_txq[queue];
3169
3170 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3171 return 0;
3172
3173 if (ah->ah_version == AR5K_AR5210) {
3174 /* Only handle data queues, others will be ignored */
3175 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3176 return 0;
3177
3178 /* Set Slot time */
3179 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3180 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3181 AR5K_SLOT_TIME);
3182 /* Set ACK_CTS timeout */
3183 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3184 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3185 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3186 /* Set Transmit Latency */
3187 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3188 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3189 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3190 /* Set IFS0 */
3191 if (ah->ah_turbo == true)
3192 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3193 (ah->ah_aifs + tq->tqi_aifs) *
3194 AR5K_INIT_SLOT_TIME_TURBO) <<
3195 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3196 AR5K_IFS0);
3197 else
3198 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3199 (ah->ah_aifs + tq->tqi_aifs) *
3200 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3201 AR5K_INIT_SIFS, AR5K_IFS0);
3202
3203 /* Set IFS1 */
3204 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3205 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3206 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3207 /* Set PHY register 0x9844 (??) */
3208 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3209 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
3210 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
3211 AR5K_PHY(17));
3212 /* Set Frame Control Register */
3213 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3214 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3215 AR5K_PHY_TURBO_SHORT | 0x2020) :
3216 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3217 AR5K_PHY_FRAME_CTL_5210);
3218 }
3219
3220 /*
3221 * Calculate cwmin/max by channel mode
3222 */
3223 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3224 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3225 ah->ah_aifs = AR5K_TUNE_AIFS;
3226 /*XR is only supported on 5212*/
3227 if (IS_CHAN_XR(ah->ah_current_channel) &&
3228 ah->ah_version == AR5K_AR5212) {
3229 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3230 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3231 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3232 /*B mode is not supported on 5210*/
3233 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3234 ah->ah_version != AR5K_AR5210) {
3235 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3236 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3237 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3238 }
3239
3240 cw_min = 1;
3241 while (cw_min < ah->ah_cw_min)
3242 cw_min = (cw_min << 1) | 1;
3243
3244 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3245 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3246 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3247 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3248
3249 /*
3250 * Calculate and set retry limits
3251 */
3252 if (ah->ah_software_retry == true) {
3253 /* XXX Need to test this */
3254 retry_lg = ah->ah_limit_tx_retries;
3255 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3256 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3257 } else {
3258 retry_lg = AR5K_INIT_LG_RETRY;
3259 retry_sh = AR5K_INIT_SH_RETRY;
3260 }
3261
3262 /*No QCU/DCU [5210]*/
3263 if (ah->ah_version == AR5K_AR5210) {
3264 ath5k_hw_reg_write(ah,
3265 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3266 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3267 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3268 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3269 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3270 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3271 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3272 AR5K_NODCU_RETRY_LMT);
3273 } else {
3274 /*QCU/DCU [5211+]*/
3275 ath5k_hw_reg_write(ah,
3276 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3277 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3278 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3279 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3280 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3281 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3282 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3283
3284 /*===Rest is also for QCU/DCU only [5211+]===*/
3285
3286 /*
3287 * Set initial content window (cw_min/cw_max)
3288 * and arbitrated interframe space (aifs)...
3289 */
3290 ath5k_hw_reg_write(ah,
3291 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3292 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3293 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3294 AR5K_DCU_LCL_IFS_AIFS),
3295 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3296
3297 /*
3298 * Set misc registers
3299 */
3300 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3301 AR5K_QUEUE_MISC(queue));
3302
3303 if (tq->tqi_cbr_period) {
3304 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3305 AR5K_QCU_CBRCFG_INTVAL) |
3306 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3307 AR5K_QCU_CBRCFG_ORN_THRES),
3308 AR5K_QUEUE_CBRCFG(queue));
3309 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3310 AR5K_QCU_MISC_FRSHED_CBR);
3311 if (tq->tqi_cbr_overflow_limit)
3312 AR5K_REG_ENABLE_BITS(ah,
3313 AR5K_QUEUE_MISC(queue),
3314 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3315 }
3316
3317 if (tq->tqi_ready_time)
3318 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3319 AR5K_QCU_RDYTIMECFG_INTVAL) |
3320 AR5K_QCU_RDYTIMECFG_ENABLE,
3321 AR5K_QUEUE_RDYTIMECFG(queue));
3322
3323 if (tq->tqi_burst_time) {
3324 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3325 AR5K_DCU_CHAN_TIME_DUR) |
3326 AR5K_DCU_CHAN_TIME_ENABLE,
3327 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3328
3329 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3330 AR5K_REG_ENABLE_BITS(ah,
3331 AR5K_QUEUE_MISC(queue),
3332 AR5K_QCU_MISC_TXE);
3333 }
3334
3335 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3336 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3337 AR5K_QUEUE_DFS_MISC(queue));
3338
3339 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3340 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3341 AR5K_QUEUE_DFS_MISC(queue));
3342
3343 /*
3344 * Set registers by queue type
3345 */
3346 switch (tq->tqi_type) {
3347 case AR5K_TX_QUEUE_BEACON:
3348 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3349 AR5K_QCU_MISC_FRSHED_DBA_GT |
3350 AR5K_QCU_MISC_CBREXP_BCN |
3351 AR5K_QCU_MISC_BCN_ENABLE);
3352
3353 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3354 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3355 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3356 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3357 AR5K_DCU_MISC_BCN_ENABLE);
3358
3359 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3360 (AR5K_TUNE_SW_BEACON_RESP -
3361 AR5K_TUNE_DMA_BEACON_RESP) -
3362 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3363 AR5K_QCU_RDYTIMECFG_ENABLE,
3364 AR5K_QUEUE_RDYTIMECFG(queue));
3365 break;
3366
3367 case AR5K_TX_QUEUE_CAB:
3368 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3369 AR5K_QCU_MISC_FRSHED_DBA_GT |
3370 AR5K_QCU_MISC_CBREXP |
3371 AR5K_QCU_MISC_CBREXP_BCN);
3372
3373 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3374 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3375 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3376 break;
3377
3378 case AR5K_TX_QUEUE_UAPSD:
3379 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3380 AR5K_QCU_MISC_CBREXP);
3381 break;
3382
3383 case AR5K_TX_QUEUE_DATA:
3384 default:
3385 break;
3386 }
3387
3388 /*
3389 * Enable interrupts for this tx queue
3390 * in the secondary interrupt mask registers
3391 */
3392 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3393 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3394
3395 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3396 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3397
3398 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3399 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3400
3401 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3402 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3403
3404 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3405 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3406
3407
3408 /* Update secondary interrupt mask registers */
3409 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3410 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3411 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3412 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3413 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3414
3415 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3416 AR5K_SIMR0_QCU_TXOK) |
3417 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3418 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3419 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3420 AR5K_SIMR1_QCU_TXERR) |
3421 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3422 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3423 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3424 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3425 }
3426
3427 return 0;
3428}
3429
3430/*
3431 * Get number of pending frames
3432 * for a specific queue [5211+]
3433 */
3434u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3435 ATH5K_TRACE(ah->ah_sc);
3436 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3437
3438 /* Return if queue is declared inactive */
3439 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3440 return false;
3441
3442 /* XXX: How about AR5K_CFG_TXCNT ? */
3443 if (ah->ah_version == AR5K_AR5210)
3444 return false;
3445
3446 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3447}
3448
3449/*
3450 * Set slot time
3451 */
3452int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3453{
3454 ATH5K_TRACE(ah->ah_sc);
3455 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3456 return -EINVAL;
3457
3458 if (ah->ah_version == AR5K_AR5210)
3459 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3460 ah->ah_turbo), AR5K_SLOT_TIME);
3461 else
3462 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3463
3464 return 0;
3465}
3466
3467/*
3468 * Get slot time
3469 */
3470unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3471{
3472 ATH5K_TRACE(ah->ah_sc);
3473 if (ah->ah_version == AR5K_AR5210)
3474 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3475 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3476 else
3477 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3478}
3479
3480
3481/******************************\
3482 Hardware Descriptor Functions
3483\******************************/
3484
3485/*
3486 * TX Descriptor
3487 */
3488
3489/*
3490 * Initialize the 2-word tx descriptor on 5210/5211
3491 */
3492static int
3493ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3494 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3495 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3496 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3497 unsigned int rtscts_rate, unsigned int rtscts_duration)
3498{
3499 u32 frame_type;
3500 struct ath5k_hw_2w_tx_desc *tx_desc;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003501 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003502
3503 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3504
3505 /*
3506 * Validate input
3507 * - Zero retries don't make sense.
3508 * - A zero rate will put the HW into a mode where it continously sends
3509 * noise on the channel, so it is important to avoid this.
3510 */
3511 if (unlikely(tx_tries0 == 0)) {
3512 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3513 WARN_ON(1);
3514 return -EINVAL;
3515 }
3516 if (unlikely(tx_rate0 == 0)) {
3517 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3518 WARN_ON(1);
3519 return -EINVAL;
3520 }
3521
3522 /* Clear status descriptor */
3523 memset(desc->ds_hw, 0, sizeof(struct ath5k_hw_tx_status));
3524
3525 /* Initialize control descriptor */
3526 tx_desc->tx_control_0 = 0;
3527 tx_desc->tx_control_1 = 0;
3528
3529 /* Setup control descriptor */
3530
3531 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003532
3533 /* remove padding we might have added before */
3534 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3535
3536 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003537 return -EINVAL;
3538
Bruno Randolf281c56d2008-02-05 18:44:55 +09003539 tx_desc->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003540
3541 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003542
3543 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3544 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003545 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003546
Bruno Randolf281c56d2008-02-05 18:44:55 +09003547 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003548 return -EINVAL;
3549
Bruno Randolf281c56d2008-02-05 18:44:55 +09003550 tx_desc->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003551
3552 /*
3553 * Verify and set header length
3554 * XXX: I only found that on 5210 code, does it work on 5211 ?
3555 */
3556 if (ah->ah_version == AR5K_AR5210) {
3557 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3558 return -EINVAL;
3559 tx_desc->tx_control_0 |=
3560 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3561 }
3562
3563 /*Diferences between 5210-5211*/
3564 if (ah->ah_version == AR5K_AR5210) {
3565 switch (type) {
3566 case AR5K_PKT_TYPE_BEACON:
3567 case AR5K_PKT_TYPE_PROBE_RESP:
3568 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3569 case AR5K_PKT_TYPE_PIFS:
3570 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3571 default:
3572 frame_type = type /*<< 2 ?*/;
3573 }
3574
3575 tx_desc->tx_control_0 |=
3576 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3577 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3578 } else {
3579 tx_desc->tx_control_0 |=
3580 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3581 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3582 tx_desc->tx_control_1 |=
3583 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3584 }
3585#define _TX_FLAGS(_c, _flag) \
3586 if (flags & AR5K_TXDESC_##_flag) \
3587 tx_desc->tx_control_##_c |= \
3588 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3589
3590 _TX_FLAGS(0, CLRDMASK);
3591 _TX_FLAGS(0, VEOL);
3592 _TX_FLAGS(0, INTREQ);
3593 _TX_FLAGS(0, RTSENA);
3594 _TX_FLAGS(1, NOACK);
3595
3596#undef _TX_FLAGS
3597
3598 /*
3599 * WEP crap
3600 */
3601 if (key_index != AR5K_TXKEYIX_INVALID) {
3602 tx_desc->tx_control_0 |=
3603 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3604 tx_desc->tx_control_1 |=
3605 AR5K_REG_SM(key_index,
3606 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3607 }
3608
3609 /*
3610 * RTS/CTS Duration [5210 ?]
3611 */
3612 if ((ah->ah_version == AR5K_AR5210) &&
3613 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3614 tx_desc->tx_control_1 |= rtscts_duration &
3615 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3616
3617 return 0;
3618}
3619
3620/*
3621 * Initialize the 4-word tx descriptor on 5212
3622 */
3623static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3624 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3625 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3626 unsigned int tx_tries0, unsigned int key_index,
3627 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3628 unsigned int rtscts_duration)
3629{
3630 struct ath5k_hw_4w_tx_desc *tx_desc;
3631 struct ath5k_hw_tx_status *tx_status;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003632 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003633
3634 ATH5K_TRACE(ah->ah_sc);
3635 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3636 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3637
3638 /*
3639 * Validate input
3640 * - Zero retries don't make sense.
3641 * - A zero rate will put the HW into a mode where it continously sends
3642 * noise on the channel, so it is important to avoid this.
3643 */
3644 if (unlikely(tx_tries0 == 0)) {
3645 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3646 WARN_ON(1);
3647 return -EINVAL;
3648 }
3649 if (unlikely(tx_rate0 == 0)) {
3650 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3651 WARN_ON(1);
3652 return -EINVAL;
3653 }
3654
3655 /* Clear status descriptor */
3656 memset(tx_status, 0, sizeof(struct ath5k_hw_tx_status));
3657
3658 /* Initialize control descriptor */
3659 tx_desc->tx_control_0 = 0;
3660 tx_desc->tx_control_1 = 0;
3661 tx_desc->tx_control_2 = 0;
3662 tx_desc->tx_control_3 = 0;
3663
3664 /* Setup control descriptor */
3665
3666 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003667
3668 /* remove padding we might have added before */
3669 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3670
3671 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003672 return -EINVAL;
3673
Bruno Randolf281c56d2008-02-05 18:44:55 +09003674 tx_desc->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003675
3676 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003677
3678 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3679 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003680 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003681
Bruno Randolf281c56d2008-02-05 18:44:55 +09003682 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003683 return -EINVAL;
3684
Bruno Randolf281c56d2008-02-05 18:44:55 +09003685 tx_desc->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003686
3687 tx_desc->tx_control_0 |=
3688 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3689 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3690 tx_desc->tx_control_1 |= AR5K_REG_SM(type,
3691 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3692 tx_desc->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3693 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3694 tx_desc->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3695
3696#define _TX_FLAGS(_c, _flag) \
3697 if (flags & AR5K_TXDESC_##_flag) \
3698 tx_desc->tx_control_##_c |= \
3699 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3700
3701 _TX_FLAGS(0, CLRDMASK);
3702 _TX_FLAGS(0, VEOL);
3703 _TX_FLAGS(0, INTREQ);
3704 _TX_FLAGS(0, RTSENA);
3705 _TX_FLAGS(0, CTSENA);
3706 _TX_FLAGS(1, NOACK);
3707
3708#undef _TX_FLAGS
3709
3710 /*
3711 * WEP crap
3712 */
3713 if (key_index != AR5K_TXKEYIX_INVALID) {
3714 tx_desc->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3715 tx_desc->tx_control_1 |= AR5K_REG_SM(key_index,
3716 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3717 }
3718
3719 /*
3720 * RTS/CTS
3721 */
3722 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3723 if ((flags & AR5K_TXDESC_RTSENA) &&
3724 (flags & AR5K_TXDESC_CTSENA))
3725 return -EINVAL;
3726 tx_desc->tx_control_2 |= rtscts_duration &
3727 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3728 tx_desc->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3729 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3730 }
3731
3732 return 0;
3733}
3734
3735/*
3736 * Initialize a 4-word multirate tx descriptor on 5212
3737 */
Jiri Slabyb9887632008-02-15 21:58:52 +01003738static int
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003739ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3740 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3741 unsigned int tx_rate3, u_int tx_tries3)
3742{
3743 struct ath5k_hw_4w_tx_desc *tx_desc;
3744
3745 /*
3746 * Rates can be 0 as long as the retry count is 0 too.
3747 * A zero rate and nonzero retry count will put the HW into a mode where
3748 * it continously sends noise on the channel, so it is important to
3749 * avoid this.
3750 */
3751 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3752 (tx_rate2 == 0 && tx_tries2 != 0) ||
3753 (tx_rate3 == 0 && tx_tries3 != 0))) {
3754 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3755 WARN_ON(1);
3756 return -EINVAL;
3757 }
3758
3759 if (ah->ah_version == AR5K_AR5212) {
3760 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3761
3762#define _XTX_TRIES(_n) \
3763 if (tx_tries##_n) { \
3764 tx_desc->tx_control_2 |= \
3765 AR5K_REG_SM(tx_tries##_n, \
3766 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3767 tx_desc->tx_control_3 |= \
3768 AR5K_REG_SM(tx_rate##_n, \
3769 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3770 }
3771
3772 _XTX_TRIES(1);
3773 _XTX_TRIES(2);
3774 _XTX_TRIES(3);
3775
3776#undef _XTX_TRIES
3777
Jiri Slabyb9887632008-02-15 21:58:52 +01003778 return 1;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003779 }
3780
Jiri Slabyb9887632008-02-15 21:58:52 +01003781 return 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003782}
3783
3784/*
3785 * Proccess the tx status descriptor on 5210/5211
3786 */
3787static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3788 struct ath5k_desc *desc)
3789{
3790 struct ath5k_hw_tx_status *tx_status;
3791 struct ath5k_hw_2w_tx_desc *tx_desc;
3792
3793 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3794 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[0];
3795
3796 /* No frame has been send or error */
3797 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3798 return -EINPROGRESS;
3799
3800 /*
3801 * Get descriptor status
3802 */
3803 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3804 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3805 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3806 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3807 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3808 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3809 /*TODO: desc->ds_us.tx.ts_virtcol + test*/
3810 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3811 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3812 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3813 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3814 desc->ds_us.tx.ts_antenna = 1;
3815 desc->ds_us.tx.ts_status = 0;
3816 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_0,
3817 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3818
3819 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3820 if (tx_status->tx_status_0 &
3821 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3822 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3823
3824 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3825 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3826
3827 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3828 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3829 }
3830
3831 return 0;
3832}
3833
3834/*
3835 * Proccess a tx descriptor on 5212
3836 */
3837static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
3838 struct ath5k_desc *desc)
3839{
3840 struct ath5k_hw_tx_status *tx_status;
3841 struct ath5k_hw_4w_tx_desc *tx_desc;
3842
3843 ATH5K_TRACE(ah->ah_sc);
3844 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3845 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3846
3847 /* No frame has been send or error */
3848 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3849 return -EINPROGRESS;
3850
3851 /*
3852 * Get descriptor status
3853 */
3854 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3855 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3856 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3857 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3858 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3859 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3860 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3861 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3862 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3863 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3864 desc->ds_us.tx.ts_antenna = (tx_status->tx_status_1 &
3865 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
3866 desc->ds_us.tx.ts_status = 0;
3867
3868 switch (AR5K_REG_MS(tx_status->tx_status_1,
3869 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
3870 case 0:
3871 desc->ds_us.tx.ts_rate = tx_desc->tx_control_3 &
3872 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3873 break;
3874 case 1:
3875 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3876 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
3877 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3878 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
3879 break;
3880 case 2:
3881 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3882 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
3883 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3884 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
3885 break;
3886 case 3:
3887 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3888 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
3889 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3890 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
3891 break;
3892 }
3893
3894 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3895 if (tx_status->tx_status_0 &
3896 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3897 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3898
3899 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3900 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3901
3902 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3903 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3904 }
3905
3906 return 0;
3907}
3908
3909/*
3910 * RX Descriptor
3911 */
3912
3913/*
3914 * Initialize an rx descriptor
3915 */
3916int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3917 u32 size, unsigned int flags)
3918{
3919 struct ath5k_rx_desc *rx_desc;
3920
3921 ATH5K_TRACE(ah->ah_sc);
3922 rx_desc = (struct ath5k_rx_desc *)&desc->ds_ctl0;
3923
3924 /*
3925 *Clear ds_hw
3926 * If we don't clean the status descriptor,
3927 * while scanning we get too many results,
3928 * most of them virtual, after some secs
3929 * of scanning system hangs. M.F.
3930 */
3931 memset(desc->ds_hw, 0, sizeof(desc->ds_hw));
3932
3933 /*Initialize rx descriptor*/
3934 rx_desc->rx_control_0 = 0;
3935 rx_desc->rx_control_1 = 0;
3936
3937 /* Setup descriptor */
3938 rx_desc->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
3939 if (unlikely(rx_desc->rx_control_1 != size))
3940 return -EINVAL;
3941
3942 if (flags & AR5K_RXDESC_INTREQ)
3943 rx_desc->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
3944
3945 return 0;
3946}
3947
3948/*
3949 * Proccess the rx status descriptor on 5210/5211
3950 */
3951static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *ah,
3952 struct ath5k_desc *desc)
3953{
3954 struct ath5k_hw_old_rx_status *rx_status;
3955
3956 rx_status = (struct ath5k_hw_old_rx_status *)&desc->ds_hw[0];
3957
3958 /* No frame received / not ready */
3959 if (unlikely((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_DONE)
3960 == 0))
3961 return -EINPROGRESS;
3962
3963 /*
3964 * Frame receive status
3965 */
3966 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
3967 AR5K_OLD_RX_DESC_STATUS0_DATA_LEN;
3968 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
3969 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_SIGNAL);
3970 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
3971 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_RATE);
3972 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
3973 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_ANTENNA;
3974 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
3975 AR5K_OLD_RX_DESC_STATUS0_MORE;
3976 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
3977 AR5K_OLD_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
3978 desc->ds_us.rx.rs_status = 0;
3979
3980 /*
3981 * Key table status
3982 */
3983 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX_VALID)
3984 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
3985 AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX);
3986 else
3987 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
3988
3989 /*
3990 * Receive/descriptor errors
3991 */
3992 if ((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_FRAME_RECEIVE_OK)
3993 == 0) {
3994 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_CRC_ERROR)
3995 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
3996
3997 if (rx_status->rx_status_1 &
3998 AR5K_OLD_RX_DESC_STATUS1_FIFO_OVERRUN)
3999 desc->ds_us.rx.rs_status |= AR5K_RXERR_FIFO;
4000
4001 if (rx_status->rx_status_1 &
4002 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR) {
4003 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
4004 desc->ds_us.rx.rs_phyerr =
4005 AR5K_REG_MS(rx_status->rx_status_1,
4006 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR);
4007 }
4008
4009 if (rx_status->rx_status_1 &
4010 AR5K_OLD_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4011 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
4012 }
4013
4014 return 0;
4015}
4016
4017/*
4018 * Proccess the rx status descriptor on 5212
4019 */
4020static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *ah,
4021 struct ath5k_desc *desc)
4022{
4023 struct ath5k_hw_new_rx_status *rx_status;
4024 struct ath5k_hw_rx_error *rx_err;
4025
4026 ATH5K_TRACE(ah->ah_sc);
4027 rx_status = (struct ath5k_hw_new_rx_status *)&desc->ds_hw[0];
4028
4029 /* Overlay on error */
4030 rx_err = (struct ath5k_hw_rx_error *)&desc->ds_hw[0];
4031
4032 /* No frame received / not ready */
4033 if (unlikely((rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_DONE)
4034 == 0))
4035 return -EINPROGRESS;
4036
4037 /*
4038 * Frame receive status
4039 */
4040 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
4041 AR5K_NEW_RX_DESC_STATUS0_DATA_LEN;
4042 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4043 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4044 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4045 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_RATE);
4046 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
4047 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4048 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
4049 AR5K_NEW_RX_DESC_STATUS0_MORE;
4050 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4051 AR5K_NEW_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4052 desc->ds_us.rx.rs_status = 0;
4053
4054 /*
4055 * Key table status
4056 */
4057 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX_VALID)
4058 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4059 AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX);
4060 else
4061 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
4062
4063 /*
4064 * Receive/descriptor errors
4065 */
4066 if ((rx_status->rx_status_1 &
4067 AR5K_NEW_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4068 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_CRC_ERROR)
4069 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
4070
4071 if (rx_status->rx_status_1 &
4072 AR5K_NEW_RX_DESC_STATUS1_PHY_ERROR) {
4073 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
4074 desc->ds_us.rx.rs_phyerr =
4075 AR5K_REG_MS(rx_err->rx_error_1,
4076 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4077 }
4078
4079 if (rx_status->rx_status_1 &
4080 AR5K_NEW_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4081 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
4082
4083 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_MIC_ERROR)
4084 desc->ds_us.rx.rs_status |= AR5K_RXERR_MIC;
4085 }
4086
4087 return 0;
4088}
4089
4090
4091/****************\
4092 GPIO Functions
4093\****************/
4094
4095/*
4096 * Set led state
4097 */
4098void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4099{
4100 u32 led;
4101 /*5210 has different led mode handling*/
4102 u32 led_5210;
4103
4104 ATH5K_TRACE(ah->ah_sc);
4105
4106 /*Reset led status*/
4107 if (ah->ah_version != AR5K_AR5210)
4108 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4109 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4110 else
4111 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4112
4113 /*
4114 * Some blinking values, define at your wish
4115 */
4116 switch (state) {
4117 case AR5K_LED_SCAN:
4118 case AR5K_LED_AUTH:
4119 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4120 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4121 break;
4122
4123 case AR5K_LED_INIT:
4124 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4125 led_5210 = AR5K_PCICFG_LED_PEND;
4126 break;
4127
4128 case AR5K_LED_ASSOC:
4129 case AR5K_LED_RUN:
4130 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4131 led_5210 = AR5K_PCICFG_LED_ASSOC;
4132 break;
4133
4134 default:
4135 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4136 led_5210 = AR5K_PCICFG_LED_PEND;
4137 break;
4138 }
4139
4140 /*Write new status to the register*/
4141 if (ah->ah_version != AR5K_AR5210)
4142 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4143 else
4144 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4145}
4146
4147/*
4148 * Set GPIO outputs
4149 */
4150int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4151{
4152 ATH5K_TRACE(ah->ah_sc);
4153 if (gpio > AR5K_NUM_GPIO)
4154 return -EINVAL;
4155
4156 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4157 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4158
4159 return 0;
4160}
4161
4162/*
4163 * Set GPIO inputs
4164 */
4165int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4166{
4167 ATH5K_TRACE(ah->ah_sc);
4168 if (gpio > AR5K_NUM_GPIO)
4169 return -EINVAL;
4170
4171 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4172 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4173
4174 return 0;
4175}
4176
4177/*
4178 * Get GPIO state
4179 */
4180u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4181{
4182 ATH5K_TRACE(ah->ah_sc);
4183 if (gpio > AR5K_NUM_GPIO)
4184 return 0xffffffff;
4185
4186 /* GPIO input magic */
4187 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4188 0x1;
4189}
4190
4191/*
4192 * Set GPIO state
4193 */
4194int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4195{
4196 u32 data;
4197 ATH5K_TRACE(ah->ah_sc);
4198
4199 if (gpio > AR5K_NUM_GPIO)
4200 return -EINVAL;
4201
4202 /* GPIO output magic */
4203 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4204
4205 data &= ~(1 << gpio);
4206 data |= (val & 1) << gpio;
4207
4208 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4209
4210 return 0;
4211}
4212
4213/*
4214 * Initialize the GPIO interrupt (RFKill switch)
4215 */
4216void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4217 u32 interrupt_level)
4218{
4219 u32 data;
4220
4221 ATH5K_TRACE(ah->ah_sc);
4222 if (gpio > AR5K_NUM_GPIO)
4223 return;
4224
4225 /*
4226 * Set the GPIO interrupt
4227 */
4228 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4229 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4230 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4231 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4232
4233 ath5k_hw_reg_write(ah, interrupt_level ? data :
4234 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4235
4236 ah->ah_imr |= AR5K_IMR_GPIO;
4237
4238 /* Enable GPIO interrupts */
4239 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4240}
4241
4242
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004243
4244
4245/****************\
4246 Misc functions
4247\****************/
4248
4249int ath5k_hw_get_capability(struct ath5k_hw *ah,
4250 enum ath5k_capability_type cap_type,
4251 u32 capability, u32 *result)
4252{
4253 ATH5K_TRACE(ah->ah_sc);
4254
4255 switch (cap_type) {
4256 case AR5K_CAP_NUM_TXQUEUES:
4257 if (result) {
4258 if (ah->ah_version == AR5K_AR5210)
4259 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4260 else
4261 *result = AR5K_NUM_TX_QUEUES;
4262 goto yes;
4263 }
4264 case AR5K_CAP_VEOL:
4265 goto yes;
4266 case AR5K_CAP_COMPRESSION:
4267 if (ah->ah_version == AR5K_AR5212)
4268 goto yes;
4269 else
4270 goto no;
4271 case AR5K_CAP_BURST:
4272 goto yes;
4273 case AR5K_CAP_TPC:
4274 goto yes;
4275 case AR5K_CAP_BSSIDMASK:
4276 if (ah->ah_version == AR5K_AR5212)
4277 goto yes;
4278 else
4279 goto no;
4280 case AR5K_CAP_XR:
4281 if (ah->ah_version == AR5K_AR5212)
4282 goto yes;
4283 else
4284 goto no;
4285 default:
4286 goto no;
4287 }
4288
4289no:
4290 return -EINVAL;
4291yes:
4292 return 0;
4293}
4294
4295static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4296 u16 assoc_id)
4297{
4298 ATH5K_TRACE(ah->ah_sc);
4299
4300 if (ah->ah_version == AR5K_AR5210) {
4301 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4302 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4303 return 0;
4304 }
4305
4306 return -EIO;
4307}
4308
4309static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4310{
4311 ATH5K_TRACE(ah->ah_sc);
4312
4313 if (ah->ah_version == AR5K_AR5210) {
4314 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4315 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4316 return 0;
4317 }
4318
4319 return -EIO;
4320}