blob: 77a60777909f6b228e8126aecba73b6a99a9f68a [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
Joe Perches516304b2012-03-18 17:30:52 -070024#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030026#include "ath5k.h"
27#include "reg.h"
28#include "debug.h"
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030029
Nick Kossifidis9320b5c42010-11-23 20:36:45 +020030
Nick Kossifidisc47faa32011-11-25 20:40:25 +020031/**
32 * DOC: Hardware descriptor functions
33 *
34 * Here we handle the processing of the low-level hw descriptors
35 * that hw reads and writes via DMA for each TX and RX attempt (that means
36 * we can also have descriptors for failed TX/RX tries). We have two kind of
37 * descriptors for RX and TX, control descriptors tell the hw how to send or
38 * receive a packet where to read/write it from/to etc and status descriptors
39 * that contain information about how the packet was sent or received (errors
40 * included).
41 *
42 * Descriptor format is not exactly the same for each MAC chip version so we
43 * have function pointers on &struct ath5k_hw we initialize at runtime based on
44 * the chip used.
45 */
46
47
Nick Kossifidis9320b5c42010-11-23 20:36:45 +020048/************************\
49* TX Control descriptors *
50\************************/
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030051
Nick Kossifidisc47faa32011-11-25 20:40:25 +020052/**
53 * ath5k_hw_setup_2word_tx_desc() - Initialize a 2-word tx control descriptor
54 * @ah: The &struct ath5k_hw
55 * @desc: The &struct ath5k_desc
56 * @pkt_len: Frame length in bytes
57 * @hdr_len: Header length in bytes (only used on AR5210)
58 * @padsize: Any padding we've added to the frame length
59 * @type: One of enum ath5k_pkt_type
60 * @tx_power: Tx power in 0.5dB steps
61 * @tx_rate0: HW idx for transmission rate
62 * @tx_tries0: Max number of retransmissions
63 * @key_index: Index on key table to use for encryption
64 * @antenna_mode: Which antenna to use (0 for auto)
65 * @flags: One of AR5K_TXDESC_* flags (desc.h)
66 * @rtscts_rate: HW idx for RTS/CTS transmission rate
67 * @rtscts_duration: What to put on duration field on the header of RTS/CTS
68 *
69 * Internal function to initialize a 2-Word TX control descriptor
70 * found on AR5210 and AR5211 MACs chips.
71 *
72 * Returns 0 on success or -EINVAL on false input
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030073 */
74static int
Nick Kossifidisc47faa32011-11-25 20:40:25 +020075ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah,
76 struct ath5k_desc *desc,
77 unsigned int pkt_len, unsigned int hdr_len,
78 int padsize,
79 enum ath5k_pkt_type type,
80 unsigned int tx_power,
81 unsigned int tx_rate0, unsigned int tx_tries0,
82 unsigned int key_index,
83 unsigned int antenna_mode,
84 unsigned int flags,
85 unsigned int rtscts_rate, unsigned int rtscts_duration)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030086{
87 u32 frame_type;
88 struct ath5k_hw_2w_tx_ctl *tx_ctl;
89 unsigned int frame_len;
90
91 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
92
93 /*
94 * Validate input
95 * - Zero retries don't make sense.
Lucas De Marchi25985ed2011-03-30 22:57:33 -030096 * - A zero rate will put the HW into a mode where it continuously sends
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030097 * noise on the channel, so it is important to avoid this.
98 */
99 if (unlikely(tx_tries0 == 0)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400100 ATH5K_ERR(ah, "zero retries\n");
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300101 WARN_ON(1);
102 return -EINVAL;
103 }
104 if (unlikely(tx_rate0 == 0)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400105 ATH5K_ERR(ah, "zero rate\n");
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300106 WARN_ON(1);
107 return -EINVAL;
108 }
109
110 /* Clear descriptor */
111 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
112
113 /* Setup control descriptor */
114
115 /* Verify and set frame length */
116
117 /* remove padding we might have added before */
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100118 frame_len = pkt_len - padsize + FCS_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300119
120 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
121 return -EINVAL;
122
123 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
124
125 /* Verify and set buffer length */
126
127 /* NB: beacon's BufLen must be a multiple of 4 bytes */
128 if (type == AR5K_PKT_TYPE_BEACON)
129 pkt_len = roundup(pkt_len, 4);
130
131 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
132 return -EINVAL;
133
134 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
135
136 /*
Bruno Randolf1884a362010-06-16 19:12:28 +0900137 * Verify and set header length (only 5210)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300138 */
139 if (ah->ah_version == AR5K_AR5210) {
Bruno Randolf03417bc2010-06-16 19:12:17 +0900140 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300141 return -EINVAL;
142 tx_ctl->tx_control_0 |=
Bruno Randolf03417bc2010-06-16 19:12:17 +0900143 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300144 }
145
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100146 /*Differences between 5210-5211*/
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300147 if (ah->ah_version == AR5K_AR5210) {
148 switch (type) {
149 case AR5K_PKT_TYPE_BEACON:
150 case AR5K_PKT_TYPE_PROBE_RESP:
151 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
Joe Perches3ffca4f2011-07-10 02:28:26 -0700152 break;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300153 case AR5K_PKT_TYPE_PIFS:
154 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
Joe Perches3ffca4f2011-07-10 02:28:26 -0700155 break;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300156 default:
Bruno Randolf2237e922010-06-16 19:12:22 +0900157 frame_type = type;
Joe Perches3ffca4f2011-07-10 02:28:26 -0700158 break;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300159 }
160
161 tx_ctl->tx_control_0 |=
Bruno Randolf03417bc2010-06-16 19:12:17 +0900162 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE_5210) |
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300163 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
164
165 } else {
166 tx_ctl->tx_control_0 |=
167 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
168 AR5K_REG_SM(antenna_mode,
169 AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
170 tx_ctl->tx_control_1 |=
Bruno Randolf03417bc2010-06-16 19:12:17 +0900171 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE_5211);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300172 }
Bruno Randolf1884a362010-06-16 19:12:28 +0900173
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300174#define _TX_FLAGS(_c, _flag) \
175 if (flags & AR5K_TXDESC_##_flag) { \
176 tx_ctl->tx_control_##_c |= \
177 AR5K_2W_TX_DESC_CTL##_c##_##_flag; \
178 }
Bruno Randolf1884a362010-06-16 19:12:28 +0900179#define _TX_FLAGS_5211(_c, _flag) \
180 if (flags & AR5K_TXDESC_##_flag) { \
181 tx_ctl->tx_control_##_c |= \
182 AR5K_2W_TX_DESC_CTL##_c##_##_flag##_5211; \
183 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300184 _TX_FLAGS(0, CLRDMASK);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300185 _TX_FLAGS(0, INTREQ);
186 _TX_FLAGS(0, RTSENA);
Bruno Randolf1884a362010-06-16 19:12:28 +0900187
188 if (ah->ah_version == AR5K_AR5211) {
189 _TX_FLAGS_5211(0, VEOL);
190 _TX_FLAGS_5211(1, NOACK);
191 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300192
193#undef _TX_FLAGS
Bruno Randolf1884a362010-06-16 19:12:28 +0900194#undef _TX_FLAGS_5211
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300195
196 /*
197 * WEP crap
198 */
199 if (key_index != AR5K_TXKEYIX_INVALID) {
200 tx_ctl->tx_control_0 |=
201 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
202 tx_ctl->tx_control_1 |=
203 AR5K_REG_SM(key_index,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900204 AR5K_2W_TX_DESC_CTL1_ENC_KEY_IDX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300205 }
206
207 /*
208 * RTS/CTS Duration [5210 ?]
209 */
210 if ((ah->ah_version == AR5K_AR5210) &&
211 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
212 tx_ctl->tx_control_1 |= rtscts_duration &
Bruno Randolf03417bc2010-06-16 19:12:17 +0900213 AR5K_2W_TX_DESC_CTL1_RTS_DURATION_5210;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300214
215 return 0;
216}
217
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200218/**
219 * ath5k_hw_setup_4word_tx_desc() - Initialize a 4-word tx control descriptor
220 * @ah: The &struct ath5k_hw
221 * @desc: The &struct ath5k_desc
222 * @pkt_len: Frame length in bytes
223 * @hdr_len: Header length in bytes (only used on AR5210)
224 * @padsize: Any padding we've added to the frame length
225 * @type: One of enum ath5k_pkt_type
226 * @tx_power: Tx power in 0.5dB steps
227 * @tx_rate0: HW idx for transmission rate
228 * @tx_tries0: Max number of retransmissions
229 * @key_index: Index on key table to use for encryption
230 * @antenna_mode: Which antenna to use (0 for auto)
231 * @flags: One of AR5K_TXDESC_* flags (desc.h)
232 * @rtscts_rate: HW idx for RTS/CTS transmission rate
233 * @rtscts_duration: What to put on duration field on the header of RTS/CTS
234 *
235 * Internal function to initialize a 4-Word TX control descriptor
236 * found on AR5212 and later MACs chips.
237 *
238 * Returns 0 on success or -EINVAL on false input
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300239 */
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200240static int
241ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
242 struct ath5k_desc *desc,
243 unsigned int pkt_len, unsigned int hdr_len,
244 int padsize,
245 enum ath5k_pkt_type type,
246 unsigned int tx_power,
247 unsigned int tx_rate0, unsigned int tx_tries0,
248 unsigned int key_index,
249 unsigned int antenna_mode,
250 unsigned int flags,
251 unsigned int rtscts_rate, unsigned int rtscts_duration)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300252{
253 struct ath5k_hw_4w_tx_ctl *tx_ctl;
254 unsigned int frame_len;
255
John W. Linville8962d872011-04-13 08:47:32 -0400256 /*
257 * Use local variables for these to reduce load/store access on
258 * uncached memory
259 */
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200260 u32 txctl0 = 0, txctl1 = 0, txctl2 = 0, txctl3 = 0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300261
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300262 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
263
264 /*
265 * Validate input
266 * - Zero retries don't make sense.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300267 * - A zero rate will put the HW into a mode where it continuously sends
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300268 * noise on the channel, so it is important to avoid this.
269 */
270 if (unlikely(tx_tries0 == 0)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400271 ATH5K_ERR(ah, "zero retries\n");
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300272 WARN_ON(1);
273 return -EINVAL;
274 }
275 if (unlikely(tx_rate0 == 0)) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400276 ATH5K_ERR(ah, "zero rate\n");
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300277 WARN_ON(1);
278 return -EINVAL;
279 }
280
Nick Kossifidis8f655dd2009-03-15 22:20:35 +0200281 tx_power += ah->ah_txpower.txp_offset;
282 if (tx_power > AR5K_TUNE_MAX_TXPOWER)
283 tx_power = AR5K_TUNE_MAX_TXPOWER;
284
John W. Linville8962d872011-04-13 08:47:32 -0400285 /* Clear descriptor status area */
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200286 memset(&desc->ud.ds_tx5212.tx_stat, 0,
287 sizeof(desc->ud.ds_tx5212.tx_stat));
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300288
289 /* Setup control descriptor */
290
291 /* Verify and set frame length */
292
293 /* remove padding we might have added before */
Benoit Papillault8127fbd2010-02-27 23:05:26 +0100294 frame_len = pkt_len - padsize + FCS_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300295
296 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
297 return -EINVAL;
298
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200299 txctl0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300300
301 /* Verify and set buffer length */
302
303 /* NB: beacon's BufLen must be a multiple of 4 bytes */
304 if (type == AR5K_PKT_TYPE_BEACON)
305 pkt_len = roundup(pkt_len, 4);
306
307 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
308 return -EINVAL;
309
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200310 txctl1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300311
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200312 txctl0 |= AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
313 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
314 txctl1 |= AR5K_REG_SM(type, AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
315 txctl2 = AR5K_REG_SM(tx_tries0, AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
316 txctl3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300317
318#define _TX_FLAGS(_c, _flag) \
319 if (flags & AR5K_TXDESC_##_flag) { \
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200320 txctl##_c |= AR5K_4W_TX_DESC_CTL##_c##_##_flag; \
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300321 }
322
323 _TX_FLAGS(0, CLRDMASK);
324 _TX_FLAGS(0, VEOL);
325 _TX_FLAGS(0, INTREQ);
326 _TX_FLAGS(0, RTSENA);
327 _TX_FLAGS(0, CTSENA);
328 _TX_FLAGS(1, NOACK);
329
330#undef _TX_FLAGS
331
332 /*
333 * WEP crap
334 */
335 if (key_index != AR5K_TXKEYIX_INVALID) {
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200336 txctl0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
337 txctl1 |= AR5K_REG_SM(key_index,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900338 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_IDX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300339 }
340
341 /*
342 * RTS/CTS
343 */
344 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
345 if ((flags & AR5K_TXDESC_RTSENA) &&
346 (flags & AR5K_TXDESC_CTSENA))
347 return -EINVAL;
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200348 txctl2 |= rtscts_duration & AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
349 txctl3 |= AR5K_REG_SM(rtscts_rate,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300350 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
351 }
352
Felix Fietkauc5e0a882011-04-10 18:32:13 +0200353 tx_ctl->tx_control_0 = txctl0;
354 tx_ctl->tx_control_1 = txctl1;
355 tx_ctl->tx_control_2 = txctl2;
356 tx_ctl->tx_control_3 = txctl3;
357
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300358 return 0;
359}
360
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200361/**
362 * ath5k_hw_setup_mrr_tx_desc() - Initialize an MRR tx control descriptor
363 * @ah: The &struct ath5k_hw
364 * @desc: The &struct ath5k_desc
365 * @tx_rate1: HW idx for rate used on transmission series 1
366 * @tx_tries1: Max number of retransmissions for transmission series 1
367 * @tx_rate2: HW idx for rate used on transmission series 2
368 * @tx_tries2: Max number of retransmissions for transmission series 2
369 * @tx_rate3: HW idx for rate used on transmission series 3
370 * @tx_tries3: Max number of retransmissions for transmission series 3
371 *
372 * Multi rate retry (MRR) tx control descriptors are available only on AR5212
373 * MACs, they are part of the normal 4-word tx control descriptor (see above)
374 * but we handle them through a separate function for better abstraction.
375 *
376 * Returns 0 on success or -EINVAL on invalid input
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300377 */
Bruno Randolfa6668192010-06-16 19:12:01 +0900378int
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200379ath5k_hw_setup_mrr_tx_desc(struct ath5k_hw *ah,
380 struct ath5k_desc *desc,
381 u_int tx_rate1, u_int tx_tries1,
382 u_int tx_rate2, u_int tx_tries2,
383 u_int tx_rate3, u_int tx_tries3)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300384{
385 struct ath5k_hw_4w_tx_ctl *tx_ctl;
386
Bruno Randolfa6668192010-06-16 19:12:01 +0900387 /* no mrr support for cards older than 5212 */
388 if (ah->ah_version < AR5K_AR5212)
389 return 0;
390
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300391 /*
392 * Rates can be 0 as long as the retry count is 0 too.
393 * A zero rate and nonzero retry count will put the HW into a mode where
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300394 * it continuously sends noise on the channel, so it is important to
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300395 * avoid this.
396 */
397 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
398 (tx_rate2 == 0 && tx_tries2 != 0) ||
399 (tx_rate3 == 0 && tx_tries3 != 0))) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400400 ATH5K_ERR(ah, "zero rate\n");
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300401 WARN_ON(1);
402 return -EINVAL;
403 }
404
405 if (ah->ah_version == AR5K_AR5212) {
406 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
407
408#define _XTX_TRIES(_n) \
409 if (tx_tries##_n) { \
410 tx_ctl->tx_control_2 |= \
411 AR5K_REG_SM(tx_tries##_n, \
412 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
413 tx_ctl->tx_control_3 |= \
414 AR5K_REG_SM(tx_rate##_n, \
415 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
416 }
417
418 _XTX_TRIES(1);
419 _XTX_TRIES(2);
420 _XTX_TRIES(3);
421
422#undef _XTX_TRIES
423
424 return 1;
425 }
426
427 return 0;
428}
429
Nick Kossifidis9320b5c42010-11-23 20:36:45 +0200430
431/***********************\
432* TX Status descriptors *
433\***********************/
434
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200435/**
436 * ath5k_hw_proc_2word_tx_status() - Process a tx status descriptor on 5210/1
437 * @ah: The &struct ath5k_hw
438 * @desc: The &struct ath5k_desc
439 * @ts: The &struct ath5k_tx_status
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300440 */
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200441static int
442ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
443 struct ath5k_desc *desc,
444 struct ath5k_tx_status *ts)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300445{
446 struct ath5k_hw_2w_tx_ctl *tx_ctl;
447 struct ath5k_hw_tx_status *tx_status;
448
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300449 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
450 tx_status = &desc->ud.ds_tx5210.tx_stat;
451
452 /* No frame has been send or error */
453 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
454 return -EINPROGRESS;
455
456 /*
457 * Get descriptor status
458 */
459 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
460 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
461 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
462 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Felix Fietkaued895082011-04-10 18:32:17 +0200463 ts->ts_final_retry = AR5K_REG_MS(tx_status->tx_status_0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300464 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
465 /*TODO: ts->ts_virtcol + test*/
466 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
467 AR5K_DESC_TX_STATUS1_SEQ_NUM);
468 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
469 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
470 ts->ts_antenna = 1;
471 ts->ts_status = 0;
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200472 ts->ts_final_idx = 0;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300473
474 if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
475 if (tx_status->tx_status_0 &
476 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
477 ts->ts_status |= AR5K_TXERR_XRETRY;
478
479 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
480 ts->ts_status |= AR5K_TXERR_FIFO;
481
482 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
483 ts->ts_status |= AR5K_TXERR_FILT;
484 }
485
486 return 0;
487}
488
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200489/**
490 * ath5k_hw_proc_4word_tx_status() - Process a tx status descriptor on 5212
491 * @ah: The &struct ath5k_hw
492 * @desc: The &struct ath5k_desc
493 * @ts: The &struct ath5k_tx_status
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300494 */
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200495static int
496ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
497 struct ath5k_desc *desc,
498 struct ath5k_tx_status *ts)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300499{
500 struct ath5k_hw_4w_tx_ctl *tx_ctl;
501 struct ath5k_hw_tx_status *tx_status;
Felix Fietkaued895082011-04-10 18:32:17 +0200502 u32 txstat0, txstat1;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300503
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300504 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
505 tx_status = &desc->ud.ds_tx5212.tx_stat;
506
Felix Fietkaub161b892011-04-10 18:32:15 +0200507 txstat1 = ACCESS_ONCE(tx_status->tx_status_1);
508
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300509 /* No frame has been send or error */
Felix Fietkaub161b892011-04-10 18:32:15 +0200510 if (unlikely(!(txstat1 & AR5K_DESC_TX_STATUS1_DONE)))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300511 return -EINPROGRESS;
512
Felix Fietkaub161b892011-04-10 18:32:15 +0200513 txstat0 = ACCESS_ONCE(tx_status->tx_status_0);
Felix Fietkaub161b892011-04-10 18:32:15 +0200514
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300515 /*
516 * Get descriptor status
517 */
Felix Fietkaub161b892011-04-10 18:32:15 +0200518 ts->ts_tstamp = AR5K_REG_MS(txstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300519 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
Felix Fietkaub161b892011-04-10 18:32:15 +0200520 ts->ts_shortretry = AR5K_REG_MS(txstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300521 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
Felix Fietkaued895082011-04-10 18:32:17 +0200522 ts->ts_final_retry = AR5K_REG_MS(txstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300523 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
Felix Fietkaub161b892011-04-10 18:32:15 +0200524 ts->ts_seqnum = AR5K_REG_MS(txstat1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300525 AR5K_DESC_TX_STATUS1_SEQ_NUM);
Felix Fietkaub161b892011-04-10 18:32:15 +0200526 ts->ts_rssi = AR5K_REG_MS(txstat1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300527 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
Felix Fietkaub161b892011-04-10 18:32:15 +0200528 ts->ts_antenna = (txstat1 &
Bruno Randolf03417bc2010-06-16 19:12:17 +0900529 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA_5212) ? 2 : 1;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300530 ts->ts_status = 0;
531
Felix Fietkaub161b892011-04-10 18:32:15 +0200532 ts->ts_final_idx = AR5K_REG_MS(txstat1,
Bruno Randolf03417bc2010-06-16 19:12:17 +0900533 AR5K_DESC_TX_STATUS1_FINAL_TS_IX_5212);
Felix Fietkau2f7fe872008-10-05 18:05:48 +0200534
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300535 /* TX error */
Felix Fietkaub161b892011-04-10 18:32:15 +0200536 if (!(txstat0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
537 if (txstat0 & AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300538 ts->ts_status |= AR5K_TXERR_XRETRY;
539
Felix Fietkaub161b892011-04-10 18:32:15 +0200540 if (txstat0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300541 ts->ts_status |= AR5K_TXERR_FIFO;
542
Felix Fietkaub161b892011-04-10 18:32:15 +0200543 if (txstat0 & AR5K_DESC_TX_STATUS0_FILTERED)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300544 ts->ts_status |= AR5K_TXERR_FILT;
545 }
546
547 return 0;
548}
549
Nick Kossifidis9320b5c42010-11-23 20:36:45 +0200550
551/****************\
552* RX Descriptors *
553\****************/
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300554
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200555/**
556 * ath5k_hw_setup_rx_desc() - Initialize an rx control descriptor
557 * @ah: The &struct ath5k_hw
558 * @desc: The &struct ath5k_desc
559 * @size: RX buffer length in bytes
560 * @flags: One of AR5K_RXDESC_* flags
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300561 */
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200562int
563ath5k_hw_setup_rx_desc(struct ath5k_hw *ah,
564 struct ath5k_desc *desc,
565 u32 size, unsigned int flags)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300566{
567 struct ath5k_hw_rx_ctl *rx_ctl;
568
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300569 rx_ctl = &desc->ud.ds_rx.rx_ctl;
570
571 /*
572 * Clear the descriptor
573 * If we don't clean the status descriptor,
574 * while scanning we get too many results,
575 * most of them virtual, after some secs
576 * of scanning system hangs. M.F.
577 */
578 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
579
Bruno Randolf87861232010-06-16 19:12:34 +0900580 if (unlikely(size & ~AR5K_DESC_RX_CTL1_BUF_LEN))
581 return -EINVAL;
582
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300583 /* Setup descriptor */
584 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300585
586 if (flags & AR5K_RXDESC_INTREQ)
587 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
588
589 return 0;
590}
591
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200592/**
593 * ath5k_hw_proc_5210_rx_status() - Process the rx status descriptor on 5210/1
594 * @ah: The &struct ath5k_hw
595 * @desc: The &struct ath5k_desc
596 * @rs: The &struct ath5k_rx_status
597 *
598 * Internal function used to process an RX status descriptor
599 * on AR5210/5211 MAC.
600 *
601 * Returns 0 on success or -EINPROGRESS in case we haven't received the who;e
602 * frame yet.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300603 */
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200604static int
605ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
606 struct ath5k_desc *desc,
607 struct ath5k_rx_status *rs)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300608{
609 struct ath5k_hw_rx_status *rx_status;
610
Bruno Randolf62412a82010-06-16 19:12:12 +0900611 rx_status = &desc->ud.ds_rx.rx_stat;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300612
613 /* No frame received / not ready */
614 if (unlikely(!(rx_status->rx_status_1 &
Bruno Randolf87861232010-06-16 19:12:34 +0900615 AR5K_5210_RX_DESC_STATUS1_DONE)))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300616 return -EINPROGRESS;
617
Bruno Randolf87861232010-06-16 19:12:34 +0900618 memset(rs, 0, sizeof(struct ath5k_rx_status));
619
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300620 /*
621 * Frame receive status
622 */
623 rs->rs_datalen = rx_status->rx_status_0 &
624 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
625 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
626 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
627 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
628 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
Bob Copelandc7930332008-11-03 22:14:00 -0500629 rs->rs_more = !!(rx_status->rx_status_0 &
630 AR5K_5210_RX_DESC_STATUS0_MORE);
Bruno Randolf87861232010-06-16 19:12:34 +0900631 /* TODO: this timestamp is 13 bit, later on we assume 15 bit!
632 * also the HAL code for 5210 says the timestamp is bits [10..22] of the
633 * TSF, and extends the timestamp here to 15 bit.
634 * we need to check on 5210...
635 */
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300636 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
637 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Bruno Randolf1884a362010-06-16 19:12:28 +0900638
639 if (ah->ah_version == AR5K_AR5211)
640 rs->rs_antenna = AR5K_REG_MS(rx_status->rx_status_0,
641 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANT_5211);
642 else
643 rs->rs_antenna = (rx_status->rx_status_0 &
644 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANT_5210)
645 ? 2 : 1;
646
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300647 /*
648 * Key table status
649 */
650 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
651 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
652 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
653 else
654 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
655
656 /*
657 * Receive/descriptor errors
658 */
659 if (!(rx_status->rx_status_1 &
Bruno Randolf87861232010-06-16 19:12:34 +0900660 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300661 if (rx_status->rx_status_1 &
662 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
663 rs->rs_status |= AR5K_RXERR_CRC;
664
Bruno Randolf87861232010-06-16 19:12:34 +0900665 /* only on 5210 */
666 if ((ah->ah_version == AR5K_AR5210) &&
667 (rx_status->rx_status_1 &
668 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN_5210))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300669 rs->rs_status |= AR5K_RXERR_FIFO;
670
671 if (rx_status->rx_status_1 &
672 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
673 rs->rs_status |= AR5K_RXERR_PHY;
Bruno Randolf87861232010-06-16 19:12:34 +0900674 rs->rs_phyerr = AR5K_REG_MS(rx_status->rx_status_1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300675 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
676 }
677
678 if (rx_status->rx_status_1 &
679 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
680 rs->rs_status |= AR5K_RXERR_DECRYPT;
681 }
682
683 return 0;
684}
685
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200686/**
687 * ath5k_hw_proc_5212_rx_status() - Process the rx status descriptor on 5212
688 * @ah: The &struct ath5k_hw
689 * @desc: The &struct ath5k_desc
690 * @rs: The &struct ath5k_rx_status
691 *
692 * Internal function used to process an RX status descriptor
693 * on AR5212 and later MAC.
694 *
695 * Returns 0 on success or -EINPROGRESS in case we haven't received the who;e
696 * frame yet.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300697 */
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200698static int
699ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
700 struct ath5k_desc *desc,
701 struct ath5k_rx_status *rs)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300702{
703 struct ath5k_hw_rx_status *rx_status;
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200704 u32 rxstat0, rxstat1;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300705
Bruno Randolf62412a82010-06-16 19:12:12 +0900706 rx_status = &desc->ud.ds_rx.rx_stat;
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200707 rxstat1 = ACCESS_ONCE(rx_status->rx_status_1);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300708
709 /* No frame received / not ready */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200710 if (unlikely(!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_DONE)))
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300711 return -EINPROGRESS;
712
Bruno Randolf87861232010-06-16 19:12:34 +0900713 memset(rs, 0, sizeof(struct ath5k_rx_status));
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200714 rxstat0 = ACCESS_ONCE(rx_status->rx_status_0);
Bruno Randolf87861232010-06-16 19:12:34 +0900715
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300716 /*
717 * Frame receive status
718 */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200719 rs->rs_datalen = rxstat0 & AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
720 rs->rs_rssi = AR5K_REG_MS(rxstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300721 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200722 rs->rs_rate = AR5K_REG_MS(rxstat0,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300723 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200724 rs->rs_antenna = AR5K_REG_MS(rxstat0,
Bob Copelandc7930332008-11-03 22:14:00 -0500725 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA);
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200726 rs->rs_more = !!(rxstat0 & AR5K_5212_RX_DESC_STATUS0_MORE);
727 rs->rs_tstamp = AR5K_REG_MS(rxstat1,
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300728 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300729
730 /*
731 * Key table status
732 */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200733 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
734 rs->rs_keyix = AR5K_REG_MS(rxstat1,
Bruno Randolf28471092010-06-16 19:12:07 +0900735 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300736 else
737 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
738
739 /*
740 * Receive/descriptor errors
741 */
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200742 if (!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
743 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300744 rs->rs_status |= AR5K_RXERR_CRC;
745
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200746 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300747 rs->rs_status |= AR5K_RXERR_PHY;
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200748 rs->rs_phyerr = AR5K_REG_MS(rxstat1,
Bruno Randolf62412a82010-06-16 19:12:12 +0900749 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR_CODE);
Bruno Randolf6a0076e2010-06-16 19:12:39 +0900750 if (!ah->ah_capabilities.cap_has_phyerr_counters)
751 ath5k_ani_phy_error_report(ah, rs->rs_phyerr);
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300752 }
753
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200754 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300755 rs->rs_status |= AR5K_RXERR_DECRYPT;
756
Felix Fietkaub2fd97d2011-04-10 18:32:16 +0200757 if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300758 rs->rs_status |= AR5K_RXERR_MIC;
759 }
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300760 return 0;
761}
762
Nick Kossifidis9320b5c42010-11-23 20:36:45 +0200763
764/********\
765* Attach *
766\********/
767
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200768/**
769 * ath5k_hw_init_desc_functions() - Init function pointers inside ah
770 * @ah: The &struct ath5k_hw
771 *
772 * Maps the internal descriptor functions to the function pointers on ah, used
773 * from above. This is used as an abstraction layer to handle the various chips
774 * the same way.
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300775 */
Nick Kossifidisc47faa32011-11-25 20:40:25 +0200776int
777ath5k_hw_init_desc_functions(struct ath5k_hw *ah)
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300778{
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300779 if (ah->ah_version == AR5K_AR5212) {
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300780 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300781 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300782 ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
Bruno Randolfa6668192010-06-16 19:12:01 +0900783 } else if (ah->ah_version <= AR5K_AR5211) {
784 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
785 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300786 ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
Bruno Randolfa6668192010-06-16 19:12:01 +0900787 } else
788 return -ENOTSUPP;
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300789 return 0;
790}