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, write to the
23 * Free Software Foundation, Inc.,
24 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 * Abstract: rt2800 MMIO device routines.
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/export.h>
36 #include "rt2x00mmio.h"
37 #include "rt2800lib.h"
38 #include "rt2800mmio.h"
41 * TX descriptor initialization
43 __le32 *rt2800mmio_get_txwi(struct queue_entry *entry)
45 return (__le32 *) entry->skb->data;
47 EXPORT_SYMBOL_GPL(rt2800mmio_get_txwi);
49 void rt2800mmio_write_tx_desc(struct queue_entry *entry,
50 struct txentry_desc *txdesc)
52 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
53 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
54 __le32 *txd = entry_priv->desc;
56 const unsigned int txwi_size = entry->queue->winfo_size;
59 * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1
60 * must contains a TXWI structure + 802.11 header + padding + 802.11
61 * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and
62 * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11
63 * data. It means that LAST_SEC0 is always 0.
67 * Initialize TX descriptor
70 rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
71 rt2x00_desc_write(txd, 0, word);
74 rt2x00_set_field32(&word, TXD_W1_SD_LEN1, entry->skb->len);
75 rt2x00_set_field32(&word, TXD_W1_LAST_SEC1,
76 !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
77 rt2x00_set_field32(&word, TXD_W1_BURST,
78 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
79 rt2x00_set_field32(&word, TXD_W1_SD_LEN0, txwi_size);
80 rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0);
81 rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0);
82 rt2x00_desc_write(txd, 1, word);
85 rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
86 skbdesc->skb_dma + txwi_size);
87 rt2x00_desc_write(txd, 2, word);
90 rt2x00_set_field32(&word, TXD_W3_WIV,
91 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
92 rt2x00_set_field32(&word, TXD_W3_QSEL, 2);
93 rt2x00_desc_write(txd, 3, word);
96 * Register descriptor details in skb frame descriptor.
99 skbdesc->desc_len = TXD_DESC_SIZE;
101 EXPORT_SYMBOL_GPL(rt2800mmio_write_tx_desc);
104 * RX control handlers
106 void rt2800mmio_fill_rxdone(struct queue_entry *entry,
107 struct rxdone_entry_desc *rxdesc)
109 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
110 __le32 *rxd = entry_priv->desc;
113 rt2x00_desc_read(rxd, 3, &word);
115 if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
116 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
119 * Unfortunately we don't know the cipher type used during
120 * decryption. This prevents us from correct providing
121 * correct statistics through debugfs.
123 rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
125 if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
127 * Hardware has stripped IV/EIV data from 802.11 frame during
128 * decryption. Unfortunately the descriptor doesn't contain
129 * any fields with the EIV/IV data either, so they can't
130 * be restored by rt2x00lib.
132 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
135 * The hardware has already checked the Michael Mic and has
136 * stripped it from the frame. Signal this to mac80211.
138 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
140 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
141 rxdesc->flags |= RX_FLAG_DECRYPTED;
142 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
143 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
146 if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
147 rxdesc->dev_flags |= RXDONE_MY_BSS;
149 if (rt2x00_get_field32(word, RXD_W3_L2PAD))
150 rxdesc->dev_flags |= RXDONE_L2PAD;
153 * Process the RXWI structure that is at the start of the buffer.
155 rt2800_process_rxwi(entry, rxdesc);
157 EXPORT_SYMBOL_GPL(rt2800mmio_fill_rxdone);
159 MODULE_AUTHOR(DRV_PROJECT);
160 MODULE_VERSION(DRV_VERSION);
161 MODULE_DESCRIPTION("rt2800 MMIO library");
162 MODULE_LICENSE("GPL");