blob: cb93d2375e8d094c268c5edbe366f7afa085cf37 [file] [log] [blame]
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04001/*
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. Rodriguezb622a722010-04-15 17:39:28 -040017#include "ar9003_mac.h"
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -040018
19static void ar9003_hw_rx_enable(struct ath_hw *hw)
20{
21 REG_WRITE(hw, AR_CR, 0);
22}
23
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -040024static void ar9003_hw_set_desc_link(void *ds, u32 ds_link)
25{
26 ((struct ar9003_txc *) ds)->link = ds_link;
27}
28
29static void ar9003_hw_get_desc_link(void *ds, u32 **ds_link)
30{
31 *ds_link = &((struct ar9003_txc *) ds)->link;
32}
33
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -040034static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
35{
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -040036 u32 isr = 0;
37 u32 mask2 = 0;
38 struct ath9k_hw_capabilities *pCap = &ah->caps;
39 u32 sync_cause = 0;
40 struct ath_common *common = ath9k_hw_common(ah);
41
42 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
43 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
44 == AR_RTC_STATUS_ON)
45 isr = REG_READ(ah, AR_ISR);
46 }
47
48 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & AR_INTR_SYNC_DEFAULT;
49
50 *masked = 0;
51
52 if (!isr && !sync_cause)
53 return false;
54
55 if (isr) {
56 if (isr & AR_ISR_BCNMISC) {
57 u32 isr2;
58 isr2 = REG_READ(ah, AR_ISR_S2);
59
60 mask2 |= ((isr2 & AR_ISR_S2_TIM) >>
61 MAP_ISR_S2_TIM);
62 mask2 |= ((isr2 & AR_ISR_S2_DTIM) >>
63 MAP_ISR_S2_DTIM);
64 mask2 |= ((isr2 & AR_ISR_S2_DTIMSYNC) >>
65 MAP_ISR_S2_DTIMSYNC);
66 mask2 |= ((isr2 & AR_ISR_S2_CABEND) >>
67 MAP_ISR_S2_CABEND);
68 mask2 |= ((isr2 & AR_ISR_S2_GTT) <<
69 MAP_ISR_S2_GTT);
70 mask2 |= ((isr2 & AR_ISR_S2_CST) <<
71 MAP_ISR_S2_CST);
72 mask2 |= ((isr2 & AR_ISR_S2_TSFOOR) >>
73 MAP_ISR_S2_TSFOOR);
74
75 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
76 REG_WRITE(ah, AR_ISR_S2, isr2);
77 isr &= ~AR_ISR_BCNMISC;
78 }
79 }
80
81 if ((pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED))
82 isr = REG_READ(ah, AR_ISR_RAC);
83
84 if (isr == 0xffffffff) {
85 *masked = 0;
86 return false;
87 }
88
89 *masked = isr & ATH9K_INT_COMMON;
90
91 if (ah->config.rx_intr_mitigation)
92 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
93 *masked |= ATH9K_INT_RXLP;
94
95 if (ah->config.tx_intr_mitigation)
96 if (isr & (AR_ISR_TXMINTR | AR_ISR_TXINTM))
97 *masked |= ATH9K_INT_TX;
98
99 if (isr & (AR_ISR_LP_RXOK | AR_ISR_RXERR))
100 *masked |= ATH9K_INT_RXLP;
101
102 if (isr & AR_ISR_HP_RXOK)
103 *masked |= ATH9K_INT_RXHP;
104
105 if (isr & (AR_ISR_TXOK | AR_ISR_TXERR | AR_ISR_TXEOL)) {
106 *masked |= ATH9K_INT_TX;
107
108 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
109 u32 s0, s1;
110 s0 = REG_READ(ah, AR_ISR_S0);
111 REG_WRITE(ah, AR_ISR_S0, s0);
112 s1 = REG_READ(ah, AR_ISR_S1);
113 REG_WRITE(ah, AR_ISR_S1, s1);
114
115 isr &= ~(AR_ISR_TXOK | AR_ISR_TXERR |
116 AR_ISR_TXEOL);
117 }
118 }
119
120 if (isr & AR_ISR_GENTMR) {
121 u32 s5;
122
123 if (pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)
124 s5 = REG_READ(ah, AR_ISR_S5_S);
125 else
126 s5 = REG_READ(ah, AR_ISR_S5);
127
128 ah->intr_gen_timer_trigger =
129 MS(s5, AR_ISR_S5_GENTIMER_TRIG);
130
131 ah->intr_gen_timer_thresh =
132 MS(s5, AR_ISR_S5_GENTIMER_THRESH);
133
134 if (ah->intr_gen_timer_trigger)
135 *masked |= ATH9K_INT_GENTIMER;
136
137 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
138 REG_WRITE(ah, AR_ISR_S5, s5);
139 isr &= ~AR_ISR_GENTMR;
140 }
141
142 }
143
144 *masked |= mask2;
145
146 if (!(pCap->hw_caps & ATH9K_HW_CAP_RAC_SUPPORTED)) {
147 REG_WRITE(ah, AR_ISR, isr);
148
149 (void) REG_READ(ah, AR_ISR);
150 }
151 }
152
153 if (sync_cause) {
154 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
155 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
156 REG_WRITE(ah, AR_RC, 0);
157 *masked |= ATH9K_INT_FATAL;
158 }
159
160 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
161 ath_print(common, ATH_DBG_INTERRUPT,
162 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
163
164 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
165 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
166
167 }
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400168 return true;
169}
170
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400171static void ar9003_hw_fill_txdesc(struct ath_hw *ah, void *ds, u32 seglen,
172 bool is_firstseg, bool is_lastseg,
173 const void *ds0, dma_addr_t buf_addr,
174 unsigned int qcu)
175{
176}
177
178static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds,
179 struct ath_tx_status *ts)
180{
181 return 0;
182}
183static void ar9003_hw_set11n_txdesc(struct ath_hw *ah, void *ds,
184 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
185 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
186{
187
188}
189
190static void ar9003_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
191 void *lastds,
192 u32 durUpdateEn, u32 rtsctsRate,
193 u32 rtsctsDuration,
194 struct ath9k_11n_rate_series series[],
195 u32 nseries, u32 flags)
196{
197
198}
199
200static void ar9003_hw_set11n_aggr_first(struct ath_hw *ah, void *ds,
201 u32 aggrLen)
202{
203
204}
205
206static void ar9003_hw_set11n_aggr_middle(struct ath_hw *ah, void *ds,
207 u32 numDelims)
208{
209
210}
211
212static void ar9003_hw_set11n_aggr_last(struct ath_hw *ah, void *ds)
213{
214
215}
216
217static void ar9003_hw_clr11n_aggr(struct ath_hw *ah, void *ds)
218{
219
220}
221
222static void ar9003_hw_set11n_burstduration(struct ath_hw *ah, void *ds,
223 u32 burstDuration)
224{
225
226}
227
228static void ar9003_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
229 u32 vmf)
230{
231
232}
233
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -0400234void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
235{
236 struct ath_hw_ops *ops = ath9k_hw_ops(hw);
237
238 ops->rx_enable = ar9003_hw_rx_enable;
Vasanthakumar Thiagarajan87d5efb2010-04-15 17:38:43 -0400239 ops->set_desc_link = ar9003_hw_set_desc_link;
240 ops->get_desc_link = ar9003_hw_get_desc_link;
Vasanthakumar Thiagarajan55e82df2010-04-15 17:39:06 -0400241 ops->get_isr = ar9003_hw_get_isr;
Vasanthakumar Thiagarajancc610ac02010-04-15 17:39:26 -0400242 ops->fill_txdesc = ar9003_hw_fill_txdesc;
243 ops->proc_txdesc = ar9003_hw_proc_txdesc;
244 ops->set11n_txdesc = ar9003_hw_set11n_txdesc;
245 ops->set11n_ratescenario = ar9003_hw_set11n_ratescenario;
246 ops->set11n_aggr_first = ar9003_hw_set11n_aggr_first;
247 ops->set11n_aggr_middle = ar9003_hw_set11n_aggr_middle;
248 ops->set11n_aggr_last = ar9003_hw_set11n_aggr_last;
249 ops->clr11n_aggr = ar9003_hw_clr11n_aggr;
250 ops->set11n_burstduration = ar9003_hw_set11n_burstduration;
251 ops->set11n_virtualmorefrag = ar9003_hw_set11n_virtualmorefrag;
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -0400252}
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400253
254void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
255{
256 REG_WRITE(ah, AR_DATABUF_SIZE, buf_size & AR_DATABUF_SIZE_MASK);
257}
258EXPORT_SYMBOL(ath9k_hw_set_rx_bufsize);
259
260void ath9k_hw_addrxbuf_edma(struct ath_hw *ah, u32 rxdp,
261 enum ath9k_rx_qtype qtype)
262{
263 if (qtype == ATH9K_RX_QUEUE_HP)
264 REG_WRITE(ah, AR_HP_RXDP, rxdp);
265 else
266 REG_WRITE(ah, AR_LP_RXDP, rxdp);
267}
268EXPORT_SYMBOL(ath9k_hw_addrxbuf_edma);
269
270int ath9k_hw_process_rxdesc_edma(struct ath_hw *ah, struct ath_rx_status *rxs,
271 void *buf_addr)
272{
273 struct ar9003_rxs *rxsp = (struct ar9003_rxs *) buf_addr;
274 unsigned int phyerr;
275
276 /* TODO: byte swap on big endian for ar9300_10 */
277
278 if ((rxsp->status11 & AR_RxDone) == 0)
279 return -EINPROGRESS;
280
281 if (MS(rxsp->ds_info, AR_DescId) != 0x168c)
282 return -EINVAL;
283
284 if ((rxsp->ds_info & (AR_TxRxDesc | AR_CtrlStat)) != 0)
285 return -EINPROGRESS;
286
Felix Fietkaub5c804752010-04-15 17:38:48 -0400287 if (!rxs)
288 return 0;
289
Vasanthakumar Thiagarajanad7b8062010-04-15 17:38:28 -0400290 rxs->rs_status = 0;
291 rxs->rs_flags = 0;
292
293 rxs->rs_datalen = rxsp->status2 & AR_DataLen;
294 rxs->rs_tstamp = rxsp->status3;
295
296 /* XXX: Keycache */
297 rxs->rs_rssi = MS(rxsp->status5, AR_RxRSSICombined);
298 rxs->rs_rssi_ctl0 = MS(rxsp->status1, AR_RxRSSIAnt00);
299 rxs->rs_rssi_ctl1 = MS(rxsp->status1, AR_RxRSSIAnt01);
300 rxs->rs_rssi_ctl2 = MS(rxsp->status1, AR_RxRSSIAnt02);
301 rxs->rs_rssi_ext0 = MS(rxsp->status5, AR_RxRSSIAnt10);
302 rxs->rs_rssi_ext1 = MS(rxsp->status5, AR_RxRSSIAnt11);
303 rxs->rs_rssi_ext2 = MS(rxsp->status5, AR_RxRSSIAnt12);
304
305 if (rxsp->status11 & AR_RxKeyIdxValid)
306 rxs->rs_keyix = MS(rxsp->status11, AR_KeyIdx);
307 else
308 rxs->rs_keyix = ATH9K_RXKEYIX_INVALID;
309
310 rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
311 rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
312
313 rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
314 rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
315 rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
316 rxs->rs_flags = (rxsp->status4 & AR_GI) ? ATH9K_RX_GI : 0;
317 rxs->rs_flags |= (rxsp->status4 & AR_2040) ? ATH9K_RX_2040 : 0;
318
319 rxs->evm0 = rxsp->status6;
320 rxs->evm1 = rxsp->status7;
321 rxs->evm2 = rxsp->status8;
322 rxs->evm3 = rxsp->status9;
323 rxs->evm4 = (rxsp->status10 & 0xffff);
324
325 if (rxsp->status11 & AR_PreDelimCRCErr)
326 rxs->rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
327
328 if (rxsp->status11 & AR_PostDelimCRCErr)
329 rxs->rs_flags |= ATH9K_RX_DELIM_CRC_POST;
330
331 if (rxsp->status11 & AR_DecryptBusyErr)
332 rxs->rs_flags |= ATH9K_RX_DECRYPT_BUSY;
333
334 if ((rxsp->status11 & AR_RxFrameOK) == 0) {
335 if (rxsp->status11 & AR_CRCErr) {
336 rxs->rs_status |= ATH9K_RXERR_CRC;
337 } else if (rxsp->status11 & AR_PHYErr) {
338 rxs->rs_status |= ATH9K_RXERR_PHY;
339 phyerr = MS(rxsp->status11, AR_PHYErrCode);
340 rxs->rs_phyerr = phyerr;
341 } else if (rxsp->status11 & AR_DecryptCRCErr) {
342 rxs->rs_status |= ATH9K_RXERR_DECRYPT;
343 } else if (rxsp->status11 & AR_MichaelErr) {
344 rxs->rs_status |= ATH9K_RXERR_MIC;
345 }
346 }
347
348 return 0;
349}
350EXPORT_SYMBOL(ath9k_hw_process_rxdesc_edma);
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400351
352void ath9k_hw_reset_txstatus_ring(struct ath_hw *ah)
353{
354 ah->ts_tail = 0;
355
356 memset((void *) ah->ts_ring, 0,
357 ah->ts_size * sizeof(struct ar9003_txs));
358
359 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
360 "TS Start 0x%x End 0x%x Virt %p, Size %d\n",
361 ah->ts_paddr_start, ah->ts_paddr_end,
362 ah->ts_ring, ah->ts_size);
363
364 REG_WRITE(ah, AR_Q_STATUS_RING_START, ah->ts_paddr_start);
365 REG_WRITE(ah, AR_Q_STATUS_RING_END, ah->ts_paddr_end);
366}
367
368void ath9k_hw_setup_statusring(struct ath_hw *ah, void *ts_start,
369 u32 ts_paddr_start,
370 u8 size)
371{
372
373 ah->ts_paddr_start = ts_paddr_start;
374 ah->ts_paddr_end = ts_paddr_start + (size * sizeof(struct ar9003_txs));
375 ah->ts_size = size;
376 ah->ts_ring = (struct ar9003_txs *) ts_start;
377
378 ath9k_hw_reset_txstatus_ring(ah);
379}
380EXPORT_SYMBOL(ath9k_hw_setup_statusring);