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
6 Extend rt2x00lib capabilities to support 802.11n,
7 it still lacks aggregation support, but that can
8 be added in the future.
10 Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
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
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
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
39 #define IEEE80211_HEADER 24
40 +#define AGGREGATION_SIZE 3840
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).
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;
57 + struct ieee80211_sta_ht_cap ht;
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,
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
74 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) {
75 + if (conf_is_ht40(conf))
76 + __set_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags);
78 + __clear_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags);
81 &rt2x00dev->spec.channels[conf->channel->hw_value],
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
87 EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
89 +static int rt2x00lib_rxdone_read_signal(struct rt2x00_dev *rt2x00dev,
90 + struct rxdone_entry_desc *rxdesc)
92 + struct ieee80211_supported_band *sband;
93 + const struct rt2x00_rate *rate;
99 + * For non-HT rates the MCS value needs to contain the
100 + * actually used rate modulation (CCK or OFDM).
102 + if (rxdesc->dev_flags & RXDONE_SIGNAL_MCS)
103 + signal = RATE_MCS(rxdesc->rate_mode, rxdesc->signal);
105 + signal = rxdesc->signal;
107 + type = (rxdesc->dev_flags & RXDONE_SIGNAL_MASK);
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);
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))) {
123 + WARNING(rt2x00dev, "Frame received with unrecognized signal, "
124 + "signal=0x%.4x, type=%d.\n", signal, type);
128 void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
129 struct queue_entry *entry)
131 struct rxdone_entry_desc rxdesc;
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;
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);
148 - * Update RX statistics.
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);
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))) {
164 - WARNING(rt2x00dev, "Frame received with unrecognized signal,"
165 - "signal=0x%.2x, type=%d.\n", rxdesc.signal,
166 - (rxdesc.dev_flags & RXDONE_SIGNAL_MASK));
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.
173 + if (rxdesc.rate_mode == RATE_MODE_CCK ||
174 + rxdesc.rate_mode == RATE_MODE_OFDM) {
175 + rate_idx = rt2x00lib_rxdone_read_signal(rt2x00dev, &rxdesc);
177 + rxdesc.flags |= RX_FLAG_HT;
178 + rate_idx = rxdesc.signal;
182 @@ -404,7 +431,7 @@ void rt2x00lib_rxdone(struct rt2x00_dev
183 rt2x00debug_update_crypto(rt2x00dev, &rxdesc);
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
195 + .mcs = RATE_MCS(RATE_MODE_CCK, 0),
198 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
202 + .mcs = RATE_MCS(RATE_MODE_CCK, 1),
205 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
209 + .mcs = RATE_MCS(RATE_MODE_CCK, 2),
212 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
216 + .mcs = RATE_MCS(RATE_MODE_CCK, 3),
219 .flags = DEV_RATE_OFDM,
223 + .mcs = RATE_MCS(RATE_MODE_OFDM, 0),
226 .flags = DEV_RATE_OFDM,
230 + .mcs = RATE_MCS(RATE_MODE_OFDM, 1),
233 .flags = DEV_RATE_OFDM,
237 + .mcs = RATE_MCS(RATE_MODE_OFDM, 2),
240 .flags = DEV_RATE_OFDM,
244 + .mcs = RATE_MCS(RATE_MODE_OFDM, 3),
247 .flags = DEV_RATE_OFDM,
251 + .mcs = RATE_MCS(RATE_MODE_OFDM, 4),
254 .flags = DEV_RATE_OFDM,
258 + .mcs = RATE_MCS(RATE_MODE_OFDM, 5),
261 .flags = DEV_RATE_OFDM,
265 + .mcs = RATE_MCS(RATE_MODE_OFDM, 6),
268 .flags = DEV_RATE_OFDM,
272 + .mcs = RATE_MCS(RATE_MODE_OFDM, 7),
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));
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));
295 +++ b/drivers/net/wireless/rt2x00/rt2x00ht.c
298 + Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
299 + <http://rt2x00.serialmonkey.com>
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.
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.
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.
319 + Abstract: rt2x00 HT specific routines.
322 +#include <linux/kernel.h>
323 +#include <linux/module.h>
326 +#include "rt2x00lib.h"
328 +void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
329 + struct txentry_desc *txdesc,
330 + struct ieee80211_rate *rate)
332 + struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
333 + const struct rt2x00_rate *hwrate = rt2x00_get_rate(rate->hw_value);
335 + if (tx_info->control.sta)
336 + txdesc->mpdu_density =
337 + tx_info->control.sta->ht_cap.ampdu_density;
339 + txdesc->mpdu_density = 0;
341 + txdesc->ba_size = 0; /* FIXME: What value is needed? */
342 + txdesc->stbc = 0; /* FIXME: What value is needed? */
344 + txdesc->mcs = rt2x00_get_rate_mcs(hwrate->mcs);
345 + if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
346 + txdesc->mcs |= 0x08;
351 + if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
352 + __set_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags);
355 + * Determine HT Mix/Greenfield rate mode
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);
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;
372 + unsigned short mcs;
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];
380 +#define RATE_MCS(__mode, __mcs) \
381 + ( (((__mode) & 0x00ff) << 8) | ((__mcs) & 0x00ff) )
383 +static inline int rt2x00_get_rate_mcs(const u16 mcs_value)
385 + return (mcs_value & 0x00ff);
389 * Radio control handlers.
391 @@ -330,6 +339,21 @@ static inline void rt2x00crypto_rx_inser
392 #endif /* CONFIG_RT2X00_LIB_CRYPTO */
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);
402 +static inline void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
403 + struct txentry_desc *txdesc,
404 + struct ieee80211_rate *rate)
407 +#endif /* CONFIG_RT2X00_LIB_HT */
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
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);
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
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,
447 @@ -163,7 +165,7 @@ enum rxdone_entry_desc_flags {
448 * from &rxdone_entry_desc to a signal value type.
450 #define RXDONE_SIGNAL_MASK \
451 - ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE )
452 + ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE | RXDONE_SIGNAL_MCS )
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 {
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.
480 enum txentry_desc_flags {
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,
492 @@ -271,7 +281,11 @@ enum txentry_desc_flags {
493 * @length_low: PLCP length low word.
494 * @signal: PLCP signal.
495 * @service: PLCP service.
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.
504 @@ -291,7 +305,11 @@ struct txentry_desc {