blob: dc51b844c62d5c673a4fcd579a1c8ce524b0ce77 [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 /*
1082 * Enable calibration and wait until completion
1083 */
1084 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1085 AR5K_PHY_AGCCTL_CAL);
1086
1087 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1088 AR5K_PHY_AGCCTL_CAL, 0, false)) {
1089 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001090 channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001091 return -EAGAIN;
1092 }
1093
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001094 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001095 if (ret)
1096 return ret;
1097
1098 ah->ah_calibration = false;
1099
1100 /* A and G modes can use QAM modulation which requires enabling
1101 * I and Q calibration. Don't bother in B mode. */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001102 if (!(mode == AR5K_MODE_11B)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001103 ah->ah_calibration = true;
1104 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1105 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1106 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1107 AR5K_PHY_IQ_RUN);
1108 }
1109
1110 /*
1111 * Reset queues and start beacon timers at the end of the reset routine
1112 */
1113 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
1114 /*No QCU on 5210*/
1115 if (ah->ah_version != AR5K_AR5210)
1116 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
1117
1118 ret = ath5k_hw_reset_tx_queue(ah, i);
1119 if (ret) {
1120 ATH5K_ERR(ah->ah_sc,
1121 "failed to reset TX queue #%d\n", i);
1122 return ret;
1123 }
1124 }
1125
1126 /* Pre-enable interrupts on 5211/5212*/
1127 if (ah->ah_version != AR5K_AR5210)
1128 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
1129 AR5K_INT_FATAL);
1130
1131 /*
1132 * Set RF kill flags if supported by the device (read from the EEPROM)
1133 * Disable gpio_intr for now since it results system hang.
1134 * TODO: Handle this in ath5k_intr
1135 */
1136#if 0
1137 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1138 ath5k_hw_set_gpio_input(ah, 0);
1139 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1140 if (ah->ah_gpio[0] == 0)
1141 ath5k_hw_set_gpio_intr(ah, 0, 1);
1142 else
1143 ath5k_hw_set_gpio_intr(ah, 0, 0);
1144 }
1145#endif
1146
1147 /*
1148 * Set the 32MHz reference clock on 5212 phy clock sleep register
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05001149 *
1150 * TODO: Find out how to switch to external 32Khz clock to save power
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001151 */
1152 if (ah->ah_version == AR5K_AR5212) {
1153 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1154 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1155 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1156 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1157 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
Nick Kossifidis903b4742008-02-28 14:50:50 -05001158 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
Nick Kossifidis2203d6b2008-07-20 06:36:52 +03001159
1160 data = ath5k_hw_reg_read(ah, AR5K_USEC_5211) & 0xffffc07f ;
1161 data |= (ah->ah_phy_spending == AR5K_PHY_SPENDING_18) ?
1162 0x00000f80 : 0x00001380 ;
1163 ath5k_hw_reg_write(ah, data, AR5K_USEC_5211);
1164 data = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001165 }
1166
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05001167 if (ah->ah_version == AR5K_AR5212) {
1168 ath5k_hw_reg_write(ah, 0x000100aa, 0x8118);
1169 ath5k_hw_reg_write(ah, 0x00003210, 0x811c);
1170 ath5k_hw_reg_write(ah, 0x00000052, 0x8108);
1171 if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2413)
1172 ath5k_hw_reg_write(ah, 0x00000004, 0x8120);
1173 }
1174
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001175 /*
1176 * Disable beacons and reset the register
1177 */
1178 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1179 AR5K_BEACON_RESET_TSF);
1180
1181 return 0;
1182}
1183
1184/*
1185 * Reset chipset
1186 */
1187static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1188{
1189 int ret;
1190 u32 mask = val ? val : ~0U;
1191
1192 ATH5K_TRACE(ah->ah_sc);
1193
1194 /* Read-and-clear RX Descriptor Pointer*/
1195 ath5k_hw_reg_read(ah, AR5K_RXDP);
1196
1197 /*
1198 * Reset the device and wait until success
1199 */
1200 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1201
1202 /* Wait at least 128 PCI clocks */
1203 udelay(15);
1204
1205 if (ah->ah_version == AR5K_AR5210) {
1206 val &= AR5K_RESET_CTL_CHIP;
1207 mask &= AR5K_RESET_CTL_CHIP;
1208 } else {
1209 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1210 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1211 }
1212
1213 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1214
1215 /*
1216 * Reset configuration register (for hw byte-swap). Note that this
1217 * is only set for big endian. We do the necessary magic in
1218 * AR5K_INIT_CFG.
1219 */
1220 if ((val & AR5K_RESET_CTL_PCU) == 0)
1221 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1222
1223 return ret;
1224}
1225
1226/*
1227 * Power management functions
1228 */
1229
1230/*
1231 * Sleep control
1232 */
1233int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1234 bool set_chip, u16 sleep_duration)
1235{
1236 unsigned int i;
1237 u32 staid;
1238
1239 ATH5K_TRACE(ah->ah_sc);
1240 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1241
1242 switch (mode) {
1243 case AR5K_PM_AUTO:
1244 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1245 /* fallthrough */
1246 case AR5K_PM_NETWORK_SLEEP:
Joe Perchese9010e22008-03-07 14:21:16 -08001247 if (set_chip)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001248 ath5k_hw_reg_write(ah,
1249 AR5K_SLEEP_CTL_SLE | sleep_duration,
1250 AR5K_SLEEP_CTL);
1251
1252 staid |= AR5K_STA_ID1_PWR_SV;
1253 break;
1254
1255 case AR5K_PM_FULL_SLEEP:
Joe Perchese9010e22008-03-07 14:21:16 -08001256 if (set_chip)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001257 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1258 AR5K_SLEEP_CTL);
1259
1260 staid |= AR5K_STA_ID1_PWR_SV;
1261 break;
1262
1263 case AR5K_PM_AWAKE:
Joe Perchese9010e22008-03-07 14:21:16 -08001264 if (!set_chip)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001265 goto commit;
1266
1267 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1268 AR5K_SLEEP_CTL);
1269
1270 for (i = 5000; i > 0; i--) {
1271 /* Check if the chip did wake up */
1272 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1273 AR5K_PCICFG_SPWR_DN) == 0)
1274 break;
1275
1276 /* Wait a bit and retry */
1277 udelay(200);
1278 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1279 AR5K_SLEEP_CTL);
1280 }
1281
1282 /* Fail if the chip didn't wake up */
1283 if (i <= 0)
1284 return -EIO;
1285
1286 staid &= ~AR5K_STA_ID1_PWR_SV;
1287 break;
1288
1289 default:
1290 return -EINVAL;
1291 }
1292
1293commit:
1294 ah->ah_power_mode = mode;
1295 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1296
1297 return 0;
1298}
1299
1300/***********************\
1301 DMA Related Functions
1302\***********************/
1303
1304/*
1305 * Receive functions
1306 */
1307
1308/*
1309 * Start DMA receive
1310 */
1311void ath5k_hw_start_rx(struct ath5k_hw *ah)
1312{
1313 ATH5K_TRACE(ah->ah_sc);
1314 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1315}
1316
1317/*
1318 * Stop DMA receive
1319 */
1320int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1321{
1322 unsigned int i;
1323
1324 ATH5K_TRACE(ah->ah_sc);
1325 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1326
1327 /*
1328 * It may take some time to disable the DMA receive unit
1329 */
1330 for (i = 2000; i > 0 &&
1331 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1332 i--)
1333 udelay(10);
1334
1335 return i ? 0 : -EBUSY;
1336}
1337
1338/*
1339 * Get the address of the RX Descriptor
1340 */
1341u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1342{
1343 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1344}
1345
1346/*
1347 * Set the address of the RX Descriptor
1348 */
1349void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1350{
1351 ATH5K_TRACE(ah->ah_sc);
1352
1353 /*TODO:Shouldn't we check if RX is enabled first ?*/
1354 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1355}
1356
1357/*
1358 * Transmit functions
1359 */
1360
1361/*
1362 * Start DMA transmit for a specific queue
1363 * (see also QCU/DCU functions)
1364 */
1365int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1366{
1367 u32 tx_queue;
1368
1369 ATH5K_TRACE(ah->ah_sc);
1370 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1371
1372 /* Return if queue is declared inactive */
1373 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1374 return -EIO;
1375
1376 if (ah->ah_version == AR5K_AR5210) {
1377 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1378
1379 /*
1380 * Set the queue by type on 5210
1381 */
1382 switch (ah->ah_txq[queue].tqi_type) {
1383 case AR5K_TX_QUEUE_DATA:
1384 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1385 break;
1386 case AR5K_TX_QUEUE_BEACON:
1387 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1388 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1389 AR5K_BSR);
1390 break;
1391 case AR5K_TX_QUEUE_CAB:
1392 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1393 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1394 AR5K_BCR_BDMAE, AR5K_BSR);
1395 break;
1396 default:
1397 return -EINVAL;
1398 }
1399 /* Start queue */
1400 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1401 } else {
1402 /* Return if queue is disabled */
1403 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1404 return -EIO;
1405
1406 /* Start queue */
1407 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1408 }
1409
1410 return 0;
1411}
1412
1413/*
1414 * Stop DMA transmit for a specific queue
1415 * (see also QCU/DCU functions)
1416 */
1417int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1418{
1419 unsigned int i = 100;
1420 u32 tx_queue, pending;
1421
1422 ATH5K_TRACE(ah->ah_sc);
1423 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1424
1425 /* Return if queue is declared inactive */
1426 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1427 return -EIO;
1428
1429 if (ah->ah_version == AR5K_AR5210) {
1430 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1431
1432 /*
1433 * Set by queue type
1434 */
1435 switch (ah->ah_txq[queue].tqi_type) {
1436 case AR5K_TX_QUEUE_DATA:
1437 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1438 break;
1439 case AR5K_TX_QUEUE_BEACON:
1440 case AR5K_TX_QUEUE_CAB:
1441 /* XXX Fix me... */
1442 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1443 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1444 break;
1445 default:
1446 return -EINVAL;
1447 }
1448
1449 /* Stop queue */
1450 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
Jiri Slaby274c7c32008-07-15 17:44:20 +02001451 ath5k_hw_reg_read(ah, AR5K_CR);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001452 } else {
1453 /*
1454 * Schedule TX disable and wait until queue is empty
1455 */
1456 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1457
1458 /*Check for pending frames*/
1459 do {
1460 pending = ath5k_hw_reg_read(ah,
1461 AR5K_QUEUE_STATUS(queue)) &
1462 AR5K_QCU_STS_FRMPENDCNT;
1463 udelay(100);
1464 } while (--i && pending);
1465
1466 /* Clear register */
1467 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
Jiri Slaby274c7c32008-07-15 17:44:20 +02001468 if (pending)
1469 return -EBUSY;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001470 }
1471
1472 /* TODO: Check for success else return error */
1473 return 0;
1474}
1475
1476/*
1477 * Get the address of the TX Descriptor for a specific queue
1478 * (see also QCU/DCU functions)
1479 */
1480u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1481{
1482 u16 tx_reg;
1483
1484 ATH5K_TRACE(ah->ah_sc);
1485 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1486
1487 /*
1488 * Get the transmit queue descriptor pointer from the selected queue
1489 */
1490 /*5210 doesn't have QCU*/
1491 if (ah->ah_version == AR5K_AR5210) {
1492 switch (ah->ah_txq[queue].tqi_type) {
1493 case AR5K_TX_QUEUE_DATA:
1494 tx_reg = AR5K_NOQCU_TXDP0;
1495 break;
1496 case AR5K_TX_QUEUE_BEACON:
1497 case AR5K_TX_QUEUE_CAB:
1498 tx_reg = AR5K_NOQCU_TXDP1;
1499 break;
1500 default:
1501 return 0xffffffff;
1502 }
1503 } else {
1504 tx_reg = AR5K_QUEUE_TXDP(queue);
1505 }
1506
1507 return ath5k_hw_reg_read(ah, tx_reg);
1508}
1509
1510/*
1511 * Set the address of the TX Descriptor for a specific queue
1512 * (see also QCU/DCU functions)
1513 */
1514int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1515{
1516 u16 tx_reg;
1517
1518 ATH5K_TRACE(ah->ah_sc);
1519 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1520
1521 /*
1522 * Set the transmit queue descriptor pointer register by type
1523 * on 5210
1524 */
1525 if (ah->ah_version == AR5K_AR5210) {
1526 switch (ah->ah_txq[queue].tqi_type) {
1527 case AR5K_TX_QUEUE_DATA:
1528 tx_reg = AR5K_NOQCU_TXDP0;
1529 break;
1530 case AR5K_TX_QUEUE_BEACON:
1531 case AR5K_TX_QUEUE_CAB:
1532 tx_reg = AR5K_NOQCU_TXDP1;
1533 break;
1534 default:
1535 return -EINVAL;
1536 }
1537 } else {
1538 /*
1539 * Set the transmit queue descriptor pointer for
1540 * the selected queue on QCU for 5211+
1541 * (this won't work if the queue is still active)
1542 */
1543 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1544 return -EIO;
1545
1546 tx_reg = AR5K_QUEUE_TXDP(queue);
1547 }
1548
1549 /* Set descriptor pointer */
1550 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1551
1552 return 0;
1553}
1554
1555/*
1556 * Update tx trigger level
1557 */
1558int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1559{
1560 u32 trigger_level, imr;
1561 int ret = -EIO;
1562
1563 ATH5K_TRACE(ah->ah_sc);
1564
1565 /*
1566 * Disable interrupts by setting the mask
1567 */
1568 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1569
1570 /*TODO: Boundary check on trigger_level*/
1571 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1572 AR5K_TXCFG_TXFULL);
1573
Joe Perchese9010e22008-03-07 14:21:16 -08001574 if (!increase) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001575 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1576 goto done;
1577 } else
1578 trigger_level +=
1579 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1580
1581 /*
1582 * Update trigger level on success
1583 */
1584 if (ah->ah_version == AR5K_AR5210)
1585 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1586 else
1587 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1588 AR5K_TXCFG_TXFULL, trigger_level);
1589
1590 ret = 0;
1591
1592done:
1593 /*
1594 * Restore interrupt mask
1595 */
1596 ath5k_hw_set_intr(ah, imr);
1597
1598 return ret;
1599}
1600
1601/*
1602 * Interrupt handling
1603 */
1604
1605/*
1606 * Check if we have pending interrupts
1607 */
1608bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1609{
1610 ATH5K_TRACE(ah->ah_sc);
1611 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1612}
1613
1614/*
1615 * Get interrupt mask (ISR)
1616 */
1617int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1618{
1619 u32 data;
1620
1621 ATH5K_TRACE(ah->ah_sc);
1622
1623 /*
1624 * Read interrupt status from the Interrupt Status register
1625 * on 5210
1626 */
1627 if (ah->ah_version == AR5K_AR5210) {
1628 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1629 if (unlikely(data == AR5K_INT_NOCARD)) {
1630 *interrupt_mask = data;
1631 return -ENODEV;
1632 }
1633 } else {
1634 /*
1635 * Read interrupt status from the Read-And-Clear shadow register
1636 * Note: PISR/SISR Not available on 5210
1637 */
1638 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1639 }
1640
1641 /*
1642 * Get abstract interrupt mask (driver-compatible)
1643 */
1644 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1645
1646 if (unlikely(data == AR5K_INT_NOCARD))
1647 return -ENODEV;
1648
1649 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1650 *interrupt_mask |= AR5K_INT_RX;
1651
1652 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1653 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1654 *interrupt_mask |= AR5K_INT_TX;
1655
1656 if (ah->ah_version != AR5K_AR5210) {
1657 /*HIU = Host Interface Unit (PCI etc)*/
1658 if (unlikely(data & (AR5K_ISR_HIUERR)))
1659 *interrupt_mask |= AR5K_INT_FATAL;
1660
1661 /*Beacon Not Ready*/
1662 if (unlikely(data & (AR5K_ISR_BNR)))
1663 *interrupt_mask |= AR5K_INT_BNR;
1664 }
1665
1666 /*
1667 * XXX: BMISS interrupts may occur after association.
1668 * I found this on 5210 code but it needs testing. If this is
1669 * true we should disable them before assoc and re-enable them
1670 * after a successfull assoc + some jiffies.
1671 */
1672#if 0
1673 interrupt_mask &= ~AR5K_INT_BMISS;
1674#endif
1675
1676 /*
1677 * In case we didn't handle anything,
1678 * print the register value.
1679 */
1680 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1681 ATH5K_PRINTF("0x%08x\n", data);
1682
1683 return 0;
1684}
1685
1686/*
1687 * Set interrupt mask
1688 */
1689enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1690{
1691 enum ath5k_int old_mask, int_mask;
1692
1693 /*
1694 * Disable card interrupts to prevent any race conditions
1695 * (they will be re-enabled afterwards).
1696 */
1697 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1698
1699 old_mask = ah->ah_imr;
1700
1701 /*
1702 * Add additional, chipset-dependent interrupt mask flags
1703 * and write them to the IMR (interrupt mask register).
1704 */
1705 int_mask = new_mask & AR5K_INT_COMMON;
1706
1707 if (new_mask & AR5K_INT_RX)
1708 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1709 AR5K_IMR_RXDESC;
1710
1711 if (new_mask & AR5K_INT_TX)
1712 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1713 AR5K_IMR_TXURN;
1714
1715 if (ah->ah_version != AR5K_AR5210) {
1716 if (new_mask & AR5K_INT_FATAL) {
1717 int_mask |= AR5K_IMR_HIUERR;
1718 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1719 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1720 }
1721 }
1722
1723 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1724
1725 /* Store new interrupt mask */
1726 ah->ah_imr = new_mask;
1727
1728 /* ..re-enable interrupts */
1729 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
Jiri Slaby274c7c32008-07-15 17:44:20 +02001730 ath5k_hw_reg_read(ah, AR5K_IER);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001731
1732 return old_mask;
1733}
1734
1735
1736/*************************\
1737 EEPROM access functions
1738\*************************/
1739
1740/*
1741 * Read from eeprom
1742 */
1743static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1744{
1745 u32 status, timeout;
1746
1747 ATH5K_TRACE(ah->ah_sc);
1748 /*
1749 * Initialize EEPROM access
1750 */
1751 if (ah->ah_version == AR5K_AR5210) {
1752 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1753 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1754 } else {
1755 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1756 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1757 AR5K_EEPROM_CMD_READ);
1758 }
1759
1760 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1761 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1762 if (status & AR5K_EEPROM_STAT_RDDONE) {
1763 if (status & AR5K_EEPROM_STAT_RDERR)
1764 return -EIO;
1765 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1766 0xffff);
1767 return 0;
1768 }
1769 udelay(15);
1770 }
1771
1772 return -ETIMEDOUT;
1773}
1774
1775/*
1776 * Write to eeprom - currently disabled, use at your own risk
1777 */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001778#if 0
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001779static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1780{
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001781
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001782 u32 status, timeout;
1783
1784 ATH5K_TRACE(ah->ah_sc);
1785
1786 /*
1787 * Initialize eeprom access
1788 */
1789
1790 if (ah->ah_version == AR5K_AR5210) {
1791 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1792 } else {
1793 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1794 AR5K_EEPROM_CMD_RESET);
1795 }
1796
1797 /*
1798 * Write data to data register
1799 */
1800
1801 if (ah->ah_version == AR5K_AR5210) {
1802 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1803 } else {
1804 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1805 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1806 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1807 AR5K_EEPROM_CMD_WRITE);
1808 }
1809
1810 /*
1811 * Check status
1812 */
1813
1814 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1815 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1816 if (status & AR5K_EEPROM_STAT_WRDONE) {
1817 if (status & AR5K_EEPROM_STAT_WRERR)
1818 return EIO;
1819 return 0;
1820 }
1821 udelay(15);
1822 }
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001823
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001824 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1825 return -EIO;
1826}
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001827#endif
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001828
1829/*
1830 * Translate binary channel representation in EEPROM to frequency
1831 */
1832static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1833{
1834 u16 val;
1835
1836 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1837 return bin;
1838
1839 if (mode == AR5K_EEPROM_MODE_11A) {
1840 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1841 val = (5 * bin) + 4800;
1842 else
1843 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1844 (bin * 10) + 5100;
1845 } else {
1846 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1847 val = bin + 2300;
1848 else
1849 val = bin + 2400;
1850 }
1851
1852 return val;
1853}
1854
1855/*
1856 * Read antenna infos from eeprom
1857 */
1858static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1859 unsigned int mode)
1860{
1861 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1862 u32 o = *offset;
1863 u16 val;
1864 int ret, i = 0;
1865
1866 AR5K_EEPROM_READ(o++, val);
1867 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1868 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1869 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1870
1871 AR5K_EEPROM_READ(o++, val);
1872 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1873 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1874 ee->ee_ant_control[mode][i++] = val & 0x3f;
1875
1876 AR5K_EEPROM_READ(o++, val);
1877 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1878 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1879 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1880
1881 AR5K_EEPROM_READ(o++, val);
1882 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1883 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1884 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1885 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1886
1887 AR5K_EEPROM_READ(o++, val);
1888 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1889 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1890 ee->ee_ant_control[mode][i++] = val & 0x3f;
1891
1892 /* Get antenna modes */
1893 ah->ah_antenna[mode][0] =
1894 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1895 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1896 ee->ee_ant_control[mode][1] |
1897 (ee->ee_ant_control[mode][2] << 6) |
1898 (ee->ee_ant_control[mode][3] << 12) |
1899 (ee->ee_ant_control[mode][4] << 18) |
1900 (ee->ee_ant_control[mode][5] << 24);
1901 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1902 ee->ee_ant_control[mode][6] |
1903 (ee->ee_ant_control[mode][7] << 6) |
1904 (ee->ee_ant_control[mode][8] << 12) |
1905 (ee->ee_ant_control[mode][9] << 18) |
1906 (ee->ee_ant_control[mode][10] << 24);
1907
1908 /* return new offset */
1909 *offset = o;
1910
1911 return 0;
1912}
1913
1914/*
1915 * Read supported modes from eeprom
1916 */
1917static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1918 unsigned int mode)
1919{
1920 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1921 u32 o = *offset;
1922 u16 val;
1923 int ret;
1924
1925 AR5K_EEPROM_READ(o++, val);
1926 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1927 ee->ee_thr_62[mode] = val & 0xff;
1928
1929 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1930 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1931
1932 AR5K_EEPROM_READ(o++, val);
1933 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1934 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1935
1936 AR5K_EEPROM_READ(o++, val);
1937 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1938
1939 if ((val & 0xff) & 0x80)
1940 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1941 else
1942 ee->ee_noise_floor_thr[mode] = val & 0xff;
1943
1944 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1945 ee->ee_noise_floor_thr[mode] =
1946 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1947
1948 AR5K_EEPROM_READ(o++, val);
1949 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1950 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1951 ee->ee_xpd[mode] = val & 0x1;
1952
1953 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1954 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1955
1956 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1957 AR5K_EEPROM_READ(o++, val);
1958 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1959
1960 if (mode == AR5K_EEPROM_MODE_11A)
1961 ee->ee_xr_power[mode] = val & 0x3f;
1962 else {
1963 ee->ee_ob[mode][0] = val & 0x7;
1964 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1965 }
1966 }
1967
1968 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1969 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1970 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1971 } else {
1972 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1973
1974 AR5K_EEPROM_READ(o++, val);
1975 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1976
1977 if (mode == AR5K_EEPROM_MODE_11G)
1978 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1979 }
1980
1981 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1982 mode == AR5K_EEPROM_MODE_11A) {
1983 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1984 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1985 }
1986
1987 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1988 mode == AR5K_EEPROM_MODE_11G)
1989 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1990
1991 /* return new offset */
1992 *offset = o;
1993
1994 return 0;
1995}
1996
1997/*
1998 * Initialize eeprom & capabilities structs
1999 */
2000static int ath5k_eeprom_init(struct ath5k_hw *ah)
2001{
2002 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
2003 unsigned int mode, i;
2004 int ret;
2005 u32 offset;
2006 u16 val;
2007
2008 /* Initial TX thermal adjustment values */
2009 ee->ee_tx_clip = 4;
2010 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
2011 ee->ee_gain_select = 1;
2012
2013 /*
2014 * Read values from EEPROM and store them in the capability structure
2015 */
2016 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
2017 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
2018 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
2019 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
2020 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
2021
2022 /* Return if we have an old EEPROM */
2023 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
2024 return 0;
2025
2026#ifdef notyet
2027 /*
2028 * Validate the checksum of the EEPROM date. There are some
2029 * devices with invalid EEPROMs.
2030 */
2031 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
2032 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
2033 cksum ^= val;
2034 }
2035 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
2036 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
2037 return -EIO;
2038 }
2039#endif
2040
2041 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
2042 ee_ant_gain);
2043
2044 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2045 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
2046 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
2047 }
2048
2049 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
2050 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
2051 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
2052 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
2053
2054 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
2055 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
2056 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
2057 }
2058
2059 /*
2060 * Get conformance test limit values
2061 */
2062 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
2063 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
2064
2065 for (i = 0; i < ee->ee_ctls; i++) {
2066 AR5K_EEPROM_READ(offset++, val);
2067 ee->ee_ctl[i] = (val >> 8) & 0xff;
2068 ee->ee_ctl[i + 1] = val & 0xff;
2069 }
2070
2071 /*
2072 * Get values for 802.11a (5GHz)
2073 */
2074 mode = AR5K_EEPROM_MODE_11A;
2075
2076 ee->ee_turbo_max_power[mode] =
2077 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
2078
2079 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
2080
2081 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2082 if (ret)
2083 return ret;
2084
2085 AR5K_EEPROM_READ(offset++, val);
2086 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2087 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
2088 ee->ee_db[mode][3] = (val >> 2) & 0x7;
2089 ee->ee_ob[mode][2] = (val << 1) & 0x7;
2090
2091 AR5K_EEPROM_READ(offset++, val);
2092 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
2093 ee->ee_db[mode][2] = (val >> 12) & 0x7;
2094 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
2095 ee->ee_db[mode][1] = (val >> 6) & 0x7;
2096 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
2097 ee->ee_db[mode][0] = val & 0x7;
2098
2099 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2100 if (ret)
2101 return ret;
2102
2103 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
2104 AR5K_EEPROM_READ(offset++, val);
2105 ee->ee_margin_tx_rx[mode] = val & 0x3f;
2106 }
2107
2108 /*
2109 * Get values for 802.11b (2.4GHz)
2110 */
2111 mode = AR5K_EEPROM_MODE_11B;
2112 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
2113
2114 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2115 if (ret)
2116 return ret;
2117
2118 AR5K_EEPROM_READ(offset++, val);
2119 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2120 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2121 ee->ee_db[mode][1] = val & 0x7;
2122
2123 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2124 if (ret)
2125 return ret;
2126
2127 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2128 AR5K_EEPROM_READ(offset++, val);
2129 ee->ee_cal_pier[mode][0] =
2130 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2131 ee->ee_cal_pier[mode][1] =
2132 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2133
2134 AR5K_EEPROM_READ(offset++, val);
2135 ee->ee_cal_pier[mode][2] =
2136 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2137 }
2138
2139 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2140 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2141
2142 /*
2143 * Get values for 802.11g (2.4GHz)
2144 */
2145 mode = AR5K_EEPROM_MODE_11G;
2146 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
2147
2148 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2149 if (ret)
2150 return ret;
2151
2152 AR5K_EEPROM_READ(offset++, val);
2153 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2154 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2155 ee->ee_db[mode][1] = val & 0x7;
2156
2157 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2158 if (ret)
2159 return ret;
2160
2161 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2162 AR5K_EEPROM_READ(offset++, val);
2163 ee->ee_cal_pier[mode][0] =
2164 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2165 ee->ee_cal_pier[mode][1] =
2166 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2167
2168 AR5K_EEPROM_READ(offset++, val);
2169 ee->ee_turbo_max_power[mode] = val & 0x7f;
2170 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2171
2172 AR5K_EEPROM_READ(offset++, val);
2173 ee->ee_cal_pier[mode][2] =
2174 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2175
2176 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2177 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2178
2179 AR5K_EEPROM_READ(offset++, val);
2180 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2181 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2182
2183 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2184 AR5K_EEPROM_READ(offset++, val);
2185 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2186 }
2187 }
2188
2189 /*
2190 * Read 5GHz EEPROM channels
2191 */
2192
2193 return 0;
2194}
2195
2196/*
2197 * Read the MAC address from eeprom
2198 */
2199static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2200{
2201 u8 mac_d[ETH_ALEN];
2202 u32 total, offset;
2203 u16 data;
2204 int octet, ret;
2205
2206 memset(mac, 0, ETH_ALEN);
2207 memset(mac_d, 0, ETH_ALEN);
2208
2209 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2210 if (ret)
2211 return ret;
2212
2213 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2214 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2215 if (ret)
2216 return ret;
2217
2218 total += data;
2219 mac_d[octet + 1] = data & 0xff;
2220 mac_d[octet] = data >> 8;
2221 octet += 2;
2222 }
2223
2224 memcpy(mac, mac_d, ETH_ALEN);
2225
2226 if (!total || total == 3 * 0xffff)
2227 return -EINVAL;
2228
2229 return 0;
2230}
2231
2232/*
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002233 * Fill the capabilities struct
2234 */
2235static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2236{
2237 u16 ee_header;
2238
2239 ATH5K_TRACE(ah->ah_sc);
2240 /* Capabilities stored in the EEPROM */
2241 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2242
2243 if (ah->ah_version == AR5K_AR5210) {
2244 /*
2245 * Set radio capabilities
2246 * (The AR5110 only supports the middle 5GHz band)
2247 */
2248 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2249 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2250 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2251 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2252
2253 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002254 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2255 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002256 } else {
2257 /*
2258 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2259 * XXX and from 2312 to 2732GHz. There are problems with the
2260 * XXX current ieee80211 implementation because the IEEE
2261 * XXX channel mapping does not support negative channel
2262 * XXX numbers (2312MHz is channel -19). Of course, this
2263 * XXX doesn't matter because these channels are out of range
2264 * XXX but some regulation domains like MKK (Japan) will
2265 * XXX support frequencies somewhere around 4.8GHz.
2266 */
2267
2268 /*
2269 * Set radio capabilities
2270 */
2271
2272 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2273 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2274 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2275
2276 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002277 __set_bit(AR5K_MODE_11A,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002278 ah->ah_capabilities.cap_mode);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002279 __set_bit(AR5K_MODE_11A_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002280 ah->ah_capabilities.cap_mode);
2281 if (ah->ah_version == AR5K_AR5212)
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002282 __set_bit(AR5K_MODE_11G_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002283 ah->ah_capabilities.cap_mode);
2284 }
2285
2286 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2287 * connected */
2288 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2289 AR5K_EEPROM_HDR_11G(ee_header)) {
2290 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2291 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2292
2293 if (AR5K_EEPROM_HDR_11B(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002294 __set_bit(AR5K_MODE_11B,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002295 ah->ah_capabilities.cap_mode);
2296
2297 if (AR5K_EEPROM_HDR_11G(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002298 __set_bit(AR5K_MODE_11G,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002299 ah->ah_capabilities.cap_mode);
2300 }
2301 }
2302
2303 /* GPIO */
2304 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2305
2306 /* Set number of supported TX queues */
2307 if (ah->ah_version == AR5K_AR5210)
2308 ah->ah_capabilities.cap_queues.q_tx_num =
2309 AR5K_NUM_TX_QUEUES_NOQCU;
2310 else
2311 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2312
2313 return 0;
2314}
2315
2316/*********************************\
2317 Protocol Control Unit Functions
2318\*********************************/
2319
2320/*
2321 * Set Operation mode
2322 */
2323int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2324{
2325 u32 pcu_reg, beacon_reg, low_id, high_id;
2326
2327 pcu_reg = 0;
2328 beacon_reg = 0;
2329
2330 ATH5K_TRACE(ah->ah_sc);
2331
2332 switch (ah->ah_op_mode) {
2333 case IEEE80211_IF_TYPE_IBSS:
2334 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2335 (ah->ah_version == AR5K_AR5210 ?
2336 AR5K_STA_ID1_NO_PSPOLL : 0);
2337 beacon_reg |= AR5K_BCR_ADHOC;
2338 break;
2339
2340 case IEEE80211_IF_TYPE_AP:
2341 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2342 (ah->ah_version == AR5K_AR5210 ?
2343 AR5K_STA_ID1_NO_PSPOLL : 0);
2344 beacon_reg |= AR5K_BCR_AP;
2345 break;
2346
2347 case IEEE80211_IF_TYPE_STA:
2348 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2349 (ah->ah_version == AR5K_AR5210 ?
2350 AR5K_STA_ID1_PWR_SV : 0);
2351 case IEEE80211_IF_TYPE_MNTR:
2352 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2353 (ah->ah_version == AR5K_AR5210 ?
2354 AR5K_STA_ID1_NO_PSPOLL : 0);
2355 break;
2356
2357 default:
2358 return -EINVAL;
2359 }
2360
2361 /*
2362 * Set PCU registers
2363 */
2364 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2365 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2366 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2367 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2368
2369 /*
2370 * Set Beacon Control Register on 5210
2371 */
2372 if (ah->ah_version == AR5K_AR5210)
2373 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2374
2375 return 0;
2376}
2377
2378/*
2379 * BSSID Functions
2380 */
2381
2382/*
2383 * Get station id
2384 */
2385void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2386{
2387 ATH5K_TRACE(ah->ah_sc);
2388 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2389}
2390
2391/*
2392 * Set station id
2393 */
2394int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2395{
2396 u32 low_id, high_id;
2397
2398 ATH5K_TRACE(ah->ah_sc);
2399 /* Set new station ID */
2400 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2401
2402 low_id = AR5K_LOW_ID(mac);
2403 high_id = AR5K_HIGH_ID(mac);
2404
2405 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2406 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2407
2408 return 0;
2409}
2410
2411/*
2412 * Set BSSID
2413 */
2414void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2415{
2416 u32 low_id, high_id;
2417 u16 tim_offset = 0;
2418
2419 /*
2420 * Set simple BSSID mask on 5212
2421 */
2422 if (ah->ah_version == AR5K_AR5212) {
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05002423 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
2424 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002425 }
2426
2427 /*
2428 * Set BSSID which triggers the "SME Join" operation
2429 */
2430 low_id = AR5K_LOW_ID(bssid);
2431 high_id = AR5K_HIGH_ID(bssid);
2432 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2433 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2434 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2435
2436 if (assoc_id == 0) {
2437 ath5k_hw_disable_pspoll(ah);
2438 return;
2439 }
2440
2441 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2442 tim_offset ? tim_offset + 4 : 0);
2443
2444 ath5k_hw_enable_pspoll(ah, NULL, 0);
2445}
2446/**
2447 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2448 *
2449 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2450 * which bits of the interface's MAC address should be looked at when trying
2451 * to decide which packets to ACK. In station mode every bit matters. In AP
2452 * mode with a single BSS every bit matters as well. In AP mode with
2453 * multiple BSSes not every bit matters.
2454 *
2455 * @ah: the &struct ath5k_hw
2456 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2457 *
2458 * Note that this is a simple filter and *does* not filter out all
2459 * relevant frames. Some non-relevant frames will get through, probability
2460 * jocks are welcomed to compute.
2461 *
2462 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2463 * computing the set of:
2464 *
2465 * ~ ( MAC XOR BSSID )
2466 *
2467 * When you do this you are essentially computing the common bits. Later it
2468 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2469 * to obtain the relevant bits which should match on the destination frame.
2470 *
2471 * Simple example: on your card you have have two BSSes you have created with
2472 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2473 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2474 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2475 *
2476 * \
2477 * MAC: 0001 |
2478 * BSSID-01: 0100 | --> Belongs to us
2479 * BSSID-02: 1001 |
2480 * /
2481 * -------------------
2482 * BSSID-03: 0110 | --> External
2483 * -------------------
2484 *
2485 * Our bssid_mask would then be:
2486 *
2487 * On loop iteration for BSSID-01:
2488 * ~(0001 ^ 0100) -> ~(0101)
2489 * -> 1010
2490 * bssid_mask = 1010
2491 *
2492 * On loop iteration for BSSID-02:
2493 * bssid_mask &= ~(0001 ^ 1001)
2494 * bssid_mask = (1010) & ~(0001 ^ 1001)
2495 * bssid_mask = (1010) & ~(1001)
2496 * bssid_mask = (1010) & (0110)
2497 * bssid_mask = 0010
2498 *
2499 * A bssid_mask of 0010 means "only pay attention to the second least
2500 * significant bit". This is because its the only bit common
2501 * amongst the MAC and all BSSIDs we support. To findout what the real
2502 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2503 * or our MAC address (we assume the hardware uses the MAC address).
2504 *
2505 * Now, suppose there's an incoming frame for BSSID-03:
2506 *
2507 * IFRAME-01: 0110
2508 *
2509 * An easy eye-inspeciton of this already should tell you that this frame
2510 * will not pass our check. This is beacuse the bssid_mask tells the
2511 * hardware to only look at the second least significant bit and the
2512 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2513 * as 1, which does not match 0.
2514 *
2515 * So with IFRAME-01 we *assume* the hardware will do:
2516 *
2517 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2518 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2519 * --> allow = (0010) == 0000 ? 1 : 0;
2520 * --> allow = 0
2521 *
2522 * Lets now test a frame that should work:
2523 *
2524 * IFRAME-02: 0001 (we should allow)
2525 *
2526 * allow = (0001 & 1010) == 1010
2527 *
2528 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2529 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2530 * --> allow = (0010) == (0010)
2531 * --> allow = 1
2532 *
2533 * Other examples:
2534 *
2535 * IFRAME-03: 0100 --> allowed
2536 * IFRAME-04: 1001 --> allowed
2537 * IFRAME-05: 1101 --> allowed but its not for us!!!
2538 *
2539 */
2540int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2541{
2542 u32 low_id, high_id;
2543 ATH5K_TRACE(ah->ah_sc);
2544
2545 if (ah->ah_version == AR5K_AR5212) {
2546 low_id = AR5K_LOW_ID(mask);
2547 high_id = AR5K_HIGH_ID(mask);
2548
2549 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2550 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2551
2552 return 0;
2553 }
2554
2555 return -EIO;
2556}
2557
2558/*
2559 * Receive start/stop functions
2560 */
2561
2562/*
2563 * Start receive on PCU
2564 */
2565void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2566{
2567 ATH5K_TRACE(ah->ah_sc);
2568 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05002569
2570 /* TODO: ANI Support */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002571}
2572
2573/*
2574 * Stop receive on PCU
2575 */
2576void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2577{
2578 ATH5K_TRACE(ah->ah_sc);
2579 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
Nick Kossifidisc87cdfd2008-03-07 11:48:21 -05002580
2581 /* TODO: ANI Support */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002582}
2583
2584/*
2585 * RX Filter functions
2586 */
2587
2588/*
2589 * Set multicast filter
2590 */
2591void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2592{
2593 ATH5K_TRACE(ah->ah_sc);
2594 /* Set the multicat filter */
2595 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2596 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2597}
2598
2599/*
2600 * Set multicast filter by index
2601 */
2602int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2603{
2604
2605 ATH5K_TRACE(ah->ah_sc);
2606 if (index >= 64)
2607 return -EINVAL;
2608 else if (index >= 32)
2609 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2610 (1 << (index - 32)));
2611 else
2612 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2613
2614 return 0;
2615}
2616
2617/*
2618 * Clear Multicast filter by index
2619 */
2620int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2621{
2622
2623 ATH5K_TRACE(ah->ah_sc);
2624 if (index >= 64)
2625 return -EINVAL;
2626 else if (index >= 32)
2627 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2628 (1 << (index - 32)));
2629 else
2630 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2631
2632 return 0;
2633}
2634
2635/*
2636 * Get current rx filter
2637 */
2638u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2639{
2640 u32 data, filter = 0;
2641
2642 ATH5K_TRACE(ah->ah_sc);
2643 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2644
2645 /*Radar detection for 5212*/
2646 if (ah->ah_version == AR5K_AR5212) {
2647 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2648
2649 if (data & AR5K_PHY_ERR_FIL_RADAR)
2650 filter |= AR5K_RX_FILTER_RADARERR;
2651 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2652 filter |= AR5K_RX_FILTER_PHYERR;
2653 }
2654
2655 return filter;
2656}
2657
2658/*
2659 * Set rx filter
2660 */
2661void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2662{
2663 u32 data = 0;
2664
2665 ATH5K_TRACE(ah->ah_sc);
2666
2667 /* Set PHY error filter register on 5212*/
2668 if (ah->ah_version == AR5K_AR5212) {
2669 if (filter & AR5K_RX_FILTER_RADARERR)
2670 data |= AR5K_PHY_ERR_FIL_RADAR;
2671 if (filter & AR5K_RX_FILTER_PHYERR)
2672 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2673 }
2674
2675 /*
2676 * The AR5210 uses promiscous mode to detect radar activity
2677 */
2678 if (ah->ah_version == AR5K_AR5210 &&
2679 (filter & AR5K_RX_FILTER_RADARERR)) {
2680 filter &= ~AR5K_RX_FILTER_RADARERR;
2681 filter |= AR5K_RX_FILTER_PROM;
2682 }
2683
2684 /*Zero length DMA*/
2685 if (data)
2686 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2687 else
2688 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2689
2690 /*Write RX Filter register*/
2691 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2692
2693 /*Write PHY error filter register on 5212*/
2694 if (ah->ah_version == AR5K_AR5212)
2695 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2696
2697}
2698
2699/*
2700 * Beacon related functions
2701 */
2702
2703/*
2704 * Get a 32bit TSF
2705 */
2706u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2707{
2708 ATH5K_TRACE(ah->ah_sc);
2709 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2710}
2711
2712/*
2713 * Get the full 64bit TSF
2714 */
2715u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2716{
2717 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2718 ATH5K_TRACE(ah->ah_sc);
2719
2720 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2721}
2722
2723/*
2724 * Force a TSF reset
2725 */
2726void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2727{
2728 ATH5K_TRACE(ah->ah_sc);
2729 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2730}
2731
2732/*
2733 * Initialize beacon timers
2734 */
2735void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2736{
2737 u32 timer1, timer2, timer3;
2738
2739 ATH5K_TRACE(ah->ah_sc);
2740 /*
2741 * Set the additional timers by mode
2742 */
2743 switch (ah->ah_op_mode) {
2744 case IEEE80211_IF_TYPE_STA:
2745 if (ah->ah_version == AR5K_AR5210) {
2746 timer1 = 0xffffffff;
2747 timer2 = 0xffffffff;
2748 } else {
2749 timer1 = 0x0000ffff;
2750 timer2 = 0x0007ffff;
2751 }
2752 break;
2753
2754 default:
Bruno Randolf1008e0f2008-01-18 21:51:19 +09002755 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2756 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002757 }
2758
2759 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2760
2761 /*
2762 * Set the beacon register and enable all timers.
2763 * (next beacon, DMA beacon, software beacon, ATIM window time)
2764 */
2765 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2766 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2767 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2768 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2769
2770 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2771 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2772 AR5K_BEACON);
2773}
2774
2775#if 0
2776/*
2777 * Set beacon timers
2778 */
2779int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2780 const struct ath5k_beacon_state *state)
2781{
2782 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2783
2784 /*
2785 * TODO: should be changed through *state
2786 * review struct ath5k_beacon_state struct
2787 *
2788 * XXX: These are used for cfp period bellow, are they
2789 * ok ? Is it O.K. for tsf here to be 0 or should we use
2790 * get_tsf ?
2791 */
2792 u32 dtim_count = 0; /* XXX */
2793 u32 cfp_count = 0; /* XXX */
2794 u32 tsf = 0; /* XXX */
2795
2796 ATH5K_TRACE(ah->ah_sc);
2797 /* Return on an invalid beacon state */
2798 if (state->bs_interval < 1)
2799 return -EINVAL;
2800
2801 interval = state->bs_interval;
2802 dtim = state->bs_dtim_period;
2803
2804 /*
2805 * PCF support?
2806 */
2807 if (state->bs_cfp_period > 0) {
2808 /*
2809 * Enable PCF mode and set the CFP
2810 * (Contention Free Period) and timer registers
2811 */
2812 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2813 state->bs_interval;
2814 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2815 state->bs_interval;
2816
2817 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2818 AR5K_STA_ID1_DEFAULT_ANTENNA |
2819 AR5K_STA_ID1_PCF);
2820 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2821 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2822 AR5K_CFP_DUR);
2823 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2824 next_cfp)) << 3, AR5K_TIMER2);
2825 } else {
2826 /* Disable PCF mode */
2827 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2828 AR5K_STA_ID1_DEFAULT_ANTENNA |
2829 AR5K_STA_ID1_PCF);
2830 }
2831
2832 /*
2833 * Enable the beacon timer register
2834 */
2835 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2836
2837 /*
2838 * Start the beacon timers
2839 */
2840 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2841 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2842 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2843 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2844 AR5K_BEACON_PERIOD), AR5K_BEACON);
2845
2846 /*
2847 * Write new beacon miss threshold, if it appears to be valid
2848 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2849 * and return if its not in range. We can test this by reading value and
2850 * setting value to a largest value and seeing which values register.
2851 */
2852
2853 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2854 state->bs_bmiss_threshold);
2855
2856 /*
2857 * Set sleep control register
2858 * XXX: Didn't find this in 5210 code but since this register
2859 * exists also in ar5k's 5210 headers i leave it as common code.
2860 */
2861 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2862 (state->bs_sleep_duration - 3) << 3);
2863
2864 /*
2865 * Set enhanced sleep registers on 5212
2866 */
2867 if (ah->ah_version == AR5K_AR5212) {
2868 if (state->bs_sleep_duration > state->bs_interval &&
2869 roundup(state->bs_sleep_duration, interval) ==
2870 state->bs_sleep_duration)
2871 interval = state->bs_sleep_duration;
2872
2873 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2874 roundup(state->bs_sleep_duration, dtim) ==
2875 state->bs_sleep_duration))
2876 dtim = state->bs_sleep_duration;
2877
2878 if (interval > dtim)
2879 return -EINVAL;
2880
2881 next_beacon = interval == dtim ? state->bs_next_dtim :
2882 state->bs_next_beacon;
2883
2884 ath5k_hw_reg_write(ah,
2885 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2886 AR5K_SLEEP0_NEXT_DTIM) |
2887 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2888 AR5K_SLEEP0_ENH_SLEEP_EN |
2889 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2890
2891 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2892 AR5K_SLEEP1_NEXT_TIM) |
2893 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2894
2895 ath5k_hw_reg_write(ah,
2896 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2897 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2898 }
2899
2900 return 0;
2901}
2902
2903/*
2904 * Reset beacon timers
2905 */
2906void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2907{
2908 ATH5K_TRACE(ah->ah_sc);
2909 /*
2910 * Disable beacon timer
2911 */
2912 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2913
2914 /*
2915 * Disable some beacon register values
2916 */
2917 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2918 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2919 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2920}
2921
2922/*
2923 * Wait for beacon queue to finish
2924 */
2925int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2926{
2927 unsigned int i;
2928 int ret;
2929
2930 ATH5K_TRACE(ah->ah_sc);
2931
2932 /* 5210 doesn't have QCU*/
2933 if (ah->ah_version == AR5K_AR5210) {
2934 /*
2935 * Wait for beaconn queue to finish by checking
2936 * Control Register and Beacon Status Register.
2937 */
2938 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2939 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2940 ||
2941 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2942 break;
2943 udelay(10);
2944 }
2945
2946 /* Timeout... */
2947 if (i <= 0) {
2948 /*
2949 * Re-schedule the beacon queue
2950 */
2951 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2952 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2953 AR5K_BCR);
2954
2955 return -EIO;
2956 }
2957 ret = 0;
2958 } else {
2959 /*5211/5212*/
2960 ret = ath5k_hw_register_timeout(ah,
2961 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2962 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2963
2964 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2965 return -EIO;
2966 }
2967
2968 return ret;
2969}
2970#endif
2971
2972/*
2973 * Update mib counters (statistics)
2974 */
2975void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
Nick Kossifidis194828a2008-04-16 18:49:02 +03002976 struct ieee80211_low_level_stats *stats)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002977{
2978 ATH5K_TRACE(ah->ah_sc);
Nick Kossifidis194828a2008-04-16 18:49:02 +03002979
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002980 /* Read-And-Clear */
Nick Kossifidis194828a2008-04-16 18:49:02 +03002981 stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2982 stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2983 stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2984 stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2985
2986 /* XXX: Should we use this to track beacon count ?
2987 * -we read it anyway to clear the register */
2988 ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002989
2990 /* Reset profile count registers on 5212*/
2991 if (ah->ah_version == AR5K_AR5212) {
2992 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2993 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2994 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2995 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2996 }
2997}
2998
2999/** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
3000 *
3001 * @ah: the &struct ath5k_hw
3002 * @high: determines if to use low bit rate or now
3003 */
3004void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
3005{
3006 if (ah->ah_version != AR5K_AR5212)
3007 return;
3008 else {
3009 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
3010 if (high)
3011 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
3012 else
3013 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
3014 }
3015}
3016
3017
3018/*
3019 * ACK/CTS Timeouts
3020 */
3021
3022/*
3023 * Set ACK timeout on PCU
3024 */
3025int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
3026{
3027 ATH5K_TRACE(ah->ah_sc);
3028 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
3029 ah->ah_turbo) <= timeout)
3030 return -EINVAL;
3031
3032 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
3033 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3034
3035 return 0;
3036}
3037
3038/*
3039 * Read the ACK timeout from PCU
3040 */
3041unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
3042{
3043 ATH5K_TRACE(ah->ah_sc);
3044
3045 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3046 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
3047}
3048
3049/*
3050 * Set CTS timeout on PCU
3051 */
3052int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
3053{
3054 ATH5K_TRACE(ah->ah_sc);
3055 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
3056 ah->ah_turbo) <= timeout)
3057 return -EINVAL;
3058
3059 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
3060 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3061
3062 return 0;
3063}
3064
3065/*
3066 * Read CTS timeout from PCU
3067 */
3068unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
3069{
3070 ATH5K_TRACE(ah->ah_sc);
3071 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3072 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
3073}
3074
3075/*
3076 * Key table (WEP) functions
3077 */
3078
3079int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
3080{
3081 unsigned int i;
3082
3083 ATH5K_TRACE(ah->ah_sc);
3084 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3085
3086 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
3087 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
3088
Nick Kossifidis194828a2008-04-16 18:49:02 +03003089 /*
3090 * Set NULL encryption on AR5212+
3091 *
3092 * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
3093 * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
3094 *
3095 * Note2: Windows driver (ndiswrapper) sets this to
3096 * 0x00000714 instead of 0x00000007
3097 */
3098 if (ah->ah_version > AR5K_AR5211)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003099 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
3100 AR5K_KEYTABLE_TYPE(entry));
3101
3102 return 0;
3103}
3104
3105int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
3106{
3107 ATH5K_TRACE(ah->ah_sc);
3108 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3109
3110 /* Check the validation flag at the end of the entry */
3111 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
3112 AR5K_KEYTABLE_VALID;
3113}
3114
3115int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
3116 const struct ieee80211_key_conf *key, const u8 *mac)
3117{
3118 unsigned int i;
3119 __le32 key_v[5] = {};
3120 u32 keytype;
3121
3122 ATH5K_TRACE(ah->ah_sc);
3123
3124 /* key->keylen comes in from mac80211 in bytes */
3125
3126 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
3127 return -EOPNOTSUPP;
3128
3129 switch (key->keylen) {
3130 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
3131 case 40 / 8:
3132 memcpy(&key_v[0], key->key, 5);
3133 keytype = AR5K_KEYTABLE_TYPE_40;
3134 break;
3135
3136 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
3137 case 104 / 8:
3138 memcpy(&key_v[0], &key->key[0], 6);
3139 memcpy(&key_v[2], &key->key[6], 6);
3140 memcpy(&key_v[4], &key->key[12], 1);
3141 keytype = AR5K_KEYTABLE_TYPE_104;
3142 break;
3143 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
3144 case 128 / 8:
3145 memcpy(&key_v[0], &key->key[0], 6);
3146 memcpy(&key_v[2], &key->key[6], 6);
3147 memcpy(&key_v[4], &key->key[12], 4);
3148 keytype = AR5K_KEYTABLE_TYPE_128;
3149 break;
3150
3151 default:
3152 return -EINVAL; /* shouldn't happen */
3153 }
3154
3155 for (i = 0; i < ARRAY_SIZE(key_v); i++)
3156 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
3157 AR5K_KEYTABLE_OFF(entry, i));
3158
3159 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
3160
3161 return ath5k_hw_set_key_lladdr(ah, entry, mac);
3162}
3163
3164int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
3165{
3166 u32 low_id, high_id;
3167
3168 ATH5K_TRACE(ah->ah_sc);
3169 /* Invalid entry (key table overflow) */
3170 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3171
3172 /* MAC may be NULL if it's a broadcast key. In this case no need to
3173 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3174 if (unlikely(mac == NULL)) {
3175 low_id = 0xffffffff;
3176 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3177 } else {
3178 low_id = AR5K_LOW_ID(mac);
3179 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3180 }
3181
3182 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3183 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3184
3185 return 0;
3186}
3187
3188
3189/********************************************\
3190Queue Control Unit, DFS Control Unit Functions
3191\********************************************/
3192
3193/*
3194 * Initialize a transmit queue
3195 */
3196int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3197 struct ath5k_txq_info *queue_info)
3198{
3199 unsigned int queue;
3200 int ret;
3201
3202 ATH5K_TRACE(ah->ah_sc);
3203
3204 /*
3205 * Get queue by type
3206 */
3207 /*5210 only has 2 queues*/
3208 if (ah->ah_version == AR5K_AR5210) {
3209 switch (queue_type) {
3210 case AR5K_TX_QUEUE_DATA:
3211 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3212 break;
3213 case AR5K_TX_QUEUE_BEACON:
3214 case AR5K_TX_QUEUE_CAB:
3215 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3216 break;
3217 default:
3218 return -EINVAL;
3219 }
3220 } else {
3221 switch (queue_type) {
3222 case AR5K_TX_QUEUE_DATA:
3223 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3224 ah->ah_txq[queue].tqi_type !=
3225 AR5K_TX_QUEUE_INACTIVE; queue++) {
3226
3227 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3228 return -EINVAL;
3229 }
3230 break;
3231 case AR5K_TX_QUEUE_UAPSD:
3232 queue = AR5K_TX_QUEUE_ID_UAPSD;
3233 break;
3234 case AR5K_TX_QUEUE_BEACON:
3235 queue = AR5K_TX_QUEUE_ID_BEACON;
3236 break;
3237 case AR5K_TX_QUEUE_CAB:
3238 queue = AR5K_TX_QUEUE_ID_CAB;
3239 break;
3240 case AR5K_TX_QUEUE_XR_DATA:
3241 if (ah->ah_version != AR5K_AR5212)
3242 ATH5K_ERR(ah->ah_sc,
3243 "XR data queues only supported in"
3244 " 5212!\n");
3245 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3246 break;
3247 default:
3248 return -EINVAL;
3249 }
3250 }
3251
3252 /*
3253 * Setup internal queue structure
3254 */
3255 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3256 ah->ah_txq[queue].tqi_type = queue_type;
3257
3258 if (queue_info != NULL) {
3259 queue_info->tqi_type = queue_type;
3260 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3261 if (ret)
3262 return ret;
3263 }
3264 /*
3265 * We use ah_txq_status to hold a temp value for
3266 * the Secondary interrupt mask registers on 5211+
3267 * check out ath5k_hw_reset_tx_queue
3268 */
3269 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3270
3271 return queue;
3272}
3273
3274/*
3275 * Setup a transmit queue
3276 */
3277int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3278 const struct ath5k_txq_info *queue_info)
3279{
3280 ATH5K_TRACE(ah->ah_sc);
3281 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3282
3283 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3284 return -EIO;
3285
3286 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3287
3288 /*XXX: Is this supported on 5210 ?*/
3289 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3290 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3291 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3292 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3293 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3294
3295 return 0;
3296}
3297
3298/*
3299 * Get properties for a specific transmit queue
3300 */
3301int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3302 struct ath5k_txq_info *queue_info)
3303{
3304 ATH5K_TRACE(ah->ah_sc);
3305 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3306 return 0;
3307}
3308
3309/*
3310 * Set a transmit queue inactive
3311 */
3312void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3313{
3314 ATH5K_TRACE(ah->ah_sc);
3315 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3316 return;
3317
3318 /* This queue will be skipped in further operations */
3319 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3320 /*For SIMR setup*/
3321 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3322}
3323
3324/*
3325 * Set DFS params for a transmit queue
3326 */
3327int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3328{
3329 u32 cw_min, cw_max, retry_lg, retry_sh;
3330 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3331
3332 ATH5K_TRACE(ah->ah_sc);
3333 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3334
3335 tq = &ah->ah_txq[queue];
3336
3337 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3338 return 0;
3339
3340 if (ah->ah_version == AR5K_AR5210) {
3341 /* Only handle data queues, others will be ignored */
3342 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3343 return 0;
3344
3345 /* Set Slot time */
Joe Perchese9010e22008-03-07 14:21:16 -08003346 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003347 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3348 AR5K_SLOT_TIME);
3349 /* Set ACK_CTS timeout */
Joe Perchese9010e22008-03-07 14:21:16 -08003350 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003351 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3352 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3353 /* Set Transmit Latency */
Joe Perchese9010e22008-03-07 14:21:16 -08003354 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003355 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3356 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3357 /* Set IFS0 */
Joe Perchese9010e22008-03-07 14:21:16 -08003358 if (ah->ah_turbo)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003359 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3360 (ah->ah_aifs + tq->tqi_aifs) *
3361 AR5K_INIT_SLOT_TIME_TURBO) <<
3362 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3363 AR5K_IFS0);
3364 else
3365 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3366 (ah->ah_aifs + tq->tqi_aifs) *
3367 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3368 AR5K_INIT_SIFS, AR5K_IFS0);
3369
3370 /* Set IFS1 */
Joe Perchese9010e22008-03-07 14:21:16 -08003371 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003372 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3373 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
Nick Kossifidis0bacdf32008-07-30 13:18:59 +03003374 /* Set AR5K_PHY_SETTLING */
Joe Perchese9010e22008-03-07 14:21:16 -08003375 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Nick Kossifidis0bacdf32008-07-30 13:18:59 +03003376 (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
3377 | 0x38 :
3378 (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
3379 | 0x1C,
3380 AR5K_PHY_SETTLING);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003381 /* Set Frame Control Register */
Joe Perchese9010e22008-03-07 14:21:16 -08003382 ath5k_hw_reg_write(ah, ah->ah_turbo ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003383 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3384 AR5K_PHY_TURBO_SHORT | 0x2020) :
3385 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3386 AR5K_PHY_FRAME_CTL_5210);
3387 }
3388
3389 /*
3390 * Calculate cwmin/max by channel mode
3391 */
3392 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3393 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3394 ah->ah_aifs = AR5K_TUNE_AIFS;
3395 /*XR is only supported on 5212*/
3396 if (IS_CHAN_XR(ah->ah_current_channel) &&
3397 ah->ah_version == AR5K_AR5212) {
3398 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3399 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3400 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3401 /*B mode is not supported on 5210*/
3402 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3403 ah->ah_version != AR5K_AR5210) {
3404 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3405 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3406 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3407 }
3408
3409 cw_min = 1;
3410 while (cw_min < ah->ah_cw_min)
3411 cw_min = (cw_min << 1) | 1;
3412
3413 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3414 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3415 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3416 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3417
3418 /*
3419 * Calculate and set retry limits
3420 */
Joe Perchese9010e22008-03-07 14:21:16 -08003421 if (ah->ah_software_retry) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003422 /* XXX Need to test this */
3423 retry_lg = ah->ah_limit_tx_retries;
3424 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3425 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3426 } else {
3427 retry_lg = AR5K_INIT_LG_RETRY;
3428 retry_sh = AR5K_INIT_SH_RETRY;
3429 }
3430
3431 /*No QCU/DCU [5210]*/
3432 if (ah->ah_version == AR5K_AR5210) {
3433 ath5k_hw_reg_write(ah,
3434 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3435 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3436 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3437 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3438 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3439 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3440 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3441 AR5K_NODCU_RETRY_LMT);
3442 } else {
3443 /*QCU/DCU [5211+]*/
3444 ath5k_hw_reg_write(ah,
3445 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3446 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3447 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3448 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3449 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3450 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3451 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3452
3453 /*===Rest is also for QCU/DCU only [5211+]===*/
3454
3455 /*
3456 * Set initial content window (cw_min/cw_max)
3457 * and arbitrated interframe space (aifs)...
3458 */
3459 ath5k_hw_reg_write(ah,
3460 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3461 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3462 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3463 AR5K_DCU_LCL_IFS_AIFS),
3464 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3465
3466 /*
3467 * Set misc registers
3468 */
3469 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3470 AR5K_QUEUE_MISC(queue));
3471
3472 if (tq->tqi_cbr_period) {
3473 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3474 AR5K_QCU_CBRCFG_INTVAL) |
3475 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3476 AR5K_QCU_CBRCFG_ORN_THRES),
3477 AR5K_QUEUE_CBRCFG(queue));
3478 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3479 AR5K_QCU_MISC_FRSHED_CBR);
3480 if (tq->tqi_cbr_overflow_limit)
3481 AR5K_REG_ENABLE_BITS(ah,
3482 AR5K_QUEUE_MISC(queue),
3483 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3484 }
3485
3486 if (tq->tqi_ready_time)
3487 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3488 AR5K_QCU_RDYTIMECFG_INTVAL) |
3489 AR5K_QCU_RDYTIMECFG_ENABLE,
3490 AR5K_QUEUE_RDYTIMECFG(queue));
3491
3492 if (tq->tqi_burst_time) {
3493 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3494 AR5K_DCU_CHAN_TIME_DUR) |
3495 AR5K_DCU_CHAN_TIME_ENABLE,
3496 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3497
3498 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3499 AR5K_REG_ENABLE_BITS(ah,
3500 AR5K_QUEUE_MISC(queue),
3501 AR5K_QCU_MISC_TXE);
3502 }
3503
3504 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3505 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3506 AR5K_QUEUE_DFS_MISC(queue));
3507
3508 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3509 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3510 AR5K_QUEUE_DFS_MISC(queue));
3511
3512 /*
3513 * Set registers by queue type
3514 */
3515 switch (tq->tqi_type) {
3516 case AR5K_TX_QUEUE_BEACON:
3517 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3518 AR5K_QCU_MISC_FRSHED_DBA_GT |
3519 AR5K_QCU_MISC_CBREXP_BCN |
3520 AR5K_QCU_MISC_BCN_ENABLE);
3521
3522 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3523 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3524 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3525 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3526 AR5K_DCU_MISC_BCN_ENABLE);
3527
3528 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3529 (AR5K_TUNE_SW_BEACON_RESP -
3530 AR5K_TUNE_DMA_BEACON_RESP) -
3531 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3532 AR5K_QCU_RDYTIMECFG_ENABLE,
3533 AR5K_QUEUE_RDYTIMECFG(queue));
3534 break;
3535
3536 case AR5K_TX_QUEUE_CAB:
3537 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3538 AR5K_QCU_MISC_FRSHED_DBA_GT |
3539 AR5K_QCU_MISC_CBREXP |
3540 AR5K_QCU_MISC_CBREXP_BCN);
3541
3542 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3543 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3544 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3545 break;
3546
3547 case AR5K_TX_QUEUE_UAPSD:
3548 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3549 AR5K_QCU_MISC_CBREXP);
3550 break;
3551
3552 case AR5K_TX_QUEUE_DATA:
3553 default:
3554 break;
3555 }
3556
3557 /*
3558 * Enable interrupts for this tx queue
3559 * in the secondary interrupt mask registers
3560 */
3561 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3562 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3563
3564 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3565 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3566
3567 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3568 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3569
3570 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3571 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3572
3573 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3574 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3575
3576
3577 /* Update secondary interrupt mask registers */
3578 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3579 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3580 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3581 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3582 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3583
3584 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3585 AR5K_SIMR0_QCU_TXOK) |
3586 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3587 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3588 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3589 AR5K_SIMR1_QCU_TXERR) |
3590 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3591 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3592 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3593 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3594 }
3595
3596 return 0;
3597}
3598
3599/*
3600 * Get number of pending frames
3601 * for a specific queue [5211+]
3602 */
3603u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3604 ATH5K_TRACE(ah->ah_sc);
3605 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3606
3607 /* Return if queue is declared inactive */
3608 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3609 return false;
3610
3611 /* XXX: How about AR5K_CFG_TXCNT ? */
3612 if (ah->ah_version == AR5K_AR5210)
3613 return false;
3614
3615 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3616}
3617
3618/*
3619 * Set slot time
3620 */
3621int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3622{
3623 ATH5K_TRACE(ah->ah_sc);
3624 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3625 return -EINVAL;
3626
3627 if (ah->ah_version == AR5K_AR5210)
3628 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3629 ah->ah_turbo), AR5K_SLOT_TIME);
3630 else
3631 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3632
3633 return 0;
3634}
3635
3636/*
3637 * Get slot time
3638 */
3639unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3640{
3641 ATH5K_TRACE(ah->ah_sc);
3642 if (ah->ah_version == AR5K_AR5210)
3643 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3644 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3645 else
3646 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3647}
3648
3649
3650/******************************\
3651 Hardware Descriptor Functions
3652\******************************/
3653
3654/*
3655 * TX Descriptor
3656 */
3657
3658/*
3659 * Initialize the 2-word tx descriptor on 5210/5211
3660 */
3661static int
3662ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3663 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3664 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3665 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3666 unsigned int rtscts_rate, unsigned int rtscts_duration)
3667{
3668 u32 frame_type;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003669 struct ath5k_hw_2w_tx_ctl *tx_ctl;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003670 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003671
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003672 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003673
3674 /*
3675 * Validate input
3676 * - Zero retries don't make sense.
3677 * - A zero rate will put the HW into a mode where it continously sends
3678 * noise on the channel, so it is important to avoid this.
3679 */
3680 if (unlikely(tx_tries0 == 0)) {
3681 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3682 WARN_ON(1);
3683 return -EINVAL;
3684 }
3685 if (unlikely(tx_rate0 == 0)) {
3686 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3687 WARN_ON(1);
3688 return -EINVAL;
3689 }
3690
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003691 /* Clear descriptor */
3692 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003693
3694 /* Setup control descriptor */
3695
3696 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003697
3698 /* remove padding we might have added before */
3699 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3700
3701 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003702 return -EINVAL;
3703
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003704 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003705
3706 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003707
3708 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3709 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003710 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003711
Bruno Randolf281c56d2008-02-05 18:44:55 +09003712 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003713 return -EINVAL;
3714
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003715 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003716
3717 /*
3718 * Verify and set header length
3719 * XXX: I only found that on 5210 code, does it work on 5211 ?
3720 */
3721 if (ah->ah_version == AR5K_AR5210) {
3722 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3723 return -EINVAL;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003724 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003725 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3726 }
3727
3728 /*Diferences between 5210-5211*/
3729 if (ah->ah_version == AR5K_AR5210) {
3730 switch (type) {
3731 case AR5K_PKT_TYPE_BEACON:
3732 case AR5K_PKT_TYPE_PROBE_RESP:
3733 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3734 case AR5K_PKT_TYPE_PIFS:
3735 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3736 default:
3737 frame_type = type /*<< 2 ?*/;
3738 }
3739
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003740 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003741 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3742 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3743 } else {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003744 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003745 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3746 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003747 tx_ctl->tx_control_1 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003748 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3749 }
3750#define _TX_FLAGS(_c, _flag) \
3751 if (flags & AR5K_TXDESC_##_flag) \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003752 tx_ctl->tx_control_##_c |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003753 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3754
3755 _TX_FLAGS(0, CLRDMASK);
3756 _TX_FLAGS(0, VEOL);
3757 _TX_FLAGS(0, INTREQ);
3758 _TX_FLAGS(0, RTSENA);
3759 _TX_FLAGS(1, NOACK);
3760
3761#undef _TX_FLAGS
3762
3763 /*
3764 * WEP crap
3765 */
3766 if (key_index != AR5K_TXKEYIX_INVALID) {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003767 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003768 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003769 tx_ctl->tx_control_1 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003770 AR5K_REG_SM(key_index,
3771 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3772 }
3773
3774 /*
3775 * RTS/CTS Duration [5210 ?]
3776 */
3777 if ((ah->ah_version == AR5K_AR5210) &&
3778 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003779 tx_ctl->tx_control_1 |= rtscts_duration &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003780 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3781
3782 return 0;
3783}
3784
3785/*
3786 * Initialize the 4-word tx descriptor on 5212
3787 */
3788static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3789 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3790 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3791 unsigned int tx_tries0, unsigned int key_index,
3792 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3793 unsigned int rtscts_duration)
3794{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003795 struct ath5k_hw_4w_tx_ctl *tx_ctl;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003796 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003797
3798 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003799 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003800
3801 /*
3802 * Validate input
3803 * - Zero retries don't make sense.
3804 * - A zero rate will put the HW into a mode where it continously sends
3805 * noise on the channel, so it is important to avoid this.
3806 */
3807 if (unlikely(tx_tries0 == 0)) {
3808 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3809 WARN_ON(1);
3810 return -EINVAL;
3811 }
3812 if (unlikely(tx_rate0 == 0)) {
3813 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3814 WARN_ON(1);
3815 return -EINVAL;
3816 }
3817
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003818 /* Clear descriptor */
3819 memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003820
3821 /* Setup control descriptor */
3822
3823 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003824
3825 /* remove padding we might have added before */
3826 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3827
3828 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003829 return -EINVAL;
3830
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003831 tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003832
3833 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003834
3835 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3836 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003837 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003838
Bruno Randolf281c56d2008-02-05 18:44:55 +09003839 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003840 return -EINVAL;
3841
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003842 tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003843
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003844 tx_ctl->tx_control_0 |=
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003845 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3846 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003847 tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003848 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003849 tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003850 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003851 tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003852
3853#define _TX_FLAGS(_c, _flag) \
3854 if (flags & AR5K_TXDESC_##_flag) \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003855 tx_ctl->tx_control_##_c |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003856 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3857
3858 _TX_FLAGS(0, CLRDMASK);
3859 _TX_FLAGS(0, VEOL);
3860 _TX_FLAGS(0, INTREQ);
3861 _TX_FLAGS(0, RTSENA);
3862 _TX_FLAGS(0, CTSENA);
3863 _TX_FLAGS(1, NOACK);
3864
3865#undef _TX_FLAGS
3866
3867 /*
3868 * WEP crap
3869 */
3870 if (key_index != AR5K_TXKEYIX_INVALID) {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003871 tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3872 tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003873 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3874 }
3875
3876 /*
3877 * RTS/CTS
3878 */
3879 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3880 if ((flags & AR5K_TXDESC_RTSENA) &&
3881 (flags & AR5K_TXDESC_CTSENA))
3882 return -EINVAL;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003883 tx_ctl->tx_control_2 |= rtscts_duration &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003884 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003885 tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003886 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3887 }
3888
3889 return 0;
3890}
3891
3892/*
3893 * Initialize a 4-word multirate tx descriptor on 5212
3894 */
Jiri Slabyb9887632008-02-15 21:58:52 +01003895static int
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003896ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3897 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3898 unsigned int tx_rate3, u_int tx_tries3)
3899{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003900 struct ath5k_hw_4w_tx_ctl *tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003901
3902 /*
3903 * Rates can be 0 as long as the retry count is 0 too.
3904 * A zero rate and nonzero retry count will put the HW into a mode where
3905 * it continously sends noise on the channel, so it is important to
3906 * avoid this.
3907 */
3908 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3909 (tx_rate2 == 0 && tx_tries2 != 0) ||
3910 (tx_rate3 == 0 && tx_tries3 != 0))) {
3911 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3912 WARN_ON(1);
3913 return -EINVAL;
3914 }
3915
3916 if (ah->ah_version == AR5K_AR5212) {
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003917 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003918
3919#define _XTX_TRIES(_n) \
3920 if (tx_tries##_n) { \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003921 tx_ctl->tx_control_2 |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003922 AR5K_REG_SM(tx_tries##_n, \
3923 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003924 tx_ctl->tx_control_3 |= \
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003925 AR5K_REG_SM(tx_rate##_n, \
3926 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3927 }
3928
3929 _XTX_TRIES(1);
3930 _XTX_TRIES(2);
3931 _XTX_TRIES(3);
3932
3933#undef _XTX_TRIES
3934
Jiri Slabyb9887632008-02-15 21:58:52 +01003935 return 1;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003936 }
3937
Jiri Slabyb9887632008-02-15 21:58:52 +01003938 return 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003939}
3940
3941/*
3942 * Proccess the tx status descriptor on 5210/5211
3943 */
3944static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09003945 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003946{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003947 struct ath5k_hw_2w_tx_ctl *tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003948 struct ath5k_hw_tx_status *tx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003949
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003950 ATH5K_TRACE(ah->ah_sc);
3951
3952 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3953 tx_status = &desc->ud.ds_tx5210.tx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003954
3955 /* No frame has been send or error */
3956 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3957 return -EINPROGRESS;
3958
3959 /*
3960 * Get descriptor status
3961 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09003962 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003963 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003964 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003965 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003966 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003967 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003968 /*TODO: ts->ts_virtcol + test*/
3969 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003970 AR5K_DESC_TX_STATUS1_SEQ_NUM);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003971 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003972 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
Bruno Randolfb47f4072008-03-05 18:35:45 +09003973 ts->ts_antenna = 1;
3974 ts->ts_status = 0;
3975 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003976 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3977
3978 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3979 if (tx_status->tx_status_0 &
3980 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
Bruno Randolfb47f4072008-03-05 18:35:45 +09003981 ts->ts_status |= AR5K_TXERR_XRETRY;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003982
3983 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
Bruno Randolfb47f4072008-03-05 18:35:45 +09003984 ts->ts_status |= AR5K_TXERR_FIFO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003985
3986 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
Bruno Randolfb47f4072008-03-05 18:35:45 +09003987 ts->ts_status |= AR5K_TXERR_FILT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003988 }
3989
3990 return 0;
3991}
3992
3993/*
3994 * Proccess a tx descriptor on 5212
3995 */
3996static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09003997 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003998{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09003999 struct ath5k_hw_4w_tx_ctl *tx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004000 struct ath5k_hw_tx_status *tx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004001
4002 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004003
4004 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
4005 tx_status = &desc->ud.ds_tx5212.tx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004006
4007 /* No frame has been send or error */
4008 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
4009 return -EINPROGRESS;
4010
4011 /*
4012 * Get descriptor status
4013 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09004014 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004015 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004016 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004017 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004018 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004019 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004020 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004021 AR5K_DESC_TX_STATUS1_SEQ_NUM);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004022 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004023 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004024 ts->ts_antenna = (tx_status->tx_status_1 &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004025 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004026 ts->ts_status = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004027
4028 switch (AR5K_REG_MS(tx_status->tx_status_1,
4029 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
4030 case 0:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004031 ts->ts_rate = tx_ctl->tx_control_3 &
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004032 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
4033 break;
4034 case 1:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004035 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004036 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004037 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004038 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
4039 break;
4040 case 2:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004041 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004042 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004043 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004044 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
4045 break;
4046 case 3:
Bruno Randolfb47f4072008-03-05 18:35:45 +09004047 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004048 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004049 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004050 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
4051 break;
4052 }
4053
4054 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
4055 if (tx_status->tx_status_0 &
4056 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004057 ts->ts_status |= AR5K_TXERR_XRETRY;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004058
4059 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004060 ts->ts_status |= AR5K_TXERR_FIFO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004061
4062 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004063 ts->ts_status |= AR5K_TXERR_FILT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004064 }
4065
4066 return 0;
4067}
4068
4069/*
4070 * RX Descriptor
4071 */
4072
4073/*
4074 * Initialize an rx descriptor
4075 */
4076int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
4077 u32 size, unsigned int flags)
4078{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004079 struct ath5k_hw_rx_ctl *rx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004080
4081 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004082 rx_ctl = &desc->ud.ds_rx.rx_ctl;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004083
4084 /*
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004085 * Clear the descriptor
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004086 * If we don't clean the status descriptor,
4087 * while scanning we get too many results,
4088 * most of them virtual, after some secs
4089 * of scanning system hangs. M.F.
4090 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004091 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004092
4093 /* Setup descriptor */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004094 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
4095 if (unlikely(rx_ctl->rx_control_1 != size))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004096 return -EINVAL;
4097
4098 if (flags & AR5K_RXDESC_INTREQ)
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004099 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004100
4101 return 0;
4102}
4103
4104/*
4105 * Proccess the rx status descriptor on 5210/5211
4106 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004107static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004108 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004109{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004110 struct ath5k_hw_rx_status *rx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004111
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004112 rx_status = &desc->ud.ds_rx.u.rx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004113
4114 /* No frame received / not ready */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004115 if (unlikely((rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004116 == 0))
4117 return -EINPROGRESS;
4118
4119 /*
4120 * Frame receive status
4121 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09004122 rs->rs_datalen = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004123 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004124 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004125 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004126 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004127 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004128 rs->rs_antenna = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004129 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004130 rs->rs_more = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004131 AR5K_5210_RX_DESC_STATUS0_MORE;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004132 /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
4133 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004134 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004135 rs->rs_status = 0;
Bob Copelandd6894b52008-05-12 21:16:44 -04004136 rs->rs_phyerr = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004137
4138 /*
4139 * Key table status
4140 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004141 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004142 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004143 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004144 else
Bruno Randolfb47f4072008-03-05 18:35:45 +09004145 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004146
4147 /*
4148 * Receive/descriptor errors
4149 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004150 if ((rx_status->rx_status_1 &
4151 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4152 if (rx_status->rx_status_1 &
4153 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004154 rs->rs_status |= AR5K_RXERR_CRC;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004155
4156 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004157 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004158 rs->rs_status |= AR5K_RXERR_FIFO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004159
4160 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004161 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
Bruno Randolfb47f4072008-03-05 18:35:45 +09004162 rs->rs_status |= AR5K_RXERR_PHY;
Bob Copelandd6894b52008-05-12 21:16:44 -04004163 rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004164 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004165 }
4166
4167 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004168 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004169 rs->rs_status |= AR5K_RXERR_DECRYPT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004170 }
4171
4172 return 0;
4173}
4174
4175/*
4176 * Proccess the rx status descriptor on 5212
4177 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004178static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004179 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004180{
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004181 struct ath5k_hw_rx_status *rx_status;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004182 struct ath5k_hw_rx_error *rx_err;
4183
4184 ATH5K_TRACE(ah->ah_sc);
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004185 rx_status = &desc->ud.ds_rx.u.rx_stat;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004186
4187 /* Overlay on error */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004188 rx_err = &desc->ud.ds_rx.u.rx_err;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004189
4190 /* No frame received / not ready */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004191 if (unlikely((rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004192 == 0))
4193 return -EINPROGRESS;
4194
4195 /*
4196 * Frame receive status
4197 */
Bruno Randolfb47f4072008-03-05 18:35:45 +09004198 rs->rs_datalen = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004199 AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004200 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004201 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004202 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004203 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004204 rs->rs_antenna = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004205 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004206 rs->rs_more = rx_status->rx_status_0 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004207 AR5K_5212_RX_DESC_STATUS0_MORE;
Bruno Randolfb47f4072008-03-05 18:35:45 +09004208 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004209 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Bruno Randolfb47f4072008-03-05 18:35:45 +09004210 rs->rs_status = 0;
Bob Copelandd6894b52008-05-12 21:16:44 -04004211 rs->rs_phyerr = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004212
4213 /*
4214 * Key table status
4215 */
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004216 if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004217 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004218 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004219 else
Bruno Randolfb47f4072008-03-05 18:35:45 +09004220 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004221
4222 /*
4223 * Receive/descriptor errors
4224 */
4225 if ((rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004226 AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4227 if (rx_status->rx_status_1 &
4228 AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004229 rs->rs_status |= AR5K_RXERR_CRC;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004230
4231 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004232 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
Bruno Randolfb47f4072008-03-05 18:35:45 +09004233 rs->rs_status |= AR5K_RXERR_PHY;
Bob Copelandd6894b52008-05-12 21:16:44 -04004234 rs->rs_phyerr |= AR5K_REG_MS(rx_err->rx_error_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09004235 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004236 }
4237
4238 if (rx_status->rx_status_1 &
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004239 AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004240 rs->rs_status |= AR5K_RXERR_DECRYPT;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004241
Bruno Randolf19fd6e52008-03-05 18:35:23 +09004242 if (rx_status->rx_status_1 &
4243 AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
Bruno Randolfb47f4072008-03-05 18:35:45 +09004244 rs->rs_status |= AR5K_RXERR_MIC;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004245 }
4246
4247 return 0;
4248}
4249
4250
4251/****************\
4252 GPIO Functions
4253\****************/
4254
4255/*
4256 * Set led state
4257 */
4258void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4259{
4260 u32 led;
4261 /*5210 has different led mode handling*/
4262 u32 led_5210;
4263
4264 ATH5K_TRACE(ah->ah_sc);
4265
4266 /*Reset led status*/
4267 if (ah->ah_version != AR5K_AR5210)
4268 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4269 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4270 else
4271 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4272
4273 /*
4274 * Some blinking values, define at your wish
4275 */
4276 switch (state) {
4277 case AR5K_LED_SCAN:
4278 case AR5K_LED_AUTH:
4279 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4280 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4281 break;
4282
4283 case AR5K_LED_INIT:
4284 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4285 led_5210 = AR5K_PCICFG_LED_PEND;
4286 break;
4287
4288 case AR5K_LED_ASSOC:
4289 case AR5K_LED_RUN:
4290 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4291 led_5210 = AR5K_PCICFG_LED_ASSOC;
4292 break;
4293
4294 default:
4295 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4296 led_5210 = AR5K_PCICFG_LED_PEND;
4297 break;
4298 }
4299
4300 /*Write new status to the register*/
4301 if (ah->ah_version != AR5K_AR5210)
4302 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4303 else
4304 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4305}
4306
4307/*
4308 * Set GPIO outputs
4309 */
4310int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4311{
4312 ATH5K_TRACE(ah->ah_sc);
4313 if (gpio > AR5K_NUM_GPIO)
4314 return -EINVAL;
4315
4316 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4317 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4318
4319 return 0;
4320}
4321
4322/*
4323 * Set GPIO inputs
4324 */
4325int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4326{
4327 ATH5K_TRACE(ah->ah_sc);
4328 if (gpio > AR5K_NUM_GPIO)
4329 return -EINVAL;
4330
4331 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4332 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4333
4334 return 0;
4335}
4336
4337/*
4338 * Get GPIO state
4339 */
4340u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4341{
4342 ATH5K_TRACE(ah->ah_sc);
4343 if (gpio > AR5K_NUM_GPIO)
4344 return 0xffffffff;
4345
4346 /* GPIO input magic */
4347 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4348 0x1;
4349}
4350
4351/*
4352 * Set GPIO state
4353 */
4354int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4355{
4356 u32 data;
4357 ATH5K_TRACE(ah->ah_sc);
4358
4359 if (gpio > AR5K_NUM_GPIO)
4360 return -EINVAL;
4361
4362 /* GPIO output magic */
4363 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4364
4365 data &= ~(1 << gpio);
4366 data |= (val & 1) << gpio;
4367
4368 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4369
4370 return 0;
4371}
4372
4373/*
4374 * Initialize the GPIO interrupt (RFKill switch)
4375 */
4376void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4377 u32 interrupt_level)
4378{
4379 u32 data;
4380
4381 ATH5K_TRACE(ah->ah_sc);
4382 if (gpio > AR5K_NUM_GPIO)
4383 return;
4384
4385 /*
4386 * Set the GPIO interrupt
4387 */
4388 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4389 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4390 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4391 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4392
4393 ath5k_hw_reg_write(ah, interrupt_level ? data :
4394 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4395
4396 ah->ah_imr |= AR5K_IMR_GPIO;
4397
4398 /* Enable GPIO interrupts */
4399 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4400}
4401
4402
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004403
4404
4405/****************\
4406 Misc functions
4407\****************/
4408
4409int ath5k_hw_get_capability(struct ath5k_hw *ah,
4410 enum ath5k_capability_type cap_type,
4411 u32 capability, u32 *result)
4412{
4413 ATH5K_TRACE(ah->ah_sc);
4414
4415 switch (cap_type) {
4416 case AR5K_CAP_NUM_TXQUEUES:
4417 if (result) {
4418 if (ah->ah_version == AR5K_AR5210)
4419 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4420 else
4421 *result = AR5K_NUM_TX_QUEUES;
4422 goto yes;
4423 }
4424 case AR5K_CAP_VEOL:
4425 goto yes;
4426 case AR5K_CAP_COMPRESSION:
4427 if (ah->ah_version == AR5K_AR5212)
4428 goto yes;
4429 else
4430 goto no;
4431 case AR5K_CAP_BURST:
4432 goto yes;
4433 case AR5K_CAP_TPC:
4434 goto yes;
4435 case AR5K_CAP_BSSIDMASK:
4436 if (ah->ah_version == AR5K_AR5212)
4437 goto yes;
4438 else
4439 goto no;
4440 case AR5K_CAP_XR:
4441 if (ah->ah_version == AR5K_AR5212)
4442 goto yes;
4443 else
4444 goto no;
4445 default:
4446 goto no;
4447 }
4448
4449no:
4450 return -EINVAL;
4451yes:
4452 return 0;
4453}
4454
4455static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4456 u16 assoc_id)
4457{
4458 ATH5K_TRACE(ah->ah_sc);
4459
4460 if (ah->ah_version == AR5K_AR5210) {
4461 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4462 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4463 return 0;
4464 }
4465
4466 return -EIO;
4467}
4468
4469static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4470{
4471 ATH5K_TRACE(ah->ah_sc);
4472
4473 if (ah->ah_version == AR5K_AR5210) {
4474 AR5K_REG_ENABLE_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}