Vasanthakumar Thiagarajan | ae3bb6d | 2010-04-15 17:38:27 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | #include "hw.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 17 | #include "ar9003_mac.h" |
Vasanthakumar Thiagarajan | ae3bb6d | 2010-04-15 17:38:27 -0400 | [diff] [blame] | 18 | |
| 19 | static void ar9003_hw_rx_enable(struct ath_hw *hw) |
| 20 | { |
| 21 | REG_WRITE(hw, AR_CR, 0); |
| 22 | } |
| 23 | |
Vasanthakumar Thiagarajan | eb82325 | 2010-04-15 17:39:35 -0400 | [diff] [blame] | 24 | static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads) |
| 25 | { |
| 26 | int checksum; |
| 27 | |
| 28 | checksum = ads->info + ads->link |
| 29 | + ads->data0 + ads->ctl3 |
| 30 | + ads->data1 + ads->ctl5 |
| 31 | + ads->data2 + ads->ctl7 |
| 32 | + ads->data3 + ads->ctl9; |
| 33 | |
| 34 | return ((checksum & 0xffff) + (checksum >> 16)) & AR_TxPtrChkSum; |
| 35 | } |
| 36 | |
Vasanthakumar Thiagarajan | 87d5efb | 2010-04-15 17:38:43 -0400 | [diff] [blame] | 37 | static void ar9003_hw_set_desc_link(void *ds, u32 ds_link) |
| 38 | { |
Vasanthakumar Thiagarajan | eb82325 | 2010-04-15 17:39:35 -0400 | [diff] [blame] | 39 | struct ar9003_txc *ads = ds; |
| 40 | |
| 41 | ads->link = ds_link; |
| 42 | ads->ctl10 &= ~AR_TxPtrChkSum; |
| 43 | ads->ctl10 |= ar9003_calc_ptr_chksum(ads); |
Vasanthakumar Thiagarajan | 87d5efb | 2010-04-15 17:38:43 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static void ar9003_hw_get_desc_link(void *ds, u32 **ds_link) |
| 47 | { |
Vasanthakumar Thiagarajan | eb82325 | 2010-04-15 17:39:35 -0400 | [diff] [blame] | 48 | struct ar9003_txc *ads = ds; |
| 49 | |
| 50 | *ds_link = &ads->link; |
Vasanthakumar Thiagarajan | 87d5efb | 2010-04-15 17:38:43 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Vasanthakumar Thiagarajan | 55e82df | 2010-04-15 17:39:06 -0400 | [diff] [blame] | 53 | static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked) |
| 54 | { |
Vasanthakumar Thiagarajan | 6c84ce0 | 2010-04-15 17:39:16 -0400 | [diff] [blame] | 55 | u32 isr = 0; |
| 56 | u32 mask2 = 0; |
| 57 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
| 58 | u32 sync_cause = 0; |
| 59 | struct ath_common *common = ath9k_hw_common(ah); |
| 60 | |
| 61 | if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) { |
| 62 | if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) |
| 63 | == AR_RTC_STATUS_ON) |
| 64 | isr = REG_READ(ah, AR_ISR); |
| 65 | } |
| 66 | |
| 67 | sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & AR_INTR_SYNC_DEFAULT; |
| 68 | |
| 69 | *masked = 0; |
| 70 | |
| 71 | if (!isr && !sync_cause) |
| 72 | return false; |
| 73 | |
| 74 | if (isr) { |
| 75 | if (isr & AR_ISR_BCNMISC) { |
| 76 | u32 isr2; |
| 77 | isr2 = REG_READ(ah, AR_ISR_S2); |
| 78 | |
| 79 | mask2 |= ((isr2 & AR_ISR_S2_TIM) >> |
| 80 | MAP_ISR_S2_TIM); |
| 81 | mask2 |= ((isr2 & AR_ISR_S2_DTIM) >> |
| 82 | MAP_ISR_S2_DTIM); |
| 83 | mask2 |= ((isr2 & AR_ISR_S2_DTIMSYNC) >> |
| 84 | MAP_ISR_S2_DTIMSYNC); |
| 85 | mask2 |= ((isr2 & AR_ISR_S2_CABEND) >> |
| 86 | MAP_ISR_S2_CABEND); |
| 87 | mask2 |= ((isr2 & AR_ISR_S2_GTT) << |
| 88 | MAP_ISR_S2_GTT); |
| 89 | mask2 |= ((isr2 & AR_ISR_S2_CST) << |
| 90 | MAP_ISR_S2_CST); |
| 91 | mask2 |= ((isr2 & AR_ISR_S2_TSFOOR) >> |
| 92 | MAP_ISR_S2_TSFOOR); |
Luis R. Rodriguez | aea702b | 2010-05-13 13:33:43 -0400 | [diff] [blame] | 93 | mask2 |= ((isr2 & AR_ISR_S2_BB_WATCHDOG) >> |
| 94 | MAP_ISR_S2_BB_WATCHDOG); |
Vasanthakumar Thiagarajan | 6c84ce0 | 2010-04-15 17:39:16 -0400 | [diff] [blame] | 95 | |
| 96 | if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) { |
| 97 | REG_WRITE(ah, AR_ISR_S2, isr2); |
| 98 | isr &= ~AR_ISR_BCNMISC; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if ((pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) |
| 103 | isr = REG_READ(ah, AR_ISR_RAC); |
| 104 | |
| 105 | if (isr == 0xffffffff) { |
| 106 | *masked = 0; |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | *masked = isr & ATH9K_INT_COMMON; |
| 111 | |
| 112 | if (ah->config.rx_intr_mitigation) |
| 113 | if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) |
| 114 | *masked |= ATH9K_INT_RXLP; |
| 115 | |
| 116 | if (ah->config.tx_intr_mitigation) |
| 117 | if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM)) |
| 118 | *masked |= ATH9K_INT_TX; |
| 119 | |
| 120 | if (isr & (AR_ISR_LP_RXOK | AR_ISR_RXERR)) |
| 121 | *masked |= ATH9K_INT_RXLP; |
| 122 | |
| 123 | if (isr & AR_ISR_HP_RXOK) |
| 124 | *masked |= ATH9K_INT_RXHP; |
| 125 | |
| 126 | if (isr & (AR_ISR_TXOK | AR_ISR_TXERR | AR_ISR_TXEOL)) { |
| 127 | *masked |= ATH9K_INT_TX; |
| 128 | |
| 129 | if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) { |
| 130 | u32 s0, s1; |
| 131 | s0 = REG_READ(ah, AR_ISR_S0); |
| 132 | REG_WRITE(ah, AR_ISR_S0, s0); |
| 133 | s1 = REG_READ(ah, AR_ISR_S1); |
| 134 | REG_WRITE(ah, AR_ISR_S1, s1); |
| 135 | |
| 136 | isr &= ~(AR_ISR_TXOK | AR_ISR_TXERR | |
| 137 | AR_ISR_TXEOL); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (isr & AR_ISR_GENTMR) { |
| 142 | u32 s5; |
| 143 | |
| 144 | if (pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED) |
| 145 | s5 = REG_READ(ah, AR_ISR_S5_S); |
| 146 | else |
| 147 | s5 = REG_READ(ah, AR_ISR_S5); |
| 148 | |
| 149 | ah->intr_gen_timer_trigger = |
| 150 | MS(s5, AR_ISR_S5_GENTIMER_TRIG); |
| 151 | |
| 152 | ah->intr_gen_timer_thresh = |
| 153 | MS(s5, AR_ISR_S5_GENTIMER_THRESH); |
| 154 | |
| 155 | if (ah->intr_gen_timer_trigger) |
| 156 | *masked |= ATH9K_INT_GENTIMER; |
| 157 | |
| 158 | if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) { |
| 159 | REG_WRITE(ah, AR_ISR_S5, s5); |
| 160 | isr &= ~AR_ISR_GENTMR; |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | |
| 165 | *masked |= mask2; |
| 166 | |
| 167 | if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) { |
| 168 | REG_WRITE(ah, AR_ISR, isr); |
| 169 | |
| 170 | (void) REG_READ(ah, AR_ISR); |
| 171 | } |
Luis R. Rodriguez | aea702b | 2010-05-13 13:33:43 -0400 | [diff] [blame] | 172 | |
| 173 | if (*masked & ATH9K_INT_BB_WATCHDOG) |
| 174 | ar9003_hw_bb_watchdog_read(ah); |
Vasanthakumar Thiagarajan | 6c84ce0 | 2010-04-15 17:39:16 -0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | if (sync_cause) { |
| 178 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) { |
| 179 | REG_WRITE(ah, AR_RC, AR_RC_HOSTIF); |
| 180 | REG_WRITE(ah, AR_RC, 0); |
| 181 | *masked |= ATH9K_INT_FATAL; |
| 182 | } |
| 183 | |
| 184 | if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) |
| 185 | ath_print(common, ATH_DBG_INTERRUPT, |
| 186 | "AR_INTR_SYNC_LOCAL_TIMEOUT\n"); |
| 187 | |
Julia Lawall | 6fe1400 | 2010-08-05 22:26:56 +0200 | [diff] [blame^] | 188 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause); |
Vasanthakumar Thiagarajan | 6c84ce0 | 2010-04-15 17:39:16 -0400 | [diff] [blame] | 189 | (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR); |
| 190 | |
| 191 | } |
Vasanthakumar Thiagarajan | 55e82df | 2010-04-15 17:39:06 -0400 | [diff] [blame] | 192 | return true; |
| 193 | } |
| 194 | |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 195 | static void ar9003_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen, |
| 196 | bool is_firstseg, bool is_lastseg, |
| 197 | const void *ds0, dma_addr_t buf_addr, |
| 198 | unsigned int qcu) |
| 199 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 200 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
| 201 | unsigned int descid = 0; |
| 202 | |
| 203 | ads->info = (ATHEROS_VENDOR_ID << AR_DescId_S) | |
| 204 | (1 << AR_TxRxDesc_S) | |
| 205 | (1 << AR_CtrlStat_S) | |
| 206 | (qcu << AR_TxQcuNum_S) | 0x17; |
| 207 | |
| 208 | ads->data0 = buf_addr; |
| 209 | ads->data1 = 0; |
| 210 | ads->data2 = 0; |
| 211 | ads->data3 = 0; |
| 212 | |
| 213 | ads->ctl3 = (seglen << AR_BufLen_S); |
| 214 | ads->ctl3 &= AR_BufLen; |
| 215 | |
| 216 | /* Fill in pointer checksum and descriptor id */ |
| 217 | ads->ctl10 = ar9003_calc_ptr_chksum(ads); |
| 218 | ads->ctl10 |= (descid << AR_TxDescId_S); |
| 219 | |
| 220 | if (is_firstseg) { |
| 221 | ads->ctl12 |= (is_lastseg ? 0 : AR_TxMore); |
| 222 | } else if (is_lastseg) { |
| 223 | ads->ctl11 = 0; |
| 224 | ads->ctl12 = 0; |
| 225 | ads->ctl13 = AR9003TXC_CONST(ds0)->ctl13; |
| 226 | ads->ctl14 = AR9003TXC_CONST(ds0)->ctl14; |
| 227 | } else { |
| 228 | /* XXX Intermediate descriptor in a multi-descriptor frame.*/ |
| 229 | ads->ctl11 = 0; |
| 230 | ads->ctl12 = AR_TxMore; |
| 231 | ads->ctl13 = 0; |
| 232 | ads->ctl14 = 0; |
| 233 | } |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds, |
| 237 | struct ath_tx_status *ts) |
| 238 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 239 | struct ar9003_txs *ads; |
| 240 | |
| 241 | ads = &ah->ts_ring[ah->ts_tail]; |
| 242 | |
| 243 | if ((ads->status8 & AR_TxDone) == 0) |
| 244 | return -EINPROGRESS; |
| 245 | |
| 246 | ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size; |
| 247 | |
| 248 | if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) || |
| 249 | (MS(ads->ds_info, AR_TxRxDesc) != 1)) { |
| 250 | ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT, |
| 251 | "Tx Descriptor error %x\n", ads->ds_info); |
| 252 | memset(ads, 0, sizeof(*ads)); |
| 253 | return -EIO; |
| 254 | } |
| 255 | |
| 256 | ts->qid = MS(ads->ds_info, AR_TxQcuNum); |
| 257 | ts->desc_id = MS(ads->status1, AR_TxDescId); |
| 258 | ts->ts_seqnum = MS(ads->status8, AR_SeqNum); |
| 259 | ts->ts_tstamp = ads->status4; |
| 260 | ts->ts_status = 0; |
| 261 | ts->ts_flags = 0; |
| 262 | |
| 263 | if (ads->status3 & AR_ExcessiveRetries) |
| 264 | ts->ts_status |= ATH9K_TXERR_XRETRY; |
| 265 | if (ads->status3 & AR_Filtered) |
| 266 | ts->ts_status |= ATH9K_TXERR_FILT; |
| 267 | if (ads->status3 & AR_FIFOUnderrun) { |
| 268 | ts->ts_status |= ATH9K_TXERR_FIFO; |
| 269 | ath9k_hw_updatetxtriglevel(ah, true); |
| 270 | } |
| 271 | if (ads->status8 & AR_TxOpExceeded) |
| 272 | ts->ts_status |= ATH9K_TXERR_XTXOP; |
| 273 | if (ads->status3 & AR_TxTimerExpired) |
| 274 | ts->ts_status |= ATH9K_TXERR_TIMER_EXPIRED; |
| 275 | |
| 276 | if (ads->status3 & AR_DescCfgErr) |
| 277 | ts->ts_flags |= ATH9K_TX_DESC_CFG_ERR; |
| 278 | if (ads->status3 & AR_TxDataUnderrun) { |
| 279 | ts->ts_flags |= ATH9K_TX_DATA_UNDERRUN; |
| 280 | ath9k_hw_updatetxtriglevel(ah, true); |
| 281 | } |
| 282 | if (ads->status3 & AR_TxDelimUnderrun) { |
| 283 | ts->ts_flags |= ATH9K_TX_DELIM_UNDERRUN; |
| 284 | ath9k_hw_updatetxtriglevel(ah, true); |
| 285 | } |
| 286 | if (ads->status2 & AR_TxBaStatus) { |
| 287 | ts->ts_flags |= ATH9K_TX_BA; |
| 288 | ts->ba_low = ads->status5; |
| 289 | ts->ba_high = ads->status6; |
| 290 | } |
| 291 | |
| 292 | ts->ts_rateindex = MS(ads->status8, AR_FinalTxIdx); |
| 293 | |
| 294 | ts->ts_rssi = MS(ads->status7, AR_TxRSSICombined); |
| 295 | ts->ts_rssi_ctl0 = MS(ads->status2, AR_TxRSSIAnt00); |
| 296 | ts->ts_rssi_ctl1 = MS(ads->status2, AR_TxRSSIAnt01); |
| 297 | ts->ts_rssi_ctl2 = MS(ads->status2, AR_TxRSSIAnt02); |
| 298 | ts->ts_rssi_ext0 = MS(ads->status7, AR_TxRSSIAnt10); |
| 299 | ts->ts_rssi_ext1 = MS(ads->status7, AR_TxRSSIAnt11); |
| 300 | ts->ts_rssi_ext2 = MS(ads->status7, AR_TxRSSIAnt12); |
| 301 | ts->ts_shortretry = MS(ads->status3, AR_RTSFailCnt); |
| 302 | ts->ts_longretry = MS(ads->status3, AR_DataFailCnt); |
| 303 | ts->ts_virtcol = MS(ads->status3, AR_VirtRetryCnt); |
| 304 | ts->ts_antenna = 0; |
| 305 | |
| 306 | ts->tid = MS(ads->status8, AR_TxTid); |
| 307 | |
| 308 | memset(ads, 0, sizeof(*ads)); |
| 309 | |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 310 | return 0; |
| 311 | } |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 312 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 313 | static void ar9003_hw_set11n_txdesc(struct ath_hw *ah, void *ds, |
| 314 | u32 pktlen, enum ath9k_pkt_type type, u32 txpower, |
| 315 | u32 keyIx, enum ath9k_key_type keyType, u32 flags) |
| 316 | { |
| 317 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
| 318 | |
Felix Fietkau | 597a94b | 2010-04-26 15:04:37 -0400 | [diff] [blame] | 319 | if (txpower > ah->txpower_limit) |
| 320 | txpower = ah->txpower_limit; |
| 321 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 322 | txpower += ah->txpower_indexoffset; |
| 323 | if (txpower > 63) |
| 324 | txpower = 63; |
| 325 | |
| 326 | ads->ctl11 = (pktlen & AR_FrameLen) |
| 327 | | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0) |
| 328 | | SM(txpower, AR_XmitPower) |
| 329 | | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0) |
| 330 | | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0) |
| 331 | | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0) |
| 332 | | (flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0); |
| 333 | |
| 334 | ads->ctl12 = |
| 335 | (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0) |
| 336 | | SM(type, AR_FrameType) |
| 337 | | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0) |
| 338 | | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0) |
| 339 | | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0); |
| 340 | |
Luis R. Rodriguez | ce01805 | 2010-04-15 17:39:38 -0400 | [diff] [blame] | 341 | ads->ctl17 = SM(keyType, AR_EncrType) | |
| 342 | (flags & ATH9K_TXDESC_LDPC ? AR_LDPC : 0); |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 343 | ads->ctl18 = 0; |
| 344 | ads->ctl19 = AR_Not_Sounding; |
| 345 | |
| 346 | ads->ctl20 = 0; |
| 347 | ads->ctl21 = 0; |
| 348 | ads->ctl22 = 0; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void ar9003_hw_set11n_ratescenario(struct ath_hw *ah, void *ds, |
| 352 | void *lastds, |
| 353 | u32 durUpdateEn, u32 rtsctsRate, |
| 354 | u32 rtsctsDuration, |
| 355 | struct ath9k_11n_rate_series series[], |
| 356 | u32 nseries, u32 flags) |
| 357 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 358 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
| 359 | struct ar9003_txc *last_ads = (struct ar9003_txc *) lastds; |
| 360 | u_int32_t ctl11; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 361 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 362 | if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) { |
| 363 | ctl11 = ads->ctl11; |
| 364 | |
| 365 | if (flags & ATH9K_TXDESC_RTSENA) { |
| 366 | ctl11 &= ~AR_CTSEnable; |
| 367 | ctl11 |= AR_RTSEnable; |
| 368 | } else { |
| 369 | ctl11 &= ~AR_RTSEnable; |
| 370 | ctl11 |= AR_CTSEnable; |
| 371 | } |
| 372 | |
| 373 | ads->ctl11 = ctl11; |
| 374 | } else { |
| 375 | ads->ctl11 = (ads->ctl11 & ~(AR_RTSEnable | AR_CTSEnable)); |
| 376 | } |
| 377 | |
| 378 | ads->ctl13 = set11nTries(series, 0) |
| 379 | | set11nTries(series, 1) |
| 380 | | set11nTries(series, 2) |
| 381 | | set11nTries(series, 3) |
| 382 | | (durUpdateEn ? AR_DurUpdateEna : 0) |
| 383 | | SM(0, AR_BurstDur); |
| 384 | |
| 385 | ads->ctl14 = set11nRate(series, 0) |
| 386 | | set11nRate(series, 1) |
| 387 | | set11nRate(series, 2) |
| 388 | | set11nRate(series, 3); |
| 389 | |
| 390 | ads->ctl15 = set11nPktDurRTSCTS(series, 0) |
| 391 | | set11nPktDurRTSCTS(series, 1); |
| 392 | |
| 393 | ads->ctl16 = set11nPktDurRTSCTS(series, 2) |
| 394 | | set11nPktDurRTSCTS(series, 3); |
| 395 | |
| 396 | ads->ctl18 = set11nRateFlags(series, 0) |
| 397 | | set11nRateFlags(series, 1) |
| 398 | | set11nRateFlags(series, 2) |
| 399 | | set11nRateFlags(series, 3) |
| 400 | | SM(rtsctsRate, AR_RTSCTSRate); |
| 401 | ads->ctl19 = AR_Not_Sounding; |
| 402 | |
| 403 | last_ads->ctl13 = ads->ctl13; |
| 404 | last_ads->ctl14 = ads->ctl14; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static void ar9003_hw_set11n_aggr_first(struct ath_hw *ah, void *ds, |
| 408 | u32 aggrLen) |
| 409 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 410 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 411 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 412 | ads->ctl12 |= (AR_IsAggr | AR_MoreAggr); |
| 413 | |
| 414 | ads->ctl17 &= ~AR_AggrLen; |
| 415 | ads->ctl17 |= SM(aggrLen, AR_AggrLen); |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static void ar9003_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds, |
| 419 | u32 numDelims) |
| 420 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 421 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
| 422 | unsigned int ctl17; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 423 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 424 | ads->ctl12 |= (AR_IsAggr | AR_MoreAggr); |
| 425 | |
| 426 | /* |
| 427 | * We use a stack variable to manipulate ctl6 to reduce uncached |
| 428 | * read modify, modfiy, write. |
| 429 | */ |
| 430 | ctl17 = ads->ctl17; |
| 431 | ctl17 &= ~AR_PadDelim; |
| 432 | ctl17 |= SM(numDelims, AR_PadDelim); |
| 433 | ads->ctl17 = ctl17; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static void ar9003_hw_set11n_aggr_last(struct ath_hw *ah, void *ds) |
| 437 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 438 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 439 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 440 | ads->ctl12 |= AR_IsAggr; |
| 441 | ads->ctl12 &= ~AR_MoreAggr; |
| 442 | ads->ctl17 &= ~AR_PadDelim; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static void ar9003_hw_clr11n_aggr(struct ath_hw *ah, void *ds) |
| 446 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 447 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 448 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 449 | ads->ctl12 &= (~AR_IsAggr & ~AR_MoreAggr); |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void ar9003_hw_set11n_burstduration(struct ath_hw *ah, void *ds, |
| 453 | u32 burstDuration) |
| 454 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 455 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
| 456 | |
| 457 | ads->ctl13 &= ~AR_BurstDur; |
| 458 | ads->ctl13 |= SM(burstDuration, AR_BurstDur); |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 459 | |
| 460 | } |
| 461 | |
| 462 | static void ar9003_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds, |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 463 | u32 vmf) |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 464 | { |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 465 | struct ar9003_txc *ads = (struct ar9003_txc *) ds; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 466 | |
Vasanthakumar Thiagarajan | 994089d | 2010-04-15 17:39:29 -0400 | [diff] [blame] | 467 | if (vmf) |
| 468 | ads->ctl11 |= AR_VirtMoreFrag; |
| 469 | else |
| 470 | ads->ctl11 &= ~AR_VirtMoreFrag; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 471 | } |
| 472 | |
Felix Fietkau | 717f6be | 2010-06-12 00:34:00 -0400 | [diff] [blame] | 473 | void ar9003_hw_set_paprd_txdesc(struct ath_hw *ah, void *ds, u8 chains) |
| 474 | { |
| 475 | struct ar9003_txc *ads = ds; |
| 476 | |
| 477 | ads->ctl12 |= SM(chains, AR_PAPRDChainMask); |
| 478 | } |
| 479 | EXPORT_SYMBOL(ar9003_hw_set_paprd_txdesc); |
| 480 | |
Vasanthakumar Thiagarajan | ae3bb6d | 2010-04-15 17:38:27 -0400 | [diff] [blame] | 481 | void ar9003_hw_attach_mac_ops(struct ath_hw *hw) |
| 482 | { |
| 483 | struct ath_hw_ops *ops = ath9k_hw_ops(hw); |
| 484 | |
| 485 | ops->rx_enable = ar9003_hw_rx_enable; |
Vasanthakumar Thiagarajan | 87d5efb | 2010-04-15 17:38:43 -0400 | [diff] [blame] | 486 | ops->set_desc_link = ar9003_hw_set_desc_link; |
| 487 | ops->get_desc_link = ar9003_hw_get_desc_link; |
Vasanthakumar Thiagarajan | 55e82df | 2010-04-15 17:39:06 -0400 | [diff] [blame] | 488 | ops->get_isr = ar9003_hw_get_isr; |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 489 | ops->fill_txdesc = ar9003_hw_fill_txdesc; |
| 490 | ops->proc_txdesc = ar9003_hw_proc_txdesc; |
| 491 | ops->set11n_txdesc = ar9003_hw_set11n_txdesc; |
| 492 | ops->set11n_ratescenario = ar9003_hw_set11n_ratescenario; |
| 493 | ops->set11n_aggr_first = ar9003_hw_set11n_aggr_first; |
| 494 | ops->set11n_aggr_middle = ar9003_hw_set11n_aggr_middle; |
| 495 | ops->set11n_aggr_last = ar9003_hw_set11n_aggr_last; |
| 496 | ops->clr11n_aggr = ar9003_hw_clr11n_aggr; |
| 497 | ops->set11n_burstduration = ar9003_hw_set11n_burstduration; |
| 498 | ops->set11n_virtualmorefrag = ar9003_hw_set11n_virtualmorefrag; |
Vasanthakumar Thiagarajan | ae3bb6d | 2010-04-15 17:38:27 -0400 | [diff] [blame] | 499 | } |
Vasanthakumar Thiagarajan | ad7b806 | 2010-04-15 17:38:28 -0400 | [diff] [blame] | 500 | |
| 501 | void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size) |
| 502 | { |
| 503 | REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK); |
| 504 | } |
| 505 | EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize); |
| 506 | |
| 507 | void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp, |
| 508 | enum ath9k_rx_qtype qtype) |
| 509 | { |
| 510 | if (qtype == ATH9K_RX_QUEUE_HP) |
| 511 | REG_WRITE(ah, AR_HP_RXDP, rxdp); |
| 512 | else |
| 513 | REG_WRITE(ah, AR_LP_RXDP, rxdp); |
| 514 | } |
| 515 | EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma); |
| 516 | |
| 517 | int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs, |
| 518 | void *buf_addr) |
| 519 | { |
| 520 | struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr; |
| 521 | unsigned int phyerr; |
| 522 | |
| 523 | /* TODO: byte swap on big endian for ar9300_10 */ |
| 524 | |
| 525 | if ((rxsp->status11 & AR_RxDone) == 0) |
| 526 | return -EINPROGRESS; |
| 527 | |
| 528 | if (MS(rxsp->ds_info, AR_DescId) != 0x168c) |
| 529 | return -EINVAL; |
| 530 | |
| 531 | if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0) |
| 532 | return -EINPROGRESS; |
| 533 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 534 | if (!rxs) |
| 535 | return 0; |
| 536 | |
Vasanthakumar Thiagarajan | ad7b806 | 2010-04-15 17:38:28 -0400 | [diff] [blame] | 537 | rxs->rs_status = 0; |
| 538 | rxs->rs_flags = 0; |
| 539 | |
| 540 | rxs->rs_datalen = rxsp->status2 & AR_DataLen; |
| 541 | rxs->rs_tstamp = rxsp->status3; |
| 542 | |
| 543 | /* XXX: Keycache */ |
| 544 | rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined); |
| 545 | rxs->rs_rssi_ctl0 = MS(rxsp->status1, AR_RxRSSIAnt00); |
| 546 | rxs->rs_rssi_ctl1 = MS(rxsp->status1, AR_RxRSSIAnt01); |
| 547 | rxs->rs_rssi_ctl2 = MS(rxsp->status1, AR_RxRSSIAnt02); |
| 548 | rxs->rs_rssi_ext0 = MS(rxsp->status5, AR_RxRSSIAnt10); |
| 549 | rxs->rs_rssi_ext1 = MS(rxsp->status5, AR_RxRSSIAnt11); |
| 550 | rxs->rs_rssi_ext2 = MS(rxsp->status5, AR_RxRSSIAnt12); |
| 551 | |
| 552 | if (rxsp->status11 & AR_RxKeyIdxValid) |
| 553 | rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx); |
| 554 | else |
| 555 | rxs->rs_keyix = ATH9K_RXKEYIX_INVALID; |
| 556 | |
| 557 | rxs->rs_rate = MS(rxsp->status1, AR_RxRate); |
| 558 | rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0; |
| 559 | |
| 560 | rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0; |
| 561 | rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0; |
| 562 | rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7); |
| 563 | rxs->rs_flags = (rxsp->status4 & AR_GI) ? ATH9K_RX_GI : 0; |
| 564 | rxs->rs_flags |= (rxsp->status4 & AR_2040) ? ATH9K_RX_2040 : 0; |
| 565 | |
| 566 | rxs->evm0 = rxsp->status6; |
| 567 | rxs->evm1 = rxsp->status7; |
| 568 | rxs->evm2 = rxsp->status8; |
| 569 | rxs->evm3 = rxsp->status9; |
| 570 | rxs->evm4 = (rxsp->status10 & 0xffff); |
| 571 | |
| 572 | if (rxsp->status11 & AR_PreDelimCRCErr) |
| 573 | rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE; |
| 574 | |
| 575 | if (rxsp->status11 & AR_PostDelimCRCErr) |
| 576 | rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST; |
| 577 | |
| 578 | if (rxsp->status11 & AR_DecryptBusyErr) |
| 579 | rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY; |
| 580 | |
| 581 | if ((rxsp->status11 & AR_RxFrameOK) == 0) { |
Luis R. Rodriguez | 9171acc | 2010-07-14 20:08:41 -0400 | [diff] [blame] | 582 | /* |
| 583 | * AR_CRCErr will bet set to true if we're on the last |
| 584 | * subframe and the AR_PostDelimCRCErr is caught. |
| 585 | * In a way this also gives us a guarantee that when |
| 586 | * (!(AR_CRCErr) && (AR_PostDelimCRCErr)) we cannot |
| 587 | * possibly be reviewing the last subframe. AR_CRCErr |
| 588 | * is the CRC of the actual data. |
| 589 | */ |
Vasanthakumar Thiagarajan | ad7b806 | 2010-04-15 17:38:28 -0400 | [diff] [blame] | 590 | if (rxsp->status11 & AR_CRCErr) { |
| 591 | rxs->rs_status |= ATH9K_RXERR_CRC; |
| 592 | } else if (rxsp->status11 & AR_PHYErr) { |
Vasanthakumar Thiagarajan | ad7b806 | 2010-04-15 17:38:28 -0400 | [diff] [blame] | 593 | phyerr = MS(rxsp->status11, AR_PHYErrCode); |
Luis R. Rodriguez | 9171acc | 2010-07-14 20:08:41 -0400 | [diff] [blame] | 594 | /* |
| 595 | * If we reach a point here where AR_PostDelimCRCErr is |
| 596 | * true it implies we're *not* on the last subframe. In |
| 597 | * in that case that we know already that the CRC of |
| 598 | * the frame was OK, and MAC would send an ACK for that |
| 599 | * subframe, even if we did get a phy error of type |
| 600 | * ATH9K_PHYERR_OFDM_RESTART. This is only applicable |
| 601 | * to frame that are prior to the last subframe. |
| 602 | * The AR_PostDelimCRCErr is the CRC for the MPDU |
| 603 | * delimiter, which contains the 4 reserved bits, |
| 604 | * the MPDU length (12 bits), and follows the MPDU |
| 605 | * delimiter for an A-MPDU subframe (0x4E = 'N' ASCII). |
| 606 | */ |
| 607 | if ((phyerr == ATH9K_PHYERR_OFDM_RESTART) && |
| 608 | (rxsp->status11 & AR_PostDelimCRCErr)) { |
| 609 | rxs->rs_phyerr = 0; |
| 610 | } else { |
| 611 | rxs->rs_status |= ATH9K_RXERR_PHY; |
| 612 | rxs->rs_phyerr = phyerr; |
| 613 | } |
| 614 | |
Vasanthakumar Thiagarajan | ad7b806 | 2010-04-15 17:38:28 -0400 | [diff] [blame] | 615 | } else if (rxsp->status11 & AR_DecryptCRCErr) { |
| 616 | rxs->rs_status |= ATH9K_RXERR_DECRYPT; |
| 617 | } else if (rxsp->status11 & AR_MichaelErr) { |
| 618 | rxs->rs_status |= ATH9K_RXERR_MIC; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma); |
Vasanthakumar Thiagarajan | 744d402 | 2010-04-15 17:39:27 -0400 | [diff] [blame] | 625 | |
| 626 | void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah) |
| 627 | { |
| 628 | ah->ts_tail = 0; |
| 629 | |
| 630 | memset((void *) ah->ts_ring, 0, |
| 631 | ah->ts_size * sizeof(struct ar9003_txs)); |
| 632 | |
| 633 | ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT, |
| 634 | "TS Start 0x%x End 0x%x Virt %p, Size %d\n", |
| 635 | ah->ts_paddr_start, ah->ts_paddr_end, |
| 636 | ah->ts_ring, ah->ts_size); |
| 637 | |
| 638 | REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start); |
| 639 | REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end); |
| 640 | } |
| 641 | |
| 642 | void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start, |
| 643 | u32 ts_paddr_start, |
| 644 | u8 size) |
| 645 | { |
| 646 | |
| 647 | ah->ts_paddr_start = ts_paddr_start; |
| 648 | ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs)); |
| 649 | ah->ts_size = size; |
| 650 | ah->ts_ring = (struct ar9003_txs *) ts_start; |
| 651 | |
| 652 | ath9k_hw_reset_txstatus_ring(ah); |
| 653 | } |
| 654 | EXPORT_SYMBOL(ath9k_hw_setup_statusring); |