blob: f1f1a22ce4757b05864920080f42531dde74e004 [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
29/*
30 * TX Descriptors
31 */
32
33/*
34 * Initialize the 2-word tx control descriptor on 5210/5211
35 */
36static int
37ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
Benoit Papillault8127fbd2010-02-27 23:05:26 +010038 unsigned int pkt_len, unsigned int hdr_len, int padsize,
39 enum ath5k_pkt_type type,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030040 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
41 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
42 unsigned int rtscts_rate, unsigned int rtscts_duration)
43{
44 u32 frame_type;
45 struct ath5k_hw_2w_tx_ctl *tx_ctl;
46 unsigned int frame_len;
47
48 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
49
50 /*
51 * Validate input
52 * - Zero retries don't make sense.
53 * - A zero rate will put the HW into a mode where it continously sends
54 * noise on the channel, so it is important to avoid this.
55 */
56 if (unlikely(tx_tries0 == 0)) {
57 ATH5K_ERR(ah->ah_sc, "zero retries\n");
58 WARN_ON(1);
59 return -EINVAL;
60 }
61 if (unlikely(tx_rate0 == 0)) {
62 ATH5K_ERR(ah->ah_sc, "zero rate\n");
63 WARN_ON(1);
64 return -EINVAL;
65 }
66
67 /* Clear descriptor */
68 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
69
70 /* Setup control descriptor */
71
72 /* Verify and set frame length */
73
74 /* remove padding we might have added before */
Benoit Papillault8127fbd2010-02-27 23:05:26 +010075 frame_len = pkt_len - padsize + FCS_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030076
77 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
78 return -EINVAL;
79
80 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
81
82 /* Verify and set buffer length */
83
84 /* NB: beacon's BufLen must be a multiple of 4 bytes */
85 if (type == AR5K_PKT_TYPE_BEACON)
86 pkt_len = roundup(pkt_len, 4);
87
88 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
89 return -EINVAL;
90
91 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
92
93 /*
94 * Verify and set header length
95 * XXX: I only found that on 5210 code, does it work on 5211 ?
96 */
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 }
128#define _TX_FLAGS(_c, _flag) \
129 if (flags & AR5K_TXDESC_##_flag) { \
130 tx_ctl->tx_control_##_c |= \
131 AR5K_2W_TX_DESC_CTL##_c##_##_flag; \
132 }
133
134 _TX_FLAGS(0, CLRDMASK);
135 _TX_FLAGS(0, VEOL);
136 _TX_FLAGS(0, INTREQ);
137 _TX_FLAGS(0, RTSENA);
138 _TX_FLAGS(1, NOACK);
139
140#undef _TX_FLAGS
141
142 /*
143 * WEP crap
144 */
145 if (key_index != AR5K_TXKEYIX_INVALID) {
146 tx_ctl->tx_control_0 |=
147 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
148 tx_ctl->tx_control_1 |=
149 AR5K_REG_SM(key_index,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900150 AR5K_2W_TX_DESC_CTL1_ENC_KEY_IDX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300151 }
152
153 /*
154 * RTS/CTS Duration [5210 ?]
155 */
156 if ((ah->ah_version == AR5K_AR5210) &&
157 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
158 tx_ctl->tx_control_1 |= rtscts_duration &
Bruno Randolf03417bc2010-06-16 19:12:17 +0900159 AR5K_2W_TX_DESC_CTL1_RTS_DURATION_5210;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300160
161 return 0;
162}
163
164/*
165 * Initialize the 4-word tx control descriptor on 5212
166 */
167static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
168 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100169 int padsize,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300170 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
171 unsigned int tx_tries0, unsigned int key_index,
172 unsigned int antenna_mode, unsigned int flags,
173 unsigned int rtscts_rate,
174 unsigned int rtscts_duration)
175{
176 struct ath5k_hw_4w_tx_ctl *tx_ctl;
177 unsigned int frame_len;
178
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300179 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
180
181 /*
182 * Validate input
183 * - Zero retries don't make sense.
184 * - A zero rate will put the HW into a mode where it continously sends
185 * noise on the channel, so it is important to avoid this.
186 */
187 if (unlikely(tx_tries0 == 0)) {
188 ATH5K_ERR(ah->ah_sc, "zero retries\n");
189 WARN_ON(1);
190 return -EINVAL;
191 }
192 if (unlikely(tx_rate0 == 0)) {
193 ATH5K_ERR(ah->ah_sc, "zero rate\n");
194 WARN_ON(1);
195 return -EINVAL;
196 }
197
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200198 tx_power += ah->ah_txpower.txp_offset;
199 if (tx_power > AR5K_TUNE_MAX_TXPOWER)
200 tx_power = AR5K_TUNE_MAX_TXPOWER;
201
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300202 /* Clear descriptor */
203 memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
204
205 /* Setup control descriptor */
206
207 /* Verify and set frame length */
208
209 /* remove padding we might have added before */
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100210 frame_len = pkt_len - padsize + FCS_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300211
212 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
213 return -EINVAL;
214
215 tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
216
217 /* Verify and set buffer length */
218
219 /* NB: beacon's BufLen must be a multiple of 4 bytes */
220 if (type == AR5K_PKT_TYPE_BEACON)
221 pkt_len = roundup(pkt_len, 4);
222
223 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
224 return -EINVAL;
225
226 tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
227
228 tx_ctl->tx_control_0 |=
229 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
230 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
231 tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
232 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
Andrew Blaiche9f08382010-03-01 10:30:40 -0500233 tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300234 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
235 tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
236
237#define _TX_FLAGS(_c, _flag) \
238 if (flags & AR5K_TXDESC_##_flag) { \
239 tx_ctl->tx_control_##_c |= \
240 AR5K_4W_TX_DESC_CTL##_c##_##_flag; \
241 }
242
243 _TX_FLAGS(0, CLRDMASK);
244 _TX_FLAGS(0, VEOL);
245 _TX_FLAGS(0, INTREQ);
246 _TX_FLAGS(0, RTSENA);
247 _TX_FLAGS(0, CTSENA);
248 _TX_FLAGS(1, NOACK);
249
250#undef _TX_FLAGS
251
252 /*
253 * WEP crap
254 */
255 if (key_index != AR5K_TXKEYIX_INVALID) {
256 tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
257 tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900258 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_IDX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300259 }
260
261 /*
262 * RTS/CTS
263 */
264 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
265 if ((flags & AR5K_TXDESC_RTSENA) &&
266 (flags & AR5K_TXDESC_CTSENA))
267 return -EINVAL;
268 tx_ctl->tx_control_2 |= rtscts_duration &
269 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
270 tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
271 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
272 }
273
274 return 0;
275}
276
277/*
278 * Initialize a 4-word multi rate retry tx control descriptor on 5212
279 */
Bruno Randolfa6668192010-06-16 19:12:01 +0900280int
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300281ath5k_hw_setup_mrr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
282 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2,
283 u_int tx_tries2, unsigned int tx_rate3, u_int tx_tries3)
284{
285 struct ath5k_hw_4w_tx_ctl *tx_ctl;
286
Bruno Randolfa6668192010-06-16 19:12:01 +0900287 /* no mrr support for cards older than 5212 */
288 if (ah->ah_version < AR5K_AR5212)
289 return 0;
290
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300291 /*
292 * Rates can be 0 as long as the retry count is 0 too.
293 * A zero rate and nonzero retry count will put the HW into a mode where
294 * it continously sends noise on the channel, so it is important to
295 * avoid this.
296 */
297 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
298 (tx_rate2 == 0 && tx_tries2 != 0) ||
299 (tx_rate3 == 0 && tx_tries3 != 0))) {
300 ATH5K_ERR(ah->ah_sc, "zero rate\n");
301 WARN_ON(1);
302 return -EINVAL;
303 }
304
305 if (ah->ah_version == AR5K_AR5212) {
306 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
307
308#define _XTX_TRIES(_n) \
309 if (tx_tries##_n) { \
310 tx_ctl->tx_control_2 |= \
311 AR5K_REG_SM(tx_tries##_n, \
312 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
313 tx_ctl->tx_control_3 |= \
314 AR5K_REG_SM(tx_rate##_n, \
315 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
316 }
317
318 _XTX_TRIES(1);
319 _XTX_TRIES(2);
320 _XTX_TRIES(3);
321
322#undef _XTX_TRIES
323
324 return 1;
325 }
326
327 return 0;
328}
329
330/*
331 * Proccess the tx status descriptor on 5210/5211
332 */
333static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
334 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
335{
336 struct ath5k_hw_2w_tx_ctl *tx_ctl;
337 struct ath5k_hw_tx_status *tx_status;
338
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300339 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
340 tx_status = &desc->ud.ds_tx5210.tx_stat;
341
342 /* No frame has been send or error */
343 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
344 return -EINPROGRESS;
345
346 /*
347 * Get descriptor status
348 */
349 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
350 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
351 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
352 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
353 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
354 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
355 /*TODO: ts->ts_virtcol + test*/
356 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
357 AR5K_DESC_TX_STATUS1_SEQ_NUM);
358 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
359 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
360 ts->ts_antenna = 1;
361 ts->ts_status = 0;
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200362 ts->ts_rate[0] = AR5K_REG_MS(tx_ctl->tx_control_0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300363 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200364 ts->ts_retry[0] = ts->ts_longretry;
365 ts->ts_final_idx = 0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300366
367 if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
368 if (tx_status->tx_status_0 &
369 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
370 ts->ts_status |= AR5K_TXERR_XRETRY;
371
372 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
373 ts->ts_status |= AR5K_TXERR_FIFO;
374
375 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
376 ts->ts_status |= AR5K_TXERR_FILT;
377 }
378
379 return 0;
380}
381
382/*
383 * Proccess a tx status descriptor on 5212
384 */
385static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
386 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
387{
388 struct ath5k_hw_4w_tx_ctl *tx_ctl;
389 struct ath5k_hw_tx_status *tx_status;
390
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300391 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
392 tx_status = &desc->ud.ds_tx5212.tx_stat;
393
394 /* No frame has been send or error */
395 if (unlikely(!(tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE)))
396 return -EINPROGRESS;
397
398 /*
399 * Get descriptor status
400 */
401 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
402 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
403 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
404 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
405 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
406 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
407 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
408 AR5K_DESC_TX_STATUS1_SEQ_NUM);
409 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
410 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
411 ts->ts_antenna = (tx_status->tx_status_1 &
Bruno Randolf03417bc2010-06-16 19:12:17 +0900412 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA_5212) ? 2 : 1;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300413 ts->ts_status = 0;
414
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200415 ts->ts_final_idx = AR5K_REG_MS(tx_status->tx_status_1,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900416 AR5K_DESC_TX_STATUS1_FINAL_TS_IX_5212);
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200417
418 /* The longretry counter has the number of un-acked retries
419 * for the final rate. To get the total number of retries
420 * we have to add the retry counters for the other rates
421 * as well
422 */
423 ts->ts_retry[ts->ts_final_idx] = ts->ts_longretry;
424 switch (ts->ts_final_idx) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300425 case 3:
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200426 ts->ts_rate[3] = AR5K_REG_MS(tx_ctl->tx_control_3,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300427 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200428
429 ts->ts_retry[2] = AR5K_REG_MS(tx_ctl->tx_control_2,
430 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
431 ts->ts_longretry += ts->ts_retry[2];
432 /* fall through */
433 case 2:
434 ts->ts_rate[2] = AR5K_REG_MS(tx_ctl->tx_control_3,
435 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
436
437 ts->ts_retry[1] = AR5K_REG_MS(tx_ctl->tx_control_2,
438 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
439 ts->ts_longretry += ts->ts_retry[1];
440 /* fall through */
441 case 1:
442 ts->ts_rate[1] = AR5K_REG_MS(tx_ctl->tx_control_3,
443 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
444
445 ts->ts_retry[0] = AR5K_REG_MS(tx_ctl->tx_control_2,
446 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
447 ts->ts_longretry += ts->ts_retry[0];
448 /* fall through */
449 case 0:
450 ts->ts_rate[0] = tx_ctl->tx_control_3 &
451 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300452 break;
453 }
454
455 /* TX error */
456 if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
457 if (tx_status->tx_status_0 &
458 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
459 ts->ts_status |= AR5K_TXERR_XRETRY;
460
461 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
462 ts->ts_status |= AR5K_TXERR_FIFO;
463
464 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
465 ts->ts_status |= AR5K_TXERR_FILT;
466 }
467
468 return 0;
469}
470
471/*
472 * RX Descriptors
473 */
474
475/*
476 * Initialize an rx control descriptor
477 */
Bruno Randolfa6668192010-06-16 19:12:01 +0900478int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
479 u32 size, unsigned int flags)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300480{
481 struct ath5k_hw_rx_ctl *rx_ctl;
482
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300483 rx_ctl = &desc->ud.ds_rx.rx_ctl;
484
485 /*
486 * Clear the descriptor
487 * If we don't clean the status descriptor,
488 * while scanning we get too many results,
489 * most of them virtual, after some secs
490 * of scanning system hangs. M.F.
491 */
492 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
493
494 /* Setup descriptor */
495 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
496 if (unlikely(rx_ctl->rx_control_1 != size))
497 return -EINVAL;
498
499 if (flags & AR5K_RXDESC_INTREQ)
500 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
501
502 return 0;
503}
504
505/*
506 * Proccess the rx status descriptor on 5210/5211
507 */
508static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
509 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
510{
511 struct ath5k_hw_rx_status *rx_status;
512
Bruno Randolf62412a82010-06-16 19:12:12 +0900513 rx_status = &desc->ud.ds_rx.rx_stat;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300514
515 /* No frame received / not ready */
516 if (unlikely(!(rx_status->rx_status_1 &
517 AR5K_5210_RX_DESC_STATUS1_DONE)))
518 return -EINPROGRESS;
519
520 /*
521 * Frame receive status
522 */
523 rs->rs_datalen = rx_status->rx_status_0 &
524 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
525 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
526 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
527 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
528 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
Bob Copelandc7930332008-11-03 22:14:00 -0500529 rs->rs_antenna = AR5K_REG_MS(rx_status->rx_status_0,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900530 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANT_5211);
Bob Copelandc7930332008-11-03 22:14:00 -0500531 rs->rs_more = !!(rx_status->rx_status_0 &
532 AR5K_5210_RX_DESC_STATUS0_MORE);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300533 /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
534 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
535 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
536 rs->rs_status = 0;
537 rs->rs_phyerr = 0;
538
539 /*
540 * Key table status
541 */
542 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
543 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
544 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
545 else
546 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
547
548 /*
549 * Receive/descriptor errors
550 */
551 if (!(rx_status->rx_status_1 &
552 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
553 if (rx_status->rx_status_1 &
554 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
555 rs->rs_status |= AR5K_RXERR_CRC;
556
557 if (rx_status->rx_status_1 &
Bruno Randolf03417bc2010-06-16 19:12:17 +0900558 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN_5210)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300559 rs->rs_status |= AR5K_RXERR_FIFO;
560
561 if (rx_status->rx_status_1 &
562 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
563 rs->rs_status |= AR5K_RXERR_PHY;
564 rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
565 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
566 }
567
568 if (rx_status->rx_status_1 &
569 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
570 rs->rs_status |= AR5K_RXERR_DECRYPT;
571 }
572
573 return 0;
574}
575
576/*
577 * Proccess the rx status descriptor on 5212
578 */
579static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
Bruno Randolf28471092010-06-16 19:12:07 +0900580 struct ath5k_desc *desc,
581 struct ath5k_rx_status *rs)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300582{
583 struct ath5k_hw_rx_status *rx_status;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300584
Bruno Randolf62412a82010-06-16 19:12:12 +0900585 rx_status = &desc->ud.ds_rx.rx_stat;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300586
587 /* No frame received / not ready */
588 if (unlikely(!(rx_status->rx_status_1 &
Bruno Randolf28471092010-06-16 19:12:07 +0900589 AR5K_5212_RX_DESC_STATUS1_DONE)))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300590 return -EINPROGRESS;
591
592 /*
593 * Frame receive status
594 */
595 rs->rs_datalen = rx_status->rx_status_0 &
596 AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
597 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
598 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
599 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
600 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
Bob Copelandc7930332008-11-03 22:14:00 -0500601 rs->rs_antenna = AR5K_REG_MS(rx_status->rx_status_0,
602 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA);
603 rs->rs_more = !!(rx_status->rx_status_0 &
604 AR5K_5212_RX_DESC_STATUS0_MORE);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300605 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
606 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
607 rs->rs_status = 0;
608 rs->rs_phyerr = 0;
609
610 /*
611 * Key table status
612 */
613 if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
614 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
Bruno Randolf28471092010-06-16 19:12:07 +0900615 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300616 else
617 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
618
619 /*
620 * Receive/descriptor errors
621 */
622 if (!(rx_status->rx_status_1 &
Bruno Randolf28471092010-06-16 19:12:07 +0900623 AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300624 if (rx_status->rx_status_1 &
625 AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
626 rs->rs_status |= AR5K_RXERR_CRC;
627
628 if (rx_status->rx_status_1 &
629 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
630 rs->rs_status |= AR5K_RXERR_PHY;
Bruno Randolf62412a82010-06-16 19:12:12 +0900631 rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
632 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR_CODE);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900633 ath5k_ani_phy_error_report(ah, rs->rs_phyerr);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300634 }
635
636 if (rx_status->rx_status_1 &
637 AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
638 rs->rs_status |= AR5K_RXERR_DECRYPT;
639
640 if (rx_status->rx_status_1 &
641 AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
642 rs->rs_status |= AR5K_RXERR_MIC;
643 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300644 return 0;
645}
646
647/*
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}