blob: 32b8e5058867e6a70f586113c3e142881227ed2c [file] [log] [blame]
Gabor Juhose5553f02013-10-17 09:42:15 +02001/* 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>
10 *
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.
15 *
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.
20 *
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.
25 */
26
27/* Module: rt2800mmio
28 * Abstract: rt2800 MMIO device routines.
29 */
30
31#include <linux/kernel.h>
32#include <linux/module.h>
Gabor Juhos0bc202b2013-10-17 09:42:17 +020033#include <linux/export.h>
34
35#include "rt2x00.h"
36#include "rt2x00mmio.h"
Gabor Juhos97324972013-10-17 09:42:19 +020037#include "rt2800lib.h"
Gabor Juhos0bc202b2013-10-17 09:42:17 +020038#include "rt2800mmio.h"
39
40/*
41 * TX descriptor initialization
42 */
43__le32 *rt2800mmio_get_txwi(struct queue_entry *entry)
44{
45 return (__le32 *) entry->skb->data;
46}
47EXPORT_SYMBOL_GPL(rt2800mmio_get_txwi);
48
49void rt2800mmio_write_tx_desc(struct queue_entry *entry,
50 struct txentry_desc *txdesc)
51{
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;
55 u32 word;
56 const unsigned int txwi_size = entry->queue->winfo_size;
57
58 /*
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.
64 */
65
66 /*
67 * Initialize TX descriptor
68 */
69 word = 0;
70 rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
71 rt2x00_desc_write(txd, 0, word);
72
73 word = 0;
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);
83
84 word = 0;
85 rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
86 skbdesc->skb_dma + txwi_size);
87 rt2x00_desc_write(txd, 2, word);
88
89 word = 0;
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);
94
95 /*
96 * Register descriptor details in skb frame descriptor.
97 */
98 skbdesc->desc = txd;
99 skbdesc->desc_len = TXD_DESC_SIZE;
100}
101EXPORT_SYMBOL_GPL(rt2800mmio_write_tx_desc);
Gabor Juhose5553f02013-10-17 09:42:15 +0200102
Gabor Juhos97324972013-10-17 09:42:19 +0200103/*
104 * RX control handlers
105 */
106void rt2800mmio_fill_rxdone(struct queue_entry *entry,
107 struct rxdone_entry_desc *rxdesc)
108{
109 struct queue_entry_priv_mmio *entry_priv = entry->priv_data;
110 __le32 *rxd = entry_priv->desc;
111 u32 word;
112
113 rt2x00_desc_read(rxd, 3, &word);
114
115 if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
116 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
117
118 /*
119 * Unfortunately we don't know the cipher type used during
120 * decryption. This prevents us from correct providing
121 * correct statistics through debugfs.
122 */
123 rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
124
125 if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
126 /*
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.
131 */
132 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
133
134 /*
135 * The hardware has already checked the Michael Mic and has
136 * stripped it from the frame. Signal this to mac80211.
137 */
138 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
139
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;
144 }
145
146 if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
147 rxdesc->dev_flags |= RXDONE_MY_BSS;
148
149 if (rt2x00_get_field32(word, RXD_W3_L2PAD))
150 rxdesc->dev_flags |= RXDONE_L2PAD;
151
152 /*
153 * Process the RXWI structure that is at the start of the buffer.
154 */
155 rt2800_process_rxwi(entry, rxdesc);
156}
157EXPORT_SYMBOL_GPL(rt2800mmio_fill_rxdone);
Gabor Juhose5553f02013-10-17 09:42:15 +0200158
159MODULE_AUTHOR(DRV_PROJECT);
160MODULE_VERSION(DRV_VERSION);
161MODULE_DESCRIPTION("rt2800 MMIO library");
162MODULE_LICENSE("GPL");