madwifi: fix the long standing bug that is triggered by nodes getting a timeout on...
[openwrt.git] / package / mac80211 / patches / 301-rt2x00-Implement-support-for-802.11n.patch
1 From 42d5399c2743dbd1ddaaadc8cb04adbfc65cc970 Mon Sep 17 00:00:00 2001
2 From: Ivo van Doorn <IvDoorn@gmail.com>
3 Date: Sat, 10 Jan 2009 11:01:10 +0100
4 Subject: [PATCH] rt2x00: Implement support for 802.11n
5
6 Extend rt2x00lib capabilities to support 802.11n,
7 it still lacks aggregation support, but that can
8 be added in the future.
9
10 Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
11 ---
12 drivers/net/wireless/rt2x00/Kconfig | 3 +
13 drivers/net/wireless/rt2x00/Makefile | 1 +
14 drivers/net/wireless/rt2x00/rt2x00.h | 5 ++
15 drivers/net/wireless/rt2x00/rt2x00config.c | 5 ++
16 drivers/net/wireless/rt2x00/rt2x00dev.c | 91 ++++++++++++++++++++-------
17 drivers/net/wireless/rt2x00/rt2x00ht.c | 69 +++++++++++++++++++++
18 drivers/net/wireless/rt2x00/rt2x00lib.h | 24 +++++++
19 drivers/net/wireless/rt2x00/rt2x00queue.c | 1 +
20 drivers/net/wireless/rt2x00/rt2x00queue.h | 26 +++++++-
21 9 files changed, 197 insertions(+), 28 deletions(-)
22 create mode 100644 drivers/net/wireless/rt2x00/rt2x00ht.c
23
24 --- a/drivers/net/wireless/rt2x00/Makefile
25 +++ b/drivers/net/wireless/rt2x00/Makefile
26 @@ -8,6 +8,7 @@ rt2x00lib-$(CONFIG_RT2X00_LIB_CRYPTO) +=
27 rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o
28 rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
29 rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o
30 +rt2x00lib-$(CONFIG_RT2X00_LIB_HT) += rt2x00ht.o
31
32 obj-$(CONFIG_RT2X00_LIB) += rt2x00lib.o
33 obj-$(CONFIG_RT2X00_LIB_PCI) += rt2x00pci.o
34 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36 @@ -108,6 +108,7 @@
37 */
38 #define ACK_SIZE 14
39 #define IEEE80211_HEADER 24
40 +#define AGGREGATION_SIZE 3840
41 #define PLCP 48
42 #define BEACON 100
43 #define PREAMBLE 144
44 @@ -357,6 +358,7 @@ static inline struct rt2x00_intf* vif_to
45 * for @tx_power_a, @tx_power_bg and @channels.
46 * @channels: Device/chipset specific channel values (See &struct rf_channel).
47 * @channels_info: Additional information for channels (See &struct channel_info).
48 + * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
49 */
50 struct hw_mode_spec {
51 unsigned int supported_bands;
52 @@ -370,6 +372,8 @@ struct hw_mode_spec {
53 unsigned int num_channels;
54 const struct rf_channel *channels;
55 const struct channel_info *channels_info;
56 +
57 + struct ieee80211_sta_ht_cap ht;
58 };
59
60 /*
61 @@ -604,6 +608,7 @@ enum rt2x00_flags {
62 CONFIG_EXTERNAL_LNA_BG,
63 CONFIG_DOUBLE_ANTENNA,
64 CONFIG_DISABLE_LINK_TUNING,
65 + CONFIG_CHANNEL_HT40,
66 };
67
68 /*
69 --- a/drivers/net/wireless/rt2x00/rt2x00config.c
70 +++ b/drivers/net/wireless/rt2x00/rt2x00config.c
71 @@ -173,6 +173,11 @@ void rt2x00lib_config(struct rt2x00_dev
72 libconf.conf = conf;
73
74 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) {
75 + if (conf_is_ht40(conf))
76 + __set_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags);
77 + else
78 + __clear_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags);
79 +
80 memcpy(&libconf.rf,
81 &rt2x00dev->spec.channels[conf->channel->hw_value],
82 sizeof(libconf.rf));
83 --- a/drivers/net/wireless/rt2x00/rt2x00dev.c
84 +++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
85 @@ -315,18 +315,54 @@ void rt2x00lib_txdone(struct queue_entry
86 }
87 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
88
89 +static int rt2x00lib_rxdone_read_signal(struct rt2x00_dev *rt2x00dev,
90 + struct rxdone_entry_desc *rxdesc)
91 +{
92 + struct ieee80211_supported_band *sband;
93 + const struct rt2x00_rate *rate;
94 + unsigned int i;
95 + int signal;
96 + int type;
97 +
98 + /*
99 + * For non-HT rates the MCS value needs to contain the
100 + * actually used rate modulation (CCK or OFDM).
101 + */
102 + if (rxdesc->dev_flags & RXDONE_SIGNAL_MCS)
103 + signal = RATE_MCS(rxdesc->rate_mode, rxdesc->signal);
104 + else
105 + signal = rxdesc->signal;
106 +
107 + type = (rxdesc->dev_flags & RXDONE_SIGNAL_MASK);
108 +
109 + sband = &rt2x00dev->bands[rt2x00dev->curr_band];
110 + for (i = 0; i < sband->n_bitrates; i++) {
111 + rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
112 +
113 + if (((type == RXDONE_SIGNAL_PLCP) &&
114 + (rate->plcp == signal)) ||
115 + ((type == RXDONE_SIGNAL_BITRATE) &&
116 + (rate->bitrate == signal)) ||
117 + ((type == RXDONE_SIGNAL_MCS) &&
118 + (rate->mcs == signal))) {
119 + return i;
120 + }
121 + }
122 +
123 + WARNING(rt2x00dev, "Frame received with unrecognized signal, "
124 + "signal=0x%.4x, type=%d.\n", signal, type);
125 + return 0;
126 +}
127 +
128 void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
129 struct queue_entry *entry)
130 {
131 struct rxdone_entry_desc rxdesc;
132 struct sk_buff *skb;
133 struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
134 - struct ieee80211_supported_band *sband;
135 - const struct rt2x00_rate *rate;
136 unsigned int header_length;
137 unsigned int align;
138 - unsigned int i;
139 - int idx = -1;
140 + int rate_idx;
141
142 /*
143 * Allocate a new sk_buffer. If no new buffer available, drop the
144 @@ -375,26 +411,17 @@ void rt2x00lib_rxdone(struct rt2x00_dev
145 skb_trim(entry->skb, rxdesc.size);
146
147 /*
148 - * Update RX statistics.
149 - */
150 - sband = &rt2x00dev->bands[rt2x00dev->curr_band];
151 - for (i = 0; i < sband->n_bitrates; i++) {
152 - rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
153 -
154 - if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
155 - (rate->plcp == rxdesc.signal)) ||
156 - ((rxdesc.dev_flags & RXDONE_SIGNAL_BITRATE) &&
157 - (rate->bitrate == rxdesc.signal))) {
158 - idx = i;
159 - break;
160 - }
161 - }
162 -
163 - if (idx < 0) {
164 - WARNING(rt2x00dev, "Frame received with unrecognized signal,"
165 - "signal=0x%.2x, type=%d.\n", rxdesc.signal,
166 - (rxdesc.dev_flags & RXDONE_SIGNAL_MASK));
167 - idx = 0;
168 + * Check if the frame was received using HT. In that case,
169 + * the rate is the MCS index and should be passed to mac80211
170 + * directly. Otherwise we need to translate the signal to
171 + * the correct bitrate index.
172 + */
173 + if (rxdesc.rate_mode == RATE_MODE_CCK ||
174 + rxdesc.rate_mode == RATE_MODE_OFDM) {
175 + rate_idx = rt2x00lib_rxdone_read_signal(rt2x00dev, &rxdesc);
176 + } else {
177 + rxdesc.flags |= RX_FLAG_HT;
178 + rate_idx = rxdesc.signal;
179 }
180
181 /*
182 @@ -404,7 +431,7 @@ void rt2x00lib_rxdone(struct rt2x00_dev
183 rt2x00debug_update_crypto(rt2x00dev, &rxdesc);
184
185 rx_status->mactime = rxdesc.timestamp;
186 - rx_status->rate_idx = idx;
187 + rx_status->rate_idx = rate_idx;
188 rx_status->qual = rt2x00link_calculate_signal(rt2x00dev, rxdesc.rssi);
189 rx_status->signal = rxdesc.rssi;
190 rx_status->noise = rxdesc.noise;
191 @@ -439,72 +466,84 @@ const struct rt2x00_rate rt2x00_supporte
192 .bitrate = 10,
193 .ratemask = BIT(0),
194 .plcp = 0x00,
195 + .mcs = RATE_MCS(RATE_MODE_CCK, 0),
196 },
197 {
198 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
199 .bitrate = 20,
200 .ratemask = BIT(1),
201 .plcp = 0x01,
202 + .mcs = RATE_MCS(RATE_MODE_CCK, 1),
203 },
204 {
205 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
206 .bitrate = 55,
207 .ratemask = BIT(2),
208 .plcp = 0x02,
209 + .mcs = RATE_MCS(RATE_MODE_CCK, 2),
210 },
211 {
212 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
213 .bitrate = 110,
214 .ratemask = BIT(3),
215 .plcp = 0x03,
216 + .mcs = RATE_MCS(RATE_MODE_CCK, 3),
217 },
218 {
219 .flags = DEV_RATE_OFDM,
220 .bitrate = 60,
221 .ratemask = BIT(4),
222 .plcp = 0x0b,
223 + .mcs = RATE_MCS(RATE_MODE_OFDM, 0),
224 },
225 {
226 .flags = DEV_RATE_OFDM,
227 .bitrate = 90,
228 .ratemask = BIT(5),
229 .plcp = 0x0f,
230 + .mcs = RATE_MCS(RATE_MODE_OFDM, 1),
231 },
232 {
233 .flags = DEV_RATE_OFDM,
234 .bitrate = 120,
235 .ratemask = BIT(6),
236 .plcp = 0x0a,
237 + .mcs = RATE_MCS(RATE_MODE_OFDM, 2),
238 },
239 {
240 .flags = DEV_RATE_OFDM,
241 .bitrate = 180,
242 .ratemask = BIT(7),
243 .plcp = 0x0e,
244 + .mcs = RATE_MCS(RATE_MODE_OFDM, 3),
245 },
246 {
247 .flags = DEV_RATE_OFDM,
248 .bitrate = 240,
249 .ratemask = BIT(8),
250 .plcp = 0x09,
251 + .mcs = RATE_MCS(RATE_MODE_OFDM, 4),
252 },
253 {
254 .flags = DEV_RATE_OFDM,
255 .bitrate = 360,
256 .ratemask = BIT(9),
257 .plcp = 0x0d,
258 + .mcs = RATE_MCS(RATE_MODE_OFDM, 5),
259 },
260 {
261 .flags = DEV_RATE_OFDM,
262 .bitrate = 480,
263 .ratemask = BIT(10),
264 .plcp = 0x08,
265 + .mcs = RATE_MCS(RATE_MODE_OFDM, 6),
266 },
267 {
268 .flags = DEV_RATE_OFDM,
269 .bitrate = 540,
270 .ratemask = BIT(11),
271 .plcp = 0x0c,
272 + .mcs = RATE_MCS(RATE_MODE_OFDM, 7),
273 },
274 };
275
276 @@ -580,6 +619,8 @@ static int rt2x00lib_probe_hw_modes(stru
277 rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates;
278 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
279 &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
280 + memcpy(&rt2x00dev->bands[IEEE80211_BAND_2GHZ].ht_cap,
281 + &spec->ht, sizeof(spec->ht));
282 }
283
284 /*
285 @@ -596,6 +637,8 @@ static int rt2x00lib_probe_hw_modes(stru
286 rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
287 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
288 &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
289 + memcpy(&rt2x00dev->bands[IEEE80211_BAND_5GHZ].ht_cap,
290 + &spec->ht, sizeof(spec->ht));
291 }
292
293 return 0;
294 --- /dev/null
295 +++ b/drivers/net/wireless/rt2x00/rt2x00ht.c
296 @@ -0,0 +1,69 @@
297 +/*
298 + Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
299 + <http://rt2x00.serialmonkey.com>
300 +
301 + This program is free software; you can redistribute it and/or modify
302 + it under the terms of the GNU General Public License as published by
303 + the Free Software Foundation; either version 2 of the License, or
304 + (at your option) any later version.
305 +
306 + This program is distributed in the hope that it will be useful,
307 + but WITHOUT ANY WARRANTY; without even the implied warranty of
308 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
309 + GNU General Public License for more details.
310 +
311 + You should have received a copy of the GNU General Public License
312 + along with this program; if not, write to the
313 + Free Software Foundation, Inc.,
314 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
315 + */
316 +
317 +/*
318 + Module: rt2x00lib
319 + Abstract: rt2x00 HT specific routines.
320 + */
321 +
322 +#include <linux/kernel.h>
323 +#include <linux/module.h>
324 +
325 +#include "rt2x00.h"
326 +#include "rt2x00lib.h"
327 +
328 +void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
329 + struct txentry_desc *txdesc,
330 + struct ieee80211_rate *rate)
331 +{
332 + struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
333 + const struct rt2x00_rate *hwrate = rt2x00_get_rate(rate->hw_value);
334 +
335 + if (tx_info->control.sta)
336 + txdesc->mpdu_density =
337 + tx_info->control.sta->ht_cap.ampdu_density;
338 + else
339 + txdesc->mpdu_density = 0;
340 +
341 + txdesc->ba_size = 0; /* FIXME: What value is needed? */
342 + txdesc->stbc = 0; /* FIXME: What value is needed? */
343 +
344 + txdesc->mcs = rt2x00_get_rate_mcs(hwrate->mcs);
345 + if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
346 + txdesc->mcs |= 0x08;
347 +
348 + /*
349 + * Convert flags
350 + */
351 + if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
352 + __set_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags);
353 +
354 + /*
355 + * Determine HT Mix/Greenfield rate mode
356 + */
357 + if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
358 + txdesc->rate_mode = RATE_MODE_HT_MIX;
359 + if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD)
360 + txdesc->rate_mode = RATE_MODE_HT_GREENFIELD;
361 + if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
362 + __set_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags);
363 + if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
364 + __set_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags);
365 +}
366 --- a/drivers/net/wireless/rt2x00/rt2x00lib.h
367 +++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
368 @@ -48,6 +48,7 @@ struct rt2x00_rate {
369 unsigned short ratemask;
370
371 unsigned short plcp;
372 + unsigned short mcs;
373 };
374
375 extern const struct rt2x00_rate rt2x00_supported_rates[12];
376 @@ -57,6 +58,14 @@ static inline const struct rt2x00_rate *
377 return &rt2x00_supported_rates[hw_value & 0xff];
378 }
379
380 +#define RATE_MCS(__mode, __mcs) \
381 + ( (((__mode) & 0x00ff) << 8) | ((__mcs) & 0x00ff) )
382 +
383 +static inline int rt2x00_get_rate_mcs(const u16 mcs_value)
384 +{
385 + return (mcs_value & 0x00ff);
386 +}
387 +
388 /*
389 * Radio control handlers.
390 */
391 @@ -330,6 +339,21 @@ static inline void rt2x00crypto_rx_inser
392 #endif /* CONFIG_RT2X00_LIB_CRYPTO */
393
394 /*
395 + * HT handlers.
396 + */
397 +#ifdef CONFIG_RT2X00_LIB_HT
398 +void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
399 + struct txentry_desc *txdesc,
400 + struct ieee80211_rate *rate);
401 +#else
402 +static inline void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
403 + struct txentry_desc *txdesc,
404 + struct ieee80211_rate *rate)
405 +{
406 +}
407 +#endif /* CONFIG_RT2X00_LIB_HT */
408 +
409 +/*
410 * RFkill handlers.
411 */
412 #ifdef CONFIG_RT2X00_LIB_RFKILL
413 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
414 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
415 @@ -326,6 +326,7 @@ static void rt2x00queue_create_tx_descri
416 * Apply TX descriptor handling by components
417 */
418 rt2x00crypto_create_tx_descriptor(entry, txdesc);
419 + rt2x00ht_create_tx_descriptor(entry, txdesc, rate);
420 rt2x00queue_create_tx_descriptor_seq(entry, txdesc);
421 rt2x00queue_create_tx_descriptor_plcp(entry, txdesc, hwrate);
422 }
423 --- a/drivers/net/wireless/rt2x00/rt2x00queue.h
424 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.h
425 @@ -145,6 +145,7 @@ static inline struct skb_frame_desc* get
426 *
427 * @RXDONE_SIGNAL_PLCP: Signal field contains the plcp value.
428 * @RXDONE_SIGNAL_BITRATE: Signal field contains the bitrate value.
429 + * @RXDONE_SIGNAL_MCS: Signal field contains the mcs value.
430 * @RXDONE_MY_BSS: Does this frame originate from device's BSS.
431 * @RXDONE_CRYPTO_IV: Driver provided IV/EIV data.
432 * @RXDONE_CRYPTO_ICV: Driver provided ICV data.
433 @@ -152,9 +153,10 @@ static inline struct skb_frame_desc* get
434 enum rxdone_entry_desc_flags {
435 RXDONE_SIGNAL_PLCP = 1 << 0,
436 RXDONE_SIGNAL_BITRATE = 1 << 1,
437 - RXDONE_MY_BSS = 1 << 2,
438 - RXDONE_CRYPTO_IV = 1 << 3,
439 - RXDONE_CRYPTO_ICV = 1 << 4,
440 + RXDONE_SIGNAL_MCS = 1 << 2,
441 + RXDONE_MY_BSS = 1 << 3,
442 + RXDONE_CRYPTO_IV = 1 << 4,
443 + RXDONE_CRYPTO_ICV = 1 << 5,
444 };
445
446 /**
447 @@ -163,7 +165,7 @@ enum rxdone_entry_desc_flags {
448 * from &rxdone_entry_desc to a signal value type.
449 */
450 #define RXDONE_SIGNAL_MASK \
451 - ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE )
452 + ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE | RXDONE_SIGNAL_MCS )
453
454 /**
455 * struct rxdone_entry_desc: RX Entry descriptor
456 @@ -177,6 +179,7 @@ enum rxdone_entry_desc_flags {
457 * @size: Data size of the received frame.
458 * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags).
459 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
460 + * @rate_mode: Rate mode (See @enum rate_modulation).
461 * @cipher: Cipher type used during decryption.
462 * @cipher_status: Decryption status.
463 * @iv: IV/EIV data used during decryption.
464 @@ -190,6 +193,7 @@ struct rxdone_entry_desc {
465 int size;
466 int flags;
467 int dev_flags;
468 + u16 rate_mode;
469 u8 cipher;
470 u8 cipher_status;
471
472 @@ -243,6 +247,9 @@ struct txdone_entry_desc {
473 * @ENTRY_TXD_ENCRYPT_PAIRWISE: Use pairwise key table (instead of shared).
474 * @ENTRY_TXD_ENCRYPT_IV: Generate IV/EIV in hardware.
475 * @ENTRY_TXD_ENCRYPT_MMIC: Generate MIC in hardware.
476 + * @ENTRY_TXD_HT_AMPDU: This frame is part of an AMPDU.
477 + * @ENTRY_TXD_HT_BW_40: Use 40MHz Bandwidth.
478 + * @ENTRY_TXD_HT_SHORT_GI: Use short GI.
479 */
480 enum txentry_desc_flags {
481 ENTRY_TXD_RTS_FRAME,
482 @@ -258,6 +265,9 @@ enum txentry_desc_flags {
483 ENTRY_TXD_ENCRYPT_PAIRWISE,
484 ENTRY_TXD_ENCRYPT_IV,
485 ENTRY_TXD_ENCRYPT_MMIC,
486 + ENTRY_TXD_HT_AMPDU,
487 + ENTRY_TXD_HT_BW_40,
488 + ENTRY_TXD_HT_SHORT_GI,
489 };
490
491 /**
492 @@ -271,7 +281,11 @@ enum txentry_desc_flags {
493 * @length_low: PLCP length low word.
494 * @signal: PLCP signal.
495 * @service: PLCP service.
496 + * @msc: MCS.
497 + * @stbc: STBC.
498 + * @ba_size: BA size.
499 * @rate_mode: Rate mode (See @enum rate_modulation).
500 + * @mpdu_density: MDPU density.
501 * @retry_limit: Max number of retries.
502 * @aifs: AIFS value.
503 * @ifs: IFS value.
504 @@ -291,7 +305,11 @@ struct txentry_desc {
505 u16 signal;
506 u16 service;
507
508 + u16 mcs;
509 + u16 stbc;
510 + u16 ba_size;
511 u16 rate_mode;
512 + u16 mpdu_density;
513
514 short retry_limit;
515 short aifs;
This page took 0.086307 seconds and 5 git commands to generate.