blob: 62172d5857239549ba6fa233df721096773fd707 [file] [log] [blame]
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001/*
2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20/******************************\
21 Hardware Descriptor Functions
22\******************************/
23
24#include "ath5k.h"
25#include "reg.h"
26#include "debug.h"
27#include "base.h"
28
Nick Kossifidis9320b5c2010-11-23 20:36:45 +020029
30/************************\
31* TX Control descriptors *
32\************************/
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030033
34/*
35 * Initialize the 2-word tx control descriptor on 5210/5211
36 */
37static int
38ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
Benoit Papillault8127fbd2010-02-27 23:05:26 +010039 unsigned int pkt_len, unsigned int hdr_len, int padsize,
40 enum ath5k_pkt_type type,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030041 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
42 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
43 unsigned int rtscts_rate, unsigned int rtscts_duration)
44{
45 u32 frame_type;
46 struct ath5k_hw_2w_tx_ctl *tx_ctl;
47 unsigned int frame_len;
48
49 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
50
51 /*
52 * Validate input
53 * - Zero retries don't make sense.
Lucas De Marchi25985ed2011-03-30 22:57:33 -030054 * - A zero rate will put the HW into a mode where it continuously sends
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030055 * noise on the channel, so it is important to avoid this.
56 */
57 if (unlikely(tx_tries0 == 0)) {
58 ATH5K_ERR(ah->ah_sc, "zero retries\n");
59 WARN_ON(1);
60 return -EINVAL;
61 }
62 if (unlikely(tx_rate0 == 0)) {
63 ATH5K_ERR(ah->ah_sc, "zero rate\n");
64 WARN_ON(1);
65 return -EINVAL;
66 }
67
68 /* Clear descriptor */
69 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
70
71 /* Setup control descriptor */
72
73 /* Verify and set frame length */
74
75 /* remove padding we might have added before */
Benoit Papillault8127fbd2010-02-27 23:05:26 +010076 frame_len = pkt_len - padsize + FCS_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030077
78 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
79 return -EINVAL;
80
81 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
82
83 /* Verify and set buffer length */
84
85 /* NB: beacon's BufLen must be a multiple of 4 bytes */
86 if (type == AR5K_PKT_TYPE_BEACON)
87 pkt_len = roundup(pkt_len, 4);
88
89 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
90 return -EINVAL;
91
92 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
93
94 /*
Bruno Randolf1884a362010-06-16 19:12:28 +090095 * Verify and set header length (only 5210)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030096 */
97 if (ah->ah_version == AR5K_AR5210) {
Bruno Randolf03417bc2010-06-16 19:12:17 +090098 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030099 return -EINVAL;
100 tx_ctl->tx_control_0 |=
Bruno Randolf03417bc2010-06-16 19:12:17 +0900101 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300102 }
103
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100104 /*Differences between 5210-5211*/
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300105 if (ah->ah_version == AR5K_AR5210) {
106 switch (type) {
107 case AR5K_PKT_TYPE_BEACON:
108 case AR5K_PKT_TYPE_PROBE_RESP:
109 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
110 case AR5K_PKT_TYPE_PIFS:
111 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
112 default:
Bruno Randolf2237e922010-06-16 19:12:22 +0900113 frame_type = type;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300114 }
115
116 tx_ctl->tx_control_0 |=
Bruno Randolf03417bc2010-06-16 19:12:17 +0900117 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE_5210) |
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300118 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
119
120 } else {
121 tx_ctl->tx_control_0 |=
122 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
123 AR5K_REG_SM(antenna_mode,
124 AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
125 tx_ctl->tx_control_1 |=
Bruno Randolf03417bc2010-06-16 19:12:17 +0900126 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE_5211);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300127 }
Bruno Randolf1884a362010-06-16 19:12:28 +0900128
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300129#define _TX_FLAGS(_c, _flag) \
130 if (flags & AR5K_TXDESC_##_flag) { \
131 tx_ctl->tx_control_##_c |= \
132 AR5K_2W_TX_DESC_CTL##_c##_##_flag; \
133 }
Bruno Randolf1884a362010-06-16 19:12:28 +0900134#define _TX_FLAGS_5211(_c, _flag) \
135 if (flags & AR5K_TXDESC_##_flag) { \
136 tx_ctl->tx_control_##_c |= \
137 AR5K_2W_TX_DESC_CTL##_c##_##_flag##_5211; \
138 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300139 _TX_FLAGS(0, CLRDMASK);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300140 _TX_FLAGS(0, INTREQ);
141 _TX_FLAGS(0, RTSENA);
Bruno Randolf1884a362010-06-16 19:12:28 +0900142
143 if (ah->ah_version == AR5K_AR5211) {
144 _TX_FLAGS_5211(0, VEOL);
145 _TX_FLAGS_5211(1, NOACK);
146 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300147
148#undef _TX_FLAGS
Bruno Randolf1884a362010-06-16 19:12:28 +0900149#undef _TX_FLAGS_5211
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300150
151 /*
152 * WEP crap
153 */
154 if (key_index != AR5K_TXKEYIX_INVALID) {
155 tx_ctl->tx_control_0 |=
156 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
157 tx_ctl->tx_control_1 |=
158 AR5K_REG_SM(key_index,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900159 AR5K_2W_TX_DESC_CTL1_ENC_KEY_IDX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300160 }
161
162 /*
163 * RTS/CTS Duration [5210 ?]
164 */
165 if ((ah->ah_version == AR5K_AR5210) &&
166 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
167 tx_ctl->tx_control_1 |= rtscts_duration &
Bruno Randolf03417bc2010-06-16 19:12:17 +0900168 AR5K_2W_TX_DESC_CTL1_RTS_DURATION_5210;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300169
170 return 0;
171}
172
173/*
174 * Initialize the 4-word tx control descriptor on 5212
175 */
176static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
177 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100178 int padsize,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300179 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
180 unsigned int tx_tries0, unsigned int key_index,
181 unsigned int antenna_mode, unsigned int flags,
182 unsigned int rtscts_rate,
183 unsigned int rtscts_duration)
184{
185 struct ath5k_hw_4w_tx_ctl *tx_ctl;
186 unsigned int frame_len;
187
John W. Linville8962d872011-04-13 08:47:32 -0400188 /*
189 * Use local variables for these to reduce load/store access on
190 * uncached memory
191 */
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200192 u32 txctl0 = 0, txctl1 = 0, txctl2 = 0, txctl3 = 0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300193
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300194 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
195
196 /*
197 * Validate input
198 * - Zero retries don't make sense.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300199 * - A zero rate will put the HW into a mode where it continuously sends
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300200 * noise on the channel, so it is important to avoid this.
201 */
202 if (unlikely(tx_tries0 == 0)) {
203 ATH5K_ERR(ah->ah_sc, "zero retries\n");
204 WARN_ON(1);
205 return -EINVAL;
206 }
207 if (unlikely(tx_rate0 == 0)) {
208 ATH5K_ERR(ah->ah_sc, "zero rate\n");
209 WARN_ON(1);
210 return -EINVAL;
211 }
212
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200213 tx_power += ah->ah_txpower.txp_offset;
214 if (tx_power > AR5K_TUNE_MAX_TXPOWER)
215 tx_power = AR5K_TUNE_MAX_TXPOWER;
216
John W. Linville8962d872011-04-13 08:47:32 -0400217 /* Clear descriptor status area */
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200218 memset(&desc->ud.ds_tx5212.tx_stat, 0,
219 sizeof(desc->ud.ds_tx5212.tx_stat));
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300220
221 /* Setup control descriptor */
222
223 /* Verify and set frame length */
224
225 /* remove padding we might have added before */
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100226 frame_len = pkt_len - padsize + FCS_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300227
228 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
229 return -EINVAL;
230
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200231 txctl0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300232
233 /* Verify and set buffer length */
234
235 /* NB: beacon's BufLen must be a multiple of 4 bytes */
236 if (type == AR5K_PKT_TYPE_BEACON)
237 pkt_len = roundup(pkt_len, 4);
238
239 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
240 return -EINVAL;
241
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200242 txctl1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300243
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200244 txctl0 |= AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
245 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
246 txctl1 |= AR5K_REG_SM(type, AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
247 txctl2 = AR5K_REG_SM(tx_tries0, AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
248 txctl3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300249
250#define _TX_FLAGS(_c, _flag) \
251 if (flags & AR5K_TXDESC_##_flag) { \
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200252 txctl##_c |= AR5K_4W_TX_DESC_CTL##_c##_##_flag; \
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300253 }
254
255 _TX_FLAGS(0, CLRDMASK);
256 _TX_FLAGS(0, VEOL);
257 _TX_FLAGS(0, INTREQ);
258 _TX_FLAGS(0, RTSENA);
259 _TX_FLAGS(0, CTSENA);
260 _TX_FLAGS(1, NOACK);
261
262#undef _TX_FLAGS
263
264 /*
265 * WEP crap
266 */
267 if (key_index != AR5K_TXKEYIX_INVALID) {
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200268 txctl0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
269 txctl1 |= AR5K_REG_SM(key_index,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900270 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_IDX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300271 }
272
273 /*
274 * RTS/CTS
275 */
276 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
277 if ((flags & AR5K_TXDESC_RTSENA) &&
278 (flags & AR5K_TXDESC_CTSENA))
279 return -EINVAL;
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200280 txctl2 |= rtscts_duration & AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
281 txctl3 |= AR5K_REG_SM(rtscts_rate,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300282 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
283 }
284
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200285 tx_ctl->tx_control_0 = txctl0;
286 tx_ctl->tx_control_1 = txctl1;
287 tx_ctl->tx_control_2 = txctl2;
288 tx_ctl->tx_control_3 = txctl3;
289
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300290 return 0;
291}
292
293/*
294 * Initialize a 4-word multi rate retry tx control descriptor on 5212
295 */
Bruno Randolfa6668192010-06-16 19:12:01 +0900296int
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300297ath5k_hw_setup_mrr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
298 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2,
299 u_int tx_tries2, unsigned int tx_rate3, u_int tx_tries3)
300{
301 struct ath5k_hw_4w_tx_ctl *tx_ctl;
302
Bruno Randolfa6668192010-06-16 19:12:01 +0900303 /* no mrr support for cards older than 5212 */
304 if (ah->ah_version < AR5K_AR5212)
305 return 0;
306
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300307 /*
308 * Rates can be 0 as long as the retry count is 0 too.
309 * A zero rate and nonzero retry count will put the HW into a mode where
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300310 * it continuously sends noise on the channel, so it is important to
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300311 * avoid this.
312 */
313 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
314 (tx_rate2 == 0 && tx_tries2 != 0) ||
315 (tx_rate3 == 0 && tx_tries3 != 0))) {
316 ATH5K_ERR(ah->ah_sc, "zero rate\n");
317 WARN_ON(1);
318 return -EINVAL;
319 }
320
321 if (ah->ah_version == AR5K_AR5212) {
322 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
323
324#define _XTX_TRIES(_n) \
325 if (tx_tries##_n) { \
326 tx_ctl->tx_control_2 |= \
327 AR5K_REG_SM(tx_tries##_n, \
328 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
329 tx_ctl->tx_control_3 |= \
330 AR5K_REG_SM(tx_rate##_n, \
331 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
332 }
333
334 _XTX_TRIES(1);
335 _XTX_TRIES(2);
336 _XTX_TRIES(3);
337
338#undef _XTX_TRIES
339
340 return 1;
341 }
342
343 return 0;
344}
345
Nick Kossifidis9320b5c2010-11-23 20:36:45 +0200346
347/***********************\
348* TX Status descriptors *
349\***********************/
350
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300351/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300352 * Process the tx status descriptor on 5210/5211
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300353 */
354static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
355 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
356{
357 struct ath5k_hw_2w_tx_ctl *tx_ctl;
358 struct ath5k_hw_tx_status *tx_status;
359
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300360 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
361 tx_status = &desc->ud.ds_tx5210.tx_stat;
362
363 /* No frame has been send or error */
364 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
365 return -EINPROGRESS;
366
367 /*
368 * Get descriptor status
369 */
370 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
371 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
372 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
373 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Felix Fietkaued895082011-04-10 18:32:17 +0200374 ts->ts_final_retry = AR5K_REG_MS(tx_status->tx_status_0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300375 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
376 /*TODO: ts->ts_virtcol + test*/
377 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
378 AR5K_DESC_TX_STATUS1_SEQ_NUM);
379 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
380 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
381 ts->ts_antenna = 1;
382 ts->ts_status = 0;
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200383 ts->ts_final_idx = 0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300384
385 if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
386 if (tx_status->tx_status_0 &
387 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
388 ts->ts_status |= AR5K_TXERR_XRETRY;
389
390 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
391 ts->ts_status |= AR5K_TXERR_FIFO;
392
393 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
394 ts->ts_status |= AR5K_TXERR_FILT;
395 }
396
397 return 0;
398}
399
400/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300401 * Process a tx status descriptor on 5212
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300402 */
403static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
404 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
405{
406 struct ath5k_hw_4w_tx_ctl *tx_ctl;
407 struct ath5k_hw_tx_status *tx_status;
Felix Fietkaued895082011-04-10 18:32:17 +0200408 u32 txstat0, txstat1;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300409
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300410 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
411 tx_status = &desc->ud.ds_tx5212.tx_stat;
412
Felix Fietkaub161b892011-04-10 18:32:15 +0200413 txstat1 = ACCESS_ONCE(tx_status->tx_status_1);
414
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300415 /* No frame has been send or error */
Felix Fietkaub161b892011-04-10 18:32:15 +0200416 if (unlikely(!(txstat1 & AR5K_DESC_TX_STATUS1_DONE)))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300417 return -EINPROGRESS;
418
Felix Fietkaub161b892011-04-10 18:32:15 +0200419 txstat0 = ACCESS_ONCE(tx_status->tx_status_0);
Felix Fietkaub161b892011-04-10 18:32:15 +0200420
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300421 /*
422 * Get descriptor status
423 */
Felix Fietkaub161b892011-04-10 18:32:15 +0200424 ts->ts_tstamp = AR5K_REG_MS(txstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300425 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
Felix Fietkaub161b892011-04-10 18:32:15 +0200426 ts->ts_shortretry = AR5K_REG_MS(txstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300427 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Felix Fietkaued895082011-04-10 18:32:17 +0200428 ts->ts_final_retry = AR5K_REG_MS(txstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300429 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
Felix Fietkaub161b892011-04-10 18:32:15 +0200430 ts->ts_seqnum = AR5K_REG_MS(txstat1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300431 AR5K_DESC_TX_STATUS1_SEQ_NUM);
Felix Fietkaub161b892011-04-10 18:32:15 +0200432 ts->ts_rssi = AR5K_REG_MS(txstat1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300433 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
Felix Fietkaub161b892011-04-10 18:32:15 +0200434 ts->ts_antenna = (txstat1 &
Bruno Randolf03417bc2010-06-16 19:12:17 +0900435 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA_5212) ? 2 : 1;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300436 ts->ts_status = 0;
437
Felix Fietkaub161b892011-04-10 18:32:15 +0200438 ts->ts_final_idx = AR5K_REG_MS(txstat1,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900439 AR5K_DESC_TX_STATUS1_FINAL_TS_IX_5212);
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200440
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300441 /* TX error */
Felix Fietkaub161b892011-04-10 18:32:15 +0200442 if (!(txstat0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
443 if (txstat0 & AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300444 ts->ts_status |= AR5K_TXERR_XRETRY;
445
Felix Fietkaub161b892011-04-10 18:32:15 +0200446 if (txstat0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300447 ts->ts_status |= AR5K_TXERR_FIFO;
448
Felix Fietkaub161b892011-04-10 18:32:15 +0200449 if (txstat0 & AR5K_DESC_TX_STATUS0_FILTERED)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300450 ts->ts_status |= AR5K_TXERR_FILT;
451 }
452
453 return 0;
454}
455
Nick Kossifidis9320b5c2010-11-23 20:36:45 +0200456
457/****************\
458* RX Descriptors *
459\****************/
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300460
461/*
462 * Initialize an rx control descriptor
463 */
Bruno Randolfa6668192010-06-16 19:12:01 +0900464int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
465 u32 size, unsigned int flags)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300466{
467 struct ath5k_hw_rx_ctl *rx_ctl;
468
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300469 rx_ctl = &desc->ud.ds_rx.rx_ctl;
470
471 /*
472 * Clear the descriptor
473 * If we don't clean the status descriptor,
474 * while scanning we get too many results,
475 * most of them virtual, after some secs
476 * of scanning system hangs. M.F.
477 */
478 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
479
Bruno Randolf87861232010-06-16 19:12:34 +0900480 if (unlikely(size & ~AR5K_DESC_RX_CTL1_BUF_LEN))
481 return -EINVAL;
482
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300483 /* Setup descriptor */
484 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300485
486 if (flags & AR5K_RXDESC_INTREQ)
487 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
488
489 return 0;
490}
491
492/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300493 * Process the rx status descriptor on 5210/5211
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300494 */
495static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
496 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
497{
498 struct ath5k_hw_rx_status *rx_status;
499
Bruno Randolf62412a82010-06-16 19:12:12 +0900500 rx_status = &desc->ud.ds_rx.rx_stat;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300501
502 /* No frame received / not ready */
503 if (unlikely(!(rx_status->rx_status_1 &
Bruno Randolf87861232010-06-16 19:12:34 +0900504 AR5K_5210_RX_DESC_STATUS1_DONE)))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300505 return -EINPROGRESS;
506
Bruno Randolf87861232010-06-16 19:12:34 +0900507 memset(rs, 0, sizeof(struct ath5k_rx_status));
508
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300509 /*
510 * Frame receive status
511 */
512 rs->rs_datalen = rx_status->rx_status_0 &
513 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
514 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
515 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
516 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
517 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
Bob Copelandc7930332008-11-03 22:14:00 -0500518 rs->rs_more = !!(rx_status->rx_status_0 &
519 AR5K_5210_RX_DESC_STATUS0_MORE);
Bruno Randolf87861232010-06-16 19:12:34 +0900520 /* TODO: this timestamp is 13 bit, later on we assume 15 bit!
521 * also the HAL code for 5210 says the timestamp is bits [10..22] of the
522 * TSF, and extends the timestamp here to 15 bit.
523 * we need to check on 5210...
524 */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300525 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
526 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Bruno Randolf1884a362010-06-16 19:12:28 +0900527
528 if (ah->ah_version == AR5K_AR5211)
529 rs->rs_antenna = AR5K_REG_MS(rx_status->rx_status_0,
530 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANT_5211);
531 else
532 rs->rs_antenna = (rx_status->rx_status_0 &
533 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANT_5210)
534 ? 2 : 1;
535
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300536 /*
537 * Key table status
538 */
539 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
540 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
541 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
542 else
543 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
544
545 /*
546 * Receive/descriptor errors
547 */
548 if (!(rx_status->rx_status_1 &
Bruno Randolf87861232010-06-16 19:12:34 +0900549 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300550 if (rx_status->rx_status_1 &
551 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
552 rs->rs_status |= AR5K_RXERR_CRC;
553
Bruno Randolf87861232010-06-16 19:12:34 +0900554 /* only on 5210 */
555 if ((ah->ah_version == AR5K_AR5210) &&
556 (rx_status->rx_status_1 &
557 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN_5210))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300558 rs->rs_status |= AR5K_RXERR_FIFO;
559
560 if (rx_status->rx_status_1 &
561 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
562 rs->rs_status |= AR5K_RXERR_PHY;
Bruno Randolf87861232010-06-16 19:12:34 +0900563 rs->rs_phyerr = AR5K_REG_MS(rx_status->rx_status_1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300564 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
565 }
566
567 if (rx_status->rx_status_1 &
568 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
569 rs->rs_status |= AR5K_RXERR_DECRYPT;
570 }
571
572 return 0;
573}
574
575/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300576 * Process the rx status descriptor on 5212
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300577 */
578static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
Bruno Randolf28471092010-06-16 19:12:07 +0900579 struct ath5k_desc *desc,
580 struct ath5k_rx_status *rs)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300581{
582 struct ath5k_hw_rx_status *rx_status;
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200583 u32 rxstat0, rxstat1;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300584
Bruno Randolf62412a82010-06-16 19:12:12 +0900585 rx_status = &desc->ud.ds_rx.rx_stat;
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200586 rxstat1 = ACCESS_ONCE(rx_status->rx_status_1);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300587
588 /* No frame received / not ready */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200589 if (unlikely(!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_DONE)))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300590 return -EINPROGRESS;
591
Bruno Randolf87861232010-06-16 19:12:34 +0900592 memset(rs, 0, sizeof(struct ath5k_rx_status));
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200593 rxstat0 = ACCESS_ONCE(rx_status->rx_status_0);
Bruno Randolf87861232010-06-16 19:12:34 +0900594
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300595 /*
596 * Frame receive status
597 */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200598 rs->rs_datalen = rxstat0 & AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
599 rs->rs_rssi = AR5K_REG_MS(rxstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300600 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200601 rs->rs_rate = AR5K_REG_MS(rxstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300602 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200603 rs->rs_antenna = AR5K_REG_MS(rxstat0,
Bob Copelandc7930332008-11-03 22:14:00 -0500604 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA);
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200605 rs->rs_more = !!(rxstat0 & AR5K_5212_RX_DESC_STATUS0_MORE);
606 rs->rs_tstamp = AR5K_REG_MS(rxstat1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300607 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300608
609 /*
610 * Key table status
611 */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200612 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
613 rs->rs_keyix = AR5K_REG_MS(rxstat1,
Bruno Randolf28471092010-06-16 19:12:07 +0900614 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300615 else
616 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
617
618 /*
619 * Receive/descriptor errors
620 */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200621 if (!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
622 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300623 rs->rs_status |= AR5K_RXERR_CRC;
624
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200625 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300626 rs->rs_status |= AR5K_RXERR_PHY;
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200627 rs->rs_phyerr = AR5K_REG_MS(rxstat1,
Bruno Randolf62412a82010-06-16 19:12:12 +0900628 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR_CODE);
Bruno Randolf6a0076e2010-06-16 19:12:39 +0900629 if (!ah->ah_capabilities.cap_has_phyerr_counters)
630 ath5k_ani_phy_error_report(ah, rs->rs_phyerr);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300631 }
632
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200633 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300634 rs->rs_status |= AR5K_RXERR_DECRYPT;
635
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200636 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300637 rs->rs_status |= AR5K_RXERR_MIC;
638 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300639 return 0;
640}
641
Nick Kossifidis9320b5c2010-11-23 20:36:45 +0200642
643/********\
644* Attach *
645\********/
646
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300647/*
648 * Init function pointers inside ath5k_hw struct
649 */
650int ath5k_hw_init_desc_functions(struct ath5k_hw *ah)
651{
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300652 if (ah->ah_version == AR5K_AR5212) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300653 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300654 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300655 ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
Bruno Randolfa6668192010-06-16 19:12:01 +0900656 } else if (ah->ah_version <= AR5K_AR5211) {
657 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
658 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300659 ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
Bruno Randolfa6668192010-06-16 19:12:01 +0900660 } else
661 return -ENOTSUPP;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300662 return 0;
663}