blob: 3937e46e47350803b007c1c8aee42127de8e8822 [file] [log] [blame]
Joe Perchese9010e22008-03-07 14:21:16 -08001/*
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002 * 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
Pavel Macheke292c732008-06-25 12:25:53 +020034/* Rate tables */
Jiri Slabyfa1c1142007-08-12 17:33:16 +020035static 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
Pavel Macheke292c732008-06-25 12:25:53 +020041/* Prototypes */
Jiri Slabyfa1c1142007-08-12 17:33:16 +020042static 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);
Bruno Randolfb47f4072008-03-05 18:35:45 +090051static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
52 struct ath5k_tx_status *);
Jiri Slabyfa1c1142007-08-12 17:33:16 +020053static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
54 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
55 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
56 unsigned int, unsigned int);
Bruno Randolfb47f4072008-03-05 18:35:45 +090057static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
58 struct ath5k_tx_status *);
59static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *, struct ath5k_desc *,
60 struct ath5k_rx_status *);
61static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *, struct ath5k_desc *,
62 struct ath5k_rx_status *);
Jiri Slabyfa1c1142007-08-12 17:33:16 +020063static int ath5k_hw_get_capabilities(struct ath5k_hw *);
64
65static int ath5k_eeprom_init(struct ath5k_hw *);
66static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
67
68static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
69static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
70
71/*
72 * Enable to overwrite the country code (use "00" for debug)
73 */
74#if 0
75#define COUNTRYCODE "00"
76#endif
77
78/*******************\
79 General Functions
80\*******************/
81
82/*
83 * Functions used internaly
84 */
85
86static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
87{
Joe Perchese9010e22008-03-07 14:21:16 -080088 return turbo ? (usec * 80) : (usec * 40);
Jiri Slabyfa1c1142007-08-12 17:33:16 +020089}
90
91static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
92{
Joe Perchese9010e22008-03-07 14:21:16 -080093 return turbo ? (clock / 80) : (clock / 40);
Jiri Slabyfa1c1142007-08-12 17:33:16 +020094}
95
96/*
97 * Check if a register write has been completed
98 */
99int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
100 bool is_set)
101{
102 int i;
103 u32 data;
104
105 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
106 data = ath5k_hw_reg_read(ah, reg);
Joe Perchese9010e22008-03-07 14:21:16 -0800107 if (is_set && (data & flag))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200108 break;
109 else if ((data & flag) == val)
110 break;
111 udelay(15);
112 }
113
114 return (i <= 0) ? -EAGAIN : 0;
115}
116
117
118/***************************************\
119 Attach/Detach Functions
120\***************************************/
121
122/*
Nick Kossifidis194828a2008-04-16 18:49:02 +0300123 * Power On Self Test helper function
124 */
125static int ath5k_hw_post(struct ath5k_hw *ah)
126{
127
128 int i, c;
129 u16 cur_reg;
130 u16 regs[2] = {AR5K_STA_ID0, AR5K_PHY(8)};
131 u32 var_pattern;
132 u32 static_pattern[4] = {
133 0x55555555, 0xaaaaaaaa,
134 0x66666666, 0x99999999
135 };
136 u32 init_val;
137 u32 cur_val;
138
139 for (c = 0; c < 2; c++) {
140
141 cur_reg = regs[c];
Nick Kossifidisba377462008-07-20 06:32:32 +0300142
143 /* Save previous value */
Nick Kossifidis194828a2008-04-16 18:49:02 +0300144 init_val = ath5k_hw_reg_read(ah, cur_reg);
145
146 for (i = 0; i < 256; i++) {
147 var_pattern = i << 16 | i;
148 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
149 cur_val = ath5k_hw_reg_read(ah, cur_reg);
150
151 if (cur_val != var_pattern) {
152 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
153 return -EAGAIN;
154 }
155
156 /* Found on ndiswrapper dumps */
157 var_pattern = 0x0039080f;
158 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
159 }
160
161 for (i = 0; i < 4; i++) {
162 var_pattern = static_pattern[i];
163 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
164 cur_val = ath5k_hw_reg_read(ah, cur_reg);
165
166 if (cur_val != var_pattern) {
167 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
168 return -EAGAIN;
169 }
170
171 /* Found on ndiswrapper dumps */
172 var_pattern = 0x003b080f;
173 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
174 }
Nick Kossifidisba377462008-07-20 06:32:32 +0300175
176 /* Restore previous value */
177 ath5k_hw_reg_write(ah, init_val, cur_reg);
178
Nick Kossifidis194828a2008-04-16 18:49:02 +0300179 }
180
181 return 0;
182
183}
184
185/*
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200186 * Check if the device is supported and initialize the needed structs
187 */
188struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
189{
190 struct ath5k_hw *ah;
Nick Kossifidis194828a2008-04-16 18:49:02 +0300191 struct pci_dev *pdev = sc->pdev;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200192 u8 mac[ETH_ALEN];
193 int ret;
194 u32 srev;
195
196 /*If we passed the test malloc a ath5k_hw struct*/
197 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
198 if (ah == NULL) {
199 ret = -ENOMEM;
200 ATH5K_ERR(sc, "out of memory\n");
201 goto err;
202 }
203
204 ah->ah_sc = sc;
205 ah->ah_iobase = sc->iobase;
206
207 /*
208 * HW information
209 */
210
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200211 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
212 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
213 ah->ah_turbo = false;
214 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
215 ah->ah_imr = 0;
216 ah->ah_atim_window = 0;
217 ah->ah_aifs = AR5K_TUNE_AIFS;
218 ah->ah_cw_min = AR5K_TUNE_CWMIN;
219 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
220 ah->ah_software_retry = false;
221 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
222
223 /*
224 * Set the mac revision based on the pci id
225 */
226 ah->ah_version = mac_version;
227
228 /*Fill the ath5k_hw struct with the needed functions*/
229 if (ah->ah_version == AR5K_AR5212)
230 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
231 else if (ah->ah_version == AR5K_AR5211)
232 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
233
234 if (ah->ah_version == AR5K_AR5212) {
235 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
236 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
237 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
238 } else {
239 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
240 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
241 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
242 }
243
244 if (ah->ah_version == AR5K_AR5212)
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900245 ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200246 else if (ah->ah_version <= AR5K_AR5211)
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900247 ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200248
249 /* Bring device out of sleep and reset it's units */
250 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
251 if (ret)
252 goto err_free;
253
254 /* Get MAC, PHY and RADIO revisions */
255 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
256 ah->ah_mac_srev = srev;
257 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
258 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
259 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
260 0xffffffff;
261 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
262 CHANNEL_5GHZ);
263
264 if (ah->ah_version == AR5K_AR5210)
265 ah->ah_radio_2ghz_revision = 0;
266 else
267 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
268 CHANNEL_2GHZ);
269
270 /* Return on unsuported chips (unsupported eeprom etc) */
Nick Kossifidis194828a2008-04-16 18:49:02 +0300271 if ((srev >= AR5K_SREV_VER_AR5416) &&
272 (srev < AR5K_SREV_VER_AR2425)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200273 ATH5K_ERR(sc, "Device not yet supported.\n");
274 ret = -ENODEV;
275 goto err_free;
Nick Kossifidis194828a2008-04-16 18:49:02 +0300276 } else if (srev == AR5K_SREV_VER_AR2425) {
277 ATH5K_WARN(sc, "Support for RF2425 is under development.\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200278 }
279
280 /* Identify single chip solutions */
Nick Kossifidis136bfc72008-04-16 18:42:48 +0300281 if (((srev <= AR5K_SREV_VER_AR5414) &&
282 (srev >= AR5K_SREV_VER_AR2413)) ||
283 (srev == AR5K_SREV_VER_AR2425)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200284 ah->ah_single_chip = true;
285 } else {
286 ah->ah_single_chip = false;
287 }
288
289 /* Single chip radio */
290 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
291 ah->ah_radio_2ghz_revision = 0;
292
293 /* Identify the radio chip*/
294 if (ah->ah_version == AR5K_AR5210) {
295 ah->ah_radio = AR5K_RF5110;
Nick Kossifidis194828a2008-04-16 18:49:02 +0300296 /*
Nick Kossifidise5a4ad02008-07-20 06:34:39 +0300297 * Register returns 0x0/0x04 for radio revision
Nick Kossifidis194828a2008-04-16 18:49:02 +0300298 * so ath5k_hw_radio_revision doesn't parse the value
299 * correctly. For now we are based on mac's srev to
300 * identify RF2425 radio.
301 */
302 } else if (srev == AR5K_SREV_VER_AR2425) {
Nick Kossifidis136bfc72008-04-16 18:42:48 +0300303 ah->ah_radio = AR5K_RF2425;
Nick Kossifidise5a4ad02008-07-20 06:34:39 +0300304 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF2425;
305 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
306 ah->ah_radio = AR5K_RF5111;
307 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
308 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
309 ah->ah_radio = AR5K_RF5112;
Nick Kossifidis136bfc72008-04-16 18:42:48 +0300310 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
Nick Kossifidise5a4ad02008-07-20 06:34:39 +0300311 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
312 ah->ah_radio = AR5K_RF2413;
313 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF2413;
314 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) {
315 ah->ah_radio = AR5K_RF5413;
316 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5413;
317 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5133) {
318 /* AR5424 */
319 if (srev >= AR5K_SREV_VER_AR5424) {
320 ah->ah_radio = AR5K_RF5413;
321 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5413;
322 /* AR2424 */
323 } else {
324 ah->ah_radio = AR5K_RF2413; /* For testing */
325 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF2413;
326 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200327 }
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200328 ah->ah_phy = AR5K_PHY(0);
329
330 /*
Nick Kossifidise5a4ad02008-07-20 06:34:39 +0300331 * Write PCI-E power save settings
Nick Kossifidis194828a2008-04-16 18:49:02 +0300332 */
333 if ((ah->ah_version == AR5K_AR5212) && (pdev->is_pcie)) {
334 ath5k_hw_reg_write(ah, 0x9248fc00, 0x4080);
335 ath5k_hw_reg_write(ah, 0x24924924, 0x4080);
336 ath5k_hw_reg_write(ah, 0x28000039, 0x4080);
337 ath5k_hw_reg_write(ah, 0x53160824, 0x4080);
338 ath5k_hw_reg_write(ah, 0xe5980579, 0x4080);
339 ath5k_hw_reg_write(ah, 0x001defff, 0x4080);
340 ath5k_hw_reg_write(ah, 0x1aaabe40, 0x4080);
341 ath5k_hw_reg_write(ah, 0xbe105554, 0x4080);
342 ath5k_hw_reg_write(ah, 0x000e3007, 0x4080);
343 ath5k_hw_reg_write(ah, 0x00000000, 0x4084);
344 }
345
346 /*
347 * POST
348 */
349 ret = ath5k_hw_post(ah);
350 if (ret)
351 goto err_free;
352
Nick Kossifidise5a4ad02008-07-20 06:34:39 +0300353 /* Write AR5K_PCICFG_UNK on 2112B and later chips */
354 if (ah->ah_radio_5ghz_revision > AR5K_SREV_RAD_2112B ||
355 srev > AR5K_SREV_VER_AR2413) {
356 ath5k_hw_reg_write(ah, AR5K_PCICFG_UNK, AR5K_PCICFG);
357 }
358
Nick Kossifidis194828a2008-04-16 18:49:02 +0300359 /*
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200360 * Get card capabilities, values, ...
361 */
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200362 ret = ath5k_eeprom_init(ah);
363 if (ret) {
364 ATH5K_ERR(sc, "unable to init EEPROM\n");
365 goto err_free;
366 }
367
368 /* Get misc capabilities */
369 ret = ath5k_hw_get_capabilities(ah);
370 if (ret) {
371 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
372 sc->pdev->device);
373 goto err_free;
374 }
375
376 /* Get MAC address */
377 ret = ath5k_eeprom_read_mac(ah, mac);
378 if (ret) {
379 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
380 sc->pdev->device);
381 goto err_free;
382 }
383
384 ath5k_hw_set_lladdr(ah, mac);
385 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
386 memset(ah->ah_bssid, 0xff, ETH_ALEN);
387 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
388 ath5k_hw_set_opmode(ah);
389
390 ath5k_hw_set_rfgain_opt(ah);
391
392 return ah;
393err_free:
394 kfree(ah);
395err:
396 return ERR_PTR(ret);
397}
398
399/*
400 * Bring up MAC + PHY Chips
401 */
402static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
403{
Nick Kossifidis56c90542008-02-28 16:20:52 -0500404 struct pci_dev *pdev = ah->ah_sc->pdev;
405 u32 turbo, mode, clock, bus_flags;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200406 int ret;
407
408 turbo = 0;
409 mode = 0;
410 clock = 0;
411
412 ATH5K_TRACE(ah->ah_sc);
413
414 /* Wakeup the device */
415 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
416 if (ret) {
417 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
418 return ret;
419 }
420
421 if (ah->ah_version != AR5K_AR5210) {
422 /*
423 * Get channel mode flags
424 */
425
426 if (ah->ah_radio >= AR5K_RF5112) {
427 mode = AR5K_PHY_MODE_RAD_RF5112;
428 clock = AR5K_PHY_PLL_RF5112;
429 } else {
430 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
431 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
432 }
433
434 if (flags & CHANNEL_2GHZ) {
435 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
436 clock |= AR5K_PHY_PLL_44MHZ;
437
438 if (flags & CHANNEL_CCK) {
439 mode |= AR5K_PHY_MODE_MOD_CCK;
440 } else if (flags & CHANNEL_OFDM) {
441 /* XXX Dynamic OFDM/CCK is not supported by the
442 * AR5211 so we set MOD_OFDM for plain g (no
443 * CCK headers) operation. We need to test
444 * this, 5211 might support ofdm-only g after
445 * all, there are also initial register values
446 * in the code for g mode (see initvals.c). */
447 if (ah->ah_version == AR5K_AR5211)
448 mode |= AR5K_PHY_MODE_MOD_OFDM;
449 else
450 mode |= AR5K_PHY_MODE_MOD_DYN;
451 } else {
452 ATH5K_ERR(ah->ah_sc,
453 "invalid radio modulation mode\n");
454 return -EINVAL;
455 }
456 } else if (flags & CHANNEL_5GHZ) {
457 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
458 clock |= AR5K_PHY_PLL_40MHZ;
459
460 if (flags & CHANNEL_OFDM)
461 mode |= AR5K_PHY_MODE_MOD_OFDM;
462 else {
463 ATH5K_ERR(ah->ah_sc,
464 "invalid radio modulation mode\n");
465 return -EINVAL;
466 }
467 } else {
468 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
469 return -EINVAL;
470 }
471
472 if (flags & CHANNEL_TURBO)
473 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
474 } else { /* Reset the device */
475
476 /* ...enable Atheros turbo mode if requested */
477 if (flags & CHANNEL_TURBO)
478 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
479 AR5K_PHY_TURBO);
480 }
481
Nick Kossifidis56c90542008-02-28 16:20:52 -0500482 /* reseting PCI on PCI-E cards results card to hang
483 * and always return 0xffff... so we ingore that flag
484 * for PCI-E cards */
485 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
486
487 /* Reset chipset */
488 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
489 AR5K_RESET_CTL_BASEBAND | bus_flags);
490 if (ret) {
Nick Kossifidis136bfc72008-04-16 18:42:48 +0300491 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200492 return -EIO;
493 }
494
495 if (ah->ah_version == AR5K_AR5210)
496 udelay(2300);
497
498 /* ...wakeup again!*/
499 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
500 if (ret) {
501 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
502 return ret;
503 }
504
505 /* ...final warm reset */
506 if (ath5k_hw_nic_reset(ah, 0)) {
507 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
508 return -EIO;
509 }
510
511 if (ah->ah_version != AR5K_AR5210) {
512 /* ...set the PHY operating mode */
513 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
514 udelay(300);
515
516 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
517 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
518 }
519
520 return 0;
521}
522
523/*
524 * Get the rate table for a specific operation mode
525 */
526const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
527 unsigned int mode)
528{
529 ATH5K_TRACE(ah->ah_sc);
530
531 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
532 return NULL;
533
534 /* Get rate tables */
535 switch (mode) {
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500536 case AR5K_MODE_11A:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200537 return &ath5k_rt_11a;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500538 case AR5K_MODE_11A_TURBO:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200539 return &ath5k_rt_turbo;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500540 case AR5K_MODE_11B:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200541 return &ath5k_rt_11b;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500542 case AR5K_MODE_11G:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200543 return &ath5k_rt_11g;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500544 case AR5K_MODE_11G_TURBO:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200545 return &ath5k_rt_xr;
546 }
547
548 return NULL;
549}
550
551/*
552 * Free the ath5k_hw struct
553 */
554void ath5k_hw_detach(struct ath5k_hw *ah)
555{
556 ATH5K_TRACE(ah->ah_sc);
557
Pavel Roskinf50e4a82008-03-12 16:13:31 -0400558 __set_bit(ATH_STAT_INVALID, ah->ah_sc->status);
559
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200560 if (ah->ah_rf_banks != NULL)
561 kfree(ah->ah_rf_banks);
562
563 /* assume interrupts are down */
564 kfree(ah);
565}
566
567/****************************\
568 Reset function and helpers
569\****************************/
570
571/**
572 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
573 *
574 * @ah: the &struct ath5k_hw
575 * @channel: the currently set channel upon reset
576 *
577 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
578 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
579 * depending on the bandwidth of the channel.
580 *
581 */
582static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
583 struct ieee80211_channel *channel)
584{
585 /* Get exponent and mantissa and set it */
586 u32 coef_scaled, coef_exp, coef_man,
587 ds_coef_exp, ds_coef_man, clock;
588
589 if (!(ah->ah_version == AR5K_AR5212) ||
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500590 !(channel->hw_value & CHANNEL_OFDM))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200591 BUG();
592
593 /* Seems there are two PLLs, one for baseband sampling and one
594 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
595 * turbo. */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500596 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200597 coef_scaled = ((5 * (clock << 24)) / 2) /
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500598 channel->center_freq;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200599
600 for (coef_exp = 31; coef_exp > 0; coef_exp--)
601 if ((coef_scaled >> coef_exp) & 0x1)
602 break;
603
604 if (!coef_exp)
605 return -EINVAL;
606
607 coef_exp = 14 - (coef_exp - 24);
608 coef_man = coef_scaled +
609 (1 << (24 - coef_exp - 1));
610 ds_coef_man = coef_man >> (24 - coef_exp);
611 ds_coef_exp = coef_exp - 16;
612
613 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
614 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
615 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
616 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
617
618 return 0;
619}
620
621/**
622 * ath5k_hw_write_rate_duration - set rate duration during hw resets
623 *
624 * @ah: the &struct ath5k_hw
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500625 * @mode: one of enum ath5k_driver_mode
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200626 *
627 * Write the rate duration table for the current mode upon hw reset. This
628 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
629 * an ACK timeout for the hardware for the current mode for each rate. The
630 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
631 * and 11Mbps) have another register for the short preamble ACK timeout
632 * calculation.
633 *
634 */
635static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500636 unsigned int mode)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200637{
638 struct ath5k_softc *sc = ah->ah_sc;
639 const struct ath5k_rate_table *rt;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500640 struct ieee80211_rate srate = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200641 unsigned int i;
642
643 /* Get rate table for the current operating mode */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500644 rt = ath5k_hw_get_rate_table(ah, mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200645
646 /* Write rate duration table */
647 for (i = 0; i < rt->rate_count; i++) {
648 const struct ath5k_rate *rate, *control_rate;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500649
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200650 u32 reg;
651 u16 tx_time;
652
653 rate = &rt->rates[i];
654 control_rate = &rt->rates[rate->control_rate];
655
656 /* Set ACK timeout */
657 reg = AR5K_RATE_DUR(rate->rate_code);
658
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500659 srate.bitrate = control_rate->rate_kbps/100;
660
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200661 /* An ACK frame consists of 10 bytes. If you add the FCS,
662 * which ieee80211_generic_frame_duration() adds,
663 * its 14 bytes. Note we use the control rate and not the
664 * actual rate for this rate. See mac80211 tx.c
665 * ieee80211_duration() for a brief description of
666 * what rate we should choose to TX ACKs. */
Pavel Roskin38c07b42008-02-26 17:59:14 -0500667 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
668 sc->vif, 10, &srate));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200669
670 ath5k_hw_reg_write(ah, tx_time, reg);
671
672 if (!HAS_SHPREAMBLE(i))
673 continue;
674
675 /*
676 * We're not distinguishing short preamble here,
677 * This is true, all we'll get is a longer value here
678 * which is not necessarilly bad. We could use
679 * export ieee80211_frame_duration() but that needs to be
680 * fixed first to be properly used by mac802111 drivers:
681 *
682 * - remove erp stuff and let the routine figure ofdm
683 * erp rates
684 * - remove passing argument ieee80211_local as
685 * drivers don't have access to it
686 * - move drivers using ieee80211_generic_frame_duration()
687 * to this
688 */
689 ath5k_hw_reg_write(ah, tx_time,
690 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
691 }
692}
693
694/*
695 * Main reset function
696 */
697int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
698 struct ieee80211_channel *channel, bool change_channel)
699{
700 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
Nick Kossifidis56c90542008-02-28 16:20:52 -0500701 struct pci_dev *pdev = ah->ah_sc->pdev;
702 u32 data, s_seq, s_ant, s_led[3], dma_size;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500703 unsigned int i, mode, freq, ee_mode, ant[2];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200704 int ret;
705
706 ATH5K_TRACE(ah->ah_sc);
707
708 s_seq = 0;
709 s_ant = 0;
710 ee_mode = 0;
711 freq = 0;
712 mode = 0;
713
714 /*
715 * Save some registers before a reset
716 */
717 /*DCU/Antenna selection not available on 5210*/
718 if (ah->ah_version != AR5K_AR5210) {
Joe Perchese9010e22008-03-07 14:21:16 -0800719 if (change_channel) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200720 /* Seq number for queue 0 -do this for all queues ? */
721 s_seq = ath5k_hw_reg_read(ah,
722 AR5K_QUEUE_DFS_SEQNUM(0));
723 /*Default antenna*/
724 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
725 }
726 }
727
728 /*GPIOs*/
729 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
730 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
731 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
732
Joe Perchese9010e22008-03-07 14:21:16 -0800733 if (change_channel && ah->ah_rf_banks != NULL)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200734 ath5k_hw_get_rf_gain(ah);
735
736
737 /*Wakeup the device*/
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500738 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200739 if (ret)
740 return ret;
741
742 /*
743 * Initialize operating mode
744 */
745 ah->ah_op_mode = op_mode;
746
747 /*
748 * 5111/5112 Settings
749 * 5210 only comes with RF5110
750 */
751 if (ah->ah_version != AR5K_AR5210) {
752 if (ah->ah_radio != AR5K_RF5111 &&
753 ah->ah_radio != AR5K_RF5112 &&
Nick Kossifidis903b4742008-02-28 14:50:50 -0500754 ah->ah_radio != AR5K_RF5413 &&
Nick Kossifidis136bfc72008-04-16 18:42:48 +0300755 ah->ah_radio != AR5K_RF2413 &&
756 ah->ah_radio != AR5K_RF2425) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200757 ATH5K_ERR(ah->ah_sc,
758 "invalid phy radio: %u\n", ah->ah_radio);
759 return -EINVAL;
760 }
761
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500762 switch (channel->hw_value & CHANNEL_MODES) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200763 case CHANNEL_A:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500764 mode = AR5K_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200765 freq = AR5K_INI_RFGAIN_5GHZ;
766 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200767 break;
768 case CHANNEL_G:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500769 mode = AR5K_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200770 freq = AR5K_INI_RFGAIN_2GHZ;
771 ee_mode = AR5K_EEPROM_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200772 break;
773 case CHANNEL_B:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500774 mode = AR5K_MODE_11B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200775 freq = AR5K_INI_RFGAIN_2GHZ;
776 ee_mode = AR5K_EEPROM_MODE_11B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200777 break;
778 case CHANNEL_T:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500779 mode = AR5K_MODE_11A_TURBO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200780 freq = AR5K_INI_RFGAIN_5GHZ;
781 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200782 break;
783 /*Is this ok on 5211 too ?*/
784 case CHANNEL_TG:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500785 mode = AR5K_MODE_11G_TURBO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200786 freq = AR5K_INI_RFGAIN_2GHZ;
787 ee_mode = AR5K_EEPROM_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200788 break;
789 case CHANNEL_XR:
790 if (ah->ah_version == AR5K_AR5211) {
791 ATH5K_ERR(ah->ah_sc,
792 "XR mode not available on 5211");
793 return -EINVAL;
794 }
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500795 mode = AR5K_MODE_XR;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200796 freq = AR5K_INI_RFGAIN_5GHZ;
797 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200798 break;
799 default:
800 ATH5K_ERR(ah->ah_sc,
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500801 "invalid channel: %d\n", channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200802 return -EINVAL;
803 }
804
805 /* PHY access enable */
806 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
807
808 }
809
810 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
811 if (ret)
812 return ret;
813
814 /*
815 * 5211/5212 Specific
816 */
817 if (ah->ah_version != AR5K_AR5210) {
818 /*
819 * Write initial RF gain settings
820 * This should work for both 5111/5112
821 */
822 ret = ath5k_hw_rfgain(ah, freq);
823 if (ret)
824 return ret;
825
826 mdelay(1);
827
828 /*
829 * Write some more initial register settings
830 */
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -0500831 if (ah->ah_version == AR5K_AR5212) {
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300832 ath5k_hw_reg_write(ah, 0x0002a002, 0x982c);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200833
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500834 if (channel->hw_value == CHANNEL_G)
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -0500835 if (ah->ah_mac_srev < AR5K_SREV_VER_AR2413)
836 ath5k_hw_reg_write(ah, 0x00f80d80,
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300837 0x994c);
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -0500838 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2424)
839 ath5k_hw_reg_write(ah, 0x00380140,
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300840 0x994c);
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -0500841 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2425)
842 ath5k_hw_reg_write(ah, 0x00fc0ec0,
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300843 0x994c);
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -0500844 else /* 2425 */
845 ath5k_hw_reg_write(ah, 0x00fc0fc0,
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300846 0x994c);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200847 else
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300848 ath5k_hw_reg_write(ah, 0x00000000, 0x994c);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200849
Nick Kossifidis2203d6b2008-07-20 06:36:52 +0300850 /* Some bits are disabled here, we know nothing about
851 * register 0xa228 yet, most of the times this ends up
852 * with a value 0x9b5 -haven't seen any dump with
853 * a different value- */
854 /* Got this from decompiling binary HAL */
855 data = ath5k_hw_reg_read(ah, 0xa228);
856 data &= 0xfffffdff;
857 ath5k_hw_reg_write(ah, data, 0xa228);
858
859 data = ath5k_hw_reg_read(ah, 0xa228);
860 data &= 0xfffe03ff;
861 ath5k_hw_reg_write(ah, data, 0xa228);
862 data = 0;
863
864 /* Just write 0x9b5 ? */
865 /* ath5k_hw_reg_write(ah, 0x000009b5, 0xa228); */
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300866 ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200867 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
868 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
869 }
870
871 /* Fix for first revision of the RF5112 RF chipset */
872 if (ah->ah_radio >= AR5K_RF5112 &&
873 ah->ah_radio_5ghz_revision <
874 AR5K_SREV_RAD_5112A) {
875 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
876 AR5K_PHY_CCKTXCTL);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500877 if (channel->hw_value & CHANNEL_5GHZ)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200878 data = 0xffb81020;
879 else
880 data = 0xffb80d20;
881 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
Nick Kossifidis2203d6b2008-07-20 06:36:52 +0300882 data = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200883 }
884
885 /*
886 * Set TX power (FIXME)
887 */
888 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
889 if (ret)
890 return ret;
891
Luis R. Rodriguez132127e2008-01-04 02:21:05 -0500892 /* Write rate duration table only on AR5212 and if
893 * virtual interface has already been brought up
894 * XXX: rethink this after new mode changes to
895 * mac80211 are integrated */
896 if (ah->ah_version == AR5K_AR5212 &&
897 ah->ah_sc->vif != NULL)
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500898 ath5k_hw_write_rate_duration(ah, mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200899
900 /*
901 * Write RF registers
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200902 */
903 ret = ath5k_hw_rfregs(ah, channel, mode);
904 if (ret)
905 return ret;
906
907 /*
908 * Configure additional registers
909 */
910
911 /* Write OFDM timings on 5212*/
912 if (ah->ah_version == AR5K_AR5212 &&
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500913 channel->hw_value & CHANNEL_OFDM) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200914 ret = ath5k_hw_write_ofdm_timings(ah, channel);
915 if (ret)
916 return ret;
917 }
918
919 /*Enable/disable 802.11b mode on 5111
920 (enable 2111 frequency converter + CCK)*/
921 if (ah->ah_radio == AR5K_RF5111) {
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500922 if (mode == AR5K_MODE_11B)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200923 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
924 AR5K_TXCFG_B_MODE);
925 else
926 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
927 AR5K_TXCFG_B_MODE);
928 }
929
930 /*
931 * Set channel and calibrate the PHY
932 */
933 ret = ath5k_hw_channel(ah, channel);
934 if (ret)
935 return ret;
936
937 /* Set antenna mode */
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300938 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_ANT_CTL,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200939 ah->ah_antenna[ee_mode][0], 0xfffffc06);
940
941 /*
942 * In case a fixed antenna was set as default
943 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
944 * registers.
945 */
946 if (s_ant != 0){
947 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
948 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
949 else /* 2 - Aux */
950 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
951 } else {
952 ant[0] = AR5K_ANT_FIXED_A;
953 ant[1] = AR5K_ANT_FIXED_B;
954 }
955
956 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
957 AR5K_PHY_ANT_SWITCH_TABLE_0);
958 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
959 AR5K_PHY_ANT_SWITCH_TABLE_1);
960
961 /* Commit values from EEPROM */
962 if (ah->ah_radio == AR5K_RF5111)
963 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
964 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
965
966 ath5k_hw_reg_write(ah,
967 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300968 AR5K_PHY_NFTHRES);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200969
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300970 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_SETTLING,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200971 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
972 0xffffc07f);
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300973 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_GAIN,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200974 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
975 0xfffc0fff);
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300976 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_DESIRED_SIZE,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200977 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
978 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
979 0xffff0000);
980
981 ath5k_hw_reg_write(ah,
982 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
983 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
984 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300985 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200986
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300987 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_RF_CTL3,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200988 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300989 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_NF,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200990 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300991 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_OFDM_SELFCORR, 4, 0xffffff01);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200992
993 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
994 AR5K_PHY_IQ_CORR_ENABLE |
995 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
996 ee->ee_q_cal[ee_mode]);
997
998 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
999 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
1000 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
1001 ee->ee_margin_tx_rx[ee_mode]);
1002
1003 } else {
1004 mdelay(1);
1005 /* Disable phy and wait */
1006 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
1007 mdelay(1);
1008 }
1009
1010 /*
1011 * Restore saved values
1012 */
1013 /*DCU/Antenna selection not available on 5210*/
1014 if (ah->ah_version != AR5K_AR5210) {
1015 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
1016 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
1017 }
1018 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
1019 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
1020 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
1021
1022 /*
1023 * Misc
1024 */
1025 /* XXX: add ah->aid once mac80211 gives this to us */
1026 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
1027
1028 ath5k_hw_set_opmode(ah);
1029 /*PISR/SISR Not available on 5210*/
1030 if (ah->ah_version != AR5K_AR5210) {
1031 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
1032 /* If we later allow tuning for this, store into sc structure */
1033 data = AR5K_TUNE_RSSI_THRES |
1034 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
1035 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
1036 }
1037
1038 /*
1039 * Set Rx/Tx DMA Configuration
Nick Kossifidis56c90542008-02-28 16:20:52 -05001040 *
1041 * Set maximum DMA size (512) except for PCI-E cards since
1042 * it causes rx overruns and tx errors (tested on 5424 but since
1043 * rx overruns also occur on 5416/5418 with madwifi we set 128
1044 * for all PCI-E cards to be safe).
1045 *
1046 * In dumps this is 128 for allchips.
1047 *
1048 * XXX: need to check 5210 for this
1049 * TODO: Check out tx triger level, it's always 64 on dumps but I
1050 * guess we can tweak it and see how it goes ;-)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001051 */
Nick Kossifidis56c90542008-02-28 16:20:52 -05001052 dma_size = (pdev->is_pcie) ? AR5K_DMASIZE_128B : AR5K_DMASIZE_512B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001053 if (ah->ah_version != AR5K_AR5210) {
Nick Kossifidis56c90542008-02-28 16:20:52 -05001054 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1055 AR5K_TXCFG_SDMAMR, dma_size);
1056 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
1057 AR5K_RXCFG_SDMAMW, dma_size);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001058 }
1059
1060 /*
1061 * Enable the PHY and wait until completion
1062 */
1063 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
1064
1065 /*
Nick Kossifidis2203d6b2008-07-20 06:36:52 +03001066 * On 5211+ read activation -> rx delay
1067 * and use it.
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001068 */
1069 if (ah->ah_version != AR5K_AR5210) {
1070 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
1071 AR5K_PHY_RX_DELAY_M;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001072 data = (channel->hw_value & CHANNEL_CCK) ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001073 ((data << 2) / 22) : (data / 10);
1074
Nick Kossifidis2203d6b2008-07-20 06:36:52 +03001075 udelay(100 + (2 * data));
1076 data = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001077 } else {
1078 mdelay(1);
1079 }
1080
1081 /*
Nick Kossifidise2a0cce2008-07-20 06:38:16 +03001082 * Perform ADC test (?)
1083 */
1084 data = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
1085 ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
1086 for (i = 0; i <= 20; i++) {
1087 if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
1088 break;
1089 udelay(200);
1090 }
1091 ath5k_hw_reg_write(ah, data, AR5K_PHY_TST1);
1092 data = 0;
1093
1094 /*
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001095 * Enable calibration and wait until completion
1096 */
1097 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1098 AR5K_PHY_AGCCTL_CAL);
1099
1100 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1101 AR5K_PHY_AGCCTL_CAL, 0, false)) {
1102 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001103 channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001104 return -EAGAIN;
1105 }
1106
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001107 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001108 if (ret)
1109 return ret;
1110
1111 ah->ah_calibration = false;
1112
1113 /* A and G modes can use QAM modulation which requires enabling
1114 * I and Q calibration. Don't bother in B mode. */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001115 if (!(mode == AR5K_MODE_11B)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001116 ah->ah_calibration = true;
1117 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1118 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1119 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1120 AR5K_PHY_IQ_RUN);
1121 }
1122
1123 /*
1124 * Reset queues and start beacon timers at the end of the reset routine
1125 */
1126 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
1127 /*No QCU on 5210*/
1128 if (ah->ah_version != AR5K_AR5210)
1129 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
1130
1131 ret = ath5k_hw_reset_tx_queue(ah, i);
1132 if (ret) {
1133 ATH5K_ERR(ah->ah_sc,
1134 "failed to reset TX queue #%d\n", i);
1135 return ret;
1136 }
1137 }
1138
1139 /* Pre-enable interrupts on 5211/5212*/
1140 if (ah->ah_version != AR5K_AR5210)
1141 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
1142 AR5K_INT_FATAL);
1143
1144 /*
1145 * Set RF kill flags if supported by the device (read from the EEPROM)
1146 * Disable gpio_intr for now since it results system hang.
1147 * TODO: Handle this in ath5k_intr
1148 */
1149#if 0
1150 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1151 ath5k_hw_set_gpio_input(ah, 0);
1152 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1153 if (ah->ah_gpio[0] == 0)
1154 ath5k_hw_set_gpio_intr(ah, 0, 1);
1155 else
1156 ath5k_hw_set_gpio_intr(ah, 0, 0);
1157 }
1158#endif
1159
1160 /*
1161 * Set the 32MHz reference clock on 5212 phy clock sleep register
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05001162 *
1163 * TODO: Find out how to switch to external 32Khz clock to save power
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001164 */
1165 if (ah->ah_version == AR5K_AR5212) {
1166 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1167 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1168 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1169 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1170 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
Nick Kossifidis903b4742008-02-28 14:50:50 -05001171 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
Nick Kossifidis2203d6b2008-07-20 06:36:52 +03001172
1173 data = ath5k_hw_reg_read(ah, AR5K_USEC_5211) & 0xffffc07f ;
1174 data |= (ah->ah_phy_spending == AR5K_PHY_SPENDING_18) ?
1175 0x00000f80 : 0x00001380 ;
1176 ath5k_hw_reg_write(ah, data, AR5K_USEC_5211);
1177 data = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001178 }
1179
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05001180 if (ah->ah_version == AR5K_AR5212) {
1181 ath5k_hw_reg_write(ah, 0x000100aa, 0x8118);
1182 ath5k_hw_reg_write(ah, 0x00003210, 0x811c);
1183 ath5k_hw_reg_write(ah, 0x00000052, 0x8108);
1184 if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2413)
1185 ath5k_hw_reg_write(ah, 0x00000004, 0x8120);
1186 }
1187
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001188 /*
1189 * Disable beacons and reset the register
1190 */
1191 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1192 AR5K_BEACON_RESET_TSF);
1193
1194 return 0;
1195}
1196
1197/*
1198 * Reset chipset
1199 */
1200static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1201{
1202 int ret;
1203 u32 mask = val ? val : ~0U;
1204
1205 ATH5K_TRACE(ah->ah_sc);
1206
1207 /* Read-and-clear RX Descriptor Pointer*/
1208 ath5k_hw_reg_read(ah, AR5K_RXDP);
1209
1210 /*
1211 * Reset the device and wait until success
1212 */
1213 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1214
1215 /* Wait at least 128 PCI clocks */
1216 udelay(15);
1217
1218 if (ah->ah_version == AR5K_AR5210) {
1219 val &= AR5K_RESET_CTL_CHIP;
1220 mask &= AR5K_RESET_CTL_CHIP;
1221 } else {
1222 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1223 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1224 }
1225
1226 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1227
1228 /*
1229 * Reset configuration register (for hw byte-swap). Note that this
1230 * is only set for big endian. We do the necessary magic in
1231 * AR5K_INIT_CFG.
1232 */
1233 if ((val & AR5K_RESET_CTL_PCU) == 0)
1234 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1235
1236 return ret;
1237}
1238
1239/*
1240 * Power management functions
1241 */
1242
1243/*
1244 * Sleep control
1245 */
1246int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1247 bool set_chip, u16 sleep_duration)
1248{
1249 unsigned int i;
1250 u32 staid;
1251
1252 ATH5K_TRACE(ah->ah_sc);
1253 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1254
1255 switch (mode) {
1256 case AR5K_PM_AUTO:
1257 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1258 /* fallthrough */
1259 case AR5K_PM_NETWORK_SLEEP:
Joe Perchese9010e22008-03-07 14:21:16 -08001260 if (set_chip)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001261 ath5k_hw_reg_write(ah,
1262 AR5K_SLEEP_CTL_SLE | sleep_duration,
1263 AR5K_SLEEP_CTL);
1264
1265 staid |= AR5K_STA_ID1_PWR_SV;
1266 break;
1267
1268 case AR5K_PM_FULL_SLEEP:
Joe Perchese9010e22008-03-07 14:21:16 -08001269 if (set_chip)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001270 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1271 AR5K_SLEEP_CTL);
1272
1273 staid |= AR5K_STA_ID1_PWR_SV;
1274 break;
1275
1276 case AR5K_PM_AWAKE:
Joe Perchese9010e22008-03-07 14:21:16 -08001277 if (!set_chip)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001278 goto commit;
1279
1280 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1281 AR5K_SLEEP_CTL);
1282
1283 for (i = 5000; i > 0; i--) {
1284 /* Check if the chip did wake up */
1285 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1286 AR5K_PCICFG_SPWR_DN) == 0)
1287 break;
1288
1289 /* Wait a bit and retry */
1290 udelay(200);
1291 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1292 AR5K_SLEEP_CTL);
1293 }
1294
1295 /* Fail if the chip didn't wake up */
1296 if (i <= 0)
1297 return -EIO;
1298
1299 staid &= ~AR5K_STA_ID1_PWR_SV;
1300 break;
1301
1302 default:
1303 return -EINVAL;
1304 }
1305
1306commit:
1307 ah->ah_power_mode = mode;
1308 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1309
1310 return 0;
1311}
1312
1313/***********************\
1314 DMA Related Functions
1315\***********************/
1316
1317/*
1318 * Receive functions
1319 */
1320
1321/*
1322 * Start DMA receive
1323 */
1324void ath5k_hw_start_rx(struct ath5k_hw *ah)
1325{
1326 ATH5K_TRACE(ah->ah_sc);
1327 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1328}
1329
1330/*
1331 * Stop DMA receive
1332 */
1333int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1334{
1335 unsigned int i;
1336
1337 ATH5K_TRACE(ah->ah_sc);
1338 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1339
1340 /*
1341 * It may take some time to disable the DMA receive unit
1342 */
1343 for (i = 2000; i > 0 &&
1344 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1345 i--)
1346 udelay(10);
1347
1348 return i ? 0 : -EBUSY;
1349}
1350
1351/*
1352 * Get the address of the RX Descriptor
1353 */
1354u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1355{
1356 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1357}
1358
1359/*
1360 * Set the address of the RX Descriptor
1361 */
1362void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1363{
1364 ATH5K_TRACE(ah->ah_sc);
1365
1366 /*TODO:Shouldn't we check if RX is enabled first ?*/
1367 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1368}
1369
1370/*
1371 * Transmit functions
1372 */
1373
1374/*
1375 * Start DMA transmit for a specific queue
1376 * (see also QCU/DCU functions)
1377 */
1378int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1379{
1380 u32 tx_queue;
1381
1382 ATH5K_TRACE(ah->ah_sc);
1383 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1384
1385 /* Return if queue is declared inactive */
1386 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1387 return -EIO;
1388
1389 if (ah->ah_version == AR5K_AR5210) {
1390 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1391
1392 /*
1393 * Set the queue by type on 5210
1394 */
1395 switch (ah->ah_txq[queue].tqi_type) {
1396 case AR5K_TX_QUEUE_DATA:
1397 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1398 break;
1399 case AR5K_TX_QUEUE_BEACON:
1400 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1401 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1402 AR5K_BSR);
1403 break;
1404 case AR5K_TX_QUEUE_CAB:
1405 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1406 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1407 AR5K_BCR_BDMAE, AR5K_BSR);
1408 break;
1409 default:
1410 return -EINVAL;
1411 }
1412 /* Start queue */
1413 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1414 } else {
1415 /* Return if queue is disabled */
1416 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1417 return -EIO;
1418
1419 /* Start queue */
1420 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1421 }
1422
1423 return 0;
1424}
1425
1426/*
1427 * Stop DMA transmit for a specific queue
1428 * (see also QCU/DCU functions)
1429 */
1430int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1431{
1432 unsigned int i = 100;
1433 u32 tx_queue, pending;
1434
1435 ATH5K_TRACE(ah->ah_sc);
1436 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1437
1438 /* Return if queue is declared inactive */
1439 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1440 return -EIO;
1441
1442 if (ah->ah_version == AR5K_AR5210) {
1443 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1444
1445 /*
1446 * Set by queue type
1447 */
1448 switch (ah->ah_txq[queue].tqi_type) {
1449 case AR5K_TX_QUEUE_DATA:
1450 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1451 break;
1452 case AR5K_TX_QUEUE_BEACON:
1453 case AR5K_TX_QUEUE_CAB:
1454 /* XXX Fix me... */
1455 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1456 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1457 break;
1458 default:
1459 return -EINVAL;
1460 }
1461
1462 /* Stop queue */
1463 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
Jiri Slaby274c7c32008-07-15 17:44:20 +02001464 ath5k_hw_reg_read(ah, AR5K_CR);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001465 } else {
1466 /*
1467 * Schedule TX disable and wait until queue is empty
1468 */
1469 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1470
1471 /*Check for pending frames*/
1472 do {
1473 pending = ath5k_hw_reg_read(ah,
1474 AR5K_QUEUE_STATUS(queue)) &
1475 AR5K_QCU_STS_FRMPENDCNT;
1476 udelay(100);
1477 } while (--i && pending);
1478
1479 /* Clear register */
1480 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
Jiri Slaby274c7c32008-07-15 17:44:20 +02001481 if (pending)
1482 return -EBUSY;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001483 }
1484
1485 /* TODO: Check for success else return error */
1486 return 0;
1487}
1488
1489/*
1490 * Get the address of the TX Descriptor for a specific queue
1491 * (see also QCU/DCU functions)
1492 */
1493u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1494{
1495 u16 tx_reg;
1496
1497 ATH5K_TRACE(ah->ah_sc);
1498 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1499
1500 /*
1501 * Get the transmit queue descriptor pointer from the selected queue
1502 */
1503 /*5210 doesn't have QCU*/
1504 if (ah->ah_version == AR5K_AR5210) {
1505 switch (ah->ah_txq[queue].tqi_type) {
1506 case AR5K_TX_QUEUE_DATA:
1507 tx_reg = AR5K_NOQCU_TXDP0;
1508 break;
1509 case AR5K_TX_QUEUE_BEACON:
1510 case AR5K_TX_QUEUE_CAB:
1511 tx_reg = AR5K_NOQCU_TXDP1;
1512 break;
1513 default:
1514 return 0xffffffff;
1515 }
1516 } else {
1517 tx_reg = AR5K_QUEUE_TXDP(queue);
1518 }
1519
1520 return ath5k_hw_reg_read(ah, tx_reg);
1521}
1522
1523/*
1524 * Set the address of the TX Descriptor for a specific queue
1525 * (see also QCU/DCU functions)
1526 */
1527int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1528{
1529 u16 tx_reg;
1530
1531 ATH5K_TRACE(ah->ah_sc);
1532 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1533
1534 /*
1535 * Set the transmit queue descriptor pointer register by type
1536 * on 5210
1537 */
1538 if (ah->ah_version == AR5K_AR5210) {
1539 switch (ah->ah_txq[queue].tqi_type) {
1540 case AR5K_TX_QUEUE_DATA:
1541 tx_reg = AR5K_NOQCU_TXDP0;
1542 break;
1543 case AR5K_TX_QUEUE_BEACON:
1544 case AR5K_TX_QUEUE_CAB:
1545 tx_reg = AR5K_NOQCU_TXDP1;
1546 break;
1547 default:
1548 return -EINVAL;
1549 }
1550 } else {
1551 /*
1552 * Set the transmit queue descriptor pointer for
1553 * the selected queue on QCU for 5211+
1554 * (this won't work if the queue is still active)
1555 */
1556 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1557 return -EIO;
1558
1559 tx_reg = AR5K_QUEUE_TXDP(queue);
1560 }
1561
1562 /* Set descriptor pointer */
1563 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1564
1565 return 0;
1566}
1567
1568/*
1569 * Update tx trigger level
1570 */
1571int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1572{
1573 u32 trigger_level, imr;
1574 int ret = -EIO;
1575
1576 ATH5K_TRACE(ah->ah_sc);
1577
1578 /*
1579 * Disable interrupts by setting the mask
1580 */
1581 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1582
1583 /*TODO: Boundary check on trigger_level*/
1584 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1585 AR5K_TXCFG_TXFULL);
1586
Joe Perchese9010e22008-03-07 14:21:16 -08001587 if (!increase) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001588 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1589 goto done;
1590 } else
1591 trigger_level +=
1592 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1593
1594 /*
1595 * Update trigger level on success
1596 */
1597 if (ah->ah_version == AR5K_AR5210)
1598 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1599 else
1600 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1601 AR5K_TXCFG_TXFULL, trigger_level);
1602
1603 ret = 0;
1604
1605done:
1606 /*
1607 * Restore interrupt mask
1608 */
1609 ath5k_hw_set_intr(ah, imr);
1610
1611 return ret;
1612}
1613
1614/*
1615 * Interrupt handling
1616 */
1617
1618/*
1619 * Check if we have pending interrupts
1620 */
1621bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1622{
1623 ATH5K_TRACE(ah->ah_sc);
1624 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1625}
1626
1627/*
1628 * Get interrupt mask (ISR)
1629 */
1630int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1631{
1632 u32 data;
1633
1634 ATH5K_TRACE(ah->ah_sc);
1635
1636 /*
1637 * Read interrupt status from the Interrupt Status register
1638 * on 5210
1639 */
1640 if (ah->ah_version == AR5K_AR5210) {
1641 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1642 if (unlikely(data == AR5K_INT_NOCARD)) {
1643 *interrupt_mask = data;
1644 return -ENODEV;
1645 }
1646 } else {
1647 /*
1648 * Read interrupt status from the Read-And-Clear shadow register
1649 * Note: PISR/SISR Not available on 5210
1650 */
1651 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1652 }
1653
1654 /*
1655 * Get abstract interrupt mask (driver-compatible)
1656 */
1657 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1658
1659 if (unlikely(data == AR5K_INT_NOCARD))
1660 return -ENODEV;
1661
1662 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1663 *interrupt_mask |= AR5K_INT_RX;
1664
1665 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1666 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1667 *interrupt_mask |= AR5K_INT_TX;
1668
1669 if (ah->ah_version != AR5K_AR5210) {
1670 /*HIU = Host Interface Unit (PCI etc)*/
1671 if (unlikely(data & (AR5K_ISR_HIUERR)))
1672 *interrupt_mask |= AR5K_INT_FATAL;
1673
1674 /*Beacon Not Ready*/
1675 if (unlikely(data & (AR5K_ISR_BNR)))
1676 *interrupt_mask |= AR5K_INT_BNR;
1677 }
1678
1679 /*
1680 * XXX: BMISS interrupts may occur after association.
1681 * I found this on 5210 code but it needs testing. If this is
1682 * true we should disable them before assoc and re-enable them
1683 * after a successfull assoc + some jiffies.
1684 */
1685#if 0
1686 interrupt_mask &= ~AR5K_INT_BMISS;
1687#endif
1688
1689 /*
1690 * In case we didn't handle anything,
1691 * print the register value.
1692 */
1693 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1694 ATH5K_PRINTF("0x%08x\n", data);
1695
1696 return 0;
1697}
1698
1699/*
1700 * Set interrupt mask
1701 */
1702enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1703{
1704 enum ath5k_int old_mask, int_mask;
1705
1706 /*
1707 * Disable card interrupts to prevent any race conditions
1708 * (they will be re-enabled afterwards).
1709 */
1710 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1711
1712 old_mask = ah->ah_imr;
1713
1714 /*
1715 * Add additional, chipset-dependent interrupt mask flags
1716 * and write them to the IMR (interrupt mask register).
1717 */
1718 int_mask = new_mask & AR5K_INT_COMMON;
1719
1720 if (new_mask & AR5K_INT_RX)
1721 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1722 AR5K_IMR_RXDESC;
1723
1724 if (new_mask & AR5K_INT_TX)
1725 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1726 AR5K_IMR_TXURN;
1727
1728 if (ah->ah_version != AR5K_AR5210) {
1729 if (new_mask & AR5K_INT_FATAL) {
1730 int_mask |= AR5K_IMR_HIUERR;
1731 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1732 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1733 }
1734 }
1735
1736 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1737
1738 /* Store new interrupt mask */
1739 ah->ah_imr = new_mask;
1740
1741 /* ..re-enable interrupts */
1742 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
Jiri Slaby274c7c32008-07-15 17:44:20 +02001743 ath5k_hw_reg_read(ah, AR5K_IER);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001744
1745 return old_mask;
1746}
1747
1748
1749/*************************\
1750 EEPROM access functions
1751\*************************/
1752
1753/*
1754 * Read from eeprom
1755 */
1756static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1757{
1758 u32 status, timeout;
1759
1760 ATH5K_TRACE(ah->ah_sc);
1761 /*
1762 * Initialize EEPROM access
1763 */
1764 if (ah->ah_version == AR5K_AR5210) {
1765 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1766 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1767 } else {
1768 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1769 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1770 AR5K_EEPROM_CMD_READ);
1771 }
1772
1773 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1774 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1775 if (status & AR5K_EEPROM_STAT_RDDONE) {
1776 if (status & AR5K_EEPROM_STAT_RDERR)
1777 return -EIO;
1778 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1779 0xffff);
1780 return 0;
1781 }
1782 udelay(15);
1783 }
1784
1785 return -ETIMEDOUT;
1786}
1787
1788/*
1789 * Write to eeprom - currently disabled, use at your own risk
1790 */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001791#if 0
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001792static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1793{
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001794
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001795 u32 status, timeout;
1796
1797 ATH5K_TRACE(ah->ah_sc);
1798
1799 /*
1800 * Initialize eeprom access
1801 */
1802
1803 if (ah->ah_version == AR5K_AR5210) {
1804 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1805 } else {
1806 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1807 AR5K_EEPROM_CMD_RESET);
1808 }
1809
1810 /*
1811 * Write data to data register
1812 */
1813
1814 if (ah->ah_version == AR5K_AR5210) {
1815 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1816 } else {
1817 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1818 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1819 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1820 AR5K_EEPROM_CMD_WRITE);
1821 }
1822
1823 /*
1824 * Check status
1825 */
1826
1827 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1828 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1829 if (status & AR5K_EEPROM_STAT_WRDONE) {
1830 if (status & AR5K_EEPROM_STAT_WRERR)
1831 return EIO;
1832 return 0;
1833 }
1834 udelay(15);
1835 }
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001836
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001837 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1838 return -EIO;
1839}
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001840#endif
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001841
1842/*
1843 * Translate binary channel representation in EEPROM to frequency
1844 */
1845static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1846{
1847 u16 val;
1848
1849 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1850 return bin;
1851
1852 if (mode == AR5K_EEPROM_MODE_11A) {
1853 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1854 val = (5 * bin) + 4800;
1855 else
1856 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1857 (bin * 10) + 5100;
1858 } else {
1859 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1860 val = bin + 2300;
1861 else
1862 val = bin + 2400;
1863 }
1864
1865 return val;
1866}
1867
1868/*
1869 * Read antenna infos from eeprom
1870 */
1871static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1872 unsigned int mode)
1873{
1874 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1875 u32 o = *offset;
1876 u16 val;
1877 int ret, i = 0;
1878
1879 AR5K_EEPROM_READ(o++, val);
1880 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1881 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1882 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1883
1884 AR5K_EEPROM_READ(o++, val);
1885 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1886 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1887 ee->ee_ant_control[mode][i++] = val & 0x3f;
1888
1889 AR5K_EEPROM_READ(o++, val);
1890 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1891 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1892 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1893
1894 AR5K_EEPROM_READ(o++, val);
1895 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1896 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1897 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1898 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1899
1900 AR5K_EEPROM_READ(o++, val);
1901 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1902 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1903 ee->ee_ant_control[mode][i++] = val & 0x3f;
1904
1905 /* Get antenna modes */
1906 ah->ah_antenna[mode][0] =
1907 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1908 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1909 ee->ee_ant_control[mode][1] |
1910 (ee->ee_ant_control[mode][2] << 6) |
1911 (ee->ee_ant_control[mode][3] << 12) |
1912 (ee->ee_ant_control[mode][4] << 18) |
1913 (ee->ee_ant_control[mode][5] << 24);
1914 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1915 ee->ee_ant_control[mode][6] |
1916 (ee->ee_ant_control[mode][7] << 6) |
1917 (ee->ee_ant_control[mode][8] << 12) |
1918 (ee->ee_ant_control[mode][9] << 18) |
1919 (ee->ee_ant_control[mode][10] << 24);
1920
1921 /* return new offset */
1922 *offset = o;
1923
1924 return 0;
1925}
1926
1927/*
1928 * Read supported modes from eeprom
1929 */
1930static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1931 unsigned int mode)
1932{
1933 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1934 u32 o = *offset;
1935 u16 val;
1936 int ret;
1937
1938 AR5K_EEPROM_READ(o++, val);
1939 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1940 ee->ee_thr_62[mode] = val & 0xff;
1941
1942 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1943 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1944
1945 AR5K_EEPROM_READ(o++, val);
1946 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1947 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1948
1949 AR5K_EEPROM_READ(o++, val);
1950 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1951
1952 if ((val & 0xff) & 0x80)
1953 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1954 else
1955 ee->ee_noise_floor_thr[mode] = val & 0xff;
1956
1957 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1958 ee->ee_noise_floor_thr[mode] =
1959 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1960
1961 AR5K_EEPROM_READ(o++, val);
1962 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1963 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1964 ee->ee_xpd[mode] = val & 0x1;
1965
1966 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1967 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1968
1969 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1970 AR5K_EEPROM_READ(o++, val);
1971 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1972
1973 if (mode == AR5K_EEPROM_MODE_11A)
1974 ee->ee_xr_power[mode] = val & 0x3f;
1975 else {
1976 ee->ee_ob[mode][0] = val & 0x7;
1977 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1978 }
1979 }
1980
1981 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1982 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1983 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1984 } else {
1985 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1986
1987 AR5K_EEPROM_READ(o++, val);
1988 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1989
1990 if (mode == AR5K_EEPROM_MODE_11G)
1991 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1992 }
1993
1994 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1995 mode == AR5K_EEPROM_MODE_11A) {
1996 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1997 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1998 }
1999
2000 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
2001 mode == AR5K_EEPROM_MODE_11G)
2002 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
2003
2004 /* return new offset */
2005 *offset = o;
2006
2007 return 0;
2008}
2009
2010/*
2011 * Initialize eeprom & capabilities structs
2012 */
2013static int ath5k_eeprom_init(struct ath5k_hw *ah)
2014{
2015 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
2016 unsigned int mode, i;
2017 int ret;
2018 u32 offset;
2019 u16 val;
2020
2021 /* Initial TX thermal adjustment values */
2022 ee->ee_tx_clip = 4;
2023 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
2024 ee->ee_gain_select = 1;
2025
2026 /*
2027 * Read values from EEPROM and store them in the capability structure
2028 */
2029 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
2030 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
2031 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
2032 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
2033 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
2034
2035 /* Return if we have an old EEPROM */
2036 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
2037 return 0;
2038
2039#ifdef notyet
2040 /*
2041 * Validate the checksum of the EEPROM date. There are some
2042 * devices with invalid EEPROMs.
2043 */
2044 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
2045 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
2046 cksum ^= val;
2047 }
2048 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
2049 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
2050 return -EIO;
2051 }
2052#endif
2053
2054 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
2055 ee_ant_gain);
2056
2057 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2058 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
2059 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
2060 }
2061
2062 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
2063 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
2064 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
2065 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
2066
2067 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
2068 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
2069 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
2070 }
2071
2072 /*
2073 * Get conformance test limit values
2074 */
2075 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
2076 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
2077
2078 for (i = 0; i < ee->ee_ctls; i++) {
2079 AR5K_EEPROM_READ(offset++, val);
2080 ee->ee_ctl[i] = (val >> 8) & 0xff;
2081 ee->ee_ctl[i + 1] = val & 0xff;
2082 }
2083
2084 /*
2085 * Get values for 802.11a (5GHz)
2086 */
2087 mode = AR5K_EEPROM_MODE_11A;
2088
2089 ee->ee_turbo_max_power[mode] =
2090 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
2091
2092 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
2093
2094 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2095 if (ret)
2096 return ret;
2097
2098 AR5K_EEPROM_READ(offset++, val);
2099 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2100 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
2101 ee->ee_db[mode][3] = (val >> 2) & 0x7;
2102 ee->ee_ob[mode][2] = (val << 1) & 0x7;
2103
2104 AR5K_EEPROM_READ(offset++, val);
2105 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
2106 ee->ee_db[mode][2] = (val >> 12) & 0x7;
2107 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
2108 ee->ee_db[mode][1] = (val >> 6) & 0x7;
2109 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
2110 ee->ee_db[mode][0] = val & 0x7;
2111
2112 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2113 if (ret)
2114 return ret;
2115
2116 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
2117 AR5K_EEPROM_READ(offset++, val);
2118 ee->ee_margin_tx_rx[mode] = val & 0x3f;
2119 }
2120
2121 /*
2122 * Get values for 802.11b (2.4GHz)
2123 */
2124 mode = AR5K_EEPROM_MODE_11B;
2125 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
2126
2127 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2128 if (ret)
2129 return ret;
2130
2131 AR5K_EEPROM_READ(offset++, val);
2132 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2133 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2134 ee->ee_db[mode][1] = val & 0x7;
2135
2136 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2137 if (ret)
2138 return ret;
2139
2140 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2141 AR5K_EEPROM_READ(offset++, val);
2142 ee->ee_cal_pier[mode][0] =
2143 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2144 ee->ee_cal_pier[mode][1] =
2145 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2146
2147 AR5K_EEPROM_READ(offset++, val);
2148 ee->ee_cal_pier[mode][2] =
2149 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2150 }
2151
2152 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2153 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2154
2155 /*
2156 * Get values for 802.11g (2.4GHz)
2157 */
2158 mode = AR5K_EEPROM_MODE_11G;
2159 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
2160
2161 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2162 if (ret)
2163 return ret;
2164
2165 AR5K_EEPROM_READ(offset++, val);
2166 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2167 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2168 ee->ee_db[mode][1] = val & 0x7;
2169
2170 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2171 if (ret)
2172 return ret;
2173
2174 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2175 AR5K_EEPROM_READ(offset++, val);
2176 ee->ee_cal_pier[mode][0] =
2177 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2178 ee->ee_cal_pier[mode][1] =
2179 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2180
2181 AR5K_EEPROM_READ(offset++, val);
2182 ee->ee_turbo_max_power[mode] = val & 0x7f;
2183 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2184
2185 AR5K_EEPROM_READ(offset++, val);
2186 ee->ee_cal_pier[mode][2] =
2187 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2188
2189 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2190 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2191
2192 AR5K_EEPROM_READ(offset++, val);
2193 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2194 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2195
2196 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2197 AR5K_EEPROM_READ(offset++, val);
2198 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2199 }
2200 }
2201
2202 /*
2203 * Read 5GHz EEPROM channels
2204 */
2205
2206 return 0;
2207}
2208
2209/*
2210 * Read the MAC address from eeprom
2211 */
2212static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2213{
2214 u8 mac_d[ETH_ALEN];
2215 u32 total, offset;
2216 u16 data;
2217 int octet, ret;
2218
2219 memset(mac, 0, ETH_ALEN);
2220 memset(mac_d, 0, ETH_ALEN);
2221
2222 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2223 if (ret)
2224 return ret;
2225
2226 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2227 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2228 if (ret)
2229 return ret;
2230
2231 total += data;
2232 mac_d[octet + 1] = data & 0xff;
2233 mac_d[octet] = data >> 8;
2234 octet += 2;
2235 }
2236
2237 memcpy(mac, mac_d, ETH_ALEN);
2238
2239 if (!total || total == 3 * 0xffff)
2240 return -EINVAL;
2241
2242 return 0;
2243}
2244
2245/*
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002246 * Fill the capabilities struct
2247 */
2248static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2249{
2250 u16 ee_header;
2251
2252 ATH5K_TRACE(ah->ah_sc);
2253 /* Capabilities stored in the EEPROM */
2254 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2255
2256 if (ah->ah_version == AR5K_AR5210) {
2257 /*
2258 * Set radio capabilities
2259 * (The AR5110 only supports the middle 5GHz band)
2260 */
2261 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2262 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2263 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2264 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2265
2266 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002267 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2268 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002269 } else {
2270 /*
2271 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2272 * XXX and from 2312 to 2732GHz. There are problems with the
2273 * XXX current ieee80211 implementation because the IEEE
2274 * XXX channel mapping does not support negative channel
2275 * XXX numbers (2312MHz is channel -19). Of course, this
2276 * XXX doesn't matter because these channels are out of range
2277 * XXX but some regulation domains like MKK (Japan) will
2278 * XXX support frequencies somewhere around 4.8GHz.
2279 */
2280
2281 /*
2282 * Set radio capabilities
2283 */
2284
2285 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2286 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2287 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2288
2289 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002290 __set_bit(AR5K_MODE_11A,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002291 ah->ah_capabilities.cap_mode);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002292 __set_bit(AR5K_MODE_11A_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002293 ah->ah_capabilities.cap_mode);
2294 if (ah->ah_version == AR5K_AR5212)
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002295 __set_bit(AR5K_MODE_11G_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002296 ah->ah_capabilities.cap_mode);
2297 }
2298
2299 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2300 * connected */
2301 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2302 AR5K_EEPROM_HDR_11G(ee_header)) {
2303 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2304 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2305
2306 if (AR5K_EEPROM_HDR_11B(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002307 __set_bit(AR5K_MODE_11B,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002308 ah->ah_capabilities.cap_mode);
2309
2310 if (AR5K_EEPROM_HDR_11G(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002311 __set_bit(AR5K_MODE_11G,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002312 ah->ah_capabilities.cap_mode);
2313 }
2314 }
2315
2316 /* GPIO */
2317 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2318
2319 /* Set number of supported TX queues */
2320 if (ah->ah_version == AR5K_AR5210)
2321 ah->ah_capabilities.cap_queues.q_tx_num =
2322 AR5K_NUM_TX_QUEUES_NOQCU;
2323 else
2324 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2325
2326 return 0;
2327}
2328
2329/*********************************\
2330 Protocol Control Unit Functions
2331\*********************************/
2332
2333/*
2334 * Set Operation mode
2335 */
2336int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2337{
2338 u32 pcu_reg, beacon_reg, low_id, high_id;
2339
2340 pcu_reg = 0;
2341 beacon_reg = 0;
2342
2343 ATH5K_TRACE(ah->ah_sc);
2344
2345 switch (ah->ah_op_mode) {
2346 case IEEE80211_IF_TYPE_IBSS:
2347 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2348 (ah->ah_version == AR5K_AR5210 ?
2349 AR5K_STA_ID1_NO_PSPOLL : 0);
2350 beacon_reg |= AR5K_BCR_ADHOC;
2351 break;
2352
2353 case IEEE80211_IF_TYPE_AP:
2354 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2355 (ah->ah_version == AR5K_AR5210 ?
2356 AR5K_STA_ID1_NO_PSPOLL : 0);
2357 beacon_reg |= AR5K_BCR_AP;
2358 break;
2359
2360 case IEEE80211_IF_TYPE_STA:
2361 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2362 (ah->ah_version == AR5K_AR5210 ?
2363 AR5K_STA_ID1_PWR_SV : 0);
2364 case IEEE80211_IF_TYPE_MNTR:
2365 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2366 (ah->ah_version == AR5K_AR5210 ?
2367 AR5K_STA_ID1_NO_PSPOLL : 0);
2368 break;
2369
2370 default:
2371 return -EINVAL;
2372 }
2373
2374 /*
2375 * Set PCU registers
2376 */
2377 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2378 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2379 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2380 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2381
2382 /*
2383 * Set Beacon Control Register on 5210
2384 */
2385 if (ah->ah_version == AR5K_AR5210)
2386 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2387
2388 return 0;
2389}
2390
2391/*
2392 * BSSID Functions
2393 */
2394
2395/*
2396 * Get station id
2397 */
2398void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2399{
2400 ATH5K_TRACE(ah->ah_sc);
2401 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2402}
2403
2404/*
2405 * Set station id
2406 */
2407int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2408{
2409 u32 low_id, high_id;
2410
2411 ATH5K_TRACE(ah->ah_sc);
2412 /* Set new station ID */
2413 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2414
2415 low_id = AR5K_LOW_ID(mac);
2416 high_id = AR5K_HIGH_ID(mac);
2417
2418 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2419 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2420
2421 return 0;
2422}
2423
2424/*
2425 * Set BSSID
2426 */
2427void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2428{
2429 u32 low_id, high_id;
2430 u16 tim_offset = 0;
2431
2432 /*
2433 * Set simple BSSID mask on 5212
2434 */
2435 if (ah->ah_version == AR5K_AR5212) {
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05002436 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
2437 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002438 }
2439
2440 /*
2441 * Set BSSID which triggers the "SME Join" operation
2442 */
2443 low_id = AR5K_LOW_ID(bssid);
2444 high_id = AR5K_HIGH_ID(bssid);
2445 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2446 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2447 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2448
2449 if (assoc_id == 0) {
2450 ath5k_hw_disable_pspoll(ah);
2451 return;
2452 }
2453
2454 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2455 tim_offset ? tim_offset + 4 : 0);
2456
2457 ath5k_hw_enable_pspoll(ah, NULL, 0);
2458}
2459/**
2460 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2461 *
2462 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2463 * which bits of the interface's MAC address should be looked at when trying
2464 * to decide which packets to ACK. In station mode every bit matters. In AP
2465 * mode with a single BSS every bit matters as well. In AP mode with
2466 * multiple BSSes not every bit matters.
2467 *
2468 * @ah: the &struct ath5k_hw
2469 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2470 *
2471 * Note that this is a simple filter and *does* not filter out all
2472 * relevant frames. Some non-relevant frames will get through, probability
2473 * jocks are welcomed to compute.
2474 *
2475 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2476 * computing the set of:
2477 *
2478 * ~ ( MAC XOR BSSID )
2479 *
2480 * When you do this you are essentially computing the common bits. Later it
2481 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2482 * to obtain the relevant bits which should match on the destination frame.
2483 *
2484 * Simple example: on your card you have have two BSSes you have created with
2485 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2486 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2487 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2488 *
2489 * \
2490 * MAC: 0001 |
2491 * BSSID-01: 0100 | --> Belongs to us
2492 * BSSID-02: 1001 |
2493 * /
2494 * -------------------
2495 * BSSID-03: 0110 | --> External
2496 * -------------------
2497 *
2498 * Our bssid_mask would then be:
2499 *
2500 * On loop iteration for BSSID-01:
2501 * ~(0001 ^ 0100) -> ~(0101)
2502 * -> 1010
2503 * bssid_mask = 1010
2504 *
2505 * On loop iteration for BSSID-02:
2506 * bssid_mask &= ~(0001 ^ 1001)
2507 * bssid_mask = (1010) & ~(0001 ^ 1001)
2508 * bssid_mask = (1010) & ~(1001)
2509 * bssid_mask = (1010) & (0110)
2510 * bssid_mask = 0010
2511 *
2512 * A bssid_mask of 0010 means "only pay attention to the second least
2513 * significant bit". This is because its the only bit common
2514 * amongst the MAC and all BSSIDs we support. To findout what the real
2515 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2516 * or our MAC address (we assume the hardware uses the MAC address).
2517 *
2518 * Now, suppose there's an incoming frame for BSSID-03:
2519 *
2520 * IFRAME-01: 0110
2521 *
2522 * An easy eye-inspeciton of this already should tell you that this frame
2523 * will not pass our check. This is beacuse the bssid_mask tells the
2524 * hardware to only look at the second least significant bit and the
2525 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2526 * as 1, which does not match 0.
2527 *
2528 * So with IFRAME-01 we *assume* the hardware will do:
2529 *
2530 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2531 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2532 * --> allow = (0010) == 0000 ? 1 : 0;
2533 * --> allow = 0
2534 *
2535 * Lets now test a frame that should work:
2536 *
2537 * IFRAME-02: 0001 (we should allow)
2538 *
2539 * allow = (0001 & 1010) == 1010
2540 *
2541 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2542 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2543 * --> allow = (0010) == (0010)
2544 * --> allow = 1
2545 *
2546 * Other examples:
2547 *
2548 * IFRAME-03: 0100 --> allowed
2549 * IFRAME-04: 1001 --> allowed
2550 * IFRAME-05: 1101 --> allowed but its not for us!!!
2551 *
2552 */
2553int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2554{
2555 u32 low_id, high_id;
2556 ATH5K_TRACE(ah->ah_sc);
2557
2558 if (ah->ah_version == AR5K_AR5212) {
2559 low_id = AR5K_LOW_ID(mask);
2560 high_id = AR5K_HIGH_ID(mask);
2561
2562 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2563 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2564
2565 return 0;
2566 }
2567
2568 return -EIO;
2569}
2570
2571/*
2572 * Receive start/stop functions
2573 */
2574
2575/*
2576 * Start receive on PCU
2577 */
2578void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2579{
2580 ATH5K_TRACE(ah->ah_sc);
2581 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05002582
2583 /* TODO: ANI Support */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002584}
2585
2586/*
2587 * Stop receive on PCU
2588 */
2589void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2590{
2591 ATH5K_TRACE(ah->ah_sc);
2592 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05002593
2594 /* TODO: ANI Support */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002595}
2596
2597/*
2598 * RX Filter functions
2599 */
2600
2601/*
2602 * Set multicast filter
2603 */
2604void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2605{
2606 ATH5K_TRACE(ah->ah_sc);
2607 /* Set the multicat filter */
2608 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2609 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2610}
2611
2612/*
2613 * Set multicast filter by index
2614 */
2615int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2616{
2617
2618 ATH5K_TRACE(ah->ah_sc);
2619 if (index >= 64)
2620 return -EINVAL;
2621 else if (index >= 32)
2622 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2623 (1 << (index - 32)));
2624 else
2625 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2626
2627 return 0;
2628}
2629
2630/*
2631 * Clear Multicast filter by index
2632 */
2633int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2634{
2635
2636 ATH5K_TRACE(ah->ah_sc);
2637 if (index >= 64)
2638 return -EINVAL;
2639 else if (index >= 32)
2640 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2641 (1 << (index - 32)));
2642 else
2643 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2644
2645 return 0;
2646}
2647
2648/*
2649 * Get current rx filter
2650 */
2651u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2652{
2653 u32 data, filter = 0;
2654
2655 ATH5K_TRACE(ah->ah_sc);
2656 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2657
2658 /*Radar detection for 5212*/
2659 if (ah->ah_version == AR5K_AR5212) {
2660 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2661
2662 if (data & AR5K_PHY_ERR_FIL_RADAR)
2663 filter |= AR5K_RX_FILTER_RADARERR;
2664 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2665 filter |= AR5K_RX_FILTER_PHYERR;
2666 }
2667
2668 return filter;
2669}
2670
2671/*
2672 * Set rx filter
2673 */
2674void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2675{
2676 u32 data = 0;
2677
2678 ATH5K_TRACE(ah->ah_sc);
2679
2680 /* Set PHY error filter register on 5212*/
2681 if (ah->ah_version == AR5K_AR5212) {
2682 if (filter & AR5K_RX_FILTER_RADARERR)
2683 data |= AR5K_PHY_ERR_FIL_RADAR;
2684 if (filter & AR5K_RX_FILTER_PHYERR)
2685 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2686 }
2687
2688 /*
2689 * The AR5210 uses promiscous mode to detect radar activity
2690 */
2691 if (ah->ah_version == AR5K_AR5210 &&
2692 (filter & AR5K_RX_FILTER_RADARERR)) {
2693 filter &= ~AR5K_RX_FILTER_RADARERR;
2694 filter |= AR5K_RX_FILTER_PROM;
2695 }
2696
2697 /*Zero length DMA*/
2698 if (data)
2699 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2700 else
2701 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2702
2703 /*Write RX Filter register*/
2704 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2705
2706 /*Write PHY error filter register on 5212*/
2707 if (ah->ah_version == AR5K_AR5212)
2708 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2709
2710}
2711
2712/*
2713 * Beacon related functions
2714 */
2715
2716/*
2717 * Get a 32bit TSF
2718 */
2719u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2720{
2721 ATH5K_TRACE(ah->ah_sc);
2722 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2723}
2724
2725/*
2726 * Get the full 64bit TSF
2727 */
2728u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2729{
2730 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2731 ATH5K_TRACE(ah->ah_sc);
2732
2733 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2734}
2735
2736/*
2737 * Force a TSF reset
2738 */
2739void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2740{
2741 ATH5K_TRACE(ah->ah_sc);
2742 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2743}
2744
2745/*
2746 * Initialize beacon timers
2747 */
2748void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2749{
2750 u32 timer1, timer2, timer3;
2751
2752 ATH5K_TRACE(ah->ah_sc);
2753 /*
2754 * Set the additional timers by mode
2755 */
2756 switch (ah->ah_op_mode) {
2757 case IEEE80211_IF_TYPE_STA:
2758 if (ah->ah_version == AR5K_AR5210) {
2759 timer1 = 0xffffffff;
2760 timer2 = 0xffffffff;
2761 } else {
2762 timer1 = 0x0000ffff;
2763 timer2 = 0x0007ffff;
2764 }
2765 break;
2766
2767 default:
Bruno Randolf1008e0f2008-01-18 21:51:19 +09002768 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2769 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002770 }
2771
2772 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2773
2774 /*
2775 * Set the beacon register and enable all timers.
2776 * (next beacon, DMA beacon, software beacon, ATIM window time)
2777 */
2778 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2779 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2780 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2781 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2782
2783 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2784 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2785 AR5K_BEACON);
2786}
2787
2788#if 0
2789/*
2790 * Set beacon timers
2791 */
2792int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2793 const struct ath5k_beacon_state *state)
2794{
2795 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2796
2797 /*
2798 * TODO: should be changed through *state
2799 * review struct ath5k_beacon_state struct
2800 *
2801 * XXX: These are used for cfp period bellow, are they
2802 * ok ? Is it O.K. for tsf here to be 0 or should we use
2803 * get_tsf ?
2804 */
2805 u32 dtim_count = 0; /* XXX */
2806 u32 cfp_count = 0; /* XXX */
2807 u32 tsf = 0; /* XXX */
2808
2809 ATH5K_TRACE(ah->ah_sc);
2810 /* Return on an invalid beacon state */
2811 if (state->bs_interval < 1)
2812 return -EINVAL;
2813
2814 interval = state->bs_interval;
2815 dtim = state->bs_dtim_period;
2816
2817 /*
2818 * PCF support?
2819 */
2820 if (state->bs_cfp_period > 0) {
2821 /*
2822 * Enable PCF mode and set the CFP
2823 * (Contention Free Period) and timer registers
2824 */
2825 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2826 state->bs_interval;
2827 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2828 state->bs_interval;
2829
2830 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2831 AR5K_STA_ID1_DEFAULT_ANTENNA |
2832 AR5K_STA_ID1_PCF);
2833 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2834 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2835 AR5K_CFP_DUR);
2836 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2837 next_cfp)) << 3, AR5K_TIMER2);
2838 } else {
2839 /* Disable PCF mode */
2840 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2841 AR5K_STA_ID1_DEFAULT_ANTENNA |
2842 AR5K_STA_ID1_PCF);
2843 }
2844
2845 /*
2846 * Enable the beacon timer register
2847 */
2848 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2849
2850 /*
2851 * Start the beacon timers
2852 */
2853 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2854 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2855 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2856 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2857 AR5K_BEACON_PERIOD), AR5K_BEACON);
2858
2859 /*
2860 * Write new beacon miss threshold, if it appears to be valid
2861 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2862 * and return if its not in range. We can test this by reading value and
2863 * setting value to a largest value and seeing which values register.
2864 */
2865
2866 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2867 state->bs_bmiss_threshold);
2868
2869 /*
2870 * Set sleep control register
2871 * XXX: Didn't find this in 5210 code but since this register
2872 * exists also in ar5k's 5210 headers i leave it as common code.
2873 */
2874 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2875 (state->bs_sleep_duration - 3) << 3);
2876
2877 /*
2878 * Set enhanced sleep registers on 5212
2879 */
2880 if (ah->ah_version == AR5K_AR5212) {
2881 if (state->bs_sleep_duration > state->bs_interval &&
2882 roundup(state->bs_sleep_duration, interval) ==
2883 state->bs_sleep_duration)
2884 interval = state->bs_sleep_duration;
2885
2886 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2887 roundup(state->bs_sleep_duration, dtim) ==
2888 state->bs_sleep_duration))
2889 dtim = state->bs_sleep_duration;
2890
2891 if (interval > dtim)
2892 return -EINVAL;
2893
2894 next_beacon = interval == dtim ? state->bs_next_dtim :
2895 state->bs_next_beacon;
2896
2897 ath5k_hw_reg_write(ah,
2898 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2899 AR5K_SLEEP0_NEXT_DTIM) |
2900 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2901 AR5K_SLEEP0_ENH_SLEEP_EN |
2902 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2903
2904 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2905 AR5K_SLEEP1_NEXT_TIM) |
2906 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2907
2908 ath5k_hw_reg_write(ah,
2909 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2910 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2911 }
2912
2913 return 0;
2914}
2915
2916/*
2917 * Reset beacon timers
2918 */
2919void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2920{
2921 ATH5K_TRACE(ah->ah_sc);
2922 /*
2923 * Disable beacon timer
2924 */
2925 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2926
2927 /*
2928 * Disable some beacon register values
2929 */
2930 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2931 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2932 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2933}
2934
2935/*
2936 * Wait for beacon queue to finish
2937 */
2938int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2939{
2940 unsigned int i;
2941 int ret;
2942
2943 ATH5K_TRACE(ah->ah_sc);
2944
2945 /* 5210 doesn't have QCU*/
2946 if (ah->ah_version == AR5K_AR5210) {
2947 /*
2948 * Wait for beaconn queue to finish by checking
2949 * Control Register and Beacon Status Register.
2950 */
2951 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2952 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2953 ||
2954 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2955 break;
2956 udelay(10);
2957 }
2958
2959 /* Timeout... */
2960 if (i <= 0) {
2961 /*
2962 * Re-schedule the beacon queue
2963 */
2964 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2965 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2966 AR5K_BCR);
2967
2968 return -EIO;
2969 }
2970 ret = 0;
2971 } else {
2972 /*5211/5212*/
2973 ret = ath5k_hw_register_timeout(ah,
2974 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2975 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2976
2977 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2978 return -EIO;
2979 }
2980
2981 return ret;
2982}
2983#endif
2984
2985/*
2986 * Update mib counters (statistics)
2987 */
2988void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
Nick Kossifidis194828a2008-04-16 18:49:02 +03002989 struct ieee80211_low_level_stats *stats)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002990{
2991 ATH5K_TRACE(ah->ah_sc);
Nick Kossifidis194828a2008-04-16 18:49:02 +03002992
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002993 /* Read-And-Clear */
Nick Kossifidis194828a2008-04-16 18:49:02 +03002994 stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2995 stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2996 stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2997 stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2998
2999 /* XXX: Should we use this to track beacon count ?
3000 * -we read it anyway to clear the register */
3001 ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003002
3003 /* Reset profile count registers on 5212*/
3004 if (ah->ah_version == AR5K_AR5212) {
3005 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
3006 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
3007 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
3008 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
3009 }
3010}
3011
3012/** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
3013 *
3014 * @ah: the &struct ath5k_hw
3015 * @high: determines if to use low bit rate or now
3016 */
3017void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
3018{
3019 if (ah->ah_version != AR5K_AR5212)
3020 return;
3021 else {
3022 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
3023 if (high)
3024 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
3025 else
3026 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
3027 }
3028}
3029
3030
3031/*
3032 * ACK/CTS Timeouts
3033 */
3034
3035/*
3036 * Set ACK timeout on PCU
3037 */
3038int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
3039{
3040 ATH5K_TRACE(ah->ah_sc);
3041 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
3042 ah->ah_turbo) <= timeout)
3043 return -EINVAL;
3044
3045 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
3046 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3047
3048 return 0;
3049}
3050
3051/*
3052 * Read the ACK timeout from PCU
3053 */
3054unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
3055{
3056 ATH5K_TRACE(ah->ah_sc);
3057
3058 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3059 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
3060}
3061
3062/*
3063 * Set CTS timeout on PCU
3064 */
3065int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
3066{
3067 ATH5K_TRACE(ah->ah_sc);
3068 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
3069 ah->ah_turbo) <= timeout)
3070 return -EINVAL;
3071
3072 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
3073 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3074
3075 return 0;
3076}
3077
3078/*
3079 * Read CTS timeout from PCU
3080 */
3081unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
3082{
3083 ATH5K_TRACE(ah->ah_sc);
3084 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3085 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
3086}
3087
3088/*
3089 * Key table (WEP) functions
3090 */
3091
3092int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
3093{
3094 unsigned int i;
3095
3096 ATH5K_TRACE(ah->ah_sc);
3097 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3098
3099 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
3100 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
3101
Nick Kossifidis194828a2008-04-16 18:49:02 +03003102 /*
3103 * Set NULL encryption on AR5212+
3104 *
3105 * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
3106 * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
3107 *
3108 * Note2: Windows driver (ndiswrapper) sets this to
3109 * 0x00000714 instead of 0x00000007
3110 */
3111 if (ah->ah_version > AR5K_AR5211)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003112 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
3113 AR5K_KEYTABLE_TYPE(entry));
3114
3115 return 0;
3116}
3117
3118int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
3119{
3120 ATH5K_TRACE(ah->ah_sc);
3121 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3122
3123 /* Check the validation flag at the end of the entry */
3124 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
3125 AR5K_KEYTABLE_VALID;
3126}
3127
3128int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
3129 const struct ieee80211_key_conf *key, const u8 *mac)
3130{
3131 unsigned int i;
3132 __le32 key_v[5] = {};
3133 u32 keytype;
3134
3135 ATH5K_TRACE(ah->ah_sc);
3136
3137 /* key->keylen comes in from mac80211 in bytes */
3138
3139 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
3140 return -EOPNOTSUPP;
3141
3142 switch (key->keylen) {
3143 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
3144 case 40 / 8:
3145 memcpy(&key_v[0], key->key, 5);
3146 keytype = AR5K_KEYTABLE_TYPE_40;
3147 break;
3148
3149 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
3150 case 104 / 8:
3151 memcpy(&key_v[0], &key->key[0], 6);
3152 memcpy(&key_v[2], &key->key[6], 6);
3153 memcpy(&key_v[4], &key->key[12], 1);
3154 keytype = AR5K_KEYTABLE_TYPE_104;
3155 break;
3156 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
3157 case 128 / 8:
3158 memcpy(&key_v[0], &key->key[0], 6);
3159 memcpy(&key_v[2], &key->key[6], 6);
3160 memcpy(&key_v[4], &key->key[12], 4);
3161 keytype = AR5K_KEYTABLE_TYPE_128;
3162 break;
3163
3164 default:
3165 return -EINVAL; /* shouldn't happen */
3166 }
3167
3168 for (i = 0; i < ARRAY_SIZE(key_v); i++)
3169 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
3170 AR5K_KEYTABLE_OFF(entry, i));
3171
3172 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
3173
3174 return ath5k_hw_set_key_lladdr(ah, entry, mac);
3175}
3176
3177int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
3178{
3179 u32 low_id, high_id;
3180
3181 ATH5K_TRACE(ah->ah_sc);
3182 /* Invalid entry (key table overflow) */
3183 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3184
3185 /* MAC may be NULL if it's a broadcast key. In this case no need to
3186 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3187 if (unlikely(mac == NULL)) {
3188 low_id = 0xffffffff;
3189 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3190 } else {
3191 low_id = AR5K_LOW_ID(mac);
3192 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3193 }
3194
3195 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3196 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3197
3198 return 0;
3199}
3200
3201
3202/********************************************\
3203Queue Control Unit, DFS Control Unit Functions
3204\********************************************/
3205
3206/*
3207 * Initialize a transmit queue
3208 */
3209int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3210 struct ath5k_txq_info *queue_info)
3211{
3212 unsigned int queue;
3213 int ret;
3214
3215 ATH5K_TRACE(ah->ah_sc);
3216
3217 /*
3218 * Get queue by type
3219 */
3220 /*5210 only has 2 queues*/
3221 if (ah->ah_version == AR5K_AR5210) {
3222 switch (queue_type) {
3223 case AR5K_TX_QUEUE_DATA:
3224 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3225 break;
3226 case AR5K_TX_QUEUE_BEACON:
3227 case AR5K_TX_QUEUE_CAB:
3228 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3229 break;
3230 default:
3231 return -EINVAL;
3232 }
3233 } else {
3234 switch (queue_type) {
3235 case AR5K_TX_QUEUE_DATA:
3236 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3237 ah->ah_txq[queue].tqi_type !=
3238 AR5K_TX_QUEUE_INACTIVE; queue++) {
3239
3240 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3241 return -EINVAL;
3242 }
3243 break;
3244 case AR5K_TX_QUEUE_UAPSD:
3245 queue = AR5K_TX_QUEUE_ID_UAPSD;
3246 break;
3247 case AR5K_TX_QUEUE_BEACON:
3248 queue = AR5K_TX_QUEUE_ID_BEACON;
3249 break;
3250 case AR5K_TX_QUEUE_CAB:
3251 queue = AR5K_TX_QUEUE_ID_CAB;
3252 break;
3253 case AR5K_TX_QUEUE_XR_DATA:
3254 if (ah->ah_version != AR5K_AR5212)
3255 ATH5K_ERR(ah->ah_sc,
3256 "XR data queues only supported in"
3257 " 5212!\n");
3258 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3259 break;
3260 default:
3261 return -EINVAL;
3262 }
3263 }
3264
3265 /*
3266 * Setup internal queue structure
3267 */
3268 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3269 ah->ah_txq[queue].tqi_type = queue_type;
3270
3271 if (queue_info != NULL) {
3272 queue_info->tqi_type = queue_type;
3273 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3274 if (ret)
3275 return ret;
3276 }
3277 /*
3278 * We use ah_txq_status to hold a temp value for
3279 * the Secondary interrupt mask registers on 5211+
3280 * check out ath5k_hw_reset_tx_queue
3281 */
3282 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3283
3284 return queue;
3285}
3286
3287/*
3288 * Setup a transmit queue
3289 */
3290int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3291 const struct ath5k_txq_info *queue_info)
3292{
3293 ATH5K_TRACE(ah->ah_sc);
3294 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3295
3296 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3297 return -EIO;
3298
3299 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3300
3301 /*XXX: Is this supported on 5210 ?*/
3302 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3303 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3304 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3305 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3306 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3307
3308 return 0;
3309}
3310
3311/*
3312 * Get properties for a specific transmit queue
3313 */
3314int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3315 struct ath5k_txq_info *queue_info)
3316{
3317 ATH5K_TRACE(ah->ah_sc);
3318 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3319 return 0;
3320}
3321
3322/*
3323 * Set a transmit queue inactive
3324 */
3325void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3326{
3327 ATH5K_TRACE(ah->ah_sc);
3328 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3329 return;
3330
3331 /* This queue will be skipped in further operations */
3332 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3333 /*For SIMR setup*/
3334 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3335}
3336
3337/*
3338 * Set DFS params for a transmit queue
3339 */
3340int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3341{
3342 u32 cw_min, cw_max, retry_lg, retry_sh;
3343 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3344
3345 ATH5K_TRACE(ah->ah_sc);
3346 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3347
3348 tq = &ah->ah_txq[queue];
3349
3350 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3351 return 0;
3352
3353 if (ah->ah_version == AR5K_AR5210) {
3354 /* Only handle data queues, others will be ignored */
3355 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3356 return 0;
3357
3358 /* Set Slot time */
Joe Perchese9010e22008-03-07 14:21:16 -08003359 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003360 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3361 AR5K_SLOT_TIME);
3362 /* Set ACK_CTS timeout */
Joe Perchese9010e22008-03-07 14:21:16 -08003363 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003364 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3365 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3366 /* Set Transmit Latency */
Joe Perchese9010e22008-03-07 14:21:16 -08003367 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003368 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3369 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3370 /* Set IFS0 */
Joe Perchese9010e22008-03-07 14:21:16 -08003371 if (ah->ah_turbo)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003372 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3373 (ah->ah_aifs + tq->tqi_aifs) *
3374 AR5K_INIT_SLOT_TIME_TURBO) <<
3375 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3376 AR5K_IFS0);
3377 else
3378 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3379 (ah->ah_aifs + tq->tqi_aifs) *
3380 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3381 AR5K_INIT_SIFS, AR5K_IFS0);
3382
3383 /* Set IFS1 */
Joe Perchese9010e22008-03-07 14:21:16 -08003384 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003385 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3386 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
Nick Kossifidis0bacdf32008-07-30 13:18:59 +03003387 /* Set AR5K_PHY_SETTLING */
Joe Perchese9010e22008-03-07 14:21:16 -08003388 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Nick Kossifidis0bacdf32008-07-30 13:18:59 +03003389 (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
3390 | 0x38 :
3391 (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
3392 | 0x1C,
3393 AR5K_PHY_SETTLING);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003394 /* Set Frame Control Register */
Joe Perchese9010e22008-03-07 14:21:16 -08003395 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003396 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3397 AR5K_PHY_TURBO_SHORT | 0x2020) :
3398 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3399 AR5K_PHY_FRAME_CTL_5210);
3400 }
3401
3402 /*
3403 * Calculate cwmin/max by channel mode
3404 */
3405 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3406 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3407 ah->ah_aifs = AR5K_TUNE_AIFS;
3408 /*XR is only supported on 5212*/
3409 if (IS_CHAN_XR(ah->ah_current_channel) &&
3410 ah->ah_version == AR5K_AR5212) {
3411 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3412 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3413 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3414 /*B mode is not supported on 5210*/
3415 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3416 ah->ah_version != AR5K_AR5210) {
3417 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3418 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3419 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3420 }
3421
3422 cw_min = 1;
3423 while (cw_min < ah->ah_cw_min)
3424 cw_min = (cw_min << 1) | 1;
3425
3426 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3427 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3428 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3429 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3430
3431 /*
3432 * Calculate and set retry limits
3433 */
Joe Perchese9010e22008-03-07 14:21:16 -08003434 if (ah->ah_software_retry) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003435 /* XXX Need to test this */
3436 retry_lg = ah->ah_limit_tx_retries;
3437 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3438 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3439 } else {
3440 retry_lg = AR5K_INIT_LG_RETRY;
3441 retry_sh = AR5K_INIT_SH_RETRY;
3442 }
3443
3444 /*No QCU/DCU [5210]*/
3445 if (ah->ah_version == AR5K_AR5210) {
3446 ath5k_hw_reg_write(ah,
3447 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3448 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3449 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3450 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3451 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3452 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3453 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3454 AR5K_NODCU_RETRY_LMT);
3455 } else {
3456 /*QCU/DCU [5211+]*/
3457 ath5k_hw_reg_write(ah,
3458 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3459 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3460 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3461 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3462 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3463 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3464 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3465
3466 /*===Rest is also for QCU/DCU only [5211+]===*/
3467
3468 /*
3469 * Set initial content window (cw_min/cw_max)
3470 * and arbitrated interframe space (aifs)...
3471 */
3472 ath5k_hw_reg_write(ah,
3473 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3474 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3475 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3476 AR5K_DCU_LCL_IFS_AIFS),
3477 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3478
3479 /*
3480 * Set misc registers
3481 */
3482 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3483 AR5K_QUEUE_MISC(queue));
3484
3485 if (tq->tqi_cbr_period) {
3486 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3487 AR5K_QCU_CBRCFG_INTVAL) |
3488 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3489 AR5K_QCU_CBRCFG_ORN_THRES),
3490 AR5K_QUEUE_CBRCFG(queue));
3491 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3492 AR5K_QCU_MISC_FRSHED_CBR);
3493 if (tq->tqi_cbr_overflow_limit)
3494 AR5K_REG_ENABLE_BITS(ah,
3495 AR5K_QUEUE_MISC(queue),
3496 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3497 }
3498
3499 if (tq->tqi_ready_time)
3500 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3501 AR5K_QCU_RDYTIMECFG_INTVAL) |
3502 AR5K_QCU_RDYTIMECFG_ENABLE,
3503 AR5K_QUEUE_RDYTIMECFG(queue));
3504
3505 if (tq->tqi_burst_time) {
3506 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3507 AR5K_DCU_CHAN_TIME_DUR) |
3508 AR5K_DCU_CHAN_TIME_ENABLE,
3509 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3510
3511 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3512 AR5K_REG_ENABLE_BITS(ah,
3513 AR5K_QUEUE_MISC(queue),
3514 AR5K_QCU_MISC_TXE);
3515 }
3516
3517 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3518 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3519 AR5K_QUEUE_DFS_MISC(queue));
3520
3521 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3522 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3523 AR5K_QUEUE_DFS_MISC(queue));
3524
3525 /*
3526 * Set registers by queue type
3527 */
3528 switch (tq->tqi_type) {
3529 case AR5K_TX_QUEUE_BEACON:
3530 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3531 AR5K_QCU_MISC_FRSHED_DBA_GT |
3532 AR5K_QCU_MISC_CBREXP_BCN |
3533 AR5K_QCU_MISC_BCN_ENABLE);
3534
3535 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3536 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3537 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3538 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3539 AR5K_DCU_MISC_BCN_ENABLE);
3540
3541 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3542 (AR5K_TUNE_SW_BEACON_RESP -
3543 AR5K_TUNE_DMA_BEACON_RESP) -
3544 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3545 AR5K_QCU_RDYTIMECFG_ENABLE,
3546 AR5K_QUEUE_RDYTIMECFG(queue));
3547 break;
3548
3549 case AR5K_TX_QUEUE_CAB:
3550 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3551 AR5K_QCU_MISC_FRSHED_DBA_GT |
3552 AR5K_QCU_MISC_CBREXP |
3553 AR5K_QCU_MISC_CBREXP_BCN);
3554
3555 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3556 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3557 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3558 break;
3559
3560 case AR5K_TX_QUEUE_UAPSD:
3561 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3562 AR5K_QCU_MISC_CBREXP);
3563 break;
3564
3565 case AR5K_TX_QUEUE_DATA:
3566 default:
3567 break;
3568 }
3569
3570 /*
3571 * Enable interrupts for this tx queue
3572 * in the secondary interrupt mask registers
3573 */
3574 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3575 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3576
3577 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3578 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3579
3580 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3581 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3582
3583 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3584 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3585
3586 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3587 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3588
3589
3590 /* Update secondary interrupt mask registers */
3591 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3592 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3593 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3594 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3595 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3596
3597 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3598 AR5K_SIMR0_QCU_TXOK) |
3599 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3600 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3601 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3602 AR5K_SIMR1_QCU_TXERR) |
3603 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3604 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3605 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3606 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3607 }
3608
3609 return 0;
3610}
3611
3612/*
3613 * Get number of pending frames
3614 * for a specific queue [5211+]
3615 */
3616u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3617 ATH5K_TRACE(ah->ah_sc);
3618 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3619
3620 /* Return if queue is declared inactive */
3621 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3622 return false;
3623
3624 /* XXX: How about AR5K_CFG_TXCNT ? */
3625 if (ah->ah_version == AR5K_AR5210)
3626 return false;
3627
3628 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3629}
3630
3631/*
3632 * Set slot time
3633 */
3634int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3635{
3636 ATH5K_TRACE(ah->ah_sc);
3637 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3638 return -EINVAL;
3639
3640 if (ah->ah_version == AR5K_AR5210)
3641 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3642 ah->ah_turbo), AR5K_SLOT_TIME);
3643 else
3644 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3645
3646 return 0;
3647}
3648
3649/*
3650 * Get slot time
3651 */
3652unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3653{
3654 ATH5K_TRACE(ah->ah_sc);
3655 if (ah->ah_version == AR5K_AR5210)
3656 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3657 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3658 else
3659 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3660}
3661
3662
3663/******************************\
3664 Hardware Descriptor Functions
3665\******************************/
3666
3667/*
3668 * TX Descriptor
3669 */
3670
3671/*
3672 * Initialize the 2-word tx descriptor on 5210/5211
3673 */
3674static int
3675ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3676 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3677 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3678 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3679 unsigned int rtscts_rate, unsigned int rtscts_duration)
3680{
3681 u32 frame_type;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003682 struct ath5k_hw_2w_tx_ctl *tx_ctl;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003683 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003684
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003685 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003686
3687 /*
3688 * Validate input
3689 * - Zero retries don't make sense.
3690 * - A zero rate will put the HW into a mode where it continously sends
3691 * noise on the channel, so it is important to avoid this.
3692 */
3693 if (unlikely(tx_tries0 == 0)) {
3694 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3695 WARN_ON(1);
3696 return -EINVAL;
3697 }
3698 if (unlikely(tx_rate0 == 0)) {
3699 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3700 WARN_ON(1);
3701 return -EINVAL;
3702 }
3703
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003704 /* Clear descriptor */
3705 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003706
3707 /* Setup control descriptor */
3708
3709 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003710
3711 /* remove padding we might have added before */
3712 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3713
3714 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003715 return -EINVAL;
3716
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003717 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003718
3719 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003720
3721 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3722 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003723 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003724
Bruno Randolf281c56d2008-02-05 18:44:55 +09003725 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003726 return -EINVAL;
3727
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003728 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003729
3730 /*
3731 * Verify and set header length
3732 * XXX: I only found that on 5210 code, does it work on 5211 ?
3733 */
3734 if (ah->ah_version == AR5K_AR5210) {
3735 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3736 return -EINVAL;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003737 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003738 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3739 }
3740
3741 /*Diferences between 5210-5211*/
3742 if (ah->ah_version == AR5K_AR5210) {
3743 switch (type) {
3744 case AR5K_PKT_TYPE_BEACON:
3745 case AR5K_PKT_TYPE_PROBE_RESP:
3746 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3747 case AR5K_PKT_TYPE_PIFS:
3748 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3749 default:
3750 frame_type = type /*<< 2 ?*/;
3751 }
3752
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003753 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003754 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3755 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3756 } else {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003757 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003758 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3759 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003760 tx_ctl->tx_control_1 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003761 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3762 }
3763#define _TX_FLAGS(_c, _flag) \
3764 if (flags & AR5K_TXDESC_##_flag) \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003765 tx_ctl->tx_control_##_c |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003766 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3767
3768 _TX_FLAGS(0, CLRDMASK);
3769 _TX_FLAGS(0, VEOL);
3770 _TX_FLAGS(0, INTREQ);
3771 _TX_FLAGS(0, RTSENA);
3772 _TX_FLAGS(1, NOACK);
3773
3774#undef _TX_FLAGS
3775
3776 /*
3777 * WEP crap
3778 */
3779 if (key_index != AR5K_TXKEYIX_INVALID) {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003780 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003781 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003782 tx_ctl->tx_control_1 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003783 AR5K_REG_SM(key_index,
3784 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3785 }
3786
3787 /*
3788 * RTS/CTS Duration [5210 ?]
3789 */
3790 if ((ah->ah_version == AR5K_AR5210) &&
3791 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003792 tx_ctl->tx_control_1 |= rtscts_duration &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003793 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3794
3795 return 0;
3796}
3797
3798/*
3799 * Initialize the 4-word tx descriptor on 5212
3800 */
3801static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3802 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3803 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3804 unsigned int tx_tries0, unsigned int key_index,
3805 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3806 unsigned int rtscts_duration)
3807{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003808 struct ath5k_hw_4w_tx_ctl *tx_ctl;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003809 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003810
3811 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003812 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003813
3814 /*
3815 * Validate input
3816 * - Zero retries don't make sense.
3817 * - A zero rate will put the HW into a mode where it continously sends
3818 * noise on the channel, so it is important to avoid this.
3819 */
3820 if (unlikely(tx_tries0 == 0)) {
3821 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3822 WARN_ON(1);
3823 return -EINVAL;
3824 }
3825 if (unlikely(tx_rate0 == 0)) {
3826 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3827 WARN_ON(1);
3828 return -EINVAL;
3829 }
3830
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003831 /* Clear descriptor */
3832 memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003833
3834 /* Setup control descriptor */
3835
3836 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003837
3838 /* remove padding we might have added before */
3839 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3840
3841 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003842 return -EINVAL;
3843
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003844 tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003845
3846 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003847
3848 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3849 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003850 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003851
Bruno Randolf281c56d2008-02-05 18:44:55 +09003852 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003853 return -EINVAL;
3854
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003855 tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003856
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003857 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003858 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3859 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003860 tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003861 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003862 tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003863 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003864 tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003865
3866#define _TX_FLAGS(_c, _flag) \
3867 if (flags & AR5K_TXDESC_##_flag) \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003868 tx_ctl->tx_control_##_c |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003869 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3870
3871 _TX_FLAGS(0, CLRDMASK);
3872 _TX_FLAGS(0, VEOL);
3873 _TX_FLAGS(0, INTREQ);
3874 _TX_FLAGS(0, RTSENA);
3875 _TX_FLAGS(0, CTSENA);
3876 _TX_FLAGS(1, NOACK);
3877
3878#undef _TX_FLAGS
3879
3880 /*
3881 * WEP crap
3882 */
3883 if (key_index != AR5K_TXKEYIX_INVALID) {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003884 tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3885 tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003886 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3887 }
3888
3889 /*
3890 * RTS/CTS
3891 */
3892 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3893 if ((flags & AR5K_TXDESC_RTSENA) &&
3894 (flags & AR5K_TXDESC_CTSENA))
3895 return -EINVAL;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003896 tx_ctl->tx_control_2 |= rtscts_duration &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003897 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003898 tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003899 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3900 }
3901
3902 return 0;
3903}
3904
3905/*
3906 * Initialize a 4-word multirate tx descriptor on 5212
3907 */
Jiri Slabyb9887632008-02-15 21:58:52 +01003908static int
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003909ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3910 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3911 unsigned int tx_rate3, u_int tx_tries3)
3912{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003913 struct ath5k_hw_4w_tx_ctl *tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003914
3915 /*
3916 * Rates can be 0 as long as the retry count is 0 too.
3917 * A zero rate and nonzero retry count will put the HW into a mode where
3918 * it continously sends noise on the channel, so it is important to
3919 * avoid this.
3920 */
3921 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3922 (tx_rate2 == 0 && tx_tries2 != 0) ||
3923 (tx_rate3 == 0 && tx_tries3 != 0))) {
3924 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3925 WARN_ON(1);
3926 return -EINVAL;
3927 }
3928
3929 if (ah->ah_version == AR5K_AR5212) {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003930 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003931
3932#define _XTX_TRIES(_n) \
3933 if (tx_tries##_n) { \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003934 tx_ctl->tx_control_2 |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003935 AR5K_REG_SM(tx_tries##_n, \
3936 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003937 tx_ctl->tx_control_3 |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003938 AR5K_REG_SM(tx_rate##_n, \
3939 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3940 }
3941
3942 _XTX_TRIES(1);
3943 _XTX_TRIES(2);
3944 _XTX_TRIES(3);
3945
3946#undef _XTX_TRIES
3947
Jiri Slabyb9887632008-02-15 21:58:52 +01003948 return 1;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003949 }
3950
Jiri Slabyb9887632008-02-15 21:58:52 +01003951 return 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003952}
3953
3954/*
3955 * Proccess the tx status descriptor on 5210/5211
3956 */
3957static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09003958 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003959{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003960 struct ath5k_hw_2w_tx_ctl *tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003961 struct ath5k_hw_tx_status *tx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003962
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003963 ATH5K_TRACE(ah->ah_sc);
3964
3965 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3966 tx_status = &desc->ud.ds_tx5210.tx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003967
3968 /* No frame has been send or error */
3969 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3970 return -EINPROGRESS;
3971
3972 /*
3973 * Get descriptor status
3974 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09003975 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003976 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003977 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003978 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003979 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003980 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003981 /*TODO: ts->ts_virtcol + test*/
3982 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003983 AR5K_DESC_TX_STATUS1_SEQ_NUM);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003984 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003985 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003986 ts->ts_antenna = 1;
3987 ts->ts_status = 0;
3988 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003989 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3990
3991 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3992 if (tx_status->tx_status_0 &
3993 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
Bruno Randolfb47f4072008-03-05 18:35:45 +09003994 ts->ts_status |= AR5K_TXERR_XRETRY;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003995
3996 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
Bruno Randolfb47f4072008-03-05 18:35:45 +09003997 ts->ts_status |= AR5K_TXERR_FIFO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003998
3999 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004000 ts->ts_status |= AR5K_TXERR_FILT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004001 }
4002
4003 return 0;
4004}
4005
4006/*
4007 * Proccess a tx descriptor on 5212
4008 */
4009static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004010 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004011{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004012 struct ath5k_hw_4w_tx_ctl *tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004013 struct ath5k_hw_tx_status *tx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004014
4015 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004016
4017 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
4018 tx_status = &desc->ud.ds_tx5212.tx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004019
4020 /* No frame has been send or error */
4021 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
4022 return -EINPROGRESS;
4023
4024 /*
4025 * Get descriptor status
4026 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09004027 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004028 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004029 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004030 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004031 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004032 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004033 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004034 AR5K_DESC_TX_STATUS1_SEQ_NUM);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004035 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004036 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004037 ts->ts_antenna = (tx_status->tx_status_1 &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004038 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004039 ts->ts_status = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004040
4041 switch (AR5K_REG_MS(tx_status->tx_status_1,
4042 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
4043 case 0:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004044 ts->ts_rate = tx_ctl->tx_control_3 &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004045 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
4046 break;
4047 case 1:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004048 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004049 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004050 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004051 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
4052 break;
4053 case 2:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004054 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004055 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004056 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004057 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
4058 break;
4059 case 3:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004060 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004061 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004062 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004063 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
4064 break;
4065 }
4066
4067 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
4068 if (tx_status->tx_status_0 &
4069 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004070 ts->ts_status |= AR5K_TXERR_XRETRY;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004071
4072 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004073 ts->ts_status |= AR5K_TXERR_FIFO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004074
4075 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004076 ts->ts_status |= AR5K_TXERR_FILT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004077 }
4078
4079 return 0;
4080}
4081
4082/*
4083 * RX Descriptor
4084 */
4085
4086/*
4087 * Initialize an rx descriptor
4088 */
4089int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
4090 u32 size, unsigned int flags)
4091{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004092 struct ath5k_hw_rx_ctl *rx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004093
4094 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004095 rx_ctl = &desc->ud.ds_rx.rx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004096
4097 /*
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004098 * Clear the descriptor
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004099 * If we don't clean the status descriptor,
4100 * while scanning we get too many results,
4101 * most of them virtual, after some secs
4102 * of scanning system hangs. M.F.
4103 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004104 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004105
4106 /* Setup descriptor */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004107 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
4108 if (unlikely(rx_ctl->rx_control_1 != size))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004109 return -EINVAL;
4110
4111 if (flags & AR5K_RXDESC_INTREQ)
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004112 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004113
4114 return 0;
4115}
4116
4117/*
4118 * Proccess the rx status descriptor on 5210/5211
4119 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004120static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004121 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004122{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004123 struct ath5k_hw_rx_status *rx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004124
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004125 rx_status = &desc->ud.ds_rx.u.rx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004126
4127 /* No frame received / not ready */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004128 if (unlikely((rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004129 == 0))
4130 return -EINPROGRESS;
4131
4132 /*
4133 * Frame receive status
4134 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09004135 rs->rs_datalen = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004136 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004137 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004138 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004139 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004140 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004141 rs->rs_antenna = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004142 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004143 rs->rs_more = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004144 AR5K_5210_RX_DESC_STATUS0_MORE;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004145 /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
4146 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004147 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004148 rs->rs_status = 0;
Bob Copelandd6894b52008-05-12 21:16:44 -04004149 rs->rs_phyerr = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004150
4151 /*
4152 * Key table status
4153 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004154 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004155 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004156 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004157 else
Bruno Randolfb47f4072008-03-05 18:35:45 +09004158 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004159
4160 /*
4161 * Receive/descriptor errors
4162 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004163 if ((rx_status->rx_status_1 &
4164 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4165 if (rx_status->rx_status_1 &
4166 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004167 rs->rs_status |= AR5K_RXERR_CRC;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004168
4169 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004170 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004171 rs->rs_status |= AR5K_RXERR_FIFO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004172
4173 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004174 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
Bruno Randolfb47f4072008-03-05 18:35:45 +09004175 rs->rs_status |= AR5K_RXERR_PHY;
Bob Copelandd6894b52008-05-12 21:16:44 -04004176 rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004177 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004178 }
4179
4180 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004181 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004182 rs->rs_status |= AR5K_RXERR_DECRYPT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004183 }
4184
4185 return 0;
4186}
4187
4188/*
4189 * Proccess the rx status descriptor on 5212
4190 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004191static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004192 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004193{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004194 struct ath5k_hw_rx_status *rx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004195 struct ath5k_hw_rx_error *rx_err;
4196
4197 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004198 rx_status = &desc->ud.ds_rx.u.rx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004199
4200 /* Overlay on error */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004201 rx_err = &desc->ud.ds_rx.u.rx_err;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004202
4203 /* No frame received / not ready */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004204 if (unlikely((rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004205 == 0))
4206 return -EINPROGRESS;
4207
4208 /*
4209 * Frame receive status
4210 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09004211 rs->rs_datalen = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004212 AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004213 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004214 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004215 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004216 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004217 rs->rs_antenna = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004218 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004219 rs->rs_more = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004220 AR5K_5212_RX_DESC_STATUS0_MORE;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004221 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004222 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004223 rs->rs_status = 0;
Bob Copelandd6894b52008-05-12 21:16:44 -04004224 rs->rs_phyerr = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004225
4226 /*
4227 * Key table status
4228 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004229 if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004230 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004231 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004232 else
Bruno Randolfb47f4072008-03-05 18:35:45 +09004233 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004234
4235 /*
4236 * Receive/descriptor errors
4237 */
4238 if ((rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004239 AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4240 if (rx_status->rx_status_1 &
4241 AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004242 rs->rs_status |= AR5K_RXERR_CRC;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004243
4244 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004245 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
Bruno Randolfb47f4072008-03-05 18:35:45 +09004246 rs->rs_status |= AR5K_RXERR_PHY;
Bob Copelandd6894b52008-05-12 21:16:44 -04004247 rs->rs_phyerr |= AR5K_REG_MS(rx_err->rx_error_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004248 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004249 }
4250
4251 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004252 AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004253 rs->rs_status |= AR5K_RXERR_DECRYPT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004254
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004255 if (rx_status->rx_status_1 &
4256 AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004257 rs->rs_status |= AR5K_RXERR_MIC;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004258 }
4259
4260 return 0;
4261}
4262
4263
4264/****************\
4265 GPIO Functions
4266\****************/
4267
4268/*
4269 * Set led state
4270 */
4271void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4272{
4273 u32 led;
4274 /*5210 has different led mode handling*/
4275 u32 led_5210;
4276
4277 ATH5K_TRACE(ah->ah_sc);
4278
4279 /*Reset led status*/
4280 if (ah->ah_version != AR5K_AR5210)
4281 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4282 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4283 else
4284 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4285
4286 /*
4287 * Some blinking values, define at your wish
4288 */
4289 switch (state) {
4290 case AR5K_LED_SCAN:
4291 case AR5K_LED_AUTH:
4292 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4293 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4294 break;
4295
4296 case AR5K_LED_INIT:
4297 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4298 led_5210 = AR5K_PCICFG_LED_PEND;
4299 break;
4300
4301 case AR5K_LED_ASSOC:
4302 case AR5K_LED_RUN:
4303 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4304 led_5210 = AR5K_PCICFG_LED_ASSOC;
4305 break;
4306
4307 default:
4308 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4309 led_5210 = AR5K_PCICFG_LED_PEND;
4310 break;
4311 }
4312
4313 /*Write new status to the register*/
4314 if (ah->ah_version != AR5K_AR5210)
4315 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4316 else
4317 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4318}
4319
4320/*
4321 * Set GPIO outputs
4322 */
4323int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4324{
4325 ATH5K_TRACE(ah->ah_sc);
4326 if (gpio > AR5K_NUM_GPIO)
4327 return -EINVAL;
4328
4329 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4330 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4331
4332 return 0;
4333}
4334
4335/*
4336 * Set GPIO inputs
4337 */
4338int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4339{
4340 ATH5K_TRACE(ah->ah_sc);
4341 if (gpio > AR5K_NUM_GPIO)
4342 return -EINVAL;
4343
4344 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4345 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4346
4347 return 0;
4348}
4349
4350/*
4351 * Get GPIO state
4352 */
4353u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4354{
4355 ATH5K_TRACE(ah->ah_sc);
4356 if (gpio > AR5K_NUM_GPIO)
4357 return 0xffffffff;
4358
4359 /* GPIO input magic */
4360 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4361 0x1;
4362}
4363
4364/*
4365 * Set GPIO state
4366 */
4367int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4368{
4369 u32 data;
4370 ATH5K_TRACE(ah->ah_sc);
4371
4372 if (gpio > AR5K_NUM_GPIO)
4373 return -EINVAL;
4374
4375 /* GPIO output magic */
4376 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4377
4378 data &= ~(1 << gpio);
4379 data |= (val & 1) << gpio;
4380
4381 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4382
4383 return 0;
4384}
4385
4386/*
4387 * Initialize the GPIO interrupt (RFKill switch)
4388 */
4389void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4390 u32 interrupt_level)
4391{
4392 u32 data;
4393
4394 ATH5K_TRACE(ah->ah_sc);
4395 if (gpio > AR5K_NUM_GPIO)
4396 return;
4397
4398 /*
4399 * Set the GPIO interrupt
4400 */
4401 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4402 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4403 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4404 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4405
4406 ath5k_hw_reg_write(ah, interrupt_level ? data :
4407 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4408
4409 ah->ah_imr |= AR5K_IMR_GPIO;
4410
4411 /* Enable GPIO interrupts */
4412 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4413}
4414
4415
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004416
4417
4418/****************\
4419 Misc functions
4420\****************/
4421
4422int ath5k_hw_get_capability(struct ath5k_hw *ah,
4423 enum ath5k_capability_type cap_type,
4424 u32 capability, u32 *result)
4425{
4426 ATH5K_TRACE(ah->ah_sc);
4427
4428 switch (cap_type) {
4429 case AR5K_CAP_NUM_TXQUEUES:
4430 if (result) {
4431 if (ah->ah_version == AR5K_AR5210)
4432 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4433 else
4434 *result = AR5K_NUM_TX_QUEUES;
4435 goto yes;
4436 }
4437 case AR5K_CAP_VEOL:
4438 goto yes;
4439 case AR5K_CAP_COMPRESSION:
4440 if (ah->ah_version == AR5K_AR5212)
4441 goto yes;
4442 else
4443 goto no;
4444 case AR5K_CAP_BURST:
4445 goto yes;
4446 case AR5K_CAP_TPC:
4447 goto yes;
4448 case AR5K_CAP_BSSIDMASK:
4449 if (ah->ah_version == AR5K_AR5212)
4450 goto yes;
4451 else
4452 goto no;
4453 case AR5K_CAP_XR:
4454 if (ah->ah_version == AR5K_AR5212)
4455 goto yes;
4456 else
4457 goto no;
4458 default:
4459 goto no;
4460 }
4461
4462no:
4463 return -EINVAL;
4464yes:
4465 return 0;
4466}
4467
4468static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4469 u16 assoc_id)
4470{
4471 ATH5K_TRACE(ah->ah_sc);
4472
4473 if (ah->ah_version == AR5K_AR5210) {
4474 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4475 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4476 return 0;
4477 }
4478
4479 return -EIO;
4480}
4481
4482static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4483{
4484 ATH5K_TRACE(ah->ah_sc);
4485
4486 if (ah->ah_version == AR5K_AR5210) {
4487 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4488 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4489 return 0;
4490 }
4491
4492 return -EIO;
4493}