1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/export.h>
32
33#include "rt2x00.h"
34#include "rt2x00mmio.h"
35#include "rt2800.h"
36#include "rt2800lib.h"
37#include "rt2800mmio.h"
38
39
40
41
42__le32 *rt2800mmio_get_txwi(struct queue_entry *entry)
43{
44 return (__le32 *) entry->skb->data;
45}
46EXPORT_SYMBOL_GPL(rt2800mmio_get_txwi);
47
48void rt2800mmio_write_tx_desc(struct queue_entry *entry,
49 struct txentry_desc *txdesc)
50{
51 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
52 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
53 __le32 *txd = entry_priv->desc;
54 u32 word;
55 const unsigned int txwi_size = entry->queue->winfo_size;
56
57
58
59
60
61
62
63
64
65
66
67
68 word = 0;
69 rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
70 rt2x00_desc_write(txd, 0, word);
71
72 word = 0;
73 rt2x00_set_field32(&word, TXD_W1_SD_LEN1, entry->skb->len);
74 rt2x00_set_field32(&word, TXD_W1_LAST_SEC1,
75 !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
76 rt2x00_set_field32(&word, TXD_W1_BURST,
77 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
78 rt2x00_set_field32(&word, TXD_W1_SD_LEN0, txwi_size);
79 rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0);
80 rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0);
81 rt2x00_desc_write(txd, 1, word);
82
83 word = 0;
84 rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
85 skbdesc->skb_dma + txwi_size);
86 rt2x00_desc_write(txd, 2, word);
87
88 word = 0;
89 rt2x00_set_field32(&word, TXD_W3_WIV,
90 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
91 rt2x00_set_field32(&word, TXD_W3_QSEL, 2);
92 rt2x00_desc_write(txd, 3, word);
93
94
95
96
97 skbdesc->desc = txd;
98 skbdesc->desc_len = TXD_DESC_SIZE;
99}
100EXPORT_SYMBOL_GPL(rt2800mmio_write_tx_desc);
101
102
103
104
105void rt2800mmio_fill_rxdone(struct queue_entry *entry,
106 struct rxdone_entry_desc *rxdesc)
107{
108 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
109 __le32 *rxd = entry_priv->desc;
110 u32 word;
111
112 word = rt2x00_desc_read(rxd, 3);
113
114 if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
115 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
116
117
118
119
120
121
122 rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
123
124 if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
125
126
127
128
129
130
131 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
132
133
134
135
136
137 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
138
139 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS) {
140 rxdesc->flags |= RX_FLAG_DECRYPTED;
141 } else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC) {
142
143
144
145
146
147
148 rxdesc->flags |= RX_FLAG_DECRYPTED;
149
150 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
151 }
152 }
153
154 if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
155 rxdesc->dev_flags |= RXDONE_MY_BSS;
156
157 if (rt2x00_get_field32(word, RXD_W3_L2PAD))
158 rxdesc->dev_flags |= RXDONE_L2PAD;
159
160
161
162
163 rt2800_process_rxwi(entry, rxdesc);
164}
165EXPORT_SYMBOL_GPL(rt2800mmio_fill_rxdone);
166
167
168
169
170static void rt2800mmio_wakeup(struct rt2x00_dev *rt2x00dev)
171{
172 struct ieee80211_conf conf = { .flags = 0 };
173 struct rt2x00lib_conf libconf = { .conf = &conf };
174
175 rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
176}
177
178static bool rt2800mmio_txdone_entry_check(struct queue_entry *entry, u32 status)
179{
180 __le32 *txwi;
181 u32 word;
182 int wcid, tx_wcid;
183
184 wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
185
186 txwi = rt2800_drv_get_txwi(entry);
187 word = rt2x00_desc_read(txwi, 1);
188 tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
189
190 return (tx_wcid == wcid);
191}
192
193static bool rt2800mmio_txdone_find_entry(struct queue_entry *entry, void *data)
194{
195 u32 status = *(u32 *)data;
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210 if (rt2800mmio_txdone_entry_check(entry, status) &&
211 !test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
212
213
214
215
216 entry->status = status;
217 set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
218 return true;
219 }
220
221
222 return false;
223}
224
225static bool rt2800mmio_txdone_match_first(struct queue_entry *entry, void *data)
226{
227 u32 status = *(u32 *)data;
228
229
230
231
232
233 if (!test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
234
235
236
237
238 entry->status = status;
239 set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
240 return true;
241 }
242
243
244 return false;
245}
246static bool rt2800mmio_txdone_release_entries(struct queue_entry *entry,
247 void *data)
248{
249 if (test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
250 rt2800_txdone_entry(entry, entry->status,
251 rt2800mmio_get_txwi(entry), true);
252 return false;
253 }
254
255
256 return true;
257}
258
259static bool rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
260{
261 struct data_queue *queue;
262 u32 status;
263 u8 qid;
264 int max_tx_done = 16;
265
266 while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
267 qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
268 if (unlikely(qid >= QID_RX)) {
269
270
271
272
273 rt2x00_warn(rt2x00dev, "Got TX status report with unexpected pid %u, dropping\n",
274 qid);
275 break;
276 }
277
278 queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
279 if (unlikely(queue == NULL)) {
280
281
282
283
284 rt2x00_warn(rt2x00dev, "Got TX status for an unavailable queue %u, dropping\n",
285 qid);
286 break;
287 }
288
289 if (unlikely(rt2x00queue_empty(queue))) {
290
291
292
293
294 rt2x00_warn(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
295 qid);
296 break;
297 }
298
299
300
301
302
303 if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
304 Q_INDEX, &status,
305 rt2800mmio_txdone_find_entry)) {
306
307
308
309
310 if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
311 Q_INDEX, &status,
312 rt2800mmio_txdone_match_first)) {
313 rt2x00_warn(rt2x00dev, "No frame found for TX status on queue %u, dropping\n",
314 qid);
315 break;
316 }
317 }
318
319
320
321
322 rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
323 Q_INDEX, NULL,
324 rt2800mmio_txdone_release_entries);
325
326 if (--max_tx_done == 0)
327 break;
328 }
329
330 return !max_tx_done;
331}
332
333static inline void rt2800mmio_enable_interrupt(struct rt2x00_dev *rt2x00dev,
334 struct rt2x00_field32 irq_field)
335{
336 u32 reg;
337
338
339
340
341
342 spin_lock_irq(&rt2x00dev->irqmask_lock);
343 reg = rt2x00mmio_register_read(rt2x00dev, INT_MASK_CSR);
344 rt2x00_set_field32(®, irq_field, 1);
345 rt2x00mmio_register_write(rt2x00dev, INT_MASK_CSR, reg);
346 spin_unlock_irq(&rt2x00dev->irqmask_lock);
347}
348
349void rt2800mmio_txstatus_tasklet(unsigned long data)
350{
351 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
352 if (rt2800mmio_txdone(rt2x00dev))
353 tasklet_schedule(&rt2x00dev->txstatus_tasklet);
354
355
356
357
358
359
360}
361EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
362
363void rt2800mmio_pretbtt_tasklet(unsigned long data)
364{
365 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
366 rt2x00lib_pretbtt(rt2x00dev);
367 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
368 rt2800mmio_enable_interrupt(rt2x00dev, INT_MASK_CSR_PRE_TBTT);
369}
370EXPORT_SYMBOL_GPL(rt2800mmio_pretbtt_tasklet);
371
372void rt2800mmio_tbtt_tasklet(unsigned long data)
373{
374 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
375 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
376 u32 reg;
377
378 rt2x00lib_beacondone(rt2x00dev);
379
380 if (rt2x00dev->intf_ap_count) {
381
382
383
384
385
386
387 if (drv_data->tbtt_tick == (BCN_TBTT_OFFSET - 2)) {
388 reg = rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG);
389 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL,
390 (rt2x00dev->beacon_int * 16) - 1);
391 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
392 } else if (drv_data->tbtt_tick == (BCN_TBTT_OFFSET - 1)) {
393 reg = rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG);
394 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL,
395 (rt2x00dev->beacon_int * 16));
396 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
397 }
398 drv_data->tbtt_tick++;
399 drv_data->tbtt_tick %= BCN_TBTT_OFFSET;
400 }
401
402 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
403 rt2800mmio_enable_interrupt(rt2x00dev, INT_MASK_CSR_TBTT);
404}
405EXPORT_SYMBOL_GPL(rt2800mmio_tbtt_tasklet);
406
407void rt2800mmio_rxdone_tasklet(unsigned long data)
408{
409 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
410 if (rt2x00mmio_rxdone(rt2x00dev))
411 tasklet_schedule(&rt2x00dev->rxdone_tasklet);
412 else if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
413 rt2800mmio_enable_interrupt(rt2x00dev, INT_MASK_CSR_RX_DONE);
414}
415EXPORT_SYMBOL_GPL(rt2800mmio_rxdone_tasklet);
416
417void rt2800mmio_autowake_tasklet(unsigned long data)
418{
419 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
420 rt2800mmio_wakeup(rt2x00dev);
421 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
422 rt2800mmio_enable_interrupt(rt2x00dev,
423 INT_MASK_CSR_AUTO_WAKEUP);
424}
425EXPORT_SYMBOL_GPL(rt2800mmio_autowake_tasklet);
426
427static void rt2800mmio_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
428{
429 u32 status;
430 int i;
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450 for (i = 0; i < rt2x00dev->tx->limit; i++) {
451 status = rt2x00mmio_register_read(rt2x00dev, TX_STA_FIFO);
452
453 if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
454 break;
455
456 if (!kfifo_put(&rt2x00dev->txstatus_fifo, &status)) {
457 gmb();
458 rt2x00_warn(rt2x00dev, "TX status FIFO overrun, drop tx status report\n");
459 break;
460 }
461 }
462
463
464 tasklet_schedule(&rt2x00dev->txstatus_tasklet);
465}
466
467irqreturn_t rt2800mmio_interrupt(int irq, void *dev_instance)
468{
469 struct rt2x00_dev *rt2x00dev = dev_instance;
470 u32 reg, mask;
471
472
473 reg = rt2x00mmio_register_read(rt2x00dev, INT_SOURCE_CSR);
474 rt2x00mmio_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
475
476 if (!reg)
477 return IRQ_NONE;
478
479 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
480 return IRQ_HANDLED;
481
482
483
484
485
486
487 mask = ~reg;
488
489 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
490 rt2800mmio_txstatus_interrupt(rt2x00dev);
491
492
493
494 rt2x00_set_field32(&mask, INT_MASK_CSR_TX_FIFO_STATUS, 1);
495 }
496
497 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
498 tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
499
500 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TBTT))
501 tasklet_hi_schedule(&rt2x00dev->tbtt_tasklet);
502
503 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE))
504 tasklet_schedule(&rt2x00dev->rxdone_tasklet);
505
506 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_AUTO_WAKEUP))
507 tasklet_schedule(&rt2x00dev->autowake_tasklet);
508
509
510
511
512
513 spin_lock(&rt2x00dev->irqmask_lock);
514 reg = rt2x00mmio_register_read(rt2x00dev, INT_MASK_CSR);
515 reg &= mask;
516 rt2x00mmio_register_write(rt2x00dev, INT_MASK_CSR, reg);
517 spin_unlock(&rt2x00dev->irqmask_lock);
518
519 return IRQ_HANDLED;
520}
521EXPORT_SYMBOL_GPL(rt2800mmio_interrupt);
522
523void rt2800mmio_toggle_irq(struct rt2x00_dev *rt2x00dev,
524 enum dev_state state)
525{
526 u32 reg;
527 unsigned long flags;
528
529
530
531
532
533 if (state == STATE_RADIO_IRQ_ON) {
534 reg = rt2x00mmio_register_read(rt2x00dev, INT_SOURCE_CSR);
535 rt2x00mmio_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
536 }
537
538 spin_lock_irqsave(&rt2x00dev->irqmask_lock, flags);
539 reg = 0;
540 if (state == STATE_RADIO_IRQ_ON) {
541 rt2x00_set_field32(®, INT_MASK_CSR_RX_DONE, 1);
542 rt2x00_set_field32(®, INT_MASK_CSR_TBTT, 1);
543 rt2x00_set_field32(®, INT_MASK_CSR_PRE_TBTT, 1);
544 rt2x00_set_field32(®, INT_MASK_CSR_TX_FIFO_STATUS, 1);
545 rt2x00_set_field32(®, INT_MASK_CSR_AUTO_WAKEUP, 1);
546 }
547 rt2x00mmio_register_write(rt2x00dev, INT_MASK_CSR, reg);
548 spin_unlock_irqrestore(&rt2x00dev->irqmask_lock, flags);
549
550 if (state == STATE_RADIO_IRQ_OFF) {
551
552
553
554 tasklet_kill(&rt2x00dev->txstatus_tasklet);
555 tasklet_kill(&rt2x00dev->rxdone_tasklet);
556 tasklet_kill(&rt2x00dev->autowake_tasklet);
557 tasklet_kill(&rt2x00dev->tbtt_tasklet);
558 tasklet_kill(&rt2x00dev->pretbtt_tasklet);
559 }
560}
561EXPORT_SYMBOL_GPL(rt2800mmio_toggle_irq);
562
563
564
565
566void rt2800mmio_start_queue(struct data_queue *queue)
567{
568 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
569 u32 reg;
570
571 switch (queue->qid) {
572 case QID_RX:
573 reg = rt2x00mmio_register_read(rt2x00dev, MAC_SYS_CTRL);
574 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1);
575 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
576 break;
577 case QID_BEACON:
578 reg = rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG);
579 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1);
580 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 1);
581 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1);
582 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
583
584 reg = rt2x00mmio_register_read(rt2x00dev, INT_TIMER_EN);
585 rt2x00_set_field32(®, INT_TIMER_EN_PRE_TBTT_TIMER, 1);
586 rt2x00mmio_register_write(rt2x00dev, INT_TIMER_EN, reg);
587 break;
588 default:
589 break;
590 }
591}
592EXPORT_SYMBOL_GPL(rt2800mmio_start_queue);
593
594void rt2800mmio_kick_queue(struct data_queue *queue)
595{
596 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
597 struct queue_entry *entry;
598
599 switch (queue->qid) {
600 case QID_AC_VO:
601 case QID_AC_VI:
602 case QID_AC_BE:
603 case QID_AC_BK:
604 entry = rt2x00queue_get_entry(queue, Q_INDEX);
605 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX(queue->qid),
606 entry->entry_idx);
607 break;
608 case QID_MGMT:
609 entry = rt2x00queue_get_entry(queue, Q_INDEX);
610 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX(5),
611 entry->entry_idx);
612 break;
613 default:
614 break;
615 }
616}
617EXPORT_SYMBOL_GPL(rt2800mmio_kick_queue);
618
619void rt2800mmio_stop_queue(struct data_queue *queue)
620{
621 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
622 u32 reg;
623
624 switch (queue->qid) {
625 case QID_RX:
626 reg = rt2x00mmio_register_read(rt2x00dev, MAC_SYS_CTRL);
627 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0);
628 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
629 break;
630 case QID_BEACON:
631 reg = rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG);
632 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0);
633 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0);
634 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
635 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
636
637 reg = rt2x00mmio_register_read(rt2x00dev, INT_TIMER_EN);
638 rt2x00_set_field32(®, INT_TIMER_EN_PRE_TBTT_TIMER, 0);
639 rt2x00mmio_register_write(rt2x00dev, INT_TIMER_EN, reg);
640
641
642
643
644
645
646 tasklet_kill(&rt2x00dev->tbtt_tasklet);
647 tasklet_kill(&rt2x00dev->pretbtt_tasklet);
648
649 break;
650 default:
651 break;
652 }
653}
654EXPORT_SYMBOL_GPL(rt2800mmio_stop_queue);
655
656void rt2800mmio_queue_init(struct data_queue *queue)
657{
658 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
659 unsigned short txwi_size, rxwi_size;
660
661 rt2800_get_txwi_rxwi_size(rt2x00dev, &txwi_size, &rxwi_size);
662
663 switch (queue->qid) {
664 case QID_RX:
665 queue->limit = 128;
666 queue->data_size = AGGREGATION_SIZE;
667 queue->desc_size = RXD_DESC_SIZE;
668 queue->winfo_size = rxwi_size;
669 queue->priv_size = sizeof(struct queue_entry_priv_mmio);
670 break;
671
672 case QID_AC_VO:
673 case QID_AC_VI:
674 case QID_AC_BE:
675 case QID_AC_BK:
676 queue->limit = 64;
677 queue->data_size = AGGREGATION_SIZE;
678 queue->desc_size = TXD_DESC_SIZE;
679 queue->winfo_size = txwi_size;
680 queue->priv_size = sizeof(struct queue_entry_priv_mmio);
681 break;
682
683 case QID_BEACON:
684 queue->limit = 8;
685 queue->data_size = 0;
686 queue->desc_size = TXD_DESC_SIZE;
687 queue->winfo_size = txwi_size;
688 queue->priv_size = sizeof(struct queue_entry_priv_mmio);
689 break;
690
691 case QID_ATIM:
692
693 default:
694 BUG();
695 break;
696 }
697}
698EXPORT_SYMBOL_GPL(rt2800mmio_queue_init);
699
700
701
702
703bool rt2800mmio_get_entry_state(struct queue_entry *entry)
704{
705 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
706 u32 word;
707
708 if (entry->queue->qid == QID_RX) {
709 word = rt2x00_desc_read(entry_priv->desc, 1);
710
711 return (!rt2x00_get_field32(word, RXD_W1_DMA_DONE));
712 } else {
713 word = rt2x00_desc_read(entry_priv->desc, 1);
714
715 return (!rt2x00_get_field32(word, TXD_W1_DMA_DONE));
716 }
717}
718EXPORT_SYMBOL_GPL(rt2800mmio_get_entry_state);
719
720void rt2800mmio_clear_entry(struct queue_entry *entry)
721{
722 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
723 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
724 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
725 u32 word;
726
727 if (entry->queue->qid == QID_RX) {
728 word = rt2x00_desc_read(entry_priv->desc, 0);
729 rt2x00_set_field32(&word, RXD_W0_SDP0, skbdesc->skb_dma);
730 rt2x00_desc_write(entry_priv->desc, 0, word);
731
732 word = rt2x00_desc_read(entry_priv->desc, 1);
733 rt2x00_set_field32(&word, RXD_W1_DMA_DONE, 0);
734 rt2x00_desc_write(entry_priv->desc, 1, word);
735
736
737
738
739
740 rt2x00mmio_register_write(rt2x00dev, RX_CRX_IDX,
741 entry->entry_idx);
742 } else {
743 word = rt2x00_desc_read(entry_priv->desc, 1);
744 rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 1);
745 rt2x00_desc_write(entry_priv->desc, 1, word);
746 }
747}
748EXPORT_SYMBOL_GPL(rt2800mmio_clear_entry);
749
750int rt2800mmio_init_queues(struct rt2x00_dev *rt2x00dev)
751{
752 struct queue_entry_priv_mmio *entry_priv;
753
754
755
756
757 entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
758 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR0,
759 entry_priv->desc_dma);
760 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT0,
761 rt2x00dev->tx[0].limit);
762 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX0, 0);
763 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX0, 0);
764
765 entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
766 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR1,
767 entry_priv->desc_dma);
768 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT1,
769 rt2x00dev->tx[1].limit);
770 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX1, 0);
771 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX1, 0);
772
773 entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
774 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR2,
775 entry_priv->desc_dma);
776 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT2,
777 rt2x00dev->tx[2].limit);
778 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX2, 0);
779 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX2, 0);
780
781 entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
782 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR3,
783 entry_priv->desc_dma);
784 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT3,
785 rt2x00dev->tx[3].limit);
786 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX3, 0);
787 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX3, 0);
788
789 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR4, 0);
790 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT4, 0);
791 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX4, 0);
792 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX4, 0);
793
794 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR5, 0);
795 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT5, 0);
796 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX5, 0);
797 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX5, 0);
798
799 entry_priv = rt2x00dev->rx->entries[0].priv_data;
800 rt2x00mmio_register_write(rt2x00dev, RX_BASE_PTR,
801 entry_priv->desc_dma);
802 rt2x00mmio_register_write(rt2x00dev, RX_MAX_CNT,
803 rt2x00dev->rx[0].limit);
804 rt2x00mmio_register_write(rt2x00dev, RX_CRX_IDX,
805 rt2x00dev->rx[0].limit - 1);
806 rt2x00mmio_register_write(rt2x00dev, RX_DRX_IDX, 0);
807
808 rt2800_disable_wpdma(rt2x00dev);
809
810 rt2x00mmio_register_write(rt2x00dev, DELAY_INT_CFG, 0);
811
812 return 0;
813}
814EXPORT_SYMBOL_GPL(rt2800mmio_init_queues);
815
816int rt2800mmio_init_registers(struct rt2x00_dev *rt2x00dev)
817{
818 u32 reg;
819
820
821
822
823 reg = rt2x00mmio_register_read(rt2x00dev, WPDMA_RST_IDX);
824 rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX0, 1);
825 rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX1, 1);
826 rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX2, 1);
827 rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX3, 1);
828 rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX4, 1);
829 rt2x00_set_field32(®, WPDMA_RST_IDX_DTX_IDX5, 1);
830 rt2x00_set_field32(®, WPDMA_RST_IDX_DRX_IDX0, 1);
831 rt2x00mmio_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
832
833 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
834 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
835
836 if (rt2x00_is_pcie(rt2x00dev) &&
837 (rt2x00_rt(rt2x00dev, RT3090) ||
838 rt2x00_rt(rt2x00dev, RT3390) ||
839 rt2x00_rt(rt2x00dev, RT3572) ||
840 rt2x00_rt(rt2x00dev, RT3593) ||
841 rt2x00_rt(rt2x00dev, RT5390) ||
842 rt2x00_rt(rt2x00dev, RT5392) ||
843 rt2x00_rt(rt2x00dev, RT5592))) {
844 reg = rt2x00mmio_register_read(rt2x00dev, AUX_CTRL);
845 rt2x00_set_field32(®, AUX_CTRL_FORCE_PCIE_CLK, 1);
846 rt2x00_set_field32(®, AUX_CTRL_WAKE_PCIE_EN, 1);
847 rt2x00mmio_register_write(rt2x00dev, AUX_CTRL, reg);
848 }
849
850 rt2x00mmio_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
851
852 reg = 0;
853 rt2x00_set_field32(®, MAC_SYS_CTRL_RESET_CSR, 1);
854 rt2x00_set_field32(®, MAC_SYS_CTRL_RESET_BBP, 1);
855 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
856
857 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
858
859 return 0;
860}
861EXPORT_SYMBOL_GPL(rt2800mmio_init_registers);
862
863
864
865
866int rt2800mmio_enable_radio(struct rt2x00_dev *rt2x00dev)
867{
868
869 rt2800_wait_wpdma_ready(rt2x00dev);
870
871 if (unlikely(rt2800mmio_init_queues(rt2x00dev)))
872 return -EIO;
873
874 return rt2800_enable_radio(rt2x00dev);
875}
876EXPORT_SYMBOL_GPL(rt2800mmio_enable_radio);
877
878MODULE_AUTHOR(DRV_PROJECT);
879MODULE_VERSION(DRV_VERSION);
880MODULE_DESCRIPTION("rt2800 MMIO library");
881MODULE_LICENSE("GPL");
882