Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 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 | |
| 17 | #include "core.h" |
| 18 | #include "hw.h" |
| 19 | #include "reg.h" |
| 20 | #include "phy.h" |
| 21 | |
| 22 | static void ath9k_hw_set_txq_interrupts(struct ath_hal *ah, |
| 23 | struct ath9k_tx_queue_info *qi) |
| 24 | { |
| 25 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 26 | |
| 27 | DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 28 | "tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n", |
| 29 | ahp->ah_txOkInterruptMask, ahp->ah_txErrInterruptMask, |
| 30 | ahp->ah_txDescInterruptMask, ahp->ah_txEolInterruptMask, |
| 31 | ahp->ah_txUrnInterruptMask); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 32 | |
| 33 | REG_WRITE(ah, AR_IMR_S0, |
| 34 | SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK) |
| 35 | | SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC)); |
| 36 | REG_WRITE(ah, AR_IMR_S1, |
| 37 | SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR) |
| 38 | | SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL)); |
| 39 | REG_RMW_FIELD(ah, AR_IMR_S2, |
| 40 | AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask); |
| 41 | } |
| 42 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 43 | u32 ath9k_hw_gettxbuf(struct ath_hal *ah, u32 q) |
| 44 | { |
| 45 | return REG_READ(ah, AR_QTXDP(q)); |
| 46 | } |
| 47 | |
| 48 | bool ath9k_hw_puttxbuf(struct ath_hal *ah, u32 q, u32 txdp) |
| 49 | { |
| 50 | REG_WRITE(ah, AR_QTXDP(q), txdp); |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | bool ath9k_hw_txstart(struct ath_hal *ah, u32 q) |
| 56 | { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 57 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 58 | |
| 59 | REG_WRITE(ah, AR_Q_TXE, 1 << q); |
| 60 | |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | u32 ath9k_hw_numtxpending(struct ath_hal *ah, u32 q) |
| 65 | { |
| 66 | u32 npend; |
| 67 | |
| 68 | npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT; |
| 69 | if (npend == 0) { |
| 70 | |
| 71 | if (REG_READ(ah, AR_Q_TXE) & (1 << q)) |
| 72 | npend = 1; |
| 73 | } |
| 74 | |
| 75 | return npend; |
| 76 | } |
| 77 | |
| 78 | bool ath9k_hw_updatetxtriglevel(struct ath_hal *ah, bool bIncTrigLevel) |
| 79 | { |
| 80 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 81 | u32 txcfg, curLevel, newLevel; |
| 82 | enum ath9k_int omask; |
| 83 | |
| 84 | if (ah->ah_txTrigLevel >= MAX_TX_FIFO_THRESHOLD) |
| 85 | return false; |
| 86 | |
| 87 | omask = ath9k_hw_set_interrupts(ah, ahp->ah_maskReg & ~ATH9K_INT_GLOBAL); |
| 88 | |
| 89 | txcfg = REG_READ(ah, AR_TXCFG); |
| 90 | curLevel = MS(txcfg, AR_FTRIG); |
| 91 | newLevel = curLevel; |
| 92 | if (bIncTrigLevel) { |
| 93 | if (curLevel < MAX_TX_FIFO_THRESHOLD) |
| 94 | newLevel++; |
| 95 | } else if (curLevel > MIN_TX_FIFO_THRESHOLD) |
| 96 | newLevel--; |
| 97 | if (newLevel != curLevel) |
| 98 | REG_WRITE(ah, AR_TXCFG, |
| 99 | (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG)); |
| 100 | |
| 101 | ath9k_hw_set_interrupts(ah, omask); |
| 102 | |
| 103 | ah->ah_txTrigLevel = newLevel; |
| 104 | |
| 105 | return newLevel != curLevel; |
| 106 | } |
| 107 | |
| 108 | bool ath9k_hw_stoptxdma(struct ath_hal *ah, u32 q) |
| 109 | { |
Sujith | 94ff91d | 2009-01-27 15:06:38 +0530 | [diff] [blame^] | 110 | #define ATH9K_TX_STOP_DMA_TIMEOUT 4000 /* usec */ |
| 111 | #define ATH9K_TIME_QUANTUM 100 /* usec */ |
| 112 | |
| 113 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 114 | struct ath9k_hw_capabilities *pCap = &ah->ah_caps; |
| 115 | struct ath9k_tx_queue_info *qi; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 116 | u32 tsfLow, j, wait; |
Sujith | 94ff91d | 2009-01-27 15:06:38 +0530 | [diff] [blame^] | 117 | u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM; |
| 118 | |
| 119 | if (q >= pCap->total_queues) { |
| 120 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | qi = &ahp->ah_txq[q]; |
| 125 | if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { |
| 126 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n"); |
| 127 | return false; |
| 128 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 129 | |
| 130 | REG_WRITE(ah, AR_Q_TXD, 1 << q); |
| 131 | |
Sujith | 94ff91d | 2009-01-27 15:06:38 +0530 | [diff] [blame^] | 132 | for (wait = wait_time; wait != 0; wait--) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 133 | if (ath9k_hw_numtxpending(ah, q) == 0) |
| 134 | break; |
Sujith | 94ff91d | 2009-01-27 15:06:38 +0530 | [diff] [blame^] | 135 | udelay(ATH9K_TIME_QUANTUM); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (ath9k_hw_numtxpending(ah, q)) { |
| 139 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, |
| 140 | "%s: Num of pending TX Frames %d on Q %d\n", |
| 141 | __func__, ath9k_hw_numtxpending(ah, q), q); |
| 142 | |
| 143 | for (j = 0; j < 2; j++) { |
| 144 | tsfLow = REG_READ(ah, AR_TSF_L32); |
| 145 | REG_WRITE(ah, AR_QUIET2, |
| 146 | SM(10, AR_QUIET2_QUIET_DUR)); |
| 147 | REG_WRITE(ah, AR_QUIET_PERIOD, 100); |
| 148 | REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10); |
| 149 | REG_SET_BIT(ah, AR_TIMER_MODE, |
| 150 | AR_QUIET_TIMER_EN); |
| 151 | |
| 152 | if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10)) |
| 153 | break; |
| 154 | |
| 155 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 156 | "TSF have moved while trying to set " |
| 157 | "quiet time TSF: 0x%08x\n", tsfLow); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH); |
| 161 | |
| 162 | udelay(200); |
| 163 | REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN); |
| 164 | |
Sujith | 94ff91d | 2009-01-27 15:06:38 +0530 | [diff] [blame^] | 165 | wait = wait_time; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 166 | while (ath9k_hw_numtxpending(ah, q)) { |
| 167 | if ((--wait) == 0) { |
| 168 | DPRINTF(ah->ah_sc, ATH_DBG_XMIT, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 169 | "Failed to stop Tx DMA in 100 " |
| 170 | "msec after killing last frame\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 171 | break; |
| 172 | } |
Sujith | 94ff91d | 2009-01-27 15:06:38 +0530 | [diff] [blame^] | 173 | udelay(ATH9K_TIME_QUANTUM); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH); |
| 177 | } |
| 178 | |
| 179 | REG_WRITE(ah, AR_Q_TXD, 0); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 180 | return wait != 0; |
Sujith | 94ff91d | 2009-01-27 15:06:38 +0530 | [diff] [blame^] | 181 | |
| 182 | #undef ATH9K_TX_STOP_DMA_TIMEOUT |
| 183 | #undef ATH9K_TIME_QUANTUM |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | bool ath9k_hw_filltxdesc(struct ath_hal *ah, struct ath_desc *ds, |
| 187 | u32 segLen, bool firstSeg, |
| 188 | bool lastSeg, const struct ath_desc *ds0) |
| 189 | { |
| 190 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 191 | |
| 192 | if (firstSeg) { |
| 193 | ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore); |
| 194 | } else if (lastSeg) { |
| 195 | ads->ds_ctl0 = 0; |
| 196 | ads->ds_ctl1 = segLen; |
| 197 | ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2; |
| 198 | ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3; |
| 199 | } else { |
| 200 | ads->ds_ctl0 = 0; |
| 201 | ads->ds_ctl1 = segLen | AR_TxMore; |
| 202 | ads->ds_ctl2 = 0; |
| 203 | ads->ds_ctl3 = 0; |
| 204 | } |
| 205 | ads->ds_txstatus0 = ads->ds_txstatus1 = 0; |
| 206 | ads->ds_txstatus2 = ads->ds_txstatus3 = 0; |
| 207 | ads->ds_txstatus4 = ads->ds_txstatus5 = 0; |
| 208 | ads->ds_txstatus6 = ads->ds_txstatus7 = 0; |
| 209 | ads->ds_txstatus8 = ads->ds_txstatus9 = 0; |
| 210 | |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | void ath9k_hw_cleartxdesc(struct ath_hal *ah, struct ath_desc *ds) |
| 215 | { |
| 216 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 217 | |
| 218 | ads->ds_txstatus0 = ads->ds_txstatus1 = 0; |
| 219 | ads->ds_txstatus2 = ads->ds_txstatus3 = 0; |
| 220 | ads->ds_txstatus4 = ads->ds_txstatus5 = 0; |
| 221 | ads->ds_txstatus6 = ads->ds_txstatus7 = 0; |
| 222 | ads->ds_txstatus8 = ads->ds_txstatus9 = 0; |
| 223 | } |
| 224 | |
| 225 | int ath9k_hw_txprocdesc(struct ath_hal *ah, struct ath_desc *ds) |
| 226 | { |
| 227 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 228 | |
| 229 | if ((ads->ds_txstatus9 & AR_TxDone) == 0) |
| 230 | return -EINPROGRESS; |
| 231 | |
| 232 | ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum); |
| 233 | ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp; |
| 234 | ds->ds_txstat.ts_status = 0; |
| 235 | ds->ds_txstat.ts_flags = 0; |
| 236 | |
| 237 | if (ads->ds_txstatus1 & AR_ExcessiveRetries) |
| 238 | ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY; |
| 239 | if (ads->ds_txstatus1 & AR_Filtered) |
| 240 | ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT; |
Sujith | daa9deb | 2008-11-18 09:10:22 +0530 | [diff] [blame] | 241 | if (ads->ds_txstatus1 & AR_FIFOUnderrun) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 242 | ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO; |
Sujith | daa9deb | 2008-11-18 09:10:22 +0530 | [diff] [blame] | 243 | ath9k_hw_updatetxtriglevel(ah, true); |
| 244 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 245 | if (ads->ds_txstatus9 & AR_TxOpExceeded) |
| 246 | ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP; |
| 247 | if (ads->ds_txstatus1 & AR_TxTimerExpired) |
| 248 | ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED; |
| 249 | |
| 250 | if (ads->ds_txstatus1 & AR_DescCfgErr) |
| 251 | ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR; |
| 252 | if (ads->ds_txstatus1 & AR_TxDataUnderrun) { |
| 253 | ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN; |
| 254 | ath9k_hw_updatetxtriglevel(ah, true); |
| 255 | } |
| 256 | if (ads->ds_txstatus1 & AR_TxDelimUnderrun) { |
| 257 | ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN; |
| 258 | ath9k_hw_updatetxtriglevel(ah, true); |
| 259 | } |
| 260 | if (ads->ds_txstatus0 & AR_TxBaStatus) { |
| 261 | ds->ds_txstat.ts_flags |= ATH9K_TX_BA; |
| 262 | ds->ds_txstat.ba_low = ads->AR_BaBitmapLow; |
| 263 | ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh; |
| 264 | } |
| 265 | |
| 266 | ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx); |
| 267 | switch (ds->ds_txstat.ts_rateindex) { |
| 268 | case 0: |
| 269 | ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0); |
| 270 | break; |
| 271 | case 1: |
| 272 | ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1); |
| 273 | break; |
| 274 | case 2: |
| 275 | ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2); |
| 276 | break; |
| 277 | case 3: |
| 278 | ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3); |
| 279 | break; |
| 280 | } |
| 281 | |
| 282 | ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined); |
| 283 | ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00); |
| 284 | ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01); |
| 285 | ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02); |
| 286 | ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10); |
| 287 | ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11); |
| 288 | ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12); |
| 289 | ds->ds_txstat.evm0 = ads->AR_TxEVM0; |
| 290 | ds->ds_txstat.evm1 = ads->AR_TxEVM1; |
| 291 | ds->ds_txstat.evm2 = ads->AR_TxEVM2; |
| 292 | ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt); |
| 293 | ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt); |
| 294 | ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt); |
| 295 | ds->ds_txstat.ts_antenna = 1; |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | void ath9k_hw_set11n_txdesc(struct ath_hal *ah, struct ath_desc *ds, |
| 301 | u32 pktLen, enum ath9k_pkt_type type, u32 txPower, |
| 302 | u32 keyIx, enum ath9k_key_type keyType, u32 flags) |
| 303 | { |
| 304 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 305 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 306 | |
| 307 | txPower += ahp->ah_txPowerIndexOffset; |
| 308 | if (txPower > 63) |
| 309 | txPower = 63; |
| 310 | |
| 311 | ads->ds_ctl0 = (pktLen & AR_FrameLen) |
| 312 | | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0) |
| 313 | | SM(txPower, AR_XmitPower) |
| 314 | | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0) |
| 315 | | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0) |
| 316 | | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0) |
| 317 | | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0); |
| 318 | |
| 319 | ads->ds_ctl1 = |
| 320 | (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0) |
| 321 | | SM(type, AR_FrameType) |
| 322 | | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0) |
| 323 | | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0) |
| 324 | | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0); |
| 325 | |
| 326 | ads->ds_ctl6 = SM(keyType, AR_EncrType); |
| 327 | |
| 328 | if (AR_SREV_9285(ah)) { |
| 329 | ads->ds_ctl8 = 0; |
| 330 | ads->ds_ctl9 = 0; |
| 331 | ads->ds_ctl10 = 0; |
| 332 | ads->ds_ctl11 = 0; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void ath9k_hw_set11n_ratescenario(struct ath_hal *ah, struct ath_desc *ds, |
| 337 | struct ath_desc *lastds, |
| 338 | u32 durUpdateEn, u32 rtsctsRate, |
| 339 | u32 rtsctsDuration, |
| 340 | struct ath9k_11n_rate_series series[], |
| 341 | u32 nseries, u32 flags) |
| 342 | { |
| 343 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 344 | struct ar5416_desc *last_ads = AR5416DESC(lastds); |
| 345 | u32 ds_ctl0; |
| 346 | |
| 347 | (void) nseries; |
| 348 | (void) rtsctsDuration; |
| 349 | |
| 350 | if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) { |
| 351 | ds_ctl0 = ads->ds_ctl0; |
| 352 | |
| 353 | if (flags & ATH9K_TXDESC_RTSENA) { |
| 354 | ds_ctl0 &= ~AR_CTSEnable; |
| 355 | ds_ctl0 |= AR_RTSEnable; |
| 356 | } else { |
| 357 | ds_ctl0 &= ~AR_RTSEnable; |
| 358 | ds_ctl0 |= AR_CTSEnable; |
| 359 | } |
| 360 | |
| 361 | ads->ds_ctl0 = ds_ctl0; |
| 362 | } else { |
| 363 | ads->ds_ctl0 = |
| 364 | (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable)); |
| 365 | } |
| 366 | |
| 367 | ads->ds_ctl2 = set11nTries(series, 0) |
| 368 | | set11nTries(series, 1) |
| 369 | | set11nTries(series, 2) |
| 370 | | set11nTries(series, 3) |
| 371 | | (durUpdateEn ? AR_DurUpdateEna : 0) |
| 372 | | SM(0, AR_BurstDur); |
| 373 | |
| 374 | ads->ds_ctl3 = set11nRate(series, 0) |
| 375 | | set11nRate(series, 1) |
| 376 | | set11nRate(series, 2) |
| 377 | | set11nRate(series, 3); |
| 378 | |
| 379 | ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0) |
| 380 | | set11nPktDurRTSCTS(series, 1); |
| 381 | |
| 382 | ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2) |
| 383 | | set11nPktDurRTSCTS(series, 3); |
| 384 | |
| 385 | ads->ds_ctl7 = set11nRateFlags(series, 0) |
| 386 | | set11nRateFlags(series, 1) |
| 387 | | set11nRateFlags(series, 2) |
| 388 | | set11nRateFlags(series, 3) |
| 389 | | SM(rtsctsRate, AR_RTSCTSRate); |
| 390 | last_ads->ds_ctl2 = ads->ds_ctl2; |
| 391 | last_ads->ds_ctl3 = ads->ds_ctl3; |
| 392 | } |
| 393 | |
| 394 | void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds, |
| 395 | u32 aggrLen) |
| 396 | { |
| 397 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 398 | |
| 399 | ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr); |
| 400 | ads->ds_ctl6 &= ~AR_AggrLen; |
| 401 | ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen); |
| 402 | } |
| 403 | |
| 404 | void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds, |
| 405 | u32 numDelims) |
| 406 | { |
| 407 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 408 | unsigned int ctl6; |
| 409 | |
| 410 | ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr); |
| 411 | |
| 412 | ctl6 = ads->ds_ctl6; |
| 413 | ctl6 &= ~AR_PadDelim; |
| 414 | ctl6 |= SM(numDelims, AR_PadDelim); |
| 415 | ads->ds_ctl6 = ctl6; |
| 416 | } |
| 417 | |
| 418 | void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds) |
| 419 | { |
| 420 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 421 | |
| 422 | ads->ds_ctl1 |= AR_IsAggr; |
| 423 | ads->ds_ctl1 &= ~AR_MoreAggr; |
| 424 | ads->ds_ctl6 &= ~AR_PadDelim; |
| 425 | } |
| 426 | |
| 427 | void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds) |
| 428 | { |
| 429 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 430 | |
| 431 | ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr); |
| 432 | } |
| 433 | |
| 434 | void ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds, |
| 435 | u32 burstDuration) |
| 436 | { |
| 437 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 438 | |
| 439 | ads->ds_ctl2 &= ~AR_BurstDur; |
| 440 | ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur); |
| 441 | } |
| 442 | |
| 443 | void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds, |
| 444 | u32 vmf) |
| 445 | { |
| 446 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 447 | |
| 448 | if (vmf) |
| 449 | ads->ds_ctl0 |= AR_VirtMoreFrag; |
| 450 | else |
| 451 | ads->ds_ctl0 &= ~AR_VirtMoreFrag; |
| 452 | } |
| 453 | |
| 454 | void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs) |
| 455 | { |
| 456 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 457 | |
| 458 | *txqs &= ahp->ah_intrTxqs; |
| 459 | ahp->ah_intrTxqs &= ~(*txqs); |
| 460 | } |
| 461 | |
| 462 | bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q, |
| 463 | const struct ath9k_tx_queue_info *qinfo) |
| 464 | { |
| 465 | u32 cw; |
| 466 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 467 | struct ath9k_hw_capabilities *pCap = &ah->ah_caps; |
| 468 | struct ath9k_tx_queue_info *qi; |
| 469 | |
| 470 | if (q >= pCap->total_queues) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 471 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 472 | return false; |
| 473 | } |
| 474 | |
| 475 | qi = &ahp->ah_txq[q]; |
| 476 | if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 477 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 478 | return false; |
| 479 | } |
| 480 | |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 481 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %p\n", qi); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 482 | |
| 483 | qi->tqi_ver = qinfo->tqi_ver; |
| 484 | qi->tqi_subtype = qinfo->tqi_subtype; |
| 485 | qi->tqi_qflags = qinfo->tqi_qflags; |
| 486 | qi->tqi_priority = qinfo->tqi_priority; |
| 487 | if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT) |
| 488 | qi->tqi_aifs = min(qinfo->tqi_aifs, 255U); |
| 489 | else |
| 490 | qi->tqi_aifs = INIT_AIFS; |
| 491 | if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) { |
| 492 | cw = min(qinfo->tqi_cwmin, 1024U); |
| 493 | qi->tqi_cwmin = 1; |
| 494 | while (qi->tqi_cwmin < cw) |
| 495 | qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1; |
| 496 | } else |
| 497 | qi->tqi_cwmin = qinfo->tqi_cwmin; |
| 498 | if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) { |
| 499 | cw = min(qinfo->tqi_cwmax, 1024U); |
| 500 | qi->tqi_cwmax = 1; |
| 501 | while (qi->tqi_cwmax < cw) |
| 502 | qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1; |
| 503 | } else |
| 504 | qi->tqi_cwmax = INIT_CWMAX; |
| 505 | |
| 506 | if (qinfo->tqi_shretry != 0) |
| 507 | qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U); |
| 508 | else |
| 509 | qi->tqi_shretry = INIT_SH_RETRY; |
| 510 | if (qinfo->tqi_lgretry != 0) |
| 511 | qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U); |
| 512 | else |
| 513 | qi->tqi_lgretry = INIT_LG_RETRY; |
| 514 | qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod; |
| 515 | qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit; |
| 516 | qi->tqi_burstTime = qinfo->tqi_burstTime; |
| 517 | qi->tqi_readyTime = qinfo->tqi_readyTime; |
| 518 | |
| 519 | switch (qinfo->tqi_subtype) { |
| 520 | case ATH9K_WME_UPSD: |
| 521 | if (qi->tqi_type == ATH9K_TX_QUEUE_DATA) |
| 522 | qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS; |
| 523 | break; |
| 524 | default: |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | return true; |
| 529 | } |
| 530 | |
| 531 | bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q, |
| 532 | struct ath9k_tx_queue_info *qinfo) |
| 533 | { |
| 534 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 535 | struct ath9k_hw_capabilities *pCap = &ah->ah_caps; |
| 536 | struct ath9k_tx_queue_info *qi; |
| 537 | |
| 538 | if (q >= pCap->total_queues) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 539 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 540 | return false; |
| 541 | } |
| 542 | |
| 543 | qi = &ahp->ah_txq[q]; |
| 544 | if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 545 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 546 | return false; |
| 547 | } |
| 548 | |
| 549 | qinfo->tqi_qflags = qi->tqi_qflags; |
| 550 | qinfo->tqi_ver = qi->tqi_ver; |
| 551 | qinfo->tqi_subtype = qi->tqi_subtype; |
| 552 | qinfo->tqi_qflags = qi->tqi_qflags; |
| 553 | qinfo->tqi_priority = qi->tqi_priority; |
| 554 | qinfo->tqi_aifs = qi->tqi_aifs; |
| 555 | qinfo->tqi_cwmin = qi->tqi_cwmin; |
| 556 | qinfo->tqi_cwmax = qi->tqi_cwmax; |
| 557 | qinfo->tqi_shretry = qi->tqi_shretry; |
| 558 | qinfo->tqi_lgretry = qi->tqi_lgretry; |
| 559 | qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod; |
| 560 | qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit; |
| 561 | qinfo->tqi_burstTime = qi->tqi_burstTime; |
| 562 | qinfo->tqi_readyTime = qi->tqi_readyTime; |
| 563 | |
| 564 | return true; |
| 565 | } |
| 566 | |
| 567 | int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type, |
| 568 | const struct ath9k_tx_queue_info *qinfo) |
| 569 | { |
| 570 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 571 | struct ath9k_tx_queue_info *qi; |
| 572 | struct ath9k_hw_capabilities *pCap = &ah->ah_caps; |
| 573 | int q; |
| 574 | |
| 575 | switch (type) { |
| 576 | case ATH9K_TX_QUEUE_BEACON: |
| 577 | q = pCap->total_queues - 1; |
| 578 | break; |
| 579 | case ATH9K_TX_QUEUE_CAB: |
| 580 | q = pCap->total_queues - 2; |
| 581 | break; |
| 582 | case ATH9K_TX_QUEUE_PSPOLL: |
| 583 | q = 1; |
| 584 | break; |
| 585 | case ATH9K_TX_QUEUE_UAPSD: |
| 586 | q = pCap->total_queues - 3; |
| 587 | break; |
| 588 | case ATH9K_TX_QUEUE_DATA: |
| 589 | for (q = 0; q < pCap->total_queues; q++) |
| 590 | if (ahp->ah_txq[q].tqi_type == |
| 591 | ATH9K_TX_QUEUE_INACTIVE) |
| 592 | break; |
| 593 | if (q == pCap->total_queues) { |
| 594 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 595 | "no available tx queue\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 596 | return -1; |
| 597 | } |
| 598 | break; |
| 599 | default: |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 600 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "bad tx queue type %u\n", type); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 601 | return -1; |
| 602 | } |
| 603 | |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 604 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 605 | |
| 606 | qi = &ahp->ah_txq[q]; |
| 607 | if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) { |
| 608 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 609 | "tx queue %u already active\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 610 | return -1; |
| 611 | } |
| 612 | memset(qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 613 | qi->tqi_type = type; |
| 614 | if (qinfo == NULL) { |
| 615 | qi->tqi_qflags = |
| 616 | TXQ_FLAG_TXOKINT_ENABLE |
| 617 | | TXQ_FLAG_TXERRINT_ENABLE |
| 618 | | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE; |
| 619 | qi->tqi_aifs = INIT_AIFS; |
| 620 | qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT; |
| 621 | qi->tqi_cwmax = INIT_CWMAX; |
| 622 | qi->tqi_shretry = INIT_SH_RETRY; |
| 623 | qi->tqi_lgretry = INIT_LG_RETRY; |
| 624 | qi->tqi_physCompBuf = 0; |
| 625 | } else { |
| 626 | qi->tqi_physCompBuf = qinfo->tqi_physCompBuf; |
| 627 | (void) ath9k_hw_set_txq_props(ah, q, qinfo); |
| 628 | } |
| 629 | |
| 630 | return q; |
| 631 | } |
| 632 | |
| 633 | bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q) |
| 634 | { |
| 635 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 636 | struct ath9k_hw_capabilities *pCap = &ah->ah_caps; |
| 637 | struct ath9k_tx_queue_info *qi; |
| 638 | |
| 639 | if (q >= pCap->total_queues) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 640 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 641 | return false; |
| 642 | } |
| 643 | qi = &ahp->ah_txq[q]; |
| 644 | if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 645 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 646 | return false; |
| 647 | } |
| 648 | |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 649 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "release queue %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 650 | |
| 651 | qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE; |
| 652 | ahp->ah_txOkInterruptMask &= ~(1 << q); |
| 653 | ahp->ah_txErrInterruptMask &= ~(1 << q); |
| 654 | ahp->ah_txDescInterruptMask &= ~(1 << q); |
| 655 | ahp->ah_txEolInterruptMask &= ~(1 << q); |
| 656 | ahp->ah_txUrnInterruptMask &= ~(1 << q); |
| 657 | ath9k_hw_set_txq_interrupts(ah, qi); |
| 658 | |
| 659 | return true; |
| 660 | } |
| 661 | |
| 662 | bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q) |
| 663 | { |
| 664 | struct ath_hal_5416 *ahp = AH5416(ah); |
| 665 | struct ath9k_hw_capabilities *pCap = &ah->ah_caps; |
| 666 | struct ath9k_channel *chan = ah->ah_curchan; |
| 667 | struct ath9k_tx_queue_info *qi; |
| 668 | u32 cwMin, chanCwMin, value; |
| 669 | |
| 670 | if (q >= pCap->total_queues) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 671 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 672 | return false; |
| 673 | } |
| 674 | |
| 675 | qi = &ahp->ah_txq[q]; |
| 676 | if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 677 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 678 | return true; |
| 679 | } |
| 680 | |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 681 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "reset queue %u\n", q); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 682 | |
| 683 | if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) { |
| 684 | if (chan && IS_CHAN_B(chan)) |
| 685 | chanCwMin = INIT_CWMIN_11B; |
| 686 | else |
| 687 | chanCwMin = INIT_CWMIN; |
| 688 | |
| 689 | for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1); |
| 690 | } else |
| 691 | cwMin = qi->tqi_cwmin; |
| 692 | |
| 693 | REG_WRITE(ah, AR_DLCL_IFS(q), |
| 694 | SM(cwMin, AR_D_LCL_IFS_CWMIN) | |
| 695 | SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) | |
| 696 | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS)); |
| 697 | |
| 698 | REG_WRITE(ah, AR_DRETRY_LIMIT(q), |
| 699 | SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) | |
| 700 | SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) | |
| 701 | SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)); |
| 702 | |
| 703 | REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ); |
| 704 | REG_WRITE(ah, AR_DMISC(q), |
| 705 | AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2); |
| 706 | |
| 707 | if (qi->tqi_cbrPeriod) { |
| 708 | REG_WRITE(ah, AR_QCBRCFG(q), |
| 709 | SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) | |
| 710 | SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH)); |
| 711 | REG_WRITE(ah, AR_QMISC(q), |
| 712 | REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR | |
| 713 | (qi->tqi_cbrOverflowLimit ? |
| 714 | AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0)); |
| 715 | } |
| 716 | if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) { |
| 717 | REG_WRITE(ah, AR_QRDYTIMECFG(q), |
| 718 | SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) | |
| 719 | AR_Q_RDYTIMECFG_EN); |
| 720 | } |
| 721 | |
| 722 | REG_WRITE(ah, AR_DCHNTIME(q), |
| 723 | SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) | |
| 724 | (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0)); |
| 725 | |
| 726 | if (qi->tqi_burstTime |
| 727 | && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) { |
| 728 | REG_WRITE(ah, AR_QMISC(q), |
| 729 | REG_READ(ah, AR_QMISC(q)) | |
| 730 | AR_Q_MISC_RDYTIME_EXP_POLICY); |
| 731 | |
| 732 | } |
| 733 | |
| 734 | if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) { |
| 735 | REG_WRITE(ah, AR_DMISC(q), |
| 736 | REG_READ(ah, AR_DMISC(q)) | |
| 737 | AR_D_MISC_POST_FR_BKOFF_DIS); |
| 738 | } |
| 739 | if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) { |
| 740 | REG_WRITE(ah, AR_DMISC(q), |
| 741 | REG_READ(ah, AR_DMISC(q)) | |
| 742 | AR_D_MISC_FRAG_BKOFF_EN); |
| 743 | } |
| 744 | switch (qi->tqi_type) { |
| 745 | case ATH9K_TX_QUEUE_BEACON: |
| 746 | REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q)) |
| 747 | | AR_Q_MISC_FSP_DBA_GATED |
| 748 | | AR_Q_MISC_BEACON_USE |
| 749 | | AR_Q_MISC_CBR_INCR_DIS1); |
| 750 | |
| 751 | REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
| 752 | | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL << |
| 753 | AR_D_MISC_ARB_LOCKOUT_CNTRL_S) |
| 754 | | AR_D_MISC_BEACON_USE |
| 755 | | AR_D_MISC_POST_FR_BKOFF_DIS); |
| 756 | break; |
| 757 | case ATH9K_TX_QUEUE_CAB: |
| 758 | REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q)) |
| 759 | | AR_Q_MISC_FSP_DBA_GATED |
| 760 | | AR_Q_MISC_CBR_INCR_DIS1 |
| 761 | | AR_Q_MISC_CBR_INCR_DIS0); |
| 762 | value = (qi->tqi_readyTime - |
| 763 | (ah->ah_config.sw_beacon_response_time - |
| 764 | ah->ah_config.dma_beacon_response_time) - |
| 765 | ah->ah_config.additional_swba_backoff) * 1024; |
| 766 | REG_WRITE(ah, AR_QRDYTIMECFG(q), |
| 767 | value | AR_Q_RDYTIMECFG_EN); |
| 768 | REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
| 769 | | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL << |
| 770 | AR_D_MISC_ARB_LOCKOUT_CNTRL_S)); |
| 771 | break; |
| 772 | case ATH9K_TX_QUEUE_PSPOLL: |
| 773 | REG_WRITE(ah, AR_QMISC(q), |
| 774 | REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1); |
| 775 | break; |
| 776 | case ATH9K_TX_QUEUE_UAPSD: |
| 777 | REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) | |
| 778 | AR_D_MISC_POST_FR_BKOFF_DIS); |
| 779 | break; |
| 780 | default: |
| 781 | break; |
| 782 | } |
| 783 | |
| 784 | if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) { |
| 785 | REG_WRITE(ah, AR_DMISC(q), |
| 786 | REG_READ(ah, AR_DMISC(q)) | |
| 787 | SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL, |
| 788 | AR_D_MISC_ARB_LOCKOUT_CNTRL) | |
| 789 | AR_D_MISC_POST_FR_BKOFF_DIS); |
| 790 | } |
| 791 | |
| 792 | if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE) |
| 793 | ahp->ah_txOkInterruptMask |= 1 << q; |
| 794 | else |
| 795 | ahp->ah_txOkInterruptMask &= ~(1 << q); |
| 796 | if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE) |
| 797 | ahp->ah_txErrInterruptMask |= 1 << q; |
| 798 | else |
| 799 | ahp->ah_txErrInterruptMask &= ~(1 << q); |
| 800 | if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE) |
| 801 | ahp->ah_txDescInterruptMask |= 1 << q; |
| 802 | else |
| 803 | ahp->ah_txDescInterruptMask &= ~(1 << q); |
| 804 | if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE) |
| 805 | ahp->ah_txEolInterruptMask |= 1 << q; |
| 806 | else |
| 807 | ahp->ah_txEolInterruptMask &= ~(1 << q); |
| 808 | if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE) |
| 809 | ahp->ah_txUrnInterruptMask |= 1 << q; |
| 810 | else |
| 811 | ahp->ah_txUrnInterruptMask &= ~(1 << q); |
| 812 | ath9k_hw_set_txq_interrupts(ah, qi); |
| 813 | |
| 814 | return true; |
| 815 | } |
| 816 | |
| 817 | int ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds, |
| 818 | u32 pa, struct ath_desc *nds, u64 tsf) |
| 819 | { |
| 820 | struct ar5416_desc ads; |
| 821 | struct ar5416_desc *adsp = AR5416DESC(ds); |
| 822 | u32 phyerr; |
| 823 | |
| 824 | if ((adsp->ds_rxstatus8 & AR_RxDone) == 0) |
| 825 | return -EINPROGRESS; |
| 826 | |
| 827 | ads.u.rx = adsp->u.rx; |
| 828 | |
| 829 | ds->ds_rxstat.rs_status = 0; |
| 830 | ds->ds_rxstat.rs_flags = 0; |
| 831 | |
| 832 | ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen; |
| 833 | ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp; |
| 834 | |
| 835 | ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined); |
| 836 | ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00); |
| 837 | ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01); |
| 838 | ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02); |
| 839 | ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10); |
| 840 | ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11); |
| 841 | ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12); |
| 842 | if (ads.ds_rxstatus8 & AR_RxKeyIdxValid) |
| 843 | ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx); |
| 844 | else |
| 845 | ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID; |
| 846 | |
| 847 | ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads)); |
| 848 | ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0; |
| 849 | |
| 850 | ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0; |
| 851 | ds->ds_rxstat.rs_moreaggr = |
| 852 | (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0; |
| 853 | ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna); |
| 854 | ds->ds_rxstat.rs_flags = |
| 855 | (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0; |
| 856 | ds->ds_rxstat.rs_flags |= |
| 857 | (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0; |
| 858 | |
| 859 | if (ads.ds_rxstatus8 & AR_PreDelimCRCErr) |
| 860 | ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE; |
| 861 | if (ads.ds_rxstatus8 & AR_PostDelimCRCErr) |
| 862 | ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST; |
| 863 | if (ads.ds_rxstatus8 & AR_DecryptBusyErr) |
| 864 | ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY; |
| 865 | |
| 866 | if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) { |
| 867 | if (ads.ds_rxstatus8 & AR_CRCErr) |
| 868 | ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC; |
| 869 | else if (ads.ds_rxstatus8 & AR_PHYErr) { |
| 870 | ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY; |
| 871 | phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode); |
| 872 | ds->ds_rxstat.rs_phyerr = phyerr; |
| 873 | } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr) |
| 874 | ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT; |
| 875 | else if (ads.ds_rxstatus8 & AR_MichaelErr) |
| 876 | ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC; |
| 877 | } |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds, |
| 883 | u32 size, u32 flags) |
| 884 | { |
| 885 | struct ar5416_desc *ads = AR5416DESC(ds); |
| 886 | struct ath9k_hw_capabilities *pCap = &ah->ah_caps; |
| 887 | |
| 888 | ads->ds_ctl1 = size & AR_BufLen; |
| 889 | if (flags & ATH9K_RXDESC_INTREQ) |
| 890 | ads->ds_ctl1 |= AR_RxIntrReq; |
| 891 | |
| 892 | ads->ds_rxstatus8 &= ~AR_RxDone; |
| 893 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 894 | memset(&(ads->u), 0, sizeof(ads->u)); |
| 895 | |
| 896 | return true; |
| 897 | } |
| 898 | |
| 899 | bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set) |
| 900 | { |
| 901 | u32 reg; |
| 902 | |
| 903 | if (set) { |
| 904 | REG_SET_BIT(ah, AR_DIAG_SW, |
| 905 | (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); |
| 906 | |
| 907 | if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) { |
| 908 | REG_CLR_BIT(ah, AR_DIAG_SW, |
| 909 | (AR_DIAG_RX_DIS | |
| 910 | AR_DIAG_RX_ABORT)); |
| 911 | |
| 912 | reg = REG_READ(ah, AR_OBS_BUS_1); |
| 913 | DPRINTF(ah->ah_sc, ATH_DBG_FATAL, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 914 | "rx failed to go idle in 10 ms RXSM=0x%x\n", reg); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 915 | |
| 916 | return false; |
| 917 | } |
| 918 | } else { |
| 919 | REG_CLR_BIT(ah, AR_DIAG_SW, |
| 920 | (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); |
| 921 | } |
| 922 | |
| 923 | return true; |
| 924 | } |
| 925 | |
| 926 | void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp) |
| 927 | { |
| 928 | REG_WRITE(ah, AR_RXDP, rxdp); |
| 929 | } |
| 930 | |
| 931 | void ath9k_hw_rxena(struct ath_hal *ah) |
| 932 | { |
| 933 | REG_WRITE(ah, AR_CR, AR_CR_RXE); |
| 934 | } |
| 935 | |
| 936 | void ath9k_hw_startpcureceive(struct ath_hal *ah) |
| 937 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 938 | ath9k_enable_mib_counters(ah); |
| 939 | |
| 940 | ath9k_ani_reset(ah); |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 941 | |
Senthil Balasubramanian | 8aa15e1 | 2008-12-08 19:43:50 +0530 | [diff] [blame] | 942 | REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | void ath9k_hw_stoppcurecv(struct ath_hal *ah) |
| 946 | { |
| 947 | REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS); |
| 948 | |
| 949 | ath9k_hw_disable_mib_counters(ah); |
| 950 | } |
| 951 | |
| 952 | bool ath9k_hw_stopdmarecv(struct ath_hal *ah) |
| 953 | { |
| 954 | REG_WRITE(ah, AR_CR, AR_CR_RXD); |
| 955 | |
| 956 | if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) { |
| 957 | DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 958 | "dma failed to stop in 10ms\n" |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 959 | "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n", |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 960 | REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW)); |
| 961 | return false; |
| 962 | } else { |
| 963 | return true; |
| 964 | } |
| 965 | } |