blob: 9b297fce4692a8c58a9f75900c2d3d92c0dd1f9d [file] [log] [blame]
Ivo van Doorn181d6902008-02-05 16:42:23 -05001/*
Ivo van Doorn7e613e12010-08-06 20:45:38 +02002 Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
Ivo van Doorn181d6902008-02-05 16:42:23 -05003 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
Jeff Kirshera05b8c52013-12-06 03:32:11 -080016 along with this program; if not, see <http://www.gnu.org/licenses/>.
Ivo van Doorn181d6902008-02-05 16:42:23 -050017 */
18
19/*
20 Module: rt2x00
21 Abstract: rt2x00 queue datastructures and routines
22 */
23
24#ifndef RT2X00QUEUE_H
25#define RT2X00QUEUE_H
26
27#include <linux/prefetch.h>
28
29/**
Luis Correia49513482009-07-17 21:39:19 +020030 * DOC: Entry frame size
Ivo van Doorn181d6902008-02-05 16:42:23 -050031 *
32 * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes,
33 * for USB devices this restriction does not apply, but the value of
34 * 2432 makes sense since it is big enough to contain the maximum fragment
35 * size according to the ieee802.11 specs.
Ivo van Doorn35f00cf2009-04-26 16:09:32 +020036 * The aggregation size depends on support from the driver, but should
37 * be something around 3840 bytes.
Ivo van Doorn181d6902008-02-05 16:42:23 -050038 */
Ivo van Doorn35f00cf2009-04-26 16:09:32 +020039#define DATA_FRAME_SIZE 2432
40#define MGMT_FRAME_SIZE 256
41#define AGGREGATION_SIZE 3840
Ivo van Doorn181d6902008-02-05 16:42:23 -050042
43/**
Ivo van Doorn181d6902008-02-05 16:42:23 -050044 * enum data_queue_qid: Queue identification
Ivo van Doorne58c6ac2008-04-21 19:00:47 +020045 *
Ivo van Doornf615e9a2010-12-13 12:36:38 +010046 * @QID_AC_VO: AC VO queue
47 * @QID_AC_VI: AC VI queue
Ivo van Doorne58c6ac2008-04-21 19:00:47 +020048 * @QID_AC_BE: AC BE queue
49 * @QID_AC_BK: AC BK queue
Ivo van Doorne58c6ac2008-04-21 19:00:47 +020050 * @QID_HCCA: HCCA queue
51 * @QID_MGMT: MGMT queue (prio queue)
52 * @QID_RX: RX queue
53 * @QID_OTHER: None of the above (don't use, only present for completeness)
54 * @QID_BEACON: Beacon queue (value unspecified, don't send it to device)
Joe Perches1d616b12011-06-23 15:35:18 -070055 * @QID_ATIM: Atim queue (value unspecified, don't send it to device)
Ivo van Doorn181d6902008-02-05 16:42:23 -050056 */
57enum data_queue_qid {
Ivo van Doornf615e9a2010-12-13 12:36:38 +010058 QID_AC_VO = 0,
59 QID_AC_VI = 1,
60 QID_AC_BE = 2,
61 QID_AC_BK = 3,
Ivo van Doorn181d6902008-02-05 16:42:23 -050062 QID_HCCA = 4,
63 QID_MGMT = 13,
64 QID_RX = 14,
65 QID_OTHER = 15,
Ivo van Doorne58c6ac2008-04-21 19:00:47 +020066 QID_BEACON,
67 QID_ATIM,
Ivo van Doorn181d6902008-02-05 16:42:23 -050068};
69
70/**
Ivo van Doornbaf26a72008-02-17 17:32:08 +010071 * enum skb_frame_desc_flags: Flags for &struct skb_frame_desc
72 *
Ivo van Doornd74f5ba2008-06-16 19:56:54 +020073 * @SKBDESC_DMA_MAPPED_RX: &skb_dma field has been mapped for RX
74 * @SKBDESC_DMA_MAPPED_TX: &skb_dma field has been mapped for TX
Ivo van Doorn9f166172009-04-26 16:08:50 +020075 * @SKBDESC_IV_STRIPPED: Frame contained a IV/EIV provided by
Ivo van Doorn2bb057d2008-08-04 16:37:44 +020076 * mac80211 but was stripped for processing by the driver.
Johannes Berg7351c6b2009-11-19 01:08:30 +010077 * @SKBDESC_NOT_MAC80211: Frame didn't originate from mac80211,
78 * don't try to pass it back.
Gertjan van Wingerdefd76f142010-05-11 23:51:43 +020079 * @SKBDESC_DESC_IN_SKB: The descriptor is at the start of the
80 * skb, instead of in the desc field.
Ivo van Doornbaf26a72008-02-17 17:32:08 +010081 */
Gertjan van Wingerdec4da0042008-06-16 19:56:31 +020082enum skb_frame_desc_flags {
Ivo van Doorn2bb057d2008-08-04 16:37:44 +020083 SKBDESC_DMA_MAPPED_RX = 1 << 0,
84 SKBDESC_DMA_MAPPED_TX = 1 << 1,
Ivo van Doorn9f166172009-04-26 16:08:50 +020085 SKBDESC_IV_STRIPPED = 1 << 2,
Gertjan van Wingerde354e39d2009-12-04 23:47:02 +010086 SKBDESC_NOT_MAC80211 = 1 << 3,
Gertjan van Wingerdefd76f142010-05-11 23:51:43 +020087 SKBDESC_DESC_IN_SKB = 1 << 4,
Gertjan van Wingerdec4da0042008-06-16 19:56:31 +020088};
Ivo van Doornbaf26a72008-02-17 17:32:08 +010089
90/**
Ivo van Doorn181d6902008-02-05 16:42:23 -050091 * struct skb_frame_desc: Descriptor information for the skb buffer
92 *
Johannes Berge039fa42008-05-15 12:55:29 +020093 * This structure is placed over the driver_data array, this means that
94 * this structure should not exceed the size of that array (40 bytes).
Ivo van Doorn181d6902008-02-05 16:42:23 -050095 *
Ivo van Doornbaf26a72008-02-17 17:32:08 +010096 * @flags: Frame flags, see &enum skb_frame_desc_flags.
Gertjan van Wingerdec4da0042008-06-16 19:56:31 +020097 * @desc_len: Length of the frame descriptor.
Johannes Berge6a98542008-10-21 12:40:02 +020098 * @tx_rate_idx: the index of the TX rate, used for TX status reporting
99 * @tx_rate_flags: the TX rate flags, used for TX status reporting
Ivo van Doorn181d6902008-02-05 16:42:23 -0500100 * @desc: Pointer to descriptor part of the frame.
101 * Note that this pointer could point to something outside
102 * of the scope of the skb->data pointer.
Ivo van Doorn1ce9cda2008-12-02 18:19:48 +0100103 * @iv: IV/EIV data used during encryption/decryption.
Gertjan van Wingerdec4da0042008-06-16 19:56:31 +0200104 * @skb_dma: (PCI-only) the DMA address associated with the sk buffer.
Stanislaw Gruszkaa13d9852017-02-15 10:25:05 +0100105 * @sta: The station where sk buffer was sent.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500106 */
107struct skb_frame_desc {
Johannes Berge6a98542008-10-21 12:40:02 +0200108 u8 flags;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500109
Johannes Berge6a98542008-10-21 12:40:02 +0200110 u8 desc_len;
111 u8 tx_rate_idx;
112 u8 tx_rate_flags;
113
Gertjan van Wingerdec4da0042008-06-16 19:56:31 +0200114 void *desc;
115
Ivo van Doorn1ce9cda2008-12-02 18:19:48 +0100116 __le32 iv[2];
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200117
Gertjan van Wingerdec4da0042008-06-16 19:56:31 +0200118 dma_addr_t skb_dma;
Stanislaw Gruszkaa13d9852017-02-15 10:25:05 +0100119 struct ieee80211_sta *sta;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500120};
121
Johannes Berge039fa42008-05-15 12:55:29 +0200122/**
123 * get_skb_frame_desc - Obtain the rt2x00 frame descriptor from a sk_buff.
124 * @skb: &struct sk_buff from where we obtain the &struct skb_frame_desc
125 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500126static inline struct skb_frame_desc* get_skb_frame_desc(struct sk_buff *skb)
127{
Johannes Berge039fa42008-05-15 12:55:29 +0200128 BUILD_BUG_ON(sizeof(struct skb_frame_desc) >
129 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
130 return (struct skb_frame_desc *)&IEEE80211_SKB_CB(skb)->driver_data;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500131}
132
133/**
Ivo van Doorn19d30e02008-03-15 21:38:07 +0100134 * enum rxdone_entry_desc_flags: Flags for &struct rxdone_entry_desc
135 *
Ivo van Doorn6c6aa3c2008-08-29 21:07:16 +0200136 * @RXDONE_SIGNAL_PLCP: Signal field contains the plcp value.
137 * @RXDONE_SIGNAL_BITRATE: Signal field contains the bitrate value.
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200138 * @RXDONE_SIGNAL_MCS: Signal field contains the mcs value.
Ivo van Doorn19d30e02008-03-15 21:38:07 +0100139 * @RXDONE_MY_BSS: Does this frame originate from device's BSS.
Ivo van Doorn74415ed2008-12-02 22:50:33 +0100140 * @RXDONE_CRYPTO_IV: Driver provided IV/EIV data.
141 * @RXDONE_CRYPTO_ICV: Driver provided ICV data.
Ivo van Doorn9f166172009-04-26 16:08:50 +0200142 * @RXDONE_L2PAD: 802.11 payload has been padded to 4-byte boundary.
Ivo van Doorn19d30e02008-03-15 21:38:07 +0100143 */
144enum rxdone_entry_desc_flags {
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200145 RXDONE_SIGNAL_PLCP = BIT(0),
146 RXDONE_SIGNAL_BITRATE = BIT(1),
147 RXDONE_SIGNAL_MCS = BIT(2),
148 RXDONE_MY_BSS = BIT(3),
149 RXDONE_CRYPTO_IV = BIT(4),
150 RXDONE_CRYPTO_ICV = BIT(5),
151 RXDONE_L2PAD = BIT(6),
Ivo van Doorn19d30e02008-03-15 21:38:07 +0100152};
153
154/**
Ivo van Doornb30dd5c02008-12-20 10:59:55 +0100155 * RXDONE_SIGNAL_MASK - Define to mask off all &rxdone_entry_desc_flags flags
156 * except for the RXDONE_SIGNAL_* flags. This is useful to convert the dev_flags
157 * from &rxdone_entry_desc to a signal value type.
158 */
159#define RXDONE_SIGNAL_MASK \
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200160 ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE | RXDONE_SIGNAL_MCS )
Ivo van Doornb30dd5c02008-12-20 10:59:55 +0100161
162/**
Ivo van Doorn181d6902008-02-05 16:42:23 -0500163 * struct rxdone_entry_desc: RX Entry descriptor
164 *
165 * Summary of information that has been read from the RX frame descriptor.
166 *
Ivo van Doornae73e582008-07-04 16:14:59 +0200167 * @timestamp: RX Timestamp
Ivo van Doorn181d6902008-02-05 16:42:23 -0500168 * @signal: Signal of the received frame.
169 * @rssi: RSSI of the received frame.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500170 * @size: Data size of the received frame.
171 * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags).
Ivo van Doorn19d30e02008-03-15 21:38:07 +0100172 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200173 * @rate_mode: Rate mode (See @enum rate_modulation).
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200174 * @cipher: Cipher type used during decryption.
175 * @cipher_status: Decryption status.
Ivo van Doorn1ce9cda2008-12-02 18:19:48 +0100176 * @iv: IV/EIV data used during decryption.
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200177 * @icv: ICV data used during decryption.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500178 */
179struct rxdone_entry_desc {
Ivo van Doornae73e582008-07-04 16:14:59 +0200180 u64 timestamp;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500181 int signal;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500182 int rssi;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500183 int size;
184 int flags;
Ivo van Doorn19d30e02008-03-15 21:38:07 +0100185 int dev_flags;
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200186 u16 rate_mode;
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200187 u8 cipher;
188 u8 cipher_status;
189
Ivo van Doorn1ce9cda2008-12-02 18:19:48 +0100190 __le32 iv[2];
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200191 __le32 icv;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500192};
193
194/**
Ivo van Doornfb55f4d12008-05-10 13:42:06 +0200195 * enum txdone_entry_desc_flags: Flags for &struct txdone_entry_desc
196 *
Helmut Schaa46678b12010-06-14 22:08:30 +0200197 * Every txdone report has to contain the basic result of the
198 * transmission, either &TXDONE_UNKNOWN, &TXDONE_SUCCESS or
199 * &TXDONE_FAILURE. The flag &TXDONE_FALLBACK can be used in
200 * conjunction with all of these flags but should only be set
201 * if retires > 0. The flag &TXDONE_EXCESSIVE_RETRY can only be used
202 * in conjunction with &TXDONE_FAILURE.
203 *
Ivo van Doornfb55f4d12008-05-10 13:42:06 +0200204 * @TXDONE_UNKNOWN: Hardware could not determine success of transmission.
205 * @TXDONE_SUCCESS: Frame was successfully send
Helmut Schaa46678b12010-06-14 22:08:30 +0200206 * @TXDONE_FALLBACK: Hardware used fallback rates for retries
Ivo van Doornfb55f4d12008-05-10 13:42:06 +0200207 * @TXDONE_FAILURE: Frame was not successfully send
208 * @TXDONE_EXCESSIVE_RETRY: In addition to &TXDONE_FAILURE, the
209 * frame transmission failed due to excessive retries.
210 */
211enum txdone_entry_desc_flags {
Jochen Friedrichf126cba2008-08-15 14:47:46 +0200212 TXDONE_UNKNOWN,
213 TXDONE_SUCCESS,
Benoit PAPILLAULT92ed48e2009-08-17 18:56:10 +0200214 TXDONE_FALLBACK,
Jochen Friedrichf126cba2008-08-15 14:47:46 +0200215 TXDONE_FAILURE,
216 TXDONE_EXCESSIVE_RETRY,
Helmut Schaaf16d2db2011-03-28 13:35:21 +0200217 TXDONE_AMPDU,
Ivo van Doornfb55f4d12008-05-10 13:42:06 +0200218};
219
220/**
Ivo van Doorn181d6902008-02-05 16:42:23 -0500221 * struct txdone_entry_desc: TX done entry descriptor
222 *
223 * Summary of information that has been read from the TX frame descriptor
224 * after the device is done with transmission.
225 *
Ivo van Doornfb55f4d12008-05-10 13:42:06 +0200226 * @flags: TX done flags (See &enum txdone_entry_desc_flags).
Ivo van Doorn181d6902008-02-05 16:42:23 -0500227 * @retry: Retry count.
228 */
229struct txdone_entry_desc {
Ivo van Doornfb55f4d12008-05-10 13:42:06 +0200230 unsigned long flags;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500231 int retry;
232};
233
234/**
235 * enum txentry_desc_flags: Status flags for TX entry descriptor
236 *
237 * @ENTRY_TXD_RTS_FRAME: This frame is a RTS frame.
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200238 * @ENTRY_TXD_CTS_FRAME: This frame is a CTS-to-self frame.
Ivo van Doorn5adf6d62008-07-20 18:03:38 +0200239 * @ENTRY_TXD_GENERATE_SEQ: This frame requires sequence counter.
Ivo van Doorn61486e02008-05-10 13:42:31 +0200240 * @ENTRY_TXD_FIRST_FRAGMENT: This is the first frame.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500241 * @ENTRY_TXD_MORE_FRAG: This frame is followed by another fragment.
242 * @ENTRY_TXD_REQ_TIMESTAMP: Require timestamp to be inserted.
243 * @ENTRY_TXD_BURST: This frame belongs to the same burst event.
244 * @ENTRY_TXD_ACK: An ACK is required for this frame.
Ivo van Doorn61486e02008-05-10 13:42:31 +0200245 * @ENTRY_TXD_RETRY_MODE: When set, the long retry count is used.
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200246 * @ENTRY_TXD_ENCRYPT: This frame should be encrypted.
247 * @ENTRY_TXD_ENCRYPT_PAIRWISE: Use pairwise key table (instead of shared).
248 * @ENTRY_TXD_ENCRYPT_IV: Generate IV/EIV in hardware.
249 * @ENTRY_TXD_ENCRYPT_MMIC: Generate MIC in hardware.
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200250 * @ENTRY_TXD_HT_AMPDU: This frame is part of an AMPDU.
251 * @ENTRY_TXD_HT_BW_40: Use 40MHz Bandwidth.
252 * @ENTRY_TXD_HT_SHORT_GI: Use short GI.
Ivo van Doorn84804cd2010-08-06 20:46:19 +0200253 * @ENTRY_TXD_HT_MIMO_PS: The receiving STA is in dynamic SM PS mode.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500254 */
255enum txentry_desc_flags {
256 ENTRY_TXD_RTS_FRAME,
Ivo van Doorn7050ec82008-05-10 13:46:13 +0200257 ENTRY_TXD_CTS_FRAME,
Ivo van Doorn5adf6d62008-07-20 18:03:38 +0200258 ENTRY_TXD_GENERATE_SEQ,
Ivo van Doorn61486e02008-05-10 13:42:31 +0200259 ENTRY_TXD_FIRST_FRAGMENT,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500260 ENTRY_TXD_MORE_FRAG,
261 ENTRY_TXD_REQ_TIMESTAMP,
262 ENTRY_TXD_BURST,
263 ENTRY_TXD_ACK,
Ivo van Doorn61486e02008-05-10 13:42:31 +0200264 ENTRY_TXD_RETRY_MODE,
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200265 ENTRY_TXD_ENCRYPT,
266 ENTRY_TXD_ENCRYPT_PAIRWISE,
267 ENTRY_TXD_ENCRYPT_IV,
268 ENTRY_TXD_ENCRYPT_MMIC,
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200269 ENTRY_TXD_HT_AMPDU,
270 ENTRY_TXD_HT_BW_40,
271 ENTRY_TXD_HT_SHORT_GI,
Ivo van Doorn84804cd2010-08-06 20:46:19 +0200272 ENTRY_TXD_HT_MIMO_PS,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500273};
274
275/**
276 * struct txentry_desc: TX Entry descriptor
277 *
278 * Summary of information for the frame descriptor before sending a TX frame.
279 *
280 * @flags: Descriptor flags (See &enum queue_entry_flags).
Gertjan van Wingerdedf624ca2010-05-03 22:43:05 +0200281 * @length: Length of the entire frame.
Ivo van Doorn9f166172009-04-26 16:08:50 +0200282 * @header_length: Length of 802.11 header.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500283 * @length_high: PLCP length high word.
284 * @length_low: PLCP length low word.
285 * @signal: PLCP signal.
286 * @service: PLCP service.
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200287 * @msc: MCS.
Helmut Schaa5dada062011-09-07 20:11:03 +0200288 * @stbc: Use Space Time Block Coding (only available for MCS rates < 8).
289 * @ba_size: Size of the recepients RX reorder buffer - 1.
Ivo van Doorn076f9582008-12-20 10:59:02 +0100290 * @rate_mode: Rate mode (See @enum rate_modulation).
Ivo van Doorn35f00cf2009-04-26 16:09:32 +0200291 * @mpdu_density: MDPU density.
Ivo van Doorn61486e02008-05-10 13:42:31 +0200292 * @retry_limit: Max number of retries.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500293 * @ifs: IFS value.
Helmut Schaa1affa092010-05-07 11:03:08 +0200294 * @txop: IFS value for 11n capable chips.
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200295 * @cipher: Cipher type used for encryption.
296 * @key_idx: Key index used for encryption.
297 * @iv_offset: Position where IV should be inserted by hardware.
Ivo van Doorn9eb4e212009-04-26 16:08:30 +0200298 * @iv_len: Length of IV data.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500299 */
300struct txentry_desc {
301 unsigned long flags;
302
Gertjan van Wingerdedf624ca2010-05-03 22:43:05 +0200303 u16 length;
Ivo van Doorn9f166172009-04-26 16:08:50 +0200304 u16 header_length;
Ivo van Doorn9f166172009-04-26 16:08:50 +0200305
Helmut Schaa26a1d072011-03-03 19:42:35 +0100306 union {
307 struct {
308 u16 length_high;
309 u16 length_low;
310 u16 signal;
311 u16 service;
Helmut Schaa25177942011-03-03 19:43:25 +0100312 enum ifs ifs;
Helmut Schaa26a1d072011-03-03 19:42:35 +0100313 } plcp;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500314
Helmut Schaa26a1d072011-03-03 19:42:35 +0100315 struct {
316 u16 mcs;
Ivo van Doornfe107a52011-03-03 19:42:58 +0100317 u8 stbc;
318 u8 ba_size;
319 u8 mpdu_density;
320 enum txop txop;
Helmut Schaaead2bb62011-09-08 14:37:19 +0200321 int wcid;
Helmut Schaa26a1d072011-03-03 19:42:35 +0100322 } ht;
323 } u;
324
Helmut Schaa4df10c82011-03-03 19:44:10 +0100325 enum rate_modulation rate_mode;
Ivo van Doorn076f9582008-12-20 10:59:02 +0100326
Ivo van Doorn61486e02008-05-10 13:42:31 +0200327 short retry_limit;
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200328
329 enum cipher cipher;
330 u16 key_idx;
331 u16 iv_offset;
Ivo van Doorn9eb4e212009-04-26 16:08:30 +0200332 u16 iv_len;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500333};
334
335/**
336 * enum queue_entry_flags: Status flags for queue entry
337 *
338 * @ENTRY_BCN_ASSIGNED: This entry has been assigned to an interface.
339 * As long as this bit is set, this entry may only be touched
340 * through the interface structure.
341 * @ENTRY_OWNER_DEVICE_DATA: This entry is owned by the device for data
342 * transfer (either TX or RX depending on the queue). The entry should
343 * only be touched after the device has signaled it is done with it.
Ivo van Doornf019d512008-06-06 22:47:39 +0200344 * @ENTRY_DATA_PENDING: This entry contains a valid frame and is waiting
345 * for the signal to start sending.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300346 * @ENTRY_DATA_IO_FAILED: Hardware indicated that an IO error occurred
347 * while transferring the data to the hardware. No TX status report will
Ivo van Doorn7e613e12010-08-06 20:45:38 +0200348 * be expected from the hardware.
Ivo van Doorndba5dc12010-12-13 12:36:18 +0100349 * @ENTRY_DATA_STATUS_PENDING: The entry has been send to the device and
350 * returned. It is now waiting for the status reporting before the
351 * entry can be reused again.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500352 */
Ivo van Doorn181d6902008-02-05 16:42:23 -0500353enum queue_entry_flags {
354 ENTRY_BCN_ASSIGNED,
Stanislaw Gruszkaba089102014-06-05 13:52:24 +0200355 ENTRY_BCN_ENABLED,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500356 ENTRY_OWNER_DEVICE_DATA,
Ivo van Doornf019d512008-06-06 22:47:39 +0200357 ENTRY_DATA_PENDING,
Ivo van Doorndba5dc12010-12-13 12:36:18 +0100358 ENTRY_DATA_IO_FAILED,
359 ENTRY_DATA_STATUS_PENDING,
Helmut Schaa8857d6d2013-03-15 09:57:57 +0100360 ENTRY_DATA_STATUS_SET,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500361};
362
363/**
364 * struct queue_entry: Entry inside the &struct data_queue
365 *
366 * @flags: Entry flags, see &enum queue_entry_flags.
Johannes Stezenbach75256f02011-04-18 15:29:38 +0200367 * @last_action: Timestamp of last change.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500368 * @queue: The data queue (&struct data_queue) to which this entry belongs.
369 * @skb: The buffer which is currently being transmitted (for TX queue),
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300370 * or used to directly receive data in (for RX queue).
Ivo van Doorn181d6902008-02-05 16:42:23 -0500371 * @entry_idx: The entry index number.
372 * @priv_data: Private data belonging to this queue entry. The pointer
373 * points to data specific to a particular driver and queue type.
Helmut Schaa8857d6d2013-03-15 09:57:57 +0100374 * @status: Device specific status
Ivo van Doorn181d6902008-02-05 16:42:23 -0500375 */
376struct queue_entry {
377 unsigned long flags;
Johannes Stezenbach75256f02011-04-18 15:29:38 +0200378 unsigned long last_action;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500379
380 struct data_queue *queue;
381
382 struct sk_buff *skb;
383
384 unsigned int entry_idx;
385
Helmut Schaa8857d6d2013-03-15 09:57:57 +0100386 u32 status;
387
Ivo van Doorn181d6902008-02-05 16:42:23 -0500388 void *priv_data;
389};
390
391/**
392 * enum queue_index: Queue index type
393 *
394 * @Q_INDEX: Index pointer to the current entry in the queue, if this entry is
395 * owned by the hardware then the queue is considered to be full.
Ivo van Doorn652a9dd2010-08-30 21:15:19 +0200396 * @Q_INDEX_DMA_DONE: Index pointer for the next entry which will have been
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300397 * transferred to the hardware.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500398 * @Q_INDEX_DONE: Index pointer to the next entry which will be completed by
399 * the hardware and for which we need to run the txdone handler. If this
400 * entry is not owned by the hardware the queue is considered to be empty.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500401 * @Q_INDEX_MAX: Keep last, used in &struct data_queue to determine the size
402 * of the index array.
403 */
404enum queue_index {
405 Q_INDEX,
Ivo van Doorn652a9dd2010-08-30 21:15:19 +0200406 Q_INDEX_DMA_DONE,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500407 Q_INDEX_DONE,
Ivo van Doorn181d6902008-02-05 16:42:23 -0500408 Q_INDEX_MAX,
409};
410
411/**
Ivo van Doorn0b7fde52010-12-13 12:35:17 +0100412 * enum data_queue_flags: Status flags for data queues
413 *
414 * @QUEUE_STARTED: The queue has been started. Fox RX queues this means the
415 * device might be DMA'ing skbuffers. TX queues will accept skbuffers to
416 * be transmitted and beacon queues will start beaconing the configured
417 * beacons.
418 * @QUEUE_PAUSED: The queue has been started but is currently paused.
419 * When this bit is set, the queue has been stopped in mac80211,
420 * preventing new frames to be enqueued. However, a few frames
421 * might still appear shortly after the pausing...
422 */
423enum data_queue_flags {
424 QUEUE_STARTED,
425 QUEUE_PAUSED,
426};
427
428/**
Ivo van Doorn181d6902008-02-05 16:42:23 -0500429 * struct data_queue: Data queue
430 *
431 * @rt2x00dev: Pointer to main &struct rt2x00dev where this queue belongs to.
432 * @entries: Base address of the &struct queue_entry which are
433 * part of this queue.
434 * @qid: The queue identification, see &enum data_queue_qid.
Ivo van Doorn0b7fde52010-12-13 12:35:17 +0100435 * @flags: Entry flags, see &enum queue_entry_flags.
436 * @status_lock: The mutex for protecting the start/stop/flush
437 * handling on this queue.
Gertjan van Wingerde77a861c2011-07-06 22:56:24 +0200438 * @tx_lock: Spinlock to serialize tx operations on this queue.
Ivo van Doorn813f0332010-11-06 15:48:05 +0100439 * @index_lock: Spinlock to protect index handling. Whenever @index, @index_done or
Ivo van Doorn181d6902008-02-05 16:42:23 -0500440 * @index_crypt needs to be changed this lock should be grabbed to prevent
441 * index corruption due to concurrency.
442 * @count: Number of frames handled in the queue.
443 * @limit: Maximum number of entries in the queue.
Ivo van Doornb8697672008-06-06 22:53:14 +0200444 * @threshold: Minimum number of free entries before queue is kicked by force.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500445 * @length: Number of frames in queue.
446 * @index: Index pointers to entry positions in the queue,
447 * use &enum queue_index to get a specific index field.
Ivo van Doorn2af0a572008-08-29 21:05:45 +0200448 * @txop: maximum burst time.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500449 * @aifs: The aifs value for outgoing frames (field ignored in RX queue).
450 * @cw_min: The cw min value for outgoing frames (field ignored in RX queue).
451 * @cw_max: The cw max value for outgoing frames (field ignored in RX queue).
452 * @data_size: Maximum data size for the frames in this queue.
453 * @desc_size: Hardware descriptor size for the data in this queue.
Gabor Juhos568f7a42013-06-04 13:40:38 +0200454 * @priv_size: Size of per-queue_entry private data.
Ivo van Doornf1ca2162008-11-13 23:07:33 +0100455 * @usb_endpoint: Device endpoint used for communication (USB only)
456 * @usb_maxpacket: Max packet size for given endpoint (USB only)
Ivo van Doorn181d6902008-02-05 16:42:23 -0500457 */
458struct data_queue {
459 struct rt2x00_dev *rt2x00dev;
460 struct queue_entry *entries;
461
462 enum data_queue_qid qid;
Ivo van Doorn0b7fde52010-12-13 12:35:17 +0100463 unsigned long flags;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500464
Ivo van Doorn0b7fde52010-12-13 12:35:17 +0100465 struct mutex status_lock;
Gertjan van Wingerde77a861c2011-07-06 22:56:24 +0200466 spinlock_t tx_lock;
Ivo van Doorn813f0332010-11-06 15:48:05 +0100467 spinlock_t index_lock;
Ivo van Doorn0b7fde52010-12-13 12:35:17 +0100468
Ivo van Doorn181d6902008-02-05 16:42:23 -0500469 unsigned int count;
470 unsigned short limit;
Ivo van Doornb8697672008-06-06 22:53:14 +0200471 unsigned short threshold;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500472 unsigned short length;
473 unsigned short index[Q_INDEX_MAX];
474
Ivo van Doorn2af0a572008-08-29 21:05:45 +0200475 unsigned short txop;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500476 unsigned short aifs;
477 unsigned short cw_min;
478 unsigned short cw_max;
479
480 unsigned short data_size;
Stanislaw Gruszkaf0bda572013-04-17 14:30:47 +0200481 unsigned char desc_size;
482 unsigned char winfo_size;
Gabor Juhos568f7a42013-06-04 13:40:38 +0200483 unsigned short priv_size;
Ivo van Doornf1ca2162008-11-13 23:07:33 +0100484
485 unsigned short usb_endpoint;
486 unsigned short usb_maxpacket;
Ivo van Doorn181d6902008-02-05 16:42:23 -0500487};
488
489/**
Ivo van Doorn181d6902008-02-05 16:42:23 -0500490 * queue_end - Return pointer to the last queue (HELPER MACRO).
491 * @__dev: Pointer to &struct rt2x00_dev
492 *
493 * Using the base rx pointer and the maximum number of available queues,
494 * this macro will return the address of 1 position beyond the end of the
495 * queues array.
496 */
497#define queue_end(__dev) \
498 &(__dev)->rx[(__dev)->data_queues]
499
500/**
501 * tx_queue_end - Return pointer to the last TX queue (HELPER MACRO).
502 * @__dev: Pointer to &struct rt2x00_dev
503 *
504 * Using the base tx pointer and the maximum number of available TX
505 * queues, this macro will return the address of 1 position beyond
506 * the end of the TX queue array.
507 */
508#define tx_queue_end(__dev) \
Gertjan van Wingerde61448f82008-05-10 13:43:33 +0200509 &(__dev)->tx[(__dev)->ops->tx_queues]
Ivo van Doorn181d6902008-02-05 16:42:23 -0500510
511/**
Ivo van Doornf1ca2162008-11-13 23:07:33 +0100512 * queue_next - Return pointer to next queue in list (HELPER MACRO).
513 * @__queue: Current queue for which we need the next queue
514 *
515 * Using the current queue address we take the address directly
516 * after the queue to take the next queue. Note that this macro
517 * should be used carefully since it does not protect against
518 * moving past the end of the list. (See macros &queue_end and
519 * &tx_queue_end for determining the end of the queue).
520 */
521#define queue_next(__queue) \
522 &(__queue)[1]
523
524/**
Ivo van Doorn181d6902008-02-05 16:42:23 -0500525 * queue_loop - Loop through the queues within a specific range (HELPER MACRO).
526 * @__entry: Pointer where the current queue entry will be stored in.
527 * @__start: Start queue pointer.
528 * @__end: End queue pointer.
529 *
530 * This macro will loop through all queues between &__start and &__end.
531 */
532#define queue_loop(__entry, __start, __end) \
533 for ((__entry) = (__start); \
Ivo van Doornf1ca2162008-11-13 23:07:33 +0100534 prefetch(queue_next(__entry)), (__entry) != (__end);\
535 (__entry) = queue_next(__entry))
Ivo van Doorn181d6902008-02-05 16:42:23 -0500536
537/**
538 * queue_for_each - Loop through all queues
539 * @__dev: Pointer to &struct rt2x00_dev
540 * @__entry: Pointer where the current queue entry will be stored in.
541 *
542 * This macro will loop through all available queues.
543 */
544#define queue_for_each(__dev, __entry) \
545 queue_loop(__entry, (__dev)->rx, queue_end(__dev))
546
547/**
548 * tx_queue_for_each - Loop through the TX queues
549 * @__dev: Pointer to &struct rt2x00_dev
550 * @__entry: Pointer where the current queue entry will be stored in.
551 *
552 * This macro will loop through all TX related queues excluding
553 * the Beacon and Atim queues.
554 */
555#define tx_queue_for_each(__dev, __entry) \
556 queue_loop(__entry, (__dev)->tx, tx_queue_end(__dev))
557
558/**
559 * txall_queue_for_each - Loop through all TX related queues
560 * @__dev: Pointer to &struct rt2x00_dev
561 * @__entry: Pointer where the current queue entry will be stored in.
562 *
563 * This macro will loop through all TX related queues including
564 * the Beacon and Atim queues.
565 */
566#define txall_queue_for_each(__dev, __entry) \
567 queue_loop(__entry, (__dev)->tx, queue_end(__dev))
568
569/**
Ivo van Doorn5eb7efe2010-08-23 19:54:21 +0200570 * rt2x00queue_for_each_entry - Loop through all entries in the queue
571 * @queue: Pointer to @data_queue
572 * @start: &enum queue_index Pointer to start index
573 * @end: &enum queue_index Pointer to end index
Helmut Schaa1dd0dbb2013-03-15 09:57:56 +0100574 * @data: Data to pass to the callback function
Ivo van Doorn5eb7efe2010-08-23 19:54:21 +0200575 * @fn: The function to call for each &struct queue_entry
576 *
577 * This will walk through all entries in the queue, in chronological
578 * order. This means it will start at the current @start pointer
579 * and will walk through the queue until it reaches the @end pointer.
Helmut Schaa10e11562011-04-18 15:27:43 +0200580 *
581 * If fn returns true for an entry rt2x00queue_for_each_entry will stop
582 * processing and return true as well.
Ivo van Doorn5eb7efe2010-08-23 19:54:21 +0200583 */
Helmut Schaa10e11562011-04-18 15:27:43 +0200584bool rt2x00queue_for_each_entry(struct data_queue *queue,
Ivo van Doorn5eb7efe2010-08-23 19:54:21 +0200585 enum queue_index start,
586 enum queue_index end,
Helmut Schaa1dd0dbb2013-03-15 09:57:56 +0100587 void *data,
588 bool (*fn)(struct queue_entry *entry,
589 void *data));
Ivo van Doorn5eb7efe2010-08-23 19:54:21 +0200590
591/**
Ivo van Doorn181d6902008-02-05 16:42:23 -0500592 * rt2x00queue_empty - Check if the queue is empty.
593 * @queue: Queue to check if empty.
594 */
595static inline int rt2x00queue_empty(struct data_queue *queue)
596{
597 return queue->length == 0;
598}
599
600/**
601 * rt2x00queue_full - Check if the queue is full.
602 * @queue: Queue to check if full.
603 */
604static inline int rt2x00queue_full(struct data_queue *queue)
605{
606 return queue->length == queue->limit;
607}
608
609/**
610 * rt2x00queue_free - Check the number of available entries in queue.
611 * @queue: Queue to check.
612 */
613static inline int rt2x00queue_available(struct data_queue *queue)
614{
615 return queue->limit - queue->length;
616}
617
618/**
Ivo van Doornb8697672008-06-06 22:53:14 +0200619 * rt2x00queue_threshold - Check if the queue is below threshold
620 * @queue: Queue to check.
621 */
622static inline int rt2x00queue_threshold(struct data_queue *queue)
623{
624 return rt2x00queue_available(queue) < queue->threshold;
625}
Ivo van Doorn652a9dd2010-08-30 21:15:19 +0200626/**
John W. Linvillecfef6042011-04-25 14:34:25 -0400627 * rt2x00queue_dma_timeout - Check if a timeout occurred for DMA transfers
Johannes Stezenbach75256f02011-04-18 15:29:38 +0200628 * @entry: Queue entry to check.
Ivo van Doorn652a9dd2010-08-30 21:15:19 +0200629 */
Johannes Stezenbach75256f02011-04-18 15:29:38 +0200630static inline int rt2x00queue_dma_timeout(struct queue_entry *entry)
Ivo van Doorn652a9dd2010-08-30 21:15:19 +0200631{
Johannes Stezenbach75256f02011-04-18 15:29:38 +0200632 if (!test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
633 return false;
634 return time_after(jiffies, entry->last_action + msecs_to_jiffies(100));
Ivo van Doornc965c742010-07-11 12:25:46 +0200635}
636
637/**
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200638 * _rt2x00_desc_read - Read a word from the hardware descriptor.
639 * @desc: Base descriptor address
640 * @word: Word index from where the descriptor should be read.
641 * @value: Address where the descriptor value should be written into.
642 */
643static inline void _rt2x00_desc_read(__le32 *desc, const u8 word, __le32 *value)
644{
645 *value = desc[word];
646}
647
648/**
649 * rt2x00_desc_read - Read a word from the hardware descriptor, this
650 * function will take care of the byte ordering.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500651 * @desc: Base descriptor address
652 * @word: Word index from where the descriptor should be read.
653 * @value: Address where the descriptor value should be written into.
654 */
655static inline void rt2x00_desc_read(__le32 *desc, const u8 word, u32 *value)
656{
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200657 __le32 tmp;
658 _rt2x00_desc_read(desc, word, &tmp);
659 *value = le32_to_cpu(tmp);
Ivo van Doorn181d6902008-02-05 16:42:23 -0500660}
661
662/**
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200663 * rt2x00_desc_write - write a word to the hardware descriptor, this
664 * function will take care of the byte ordering.
665 * @desc: Base descriptor address
666 * @word: Word index from where the descriptor should be written.
667 * @value: Value that should be written into the descriptor.
668 */
669static inline void _rt2x00_desc_write(__le32 *desc, const u8 word, __le32 value)
670{
671 desc[word] = value;
672}
673
674/**
675 * rt2x00_desc_write - write a word to the hardware descriptor.
Ivo van Doorn181d6902008-02-05 16:42:23 -0500676 * @desc: Base descriptor address
677 * @word: Word index from where the descriptor should be written.
678 * @value: Value that should be written into the descriptor.
679 */
680static inline void rt2x00_desc_write(__le32 *desc, const u8 word, u32 value)
681{
Ivo van Doorn2bb057d2008-08-04 16:37:44 +0200682 _rt2x00_desc_write(desc, word, cpu_to_le32(value));
Ivo van Doorn181d6902008-02-05 16:42:23 -0500683}
684
685#endif /* RT2X00QUEUE_H */