Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 1 | /* |
| 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 Kossifidis | 9320b5c | 2010-11-23 20:36:45 +0200 | [diff] [blame] | 29 | |
| 30 | /************************\ |
| 31 | * TX Control descriptors * |
| 32 | \************************/ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * Initialize the 2-word tx control descriptor on 5210/5211 |
| 36 | */ |
| 37 | static int |
| 38 | ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc, |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 39 | unsigned int pkt_len, unsigned int hdr_len, int padsize, |
| 40 | enum ath5k_pkt_type type, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 41 | 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 Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 54 | * - A zero rate will put the HW into a mode where it continuously sends |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 55 | * 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 Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 76 | frame_len = pkt_len - padsize + FCS_LEN; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 77 | |
| 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 Randolf | 1884a36 | 2010-06-16 19:12:28 +0900 | [diff] [blame] | 95 | * Verify and set header length (only 5210) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 96 | */ |
| 97 | if (ah->ah_version == AR5K_AR5210) { |
Bruno Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 98 | if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 99 | return -EINVAL; |
| 100 | tx_ctl->tx_control_0 |= |
Bruno Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 101 | AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 102 | } |
| 103 | |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 104 | /*Differences between 5210-5211*/ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 105 | 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 Randolf | 2237e92 | 2010-06-16 19:12:22 +0900 | [diff] [blame] | 113 | frame_type = type; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | tx_ctl->tx_control_0 |= |
Bruno Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 117 | AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE_5210) | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 118 | 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 Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 126 | AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE_5211); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 127 | } |
Bruno Randolf | 1884a36 | 2010-06-16 19:12:28 +0900 | [diff] [blame] | 128 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 129 | #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 Randolf | 1884a36 | 2010-06-16 19:12:28 +0900 | [diff] [blame] | 134 | #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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 139 | _TX_FLAGS(0, CLRDMASK); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 140 | _TX_FLAGS(0, INTREQ); |
| 141 | _TX_FLAGS(0, RTSENA); |
Bruno Randolf | 1884a36 | 2010-06-16 19:12:28 +0900 | [diff] [blame] | 142 | |
| 143 | if (ah->ah_version == AR5K_AR5211) { |
| 144 | _TX_FLAGS_5211(0, VEOL); |
| 145 | _TX_FLAGS_5211(1, NOACK); |
| 146 | } |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 147 | |
| 148 | #undef _TX_FLAGS |
Bruno Randolf | 1884a36 | 2010-06-16 19:12:28 +0900 | [diff] [blame] | 149 | #undef _TX_FLAGS_5211 |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 150 | |
| 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 Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 159 | AR5K_2W_TX_DESC_CTL1_ENC_KEY_IDX); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 160 | } |
| 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 Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 168 | AR5K_2W_TX_DESC_CTL1_RTS_DURATION_5210; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Initialize the 4-word tx control descriptor on 5212 |
| 175 | */ |
| 176 | static 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 Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 178 | int padsize, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 179 | 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. Linville | 8962d87 | 2011-04-13 08:47:32 -0400 | [diff] [blame] | 188 | /* |
| 189 | * Use local variables for these to reduce load/store access on |
| 190 | * uncached memory |
| 191 | */ |
Felix Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 192 | u32 txctl0 = 0, txctl1 = 0, txctl2 = 0, txctl3 = 0; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 193 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 194 | tx_ctl = &desc->ud.ds_tx5212.tx_ctl; |
| 195 | |
| 196 | /* |
| 197 | * Validate input |
| 198 | * - Zero retries don't make sense. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 199 | * - A zero rate will put the HW into a mode where it continuously sends |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 200 | * 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 Kossifidis | 8f655dd | 2009-03-15 22:20:35 +0200 | [diff] [blame] | 213 | 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. Linville | 8962d87 | 2011-04-13 08:47:32 -0400 | [diff] [blame] | 217 | /* Clear descriptor status area */ |
Felix Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 218 | memset(&desc->ud.ds_tx5212.tx_stat, 0, |
| 219 | sizeof(desc->ud.ds_tx5212.tx_stat)); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 220 | |
| 221 | /* Setup control descriptor */ |
| 222 | |
| 223 | /* Verify and set frame length */ |
| 224 | |
| 225 | /* remove padding we might have added before */ |
Benoit Papillault | 8127fbd | 2010-02-27 23:05:26 +0100 | [diff] [blame] | 226 | frame_len = pkt_len - padsize + FCS_LEN; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 227 | |
| 228 | if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN) |
| 229 | return -EINVAL; |
| 230 | |
Felix Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 231 | txctl0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 232 | |
| 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 Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 242 | txctl1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 243 | |
Felix Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 244 | 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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 249 | |
| 250 | #define _TX_FLAGS(_c, _flag) \ |
| 251 | if (flags & AR5K_TXDESC_##_flag) { \ |
Felix Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 252 | txctl##_c |= AR5K_4W_TX_DESC_CTL##_c##_##_flag; \ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 253 | } |
| 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 Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 268 | txctl0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID; |
| 269 | txctl1 |= AR5K_REG_SM(key_index, |
Bruno Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 270 | AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_IDX); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 271 | } |
| 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 Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 280 | txctl2 |= rtscts_duration & AR5K_4W_TX_DESC_CTL2_RTS_DURATION; |
| 281 | txctl3 |= AR5K_REG_SM(rtscts_rate, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 282 | AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE); |
| 283 | } |
| 284 | |
Felix Fietkau | c5e0a88 | 2011-04-10 18:32:13 +0200 | [diff] [blame] | 285 | 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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * Initialize a 4-word multi rate retry tx control descriptor on 5212 |
| 295 | */ |
Bruno Randolf | a666819 | 2010-06-16 19:12:01 +0900 | [diff] [blame] | 296 | int |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 297 | ath5k_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 Randolf | a666819 | 2010-06-16 19:12:01 +0900 | [diff] [blame] | 303 | /* no mrr support for cards older than 5212 */ |
| 304 | if (ah->ah_version < AR5K_AR5212) |
| 305 | return 0; |
| 306 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 307 | /* |
| 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 Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 310 | * it continuously sends noise on the channel, so it is important to |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 311 | * 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 Kossifidis | 9320b5c | 2010-11-23 20:36:45 +0200 | [diff] [blame] | 346 | |
| 347 | /***********************\ |
| 348 | * TX Status descriptors * |
| 349 | \***********************/ |
| 350 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 351 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 352 | * Process the tx status descriptor on 5210/5211 |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 353 | */ |
| 354 | static 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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 360 | 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 Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 374 | ts->ts_final_retry = AR5K_REG_MS(tx_status->tx_status_0, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 375 | 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 Fietkau | 2f7fe87 | 2008-10-05 18:05:48 +0200 | [diff] [blame] | 383 | ts->ts_final_idx = 0; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 384 | |
| 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 Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 401 | * Process a tx status descriptor on 5212 |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 402 | */ |
| 403 | static 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 Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 408 | u32 txstat0, txstat1; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 409 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 410 | tx_ctl = &desc->ud.ds_tx5212.tx_ctl; |
| 411 | tx_status = &desc->ud.ds_tx5212.tx_stat; |
| 412 | |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 413 | txstat1 = ACCESS_ONCE(tx_status->tx_status_1); |
| 414 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 415 | /* No frame has been send or error */ |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 416 | if (unlikely(!(txstat1 & AR5K_DESC_TX_STATUS1_DONE))) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 417 | return -EINPROGRESS; |
| 418 | |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 419 | txstat0 = ACCESS_ONCE(tx_status->tx_status_0); |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 420 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 421 | /* |
| 422 | * Get descriptor status |
| 423 | */ |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 424 | ts->ts_tstamp = AR5K_REG_MS(txstat0, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 425 | AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP); |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 426 | ts->ts_shortretry = AR5K_REG_MS(txstat0, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 427 | AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT); |
Felix Fietkau | ed89508 | 2011-04-10 18:32:17 +0200 | [diff] [blame] | 428 | ts->ts_final_retry = AR5K_REG_MS(txstat0, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 429 | AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT); |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 430 | ts->ts_seqnum = AR5K_REG_MS(txstat1, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 431 | AR5K_DESC_TX_STATUS1_SEQ_NUM); |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 432 | ts->ts_rssi = AR5K_REG_MS(txstat1, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 433 | AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH); |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 434 | ts->ts_antenna = (txstat1 & |
Bruno Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 435 | AR5K_DESC_TX_STATUS1_XMIT_ANTENNA_5212) ? 2 : 1; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 436 | ts->ts_status = 0; |
| 437 | |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 438 | ts->ts_final_idx = AR5K_REG_MS(txstat1, |
Bruno Randolf | 03417bc | 2010-06-16 19:12:17 +0900 | [diff] [blame] | 439 | AR5K_DESC_TX_STATUS1_FINAL_TS_IX_5212); |
Felix Fietkau | 2f7fe87 | 2008-10-05 18:05:48 +0200 | [diff] [blame] | 440 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 441 | /* TX error */ |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 442 | if (!(txstat0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) { |
| 443 | if (txstat0 & AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 444 | ts->ts_status |= AR5K_TXERR_XRETRY; |
| 445 | |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 446 | if (txstat0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 447 | ts->ts_status |= AR5K_TXERR_FIFO; |
| 448 | |
Felix Fietkau | b161b89 | 2011-04-10 18:32:15 +0200 | [diff] [blame] | 449 | if (txstat0 & AR5K_DESC_TX_STATUS0_FILTERED) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 450 | ts->ts_status |= AR5K_TXERR_FILT; |
| 451 | } |
| 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
Nick Kossifidis | 9320b5c | 2010-11-23 20:36:45 +0200 | [diff] [blame] | 456 | |
| 457 | /****************\ |
| 458 | * RX Descriptors * |
| 459 | \****************/ |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 460 | |
| 461 | /* |
| 462 | * Initialize an rx control descriptor |
| 463 | */ |
Bruno Randolf | a666819 | 2010-06-16 19:12:01 +0900 | [diff] [blame] | 464 | int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc, |
| 465 | u32 size, unsigned int flags) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 466 | { |
| 467 | struct ath5k_hw_rx_ctl *rx_ctl; |
| 468 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 469 | 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 Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 480 | if (unlikely(size & ~AR5K_DESC_RX_CTL1_BUF_LEN)) |
| 481 | return -EINVAL; |
| 482 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 483 | /* Setup descriptor */ |
| 484 | rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 485 | |
| 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 Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 493 | * Process the rx status descriptor on 5210/5211 |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 494 | */ |
| 495 | static 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 Randolf | 62412a8 | 2010-06-16 19:12:12 +0900 | [diff] [blame] | 500 | rx_status = &desc->ud.ds_rx.rx_stat; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 501 | |
| 502 | /* No frame received / not ready */ |
| 503 | if (unlikely(!(rx_status->rx_status_1 & |
Bruno Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 504 | AR5K_5210_RX_DESC_STATUS1_DONE))) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 505 | return -EINPROGRESS; |
| 506 | |
Bruno Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 507 | memset(rs, 0, sizeof(struct ath5k_rx_status)); |
| 508 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 509 | /* |
| 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 Copeland | c793033 | 2008-11-03 22:14:00 -0500 | [diff] [blame] | 518 | rs->rs_more = !!(rx_status->rx_status_0 & |
| 519 | AR5K_5210_RX_DESC_STATUS0_MORE); |
Bruno Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 520 | /* 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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 525 | rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1, |
| 526 | AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP); |
Bruno Randolf | 1884a36 | 2010-06-16 19:12:28 +0900 | [diff] [blame] | 527 | |
| 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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 536 | /* |
| 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 Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 549 | AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 550 | if (rx_status->rx_status_1 & |
| 551 | AR5K_5210_RX_DESC_STATUS1_CRC_ERROR) |
| 552 | rs->rs_status |= AR5K_RXERR_CRC; |
| 553 | |
Bruno Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 554 | /* 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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 558 | 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 Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 563 | rs->rs_phyerr = AR5K_REG_MS(rx_status->rx_status_1, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 564 | 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 Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 576 | * Process the rx status descriptor on 5212 |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 577 | */ |
| 578 | static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah, |
Bruno Randolf | 2847109 | 2010-06-16 19:12:07 +0900 | [diff] [blame] | 579 | struct ath5k_desc *desc, |
| 580 | struct ath5k_rx_status *rs) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 581 | { |
| 582 | struct ath5k_hw_rx_status *rx_status; |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 583 | u32 rxstat0, rxstat1; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 584 | |
Bruno Randolf | 62412a8 | 2010-06-16 19:12:12 +0900 | [diff] [blame] | 585 | rx_status = &desc->ud.ds_rx.rx_stat; |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 586 | rxstat1 = ACCESS_ONCE(rx_status->rx_status_1); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 587 | |
| 588 | /* No frame received / not ready */ |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 589 | if (unlikely(!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_DONE))) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 590 | return -EINPROGRESS; |
| 591 | |
Bruno Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 592 | memset(rs, 0, sizeof(struct ath5k_rx_status)); |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 593 | rxstat0 = ACCESS_ONCE(rx_status->rx_status_0); |
Bruno Randolf | 8786123 | 2010-06-16 19:12:34 +0900 | [diff] [blame] | 594 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 595 | /* |
| 596 | * Frame receive status |
| 597 | */ |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 598 | rs->rs_datalen = rxstat0 & AR5K_5212_RX_DESC_STATUS0_DATA_LEN; |
| 599 | rs->rs_rssi = AR5K_REG_MS(rxstat0, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 600 | AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL); |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 601 | rs->rs_rate = AR5K_REG_MS(rxstat0, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 602 | AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE); |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 603 | rs->rs_antenna = AR5K_REG_MS(rxstat0, |
Bob Copeland | c793033 | 2008-11-03 22:14:00 -0500 | [diff] [blame] | 604 | AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA); |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 605 | rs->rs_more = !!(rxstat0 & AR5K_5212_RX_DESC_STATUS0_MORE); |
| 606 | rs->rs_tstamp = AR5K_REG_MS(rxstat1, |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 607 | AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 608 | |
| 609 | /* |
| 610 | * Key table status |
| 611 | */ |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 612 | if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID) |
| 613 | rs->rs_keyix = AR5K_REG_MS(rxstat1, |
Bruno Randolf | 2847109 | 2010-06-16 19:12:07 +0900 | [diff] [blame] | 614 | AR5K_5212_RX_DESC_STATUS1_KEY_INDEX); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 615 | else |
| 616 | rs->rs_keyix = AR5K_RXKEYIX_INVALID; |
| 617 | |
| 618 | /* |
| 619 | * Receive/descriptor errors |
| 620 | */ |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 621 | if (!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) { |
| 622 | if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_CRC_ERROR) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 623 | rs->rs_status |= AR5K_RXERR_CRC; |
| 624 | |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 625 | if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 626 | rs->rs_status |= AR5K_RXERR_PHY; |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 627 | rs->rs_phyerr = AR5K_REG_MS(rxstat1, |
Bruno Randolf | 62412a8 | 2010-06-16 19:12:12 +0900 | [diff] [blame] | 628 | AR5K_5212_RX_DESC_STATUS1_PHY_ERROR_CODE); |
Bruno Randolf | 6a0076e | 2010-06-16 19:12:39 +0900 | [diff] [blame] | 629 | if (!ah->ah_capabilities.cap_has_phyerr_counters) |
| 630 | ath5k_ani_phy_error_report(ah, rs->rs_phyerr); |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 631 | } |
| 632 | |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 633 | if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 634 | rs->rs_status |= AR5K_RXERR_DECRYPT; |
| 635 | |
Felix Fietkau | b2fd97d | 2011-04-10 18:32:16 +0200 | [diff] [blame] | 636 | if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_MIC_ERROR) |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 637 | rs->rs_status |= AR5K_RXERR_MIC; |
| 638 | } |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | |
Nick Kossifidis | 9320b5c | 2010-11-23 20:36:45 +0200 | [diff] [blame] | 642 | |
| 643 | /********\ |
| 644 | * Attach * |
| 645 | \********/ |
| 646 | |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 647 | /* |
| 648 | * Init function pointers inside ath5k_hw struct |
| 649 | */ |
| 650 | int ath5k_hw_init_desc_functions(struct ath5k_hw *ah) |
| 651 | { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 652 | if (ah->ah_version == AR5K_AR5212) { |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 653 | ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 654 | ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 655 | ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status; |
Bruno Randolf | a666819 | 2010-06-16 19:12:01 +0900 | [diff] [blame] | 656 | } 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 Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 659 | ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status; |
Bruno Randolf | a666819 | 2010-06-16 19:12:01 +0900 | [diff] [blame] | 660 | } else |
| 661 | return -ENOTSUPP; |
Nick Kossifidis | c6e387a | 2008-08-29 22:45:39 +0300 | [diff] [blame] | 662 | return 0; |
| 663 | } |