net: ptp: do not reimplement PTP/BPF classifier
[linux/fpc-iii.git] / drivers / net / wireless / rt2x00 / rt2800mmio.c
blobde4790b41be7d64a7c3a9651e27451c3f76183d6
1 /* Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
2 * Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
3 * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
5 * Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
6 * Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
7 * Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
8 * Copyright (C) 2009 Bart Zolnierkiewicz <bzolnier@gmail.com>
9 * <http://rt2x00.serialmonkey.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* Module: rt2800mmio
26 * Abstract: rt2800 MMIO device routines.
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/export.h>
33 #include "rt2x00.h"
34 #include "rt2x00mmio.h"
35 #include "rt2800.h"
36 #include "rt2800lib.h"
37 #include "rt2800mmio.h"
40 * TX descriptor initialization
42 __le32 *rt2800mmio_get_txwi(struct queue_entry *entry)
44 return (__le32 *) entry->skb->data;
46 EXPORT_SYMBOL_GPL(rt2800mmio_get_txwi);
48 void rt2800mmio_write_tx_desc(struct queue_entry *entry,
49 struct txentry_desc *txdesc)
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;
58 * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1
59 * must contains a TXWI structure + 802.11 header + padding + 802.11
60 * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and
61 * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11
62 * data. It means that LAST_SEC0 is always 0.
66 * Initialize TX descriptor
68 word = 0;
69 rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
70 rt2x00_desc_write(txd, 0, word);
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);
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);
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);
95 * Register descriptor details in skb frame descriptor.
97 skbdesc->desc = txd;
98 skbdesc->desc_len = TXD_DESC_SIZE;
100 EXPORT_SYMBOL_GPL(rt2800mmio_write_tx_desc);
103 * RX control handlers
105 void rt2800mmio_fill_rxdone(struct queue_entry *entry,
106 struct rxdone_entry_desc *rxdesc)
108 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
109 __le32 *rxd = entry_priv->desc;
110 u32 word;
112 rt2x00_desc_read(rxd, 3, &word);
114 if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
115 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
118 * Unfortunately we don't know the cipher type used during
119 * decryption. This prevents us from correct providing
120 * correct statistics through debugfs.
122 rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
124 if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
126 * Hardware has stripped IV/EIV data from 802.11 frame during
127 * decryption. Unfortunately the descriptor doesn't contain
128 * any fields with the EIV/IV data either, so they can't
129 * be restored by rt2x00lib.
131 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
134 * The hardware has already checked the Michael Mic and has
135 * stripped it from the frame. Signal this to mac80211.
137 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
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 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
145 if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
146 rxdesc->dev_flags |= RXDONE_MY_BSS;
148 if (rt2x00_get_field32(word, RXD_W3_L2PAD))
149 rxdesc->dev_flags |= RXDONE_L2PAD;
152 * Process the RXWI structure that is at the start of the buffer.
154 rt2800_process_rxwi(entry, rxdesc);
156 EXPORT_SYMBOL_GPL(rt2800mmio_fill_rxdone);
159 * Interrupt functions.
161 static void rt2800mmio_wakeup(struct rt2x00_dev *rt2x00dev)
163 struct ieee80211_conf conf = { .flags = 0 };
164 struct rt2x00lib_conf libconf = { .conf = &conf };
166 rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
169 static bool rt2800mmio_txdone_entry_check(struct queue_entry *entry, u32 status)
171 __le32 *txwi;
172 u32 word;
173 int wcid, tx_wcid;
175 wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
177 txwi = rt2800_drv_get_txwi(entry);
178 rt2x00_desc_read(txwi, 1, &word);
179 tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
181 return (tx_wcid == wcid);
184 static bool rt2800mmio_txdone_find_entry(struct queue_entry *entry, void *data)
186 u32 status = *(u32 *)data;
189 * rt2800pci hardware might reorder frames when exchanging traffic
190 * with multiple BA enabled STAs.
192 * For example, a tx queue
193 * [ STA1 | STA2 | STA1 | STA2 ]
194 * can result in tx status reports
195 * [ STA1 | STA1 | STA2 | STA2 ]
196 * when the hw decides to aggregate the frames for STA1 into one AMPDU.
198 * To mitigate this effect, associate the tx status to the first frame
199 * in the tx queue with a matching wcid.
201 if (rt2800mmio_txdone_entry_check(entry, status) &&
202 !test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
204 * Got a matching frame, associate the tx status with
205 * the frame
207 entry->status = status;
208 set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
209 return true;
212 /* Check the next frame */
213 return false;
216 static bool rt2800mmio_txdone_match_first(struct queue_entry *entry, void *data)
218 u32 status = *(u32 *)data;
221 * Find the first frame without tx status and assign this status to it
222 * regardless if it matches or not.
224 if (!test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
226 * Got a matching frame, associate the tx status with
227 * the frame
229 entry->status = status;
230 set_bit(ENTRY_DATA_STATUS_SET, &entry->flags);
231 return true;
234 /* Check the next frame */
235 return false;
237 static bool rt2800mmio_txdone_release_entries(struct queue_entry *entry,
238 void *data)
240 if (test_bit(ENTRY_DATA_STATUS_SET, &entry->flags)) {
241 rt2800_txdone_entry(entry, entry->status,
242 rt2800mmio_get_txwi(entry));
243 return false;
246 /* No more frames to release */
247 return true;
250 static bool rt2800mmio_txdone(struct rt2x00_dev *rt2x00dev)
252 struct data_queue *queue;
253 u32 status;
254 u8 qid;
255 int max_tx_done = 16;
257 while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
258 qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
259 if (unlikely(qid >= QID_RX)) {
261 * Unknown queue, this shouldn't happen. Just drop
262 * this tx status.
264 rt2x00_warn(rt2x00dev, "Got TX status report with unexpected pid %u, dropping\n",
265 qid);
266 break;
269 queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
270 if (unlikely(queue == NULL)) {
272 * The queue is NULL, this shouldn't happen. Stop
273 * processing here and drop the tx status
275 rt2x00_warn(rt2x00dev, "Got TX status for an unavailable queue %u, dropping\n",
276 qid);
277 break;
280 if (unlikely(rt2x00queue_empty(queue))) {
282 * The queue is empty. Stop processing here
283 * and drop the tx status.
285 rt2x00_warn(rt2x00dev, "Got TX status for an empty queue %u, dropping\n",
286 qid);
287 break;
291 * Let's associate this tx status with the first
292 * matching frame.
294 if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
295 Q_INDEX, &status,
296 rt2800mmio_txdone_find_entry)) {
298 * We cannot match the tx status to any frame, so just
299 * use the first one.
301 if (!rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
302 Q_INDEX, &status,
303 rt2800mmio_txdone_match_first)) {
304 rt2x00_warn(rt2x00dev, "No frame found for TX status on queue %u, dropping\n",
305 qid);
306 break;
311 * Release all frames with a valid tx status.
313 rt2x00queue_for_each_entry(queue, Q_INDEX_DONE,
314 Q_INDEX, NULL,
315 rt2800mmio_txdone_release_entries);
317 if (--max_tx_done == 0)
318 break;
321 return !max_tx_done;
324 static inline void rt2800mmio_enable_interrupt(struct rt2x00_dev *rt2x00dev,
325 struct rt2x00_field32 irq_field)
327 u32 reg;
330 * Enable a single interrupt. The interrupt mask register
331 * access needs locking.
333 spin_lock_irq(&rt2x00dev->irqmask_lock);
334 rt2x00mmio_register_read(rt2x00dev, INT_MASK_CSR, &reg);
335 rt2x00_set_field32(&reg, irq_field, 1);
336 rt2x00mmio_register_write(rt2x00dev, INT_MASK_CSR, reg);
337 spin_unlock_irq(&rt2x00dev->irqmask_lock);
340 void rt2800mmio_txstatus_tasklet(unsigned long data)
342 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
343 if (rt2800mmio_txdone(rt2x00dev))
344 tasklet_schedule(&rt2x00dev->txstatus_tasklet);
347 * No need to enable the tx status interrupt here as we always
348 * leave it enabled to minimize the possibility of a tx status
349 * register overflow. See comment in interrupt handler.
352 EXPORT_SYMBOL_GPL(rt2800mmio_txstatus_tasklet);
354 void rt2800mmio_pretbtt_tasklet(unsigned long data)
356 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
357 rt2x00lib_pretbtt(rt2x00dev);
358 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
359 rt2800mmio_enable_interrupt(rt2x00dev, INT_MASK_CSR_PRE_TBTT);
361 EXPORT_SYMBOL_GPL(rt2800mmio_pretbtt_tasklet);
363 void rt2800mmio_tbtt_tasklet(unsigned long data)
365 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
366 struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
367 u32 reg;
369 rt2x00lib_beacondone(rt2x00dev);
371 if (rt2x00dev->intf_ap_count) {
373 * The rt2800pci hardware tbtt timer is off by 1us per tbtt
374 * causing beacon skew and as a result causing problems with
375 * some powersaving clients over time. Shorten the beacon
376 * interval every 64 beacons by 64us to mitigate this effect.
378 if (drv_data->tbtt_tick == (BCN_TBTT_OFFSET - 2)) {
379 rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
380 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
381 (rt2x00dev->beacon_int * 16) - 1);
382 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
383 } else if (drv_data->tbtt_tick == (BCN_TBTT_OFFSET - 1)) {
384 rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
385 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
386 (rt2x00dev->beacon_int * 16));
387 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
389 drv_data->tbtt_tick++;
390 drv_data->tbtt_tick %= BCN_TBTT_OFFSET;
393 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
394 rt2800mmio_enable_interrupt(rt2x00dev, INT_MASK_CSR_TBTT);
396 EXPORT_SYMBOL_GPL(rt2800mmio_tbtt_tasklet);
398 void rt2800mmio_rxdone_tasklet(unsigned long data)
400 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
401 if (rt2x00mmio_rxdone(rt2x00dev))
402 tasklet_schedule(&rt2x00dev->rxdone_tasklet);
403 else if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
404 rt2800mmio_enable_interrupt(rt2x00dev, INT_MASK_CSR_RX_DONE);
406 EXPORT_SYMBOL_GPL(rt2800mmio_rxdone_tasklet);
408 void rt2800mmio_autowake_tasklet(unsigned long data)
410 struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
411 rt2800mmio_wakeup(rt2x00dev);
412 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
413 rt2800mmio_enable_interrupt(rt2x00dev,
414 INT_MASK_CSR_AUTO_WAKEUP);
416 EXPORT_SYMBOL_GPL(rt2800mmio_autowake_tasklet);
418 static void rt2800mmio_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
420 u32 status;
421 int i;
424 * The TX_FIFO_STATUS interrupt needs special care. We should
425 * read TX_STA_FIFO but we should do it immediately as otherwise
426 * the register can overflow and we would lose status reports.
428 * Hence, read the TX_STA_FIFO register and copy all tx status
429 * reports into a kernel FIFO which is handled in the txstatus
430 * tasklet. We use a tasklet to process the tx status reports
431 * because we can schedule the tasklet multiple times (when the
432 * interrupt fires again during tx status processing).
434 * Furthermore we don't disable the TX_FIFO_STATUS
435 * interrupt here but leave it enabled so that the TX_STA_FIFO
436 * can also be read while the tx status tasklet gets executed.
438 * Since we have only one producer and one consumer we don't
439 * need to lock the kfifo.
441 for (i = 0; i < rt2x00dev->tx->limit; i++) {
442 rt2x00mmio_register_read(rt2x00dev, TX_STA_FIFO, &status);
444 if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
445 break;
447 if (!kfifo_put(&rt2x00dev->txstatus_fifo, status)) {
448 rt2x00_warn(rt2x00dev, "TX status FIFO overrun, drop tx status report\n");
449 break;
453 /* Schedule the tasklet for processing the tx status. */
454 tasklet_schedule(&rt2x00dev->txstatus_tasklet);
457 irqreturn_t rt2800mmio_interrupt(int irq, void *dev_instance)
459 struct rt2x00_dev *rt2x00dev = dev_instance;
460 u32 reg, mask;
462 /* Read status and ACK all interrupts */
463 rt2x00mmio_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
464 rt2x00mmio_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
466 if (!reg)
467 return IRQ_NONE;
469 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
470 return IRQ_HANDLED;
473 * Since INT_MASK_CSR and INT_SOURCE_CSR use the same bits
474 * for interrupts and interrupt masks we can just use the value of
475 * INT_SOURCE_CSR to create the interrupt mask.
477 mask = ~reg;
479 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
480 rt2800mmio_txstatus_interrupt(rt2x00dev);
482 * Never disable the TX_FIFO_STATUS interrupt.
484 rt2x00_set_field32(&mask, INT_MASK_CSR_TX_FIFO_STATUS, 1);
487 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
488 tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
490 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TBTT))
491 tasklet_hi_schedule(&rt2x00dev->tbtt_tasklet);
493 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE))
494 tasklet_schedule(&rt2x00dev->rxdone_tasklet);
496 if (rt2x00_get_field32(reg, INT_SOURCE_CSR_AUTO_WAKEUP))
497 tasklet_schedule(&rt2x00dev->autowake_tasklet);
500 * Disable all interrupts for which a tasklet was scheduled right now,
501 * the tasklet will reenable the appropriate interrupts.
503 spin_lock(&rt2x00dev->irqmask_lock);
504 rt2x00mmio_register_read(rt2x00dev, INT_MASK_CSR, &reg);
505 reg &= mask;
506 rt2x00mmio_register_write(rt2x00dev, INT_MASK_CSR, reg);
507 spin_unlock(&rt2x00dev->irqmask_lock);
509 return IRQ_HANDLED;
511 EXPORT_SYMBOL_GPL(rt2800mmio_interrupt);
513 void rt2800mmio_toggle_irq(struct rt2x00_dev *rt2x00dev,
514 enum dev_state state)
516 u32 reg;
517 unsigned long flags;
520 * When interrupts are being enabled, the interrupt registers
521 * should clear the register to assure a clean state.
523 if (state == STATE_RADIO_IRQ_ON) {
524 rt2x00mmio_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
525 rt2x00mmio_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
528 spin_lock_irqsave(&rt2x00dev->irqmask_lock, flags);
529 reg = 0;
530 if (state == STATE_RADIO_IRQ_ON) {
531 rt2x00_set_field32(&reg, INT_MASK_CSR_RX_DONE, 1);
532 rt2x00_set_field32(&reg, INT_MASK_CSR_TBTT, 1);
533 rt2x00_set_field32(&reg, INT_MASK_CSR_PRE_TBTT, 1);
534 rt2x00_set_field32(&reg, INT_MASK_CSR_TX_FIFO_STATUS, 1);
535 rt2x00_set_field32(&reg, INT_MASK_CSR_AUTO_WAKEUP, 1);
537 rt2x00mmio_register_write(rt2x00dev, INT_MASK_CSR, reg);
538 spin_unlock_irqrestore(&rt2x00dev->irqmask_lock, flags);
540 if (state == STATE_RADIO_IRQ_OFF) {
542 * Wait for possibly running tasklets to finish.
544 tasklet_kill(&rt2x00dev->txstatus_tasklet);
545 tasklet_kill(&rt2x00dev->rxdone_tasklet);
546 tasklet_kill(&rt2x00dev->autowake_tasklet);
547 tasklet_kill(&rt2x00dev->tbtt_tasklet);
548 tasklet_kill(&rt2x00dev->pretbtt_tasklet);
551 EXPORT_SYMBOL_GPL(rt2800mmio_toggle_irq);
554 * Queue handlers.
556 void rt2800mmio_start_queue(struct data_queue *queue)
558 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
559 u32 reg;
561 switch (queue->qid) {
562 case QID_RX:
563 rt2x00mmio_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
564 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
565 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
566 break;
567 case QID_BEACON:
568 rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
569 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
570 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
571 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
572 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
574 rt2x00mmio_register_read(rt2x00dev, INT_TIMER_EN, &reg);
575 rt2x00_set_field32(&reg, INT_TIMER_EN_PRE_TBTT_TIMER, 1);
576 rt2x00mmio_register_write(rt2x00dev, INT_TIMER_EN, reg);
577 break;
578 default:
579 break;
582 EXPORT_SYMBOL_GPL(rt2800mmio_start_queue);
584 void rt2800mmio_kick_queue(struct data_queue *queue)
586 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
587 struct queue_entry *entry;
589 switch (queue->qid) {
590 case QID_AC_VO:
591 case QID_AC_VI:
592 case QID_AC_BE:
593 case QID_AC_BK:
594 entry = rt2x00queue_get_entry(queue, Q_INDEX);
595 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX(queue->qid),
596 entry->entry_idx);
597 break;
598 case QID_MGMT:
599 entry = rt2x00queue_get_entry(queue, Q_INDEX);
600 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX(5),
601 entry->entry_idx);
602 break;
603 default:
604 break;
607 EXPORT_SYMBOL_GPL(rt2800mmio_kick_queue);
609 void rt2800mmio_stop_queue(struct data_queue *queue)
611 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
612 u32 reg;
614 switch (queue->qid) {
615 case QID_RX:
616 rt2x00mmio_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
617 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
618 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
619 break;
620 case QID_BEACON:
621 rt2x00mmio_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
622 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
623 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
624 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
625 rt2x00mmio_register_write(rt2x00dev, BCN_TIME_CFG, reg);
627 rt2x00mmio_register_read(rt2x00dev, INT_TIMER_EN, &reg);
628 rt2x00_set_field32(&reg, INT_TIMER_EN_PRE_TBTT_TIMER, 0);
629 rt2x00mmio_register_write(rt2x00dev, INT_TIMER_EN, reg);
632 * Wait for current invocation to finish. The tasklet
633 * won't be scheduled anymore afterwards since we disabled
634 * the TBTT and PRE TBTT timer.
636 tasklet_kill(&rt2x00dev->tbtt_tasklet);
637 tasklet_kill(&rt2x00dev->pretbtt_tasklet);
639 break;
640 default:
641 break;
644 EXPORT_SYMBOL_GPL(rt2800mmio_stop_queue);
646 void rt2800mmio_queue_init(struct data_queue *queue)
648 struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
649 unsigned short txwi_size, rxwi_size;
651 rt2800_get_txwi_rxwi_size(rt2x00dev, &txwi_size, &rxwi_size);
653 switch (queue->qid) {
654 case QID_RX:
655 queue->limit = 128;
656 queue->data_size = AGGREGATION_SIZE;
657 queue->desc_size = RXD_DESC_SIZE;
658 queue->winfo_size = rxwi_size;
659 queue->priv_size = sizeof(struct queue_entry_priv_mmio);
660 break;
662 case QID_AC_VO:
663 case QID_AC_VI:
664 case QID_AC_BE:
665 case QID_AC_BK:
666 queue->limit = 64;
667 queue->data_size = AGGREGATION_SIZE;
668 queue->desc_size = TXD_DESC_SIZE;
669 queue->winfo_size = txwi_size;
670 queue->priv_size = sizeof(struct queue_entry_priv_mmio);
671 break;
673 case QID_BEACON:
674 queue->limit = 8;
675 queue->data_size = 0; /* No DMA required for beacons */
676 queue->desc_size = TXD_DESC_SIZE;
677 queue->winfo_size = txwi_size;
678 queue->priv_size = sizeof(struct queue_entry_priv_mmio);
679 break;
681 case QID_ATIM:
682 /* fallthrough */
683 default:
684 BUG();
685 break;
688 EXPORT_SYMBOL_GPL(rt2800mmio_queue_init);
691 * Initialization functions.
693 bool rt2800mmio_get_entry_state(struct queue_entry *entry)
695 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
696 u32 word;
698 if (entry->queue->qid == QID_RX) {
699 rt2x00_desc_read(entry_priv->desc, 1, &word);
701 return (!rt2x00_get_field32(word, RXD_W1_DMA_DONE));
702 } else {
703 rt2x00_desc_read(entry_priv->desc, 1, &word);
705 return (!rt2x00_get_field32(word, TXD_W1_DMA_DONE));
708 EXPORT_SYMBOL_GPL(rt2800mmio_get_entry_state);
710 void rt2800mmio_clear_entry(struct queue_entry *entry)
712 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
713 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
714 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
715 u32 word;
717 if (entry->queue->qid == QID_RX) {
718 rt2x00_desc_read(entry_priv->desc, 0, &word);
719 rt2x00_set_field32(&word, RXD_W0_SDP0, skbdesc->skb_dma);
720 rt2x00_desc_write(entry_priv->desc, 0, word);
722 rt2x00_desc_read(entry_priv->desc, 1, &word);
723 rt2x00_set_field32(&word, RXD_W1_DMA_DONE, 0);
724 rt2x00_desc_write(entry_priv->desc, 1, word);
727 * Set RX IDX in register to inform hardware that we have
728 * handled this entry and it is available for reuse again.
730 rt2x00mmio_register_write(rt2x00dev, RX_CRX_IDX,
731 entry->entry_idx);
732 } else {
733 rt2x00_desc_read(entry_priv->desc, 1, &word);
734 rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 1);
735 rt2x00_desc_write(entry_priv->desc, 1, word);
738 EXPORT_SYMBOL_GPL(rt2800mmio_clear_entry);
740 int rt2800mmio_init_queues(struct rt2x00_dev *rt2x00dev)
742 struct queue_entry_priv_mmio *entry_priv;
745 * Initialize registers.
747 entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
748 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR0,
749 entry_priv->desc_dma);
750 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT0,
751 rt2x00dev->tx[0].limit);
752 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX0, 0);
753 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX0, 0);
755 entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
756 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR1,
757 entry_priv->desc_dma);
758 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT1,
759 rt2x00dev->tx[1].limit);
760 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX1, 0);
761 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX1, 0);
763 entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
764 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR2,
765 entry_priv->desc_dma);
766 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT2,
767 rt2x00dev->tx[2].limit);
768 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX2, 0);
769 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX2, 0);
771 entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
772 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR3,
773 entry_priv->desc_dma);
774 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT3,
775 rt2x00dev->tx[3].limit);
776 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX3, 0);
777 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX3, 0);
779 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR4, 0);
780 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT4, 0);
781 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX4, 0);
782 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX4, 0);
784 rt2x00mmio_register_write(rt2x00dev, TX_BASE_PTR5, 0);
785 rt2x00mmio_register_write(rt2x00dev, TX_MAX_CNT5, 0);
786 rt2x00mmio_register_write(rt2x00dev, TX_CTX_IDX5, 0);
787 rt2x00mmio_register_write(rt2x00dev, TX_DTX_IDX5, 0);
789 entry_priv = rt2x00dev->rx->entries[0].priv_data;
790 rt2x00mmio_register_write(rt2x00dev, RX_BASE_PTR,
791 entry_priv->desc_dma);
792 rt2x00mmio_register_write(rt2x00dev, RX_MAX_CNT,
793 rt2x00dev->rx[0].limit);
794 rt2x00mmio_register_write(rt2x00dev, RX_CRX_IDX,
795 rt2x00dev->rx[0].limit - 1);
796 rt2x00mmio_register_write(rt2x00dev, RX_DRX_IDX, 0);
798 rt2800_disable_wpdma(rt2x00dev);
800 rt2x00mmio_register_write(rt2x00dev, DELAY_INT_CFG, 0);
802 return 0;
804 EXPORT_SYMBOL_GPL(rt2800mmio_init_queues);
806 int rt2800mmio_init_registers(struct rt2x00_dev *rt2x00dev)
808 u32 reg;
811 * Reset DMA indexes
813 rt2x00mmio_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
814 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
815 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
816 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
817 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, 1);
818 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
819 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
820 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
821 rt2x00mmio_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
823 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
824 rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
826 if (rt2x00_is_pcie(rt2x00dev) &&
827 (rt2x00_rt(rt2x00dev, RT3090) ||
828 rt2x00_rt(rt2x00dev, RT3390) ||
829 rt2x00_rt(rt2x00dev, RT3572) ||
830 rt2x00_rt(rt2x00dev, RT3593) ||
831 rt2x00_rt(rt2x00dev, RT5390) ||
832 rt2x00_rt(rt2x00dev, RT5392) ||
833 rt2x00_rt(rt2x00dev, RT5592))) {
834 rt2x00mmio_register_read(rt2x00dev, AUX_CTRL, &reg);
835 rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
836 rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
837 rt2x00mmio_register_write(rt2x00dev, AUX_CTRL, reg);
840 rt2x00mmio_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
842 reg = 0;
843 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
844 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
845 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
847 rt2x00mmio_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
849 return 0;
851 EXPORT_SYMBOL_GPL(rt2800mmio_init_registers);
854 * Device state switch handlers.
856 int rt2800mmio_enable_radio(struct rt2x00_dev *rt2x00dev)
858 /* Wait for DMA, ignore error until we initialize queues. */
859 rt2800_wait_wpdma_ready(rt2x00dev);
861 if (unlikely(rt2800mmio_init_queues(rt2x00dev)))
862 return -EIO;
864 return rt2800_enable_radio(rt2x00dev);
866 EXPORT_SYMBOL_GPL(rt2800mmio_enable_radio);
868 MODULE_AUTHOR(DRV_PROJECT);
869 MODULE_VERSION(DRV_VERSION);
870 MODULE_DESCRIPTION("rt2800 MMIO library");
871 MODULE_LICENSE("GPL");