aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2008-01-24 13:38:38 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-02-29 15:19:32 -0500
commit8318d78a44d49ac1edf2bdec7299de3617c4232e (patch)
treed434634418edd7399737801615d247be06616fdd
parent10b6b80145cc93887dd8aab99bfffa375e9add31 (diff)
cfg80211 API for channels/bitrates, mac80211 and driver conversion
This patch creates new cfg80211 wiphy API for channel and bitrate registration and converts mac80211 and drivers to the new API. The old mac80211 API is completely ripped out. All drivers (except ath5k) are updated to the new API, in many cases I expect that optimisations can be done. Along with the regulatory code I've also ripped out the IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag, I believe it to be unnecessary if the hardware simply gives us whatever channels it wants to support and we then enable/disable them as required, which is pretty much required for travelling. Additionally, the patch adds proper "basic" rate handling for STA mode interface, AP mode interface will have to have new API added to allow userspace to set the basic rate set, currently it'll be empty... However, the basic rate handling will need to be moved to the BSS conf stuff. I do expect there to be bugs in this, especially wrt. transmit power handling where I'm basically clueless about how it should work. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/Kconfig1
-rw-r--r--drivers/net/wireless/adm8211.c80
-rw-r--r--drivers/net/wireless/adm8211.h65
-rw-r--r--drivers/net/wireless/b43/b43.h5
-rw-r--r--drivers/net/wireless/b43/main.c119
-rw-r--r--drivers/net/wireless/b43/sysfs.c89
-rw-r--r--drivers/net/wireless/b43/xmit.c81
-rw-r--r--drivers/net/wireless/b43legacy/b43legacy.h4
-rw-r--r--drivers/net/wireless/b43legacy/main.c159
-rw-r--r--drivers/net/wireless/b43legacy/xmit.c64
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c88
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c35
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-rs.c82
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c43
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.h16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c445
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c438
-rw-r--r--drivers/net/wireless/p54.h4
-rw-r--r--drivers/net/wireless/p54common.c74
-rw-r--r--drivers/net/wireless/p54common.h75
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h11
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00config.c33
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c149
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c23
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c23
-rw-r--r--drivers/net/wireless/rtl8180.h2
-rw-r--r--drivers/net/wireless/rtl8180_dev.c93
-rw-r--r--drivers/net/wireless/rtl8180_grf5101.c5
-rw-r--r--drivers/net/wireless/rtl8180_max2820.c5
-rw-r--r--drivers/net/wireless/rtl8180_rtl8225.c15
-rw-r--r--drivers/net/wireless/rtl8180_sa2400.c5
-rw-r--r--drivers/net/wireless/rtl8187.h2
-rw-r--r--drivers/net/wireless/rtl8187_dev.c82
-rw-r--r--drivers/net/wireless/rtl8187_rtl8225.c15
-rw-r--r--drivers/net/wireless/rtl818x.h70
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.c15
-rw-r--r--drivers/net/wireless/zd1211rw/zd_ieee80211.c11
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c170
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.h2
-rw-r--r--include/net/mac80211.h197
-rw-r--r--include/net/wireless.h168
-rw-r--r--net/mac80211/Makefile1
-rw-r--r--net/mac80211/cfg.c11
-rw-r--r--net/mac80211/debugfs.c47
-rw-r--r--net/mac80211/debugfs_sta.c18
-rw-r--r--net/mac80211/ieee80211.c112
-rw-r--r--net/mac80211/ieee80211_i.h63
-rw-r--r--net/mac80211/ieee80211_iface.c2
-rw-r--r--net/mac80211/ieee80211_ioctl.c127
-rw-r--r--net/mac80211/ieee80211_rate.c15
-rw-r--r--net/mac80211/ieee80211_rate.h28
-rw-r--r--net/mac80211/ieee80211_sta.c384
-rw-r--r--net/mac80211/rc80211_pid_algo.c76
-rw-r--r--net/mac80211/rc80211_simple.c66
-rw-r--r--net/mac80211/regdomain.c152
-rw-r--r--net/mac80211/rx.c82
-rw-r--r--net/mac80211/sta_info.c24
-rw-r--r--net/mac80211/sta_info.h10
-rw-r--r--net/mac80211/tx.c164
-rw-r--r--net/mac80211/util.c142
-rw-r--r--net/wireless/Makefile2
-rw-r--r--net/wireless/core.c41
-rw-r--r--net/wireless/core.h3
-rw-r--r--net/wireless/reg.c153
-rw-r--r--net/wireless/util.c98
66 files changed, 2116 insertions, 2781 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 714a6ca30ad2..cd5fcc67e954 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -735,6 +735,7 @@ config P54_PCI
735config ATH5K 735config ATH5K
736 tristate "Atheros 5xxx wireless cards support" 736 tristate "Atheros 5xxx wireless cards support"
737 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL 737 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL
738 depends on BROKEN
738 ---help--- 739 ---help---
739 This module adds support for wireless adapters based on 740 This module adds support for wireless adapters based on
740 Atheros 5xxx chipset. 741 Atheros 5xxx chipset.
diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index 79796186713e..7d4218206c47 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -48,6 +48,32 @@ static struct pci_device_id adm8211_pci_id_table[] __devinitdata = {
48 { 0 } 48 { 0 }
49}; 49};
50 50
51static struct ieee80211_rate adm8211_rates[] = {
52 { .bitrate = 10, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
53 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
54 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
55 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
56 { .bitrate = 220, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, /* XX ?? */
57};
58
59static const struct ieee80211_channel adm8211_channels[] = {
60 { .center_freq = 2412},
61 { .center_freq = 2417},
62 { .center_freq = 2422},
63 { .center_freq = 2427},
64 { .center_freq = 2432},
65 { .center_freq = 2437},
66 { .center_freq = 2442},
67 { .center_freq = 2447},
68 { .center_freq = 2452},
69 { .center_freq = 2457},
70 { .center_freq = 2462},
71 { .center_freq = 2467},
72 { .center_freq = 2472},
73 { .center_freq = 2484},
74};
75
76
51static void adm8211_eeprom_register_read(struct eeprom_93cx6 *eeprom) 77static void adm8211_eeprom_register_read(struct eeprom_93cx6 *eeprom)
52{ 78{
53 struct adm8211_priv *priv = eeprom->data; 79 struct adm8211_priv *priv = eeprom->data;
@@ -155,17 +181,17 @@ static int adm8211_read_eeprom(struct ieee80211_hw *dev)
155 printk(KERN_DEBUG "%s (adm8211): Channel range: %d - %d\n", 181 printk(KERN_DEBUG "%s (adm8211): Channel range: %d - %d\n",
156 pci_name(priv->pdev), (int)chan_range.min, (int)chan_range.max); 182 pci_name(priv->pdev), (int)chan_range.min, (int)chan_range.max);
157 183
158 priv->modes[0].num_channels = chan_range.max - chan_range.min + 1; 184 BUILD_BUG_ON(sizeof(priv->channels) != sizeof(adm8211_channels));
159 priv->modes[0].channels = priv->channels;
160 185
161 memcpy(priv->channels, adm8211_channels, sizeof(adm8211_channels)); 186 memcpy(priv->channels, adm8211_channels, sizeof(priv->channels));
187 priv->band.channels = priv->channels;
188 priv->band.n_channels = ARRAY_SIZE(adm8211_channels);
189 priv->band.bitrates = adm8211_rates;
190 priv->band.n_bitrates = ARRAY_SIZE(adm8211_rates);
162 191
163 for (i = 1; i <= ARRAY_SIZE(adm8211_channels); i++) 192 for (i = 1; i <= ARRAY_SIZE(adm8211_channels); i++)
164 if (i >= chan_range.min && i <= chan_range.max) 193 if (i < chan_range.min || i > chan_range.max)
165 priv->channels[i - 1].flag = 194 priv->channels[i - 1].flags |= IEEE80211_CHAN_DISABLED;
166 IEEE80211_CHAN_W_SCAN |
167 IEEE80211_CHAN_W_ACTIVE_SCAN |
168 IEEE80211_CHAN_W_IBSS;
169 195
170 switch (priv->eeprom->specific_bbptype) { 196 switch (priv->eeprom->specific_bbptype) {
171 case ADM8211_BBP_RFMD3000: 197 case ADM8211_BBP_RFMD3000:
@@ -347,7 +373,6 @@ static void adm8211_interrupt_rci(struct ieee80211_hw *dev)
347 unsigned int pktlen; 373 unsigned int pktlen;
348 struct sk_buff *skb, *newskb; 374 struct sk_buff *skb, *newskb;
349 unsigned int limit = priv->rx_ring_size; 375 unsigned int limit = priv->rx_ring_size;
350 static const u8 rate_tbl[] = {10, 20, 55, 110, 220};
351 u8 rssi, rate; 376 u8 rssi, rate;
352 377
353 while (!(priv->rx_ring[entry].status & cpu_to_le32(RDES0_STATUS_OWN))) { 378 while (!(priv->rx_ring[entry].status & cpu_to_le32(RDES0_STATUS_OWN))) {
@@ -425,12 +450,10 @@ static void adm8211_interrupt_rci(struct ieee80211_hw *dev)
425 else 450 else
426 rx_status.ssi = 100 - rssi; 451 rx_status.ssi = 100 - rssi;
427 452
428 if (rate <= 4) 453 rx_status.rate_idx = rate;
429 rx_status.rate = rate_tbl[rate];
430 454
431 rx_status.channel = priv->channel; 455 rx_status.freq = adm8211_channels[priv->channel - 1].center_freq;
432 rx_status.freq = adm8211_channels[priv->channel - 1].freq; 456 rx_status.band = IEEE80211_BAND_2GHZ;
433 rx_status.phymode = MODE_IEEE80211B;
434 457
435 ieee80211_rx_irqsafe(dev, skb, &rx_status); 458 ieee80211_rx_irqsafe(dev, skb, &rx_status);
436 } 459 }
@@ -1054,7 +1077,7 @@ static int adm8211_set_rate(struct ieee80211_hw *dev)
1054 if (priv->pdev->revision != ADM8211_REV_BA) { 1077 if (priv->pdev->revision != ADM8211_REV_BA) {
1055 rate_buf[0] = ARRAY_SIZE(adm8211_rates); 1078 rate_buf[0] = ARRAY_SIZE(adm8211_rates);
1056 for (i = 0; i < ARRAY_SIZE(adm8211_rates); i++) 1079 for (i = 0; i < ARRAY_SIZE(adm8211_rates); i++)
1057 rate_buf[i + 1] = (adm8211_rates[i].rate / 5) | 0x80; 1080 rate_buf[i + 1] = (adm8211_rates[i].bitrate / 5) | 0x80;
1058 } else { 1081 } else {
1059 /* workaround for rev BA specific bug */ 1082 /* workaround for rev BA specific bug */
1060 rate_buf[0] = 0x04; 1083 rate_buf[0] = 0x04;
@@ -1303,9 +1326,10 @@ static int adm8211_set_ssid(struct ieee80211_hw *dev, u8 *ssid, size_t ssid_len)
1303static int adm8211_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf) 1326static int adm8211_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
1304{ 1327{
1305 struct adm8211_priv *priv = dev->priv; 1328 struct adm8211_priv *priv = dev->priv;
1329 int channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
1306 1330
1307 if (conf->channel != priv->channel) { 1331 if (channel != priv->channel) {
1308 priv->channel = conf->channel; 1332 priv->channel = channel;
1309 adm8211_rf_set_channel(dev, priv->channel); 1333 adm8211_rf_set_channel(dev, priv->channel);
1310 } 1334 }
1311 1335
@@ -1680,10 +1704,10 @@ static int adm8211_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
1680 1704
1681 if (control->tx_rate < 0) { 1705 if (control->tx_rate < 0) {
1682 short_preamble = 1; 1706 short_preamble = 1;
1683 plcp_signal = -control->tx_rate; 1707 plcp_signal = -control->tx_rate->bitrate;
1684 } else { 1708 } else {
1685 short_preamble = 0; 1709 short_preamble = 0;
1686 plcp_signal = control->tx_rate; 1710 plcp_signal = control->tx_rate->bitrate;
1687 } 1711 }
1688 1712
1689 hdr = (struct ieee80211_hdr *)skb->data; 1713 hdr = (struct ieee80211_hdr *)skb->data;
@@ -1880,18 +1904,11 @@ static int __devinit adm8211_probe(struct pci_dev *pdev,
1880 SET_IEEE80211_PERM_ADDR(dev, perm_addr); 1904 SET_IEEE80211_PERM_ADDR(dev, perm_addr);
1881 1905
1882 dev->extra_tx_headroom = sizeof(struct adm8211_tx_hdr); 1906 dev->extra_tx_headroom = sizeof(struct adm8211_tx_hdr);
1883 dev->flags = IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED; 1907 /* dev->flags = IEEE80211_HW_RX_INCLUDES_FCS in promisc mode */
1884 /* IEEE80211_HW_RX_INCLUDES_FCS in promisc mode */
1885 1908
1886 dev->channel_change_time = 1000; 1909 dev->channel_change_time = 1000;
1887 dev->max_rssi = 100; /* FIXME: find better value */ 1910 dev->max_rssi = 100; /* FIXME: find better value */
1888 1911
1889 priv->modes[0].mode = MODE_IEEE80211B;
1890 /* channel info filled in by adm8211_read_eeprom */
1891 memcpy(priv->rates, adm8211_rates, sizeof(adm8211_rates));
1892 priv->modes[0].num_rates = ARRAY_SIZE(adm8211_rates);
1893 priv->modes[0].rates = priv->rates;
1894
1895 dev->queues = 1; /* ADM8211C supports more, maybe ADM8211B too */ 1912 dev->queues = 1; /* ADM8211C supports more, maybe ADM8211B too */
1896 1913
1897 priv->retry_limit = 3; 1914 priv->retry_limit = 3;
@@ -1917,14 +1934,7 @@ static int __devinit adm8211_probe(struct pci_dev *pdev,
1917 goto err_free_desc; 1934 goto err_free_desc;
1918 } 1935 }
1919 1936
1920 priv->channel = priv->modes[0].channels[0].chan; 1937 priv->channel = 1;
1921
1922 err = ieee80211_register_hwmode(dev, &priv->modes[0]);
1923 if (err) {
1924 printk(KERN_ERR "%s (adm8211): Can't register hwmode\n",
1925 pci_name(pdev));
1926 goto err_free_desc;
1927 }
1928 1938
1929 err = ieee80211_register_hw(dev); 1939 err = ieee80211_register_hw(dev);
1930 if (err) { 1940 if (err) {
diff --git a/drivers/net/wireless/adm8211.h b/drivers/net/wireless/adm8211.h
index ef326fed42e4..8d7c564b3b04 100644
--- a/drivers/net/wireless/adm8211.h
+++ b/drivers/net/wireless/adm8211.h
@@ -534,61 +534,6 @@ struct adm8211_eeprom {
534 u8 cis_data[0]; /* 0x80, 384 bytes */ 534 u8 cis_data[0]; /* 0x80, 384 bytes */
535} __attribute__ ((packed)); 535} __attribute__ ((packed));
536 536
537static const struct ieee80211_rate adm8211_rates[] = {
538 { .rate = 10,
539 .val = 10,
540 .val2 = -10,
541 .flags = IEEE80211_RATE_CCK_2 },
542 { .rate = 20,
543 .val = 20,
544 .val2 = -20,
545 .flags = IEEE80211_RATE_CCK_2 },
546 { .rate = 55,
547 .val = 55,
548 .val2 = -55,
549 .flags = IEEE80211_RATE_CCK_2 },
550 { .rate = 110,
551 .val = 110,
552 .val2 = -110,
553 .flags = IEEE80211_RATE_CCK_2 }
554};
555
556struct ieee80211_chan_range {
557 u8 min;
558 u8 max;
559};
560
561static const struct ieee80211_channel adm8211_channels[] = {
562 { .chan = 1,
563 .freq = 2412},
564 { .chan = 2,
565 .freq = 2417},
566 { .chan = 3,
567 .freq = 2422},
568 { .chan = 4,
569 .freq = 2427},
570 { .chan = 5,
571 .freq = 2432},
572 { .chan = 6,
573 .freq = 2437},
574 { .chan = 7,
575 .freq = 2442},
576 { .chan = 8,
577 .freq = 2447},
578 { .chan = 9,
579 .freq = 2452},
580 { .chan = 10,
581 .freq = 2457},
582 { .chan = 11,
583 .freq = 2462},
584 { .chan = 12,
585 .freq = 2467},
586 { .chan = 13,
587 .freq = 2472},
588 { .chan = 14,
589 .freq = 2484},
590};
591
592struct adm8211_priv { 537struct adm8211_priv {
593 struct pci_dev *pdev; 538 struct pci_dev *pdev;
594 spinlock_t lock; 539 spinlock_t lock;
@@ -603,9 +548,8 @@ struct adm8211_priv {
603 unsigned int cur_tx, dirty_tx, cur_rx; 548 unsigned int cur_tx, dirty_tx, cur_rx;
604 549
605 struct ieee80211_low_level_stats stats; 550 struct ieee80211_low_level_stats stats;
606 struct ieee80211_hw_mode modes[1]; 551 struct ieee80211_supported_band band;
607 struct ieee80211_channel channels[ARRAY_SIZE(adm8211_channels)]; 552 struct ieee80211_channel channels[14];
608 struct ieee80211_rate rates[ARRAY_SIZE(adm8211_rates)];
609 int mode; 553 int mode;
610 554
611 int channel; 555 int channel;
@@ -643,6 +587,11 @@ struct adm8211_priv {
643 } transceiver_type; 587 } transceiver_type;
644}; 588};
645 589
590struct ieee80211_chan_range {
591 u8 min;
592 u8 max;
593};
594
646static const struct ieee80211_chan_range cranges[] = { 595static const struct ieee80211_chan_range cranges[] = {
647 {1, 11}, /* FCC */ 596 {1, 11}, /* FCC */
648 {1, 11}, /* IC */ 597 {1, 11}, /* IC */
diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
index f13346ba9dd2..3e40323cd43f 100644
--- a/drivers/net/wireless/b43/b43.h
+++ b/drivers/net/wireless/b43/b43.h
@@ -468,10 +468,6 @@ struct b43_phy {
468 u8 possible_phymodes; 468 u8 possible_phymodes;
469 /* GMODE bit enabled? */ 469 /* GMODE bit enabled? */
470 bool gmode; 470 bool gmode;
471 /* Possible ieee80211 subsystem hwmodes for this PHY.
472 * Which mode is selected, depends on thr GMODE enabled bit */
473#define B43_MAX_PHYHWMODES 2
474 struct ieee80211_hw_mode hwmodes[B43_MAX_PHYHWMODES];
475 471
476 /* Analog Type */ 472 /* Analog Type */
477 u8 analog; 473 u8 analog;
@@ -727,7 +723,6 @@ struct b43_wldev {
727 723
728 bool bad_frames_preempt; /* Use "Bad Frames Preemption" (default off) */ 724 bool bad_frames_preempt; /* Use "Bad Frames Preemption" (default off) */
729 bool dfq_valid; /* Directed frame queue valid (IBSS PS mode, ATIM) */ 725 bool dfq_valid; /* Directed frame queue valid (IBSS PS mode, ATIM) */
730 bool short_preamble; /* TRUE, if short preamble is enabled. */
731 bool short_slot; /* TRUE, if short slot timing is enabled. */ 726 bool short_slot; /* TRUE, if short slot timing is enabled. */
732 bool radio_hw_enable; /* saved state of radio hardware enabled state */ 727 bool radio_hw_enable; /* saved state of radio hardware enabled state */
733 bool suspend_in_progress; /* TRUE, if we are in a suspend/resume cycle */ 728 bool suspend_in_progress; /* TRUE, if we are in a suspend/resume cycle */
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 51dfce16178a..017a041d07d0 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -96,25 +96,29 @@ MODULE_DEVICE_TABLE(ssb, b43_ssb_tbl);
96 * data in there. This data is the same for all devices, so we don't 96 * data in there. This data is the same for all devices, so we don't
97 * get concurrency issues */ 97 * get concurrency issues */
98#define RATETAB_ENT(_rateid, _flags) \ 98#define RATETAB_ENT(_rateid, _flags) \
99 { \ 99 { \
100 .rate = B43_RATE_TO_BASE100KBPS(_rateid), \ 100 .bitrate = B43_RATE_TO_BASE100KBPS(_rateid), \
101 .val = (_rateid), \ 101 .hw_value = (_rateid), \
102 .val2 = (_rateid), \ 102 .flags = (_flags), \
103 .flags = (_flags), \
104 } 103 }
104
105/*
106 * NOTE: When changing this, sync with xmit.c's
107 * b43_plcp_get_bitrate_idx_* functions!
108 */
105static struct ieee80211_rate __b43_ratetable[] = { 109static struct ieee80211_rate __b43_ratetable[] = {
106 RATETAB_ENT(B43_CCK_RATE_1MB, IEEE80211_RATE_CCK), 110 RATETAB_ENT(B43_CCK_RATE_1MB, 0),
107 RATETAB_ENT(B43_CCK_RATE_2MB, IEEE80211_RATE_CCK_2), 111 RATETAB_ENT(B43_CCK_RATE_2MB, IEEE80211_RATE_SHORT_PREAMBLE),
108 RATETAB_ENT(B43_CCK_RATE_5MB, IEEE80211_RATE_CCK_2), 112 RATETAB_ENT(B43_CCK_RATE_5MB, IEEE80211_RATE_SHORT_PREAMBLE),
109 RATETAB_ENT(B43_CCK_RATE_11MB, IEEE80211_RATE_CCK_2), 113 RATETAB_ENT(B43_CCK_RATE_11MB, IEEE80211_RATE_SHORT_PREAMBLE),
110 RATETAB_ENT(B43_OFDM_RATE_6MB, IEEE80211_RATE_OFDM), 114 RATETAB_ENT(B43_OFDM_RATE_6MB, 0),
111 RATETAB_ENT(B43_OFDM_RATE_9MB, IEEE80211_RATE_OFDM), 115 RATETAB_ENT(B43_OFDM_RATE_9MB, 0),
112 RATETAB_ENT(B43_OFDM_RATE_12MB, IEEE80211_RATE_OFDM), 116 RATETAB_ENT(B43_OFDM_RATE_12MB, 0),
113 RATETAB_ENT(B43_OFDM_RATE_18MB, IEEE80211_RATE_OFDM), 117 RATETAB_ENT(B43_OFDM_RATE_18MB, 0),
114 RATETAB_ENT(B43_OFDM_RATE_24MB, IEEE80211_RATE_OFDM), 118 RATETAB_ENT(B43_OFDM_RATE_24MB, 0),
115 RATETAB_ENT(B43_OFDM_RATE_36MB, IEEE80211_RATE_OFDM), 119 RATETAB_ENT(B43_OFDM_RATE_36MB, 0),
116 RATETAB_ENT(B43_OFDM_RATE_48MB, IEEE80211_RATE_OFDM), 120 RATETAB_ENT(B43_OFDM_RATE_48MB, 0),
117 RATETAB_ENT(B43_OFDM_RATE_54MB, IEEE80211_RATE_OFDM), 121 RATETAB_ENT(B43_OFDM_RATE_54MB, 0),
118}; 122};
119 123
120#define b43_a_ratetable (__b43_ratetable + 4) 124#define b43_a_ratetable (__b43_ratetable + 4)
@@ -126,14 +130,8 @@ static struct ieee80211_rate __b43_ratetable[] = {
126 130
127#define CHANTAB_ENT(_chanid, _freq) \ 131#define CHANTAB_ENT(_chanid, _freq) \
128 { \ 132 { \
129 .chan = (_chanid), \ 133 .center_freq = (_freq), \
130 .freq = (_freq), \ 134 .hw_value = (_chanid), \
131 .val = (_chanid), \
132 .flag = IEEE80211_CHAN_W_SCAN | \
133 IEEE80211_CHAN_W_ACTIVE_SCAN | \
134 IEEE80211_CHAN_W_IBSS, \
135 .power_level = 0xFF, \
136 .antenna_max = 0xFF, \
137 } 135 }
138static struct ieee80211_channel b43_2ghz_chantable[] = { 136static struct ieee80211_channel b43_2ghz_chantable[] = {
139 CHANTAB_ENT(1, 2412), 137 CHANTAB_ENT(1, 2412),
@@ -151,9 +149,8 @@ static struct ieee80211_channel b43_2ghz_chantable[] = {
151 CHANTAB_ENT(13, 2472), 149 CHANTAB_ENT(13, 2472),
152 CHANTAB_ENT(14, 2484), 150 CHANTAB_ENT(14, 2484),
153}; 151};
154#define b43_2ghz_chantable_size ARRAY_SIZE(b43_2ghz_chantable)
155 152
156#if 0 153#ifdef NOTYET
157static struct ieee80211_channel b43_5ghz_chantable[] = { 154static struct ieee80211_channel b43_5ghz_chantable[] = {
158 CHANTAB_ENT(36, 5180), 155 CHANTAB_ENT(36, 5180),
159 CHANTAB_ENT(40, 5200), 156 CHANTAB_ENT(40, 5200),
@@ -169,9 +166,22 @@ static struct ieee80211_channel b43_5ghz_chantable[] = {
169 CHANTAB_ENT(161, 5805), 166 CHANTAB_ENT(161, 5805),
170 CHANTAB_ENT(165, 5825), 167 CHANTAB_ENT(165, 5825),
171}; 168};
172#define b43_5ghz_chantable_size ARRAY_SIZE(b43_5ghz_chantable) 169
170static struct ieee80211_supported_band b43_band_5GHz = {
171 .channels = b43_5ghz_chantable,
172 .n_channels = ARRAY_SIZE(b43_5ghz_chantable),
173 .bitrates = b43_a_ratetable,
174 .n_bitrates = b43_a_ratetable_size,
175};
173#endif 176#endif
174 177
178static struct ieee80211_supported_band b43_band_2GHz = {
179 .channels = b43_2ghz_chantable,
180 .n_channels = ARRAY_SIZE(b43_2ghz_chantable),
181 .bitrates = b43_g_ratetable,
182 .n_bitrates = b43_g_ratetable_size,
183};
184
175static void b43_wireless_core_exit(struct b43_wldev *dev); 185static void b43_wireless_core_exit(struct b43_wldev *dev);
176static int b43_wireless_core_init(struct b43_wldev *dev); 186static int b43_wireless_core_init(struct b43_wldev *dev);
177static void b43_wireless_core_stop(struct b43_wldev *dev); 187static void b43_wireless_core_stop(struct b43_wldev *dev);
@@ -1222,17 +1232,18 @@ static void b43_write_beacon_template(struct b43_wldev *dev,
1222} 1232}
1223 1233
1224static void b43_write_probe_resp_plcp(struct b43_wldev *dev, 1234static void b43_write_probe_resp_plcp(struct b43_wldev *dev,
1225 u16 shm_offset, u16 size, u8 rate) 1235 u16 shm_offset, u16 size,
1236 struct ieee80211_rate *rate)
1226{ 1237{
1227 struct b43_plcp_hdr4 plcp; 1238 struct b43_plcp_hdr4 plcp;
1228 u32 tmp; 1239 u32 tmp;
1229 __le16 dur; 1240 __le16 dur;
1230 1241
1231 plcp.data = 0; 1242 plcp.data = 0;
1232 b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate); 1243 b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate->hw_value);
1233 dur = ieee80211_generic_frame_duration(dev->wl->hw, 1244 dur = ieee80211_generic_frame_duration(dev->wl->hw,
1234 dev->wl->vif, size, 1245 dev->wl->vif, size,
1235 B43_RATE_TO_BASE100KBPS(rate)); 1246 rate);
1236 /* Write PLCP in two parts and timing for packet transfer */ 1247 /* Write PLCP in two parts and timing for packet transfer */
1237 tmp = le32_to_cpu(plcp.data); 1248 tmp = le32_to_cpu(plcp.data);
1238 b43_shm_write16(dev, B43_SHM_SHARED, shm_offset, tmp & 0xFFFF); 1249 b43_shm_write16(dev, B43_SHM_SHARED, shm_offset, tmp & 0xFFFF);
@@ -1247,7 +1258,8 @@ static void b43_write_probe_resp_plcp(struct b43_wldev *dev,
1247 * 3) Stripping TIM 1258 * 3) Stripping TIM
1248 */ 1259 */
1249static const u8 * b43_generate_probe_resp(struct b43_wldev *dev, 1260static const u8 * b43_generate_probe_resp(struct b43_wldev *dev,
1250 u16 *dest_size, u8 rate) 1261 u16 *dest_size,
1262 struct ieee80211_rate *rate)
1251{ 1263{
1252 const u8 *src_data; 1264 const u8 *src_data;
1253 u8 *dest_data; 1265 u8 *dest_data;
@@ -1292,7 +1304,7 @@ static const u8 * b43_generate_probe_resp(struct b43_wldev *dev,
1292 IEEE80211_STYPE_PROBE_RESP); 1304 IEEE80211_STYPE_PROBE_RESP);
1293 dur = ieee80211_generic_frame_duration(dev->wl->hw, 1305 dur = ieee80211_generic_frame_duration(dev->wl->hw,
1294 dev->wl->vif, *dest_size, 1306 dev->wl->vif, *dest_size,
1295 B43_RATE_TO_BASE100KBPS(rate)); 1307 rate);
1296 hdr->duration_id = dur; 1308 hdr->duration_id = dur;
1297 1309
1298 return dest_data; 1310 return dest_data;
@@ -1300,7 +1312,8 @@ static const u8 * b43_generate_probe_resp(struct b43_wldev *dev,
1300 1312
1301static void b43_write_probe_resp_template(struct b43_wldev *dev, 1313static void b43_write_probe_resp_template(struct b43_wldev *dev,
1302 u16 ram_offset, 1314 u16 ram_offset,
1303 u16 shm_size_offset, u8 rate) 1315 u16 shm_size_offset,
1316 struct ieee80211_rate *rate)
1304{ 1317{
1305 const u8 *probe_resp_data; 1318 const u8 *probe_resp_data;
1306 u16 size; 1319 u16 size;
@@ -1313,14 +1326,15 @@ static void b43_write_probe_resp_template(struct b43_wldev *dev,
1313 /* Looks like PLCP headers plus packet timings are stored for 1326 /* Looks like PLCP headers plus packet timings are stored for
1314 * all possible basic rates 1327 * all possible basic rates
1315 */ 1328 */
1316 b43_write_probe_resp_plcp(dev, 0x31A, size, B43_CCK_RATE_1MB); 1329 b43_write_probe_resp_plcp(dev, 0x31A, size, &b43_b_ratetable[0]);
1317 b43_write_probe_resp_plcp(dev, 0x32C, size, B43_CCK_RATE_2MB); 1330 b43_write_probe_resp_plcp(dev, 0x32C, size, &b43_b_ratetable[1]);
1318 b43_write_probe_resp_plcp(dev, 0x33E, size, B43_CCK_RATE_5MB); 1331 b43_write_probe_resp_plcp(dev, 0x33E, size, &b43_b_ratetable[2]);
1319 b43_write_probe_resp_plcp(dev, 0x350, size, B43_CCK_RATE_11MB); 1332 b43_write_probe_resp_plcp(dev, 0x350, size, &b43_b_ratetable[3]);
1320 1333
1321 size = min((size_t) size, 0x200 - sizeof(struct b43_plcp_hdr6)); 1334 size = min((size_t) size, 0x200 - sizeof(struct b43_plcp_hdr6));
1322 b43_write_template_common(dev, probe_resp_data, 1335 b43_write_template_common(dev, probe_resp_data,
1323 size, ram_offset, shm_size_offset, rate); 1336 size, ram_offset, shm_size_offset,
1337 rate->hw_value);
1324 kfree(probe_resp_data); 1338 kfree(probe_resp_data);
1325} 1339}
1326 1340
@@ -1388,7 +1402,7 @@ static void handle_irq_beacon(struct b43_wldev *dev)
1388 b43_write_beacon_template(dev, 0x68, 0x18, 1402 b43_write_beacon_template(dev, 0x68, 0x18,
1389 B43_CCK_RATE_1MB); 1403 B43_CCK_RATE_1MB);
1390 b43_write_probe_resp_template(dev, 0x268, 0x4A, 1404 b43_write_probe_resp_template(dev, 0x268, 0x4A,
1391 B43_CCK_RATE_11MB); 1405 &__b43_ratetable[3]);
1392 wl->beacon0_uploaded = 1; 1406 wl->beacon0_uploaded = 1;
1393 } 1407 }
1394 cmd |= B43_MACCMD_BEACON0_VALID; 1408 cmd |= B43_MACCMD_BEACON0_VALID;
@@ -2830,14 +2844,11 @@ static int b43_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
2830 mutex_lock(&wl->mutex); 2844 mutex_lock(&wl->mutex);
2831 2845
2832 /* Switch the PHY mode (if necessary). */ 2846 /* Switch the PHY mode (if necessary). */
2833 switch (conf->phymode) { 2847 switch (conf->channel->band) {
2834 case MODE_IEEE80211A: 2848 case IEEE80211_BAND_5GHZ:
2835 new_phymode = B43_PHYMODE_A; 2849 new_phymode = B43_PHYMODE_A;
2836 break; 2850 break;
2837 case MODE_IEEE80211B: 2851 case IEEE80211_BAND_2GHZ:
2838 new_phymode = B43_PHYMODE_B;
2839 break;
2840 case MODE_IEEE80211G:
2841 new_phymode = B43_PHYMODE_G; 2852 new_phymode = B43_PHYMODE_G;
2842 break; 2853 break;
2843 default: 2854 default:
@@ -2863,8 +2874,8 @@ static int b43_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
2863 2874
2864 /* Switch to the requested channel. 2875 /* Switch to the requested channel.
2865 * The firmware takes care of races with the TX handler. */ 2876 * The firmware takes care of races with the TX handler. */
2866 if (conf->channel_val != phy->channel) 2877 if (conf->channel->hw_value != phy->channel)
2867 b43_radio_selectchannel(dev, conf->channel_val, 0); 2878 b43_radio_selectchannel(dev, conf->channel->hw_value, 0);
2868 2879
2869 /* Enable/Disable ShortSlot timing. */ 2880 /* Enable/Disable ShortSlot timing. */
2870 if ((!!(conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)) != 2881 if ((!!(conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)) !=
@@ -3810,9 +3821,7 @@ static int b43_setup_modes(struct b43_wldev *dev,
3810 bool have_2ghz_phy, bool have_5ghz_phy) 3821 bool have_2ghz_phy, bool have_5ghz_phy)
3811{ 3822{
3812 struct ieee80211_hw *hw = dev->wl->hw; 3823 struct ieee80211_hw *hw = dev->wl->hw;
3813 struct ieee80211_hw_mode *mode;
3814 struct b43_phy *phy = &dev->phy; 3824 struct b43_phy *phy = &dev->phy;
3815 int err;
3816 3825
3817 /* XXX: This function will go away soon, when mac80211 3826 /* XXX: This function will go away soon, when mac80211
3818 * band stuff is rewritten. So this is just a hack. 3827 * band stuff is rewritten. So this is just a hack.
@@ -3821,15 +3830,7 @@ static int b43_setup_modes(struct b43_wldev *dev,
3821 * This assumption is OK, as any B, N or A PHY will already 3830 * This assumption is OK, as any B, N or A PHY will already
3822 * have died a horrible sanity check death earlier. */ 3831 * have died a horrible sanity check death earlier. */
3823 3832
3824 mode = &phy->hwmodes[0]; 3833 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &b43_band_2GHz;
3825 mode->mode = MODE_IEEE80211G;
3826 mode->num_channels = b43_2ghz_chantable_size;
3827 mode->channels = b43_2ghz_chantable;
3828 mode->num_rates = b43_g_ratetable_size;
3829 mode->rates = b43_g_ratetable;
3830 err = ieee80211_register_hwmode(hw, mode);
3831 if (err)
3832 return err;
3833 phy->possible_phymodes |= B43_PHYMODE_G; 3834 phy->possible_phymodes |= B43_PHYMODE_G;
3834 3835
3835 return 0; 3836 return 0;
diff --git a/drivers/net/wireless/b43/sysfs.c b/drivers/net/wireless/b43/sysfs.c
index f4faff6a7d6c..275095b8cbe7 100644
--- a/drivers/net/wireless/b43/sysfs.c
+++ b/drivers/net/wireless/b43/sysfs.c
@@ -47,29 +47,6 @@ static int get_integer(const char *buf, size_t count)
47 return ret; 47 return ret;
48} 48}
49 49
50static int get_boolean(const char *buf, size_t count)
51{
52 if (count != 0) {
53 if (buf[0] == '1')
54 return 1;
55 if (buf[0] == '0')
56 return 0;
57 if (count >= 4 && memcmp(buf, "true", 4) == 0)
58 return 1;
59 if (count >= 5 && memcmp(buf, "false", 5) == 0)
60 return 0;
61 if (count >= 3 && memcmp(buf, "yes", 3) == 0)
62 return 1;
63 if (count >= 2 && memcmp(buf, "no", 2) == 0)
64 return 0;
65 if (count >= 2 && memcmp(buf, "on", 2) == 0)
66 return 1;
67 if (count >= 3 && memcmp(buf, "off", 3) == 0)
68 return 0;
69 }
70 return -EINVAL;
71}
72
73static ssize_t b43_attr_interfmode_show(struct device *dev, 50static ssize_t b43_attr_interfmode_show(struct device *dev,
74 struct device_attribute *attr, 51 struct device_attribute *attr,
75 char *buf) 52 char *buf)
@@ -155,82 +132,18 @@ static ssize_t b43_attr_interfmode_store(struct device *dev,
155static DEVICE_ATTR(interference, 0644, 132static DEVICE_ATTR(interference, 0644,
156 b43_attr_interfmode_show, b43_attr_interfmode_store); 133 b43_attr_interfmode_show, b43_attr_interfmode_store);
157 134
158static ssize_t b43_attr_preamble_show(struct device *dev,
159 struct device_attribute *attr, char *buf)
160{
161 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
162 ssize_t count;
163
164 if (!capable(CAP_NET_ADMIN))
165 return -EPERM;
166
167 mutex_lock(&wldev->wl->mutex);
168
169 if (wldev->short_preamble)
170 count =
171 snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
172 else
173 count =
174 snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
175
176 mutex_unlock(&wldev->wl->mutex);
177
178 return count;
179}
180
181static ssize_t b43_attr_preamble_store(struct device *dev,
182 struct device_attribute *attr,
183 const char *buf, size_t count)
184{
185 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
186 unsigned long flags;
187 int value;
188
189 if (!capable(CAP_NET_ADMIN))
190 return -EPERM;
191
192 value = get_boolean(buf, count);
193 if (value < 0)
194 return value;
195 mutex_lock(&wldev->wl->mutex);
196 spin_lock_irqsave(&wldev->wl->irq_lock, flags);
197
198 wldev->short_preamble = !!value;
199
200 spin_unlock_irqrestore(&wldev->wl->irq_lock, flags);
201 mutex_unlock(&wldev->wl->mutex);
202
203 return count;
204}
205
206static DEVICE_ATTR(shortpreamble, 0644,
207 b43_attr_preamble_show, b43_attr_preamble_store);
208
209int b43_sysfs_register(struct b43_wldev *wldev) 135int b43_sysfs_register(struct b43_wldev *wldev)
210{ 136{
211 struct device *dev = wldev->dev->dev; 137 struct device *dev = wldev->dev->dev;
212 int err;
213 138
214 B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED); 139 B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED);
215 140
216 err = device_create_file(dev, &dev_attr_interference); 141 return device_create_file(dev, &dev_attr_interference);
217 if (err)
218 goto out;
219 err = device_create_file(dev, &dev_attr_shortpreamble);
220 if (err)
221 goto err_remove_interfmode;
222
223 out:
224 return err;
225 err_remove_interfmode:
226 device_remove_file(dev, &dev_attr_interference);
227 goto out;
228} 142}
229 143
230void b43_sysfs_unregister(struct b43_wldev *wldev) 144void b43_sysfs_unregister(struct b43_wldev *wldev)
231{ 145{
232 struct device *dev = wldev->dev->dev; 146 struct device *dev = wldev->dev->dev;
233 147
234 device_remove_file(dev, &dev_attr_shortpreamble);
235 device_remove_file(dev, &dev_attr_interference); 148 device_remove_file(dev, &dev_attr_interference);
236} 149}
diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c
index 7caa26eb4105..4014b6c8272b 100644
--- a/drivers/net/wireless/b43/xmit.c
+++ b/drivers/net/wireless/b43/xmit.c
@@ -32,46 +32,48 @@
32#include "dma.h" 32#include "dma.h"
33 33
34 34
35/* Extract the bitrate out of a CCK PLCP header. */ 35/* Extract the bitrate index out of a CCK PLCP header. */
36static u8 b43_plcp_get_bitrate_cck(struct b43_plcp_hdr6 *plcp) 36static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
37{ 37{
38 switch (plcp->raw[0]) { 38 switch (plcp->raw[0]) {
39 case 0x0A: 39 case 0x0A:
40 return B43_CCK_RATE_1MB; 40 return 0;
41 case 0x14: 41 case 0x14:
42 return B43_CCK_RATE_2MB; 42 return 1;
43 case 0x37: 43 case 0x37:
44 return B43_CCK_RATE_5MB; 44 return 2;
45 case 0x6E: 45 case 0x6E:
46 return B43_CCK_RATE_11MB; 46 return 3;
47 } 47 }
48 B43_WARN_ON(1); 48 B43_WARN_ON(1);
49 return 0; 49 return -1;
50} 50}
51 51
52/* Extract the bitrate out of an OFDM PLCP header. */ 52/* Extract the bitrate index out of an OFDM PLCP header. */
53static u8 b43_plcp_get_bitrate_ofdm(struct b43_plcp_hdr6 *plcp) 53static u8 b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy)
54{ 54{
55 int base = aphy ? 0 : 4;
56
55 switch (plcp->raw[0] & 0xF) { 57 switch (plcp->raw[0] & 0xF) {
56 case 0xB: 58 case 0xB:
57 return B43_OFDM_RATE_6MB; 59 return base + 0;
58 case 0xF: 60 case 0xF:
59 return B43_OFDM_RATE_9MB; 61 return base + 1;
60 case 0xA: 62 case 0xA:
61 return B43_OFDM_RATE_12MB; 63 return base + 2;
62 case 0xE: 64 case 0xE:
63 return B43_OFDM_RATE_18MB; 65 return base + 3;
64 case 0x9: 66 case 0x9:
65 return B43_OFDM_RATE_24MB; 67 return base + 4;
66 case 0xD: 68 case 0xD:
67 return B43_OFDM_RATE_36MB; 69 return base + 5;
68 case 0x8: 70 case 0x8:
69 return B43_OFDM_RATE_48MB; 71 return base + 6;
70 case 0xC: 72 case 0xC:
71 return B43_OFDM_RATE_54MB; 73 return base + 7;
72 } 74 }
73 B43_WARN_ON(1); 75 B43_WARN_ON(1);
74 return 0; 76 return -1;
75} 77}
76 78
77u8 b43_plcp_get_ratecode_cck(const u8 bitrate) 79u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
@@ -191,6 +193,7 @@ int b43_generate_txhdr(struct b43_wldev *dev,
191 (const struct ieee80211_hdr *)fragment_data; 193 (const struct ieee80211_hdr *)fragment_data;
192 int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)); 194 int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
193 u16 fctl = le16_to_cpu(wlhdr->frame_control); 195 u16 fctl = le16_to_cpu(wlhdr->frame_control);
196 struct ieee80211_rate *fbrate;
194 u8 rate, rate_fb; 197 u8 rate, rate_fb;
195 int rate_ofdm, rate_fb_ofdm; 198 int rate_ofdm, rate_fb_ofdm;
196 unsigned int plcp_fragment_len; 199 unsigned int plcp_fragment_len;
@@ -200,9 +203,11 @@ int b43_generate_txhdr(struct b43_wldev *dev,
200 203
201 memset(txhdr, 0, sizeof(*txhdr)); 204 memset(txhdr, 0, sizeof(*txhdr));
202 205
203 rate = txctl->tx_rate; 206 WARN_ON(!txctl->tx_rate);
207 rate = txctl->tx_rate ? txctl->tx_rate->hw_value : B43_CCK_RATE_1MB;
204 rate_ofdm = b43_is_ofdm_rate(rate); 208 rate_ofdm = b43_is_ofdm_rate(rate);
205 rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate; 209 fbrate = txctl->alt_retry_rate ? : txctl->tx_rate;
210 rate_fb = fbrate->hw_value;
206 rate_fb_ofdm = b43_is_ofdm_rate(rate_fb); 211 rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
207 212
208 if (rate_ofdm) 213 if (rate_ofdm)
@@ -221,11 +226,10 @@ int b43_generate_txhdr(struct b43_wldev *dev,
221 * use the original dur_id field. */ 226 * use the original dur_id field. */
222 txhdr->dur_fb = wlhdr->duration_id; 227 txhdr->dur_fb = wlhdr->duration_id;
223 } else { 228 } else {
224 int fbrate_base100kbps = B43_RATE_TO_BASE100KBPS(rate_fb);
225 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw, 229 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
226 txctl->vif, 230 txctl->vif,
227 fragment_len, 231 fragment_len,
228 fbrate_base100kbps); 232 fbrate);
229 } 233 }
230 234
231 plcp_fragment_len = fragment_len + FCS_LEN; 235 plcp_fragment_len = fragment_len + FCS_LEN;
@@ -287,7 +291,7 @@ int b43_generate_txhdr(struct b43_wldev *dev,
287 phy_ctl |= B43_TXH_PHY_ENC_OFDM; 291 phy_ctl |= B43_TXH_PHY_ENC_OFDM;
288 else 292 else
289 phy_ctl |= B43_TXH_PHY_ENC_CCK; 293 phy_ctl |= B43_TXH_PHY_ENC_CCK;
290 if (dev->short_preamble) 294 if (txctl->flags & IEEE80211_TXCTL_SHORT_PREAMBLE)
291 phy_ctl |= B43_TXH_PHY_SHORTPRMBL; 295 phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
292 296
293 switch (b43_ieee80211_antenna_sanitize(dev, txctl->antenna_sel_tx)) { 297 switch (b43_ieee80211_antenna_sanitize(dev, txctl->antenna_sel_tx)) {
@@ -332,7 +336,8 @@ int b43_generate_txhdr(struct b43_wldev *dev,
332 int rts_rate_ofdm, rts_rate_fb_ofdm; 336 int rts_rate_ofdm, rts_rate_fb_ofdm;
333 struct b43_plcp_hdr6 *plcp; 337 struct b43_plcp_hdr6 *plcp;
334 338
335 rts_rate = txctl->rts_cts_rate; 339 WARN_ON(!txctl->rts_cts_rate);
340 rts_rate = txctl->rts_cts_rate ? txctl->rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
336 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate); 341 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
337 rts_rate_fb = b43_calc_fallback_rate(rts_rate); 342 rts_rate_fb = b43_calc_fallback_rate(rts_rate);
338 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb); 343 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
@@ -506,6 +511,7 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
506 u16 phystat0, phystat3, chanstat, mactime; 511 u16 phystat0, phystat3, chanstat, mactime;
507 u32 macstat; 512 u32 macstat;
508 u16 chanid; 513 u16 chanid;
514 u16 phytype;
509 u8 jssi; 515 u8 jssi;
510 int padding; 516 int padding;
511 517
@@ -518,6 +524,7 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
518 macstat = le32_to_cpu(rxhdr->mac_status); 524 macstat = le32_to_cpu(rxhdr->mac_status);
519 mactime = le16_to_cpu(rxhdr->mac_time); 525 mactime = le16_to_cpu(rxhdr->mac_time);
520 chanstat = le16_to_cpu(rxhdr->channel); 526 chanstat = le16_to_cpu(rxhdr->channel);
527 phytype = chanstat & B43_RX_CHAN_PHYTYPE;
521 528
522 if (macstat & B43_RX_MAC_FCSERR) 529 if (macstat & B43_RX_MAC_FCSERR)
523 dev->wl->ieee_stats.dot11FCSErrorCount++; 530 dev->wl->ieee_stats.dot11FCSErrorCount++;
@@ -575,9 +582,10 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
575 /* the next line looks wrong, but is what mac80211 wants */ 582 /* the next line looks wrong, but is what mac80211 wants */
576 status.signal = (jssi * 100) / B43_RX_MAX_SSI; 583 status.signal = (jssi * 100) / B43_RX_MAX_SSI;
577 if (phystat0 & B43_RX_PHYST0_OFDM) 584 if (phystat0 & B43_RX_PHYST0_OFDM)
578 status.rate = b43_plcp_get_bitrate_ofdm(plcp); 585 status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
586 phytype == B43_PHYTYPE_A);
579 else 587 else
580 status.rate = b43_plcp_get_bitrate_cck(plcp); 588 status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
581 status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT); 589 status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
582 590
583 /* 591 /*
@@ -601,29 +609,28 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
601 chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT; 609 chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
602 switch (chanstat & B43_RX_CHAN_PHYTYPE) { 610 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
603 case B43_PHYTYPE_A: 611 case B43_PHYTYPE_A:
604 status.phymode = MODE_IEEE80211A; 612 status.band = IEEE80211_BAND_5GHZ;
605 B43_WARN_ON(1); 613 B43_WARN_ON(1);
606 /* FIXME: We don't really know which value the "chanid" contains. 614 /* FIXME: We don't really know which value the "chanid" contains.
607 * So the following assignment might be wrong. */ 615 * So the following assignment might be wrong. */
608 status.channel = chanid; 616 status.freq = b43_channel_to_freq_5ghz(chanid);
609 status.freq = b43_channel_to_freq_5ghz(status.channel);
610 break; 617 break;
611 case B43_PHYTYPE_G: 618 case B43_PHYTYPE_G:
612 status.phymode = MODE_IEEE80211G; 619 status.band = IEEE80211_BAND_2GHZ;
613 /* chanid is the radio channel cookie value as used 620 /* chanid is the radio channel cookie value as used
614 * to tune the radio. */ 621 * to tune the radio. */
615 status.freq = chanid + 2400; 622 status.freq = chanid + 2400;
616 status.channel = b43_freq_to_channel_2ghz(status.freq);
617 break; 623 break;
618 case B43_PHYTYPE_N: 624 case B43_PHYTYPE_N:
619 status.phymode = 0xDEAD /*FIXME MODE_IEEE80211N*/;
620 /* chanid is the SHM channel cookie. Which is the plain 625 /* chanid is the SHM channel cookie. Which is the plain
621 * channel number in b43. */ 626 * channel number in b43. */
622 status.channel = chanid; 627 if (chanstat & B43_RX_CHAN_5GHZ) {
623 if (chanstat & B43_RX_CHAN_5GHZ) 628 status.band = IEEE80211_BAND_5GHZ;
624 status.freq = b43_freq_to_channel_5ghz(status.freq); 629 status.freq = b43_freq_to_channel_5ghz(chanid);
625 else 630 } else {
626 status.freq = b43_freq_to_channel_2ghz(status.freq); 631 status.band = IEEE80211_BAND_2GHZ;
632 status.freq = b43_freq_to_channel_2ghz(chanid);
633 }
627 break; 634 break;
628 default: 635 default:
629 B43_WARN_ON(1); 636 B43_WARN_ON(1);
diff --git a/drivers/net/wireless/b43legacy/b43legacy.h b/drivers/net/wireless/b43legacy/b43legacy.h
index 93d45b71799a..5f217d6d2e6a 100644
--- a/drivers/net/wireless/b43legacy/b43legacy.h
+++ b/drivers/net/wireless/b43legacy/b43legacy.h
@@ -392,10 +392,6 @@ struct b43legacy_phy {
392 u8 possible_phymodes; 392 u8 possible_phymodes;
393 /* GMODE bit enabled in MACCTL? */ 393 /* GMODE bit enabled in MACCTL? */
394 bool gmode; 394 bool gmode;
395 /* Possible ieee80211 subsystem hwmodes for this PHY.
396 * Which mode is selected, depends on thr GMODE enabled bit */
397#define B43legacy_MAX_PHYHWMODES 2
398 struct ieee80211_hw_mode hwmodes[B43legacy_MAX_PHYHWMODES];
399 395
400 /* Analog Type */ 396 /* Analog Type */
401 u8 analog; 397 u8 analog;
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index c39de422e220..d2a72a2cd178 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -95,28 +95,29 @@ MODULE_DEVICE_TABLE(ssb, b43legacy_ssb_tbl);
95 * data in there. This data is the same for all devices, so we don't 95 * data in there. This data is the same for all devices, so we don't
96 * get concurrency issues */ 96 * get concurrency issues */
97#define RATETAB_ENT(_rateid, _flags) \ 97#define RATETAB_ENT(_rateid, _flags) \
98 { \ 98 { \
99 .rate = B43legacy_RATE_TO_100KBPS(_rateid), \ 99 .bitrate = B43legacy_RATE_TO_100KBPS(_rateid), \
100 .val = (_rateid), \ 100 .hw_value = (_rateid), \
101 .val2 = (_rateid), \ 101 .flags = (_flags), \
102 .flags = (_flags), \
103 } 102 }
103/*
104 * NOTE: When changing this, sync with xmit.c's
105 * b43legacy_plcp_get_bitrate_idx_* functions!
106 */
104static struct ieee80211_rate __b43legacy_ratetable[] = { 107static struct ieee80211_rate __b43legacy_ratetable[] = {
105 RATETAB_ENT(B43legacy_CCK_RATE_1MB, IEEE80211_RATE_CCK), 108 RATETAB_ENT(B43legacy_CCK_RATE_1MB, 0),
106 RATETAB_ENT(B43legacy_CCK_RATE_2MB, IEEE80211_RATE_CCK_2), 109 RATETAB_ENT(B43legacy_CCK_RATE_2MB, IEEE80211_RATE_SHORT_PREAMBLE),
107 RATETAB_ENT(B43legacy_CCK_RATE_5MB, IEEE80211_RATE_CCK_2), 110 RATETAB_ENT(B43legacy_CCK_RATE_5MB, IEEE80211_RATE_SHORT_PREAMBLE),
108 RATETAB_ENT(B43legacy_CCK_RATE_11MB, IEEE80211_RATE_CCK_2), 111 RATETAB_ENT(B43legacy_CCK_RATE_11MB, IEEE80211_RATE_SHORT_PREAMBLE),
109 RATETAB_ENT(B43legacy_OFDM_RATE_6MB, IEEE80211_RATE_OFDM), 112 RATETAB_ENT(B43legacy_OFDM_RATE_6MB, 0),
110 RATETAB_ENT(B43legacy_OFDM_RATE_9MB, IEEE80211_RATE_OFDM), 113 RATETAB_ENT(B43legacy_OFDM_RATE_9MB, 0),
111 RATETAB_ENT(B43legacy_OFDM_RATE_12MB, IEEE80211_RATE_OFDM), 114 RATETAB_ENT(B43legacy_OFDM_RATE_12MB, 0),
112 RATETAB_ENT(B43legacy_OFDM_RATE_18MB, IEEE80211_RATE_OFDM), 115 RATETAB_ENT(B43legacy_OFDM_RATE_18MB, 0),
113 RATETAB_ENT(B43legacy_OFDM_RATE_24MB, IEEE80211_RATE_OFDM), 116 RATETAB_ENT(B43legacy_OFDM_RATE_24MB, 0),
114 RATETAB_ENT(B43legacy_OFDM_RATE_36MB, IEEE80211_RATE_OFDM), 117 RATETAB_ENT(B43legacy_OFDM_RATE_36MB, 0),
115 RATETAB_ENT(B43legacy_OFDM_RATE_48MB, IEEE80211_RATE_OFDM), 118 RATETAB_ENT(B43legacy_OFDM_RATE_48MB, 0),
116 RATETAB_ENT(B43legacy_OFDM_RATE_54MB, IEEE80211_RATE_OFDM), 119 RATETAB_ENT(B43legacy_OFDM_RATE_54MB, 0),
117}; 120};
118#define b43legacy_a_ratetable (__b43legacy_ratetable + 4)
119#define b43legacy_a_ratetable_size 8
120#define b43legacy_b_ratetable (__b43legacy_ratetable + 0) 121#define b43legacy_b_ratetable (__b43legacy_ratetable + 0)
121#define b43legacy_b_ratetable_size 4 122#define b43legacy_b_ratetable_size 4
122#define b43legacy_g_ratetable (__b43legacy_ratetable + 0) 123#define b43legacy_g_ratetable (__b43legacy_ratetable + 0)
@@ -124,14 +125,8 @@ static struct ieee80211_rate __b43legacy_ratetable[] = {
124 125
125#define CHANTAB_ENT(_chanid, _freq) \ 126#define CHANTAB_ENT(_chanid, _freq) \
126 { \ 127 { \
127 .chan = (_chanid), \ 128 .center_freq = (_freq), \
128 .freq = (_freq), \ 129 .hw_value = (_chanid), \
129 .val = (_chanid), \
130 .flag = IEEE80211_CHAN_W_SCAN | \
131 IEEE80211_CHAN_W_ACTIVE_SCAN | \
132 IEEE80211_CHAN_W_IBSS, \
133 .power_level = 0x0A, \
134 .antenna_max = 0xFF, \
135 } 130 }
136static struct ieee80211_channel b43legacy_bg_chantable[] = { 131static struct ieee80211_channel b43legacy_bg_chantable[] = {
137 CHANTAB_ENT(1, 2412), 132 CHANTAB_ENT(1, 2412),
@@ -149,7 +144,20 @@ static struct ieee80211_channel b43legacy_bg_chantable[] = {
149 CHANTAB_ENT(13, 2472), 144 CHANTAB_ENT(13, 2472),
150 CHANTAB_ENT(14, 2484), 145 CHANTAB_ENT(14, 2484),
151}; 146};
152#define b43legacy_bg_chantable_size ARRAY_SIZE(b43legacy_bg_chantable) 147
148static struct ieee80211_supported_band b43legacy_band_2GHz_BPHY = {
149 .channels = b43legacy_bg_chantable,
150 .n_channels = ARRAY_SIZE(b43legacy_bg_chantable),
151 .bitrates = b43legacy_b_ratetable,
152 .n_bitrates = b43legacy_b_ratetable_size,
153};
154
155static struct ieee80211_supported_band b43legacy_band_2GHz_GPHY = {
156 .channels = b43legacy_bg_chantable,
157 .n_channels = ARRAY_SIZE(b43legacy_bg_chantable),
158 .bitrates = b43legacy_g_ratetable,
159 .n_bitrates = b43legacy_g_ratetable_size,
160};
153 161
154static void b43legacy_wireless_core_exit(struct b43legacy_wldev *dev); 162static void b43legacy_wireless_core_exit(struct b43legacy_wldev *dev);
155static int b43legacy_wireless_core_init(struct b43legacy_wldev *dev); 163static int b43legacy_wireless_core_init(struct b43legacy_wldev *dev);
@@ -969,18 +977,18 @@ static void b43legacy_write_beacon_template(struct b43legacy_wldev *dev,
969 977
970static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev, 978static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev,
971 u16 shm_offset, u16 size, 979 u16 shm_offset, u16 size,
972 u8 rate) 980 struct ieee80211_rate *rate)
973{ 981{
974 struct b43legacy_plcp_hdr4 plcp; 982 struct b43legacy_plcp_hdr4 plcp;
975 u32 tmp; 983 u32 tmp;
976 __le16 dur; 984 __le16 dur;
977 985
978 plcp.data = 0; 986 plcp.data = 0;
979 b43legacy_generate_plcp_hdr(&plcp, size + FCS_LEN, rate); 987 b43legacy_generate_plcp_hdr(&plcp, size + FCS_LEN, rate->bitrate);
980 dur = ieee80211_generic_frame_duration(dev->wl->hw, 988 dur = ieee80211_generic_frame_duration(dev->wl->hw,
981 dev->wl->vif, 989 dev->wl->vif,
982 size, 990 size,
983 B43legacy_RATE_TO_100KBPS(rate)); 991 rate);
984 /* Write PLCP in two parts and timing for packet transfer */ 992 /* Write PLCP in two parts and timing for packet transfer */
985 tmp = le32_to_cpu(plcp.data); 993 tmp = le32_to_cpu(plcp.data);
986 b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, shm_offset, 994 b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, shm_offset,
@@ -998,7 +1006,8 @@ static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev,
998 * 3) Stripping TIM 1006 * 3) Stripping TIM
999 */ 1007 */
1000static u8 *b43legacy_generate_probe_resp(struct b43legacy_wldev *dev, 1008static u8 *b43legacy_generate_probe_resp(struct b43legacy_wldev *dev,
1001 u16 *dest_size, u8 rate) 1009 u16 *dest_size,
1010 struct ieee80211_rate *rate)
1002{ 1011{
1003 const u8 *src_data; 1012 const u8 *src_data;
1004 u8 *dest_data; 1013 u8 *dest_data;
@@ -1046,7 +1055,7 @@ static u8 *b43legacy_generate_probe_resp(struct b43legacy_wldev *dev,
1046 dur = ieee80211_generic_frame_duration(dev->wl->hw, 1055 dur = ieee80211_generic_frame_duration(dev->wl->hw,
1047 dev->wl->vif, 1056 dev->wl->vif,
1048 *dest_size, 1057 *dest_size,
1049 B43legacy_RATE_TO_100KBPS(rate)); 1058 rate);
1050 hdr->duration_id = dur; 1059 hdr->duration_id = dur;
1051 1060
1052 return dest_data; 1061 return dest_data;
@@ -1054,7 +1063,8 @@ static u8 *b43legacy_generate_probe_resp(struct b43legacy_wldev *dev,
1054 1063
1055static void b43legacy_write_probe_resp_template(struct b43legacy_wldev *dev, 1064static void b43legacy_write_probe_resp_template(struct b43legacy_wldev *dev,
1056 u16 ram_offset, 1065 u16 ram_offset,
1057 u16 shm_size_offset, u8 rate) 1066 u16 shm_size_offset,
1067 struct ieee80211_rate *rate)
1058{ 1068{
1059 u8 *probe_resp_data; 1069 u8 *probe_resp_data;
1060 u16 size; 1070 u16 size;
@@ -1069,19 +1079,19 @@ static void b43legacy_write_probe_resp_template(struct b43legacy_wldev *dev,
1069 * all possible basic rates 1079 * all possible basic rates
1070 */ 1080 */
1071 b43legacy_write_probe_resp_plcp(dev, 0x31A, size, 1081 b43legacy_write_probe_resp_plcp(dev, 0x31A, size,
1072 B43legacy_CCK_RATE_1MB); 1082 &b43legacy_b_ratetable[0]);
1073 b43legacy_write_probe_resp_plcp(dev, 0x32C, size, 1083 b43legacy_write_probe_resp_plcp(dev, 0x32C, size,
1074 B43legacy_CCK_RATE_2MB); 1084 &b43legacy_b_ratetable[1]);
1075 b43legacy_write_probe_resp_plcp(dev, 0x33E, size, 1085 b43legacy_write_probe_resp_plcp(dev, 0x33E, size,
1076 B43legacy_CCK_RATE_5MB); 1086 &b43legacy_b_ratetable[2]);
1077 b43legacy_write_probe_resp_plcp(dev, 0x350, size, 1087 b43legacy_write_probe_resp_plcp(dev, 0x350, size,
1078 B43legacy_CCK_RATE_11MB); 1088 &b43legacy_b_ratetable[3]);
1079 1089
1080 size = min((size_t)size, 1090 size = min((size_t)size,
1081 0x200 - sizeof(struct b43legacy_plcp_hdr6)); 1091 0x200 - sizeof(struct b43legacy_plcp_hdr6));
1082 b43legacy_write_template_common(dev, probe_resp_data, 1092 b43legacy_write_template_common(dev, probe_resp_data,
1083 size, ram_offset, 1093 size, ram_offset,
1084 shm_size_offset, rate); 1094 shm_size_offset, rate->bitrate);
1085 kfree(probe_resp_data); 1095 kfree(probe_resp_data);
1086} 1096}
1087 1097
@@ -1106,7 +1116,7 @@ static void b43legacy_update_templates(struct b43legacy_wldev *dev)
1106 b43legacy_write_beacon_template(dev, 0x468, 0x1A, 1116 b43legacy_write_beacon_template(dev, 0x468, 0x1A,
1107 B43legacy_CCK_RATE_1MB); 1117 B43legacy_CCK_RATE_1MB);
1108 b43legacy_write_probe_resp_template(dev, 0x268, 0x4A, 1118 b43legacy_write_probe_resp_template(dev, 0x268, 0x4A,
1109 B43legacy_CCK_RATE_11MB); 1119 &b43legacy_b_ratetable[0]);
1110 1120
1111 status = b43legacy_read32(dev, B43legacy_MMIO_MACCMD); 1121 status = b43legacy_read32(dev, B43legacy_MMIO_MACCMD);
1112 status |= 0x03; 1122 status |= 0x03;
@@ -2550,14 +2560,16 @@ static int b43legacy_op_dev_config(struct ieee80211_hw *hw,
2550 antenna_rx = b43legacy_antenna_from_ieee80211(conf->antenna_sel_rx); 2560 antenna_rx = b43legacy_antenna_from_ieee80211(conf->antenna_sel_rx);
2551 2561
2552 mutex_lock(&wl->mutex); 2562 mutex_lock(&wl->mutex);
2563 dev = wl->current_dev;
2564 phy = &dev->phy;
2553 2565
2554 /* Switch the PHY mode (if necessary). */ 2566 /* Switch the PHY mode (if necessary). */
2555 switch (conf->phymode) { 2567 switch (conf->channel->band) {
2556 case MODE_IEEE80211B: 2568 case IEEE80211_BAND_2GHZ:
2557 new_phymode = B43legacy_PHYMODE_B; 2569 if (phy->type == B43legacy_PHYTYPE_B)
2558 break; 2570 new_phymode = B43legacy_PHYMODE_B;
2559 case MODE_IEEE80211G: 2571 else
2560 new_phymode = B43legacy_PHYMODE_G; 2572 new_phymode = B43legacy_PHYMODE_G;
2561 break; 2573 break;
2562 default: 2574 default:
2563 B43legacy_WARN_ON(1); 2575 B43legacy_WARN_ON(1);
@@ -2565,8 +2577,6 @@ static int b43legacy_op_dev_config(struct ieee80211_hw *hw,
2565 err = b43legacy_switch_phymode(wl, new_phymode); 2577 err = b43legacy_switch_phymode(wl, new_phymode);
2566 if (err) 2578 if (err)
2567 goto out_unlock_mutex; 2579 goto out_unlock_mutex;
2568 dev = wl->current_dev;
2569 phy = &dev->phy;
2570 2580
2571 /* Disable IRQs while reconfiguring the device. 2581 /* Disable IRQs while reconfiguring the device.
2572 * This makes it possible to drop the spinlock throughout 2582 * This makes it possible to drop the spinlock throughout
@@ -2582,8 +2592,8 @@ static int b43legacy_op_dev_config(struct ieee80211_hw *hw,
2582 2592
2583 /* Switch to the requested channel. 2593 /* Switch to the requested channel.
2584 * The firmware takes care of races with the TX handler. */ 2594 * The firmware takes care of races with the TX handler. */
2585 if (conf->channel_val != phy->channel) 2595 if (conf->channel->hw_value != phy->channel)
2586 b43legacy_radio_selectchannel(dev, conf->channel_val, 0); 2596 b43legacy_radio_selectchannel(dev, conf->channel->hw_value, 0);
2587 2597
2588 /* Enable/Disable ShortSlot timing. */ 2598 /* Enable/Disable ShortSlot timing. */
2589 if ((!!(conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)) 2599 if ((!!(conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME))
@@ -3398,48 +3408,19 @@ static int b43legacy_setup_modes(struct b43legacy_wldev *dev,
3398 int have_gphy) 3408 int have_gphy)
3399{ 3409{
3400 struct ieee80211_hw *hw = dev->wl->hw; 3410 struct ieee80211_hw *hw = dev->wl->hw;
3401 struct ieee80211_hw_mode *mode;
3402 struct b43legacy_phy *phy = &dev->phy; 3411 struct b43legacy_phy *phy = &dev->phy;
3403 int cnt = 0;
3404 int err;
3405 3412
3406 phy->possible_phymodes = 0; 3413 phy->possible_phymodes = 0;
3407 for (; 1; cnt++) { 3414 if (have_bphy) {
3408 if (have_bphy) { 3415 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3409 B43legacy_WARN_ON(cnt >= B43legacy_MAX_PHYHWMODES); 3416 &b43legacy_band_2GHz_BPHY;
3410 mode = &phy->hwmodes[cnt]; 3417 phy->possible_phymodes |= B43legacy_PHYMODE_B;
3411 3418 }
3412 mode->mode = MODE_IEEE80211B; 3419
3413 mode->num_channels = b43legacy_bg_chantable_size; 3420 if (have_gphy) {
3414 mode->channels = b43legacy_bg_chantable; 3421 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3415 mode->num_rates = b43legacy_b_ratetable_size; 3422 &b43legacy_band_2GHz_GPHY;
3416 mode->rates = b43legacy_b_ratetable; 3423 phy->possible_phymodes |= B43legacy_PHYMODE_G;
3417 err = ieee80211_register_hwmode(hw, mode);
3418 if (err)
3419 return err;
3420
3421 phy->possible_phymodes |= B43legacy_PHYMODE_B;
3422 have_bphy = 0;
3423 continue;
3424 }
3425 if (have_gphy) {
3426 B43legacy_WARN_ON(cnt >= B43legacy_MAX_PHYHWMODES);
3427 mode = &phy->hwmodes[cnt];
3428
3429 mode->mode = MODE_IEEE80211G;
3430 mode->num_channels = b43legacy_bg_chantable_size;
3431 mode->channels = b43legacy_bg_chantable;
3432 mode->num_rates = b43legacy_g_ratetable_size;
3433 mode->rates = b43legacy_g_ratetable;
3434 err = ieee80211_register_hwmode(hw, mode);
3435 if (err)
3436 return err;
3437
3438 phy->possible_phymodes |= B43legacy_PHYMODE_G;
3439 have_gphy = 0;
3440 continue;
3441 }
3442 break;
3443 } 3424 }
3444 3425
3445 return 0; 3426 return 0;
diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c
index d84408a82db9..47e130e9fdf2 100644
--- a/drivers/net/wireless/b43legacy/xmit.c
+++ b/drivers/net/wireless/b43legacy/xmit.c
@@ -37,45 +37,48 @@
37 37
38 38
39/* Extract the bitrate out of a CCK PLCP header. */ 39/* Extract the bitrate out of a CCK PLCP header. */
40static u8 b43legacy_plcp_get_bitrate_cck(struct b43legacy_plcp_hdr6 *plcp) 40static u8 b43legacy_plcp_get_bitrate_idx_cck(struct b43legacy_plcp_hdr6 *plcp)
41{ 41{
42 switch (plcp->raw[0]) { 42 switch (plcp->raw[0]) {
43 case 0x0A: 43 case 0x0A:
44 return B43legacy_CCK_RATE_1MB; 44 return 0;
45 case 0x14: 45 case 0x14:
46 return B43legacy_CCK_RATE_2MB; 46 return 1;
47 case 0x37: 47 case 0x37:
48 return B43legacy_CCK_RATE_5MB; 48 return 2;
49 case 0x6E: 49 case 0x6E:
50 return B43legacy_CCK_RATE_11MB; 50 return 3;
51 } 51 }
52 B43legacy_BUG_ON(1); 52 B43legacy_BUG_ON(1);
53 return 0; 53 return -1;
54} 54}
55 55
56/* Extract the bitrate out of an OFDM PLCP header. */ 56/* Extract the bitrate out of an OFDM PLCP header. */
57static u8 b43legacy_plcp_get_bitrate_ofdm(struct b43legacy_plcp_hdr6 *plcp) 57static u8 b43legacy_plcp_get_bitrate_idx_ofdm(struct b43legacy_plcp_hdr6 *plcp,
58 bool aphy)
58{ 59{
60 int base = aphy ? 0 : 4;
61
59 switch (plcp->raw[0] & 0xF) { 62 switch (plcp->raw[0] & 0xF) {
60 case 0xB: 63 case 0xB:
61 return B43legacy_OFDM_RATE_6MB; 64 return base + 0;
62 case 0xF: 65 case 0xF:
63 return B43legacy_OFDM_RATE_9MB; 66 return base + 1;
64 case 0xA: 67 case 0xA:
65 return B43legacy_OFDM_RATE_12MB; 68 return base + 2;
66 case 0xE: 69 case 0xE:
67 return B43legacy_OFDM_RATE_18MB; 70 return base + 3;
68 case 0x9: 71 case 0x9:
69 return B43legacy_OFDM_RATE_24MB; 72 return base + 4;
70 case 0xD: 73 case 0xD:
71 return B43legacy_OFDM_RATE_36MB; 74 return base + 5;
72 case 0x8: 75 case 0x8:
73 return B43legacy_OFDM_RATE_48MB; 76 return base + 6;
74 case 0xC: 77 case 0xC:
75 return B43legacy_OFDM_RATE_54MB; 78 return base + 7;
76 } 79 }
77 B43legacy_BUG_ON(1); 80 B43legacy_BUG_ON(1);
78 return 0; 81 return -1;
79} 82}
80 83
81u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate) 84u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate)
@@ -192,7 +195,7 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
192 int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)); 195 int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
193 u16 fctl; 196 u16 fctl;
194 u8 rate; 197 u8 rate;
195 u8 rate_fb; 198 struct ieee80211_rate *rate_fb;
196 int rate_ofdm; 199 int rate_ofdm;
197 int rate_fb_ofdm; 200 int rate_fb_ofdm;
198 unsigned int plcp_fragment_len; 201 unsigned int plcp_fragment_len;
@@ -204,16 +207,16 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
204 207
205 memset(txhdr, 0, sizeof(*txhdr)); 208 memset(txhdr, 0, sizeof(*txhdr));
206 209
207 rate = txctl->tx_rate; 210 rate = txctl->tx_rate->hw_value;
208 rate_ofdm = b43legacy_is_ofdm_rate(rate); 211 rate_ofdm = b43legacy_is_ofdm_rate(rate);
209 rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate; 212 rate_fb = txctl->alt_retry_rate ? : txctl->tx_rate;
210 rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb); 213 rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value);
211 214
212 txhdr->mac_frame_ctl = wlhdr->frame_control; 215 txhdr->mac_frame_ctl = wlhdr->frame_control;
213 memcpy(txhdr->tx_receiver, wlhdr->addr1, 6); 216 memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
214 217
215 /* Calculate duration for fallback rate */ 218 /* Calculate duration for fallback rate */
216 if ((rate_fb == rate) || 219 if ((rate_fb->hw_value == rate) ||
217 (wlhdr->duration_id & cpu_to_le16(0x8000)) || 220 (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
218 (wlhdr->duration_id == cpu_to_le16(0))) { 221 (wlhdr->duration_id == cpu_to_le16(0))) {
219 /* If the fallback rate equals the normal rate or the 222 /* If the fallback rate equals the normal rate or the
@@ -221,11 +224,10 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
221 * use the original dur_id field. */ 224 * use the original dur_id field. */
222 txhdr->dur_fb = wlhdr->duration_id; 225 txhdr->dur_fb = wlhdr->duration_id;
223 } else { 226 } else {
224 int fbrate_base100kbps = B43legacy_RATE_TO_100KBPS(rate_fb);
225 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw, 227 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
226 txctl->vif, 228 txctl->vif,
227 fragment_len, 229 fragment_len,
228 fbrate_base100kbps); 230 rate_fb);
229 } 231 }
230 232
231 plcp_fragment_len = fragment_len + FCS_LEN; 233 plcp_fragment_len = fragment_len + FCS_LEN;
@@ -266,7 +268,7 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
266 rate); 268 rate);
267 b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) 269 b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
268 (&txhdr->plcp_fb), plcp_fragment_len, 270 (&txhdr->plcp_fb), plcp_fragment_len,
269 rate_fb); 271 rate_fb->hw_value);
270 272
271 /* PHY TX Control word */ 273 /* PHY TX Control word */
272 if (rate_ofdm) 274 if (rate_ofdm)
@@ -310,7 +312,7 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
310 int rts_rate_ofdm; 312 int rts_rate_ofdm;
311 int rts_rate_fb_ofdm; 313 int rts_rate_fb_ofdm;
312 314
313 rts_rate = txctl->rts_cts_rate; 315 rts_rate = txctl->rts_cts_rate->hw_value;
314 rts_rate_ofdm = b43legacy_is_ofdm_rate(rts_rate); 316 rts_rate_ofdm = b43legacy_is_ofdm_rate(rts_rate);
315 rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate); 317 rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
316 rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb); 318 rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
@@ -536,10 +538,11 @@ void b43legacy_rx(struct b43legacy_wldev *dev,
536 (phystat3 & B43legacy_RX_PHYST3_TRSTATE)); 538 (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
537 status.noise = dev->stats.link_noise; 539 status.noise = dev->stats.link_noise;
538 status.signal = (jssi * 100) / B43legacy_RX_MAX_SSI; 540 status.signal = (jssi * 100) / B43legacy_RX_MAX_SSI;
541 /* change to support A PHY */
539 if (phystat0 & B43legacy_RX_PHYST0_OFDM) 542 if (phystat0 & B43legacy_RX_PHYST0_OFDM)
540 status.rate = b43legacy_plcp_get_bitrate_ofdm(plcp); 543 status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
541 else 544 else
542 status.rate = b43legacy_plcp_get_bitrate_cck(plcp); 545 status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
543 status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT); 546 status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
544 547
545 /* 548 /*
@@ -564,14 +567,9 @@ void b43legacy_rx(struct b43legacy_wldev *dev,
564 B43legacy_RX_CHAN_ID_SHIFT; 567 B43legacy_RX_CHAN_ID_SHIFT;
565 switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) { 568 switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
566 case B43legacy_PHYTYPE_B: 569 case B43legacy_PHYTYPE_B:
567 status.phymode = MODE_IEEE80211B;
568 status.freq = chanid + 2400;
569 status.channel = b43legacy_freq_to_channel_bg(chanid + 2400);
570 break;
571 case B43legacy_PHYTYPE_G: 570 case B43legacy_PHYTYPE_G:
572 status.phymode = MODE_IEEE80211G; 571 status.band = IEEE80211_BAND_2GHZ;
573 status.freq = chanid + 2400; 572 status.freq = chanid + 2400;
574 status.channel = b43legacy_freq_to_channel_bg(chanid + 2400);
575 break; 573 break;
576 default: 574 default:
577 b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n", 575 b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index 80d31ae51e77..f018ce464d97 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -100,14 +100,6 @@ static struct iwl3945_tpt_entry iwl3945_tpt_table_a[] = {
100 {-89, IWL_RATE_6M_INDEX} 100 {-89, IWL_RATE_6M_INDEX}
101}; 101};
102 102
103static struct iwl3945_tpt_entry iwl3945_tpt_table_b[] = {
104 {-86, IWL_RATE_11M_INDEX},
105 {-88, IWL_RATE_5M_INDEX},
106 {-90, IWL_RATE_2M_INDEX},
107 {-92, IWL_RATE_1M_INDEX}
108
109};
110
111static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = { 103static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = {
112 {-60, IWL_RATE_54M_INDEX}, 104 {-60, IWL_RATE_54M_INDEX},
113 {-64, IWL_RATE_48M_INDEX}, 105 {-64, IWL_RATE_48M_INDEX},
@@ -129,7 +121,7 @@ static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = {
129#define IWL_RATE_MIN_SUCCESS_TH 8 121#define IWL_RATE_MIN_SUCCESS_TH 8
130#define IWL_RATE_DECREASE_TH 1920 122#define IWL_RATE_DECREASE_TH 1920
131 123
132static u8 iwl3945_get_rate_index_by_rssi(s32 rssi, u8 mode) 124static u8 iwl3945_get_rate_index_by_rssi(s32 rssi, enum ieee80211_band band)
133{ 125{
134 u32 index = 0; 126 u32 index = 0;
135 u32 table_size = 0; 127 u32 table_size = 0;
@@ -138,21 +130,19 @@ static u8 iwl3945_get_rate_index_by_rssi(s32 rssi, u8 mode)
138 if ((rssi < IWL_MIN_RSSI_VAL) || (rssi > IWL_MAX_RSSI_VAL)) 130 if ((rssi < IWL_MIN_RSSI_VAL) || (rssi > IWL_MAX_RSSI_VAL))
139 rssi = IWL_MIN_RSSI_VAL; 131 rssi = IWL_MIN_RSSI_VAL;
140 132
141 switch (mode) { 133 switch (band) {
142 case MODE_IEEE80211G: 134 case IEEE80211_BAND_2GHZ:
143 tpt_table = iwl3945_tpt_table_g; 135 tpt_table = iwl3945_tpt_table_g;
144 table_size = ARRAY_SIZE(iwl3945_tpt_table_g); 136 table_size = ARRAY_SIZE(iwl3945_tpt_table_g);
145 break; 137 break;
146 138
147 case MODE_IEEE80211A: 139 case IEEE80211_BAND_5GHZ:
148 tpt_table = iwl3945_tpt_table_a; 140 tpt_table = iwl3945_tpt_table_a;
149 table_size = ARRAY_SIZE(iwl3945_tpt_table_a); 141 table_size = ARRAY_SIZE(iwl3945_tpt_table_a);
150 break; 142 break;
151 143
152 default: 144 default:
153 case MODE_IEEE80211B: 145 BUG();
154 tpt_table = iwl3945_tpt_table_b;
155 table_size = ARRAY_SIZE(iwl3945_tpt_table_b);
156 break; 146 break;
157 } 147 }
158 148
@@ -340,17 +330,17 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
340 * after assoc.. */ 330 * after assoc.. */
341 331
342 for (i = IWL_RATE_COUNT - 1; i >= 0; i--) { 332 for (i = IWL_RATE_COUNT - 1; i >= 0; i--) {
343 if (sta->supp_rates & (1 << i)) { 333 if (sta->supp_rates[local->hw.conf.channel->band] & (1 << i)) {
344 sta->txrate = i; 334 sta->txrate_idx = i;
345 break; 335 break;
346 } 336 }
347 } 337 }
348 338
349 sta->last_txrate = sta->txrate; 339 sta->last_txrate_idx = sta->txrate_idx;
350 340
351 /* For MODE_IEEE80211A mode it start at IWL_FIRST_OFDM_RATE */ 341 /* For 5 GHz band it start at IWL_FIRST_OFDM_RATE */
352 if (local->hw.conf.phymode == MODE_IEEE80211A) 342 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
353 sta->last_txrate += IWL_FIRST_OFDM_RATE; 343 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
354 344
355 IWL_DEBUG_RATE("leave\n"); 345 IWL_DEBUG_RATE("leave\n");
356} 346}
@@ -429,17 +419,19 @@ static int rs_adjust_next_rate(struct iwl3945_priv *priv, int rate)
429{ 419{
430 int next_rate = iwl3945_get_prev_ieee_rate(rate); 420 int next_rate = iwl3945_get_prev_ieee_rate(rate);
431 421
432 switch (priv->phymode) { 422 switch (priv->band) {
433 case MODE_IEEE80211A: 423 case IEEE80211_BAND_5GHZ:
434 if (rate == IWL_RATE_12M_INDEX) 424 if (rate == IWL_RATE_12M_INDEX)
435 next_rate = IWL_RATE_9M_INDEX; 425 next_rate = IWL_RATE_9M_INDEX;
436 else if (rate == IWL_RATE_6M_INDEX) 426 else if (rate == IWL_RATE_6M_INDEX)
437 next_rate = IWL_RATE_6M_INDEX; 427 next_rate = IWL_RATE_6M_INDEX;
438 break; 428 break;
429/* XXX cannot be invoked in current mac80211 so not a regression
439 case MODE_IEEE80211B: 430 case MODE_IEEE80211B:
440 if (rate == IWL_RATE_11M_INDEX_TABLE) 431 if (rate == IWL_RATE_11M_INDEX_TABLE)
441 next_rate = IWL_RATE_5M_INDEX_TABLE; 432 next_rate = IWL_RATE_5M_INDEX_TABLE;
442 break; 433 break;
434 */
443 default: 435 default:
444 break; 436 break;
445 } 437 }
@@ -465,15 +457,17 @@ static void rs_tx_status(void *priv_rate,
465 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; 457 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate;
466 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 458 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
467 struct iwl3945_rs_sta *rs_sta; 459 struct iwl3945_rs_sta *rs_sta;
460 struct ieee80211_supported_band *sband;
461
462 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
468 463
469 IWL_DEBUG_RATE("enter\n"); 464 IWL_DEBUG_RATE("enter\n");
470 465
471 retries = tx_resp->retry_count; 466 retries = tx_resp->retry_count;
472 467
473 first_index = tx_resp->control.tx_rate; 468 first_index = &sband->bitrates[0] - tx_resp->control.tx_rate;
474 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) { 469 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) {
475 IWL_DEBUG_RATE("leave: Rate out of bounds: %0x for %d\n", 470 IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index);
476 tx_resp->control.tx_rate, first_index);
477 return; 471 return;
478 } 472 }
479 473
@@ -561,14 +555,14 @@ static void rs_tx_status(void *priv_rate,
561} 555}
562 556
563static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta, 557static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta,
564 u8 index, u16 rate_mask, int phymode) 558 u8 index, u16 rate_mask, enum ieee80211_band band)
565{ 559{
566 u8 high = IWL_RATE_INVALID; 560 u8 high = IWL_RATE_INVALID;
567 u8 low = IWL_RATE_INVALID; 561 u8 low = IWL_RATE_INVALID;
568 562
569 /* 802.11A walks to the next literal adjacent rate in 563 /* 802.11A walks to the next literal adjacent rate in
570 * the rate table */ 564 * the rate table */
571 if (unlikely(phymode == MODE_IEEE80211A)) { 565 if (unlikely(band == IEEE80211_BAND_5GHZ)) {
572 int i; 566 int i;
573 u32 mask; 567 u32 mask;
574 568
@@ -639,7 +633,8 @@ static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta,
639 * 633 *
640 */ 634 */
641static void rs_get_rate(void *priv_rate, struct net_device *dev, 635static void rs_get_rate(void *priv_rate, struct net_device *dev,
642 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 636 struct ieee80211_supported_band *band,
637 struct sk_buff *skb,
643 struct rate_selection *sel) 638 struct rate_selection *sel)
644{ 639{
645 u8 low = IWL_RATE_INVALID; 640 u8 low = IWL_RATE_INVALID;
@@ -672,16 +667,16 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
672 is_multicast_ether_addr(hdr->addr1) || 667 is_multicast_ether_addr(hdr->addr1) ||
673 !sta || !sta->rate_ctrl_priv) { 668 !sta || !sta->rate_ctrl_priv) {
674 IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); 669 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
675 sel->rate = rate_lowest(local, local->oper_hw_mode, sta); 670 sel->rate = rate_lowest(local, band, sta);
676 if (sta) 671 if (sta)
677 sta_info_put(sta); 672 sta_info_put(sta);
678 return; 673 return;
679 } 674 }
680 675
681 rate_mask = sta->supp_rates; 676 rate_mask = sta->supp_rates[band->band];
682 index = min(sta->last_txrate & 0xffff, IWL_RATE_COUNT - 1); 677 index = min(sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT - 1);
683 678
684 if (priv->phymode == (u8) MODE_IEEE80211A) 679 if (priv->band == IEEE80211_BAND_5GHZ)
685 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE; 680 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE;
686 681
687 rs_sta = (void *)sta->rate_ctrl_priv; 682 rs_sta = (void *)sta->rate_ctrl_priv;
@@ -732,7 +727,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
732 current_tpt = window->average_tpt; 727 current_tpt = window->average_tpt;
733 728
734 high_low = iwl3945_get_adjacent_rate(rs_sta, index, rate_mask, 729 high_low = iwl3945_get_adjacent_rate(rs_sta, index, rate_mask,
735 local->hw.conf.phymode); 730 band->band);
736 low = high_low & 0xff; 731 low = high_low & 0xff;
737 high = (high_low >> 8) & 0xff; 732 high = (high_low >> 8) & 0xff;
738 733
@@ -810,11 +805,11 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
810 805
811 out: 806 out:
812 807
813 sta->last_txrate = index; 808 sta->last_txrate_idx = index;
814 if (priv->phymode == (u8) MODE_IEEE80211A) 809 if (priv->band == IEEE80211_BAND_5GHZ)
815 sta->txrate = sta->last_txrate - IWL_FIRST_OFDM_RATE; 810 sta->txrate_idx = sta->last_txrate_idx - IWL_FIRST_OFDM_RATE;
816 else 811 else
817 sta->txrate = sta->last_txrate; 812 sta->txrate_idx = sta->last_txrate_idx;
818 813
819 sta_info_put(sta); 814 sta_info_put(sta);
820 815
@@ -945,8 +940,9 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
945 spin_lock_irqsave(&rs_sta->lock, flags); 940 spin_lock_irqsave(&rs_sta->lock, flags);
946 941
947 rs_sta->tgg = 0; 942 rs_sta->tgg = 0;
948 switch (priv->phymode) { 943 switch (priv->band) {
949 case MODE_IEEE80211G: 944 case IEEE80211_BAND_2GHZ:
945 /* TODO: this always does G, not a regression */
950 if (priv->active_rxon.flags & RXON_FLG_TGG_PROTECT_MSK) { 946 if (priv->active_rxon.flags & RXON_FLG_TGG_PROTECT_MSK) {
951 rs_sta->tgg = 1; 947 rs_sta->tgg = 1;
952 rs_sta->expected_tpt = iwl3945_expected_tpt_g_prot; 948 rs_sta->expected_tpt = iwl3945_expected_tpt_g_prot;
@@ -954,14 +950,11 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
954 rs_sta->expected_tpt = iwl3945_expected_tpt_g; 950 rs_sta->expected_tpt = iwl3945_expected_tpt_g;
955 break; 951 break;
956 952
957 case MODE_IEEE80211A: 953 case IEEE80211_BAND_5GHZ:
958 rs_sta->expected_tpt = iwl3945_expected_tpt_a; 954 rs_sta->expected_tpt = iwl3945_expected_tpt_a;
959 break; 955 break;
960 956 case IEEE80211_NUM_BANDS:
961 default: 957 BUG();
962 IWL_WARNING("Invalid phymode. Defaulting to 802.11b\n");
963 case MODE_IEEE80211B:
964 rs_sta->expected_tpt = iwl3945_expected_tpt_b;
965 break; 958 break;
966 } 959 }
967 960
@@ -974,8 +967,7 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
974 967
975 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RATE, "Network RSSI: %d\n", rssi); 968 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RATE, "Network RSSI: %d\n", rssi);
976 969
977 rs_sta->start_rate = 970 rs_sta->start_rate = iwl3945_get_rate_index_by_rssi(rssi, priv->band);
978 iwl3945_get_rate_index_by_rssi(rssi, priv->phymode);
979 971
980 IWL_DEBUG_RATE("leave: rssi %d assign rate index: " 972 IWL_DEBUG_RATE("leave: rssi %d assign rate index: "
981 "%d (plcp 0x%x)\n", rssi, rs_sta->start_rate, 973 "%d (plcp 0x%x)\n", rssi, rs_sta->start_rate,
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 8d4d91d35fd2..50d927bb2170 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -247,7 +247,7 @@ static void iwl3945_add_radiotap(struct iwl3945_priv *priv,
247 * the information provided in the skb from the hardware */ 247 * the information provided in the skb from the hardware */
248 s8 signal = stats->ssi; 248 s8 signal = stats->ssi;
249 s8 noise = 0; 249 s8 noise = 0;
250 int rate = stats->rate; 250 int rate = stats->rate_idx;
251 u64 tsf = stats->mactime; 251 u64 tsf = stats->mactime;
252 __le16 phy_flags_hw = rx_hdr->phy_flags; 252 __le16 phy_flags_hw = rx_hdr->phy_flags;
253 253
@@ -315,7 +315,6 @@ static void iwl3945_add_radiotap(struct iwl3945_priv *priv,
315 IEEE80211_CHAN_2GHZ), 315 IEEE80211_CHAN_2GHZ),
316 &iwl3945_rt->rt_chbitmask); 316 &iwl3945_rt->rt_chbitmask);
317 317
318 rate = iwl3945_rate_index_from_plcp(rate);
319 if (rate == -1) 318 if (rate == -1)
320 iwl3945_rt->rt_rate = 0; 319 iwl3945_rt->rt_rate = 0;
321 else 320 else
@@ -387,11 +386,10 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
387 struct ieee80211_rx_status stats = { 386 struct ieee80211_rx_status stats = {
388 .mactime = le64_to_cpu(rx_end->timestamp), 387 .mactime = le64_to_cpu(rx_end->timestamp),
389 .freq = ieee80211chan2mhz(le16_to_cpu(rx_hdr->channel)), 388 .freq = ieee80211chan2mhz(le16_to_cpu(rx_hdr->channel)),
390 .channel = le16_to_cpu(rx_hdr->channel), 389 .band = (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
391 .phymode = (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? 390 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ,
392 MODE_IEEE80211G : MODE_IEEE80211A,
393 .antenna = 0, 391 .antenna = 0,
394 .rate = rx_hdr->rate, 392 .rate_idx = iwl3945_rate_index_from_plcp(rx_hdr->rate),
395 .flag = 0, 393 .flag = 0,
396 }; 394 };
397 u8 network_packet; 395 u8 network_packet;
@@ -450,8 +448,6 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
450 stats.ssi, stats.noise, stats.signal, 448 stats.ssi, stats.noise, stats.signal,
451 rx_stats_sig_avg, rx_stats_noise_diff); 449 rx_stats_sig_avg, rx_stats_noise_diff);
452 450
453 stats.freq = ieee80211chan2mhz(stats.channel);
454
455 /* can be covered by iwl3945_report_frame() in most cases */ 451 /* can be covered by iwl3945_report_frame() in most cases */
456/* IWL_DEBUG_RX("RX status: 0x%08X\n", rx_end->status); */ 452/* IWL_DEBUG_RX("RX status: 0x%08X\n", rx_end->status); */
457 453
@@ -464,8 +460,9 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
464 IWL_DEBUG_STATS 460 IWL_DEBUG_STATS
465 ("[%c] %d RSSI: %d Signal: %u, Noise: %u, Rate: %u\n", 461 ("[%c] %d RSSI: %d Signal: %u, Noise: %u, Rate: %u\n",
466 network_packet ? '*' : ' ', 462 network_packet ? '*' : ' ',
467 stats.channel, stats.ssi, stats.ssi, 463 le16_to_cpu(rx_hdr->channel),
468 stats.ssi, stats.rate); 464 stats.ssi, stats.ssi,
465 stats.ssi, stats.rate_idx);
469 466
470 if (iwl3945_debug_level & (IWL_DL_RX)) 467 if (iwl3945_debug_level & (IWL_DL_RX))
471 /* Set "1" to report good data frames in groups of 100 */ 468 /* Set "1" to report good data frames in groups of 100 */
@@ -689,7 +686,7 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
689 struct ieee80211_hdr *hdr, int sta_id, int tx_id) 686 struct ieee80211_hdr *hdr, int sta_id, int tx_id)
690{ 687{
691 unsigned long flags; 688 unsigned long flags;
692 u16 rate_index = min(ctrl->tx_rate & 0xffff, IWL_RATE_COUNT - 1); 689 u16 rate_index = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1);
693 u16 rate_mask; 690 u16 rate_mask;
694 int rate; 691 int rate;
695 u8 rts_retry_limit; 692 u8 rts_retry_limit;
@@ -1552,14 +1549,14 @@ int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv)
1552 .channel = priv->active_rxon.channel, 1549 .channel = priv->active_rxon.channel,
1553 }; 1550 };
1554 1551
1555 txpower.band = (priv->phymode == MODE_IEEE80211A) ? 0 : 1; 1552 txpower.band = (priv->band == IEEE80211_BAND_5GHZ) ? 0 : 1;
1556 ch_info = iwl3945_get_channel_info(priv, 1553 ch_info = iwl3945_get_channel_info(priv,
1557 priv->phymode, 1554 priv->band,
1558 le16_to_cpu(priv->active_rxon.channel)); 1555 le16_to_cpu(priv->active_rxon.channel));
1559 if (!ch_info) { 1556 if (!ch_info) {
1560 IWL_ERROR 1557 IWL_ERROR
1561 ("Failed to get channel info for channel %d [%d]\n", 1558 ("Failed to get channel info for channel %d [%d]\n",
1562 le16_to_cpu(priv->active_rxon.channel), priv->phymode); 1559 le16_to_cpu(priv->active_rxon.channel), priv->band);
1563 return -EINVAL; 1560 return -EINVAL;
1564 } 1561 }
1565 1562
@@ -2241,8 +2238,8 @@ int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv)
2241 table[index].next_rate_index = iwl3945_rates[prev_index].table_rs_index; 2238 table[index].next_rate_index = iwl3945_rates[prev_index].table_rs_index;
2242 } 2239 }
2243 2240
2244 switch (priv->phymode) { 2241 switch (priv->band) {
2245 case MODE_IEEE80211A: 2242 case IEEE80211_BAND_5GHZ:
2246 IWL_DEBUG_RATE("Select A mode rate scale\n"); 2243 IWL_DEBUG_RATE("Select A mode rate scale\n");
2247 /* If one of the following CCK rates is used, 2244 /* If one of the following CCK rates is used,
2248 * have it fall back to the 6M OFDM rate */ 2245 * have it fall back to the 6M OFDM rate */
@@ -2257,8 +2254,8 @@ int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv)
2257 iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index; 2254 iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index;
2258 break; 2255 break;
2259 2256
2260 case MODE_IEEE80211B: 2257 case IEEE80211_BAND_2GHZ:
2261 IWL_DEBUG_RATE("Select B mode rate scale\n"); 2258 IWL_DEBUG_RATE("Select B/G mode rate scale\n");
2262 /* If an OFDM rate is used, have it fall back to the 2259 /* If an OFDM rate is used, have it fall back to the
2263 * 1M CCK rates */ 2260 * 1M CCK rates */
2264 for (i = IWL_RATE_6M_INDEX_TABLE; i <= IWL_RATE_54M_INDEX_TABLE; i++) 2261 for (i = IWL_RATE_6M_INDEX_TABLE; i <= IWL_RATE_54M_INDEX_TABLE; i++)
@@ -2269,7 +2266,7 @@ int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv)
2269 break; 2266 break;
2270 2267
2271 default: 2268 default:
2272 IWL_DEBUG_RATE("Select G mode rate scale\n"); 2269 WARN_ON(1);
2273 break; 2270 break;
2274 } 2271 }
2275 2272
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index 1da14f9bbe0f..1beb5b676797 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -195,7 +195,7 @@ struct iwl3945_channel_info {
195 195
196 u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */ 196 u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
197 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */ 197 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
198 u8 phymode; /* MODE_IEEE80211{A,B,G} */ 198 enum ieee80211_band band;
199 199
200 /* Radio/DSP gain settings for each "normal" data Tx rate. 200 /* Radio/DSP gain settings for each "normal" data Tx rate.
201 * These include, in addition to RF and DSP gain, a few fields for 201 * These include, in addition to RF and DSP gain, a few fields for
@@ -699,14 +699,14 @@ struct iwl3945_priv {
699 struct list_head free_frames; 699 struct list_head free_frames;
700 int frames_count; 700 int frames_count;
701 701
702 u8 phymode; 702 enum ieee80211_band band;
703 int alloc_rxb_skb; 703 int alloc_rxb_skb;
704 bool add_radiotap; 704 bool add_radiotap;
705 705
706 void (*rx_handlers[REPLY_MAX])(struct iwl3945_priv *priv, 706 void (*rx_handlers[REPLY_MAX])(struct iwl3945_priv *priv,
707 struct iwl3945_rx_mem_buffer *rxb); 707 struct iwl3945_rx_mem_buffer *rxb);
708 708
709 const struct ieee80211_hw_mode *modes; 709 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
710 710
711#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT 711#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
712 /* spectrum measurement report caching */ 712 /* spectrum measurement report caching */
@@ -937,13 +937,12 @@ static inline int is_channel_radar(const struct iwl3945_channel_info *ch_info)
937 937
938static inline u8 is_channel_a_band(const struct iwl3945_channel_info *ch_info) 938static inline u8 is_channel_a_band(const struct iwl3945_channel_info *ch_info)
939{ 939{
940 return ch_info->phymode == MODE_IEEE80211A; 940 return ch_info->band == IEEE80211_BAND_5GHZ;
941} 941}
942 942
943static inline u8 is_channel_bg_band(const struct iwl3945_channel_info *ch_info) 943static inline u8 is_channel_bg_band(const struct iwl3945_channel_info *ch_info)
944{ 944{
945 return ((ch_info->phymode == MODE_IEEE80211B) || 945 return ch_info->band == IEEE80211_BAND_2GHZ;
946 (ch_info->phymode == MODE_IEEE80211G));
947} 946}
948 947
949static inline int is_channel_passive(const struct iwl3945_channel_info *ch) 948static inline int is_channel_passive(const struct iwl3945_channel_info *ch)
@@ -967,7 +966,7 @@ static inline int iwl3945_rate_index_from_plcp(int plcp)
967} 966}
968 967
969extern const struct iwl3945_channel_info *iwl3945_get_channel_info( 968extern const struct iwl3945_channel_info *iwl3945_get_channel_info(
970 const struct iwl3945_priv *priv, int phymode, u16 channel); 969 const struct iwl3945_priv *priv, enum ieee80211_band band, u16 channel);
971 970
972/* Requires full declaration of iwl3945_priv before including */ 971/* Requires full declaration of iwl3945_priv before including */
973#include "iwl-3945-io.h" 972#include "iwl-3945-io.h"
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
index 660671f17a3b..48a6a85355ec 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
@@ -139,7 +139,7 @@ struct iwl4965_lq_sta {
139 u8 valid_antenna; 139 u8 valid_antenna;
140 u8 is_green; 140 u8 is_green;
141 u8 is_dup; 141 u8 is_dup;
142 u8 phymode; 142 enum ieee80211_band band;
143 u8 ibss_sta_added; 143 u8 ibss_sta_added;
144 144
145 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ 145 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
@@ -563,7 +563,8 @@ static void rs_mcs_from_tbl(struct iwl4965_rate *mcs_rate,
563 * fill "search" or "active" tx mode table. 563 * fill "search" or "active" tx mode table.
564 */ 564 */
565static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate, 565static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate,
566 int phymode, struct iwl4965_scale_tbl_info *tbl, 566 enum ieee80211_band band,
567 struct iwl4965_scale_tbl_info *tbl,
567 int *rate_idx) 568 int *rate_idx)
568{ 569{
569 int index; 570 int index;
@@ -588,7 +589,7 @@ static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate,
588 tbl->lq_type = LQ_NONE; 589 tbl->lq_type = LQ_NONE;
589 else { 590 else {
590 591
591 if (phymode == MODE_IEEE80211A) 592 if (band == IEEE80211_BAND_5GHZ)
592 tbl->lq_type = LQ_A; 593 tbl->lq_type = LQ_A;
593 else 594 else
594 tbl->lq_type = LQ_G; 595 tbl->lq_type = LQ_G;
@@ -766,7 +767,7 @@ static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
766 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) { 767 if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
767 switch_to_legacy = 1; 768 switch_to_legacy = 1;
768 scale_index = rs_ht_to_legacy[scale_index]; 769 scale_index = rs_ht_to_legacy[scale_index];
769 if (lq_sta->phymode == MODE_IEEE80211A) 770 if (lq_sta->band == IEEE80211_BAND_5GHZ)
770 tbl->lq_type = LQ_A; 771 tbl->lq_type = LQ_A;
771 else 772 else
772 tbl->lq_type = LQ_G; 773 tbl->lq_type = LQ_G;
@@ -784,7 +785,7 @@ static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
784 /* Mask with station rate restriction */ 785 /* Mask with station rate restriction */
785 if (is_legacy(tbl->lq_type)) { 786 if (is_legacy(tbl->lq_type)) {
786 /* supp_rates has no CCK bits in A mode */ 787 /* supp_rates has no CCK bits in A mode */
787 if (lq_sta->phymode == (u8) MODE_IEEE80211A) 788 if (lq_sta->band == IEEE80211_BAND_5GHZ)
788 rate_mask = (u16)(rate_mask & 789 rate_mask = (u16)(rate_mask &
789 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); 790 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
790 else 791 else
@@ -883,9 +884,9 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
883 search_win = (struct iwl4965_rate_scale_data *) 884 search_win = (struct iwl4965_rate_scale_data *)
884 &(search_tbl->win[0]); 885 &(search_tbl->win[0]);
885 886
886 tx_mcs.rate_n_flags = tx_resp->control.tx_rate; 887 tx_mcs.rate_n_flags = tx_resp->control.tx_rate->hw_value;
887 888
888 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode, 889 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band,
889 &tbl_type, &rs_index); 890 &tbl_type, &rs_index);
890 if ((rs_index < 0) || (rs_index >= IWL_RATE_COUNT)) { 891 if ((rs_index < 0) || (rs_index >= IWL_RATE_COUNT)) {
891 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n", 892 IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
@@ -918,7 +919,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
918 * Each tx attempt steps one entry deeper in the rate table. */ 919 * Each tx attempt steps one entry deeper in the rate table. */
919 tx_mcs.rate_n_flags = 920 tx_mcs.rate_n_flags =
920 le32_to_cpu(table->rs_table[index].rate_n_flags); 921 le32_to_cpu(table->rs_table[index].rate_n_flags);
921 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode, 922 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band,
922 &tbl_type, &rs_index); 923 &tbl_type, &rs_index);
923 924
924 /* If type matches "search" table, 925 /* If type matches "search" table,
@@ -959,12 +960,12 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
959 * else look up the rate that was, finally, successful. 960 * else look up the rate that was, finally, successful.
960 */ 961 */
961 if (!tx_resp->retry_count) 962 if (!tx_resp->retry_count)
962 tx_mcs.rate_n_flags = tx_resp->control.tx_rate; 963 tx_mcs.rate_n_flags = tx_resp->control.tx_rate->hw_value;
963 else 964 else
964 tx_mcs.rate_n_flags = 965 tx_mcs.rate_n_flags =
965 le32_to_cpu(table->rs_table[index].rate_n_flags); 966 le32_to_cpu(table->rs_table[index].rate_n_flags);
966 967
967 rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode, 968 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band,
968 &tbl_type, &rs_index); 969 &tbl_type, &rs_index);
969 970
970 /* Update frame history window with "success" if Tx got ACKed ... */ 971 /* Update frame history window with "success" if Tx got ACKed ... */
@@ -1801,7 +1802,7 @@ static void rs_rate_scale_perform(struct iwl4965_priv *priv,
1801 is_green = lq_sta->is_green; 1802 is_green = lq_sta->is_green;
1802 1803
1803 /* current tx rate */ 1804 /* current tx rate */
1804 index = sta->last_txrate; 1805 index = sta->last_txrate_idx;
1805 1806
1806 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index, 1807 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
1807 tbl->lq_type); 1808 tbl->lq_type);
@@ -1814,7 +1815,7 @@ static void rs_rate_scale_perform(struct iwl4965_priv *priv,
1814 1815
1815 /* mask with station rate restriction */ 1816 /* mask with station rate restriction */
1816 if (is_legacy(tbl->lq_type)) { 1817 if (is_legacy(tbl->lq_type)) {
1817 if (lq_sta->phymode == (u8) MODE_IEEE80211A) 1818 if (lq_sta->band == IEEE80211_BAND_5GHZ)
1818 /* supp_rates has no CCK bits in A mode */ 1819 /* supp_rates has no CCK bits in A mode */
1819 rate_scale_index_msk = (u16) (rate_mask & 1820 rate_scale_index_msk = (u16) (rate_mask &
1820 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); 1821 (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
@@ -2134,15 +2135,15 @@ static void rs_rate_scale_perform(struct iwl4965_priv *priv,
2134out: 2135out:
2135 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green); 2136 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green);
2136 i = index; 2137 i = index;
2137 sta->last_txrate = i; 2138 sta->last_txrate_idx = i;
2138 2139
2139 /* sta->txrate is an index to A mode rates which start 2140 /* sta->txrate_idx is an index to A mode rates which start
2140 * at IWL_FIRST_OFDM_RATE 2141 * at IWL_FIRST_OFDM_RATE
2141 */ 2142 */
2142 if (lq_sta->phymode == (u8) MODE_IEEE80211A) 2143 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2143 sta->txrate = i - IWL_FIRST_OFDM_RATE; 2144 sta->txrate_idx = i - IWL_FIRST_OFDM_RATE;
2144 else 2145 else
2145 sta->txrate = i; 2146 sta->txrate_idx = i;
2146 2147
2147 return; 2148 return;
2148} 2149}
@@ -2164,7 +2165,7 @@ static void rs_initialize_lq(struct iwl4965_priv *priv,
2164 goto out; 2165 goto out;
2165 2166
2166 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; 2167 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
2167 i = sta->last_txrate; 2168 i = sta->last_txrate_idx;
2168 2169
2169 if ((lq_sta->lq.sta_id == 0xff) && 2170 if ((lq_sta->lq.sta_id == 0xff) &&
2170 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)) 2171 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
@@ -2188,7 +2189,7 @@ static void rs_initialize_lq(struct iwl4965_priv *priv,
2188 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK; 2189 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK;
2189 2190
2190 tbl->antenna_type = ANT_AUX; 2191 tbl->antenna_type = ANT_AUX;
2191 rs_get_tbl_info_from_mcs(&mcs_rate, priv->phymode, tbl, &rate_idx); 2192 rs_get_tbl_info_from_mcs(&mcs_rate, priv->band, tbl, &rate_idx);
2192 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type)) 2193 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type))
2193 rs_toggle_antenna(&mcs_rate, tbl); 2194 rs_toggle_antenna(&mcs_rate, tbl);
2194 2195
@@ -2202,7 +2203,8 @@ static void rs_initialize_lq(struct iwl4965_priv *priv,
2202} 2203}
2203 2204
2204static void rs_get_rate(void *priv_rate, struct net_device *dev, 2205static void rs_get_rate(void *priv_rate, struct net_device *dev,
2205 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 2206 struct ieee80211_supported_band *sband,
2207 struct sk_buff *skb,
2206 struct rate_selection *sel) 2208 struct rate_selection *sel)
2207{ 2209{
2208 2210
@@ -2224,14 +2226,14 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
2224 fc = le16_to_cpu(hdr->frame_control); 2226 fc = le16_to_cpu(hdr->frame_control);
2225 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) || 2227 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) ||
2226 !sta || !sta->rate_ctrl_priv) { 2228 !sta || !sta->rate_ctrl_priv) {
2227 sel->rate = rate_lowest(local, local->oper_hw_mode, sta); 2229 sel->rate = rate_lowest(local, sband, sta);
2228 if (sta) 2230 if (sta)
2229 sta_info_put(sta); 2231 sta_info_put(sta);
2230 return; 2232 return;
2231 } 2233 }
2232 2234
2233 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; 2235 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
2234 i = sta->last_txrate; 2236 i = sta->last_txrate_idx;
2235 2237
2236 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && 2238 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2237 !lq_sta->ibss_sta_added) { 2239 !lq_sta->ibss_sta_added) {
@@ -2256,7 +2258,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
2256 2258
2257 done: 2259 done:
2258 if ((i < 0) || (i > IWL_RATE_COUNT)) { 2260 if ((i < 0) || (i > IWL_RATE_COUNT)) {
2259 sel->rate = rate_lowest(local, local->oper_hw_mode, sta); 2261 sel->rate = rate_lowest(local, sband, sta);
2260 return; 2262 return;
2261 } 2263 }
2262 sta_info_put(sta); 2264 sta_info_put(sta);
@@ -2291,13 +2293,15 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2291{ 2293{
2292 int i, j; 2294 int i, j;
2293 struct ieee80211_conf *conf = &local->hw.conf; 2295 struct ieee80211_conf *conf = &local->hw.conf;
2294 struct ieee80211_hw_mode *mode = local->oper_hw_mode; 2296 struct ieee80211_supported_band *sband;
2295 struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate; 2297 struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate;
2296 struct iwl4965_lq_sta *lq_sta = priv_sta; 2298 struct iwl4965_lq_sta *lq_sta = priv_sta;
2297 2299
2300 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2301
2298 lq_sta->flush_timer = 0; 2302 lq_sta->flush_timer = 0;
2299 lq_sta->supp_rates = sta->supp_rates; 2303 lq_sta->supp_rates = sta->supp_rates[sband->band];
2300 sta->txrate = 3; 2304 sta->txrate_idx = 3;
2301 for (j = 0; j < LQ_SIZE; j++) 2305 for (j = 0; j < LQ_SIZE; j++)
2302 for (i = 0; i < IWL_RATE_COUNT; i++) 2306 for (i = 0; i < IWL_RATE_COUNT; i++)
2303 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i])); 2307 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i]));
@@ -2332,15 +2336,15 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2332 } 2336 }
2333 2337
2334 /* Find highest tx rate supported by hardware and destination station */ 2338 /* Find highest tx rate supported by hardware and destination station */
2335 for (i = 0; i < mode->num_rates; i++) { 2339 for (i = 0; i < sband->n_bitrates; i++)
2336 if ((sta->supp_rates & BIT(i)) && 2340 if (sta->supp_rates[sband->band] & BIT(i))
2337 (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED)) 2341 sta->txrate_idx = i;
2338 sta->txrate = i; 2342
2339 } 2343 sta->last_txrate_idx = sta->txrate_idx;
2340 sta->last_txrate = sta->txrate; 2344 /* WTF is with this bogus comment? A doesn't have cck rates */
2341 /* For MODE_IEEE80211A, cck rates are at end of rate table */ 2345 /* For MODE_IEEE80211A, cck rates are at end of rate table */
2342 if (local->hw.conf.phymode == MODE_IEEE80211A) 2346 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
2343 sta->last_txrate += IWL_FIRST_OFDM_RATE; 2347 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
2344 2348
2345 lq_sta->is_dup = 0; 2349 lq_sta->is_dup = 0;
2346 lq_sta->valid_antenna = priv->valid_antenna; 2350 lq_sta->valid_antenna = priv->valid_antenna;
@@ -2349,7 +2353,7 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2349 lq_sta->active_rate = priv->active_rate; 2353 lq_sta->active_rate = priv->active_rate;
2350 lq_sta->active_rate &= ~(0x1000); 2354 lq_sta->active_rate &= ~(0x1000);
2351 lq_sta->active_rate_basic = priv->active_rate_basic; 2355 lq_sta->active_rate_basic = priv->active_rate_basic;
2352 lq_sta->phymode = priv->phymode; 2356 lq_sta->band = priv->band;
2353#ifdef CONFIG_IWL4965_HT 2357#ifdef CONFIG_IWL4965_HT
2354 /* 2358 /*
2355 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3), 2359 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
@@ -2401,7 +2405,7 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2401 rs_dbgfs_set_mcs(lq_sta, tx_mcs, index); 2405 rs_dbgfs_set_mcs(lq_sta, tx_mcs, index);
2402 2406
2403 /* Interpret rate_n_flags */ 2407 /* Interpret rate_n_flags */
2404 rs_get_tbl_info_from_mcs(tx_mcs, lq_sta->phymode, 2408 rs_get_tbl_info_from_mcs(tx_mcs, lq_sta->band,
2405 &tbl_type, &rate_idx); 2409 &tbl_type, &rate_idx);
2406 2410
2407 /* How many times should we repeat the initial rate? */ 2411 /* How many times should we repeat the initial rate? */
@@ -2455,7 +2459,7 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2455 index++; 2459 index++;
2456 } 2460 }
2457 2461
2458 rs_get_tbl_info_from_mcs(&new_rate, lq_sta->phymode, &tbl_type, 2462 rs_get_tbl_info_from_mcs(&new_rate, lq_sta->band, &tbl_type,
2459 &rate_idx); 2463 &rate_idx);
2460 2464
2461 /* Indicate to uCode which entries might be MIMO. 2465 /* Indicate to uCode which entries might be MIMO.
@@ -2542,7 +2546,7 @@ static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
2542{ 2546{
2543 u32 base_rate; 2547 u32 base_rate;
2544 2548
2545 if (lq_sta->phymode == (u8) MODE_IEEE80211A) 2549 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2546 base_rate = 0x800D; 2550 base_rate = 0x800D;
2547 else 2551 else
2548 base_rate = 0x820A; 2552 base_rate = 0x820A;
@@ -2802,7 +2806,7 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2802 2806
2803 cnt += sprintf(&buf[cnt], "\nrate scale type %d antenna %d " 2807 cnt += sprintf(&buf[cnt], "\nrate scale type %d antenna %d "
2804 "active_search %d rate index %d\n", lq_type, antenna, 2808 "active_search %d rate index %d\n", lq_type, antenna,
2805 lq_sta->search_better_tbl, sta->last_txrate); 2809 lq_sta->search_better_tbl, sta->last_txrate_idx);
2806 2810
2807 sta_info_put(sta); 2811 sta_info_put(sta);
2808 return cnt; 2812 return cnt;
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index 0bded8570275..a89439320498 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -339,14 +339,15 @@ static int iwl4965_kw_alloc(struct iwl4965_priv *priv)
339 * 339 *
340 * Does not set up a command, or touch hardware. 340 * Does not set up a command, or touch hardware.
341 */ 341 */
342int iwl4965_set_fat_chan_info(struct iwl4965_priv *priv, int phymode, u16 channel, 342int iwl4965_set_fat_chan_info(struct iwl4965_priv *priv,
343 enum ieee80211_band band, u16 channel,
343 const struct iwl4965_eeprom_channel *eeprom_ch, 344 const struct iwl4965_eeprom_channel *eeprom_ch,
344 u8 fat_extension_channel) 345 u8 fat_extension_channel)
345{ 346{
346 struct iwl4965_channel_info *ch_info; 347 struct iwl4965_channel_info *ch_info;
347 348
348 ch_info = (struct iwl4965_channel_info *) 349 ch_info = (struct iwl4965_channel_info *)
349 iwl4965_get_channel_info(priv, phymode, channel); 350 iwl4965_get_channel_info(priv, band, channel);
350 351
351 if (!is_channel_valid(ch_info)) 352 if (!is_channel_valid(ch_info))
352 return -1; 353 return -1;
@@ -1939,11 +1940,12 @@ static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
1939} 1940}
1940 1941
1941static const struct iwl4965_channel_info * 1942static const struct iwl4965_channel_info *
1942iwl4965_get_channel_txpower_info(struct iwl4965_priv *priv, u8 phymode, u16 channel) 1943iwl4965_get_channel_txpower_info(struct iwl4965_priv *priv,
1944 enum ieee80211_band band, u16 channel)
1943{ 1945{
1944 const struct iwl4965_channel_info *ch_info; 1946 const struct iwl4965_channel_info *ch_info;
1945 1947
1946 ch_info = iwl4965_get_channel_info(priv, phymode, channel); 1948 ch_info = iwl4965_get_channel_info(priv, band, channel);
1947 1949
1948 if (!is_channel_valid(ch_info)) 1950 if (!is_channel_valid(ch_info))
1949 return NULL; 1951 return NULL;
@@ -2392,7 +2394,7 @@ static int iwl4965_fill_txpower_tbl(struct iwl4965_priv *priv, u8 band, u16 chan
2392 2394
2393 /* Get current (RXON) channel, band, width */ 2395 /* Get current (RXON) channel, band, width */
2394 ch_info = 2396 ch_info =
2395 iwl4965_get_channel_txpower_info(priv, priv->phymode, channel); 2397 iwl4965_get_channel_txpower_info(priv, priv->band, channel);
2396 2398
2397 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band, 2399 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
2398 is_fat); 2400 is_fat);
@@ -2619,8 +2621,7 @@ int iwl4965_hw_reg_send_txpower(struct iwl4965_priv *priv)
2619 return -EAGAIN; 2621 return -EAGAIN;
2620 } 2622 }
2621 2623
2622 band = ((priv->phymode == MODE_IEEE80211B) || 2624 band = priv->band == IEEE80211_BAND_2GHZ;
2623 (priv->phymode == MODE_IEEE80211G));
2624 2625
2625 is_fat = is_fat_channel(priv->active_rxon.flags); 2626 is_fat = is_fat_channel(priv->active_rxon.flags);
2626 2627
@@ -2650,10 +2651,9 @@ int iwl4965_hw_channel_switch(struct iwl4965_priv *priv, u16 channel)
2650 struct iwl4965_channel_switch_cmd cmd = { 0 }; 2651 struct iwl4965_channel_switch_cmd cmd = { 0 };
2651 const struct iwl4965_channel_info *ch_info; 2652 const struct iwl4965_channel_info *ch_info;
2652 2653
2653 band = ((priv->phymode == MODE_IEEE80211B) || 2654 band = priv->band == IEEE80211_BAND_2GHZ;
2654 (priv->phymode == MODE_IEEE80211G));
2655 2655
2656 ch_info = iwl4965_get_channel_info(priv, priv->phymode, channel); 2656 ch_info = iwl4965_get_channel_info(priv, priv->band, channel);
2657 2657
2658 is_fat = is_fat_channel(priv->staging_rxon.flags); 2658 is_fat = is_fat_channel(priv->staging_rxon.flags);
2659 2659
@@ -2698,7 +2698,7 @@ void iwl4965_hw_build_tx_cmd_rate(struct iwl4965_priv *priv,
2698 u16 fc = le16_to_cpu(hdr->frame_control); 2698 u16 fc = le16_to_cpu(hdr->frame_control);
2699 u8 rate_plcp; 2699 u8 rate_plcp;
2700 u16 rate_flags = 0; 2700 u16 rate_flags = 0;
2701 int rate_idx = min(ctrl->tx_rate & 0xffff, IWL_RATE_COUNT - 1); 2701 int rate_idx = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1);
2702 2702
2703 rate_plcp = iwl4965_rates[rate_idx].plcp; 2703 rate_plcp = iwl4965_rates[rate_idx].plcp;
2704 2704
@@ -3178,7 +3178,7 @@ static void iwl4965_add_radiotap(struct iwl4965_priv *priv,
3178{ 3178{
3179 s8 signal = stats->ssi; 3179 s8 signal = stats->ssi;
3180 s8 noise = 0; 3180 s8 noise = 0;
3181 int rate = stats->rate; 3181 int rate = stats->rate_idx;
3182 u64 tsf = stats->mactime; 3182 u64 tsf = stats->mactime;
3183 __le16 phy_flags_hw = rx_start->phy_flags; 3183 __le16 phy_flags_hw = rx_start->phy_flags;
3184 struct iwl4965_rt_rx_hdr { 3184 struct iwl4965_rt_rx_hdr {
@@ -3246,7 +3246,6 @@ static void iwl4965_add_radiotap(struct iwl4965_priv *priv,
3246 IEEE80211_CHAN_2GHZ), 3246 IEEE80211_CHAN_2GHZ),
3247 &iwl4965_rt->rt_chbitmask); 3247 &iwl4965_rt->rt_chbitmask);
3248 3248
3249 rate = iwl4965_rate_index_from_plcp(rate);
3250 if (rate == -1) 3249 if (rate == -1)
3251 iwl4965_rt->rt_rate = 0; 3250 iwl4965_rt->rt_rate = 0;
3252 else 3251 else
@@ -3542,12 +3541,13 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
3542 u16 fc; 3541 u16 fc;
3543 struct ieee80211_rx_status stats = { 3542 struct ieee80211_rx_status stats = {
3544 .mactime = le64_to_cpu(rx_start->timestamp), 3543 .mactime = le64_to_cpu(rx_start->timestamp),
3545 .channel = le16_to_cpu(rx_start->channel), 3544 .freq = ieee80211chan2mhz(le16_to_cpu(rx_start->channel)),
3546 .phymode = 3545 .band =
3547 (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? 3546 (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
3548 MODE_IEEE80211G : MODE_IEEE80211A, 3547 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ,
3549 .antenna = 0, 3548 .antenna = 0,
3550 .rate = iwl4965_hw_get_rate(rx_start->rate_n_flags), 3549 .rate_idx = iwl4965_hw_get_rate(
3550 le32_to_cpu(rx_start->rate_n_flags)),
3551 .flag = 0, 3551 .flag = 0,
3552 }; 3552 };
3553 u8 network_packet; 3553 u8 network_packet;
@@ -3598,8 +3598,6 @@ static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv,
3598 3598
3599 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp); 3599 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
3600 3600
3601 stats.freq = ieee80211chan2mhz(stats.channel);
3602
3603 /* Find max signal strength (dBm) among 3 antenna/receiver chains */ 3601 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
3604 stats.ssi = iwl4965_calc_rssi(rx_start); 3602 stats.ssi = iwl4965_calc_rssi(rx_start);
3605 3603
@@ -4185,7 +4183,7 @@ void iwl4965_add_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
4185 * all the way down to 1M in IEEE order, and then spin on 1M */ 4183 * all the way down to 1M in IEEE order, and then spin on 1M */
4186 if (is_ap) 4184 if (is_ap)
4187 r = IWL_RATE_54M_INDEX; 4185 r = IWL_RATE_54M_INDEX;
4188 else if (priv->phymode == MODE_IEEE80211A) 4186 else if (priv->band == IEEE80211_BAND_5GHZ)
4189 r = IWL_RATE_6M_INDEX; 4187 r = IWL_RATE_6M_INDEX;
4190 else 4188 else
4191 r = IWL_RATE_1M_INDEX; 4189 r = IWL_RATE_1M_INDEX;
@@ -4218,12 +4216,13 @@ void iwl4965_add_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
4218 4216
4219#ifdef CONFIG_IWL4965_HT 4217#ifdef CONFIG_IWL4965_HT
4220 4218
4221static u8 iwl4965_is_channel_extension(struct iwl4965_priv *priv, int phymode, 4219static u8 iwl4965_is_channel_extension(struct iwl4965_priv *priv,
4220 enum ieee80211_band band,
4222 u16 channel, u8 extension_chan_offset) 4221 u16 channel, u8 extension_chan_offset)
4223{ 4222{
4224 const struct iwl4965_channel_info *ch_info; 4223 const struct iwl4965_channel_info *ch_info;
4225 4224
4226 ch_info = iwl4965_get_channel_info(priv, phymode, channel); 4225 ch_info = iwl4965_get_channel_info(priv, band, channel);
4227 if (!is_channel_valid(ch_info)) 4226 if (!is_channel_valid(ch_info))
4228 return 0; 4227 return 0;
4229 4228
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.h b/drivers/net/wireless/iwlwifi/iwl-4965.h
index de5c1bf8fc42..cb8f7f2a8d48 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.h
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.h
@@ -206,7 +206,7 @@ struct iwl4965_channel_info {
206 206
207 u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */ 207 u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
208 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */ 208 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
209 u8 phymode; /* MODE_IEEE80211{A,B,G} */ 209 enum ieee80211_band band;
210 210
211 /* Radio/DSP gain settings for each "normal" data Tx rate. 211 /* Radio/DSP gain settings for each "normal" data Tx rate.
212 * These include, in addition to RF and DSP gain, a few fields for 212 * These include, in addition to RF and DSP gain, a few fields for
@@ -764,7 +764,8 @@ extern void iwl4965_update_rate_scaling(struct iwl4965_priv *priv, u8 mode);
764extern void iwl4965_chain_noise_reset(struct iwl4965_priv *priv); 764extern void iwl4965_chain_noise_reset(struct iwl4965_priv *priv);
765extern void iwl4965_init_sensitivity(struct iwl4965_priv *priv, u8 flags, 765extern void iwl4965_init_sensitivity(struct iwl4965_priv *priv, u8 flags,
766 u8 force); 766 u8 force);
767extern int iwl4965_set_fat_chan_info(struct iwl4965_priv *priv, int phymode, 767extern int iwl4965_set_fat_chan_info(struct iwl4965_priv *priv,
768 enum ieee80211_band band,
768 u16 channel, 769 u16 channel,
769 const struct iwl4965_eeprom_channel *eeprom_ch, 770 const struct iwl4965_eeprom_channel *eeprom_ch,
770 u8 fat_extension_channel); 771 u8 fat_extension_channel);
@@ -977,14 +978,14 @@ struct iwl4965_priv {
977 struct list_head free_frames; 978 struct list_head free_frames;
978 int frames_count; 979 int frames_count;
979 980
980 u8 phymode; 981 enum ieee80211_band band;
981 int alloc_rxb_skb; 982 int alloc_rxb_skb;
982 bool add_radiotap; 983 bool add_radiotap;
983 984
984 void (*rx_handlers[REPLY_MAX])(struct iwl4965_priv *priv, 985 void (*rx_handlers[REPLY_MAX])(struct iwl4965_priv *priv,
985 struct iwl4965_rx_mem_buffer *rxb); 986 struct iwl4965_rx_mem_buffer *rxb);
986 987
987 const struct ieee80211_hw_mode *modes; 988 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
988 989
989#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT 990#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
990 /* spectrum measurement report caching */ 991 /* spectrum measurement report caching */
@@ -1243,13 +1244,12 @@ static inline int is_channel_radar(const struct iwl4965_channel_info *ch_info)
1243 1244
1244static inline u8 is_channel_a_band(const struct iwl4965_channel_info *ch_info) 1245static inline u8 is_channel_a_band(const struct iwl4965_channel_info *ch_info)
1245{ 1246{
1246 return ch_info->phymode == MODE_IEEE80211A; 1247 return ch_info->band == IEEE80211_BAND_5GHZ;
1247} 1248}
1248 1249
1249static inline u8 is_channel_bg_band(const struct iwl4965_channel_info *ch_info) 1250static inline u8 is_channel_bg_band(const struct iwl4965_channel_info *ch_info)
1250{ 1251{
1251 return ((ch_info->phymode == MODE_IEEE80211B) || 1252 return ch_info->band == IEEE80211_BAND_2GHZ;
1252 (ch_info->phymode == MODE_IEEE80211G));
1253} 1253}
1254 1254
1255static inline int is_channel_passive(const struct iwl4965_channel_info *ch) 1255static inline int is_channel_passive(const struct iwl4965_channel_info *ch)
@@ -1263,7 +1263,7 @@ static inline int is_channel_ibss(const struct iwl4965_channel_info *ch)
1263} 1263}
1264 1264
1265extern const struct iwl4965_channel_info *iwl4965_get_channel_info( 1265extern const struct iwl4965_channel_info *iwl4965_get_channel_info(
1266 const struct iwl4965_priv *priv, int phymode, u16 channel); 1266 const struct iwl4965_priv *priv, enum ieee80211_band band, u16 channel);
1267 1267
1268/* Requires full declaration of iwl4965_priv before including */ 1268/* Requires full declaration of iwl4965_priv before including */
1269#include "iwl-4965-io.h" 1269#include "iwl-4965-io.h"
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 40b71bc2c4a4..57a1d70f2abf 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -116,16 +116,10 @@ static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
116 return NULL; 116 return NULL;
117} 117}
118 118
119static const struct ieee80211_hw_mode *iwl3945_get_hw_mode( 119static const struct ieee80211_supported_band *iwl3945_get_band(
120 struct iwl3945_priv *priv, int mode) 120 struct iwl3945_priv *priv, enum ieee80211_band band)
121{ 121{
122 int i; 122 return priv->hw->wiphy->bands[band];
123
124 for (i = 0; i < 3; i++)
125 if (priv->modes[i].mode == mode)
126 return &priv->modes[i];
127
128 return NULL;
129} 123}
130 124
131static int iwl3945_is_empty_essid(const char *essid, int essid_len) 125static int iwl3945_is_empty_essid(const char *essid, int essid_len)
@@ -547,7 +541,7 @@ u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8
547 station->sta.sta.sta_id = index; 541 station->sta.sta.sta_id = index;
548 station->sta.station_flags = 0; 542 station->sta.station_flags = 0;
549 543
550 if (priv->phymode == MODE_IEEE80211A) 544 if (priv->band == IEEE80211_BAND_5GHZ)
551 rate = IWL_RATE_6M_PLCP; 545 rate = IWL_RATE_6M_PLCP;
552 else 546 else
553 rate = IWL_RATE_1M_PLCP; 547 rate = IWL_RATE_1M_PLCP;
@@ -894,35 +888,37 @@ int iwl3945_send_statistics_request(struct iwl3945_priv *priv)
894 888
895/** 889/**
896 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON 890 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
897 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz 891 * @band: 2.4 or 5 GHz band
898 * @channel: Any channel valid for the requested phymode 892 * @channel: Any channel valid for the requested band
899 893
900 * In addition to setting the staging RXON, priv->phymode is also set. 894 * In addition to setting the staging RXON, priv->band is also set.
901 * 895 *
902 * NOTE: Does not commit to the hardware; it sets appropriate bit fields 896 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
903 * in the staging RXON flag structure based on the phymode 897 * in the staging RXON flag structure based on the band
904 */ 898 */
905static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv, u8 phymode, u16 channel) 899static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv,
900 enum ieee80211_band band,
901 u16 channel)
906{ 902{
907 if (!iwl3945_get_channel_info(priv, phymode, channel)) { 903 if (!iwl3945_get_channel_info(priv, band, channel)) {
908 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", 904 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
909 channel, phymode); 905 channel, band);
910 return -EINVAL; 906 return -EINVAL;
911 } 907 }
912 908
913 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && 909 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
914 (priv->phymode == phymode)) 910 (priv->band == band))
915 return 0; 911 return 0;
916 912
917 priv->staging_rxon.channel = cpu_to_le16(channel); 913 priv->staging_rxon.channel = cpu_to_le16(channel);
918 if (phymode == MODE_IEEE80211A) 914 if (band == IEEE80211_BAND_5GHZ)
919 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; 915 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
920 else 916 else
921 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; 917 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
922 918
923 priv->phymode = phymode; 919 priv->band = band;
924 920
925 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode); 921 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
926 922
927 return 0; 923 return 0;
928} 924}
@@ -1210,8 +1206,7 @@ static int iwl3945_commit_rxon(struct iwl3945_priv *priv)
1210 return -EIO; 1206 return -EIO;
1211 } 1207 }
1212 1208
1213 /* Init the hardware's rate fallback order based on the 1209 /* Init the hardware's rate fallback order based on the band */
1214 * phymode */
1215 rc = iwl3945_init_hw_rate_table(priv); 1210 rc = iwl3945_init_hw_rate_table(priv);
1216 if (rc) { 1211 if (rc) {
1217 IWL_ERROR("Error setting HW rate table: %02X\n", rc); 1212 IWL_ERROR("Error setting HW rate table: %02X\n", rc);
@@ -2461,9 +2456,10 @@ static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt)
2461 return 0; 2456 return 0;
2462} 2457}
2463 2458
2464static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode) 2459static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv,
2460 enum ieee80211_band band)
2465{ 2461{
2466 if (phymode == MODE_IEEE80211A) { 2462 if (band == IEEE80211_BAND_5GHZ) {
2467 priv->staging_rxon.flags &= 2463 priv->staging_rxon.flags &=
2468 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK 2464 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2469 | RXON_FLG_CCK_MSK); 2465 | RXON_FLG_CCK_MSK);
@@ -2526,7 +2522,7 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2526 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; 2522 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2527#endif 2523#endif
2528 2524
2529 ch_info = iwl3945_get_channel_info(priv, priv->phymode, 2525 ch_info = iwl3945_get_channel_info(priv, priv->band,
2530 le16_to_cpu(priv->staging_rxon.channel)); 2526 le16_to_cpu(priv->staging_rxon.channel));
2531 2527
2532 if (!ch_info) 2528 if (!ch_info)
@@ -2542,11 +2538,11 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2542 2538
2543 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); 2539 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2544 if (is_channel_a_band(ch_info)) 2540 if (is_channel_a_band(ch_info))
2545 priv->phymode = MODE_IEEE80211A; 2541 priv->band = IEEE80211_BAND_5GHZ;
2546 else 2542 else
2547 priv->phymode = MODE_IEEE80211G; 2543 priv->band = IEEE80211_BAND_2GHZ;
2548 2544
2549 iwl3945_set_flags_for_phymode(priv, priv->phymode); 2545 iwl3945_set_flags_for_phymode(priv, priv->band);
2550 2546
2551 priv->staging_rxon.ofdm_basic_rates = 2547 priv->staging_rxon.ofdm_basic_rates =
2552 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 2548 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
@@ -2560,7 +2556,7 @@ static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
2560 const struct iwl3945_channel_info *ch_info; 2556 const struct iwl3945_channel_info *ch_info;
2561 2557
2562 ch_info = iwl3945_get_channel_info(priv, 2558 ch_info = iwl3945_get_channel_info(priv,
2563 priv->phymode, 2559 priv->band,
2564 le16_to_cpu(priv->staging_rxon.channel)); 2560 le16_to_cpu(priv->staging_rxon.channel));
2565 2561
2566 if (!ch_info || !is_channel_ibss(ch_info)) { 2562 if (!ch_info || !is_channel_ibss(ch_info)) {
@@ -2792,7 +2788,7 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2792 goto drop_unlock; 2788 goto drop_unlock;
2793 } 2789 }
2794 2790
2795 if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) { 2791 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
2796 IWL_ERROR("ERROR: No TX rate available.\n"); 2792 IWL_ERROR("ERROR: No TX rate available.\n");
2797 goto drop_unlock; 2793 goto drop_unlock;
2798 } 2794 }
@@ -2992,12 +2988,12 @@ drop:
2992 2988
2993static void iwl3945_set_rate(struct iwl3945_priv *priv) 2989static void iwl3945_set_rate(struct iwl3945_priv *priv)
2994{ 2990{
2995 const struct ieee80211_hw_mode *hw = NULL; 2991 const struct ieee80211_supported_band *sband = NULL;
2996 struct ieee80211_rate *rate; 2992 struct ieee80211_rate *rate;
2997 int i; 2993 int i;
2998 2994
2999 hw = iwl3945_get_hw_mode(priv, priv->phymode); 2995 sband = iwl3945_get_band(priv, priv->band);
3000 if (!hw) { 2996 if (!sband) {
3001 IWL_ERROR("Failed to set rate: unable to get hw mode\n"); 2997 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3002 return; 2998 return;
3003 } 2999 }
@@ -3005,24 +3001,17 @@ static void iwl3945_set_rate(struct iwl3945_priv *priv)
3005 priv->active_rate = 0; 3001 priv->active_rate = 0;
3006 priv->active_rate_basic = 0; 3002 priv->active_rate_basic = 0;
3007 3003
3008 IWL_DEBUG_RATE("Setting rates for 802.11%c\n", 3004 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
3009 hw->mode == MODE_IEEE80211A ? 3005 sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
3010 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g')); 3006
3011 3007 for (i = 0; i < sband->n_bitrates; i++) {
3012 for (i = 0; i < hw->num_rates; i++) { 3008 rate = &sband->bitrates[i];
3013 rate = &(hw->rates[i]); 3009 if ((rate->hw_value < IWL_RATE_COUNT) &&
3014 if ((rate->val < IWL_RATE_COUNT) && 3010 !(rate->flags & IEEE80211_CHAN_DISABLED)) {
3015 (rate->flags & IEEE80211_RATE_SUPPORTED)) { 3011 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
3016 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n", 3012 rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
3017 rate->val, iwl3945_rates[rate->val].plcp, 3013 priv->active_rate |= (1 << rate->hw_value);
3018 (rate->flags & IEEE80211_RATE_BASIC) ? 3014 }
3019 "*" : "");
3020 priv->active_rate |= (1 << rate->val);
3021 if (rate->flags & IEEE80211_RATE_BASIC)
3022 priv->active_rate_basic |= (1 << rate->val);
3023 } else
3024 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
3025 rate->val, iwl3945_rates[rate->val].plcp);
3026 } 3015 }
3027 3016
3028 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", 3017 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
@@ -3436,8 +3425,6 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
3436 tx_status->flags = 3425 tx_status->flags =
3437 iwl3945_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; 3426 iwl3945_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3438 3427
3439 tx_status->control.tx_rate = iwl3945_rate_index_from_plcp(tx_resp->rate);
3440
3441 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n", 3428 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
3442 txq_id, iwl3945_get_tx_fail_reason(status), status, 3429 txq_id, iwl3945_get_tx_fail_reason(status), status,
3443 tx_resp->rate, tx_resp->failure_frame); 3430 tx_resp->rate, tx_resp->failure_frame);
@@ -5026,24 +5013,24 @@ static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int ban
5026 * Based on band and channel number. 5013 * Based on band and channel number.
5027 */ 5014 */
5028const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv, 5015const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv,
5029 int phymode, u16 channel) 5016 enum ieee80211_band band, u16 channel)
5030{ 5017{
5031 int i; 5018 int i;
5032 5019
5033 switch (phymode) { 5020 switch (band) {
5034 case MODE_IEEE80211A: 5021 case IEEE80211_BAND_5GHZ:
5035 for (i = 14; i < priv->channel_count; i++) { 5022 for (i = 14; i < priv->channel_count; i++) {
5036 if (priv->channel_info[i].channel == channel) 5023 if (priv->channel_info[i].channel == channel)
5037 return &priv->channel_info[i]; 5024 return &priv->channel_info[i];
5038 } 5025 }
5039 break; 5026 break;
5040 5027
5041 case MODE_IEEE80211B: 5028 case IEEE80211_BAND_2GHZ:
5042 case MODE_IEEE80211G:
5043 if (channel >= 1 && channel <= 14) 5029 if (channel >= 1 && channel <= 14)
5044 return &priv->channel_info[channel - 1]; 5030 return &priv->channel_info[channel - 1];
5045 break; 5031 break;
5046 5032 case IEEE80211_NUM_BANDS:
5033 WARN_ON(1);
5047 } 5034 }
5048 5035
5049 return NULL; 5036 return NULL;
@@ -5106,8 +5093,8 @@ static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
5106 /* Loop through each band adding each of the channels */ 5093 /* Loop through each band adding each of the channels */
5107 for (ch = 0; ch < eeprom_ch_count; ch++) { 5094 for (ch = 0; ch < eeprom_ch_count; ch++) {
5108 ch_info->channel = eeprom_ch_index[ch]; 5095 ch_info->channel = eeprom_ch_index[ch];
5109 ch_info->phymode = (band == 1) ? MODE_IEEE80211B : 5096 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
5110 MODE_IEEE80211A; 5097 IEEE80211_BAND_5GHZ;
5111 5098
5112 /* permanently store EEPROM's channel regulatory flags 5099 /* permanently store EEPROM's channel regulatory flags
5113 * and max power in channel info database. */ 5100 * and max power in channel info database. */
@@ -5203,18 +5190,20 @@ static void iwl3945_free_channel_map(struct iwl3945_priv *priv)
5203#define IWL_PASSIVE_DWELL_BASE (100) 5190#define IWL_PASSIVE_DWELL_BASE (100)
5204#define IWL_CHANNEL_TUNE_TIME 5 5191#define IWL_CHANNEL_TUNE_TIME 5
5205 5192
5206static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv, int phymode) 5193static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv,
5194 enum ieee80211_band band)
5207{ 5195{
5208 if (phymode == MODE_IEEE80211A) 5196 if (band == IEEE80211_BAND_5GHZ)
5209 return IWL_ACTIVE_DWELL_TIME_52; 5197 return IWL_ACTIVE_DWELL_TIME_52;
5210 else 5198 else
5211 return IWL_ACTIVE_DWELL_TIME_24; 5199 return IWL_ACTIVE_DWELL_TIME_24;
5212} 5200}
5213 5201
5214static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, int phymode) 5202static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv,
5203 enum ieee80211_band band)
5215{ 5204{
5216 u16 active = iwl3945_get_active_dwell_time(priv, phymode); 5205 u16 active = iwl3945_get_active_dwell_time(priv, band);
5217 u16 passive = (phymode != MODE_IEEE80211A) ? 5206 u16 passive = (band == IEEE80211_BAND_2GHZ) ?
5218 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : 5207 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5219 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; 5208 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5220 5209
@@ -5234,28 +5223,29 @@ static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, int phymode
5234 return passive; 5223 return passive;
5235} 5224}
5236 5225
5237static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode, 5226static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
5227 enum ieee80211_band band,
5238 u8 is_active, u8 direct_mask, 5228 u8 is_active, u8 direct_mask,
5239 struct iwl3945_scan_channel *scan_ch) 5229 struct iwl3945_scan_channel *scan_ch)
5240{ 5230{
5241 const struct ieee80211_channel *channels = NULL; 5231 const struct ieee80211_channel *channels = NULL;
5242 const struct ieee80211_hw_mode *hw_mode; 5232 const struct ieee80211_supported_band *sband;
5243 const struct iwl3945_channel_info *ch_info; 5233 const struct iwl3945_channel_info *ch_info;
5244 u16 passive_dwell = 0; 5234 u16 passive_dwell = 0;
5245 u16 active_dwell = 0; 5235 u16 active_dwell = 0;
5246 int added, i; 5236 int added, i;
5247 5237
5248 hw_mode = iwl3945_get_hw_mode(priv, phymode); 5238 sband = iwl3945_get_band(priv, band);
5249 if (!hw_mode) 5239 if (!sband)
5250 return 0; 5240 return 0;
5251 5241
5252 channels = hw_mode->channels; 5242 channels = sband->channels;
5253 5243
5254 active_dwell = iwl3945_get_active_dwell_time(priv, phymode); 5244 active_dwell = iwl3945_get_active_dwell_time(priv, band);
5255 passive_dwell = iwl3945_get_passive_dwell_time(priv, phymode); 5245 passive_dwell = iwl3945_get_passive_dwell_time(priv, band);
5256 5246
5257 for (i = 0, added = 0; i < hw_mode->num_channels; i++) { 5247 for (i = 0, added = 0; i < sband->n_channels; i++) {
5258 if (channels[i].chan == 5248 if (channels[i].hw_value ==
5259 le16_to_cpu(priv->active_rxon.channel)) { 5249 le16_to_cpu(priv->active_rxon.channel)) {
5260 if (iwl3945_is_associated(priv)) { 5250 if (iwl3945_is_associated(priv)) {
5261 IWL_DEBUG_SCAN 5251 IWL_DEBUG_SCAN
@@ -5266,9 +5256,9 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode,
5266 } else if (priv->only_active_channel) 5256 } else if (priv->only_active_channel)
5267 continue; 5257 continue;
5268 5258
5269 scan_ch->channel = channels[i].chan; 5259 scan_ch->channel = channels[i].hw_value;
5270 5260
5271 ch_info = iwl3945_get_channel_info(priv, phymode, scan_ch->channel); 5261 ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel);
5272 if (!is_channel_valid(ch_info)) { 5262 if (!is_channel_valid(ch_info)) {
5273 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", 5263 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5274 scan_ch->channel); 5264 scan_ch->channel);
@@ -5276,7 +5266,7 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode,
5276 } 5266 }
5277 5267
5278 if (!is_active || is_channel_passive(ch_info) || 5268 if (!is_active || is_channel_passive(ch_info) ||
5279 !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN)) 5269 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
5280 scan_ch->type = 0; /* passive */ 5270 scan_ch->type = 0; /* passive */
5281 else 5271 else
5282 scan_ch->type = 1; /* active */ 5272 scan_ch->type = 1; /* active */
@@ -5295,7 +5285,7 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode,
5295 /* scan_pwr_info->tpc.dsp_atten; */ 5285 /* scan_pwr_info->tpc.dsp_atten; */
5296 5286
5297 /*scan_pwr_info->tpc.tx_gain; */ 5287 /*scan_pwr_info->tpc.tx_gain; */
5298 if (phymode == MODE_IEEE80211A) 5288 if (band == IEEE80211_BAND_5GHZ)
5299 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; 5289 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5300 else { 5290 else {
5301 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); 5291 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
@@ -5319,41 +5309,23 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode,
5319 return added; 5309 return added;
5320} 5310}
5321 5311
5322static void iwl3945_reset_channel_flag(struct iwl3945_priv *priv)
5323{
5324 int i, j;
5325 for (i = 0; i < 3; i++) {
5326 struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5327 for (j = 0; j < hw_mode->num_channels; j++)
5328 hw_mode->channels[j].flag = hw_mode->channels[j].val;
5329 }
5330}
5331
5332static void iwl3945_init_hw_rates(struct iwl3945_priv *priv, 5312static void iwl3945_init_hw_rates(struct iwl3945_priv *priv,
5333 struct ieee80211_rate *rates) 5313 struct ieee80211_rate *rates)
5334{ 5314{
5335 int i; 5315 int i;
5336 5316
5337 for (i = 0; i < IWL_RATE_COUNT; i++) { 5317 for (i = 0; i < IWL_RATE_COUNT; i++) {
5338 rates[i].rate = iwl3945_rates[i].ieee * 5; 5318 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
5339 rates[i].val = i; /* Rate scaling will work on indexes */ 5319 rates[i].hw_value = i; /* Rate scaling will work on indexes */
5340 rates[i].val2 = i; 5320 rates[i].hw_value_short = i;
5341 rates[i].flags = IEEE80211_RATE_SUPPORTED; 5321 rates[i].flags = 0;
5342 /* Only OFDM have the bits-per-symbol set */ 5322 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
5343 if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5344 rates[i].flags |= IEEE80211_RATE_OFDM;
5345 else {
5346 /* 5323 /*
5347 * If CCK 1M then set rate flag to CCK else CCK_2 5324 * If CCK != 1M then set short preamble rate flag.
5348 * which is CCK | PREAMBLE2
5349 */ 5325 */
5350 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? 5326 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
5351 IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; 5327 0 : IEEE80211_RATE_SHORT_PREAMBLE;
5352 } 5328 }
5353
5354 /* Set up which ones are basic rates... */
5355 if (IWL_BASIC_RATES_MASK & (1 << i))
5356 rates[i].flags |= IEEE80211_RATE_BASIC;
5357 } 5329 }
5358} 5330}
5359 5331
@@ -5363,67 +5335,41 @@ static void iwl3945_init_hw_rates(struct iwl3945_priv *priv,
5363static int iwl3945_init_geos(struct iwl3945_priv *priv) 5335static int iwl3945_init_geos(struct iwl3945_priv *priv)
5364{ 5336{
5365 struct iwl3945_channel_info *ch; 5337 struct iwl3945_channel_info *ch;
5366 struct ieee80211_hw_mode *modes; 5338 struct ieee80211_supported_band *band;
5367 struct ieee80211_channel *channels; 5339 struct ieee80211_channel *channels;
5368 struct ieee80211_channel *geo_ch; 5340 struct ieee80211_channel *geo_ch;
5369 struct ieee80211_rate *rates; 5341 struct ieee80211_rate *rates;
5370 int i = 0; 5342 int i = 0;
5371 enum {
5372 A = 0,
5373 B = 1,
5374 G = 2,
5375 };
5376 int mode_count = 3;
5377 5343
5378 if (priv->modes) { 5344 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
5345 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
5379 IWL_DEBUG_INFO("Geography modes already initialized.\n"); 5346 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5380 set_bit(STATUS_GEO_CONFIGURED, &priv->status); 5347 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5381 return 0; 5348 return 0;
5382 } 5349 }
5383 5350
5384 modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5385 GFP_KERNEL);
5386 if (!modes)
5387 return -ENOMEM;
5388
5389 channels = kzalloc(sizeof(struct ieee80211_channel) * 5351 channels = kzalloc(sizeof(struct ieee80211_channel) *
5390 priv->channel_count, GFP_KERNEL); 5352 priv->channel_count, GFP_KERNEL);
5391 if (!channels) { 5353 if (!channels)
5392 kfree(modes);
5393 return -ENOMEM; 5354 return -ENOMEM;
5394 }
5395 5355
5396 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)), 5356 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5397 GFP_KERNEL); 5357 GFP_KERNEL);
5398 if (!rates) { 5358 if (!rates) {
5399 kfree(modes);
5400 kfree(channels); 5359 kfree(channels);
5401 return -ENOMEM; 5360 return -ENOMEM;
5402 } 5361 }
5403 5362
5404 /* 0 = 802.11a
5405 * 1 = 802.11b
5406 * 2 = 802.11g
5407 */
5408
5409 /* 5.2GHz channels start after the 2.4GHz channels */ 5363 /* 5.2GHz channels start after the 2.4GHz channels */
5410 modes[A].mode = MODE_IEEE80211A; 5364 band = &priv->bands[IEEE80211_BAND_5GHZ];
5411 modes[A].channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; 5365 band->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
5412 modes[A].rates = &rates[4]; 5366 band->bitrates = &rates[4];
5413 modes[A].num_rates = 8; /* just OFDM */ 5367 band->n_bitrates = 8; /* just OFDM */
5414 modes[A].num_channels = 0; 5368
5415 5369 band = &priv->bands[IEEE80211_BAND_2GHZ];
5416 modes[B].mode = MODE_IEEE80211B; 5370 band->channels = channels;
5417 modes[B].channels = channels; 5371 band->bitrates = rates;
5418 modes[B].rates = rates; 5372 band->n_bitrates = 12; /* OFDM & CCK */
5419 modes[B].num_rates = 4; /* just CCK */
5420 modes[B].num_channels = 0;
5421
5422 modes[G].mode = MODE_IEEE80211G;
5423 modes[G].channels = channels;
5424 modes[G].rates = rates;
5425 modes[G].num_rates = 12; /* OFDM & CCK */
5426 modes[G].num_channels = 0;
5427 5373
5428 priv->ieee_channels = channels; 5374 priv->ieee_channels = channels;
5429 priv->ieee_rates = rates; 5375 priv->ieee_rates = rates;
@@ -5442,37 +5388,32 @@ static int iwl3945_init_geos(struct iwl3945_priv *priv)
5442 } 5388 }
5443 5389
5444 if (is_channel_a_band(ch)) 5390 if (is_channel_a_band(ch))
5445 geo_ch = &modes[A].channels[modes[A].num_channels++]; 5391 geo_ch = &priv->bands[IEEE80211_BAND_5GHZ].channels[priv->bands[IEEE80211_BAND_5GHZ].n_channels++];
5446 else { 5392 else
5447 geo_ch = &modes[B].channels[modes[B].num_channels++]; 5393 geo_ch = &priv->bands[IEEE80211_BAND_2GHZ].channels[priv->bands[IEEE80211_BAND_2GHZ].n_channels++];
5448 modes[G].num_channels++;
5449 }
5450 5394
5451 geo_ch->freq = ieee80211chan2mhz(ch->channel); 5395 geo_ch->center_freq = ieee80211chan2mhz(ch->channel);
5452 geo_ch->chan = ch->channel; 5396 geo_ch->max_power = ch->max_power_avg;
5453 geo_ch->power_level = ch->max_power_avg; 5397 geo_ch->max_antenna_gain = 0xff;
5454 geo_ch->antenna_max = 0xff;
5455 5398
5456 if (is_channel_valid(ch)) { 5399 if (is_channel_valid(ch)) {
5457 geo_ch->flag = IEEE80211_CHAN_W_SCAN; 5400 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
5458 if (ch->flags & EEPROM_CHANNEL_IBSS) 5401 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
5459 geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
5460 5402
5461 if (ch->flags & EEPROM_CHANNEL_ACTIVE) 5403 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
5462 geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN; 5404 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
5463 5405
5464 if (ch->flags & EEPROM_CHANNEL_RADAR) 5406 if (ch->flags & EEPROM_CHANNEL_RADAR)
5465 geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT; 5407 geo_ch->flags |= IEEE80211_CHAN_RADAR;
5466 5408
5467 if (ch->max_power_avg > priv->max_channel_txpower_limit) 5409 if (ch->max_power_avg > priv->max_channel_txpower_limit)
5468 priv->max_channel_txpower_limit = 5410 priv->max_channel_txpower_limit =
5469 ch->max_power_avg; 5411 ch->max_power_avg;
5470 } 5412 } else
5471 5413 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
5472 geo_ch->val = geo_ch->flag;
5473 } 5414 }
5474 5415
5475 if ((modes[A].num_channels == 0) && priv->is_abg) { 5416 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && priv->is_abg) {
5476 printk(KERN_INFO DRV_NAME 5417 printk(KERN_INFO DRV_NAME
5477 ": Incorrectly detected BG card as ABG. Please send " 5418 ": Incorrectly detected BG card as ABG. Please send "
5478 "your PCI ID 0x%04X:0x%04X to maintainer.\n", 5419 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
@@ -5482,24 +5423,12 @@ static int iwl3945_init_geos(struct iwl3945_priv *priv)
5482 5423
5483 printk(KERN_INFO DRV_NAME 5424 printk(KERN_INFO DRV_NAME
5484 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", 5425 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5485 modes[G].num_channels, modes[A].num_channels); 5426 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
5427 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
5486 5428
5487 /* 5429 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ];
5488 * NOTE: We register these in preference of order -- the 5430 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ];
5489 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5490 * a phymode based on rates or AP capabilities but seems to
5491 * configure it purely on if the channel being configured
5492 * is supported by a mode -- and the first match is taken
5493 */
5494
5495 if (modes[G].num_channels)
5496 ieee80211_register_hwmode(priv->hw, &modes[G]);
5497 if (modes[B].num_channels)
5498 ieee80211_register_hwmode(priv->hw, &modes[B]);
5499 if (modes[A].num_channels)
5500 ieee80211_register_hwmode(priv->hw, &modes[A]);
5501 5431
5502 priv->modes = modes;
5503 set_bit(STATUS_GEO_CONFIGURED, &priv->status); 5432 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5504 5433
5505 return 0; 5434 return 0;
@@ -5510,7 +5439,6 @@ static int iwl3945_init_geos(struct iwl3945_priv *priv)
5510 */ 5439 */
5511static void iwl3945_free_geos(struct iwl3945_priv *priv) 5440static void iwl3945_free_geos(struct iwl3945_priv *priv)
5512{ 5441{
5513 kfree(priv->modes);
5514 kfree(priv->ieee_channels); 5442 kfree(priv->ieee_channels);
5515 kfree(priv->ieee_rates); 5443 kfree(priv->ieee_rates);
5516 clear_bit(STATUS_GEO_CONFIGURED, &priv->status); 5444 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
@@ -6519,7 +6447,7 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6519 struct iwl3945_scan_cmd *scan; 6447 struct iwl3945_scan_cmd *scan;
6520 struct ieee80211_conf *conf = NULL; 6448 struct ieee80211_conf *conf = NULL;
6521 u8 direct_mask; 6449 u8 direct_mask;
6522 int phymode; 6450 enum ieee80211_band band;
6523 6451
6524 conf = ieee80211_get_hw_conf(priv->hw); 6452 conf = ieee80211_get_hw_conf(priv->hw);
6525 6453
@@ -6651,13 +6579,13 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6651 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; 6579 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
6652 scan->tx_cmd.rate = IWL_RATE_1M_PLCP; 6580 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
6653 scan->good_CRC_th = 0; 6581 scan->good_CRC_th = 0;
6654 phymode = MODE_IEEE80211G; 6582 band = IEEE80211_BAND_2GHZ;
6655 break; 6583 break;
6656 6584
6657 case 1: 6585 case 1:
6658 scan->tx_cmd.rate = IWL_RATE_6M_PLCP; 6586 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
6659 scan->good_CRC_th = IWL_GOOD_CRC_TH; 6587 scan->good_CRC_th = IWL_GOOD_CRC_TH;
6660 phymode = MODE_IEEE80211A; 6588 band = IEEE80211_BAND_5GHZ;
6661 break; 6589 break;
6662 6590
6663 default: 6591 default:
@@ -6680,7 +6608,7 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6680 6608
6681 scan->channel_count = 6609 scan->channel_count =
6682 iwl3945_get_channels_for_scan( 6610 iwl3945_get_channels_for_scan(
6683 priv, phymode, 1, /* active */ 6611 priv, band, 1, /* active */
6684 direct_mask, 6612 direct_mask,
6685 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 6613 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6686 6614
@@ -6825,7 +6753,7 @@ static void iwl3945_bg_post_associate(struct work_struct *data)
6825 iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0); 6753 iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
6826 iwl3945_add_station(priv, priv->bssid, 0, 0); 6754 iwl3945_add_station(priv, priv->bssid, 0, 0);
6827 iwl3945_sync_sta(priv, IWL_STA_ID, 6755 iwl3945_sync_sta(priv, IWL_STA_ID,
6828 (priv->phymode == MODE_IEEE80211A)? 6756 (priv->band == IEEE80211_BAND_5GHZ) ?
6829 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, 6757 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
6830 CMD_ASYNC); 6758 CMD_ASYNC);
6831 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); 6759 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
@@ -7020,7 +6948,7 @@ static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
7020 } 6948 }
7021 6949
7022 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, 6950 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
7023 ctl->tx_rate); 6951 ctl->tx_rate->bitrate);
7024 6952
7025 if (iwl3945_tx_skb(priv, skb, ctl)) 6953 if (iwl3945_tx_skb(priv, skb, ctl))
7026 dev_kfree_skb_any(skb); 6954 dev_kfree_skb_any(skb);
@@ -7079,7 +7007,7 @@ static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
7079 int ret = 0; 7007 int ret = 0;
7080 7008
7081 mutex_lock(&priv->mutex); 7009 mutex_lock(&priv->mutex);
7082 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); 7010 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
7083 7011
7084 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); 7012 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
7085 7013
@@ -7099,19 +7027,20 @@ static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
7099 7027
7100 spin_lock_irqsave(&priv->lock, flags); 7028 spin_lock_irqsave(&priv->lock, flags);
7101 7029
7102 ch_info = iwl3945_get_channel_info(priv, conf->phymode, conf->channel); 7030 ch_info = iwl3945_get_channel_info(priv, conf->channel->band,
7031 conf->channel->hw_value);
7103 if (!is_channel_valid(ch_info)) { 7032 if (!is_channel_valid(ch_info)) {
7104 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", 7033 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7105 conf->channel, conf->phymode); 7034 conf->channel->hw_value, conf->channel->band);
7106 IWL_DEBUG_MAC80211("leave - invalid channel\n"); 7035 IWL_DEBUG_MAC80211("leave - invalid channel\n");
7107 spin_unlock_irqrestore(&priv->lock, flags); 7036 spin_unlock_irqrestore(&priv->lock, flags);
7108 ret = -EINVAL; 7037 ret = -EINVAL;
7109 goto out; 7038 goto out;
7110 } 7039 }
7111 7040
7112 iwl3945_set_rxon_channel(priv, conf->phymode, conf->channel); 7041 iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
7113 7042
7114 iwl3945_set_flags_for_phymode(priv, conf->phymode); 7043 iwl3945_set_flags_for_phymode(priv, conf->channel->band);
7115 7044
7116 /* The list of supported rates and rate mask can be different 7045 /* The list of supported rates and rate mask can be different
7117 * for each phymode; since the phymode may have changed, reset 7046 * for each phymode; since the phymode may have changed, reset
@@ -7892,65 +7821,6 @@ static ssize_t store_filter_flags(struct device *d,
7892static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, 7821static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
7893 store_filter_flags); 7822 store_filter_flags);
7894 7823
7895static ssize_t show_tune(struct device *d,
7896 struct device_attribute *attr, char *buf)
7897{
7898 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7899
7900 return sprintf(buf, "0x%04X\n",
7901 (priv->phymode << 8) |
7902 le16_to_cpu(priv->active_rxon.channel));
7903}
7904
7905static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode);
7906
7907static ssize_t store_tune(struct device *d,
7908 struct device_attribute *attr,
7909 const char *buf, size_t count)
7910{
7911 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7912 char *p = (char *)buf;
7913 u16 tune = simple_strtoul(p, &p, 0);
7914 u8 phymode = (tune >> 8) & 0xff;
7915 u16 channel = tune & 0xff;
7916
7917 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
7918
7919 mutex_lock(&priv->mutex);
7920 if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
7921 (priv->phymode != phymode)) {
7922 const struct iwl3945_channel_info *ch_info;
7923
7924 ch_info = iwl3945_get_channel_info(priv, phymode, channel);
7925 if (!ch_info) {
7926 IWL_WARNING("Requested invalid phymode/channel "
7927 "combination: %d %d\n", phymode, channel);
7928 mutex_unlock(&priv->mutex);
7929 return -EINVAL;
7930 }
7931
7932 /* Cancel any currently running scans... */
7933 if (iwl3945_scan_cancel_timeout(priv, 100))
7934 IWL_WARNING("Could not cancel scan.\n");
7935 else {
7936 IWL_DEBUG_INFO("Committing phymode and "
7937 "rxon.channel = %d %d\n",
7938 phymode, channel);
7939
7940 iwl3945_set_rxon_channel(priv, phymode, channel);
7941 iwl3945_set_flags_for_phymode(priv, phymode);
7942
7943 iwl3945_set_rate(priv);
7944 iwl3945_commit_rxon(priv);
7945 }
7946 }
7947 mutex_unlock(&priv->mutex);
7948
7949 return count;
7950}
7951
7952static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
7953
7954#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT 7824#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7955 7825
7956static ssize_t show_measurement(struct device *d, 7826static ssize_t show_measurement(struct device *d,
@@ -8165,73 +8035,8 @@ static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8165static ssize_t show_channels(struct device *d, 8035static ssize_t show_channels(struct device *d,
8166 struct device_attribute *attr, char *buf) 8036 struct device_attribute *attr, char *buf)
8167{ 8037{
8168 struct iwl3945_priv *priv = dev_get_drvdata(d); 8038 /* all this shit doesn't belong into sysfs anyway */
8169 int len = 0, i; 8039 return 0;
8170 struct ieee80211_channel *channels = NULL;
8171 const struct ieee80211_hw_mode *hw_mode = NULL;
8172 int count = 0;
8173
8174 if (!iwl3945_is_ready(priv))
8175 return -EAGAIN;
8176
8177 hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211G);
8178 if (!hw_mode)
8179 hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211B);
8180 if (hw_mode) {
8181 channels = hw_mode->channels;
8182 count = hw_mode->num_channels;
8183 }
8184
8185 len +=
8186 sprintf(&buf[len],
8187 "Displaying %d channels in 2.4GHz band "
8188 "(802.11bg):\n", count);
8189
8190 for (i = 0; i < count; i++)
8191 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8192 channels[i].chan,
8193 channels[i].power_level,
8194 channels[i].
8195 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8196 " (IEEE 802.11h required)" : "",
8197 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8198 || (channels[i].
8199 flag &
8200 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8201 ", IBSS",
8202 channels[i].
8203 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8204 "active/passive" : "passive only");
8205
8206 hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211A);
8207 if (hw_mode) {
8208 channels = hw_mode->channels;
8209 count = hw_mode->num_channels;
8210 } else {
8211 channels = NULL;
8212 count = 0;
8213 }
8214
8215 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8216 "(802.11a):\n", count);
8217
8218 for (i = 0; i < count; i++)
8219 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8220 channels[i].chan,
8221 channels[i].power_level,
8222 channels[i].
8223 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8224 " (IEEE 802.11h required)" : "",
8225 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8226 || (channels[i].
8227 flag &
8228 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8229 ", IBSS",
8230 channels[i].
8231 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8232 "active/passive" : "passive only");
8233
8234 return len;
8235} 8040}
8236 8041
8237static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); 8042static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
@@ -8411,7 +8216,6 @@ static struct attribute *iwl3945_sysfs_entries[] = {
8411 &dev_attr_statistics.attr, 8216 &dev_attr_statistics.attr,
8412 &dev_attr_status.attr, 8217 &dev_attr_status.attr,
8413 &dev_attr_temperature.attr, 8218 &dev_attr_temperature.attr,
8414 &dev_attr_tune.attr,
8415 &dev_attr_tx_power.attr, 8219 &dev_attr_tx_power.attr,
8416 8220
8417 NULL 8221 NULL
@@ -8532,7 +8336,7 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8532 priv->data_retry_limit = -1; 8336 priv->data_retry_limit = -1;
8533 priv->ieee_channels = NULL; 8337 priv->ieee_channels = NULL;
8534 priv->ieee_rates = NULL; 8338 priv->ieee_rates = NULL;
8535 priv->phymode = -1; 8339 priv->band = IEEE80211_BAND_2GHZ;
8536 8340
8537 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 8341 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
8538 if (!err) 8342 if (!err)
@@ -8614,7 +8418,7 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8614 priv->qos_data.qos_cap.val = 0; 8418 priv->qos_data.qos_cap.val = 0;
8615#endif /* CONFIG_IWL3945_QOS */ 8419#endif /* CONFIG_IWL3945_QOS */
8616 8420
8617 iwl3945_set_rxon_channel(priv, MODE_IEEE80211G, 6); 8421 iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
8618 iwl3945_setup_deferred_work(priv); 8422 iwl3945_setup_deferred_work(priv);
8619 iwl3945_setup_rx_handlers(priv); 8423 iwl3945_setup_rx_handlers(priv);
8620 8424
@@ -8665,7 +8469,6 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8665 IWL_ERROR("initializing geos failed: %d\n", err); 8469 IWL_ERROR("initializing geos failed: %d\n", err);
8666 goto out_free_channel_map; 8470 goto out_free_channel_map;
8667 } 8471 }
8668 iwl3945_reset_channel_flag(priv);
8669 8472
8670 iwl3945_rate_control_register(priv->hw); 8473 iwl3945_rate_control_register(priv->hw);
8671 err = ieee80211_register_hw(priv->hw); 8474 err = ieee80211_register_hw(priv->hw);
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index 5f38fc585eda..6de969de4c84 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -115,16 +115,10 @@ __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
115 return NULL; 115 return NULL;
116} 116}
117 117
118static const struct ieee80211_hw_mode *iwl4965_get_hw_mode( 118static const struct ieee80211_supported_band *iwl4965_get_hw_mode(
119 struct iwl4965_priv *priv, int mode) 119 struct iwl4965_priv *priv, enum ieee80211_band band)
120{ 120{
121 int i; 121 return priv->hw->wiphy->bands[band];
122
123 for (i = 0; i < 3; i++)
124 if (priv->modes[i].mode == mode)
125 return &priv->modes[i];
126
127 return NULL;
128} 122}
129 123
130static int iwl4965_is_empty_essid(const char *essid, int essid_len) 124static int iwl4965_is_empty_essid(const char *essid, int essid_len)
@@ -937,28 +931,29 @@ static int iwl4965_rxon_add_station(struct iwl4965_priv *priv,
937 * NOTE: Does not commit to the hardware; it sets appropriate bit fields 931 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
938 * in the staging RXON flag structure based on the phymode 932 * in the staging RXON flag structure based on the phymode
939 */ 933 */
940static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode, 934static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv,
935 enum ieee80211_band band,
941 u16 channel) 936 u16 channel)
942{ 937{
943 if (!iwl4965_get_channel_info(priv, phymode, channel)) { 938 if (!iwl4965_get_channel_info(priv, band, channel)) {
944 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", 939 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
945 channel, phymode); 940 channel, band);
946 return -EINVAL; 941 return -EINVAL;
947 } 942 }
948 943
949 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && 944 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
950 (priv->phymode == phymode)) 945 (priv->band == band))
951 return 0; 946 return 0;
952 947
953 priv->staging_rxon.channel = cpu_to_le16(channel); 948 priv->staging_rxon.channel = cpu_to_le16(channel);
954 if (phymode == MODE_IEEE80211A) 949 if (band == IEEE80211_BAND_5GHZ)
955 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; 950 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
956 else 951 else
957 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; 952 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
958 953
959 priv->phymode = phymode; 954 priv->band = band;
960 955
961 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode); 956 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
962 957
963 return 0; 958 return 0;
964} 959}
@@ -2571,9 +2566,10 @@ static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt)
2571 return 0; 2566 return 0;
2572} 2567}
2573 2568
2574static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode) 2569static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv,
2570 enum ieee80211_band band)
2575{ 2571{
2576 if (phymode == MODE_IEEE80211A) { 2572 if (band == IEEE80211_BAND_5GHZ) {
2577 priv->staging_rxon.flags &= 2573 priv->staging_rxon.flags &=
2578 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK 2574 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2579 | RXON_FLG_CCK_MSK); 2575 | RXON_FLG_CCK_MSK);
@@ -2636,7 +2632,7 @@ static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
2636 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; 2632 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2637#endif 2633#endif
2638 2634
2639 ch_info = iwl4965_get_channel_info(priv, priv->phymode, 2635 ch_info = iwl4965_get_channel_info(priv, priv->band,
2640 le16_to_cpu(priv->staging_rxon.channel)); 2636 le16_to_cpu(priv->staging_rxon.channel));
2641 2637
2642 if (!ch_info) 2638 if (!ch_info)
@@ -2651,12 +2647,9 @@ static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
2651 ch_info = &priv->channel_info[0]; 2647 ch_info = &priv->channel_info[0];
2652 2648
2653 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); 2649 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2654 if (is_channel_a_band(ch_info)) 2650 priv->band = ch_info->band;
2655 priv->phymode = MODE_IEEE80211A;
2656 else
2657 priv->phymode = MODE_IEEE80211G;
2658 2651
2659 iwl4965_set_flags_for_phymode(priv, priv->phymode); 2652 iwl4965_set_flags_for_phymode(priv, priv->band);
2660 2653
2661 priv->staging_rxon.ofdm_basic_rates = 2654 priv->staging_rxon.ofdm_basic_rates =
2662 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 2655 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
@@ -2678,7 +2671,7 @@ static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode)
2678 const struct iwl4965_channel_info *ch_info; 2671 const struct iwl4965_channel_info *ch_info;
2679 2672
2680 ch_info = iwl4965_get_channel_info(priv, 2673 ch_info = iwl4965_get_channel_info(priv,
2681 priv->phymode, 2674 priv->band,
2682 le16_to_cpu(priv->staging_rxon.channel)); 2675 le16_to_cpu(priv->staging_rxon.channel));
2683 2676
2684 if (!ch_info || !is_channel_ibss(ch_info)) { 2677 if (!ch_info || !is_channel_ibss(ch_info)) {
@@ -2918,7 +2911,7 @@ static int iwl4965_tx_skb(struct iwl4965_priv *priv,
2918 goto drop_unlock; 2911 goto drop_unlock;
2919 } 2912 }
2920 2913
2921 if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) { 2914 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
2922 IWL_ERROR("ERROR: No TX rate available.\n"); 2915 IWL_ERROR("ERROR: No TX rate available.\n");
2923 goto drop_unlock; 2916 goto drop_unlock;
2924 } 2917 }
@@ -3125,11 +3118,11 @@ drop:
3125 3118
3126static void iwl4965_set_rate(struct iwl4965_priv *priv) 3119static void iwl4965_set_rate(struct iwl4965_priv *priv)
3127{ 3120{
3128 const struct ieee80211_hw_mode *hw = NULL; 3121 const struct ieee80211_supported_band *hw = NULL;
3129 struct ieee80211_rate *rate; 3122 struct ieee80211_rate *rate;
3130 int i; 3123 int i;
3131 3124
3132 hw = iwl4965_get_hw_mode(priv, priv->phymode); 3125 hw = iwl4965_get_hw_mode(priv, priv->band);
3133 if (!hw) { 3126 if (!hw) {
3134 IWL_ERROR("Failed to set rate: unable to get hw mode\n"); 3127 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3135 return; 3128 return;
@@ -3138,24 +3131,10 @@ static void iwl4965_set_rate(struct iwl4965_priv *priv)
3138 priv->active_rate = 0; 3131 priv->active_rate = 0;
3139 priv->active_rate_basic = 0; 3132 priv->active_rate_basic = 0;
3140 3133
3141 IWL_DEBUG_RATE("Setting rates for 802.11%c\n", 3134 for (i = 0; i < hw->n_bitrates; i++) {
3142 hw->mode == MODE_IEEE80211A ? 3135 rate = &(hw->bitrates[i]);
3143 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g')); 3136 if (rate->hw_value < IWL_RATE_COUNT)
3144 3137 priv->active_rate |= (1 << rate->hw_value);
3145 for (i = 0; i < hw->num_rates; i++) {
3146 rate = &(hw->rates[i]);
3147 if ((rate->val < IWL_RATE_COUNT) &&
3148 (rate->flags & IEEE80211_RATE_SUPPORTED)) {
3149 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
3150 rate->val, iwl4965_rates[rate->val].plcp,
3151 (rate->flags & IEEE80211_RATE_BASIC) ?
3152 "*" : "");
3153 priv->active_rate |= (1 << rate->val);
3154 if (rate->flags & IEEE80211_RATE_BASIC)
3155 priv->active_rate_basic |= (1 << rate->val);
3156 } else
3157 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
3158 rate->val, iwl4965_rates[rate->val].plcp);
3159 } 3138 }
3160 3139
3161 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", 3140 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
@@ -3775,9 +3754,6 @@ static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
3775 tx_status->flags = 3754 tx_status->flags =
3776 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; 3755 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3777 3756
3778 tx_status->control.tx_rate =
3779 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
3780
3781 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x " 3757 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3782 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), 3758 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
3783 status, le32_to_cpu(tx_resp->rate_n_flags), 3759 status, le32_to_cpu(tx_resp->rate_n_flags),
@@ -5419,24 +5395,23 @@ static void iwl4965_init_band_reference(const struct iwl4965_priv *priv,
5419 * Based on band and channel number. 5395 * Based on band and channel number.
5420 */ 5396 */
5421const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv, 5397const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv,
5422 int phymode, u16 channel) 5398 enum ieee80211_band band, u16 channel)
5423{ 5399{
5424 int i; 5400 int i;
5425 5401
5426 switch (phymode) { 5402 switch (band) {
5427 case MODE_IEEE80211A: 5403 case IEEE80211_BAND_5GHZ:
5428 for (i = 14; i < priv->channel_count; i++) { 5404 for (i = 14; i < priv->channel_count; i++) {
5429 if (priv->channel_info[i].channel == channel) 5405 if (priv->channel_info[i].channel == channel)
5430 return &priv->channel_info[i]; 5406 return &priv->channel_info[i];
5431 } 5407 }
5432 break; 5408 break;
5433 5409 case IEEE80211_BAND_2GHZ:
5434 case MODE_IEEE80211B:
5435 case MODE_IEEE80211G:
5436 if (channel >= 1 && channel <= 14) 5410 if (channel >= 1 && channel <= 14)
5437 return &priv->channel_info[channel - 1]; 5411 return &priv->channel_info[channel - 1];
5438 break; 5412 break;
5439 5413 default:
5414 BUG();
5440 } 5415 }
5441 5416
5442 return NULL; 5417 return NULL;
@@ -5499,8 +5474,8 @@ static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
5499 /* Loop through each band adding each of the channels */ 5474 /* Loop through each band adding each of the channels */
5500 for (ch = 0; ch < eeprom_ch_count; ch++) { 5475 for (ch = 0; ch < eeprom_ch_count; ch++) {
5501 ch_info->channel = eeprom_ch_index[ch]; 5476 ch_info->channel = eeprom_ch_index[ch];
5502 ch_info->phymode = (band == 1) ? MODE_IEEE80211B : 5477 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
5503 MODE_IEEE80211A; 5478 IEEE80211_BAND_5GHZ;
5504 5479
5505 /* permanently store EEPROM's channel regulatory flags 5480 /* permanently store EEPROM's channel regulatory flags
5506 * and max power in channel info database. */ 5481 * and max power in channel info database. */
@@ -5559,14 +5534,14 @@ static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
5559 5534
5560 /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */ 5535 /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */
5561 for (band = 6; band <= 7; band++) { 5536 for (band = 6; band <= 7; band++) {
5562 int phymode; 5537 enum ieee80211_band ieeeband;
5563 u8 fat_extension_chan; 5538 u8 fat_extension_chan;
5564 5539
5565 iwl4965_init_band_reference(priv, band, &eeprom_ch_count, 5540 iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
5566 &eeprom_ch_info, &eeprom_ch_index); 5541 &eeprom_ch_info, &eeprom_ch_index);
5567 5542
5568 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ 5543 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
5569 phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A; 5544 ieeeband = (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
5570 5545
5571 /* Loop through each band adding each of the channels */ 5546 /* Loop through each band adding each of the channels */
5572 for (ch = 0; ch < eeprom_ch_count; ch++) { 5547 for (ch = 0; ch < eeprom_ch_count; ch++) {
@@ -5580,13 +5555,13 @@ static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
5580 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; 5555 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
5581 5556
5582 /* Set up driver's info for lower half */ 5557 /* Set up driver's info for lower half */
5583 iwl4965_set_fat_chan_info(priv, phymode, 5558 iwl4965_set_fat_chan_info(priv, ieeeband,
5584 eeprom_ch_index[ch], 5559 eeprom_ch_index[ch],
5585 &(eeprom_ch_info[ch]), 5560 &(eeprom_ch_info[ch]),
5586 fat_extension_chan); 5561 fat_extension_chan);
5587 5562
5588 /* Set up driver's info for upper half */ 5563 /* Set up driver's info for upper half */
5589 iwl4965_set_fat_chan_info(priv, phymode, 5564 iwl4965_set_fat_chan_info(priv, ieeeband,
5590 (eeprom_ch_index[ch] + 4), 5565 (eeprom_ch_index[ch] + 4),
5591 &(eeprom_ch_info[ch]), 5566 &(eeprom_ch_info[ch]),
5592 HT_IE_EXT_CHANNEL_BELOW); 5567 HT_IE_EXT_CHANNEL_BELOW);
@@ -5628,18 +5603,20 @@ static void iwl4965_free_channel_map(struct iwl4965_priv *priv)
5628#define IWL_PASSIVE_DWELL_BASE (100) 5603#define IWL_PASSIVE_DWELL_BASE (100)
5629#define IWL_CHANNEL_TUNE_TIME 5 5604#define IWL_CHANNEL_TUNE_TIME 5
5630 5605
5631static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, int phymode) 5606static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv,
5607 enum ieee80211_band band)
5632{ 5608{
5633 if (phymode == MODE_IEEE80211A) 5609 if (band == IEEE80211_BAND_5GHZ)
5634 return IWL_ACTIVE_DWELL_TIME_52; 5610 return IWL_ACTIVE_DWELL_TIME_52;
5635 else 5611 else
5636 return IWL_ACTIVE_DWELL_TIME_24; 5612 return IWL_ACTIVE_DWELL_TIME_24;
5637} 5613}
5638 5614
5639static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode) 5615static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv,
5616 enum ieee80211_band band)
5640{ 5617{
5641 u16 active = iwl4965_get_active_dwell_time(priv, phymode); 5618 u16 active = iwl4965_get_active_dwell_time(priv, band);
5642 u16 passive = (phymode != MODE_IEEE80211A) ? 5619 u16 passive = (band != IEEE80211_BAND_5GHZ) ?
5643 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : 5620 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5644 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; 5621 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5645 5622
@@ -5659,28 +5636,29 @@ static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode
5659 return passive; 5636 return passive;
5660} 5637}
5661 5638
5662static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode, 5639static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv,
5640 enum ieee80211_band band,
5663 u8 is_active, u8 direct_mask, 5641 u8 is_active, u8 direct_mask,
5664 struct iwl4965_scan_channel *scan_ch) 5642 struct iwl4965_scan_channel *scan_ch)
5665{ 5643{
5666 const struct ieee80211_channel *channels = NULL; 5644 const struct ieee80211_channel *channels = NULL;
5667 const struct ieee80211_hw_mode *hw_mode; 5645 const struct ieee80211_supported_band *sband;
5668 const struct iwl4965_channel_info *ch_info; 5646 const struct iwl4965_channel_info *ch_info;
5669 u16 passive_dwell = 0; 5647 u16 passive_dwell = 0;
5670 u16 active_dwell = 0; 5648 u16 active_dwell = 0;
5671 int added, i; 5649 int added, i;
5672 5650
5673 hw_mode = iwl4965_get_hw_mode(priv, phymode); 5651 sband = iwl4965_get_hw_mode(priv, band);
5674 if (!hw_mode) 5652 if (!sband)
5675 return 0; 5653 return 0;
5676 5654
5677 channels = hw_mode->channels; 5655 channels = sband->channels;
5678 5656
5679 active_dwell = iwl4965_get_active_dwell_time(priv, phymode); 5657 active_dwell = iwl4965_get_active_dwell_time(priv, band);
5680 passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode); 5658 passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
5681 5659
5682 for (i = 0, added = 0; i < hw_mode->num_channels; i++) { 5660 for (i = 0, added = 0; i < sband->n_channels; i++) {
5683 if (channels[i].chan == 5661 if (ieee80211_frequency_to_channel(channels[i].center_freq) ==
5684 le16_to_cpu(priv->active_rxon.channel)) { 5662 le16_to_cpu(priv->active_rxon.channel)) {
5685 if (iwl4965_is_associated(priv)) { 5663 if (iwl4965_is_associated(priv)) {
5686 IWL_DEBUG_SCAN 5664 IWL_DEBUG_SCAN
@@ -5691,9 +5669,9 @@ static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
5691 } else if (priv->only_active_channel) 5669 } else if (priv->only_active_channel)
5692 continue; 5670 continue;
5693 5671
5694 scan_ch->channel = channels[i].chan; 5672 scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
5695 5673
5696 ch_info = iwl4965_get_channel_info(priv, phymode, 5674 ch_info = iwl4965_get_channel_info(priv, band,
5697 scan_ch->channel); 5675 scan_ch->channel);
5698 if (!is_channel_valid(ch_info)) { 5676 if (!is_channel_valid(ch_info)) {
5699 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", 5677 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
@@ -5702,7 +5680,7 @@ static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
5702 } 5680 }
5703 5681
5704 if (!is_active || is_channel_passive(ch_info) || 5682 if (!is_active || is_channel_passive(ch_info) ||
5705 !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN)) 5683 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
5706 scan_ch->type = 0; /* passive */ 5684 scan_ch->type = 0; /* passive */
5707 else 5685 else
5708 scan_ch->type = 1; /* active */ 5686 scan_ch->type = 1; /* active */
@@ -5721,7 +5699,7 @@ static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
5721 /* scan_pwr_info->tpc.dsp_atten; */ 5699 /* scan_pwr_info->tpc.dsp_atten; */
5722 5700
5723 /*scan_pwr_info->tpc.tx_gain; */ 5701 /*scan_pwr_info->tpc.tx_gain; */
5724 if (phymode == MODE_IEEE80211A) 5702 if (band == IEEE80211_BAND_5GHZ)
5725 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; 5703 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5726 else { 5704 else {
5727 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); 5705 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
@@ -5745,41 +5723,23 @@ static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
5745 return added; 5723 return added;
5746} 5724}
5747 5725
5748static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv)
5749{
5750 int i, j;
5751 for (i = 0; i < 3; i++) {
5752 struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5753 for (j = 0; j < hw_mode->num_channels; j++)
5754 hw_mode->channels[j].flag = hw_mode->channels[j].val;
5755 }
5756}
5757
5758static void iwl4965_init_hw_rates(struct iwl4965_priv *priv, 5726static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
5759 struct ieee80211_rate *rates) 5727 struct ieee80211_rate *rates)
5760{ 5728{
5761 int i; 5729 int i;
5762 5730
5763 for (i = 0; i < IWL_RATE_COUNT; i++) { 5731 for (i = 0; i < IWL_RATE_COUNT; i++) {
5764 rates[i].rate = iwl4965_rates[i].ieee * 5; 5732 rates[i].bitrate = iwl4965_rates[i].ieee * 5;
5765 rates[i].val = i; /* Rate scaling will work on indexes */ 5733 rates[i].hw_value = i; /* Rate scaling will work on indexes */
5766 rates[i].val2 = i; 5734 rates[i].hw_value_short = i;
5767 rates[i].flags = IEEE80211_RATE_SUPPORTED; 5735 rates[i].flags = 0;
5768 /* Only OFDM have the bits-per-symbol set */ 5736 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
5769 if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5770 rates[i].flags |= IEEE80211_RATE_OFDM;
5771 else {
5772 /* 5737 /*
5773 * If CCK 1M then set rate flag to CCK else CCK_2 5738 * If CCK != 1M then set short preamble rate flag.
5774 * which is CCK | PREAMBLE2
5775 */ 5739 */
5776 rates[i].flags |= (iwl4965_rates[i].plcp == 10) ? 5740 rates[i].flags |= (iwl4965_rates[i].plcp == 10) ?
5777 IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; 5741 0 : IEEE80211_RATE_SHORT_PREAMBLE;
5778 } 5742 }
5779
5780 /* Set up which ones are basic rates... */
5781 if (IWL_BASIC_RATES_MASK & (1 << i))
5782 rates[i].flags |= IEEE80211_RATE_BASIC;
5783 } 5743 }
5784} 5744}
5785 5745
@@ -5789,74 +5749,47 @@ static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
5789static int iwl4965_init_geos(struct iwl4965_priv *priv) 5749static int iwl4965_init_geos(struct iwl4965_priv *priv)
5790{ 5750{
5791 struct iwl4965_channel_info *ch; 5751 struct iwl4965_channel_info *ch;
5792 struct ieee80211_hw_mode *modes; 5752 struct ieee80211_supported_band *band;
5793 struct ieee80211_channel *channels; 5753 struct ieee80211_channel *channels;
5794 struct ieee80211_channel *geo_ch; 5754 struct ieee80211_channel *geo_ch;
5795 struct ieee80211_rate *rates; 5755 struct ieee80211_rate *rates;
5796 int i = 0; 5756 int i = 0;
5797 enum {
5798 A = 0,
5799 B = 1,
5800 G = 2,
5801 };
5802 int mode_count = 3;
5803 5757
5804 if (priv->modes) { 5758 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
5759 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
5805 IWL_DEBUG_INFO("Geography modes already initialized.\n"); 5760 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5806 set_bit(STATUS_GEO_CONFIGURED, &priv->status); 5761 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5807 return 0; 5762 return 0;
5808 } 5763 }
5809 5764
5810 modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5811 GFP_KERNEL);
5812 if (!modes)
5813 return -ENOMEM;
5814
5815 channels = kzalloc(sizeof(struct ieee80211_channel) * 5765 channels = kzalloc(sizeof(struct ieee80211_channel) *
5816 priv->channel_count, GFP_KERNEL); 5766 priv->channel_count, GFP_KERNEL);
5817 if (!channels) { 5767 if (!channels)
5818 kfree(modes);
5819 return -ENOMEM; 5768 return -ENOMEM;
5820 }
5821 5769
5822 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)), 5770 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5823 GFP_KERNEL); 5771 GFP_KERNEL);
5824 if (!rates) { 5772 if (!rates) {
5825 kfree(modes);
5826 kfree(channels); 5773 kfree(channels);
5827 return -ENOMEM; 5774 return -ENOMEM;
5828 } 5775 }
5829 5776
5830 /* 0 = 802.11a
5831 * 1 = 802.11b
5832 * 2 = 802.11g
5833 */
5834
5835 /* 5.2GHz channels start after the 2.4GHz channels */ 5777 /* 5.2GHz channels start after the 2.4GHz channels */
5836 modes[A].mode = MODE_IEEE80211A;
5837 modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
5838 modes[A].rates = rates;
5839 modes[A].num_rates = 8; /* just OFDM */
5840 modes[A].rates = &rates[4];
5841 modes[A].num_channels = 0;
5842#ifdef CONFIG_IWL4965_HT 5778#ifdef CONFIG_IWL4965_HT
5843 iwl4965_init_ht_hw_capab(&modes[A].ht_info, MODE_IEEE80211A); 5779 iwl4965_init_ht_hw_capab(&modes[A].ht_info, MODE_IEEE80211A);
5844#endif 5780#endif
5845
5846 modes[B].mode = MODE_IEEE80211B;
5847 modes[B].channels = channels;
5848 modes[B].rates = rates;
5849 modes[B].num_rates = 4; /* just CCK */
5850 modes[B].num_channels = 0;
5851
5852 modes[G].mode = MODE_IEEE80211G;
5853 modes[G].channels = channels;
5854 modes[G].rates = rates;
5855 modes[G].num_rates = 12; /* OFDM & CCK */
5856 modes[G].num_channels = 0;
5857#ifdef CONFIG_IWL4965_HT 5781#ifdef CONFIG_IWL4965_HT
5858 iwl4965_init_ht_hw_capab(&modes[G].ht_info, MODE_IEEE80211G); 5782 iwl4965_init_ht_hw_capab(&modes[G].ht_info, MODE_IEEE80211G);
5859#endif 5783#endif
5784 band = &priv->bands[IEEE80211_BAND_5GHZ];
5785 band->channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
5786 band->bitrates = &rates[4];
5787 band->n_bitrates = 8; /* just OFDM */
5788
5789 band = &priv->bands[IEEE80211_BAND_2GHZ];
5790 band->channels = channels;
5791 band->bitrates = rates;
5792 band->n_bitrates = 12; /* OFDM & CCK */
5860 5793
5861 priv->ieee_channels = channels; 5794 priv->ieee_channels = channels;
5862 priv->ieee_rates = rates; 5795 priv->ieee_rates = rates;
@@ -5875,37 +5808,32 @@ static int iwl4965_init_geos(struct iwl4965_priv *priv)
5875 } 5808 }
5876 5809
5877 if (is_channel_a_band(ch)) { 5810 if (is_channel_a_band(ch)) {
5878 geo_ch = &modes[A].channels[modes[A].num_channels++]; 5811 geo_ch = &priv->bands[IEEE80211_BAND_5GHZ].channels[priv->bands[IEEE80211_BAND_5GHZ].n_channels++];
5879 } else { 5812 } else
5880 geo_ch = &modes[B].channels[modes[B].num_channels++]; 5813 geo_ch = &priv->bands[IEEE80211_BAND_2GHZ].channels[priv->bands[IEEE80211_BAND_2GHZ].n_channels++];
5881 modes[G].num_channels++;
5882 }
5883 5814
5884 geo_ch->freq = ieee80211chan2mhz(ch->channel); 5815 geo_ch->center_freq = ieee80211chan2mhz(ch->channel);
5885 geo_ch->chan = ch->channel; 5816 geo_ch->max_power = ch->max_power_avg;
5886 geo_ch->power_level = ch->max_power_avg; 5817 geo_ch->max_antenna_gain = 0xff;
5887 geo_ch->antenna_max = 0xff;
5888 5818
5889 if (is_channel_valid(ch)) { 5819 if (is_channel_valid(ch)) {
5890 geo_ch->flag = IEEE80211_CHAN_W_SCAN; 5820 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
5891 if (ch->flags & EEPROM_CHANNEL_IBSS) 5821 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
5892 geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
5893 5822
5894 if (ch->flags & EEPROM_CHANNEL_ACTIVE) 5823 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
5895 geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN; 5824 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
5896 5825
5897 if (ch->flags & EEPROM_CHANNEL_RADAR) 5826 if (ch->flags & EEPROM_CHANNEL_RADAR)
5898 geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT; 5827 geo_ch->flags |= IEEE80211_CHAN_RADAR;
5899 5828
5900 if (ch->max_power_avg > priv->max_channel_txpower_limit) 5829 if (ch->max_power_avg > priv->max_channel_txpower_limit)
5901 priv->max_channel_txpower_limit = 5830 priv->max_channel_txpower_limit =
5902 ch->max_power_avg; 5831 ch->max_power_avg;
5903 } 5832 } else
5904 5833 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
5905 geo_ch->val = geo_ch->flag;
5906 } 5834 }
5907 5835
5908 if ((modes[A].num_channels == 0) && priv->is_abg) { 5836 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && priv->is_abg) {
5909 printk(KERN_INFO DRV_NAME 5837 printk(KERN_INFO DRV_NAME
5910 ": Incorrectly detected BG card as ABG. Please send " 5838 ": Incorrectly detected BG card as ABG. Please send "
5911 "your PCI ID 0x%04X:0x%04X to maintainer.\n", 5839 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
@@ -5915,24 +5843,12 @@ static int iwl4965_init_geos(struct iwl4965_priv *priv)
5915 5843
5916 printk(KERN_INFO DRV_NAME 5844 printk(KERN_INFO DRV_NAME
5917 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", 5845 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5918 modes[G].num_channels, modes[A].num_channels); 5846 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
5919 5847 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
5920 /*
5921 * NOTE: We register these in preference of order -- the
5922 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5923 * a phymode based on rates or AP capabilities but seems to
5924 * configure it purely on if the channel being configured
5925 * is supported by a mode -- and the first match is taken
5926 */
5927 5848
5928 if (modes[G].num_channels) 5849 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ];
5929 ieee80211_register_hwmode(priv->hw, &modes[G]); 5850 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ];
5930 if (modes[B].num_channels)
5931 ieee80211_register_hwmode(priv->hw, &modes[B]);
5932 if (modes[A].num_channels)
5933 ieee80211_register_hwmode(priv->hw, &modes[A]);
5934 5851
5935 priv->modes = modes;
5936 set_bit(STATUS_GEO_CONFIGURED, &priv->status); 5852 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5937 5853
5938 return 0; 5854 return 0;
@@ -5943,7 +5859,6 @@ static int iwl4965_init_geos(struct iwl4965_priv *priv)
5943 */ 5859 */
5944static void iwl4965_free_geos(struct iwl4965_priv *priv) 5860static void iwl4965_free_geos(struct iwl4965_priv *priv)
5945{ 5861{
5946 kfree(priv->modes);
5947 kfree(priv->ieee_channels); 5862 kfree(priv->ieee_channels);
5948 kfree(priv->ieee_rates); 5863 kfree(priv->ieee_rates);
5949 clear_bit(STATUS_GEO_CONFIGURED, &priv->status); 5864 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
@@ -6945,7 +6860,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
6945 struct iwl4965_scan_cmd *scan; 6860 struct iwl4965_scan_cmd *scan;
6946 struct ieee80211_conf *conf = NULL; 6861 struct ieee80211_conf *conf = NULL;
6947 u8 direct_mask; 6862 u8 direct_mask;
6948 int phymode; 6863 enum ieee80211_band band;
6949 6864
6950 conf = ieee80211_get_hw_conf(priv->hw); 6865 conf = ieee80211_get_hw_conf(priv->hw);
6951 6866
@@ -7075,7 +6990,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
7075 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); 6990 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
7076 6991
7077 scan->good_CRC_th = 0; 6992 scan->good_CRC_th = 0;
7078 phymode = MODE_IEEE80211G; 6993 band = IEEE80211_BAND_2GHZ;
7079 break; 6994 break;
7080 6995
7081 case 1: 6996 case 1:
@@ -7083,7 +6998,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
7083 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, 6998 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
7084 RATE_MCS_ANT_B_MSK); 6999 RATE_MCS_ANT_B_MSK);
7085 scan->good_CRC_th = IWL_GOOD_CRC_TH; 7000 scan->good_CRC_th = IWL_GOOD_CRC_TH;
7086 phymode = MODE_IEEE80211A; 7001 band = IEEE80211_BAND_5GHZ;
7087 break; 7002 break;
7088 7003
7089 default: 7004 default:
@@ -7113,7 +7028,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
7113 7028
7114 scan->channel_count = 7029 scan->channel_count =
7115 iwl4965_get_channels_for_scan( 7030 iwl4965_get_channels_for_scan(
7116 priv, phymode, 1, /* active */ 7031 priv, band, 1, /* active */
7117 direct_mask, 7032 direct_mask,
7118 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 7033 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
7119 7034
@@ -7463,7 +7378,7 @@ static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
7463 } 7378 }
7464 7379
7465 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, 7380 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
7466 ctl->tx_rate); 7381 ctl->tx_rate->bitrate);
7467 7382
7468 if (iwl4965_tx_skb(priv, skb, ctl)) 7383 if (iwl4965_tx_skb(priv, skb, ctl))
7469 dev_kfree_skb_any(skb); 7384 dev_kfree_skb_any(skb);
@@ -7522,7 +7437,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
7522 int ret = 0; 7437 int ret = 0;
7523 7438
7524 mutex_lock(&priv->mutex); 7439 mutex_lock(&priv->mutex);
7525 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); 7440 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
7526 7441
7527 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); 7442 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
7528 7443
@@ -7542,10 +7457,9 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
7542 7457
7543 spin_lock_irqsave(&priv->lock, flags); 7458 spin_lock_irqsave(&priv->lock, flags);
7544 7459
7545 ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel); 7460 ch_info = iwl4965_get_channel_info(priv, conf->channel->band,
7461 ieee80211_frequency_to_channel(conf->channel->center_freq));
7546 if (!is_channel_valid(ch_info)) { 7462 if (!is_channel_valid(ch_info)) {
7547 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7548 conf->channel, conf->phymode);
7549 IWL_DEBUG_MAC80211("leave - invalid channel\n"); 7463 IWL_DEBUG_MAC80211("leave - invalid channel\n");
7550 spin_unlock_irqrestore(&priv->lock, flags); 7464 spin_unlock_irqrestore(&priv->lock, flags);
7551 ret = -EINVAL; 7465 ret = -EINVAL;
@@ -7564,12 +7478,13 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
7564 priv->staging_rxon.flags = 0; 7478 priv->staging_rxon.flags = 0;
7565#endif /* CONFIG_IWL4965_HT */ 7479#endif /* CONFIG_IWL4965_HT */
7566 7480
7567 iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel); 7481 iwl4965_set_rxon_channel(priv, conf->channel->band,
7482 ieee80211_frequency_to_channel(conf->channel->center_freq));
7568 7483
7569 iwl4965_set_flags_for_phymode(priv, conf->phymode); 7484 iwl4965_set_flags_for_phymode(priv, conf->channel->band);
7570 7485
7571 /* The list of supported rates and rate mask can be different 7486 /* The list of supported rates and rate mask can be different
7572 * for each phymode; since the phymode may have changed, reset 7487 * for each band; since the band may have changed, reset
7573 * the rate mask to what mac80211 lists */ 7488 * the rate mask to what mac80211 lists */
7574 iwl4965_set_rate(priv); 7489 iwl4965_set_rate(priv);
7575 7490
@@ -7839,7 +7754,7 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
7839 } 7754 }
7840 7755
7841 if (changes & BSS_CHANGED_ERP_CTS_PROT) { 7756 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
7842 if (bss_conf->use_cts_prot && (priv->phymode != MODE_IEEE80211A)) 7757 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
7843 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; 7758 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
7844 else 7759 else
7845 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; 7760 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
@@ -8277,7 +8192,6 @@ static void iwl4965_set_ht_capab(struct ieee80211_hw *hw,
8277 u8 use_current_config) 8192 u8 use_current_config)
8278{ 8193{
8279 struct ieee80211_conf *conf = &hw->conf; 8194 struct ieee80211_conf *conf = &hw->conf;
8280 struct ieee80211_hw_mode *mode = conf->mode;
8281 8195
8282 if (use_current_config) { 8196 if (use_current_config) {
8283 ht_cap->cap_info = cpu_to_le16(conf->ht_conf.cap); 8197 ht_cap->cap_info = cpu_to_le16(conf->ht_conf.cap);
@@ -8488,65 +8402,6 @@ static ssize_t store_filter_flags(struct device *d,
8488static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, 8402static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
8489 store_filter_flags); 8403 store_filter_flags);
8490 8404
8491static ssize_t show_tune(struct device *d,
8492 struct device_attribute *attr, char *buf)
8493{
8494 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8495
8496 return sprintf(buf, "0x%04X\n",
8497 (priv->phymode << 8) |
8498 le16_to_cpu(priv->active_rxon.channel));
8499}
8500
8501static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode);
8502
8503static ssize_t store_tune(struct device *d,
8504 struct device_attribute *attr,
8505 const char *buf, size_t count)
8506{
8507 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8508 char *p = (char *)buf;
8509 u16 tune = simple_strtoul(p, &p, 0);
8510 u8 phymode = (tune >> 8) & 0xff;
8511 u16 channel = tune & 0xff;
8512
8513 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
8514
8515 mutex_lock(&priv->mutex);
8516 if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
8517 (priv->phymode != phymode)) {
8518 const struct iwl4965_channel_info *ch_info;
8519
8520 ch_info = iwl4965_get_channel_info(priv, phymode, channel);
8521 if (!ch_info) {
8522 IWL_WARNING("Requested invalid phymode/channel "
8523 "combination: %d %d\n", phymode, channel);
8524 mutex_unlock(&priv->mutex);
8525 return -EINVAL;
8526 }
8527
8528 /* Cancel any currently running scans... */
8529 if (iwl4965_scan_cancel_timeout(priv, 100))
8530 IWL_WARNING("Could not cancel scan.\n");
8531 else {
8532 IWL_DEBUG_INFO("Committing phymode and "
8533 "rxon.channel = %d %d\n",
8534 phymode, channel);
8535
8536 iwl4965_set_rxon_channel(priv, phymode, channel);
8537 iwl4965_set_flags_for_phymode(priv, phymode);
8538
8539 iwl4965_set_rate(priv);
8540 iwl4965_commit_rxon(priv);
8541 }
8542 }
8543 mutex_unlock(&priv->mutex);
8544
8545 return count;
8546}
8547
8548static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
8549
8550#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT 8405#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
8551 8406
8552static ssize_t show_measurement(struct device *d, 8407static ssize_t show_measurement(struct device *d,
@@ -8736,73 +8591,8 @@ static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8736static ssize_t show_channels(struct device *d, 8591static ssize_t show_channels(struct device *d,
8737 struct device_attribute *attr, char *buf) 8592 struct device_attribute *attr, char *buf)
8738{ 8593{
8739 struct iwl4965_priv *priv = dev_get_drvdata(d); 8594 /* all this shit doesn't belong into sysfs anyway */
8740 int len = 0, i; 8595 return 0;
8741 struct ieee80211_channel *channels = NULL;
8742 const struct ieee80211_hw_mode *hw_mode = NULL;
8743 int count = 0;
8744
8745 if (!iwl4965_is_ready(priv))
8746 return -EAGAIN;
8747
8748 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G);
8749 if (!hw_mode)
8750 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B);
8751 if (hw_mode) {
8752 channels = hw_mode->channels;
8753 count = hw_mode->num_channels;
8754 }
8755
8756 len +=
8757 sprintf(&buf[len],
8758 "Displaying %d channels in 2.4GHz band "
8759 "(802.11bg):\n", count);
8760
8761 for (i = 0; i < count; i++)
8762 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8763 channels[i].chan,
8764 channels[i].power_level,
8765 channels[i].
8766 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8767 " (IEEE 802.11h required)" : "",
8768 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8769 || (channels[i].
8770 flag &
8771 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8772 ", IBSS",
8773 channels[i].
8774 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8775 "active/passive" : "passive only");
8776
8777 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A);
8778 if (hw_mode) {
8779 channels = hw_mode->channels;
8780 count = hw_mode->num_channels;
8781 } else {
8782 channels = NULL;
8783 count = 0;
8784 }
8785
8786 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8787 "(802.11a):\n", count);
8788
8789 for (i = 0; i < count; i++)
8790 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8791 channels[i].chan,
8792 channels[i].power_level,
8793 channels[i].
8794 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8795 " (IEEE 802.11h required)" : "",
8796 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8797 || (channels[i].
8798 flag &
8799 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8800 ", IBSS",
8801 channels[i].
8802 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8803 "active/passive" : "passive only");
8804
8805 return len;
8806} 8596}
8807 8597
8808static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); 8598static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
@@ -8981,7 +8771,6 @@ static struct attribute *iwl4965_sysfs_entries[] = {
8981 &dev_attr_statistics.attr, 8771 &dev_attr_statistics.attr,
8982 &dev_attr_status.attr, 8772 &dev_attr_status.attr,
8983 &dev_attr_temperature.attr, 8773 &dev_attr_temperature.attr,
8984 &dev_attr_tune.attr,
8985 &dev_attr_tx_power.attr, 8774 &dev_attr_tx_power.attr,
8986 8775
8987 NULL 8776 NULL
@@ -9109,7 +8898,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
9109 priv->data_retry_limit = -1; 8898 priv->data_retry_limit = -1;
9110 priv->ieee_channels = NULL; 8899 priv->ieee_channels = NULL;
9111 priv->ieee_rates = NULL; 8900 priv->ieee_rates = NULL;
9112 priv->phymode = -1; 8901 priv->band = IEEE80211_BAND_2GHZ;
9113 8902
9114 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 8903 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
9115 if (!err) 8904 if (!err)
@@ -9175,7 +8964,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
9175 priv->qos_data.qos_cap.val = 0; 8964 priv->qos_data.qos_cap.val = 0;
9176#endif /* CONFIG_IWL4965_QOS */ 8965#endif /* CONFIG_IWL4965_QOS */
9177 8966
9178 iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6); 8967 iwl4965_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
9179 iwl4965_setup_deferred_work(priv); 8968 iwl4965_setup_deferred_work(priv);
9180 iwl4965_setup_rx_handlers(priv); 8969 iwl4965_setup_rx_handlers(priv);
9181 8970
@@ -9226,7 +9015,6 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
9226 IWL_ERROR("initializing geos failed: %d\n", err); 9015 IWL_ERROR("initializing geos failed: %d\n", err);
9227 goto out_free_channel_map; 9016 goto out_free_channel_map;
9228 } 9017 }
9229 iwl4965_reset_channel_flag(priv);
9230 9018
9231 iwl4965_rate_control_register(priv->hw); 9019 iwl4965_rate_control_register(priv->hw);
9232 err = ieee80211_register_hw(priv->hw); 9020 err = ieee80211_register_hw(priv->hw);
diff --git a/drivers/net/wireless/p54.h b/drivers/net/wireless/p54.h
index 744c866066c5..06d2c67f4c81 100644
--- a/drivers/net/wireless/p54.h
+++ b/drivers/net/wireless/p54.h
@@ -64,10 +64,6 @@ struct p54_common {
64 unsigned int tx_hdr_len; 64 unsigned int tx_hdr_len;
65 void *cached_vdcf; 65 void *cached_vdcf;
66 unsigned int fw_var; 66 unsigned int fw_var;
67 /* FIXME: this channels/modes/rates stuff sucks */
68 struct ieee80211_channel channels[14];
69 struct ieee80211_rate rates[12];
70 struct ieee80211_hw_mode modes[2];
71 struct ieee80211_tx_queue_stats tx_stats; 67 struct ieee80211_tx_queue_stats tx_stats;
72}; 68};
73 69
diff --git a/drivers/net/wireless/p54common.c b/drivers/net/wireless/p54common.c
index 5cda49aff3a8..218ff7770ef6 100644
--- a/drivers/net/wireless/p54common.c
+++ b/drivers/net/wireless/p54common.c
@@ -27,6 +27,46 @@ MODULE_DESCRIPTION("Softmac Prism54 common code");
27MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
28MODULE_ALIAS("prism54common"); 28MODULE_ALIAS("prism54common");
29 29
30static struct ieee80211_rate p54_rates[] = {
31 { .bitrate = 10, .hw_value = 0, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
32 { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
33 { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
34 { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
35 { .bitrate = 60, .hw_value = 4, },
36 { .bitrate = 90, .hw_value = 5, },
37 { .bitrate = 120, .hw_value = 6, },
38 { .bitrate = 180, .hw_value = 7, },
39 { .bitrate = 240, .hw_value = 8, },
40 { .bitrate = 360, .hw_value = 9, },
41 { .bitrate = 480, .hw_value = 10, },
42 { .bitrate = 540, .hw_value = 11, },
43};
44
45static struct ieee80211_channel p54_channels[] = {
46 { .center_freq = 2412, .hw_value = 1, },
47 { .center_freq = 2417, .hw_value = 2, },
48 { .center_freq = 2422, .hw_value = 3, },
49 { .center_freq = 2427, .hw_value = 4, },
50 { .center_freq = 2432, .hw_value = 5, },
51 { .center_freq = 2437, .hw_value = 6, },
52 { .center_freq = 2442, .hw_value = 7, },
53 { .center_freq = 2447, .hw_value = 8, },
54 { .center_freq = 2452, .hw_value = 9, },
55 { .center_freq = 2457, .hw_value = 10, },
56 { .center_freq = 2462, .hw_value = 11, },
57 { .center_freq = 2467, .hw_value = 12, },
58 { .center_freq = 2472, .hw_value = 13, },
59 { .center_freq = 2484, .hw_value = 14, },
60};
61
62struct ieee80211_supported_band band_2GHz = {
63 .channels = p54_channels,
64 .n_channels = ARRAY_SIZE(p54_channels),
65 .bitrates = p54_rates,
66 .n_bitrates = ARRAY_SIZE(p54_rates),
67};
68
69
30void p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw) 70void p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
31{ 71{
32 struct p54_common *priv = dev->priv; 72 struct p54_common *priv = dev->priv;
@@ -308,10 +348,10 @@ static void p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb)
308 u16 freq = le16_to_cpu(hdr->freq); 348 u16 freq = le16_to_cpu(hdr->freq);
309 349
310 rx_status.ssi = hdr->rssi; 350 rx_status.ssi = hdr->rssi;
311 rx_status.rate = hdr->rate & 0x1f; /* report short preambles & CCK too */ 351 /* XX correct? */
312 rx_status.channel = freq == 2484 ? 14 : (freq - 2407)/5; 352 rx_status.rate_idx = hdr->rate & 0xf;
313 rx_status.freq = freq; 353 rx_status.freq = freq;
314 rx_status.phymode = MODE_IEEE80211G; 354 rx_status.band = IEEE80211_BAND_2GHZ;
315 rx_status.antenna = hdr->antenna; 355 rx_status.antenna = hdr->antenna;
316 rx_status.mactime = le64_to_cpu(hdr->timestamp); 356 rx_status.mactime = le64_to_cpu(hdr->timestamp);
317 rx_status.flag |= RX_FLAG_TSFT; 357 rx_status.flag |= RX_FLAG_TSFT;
@@ -547,7 +587,9 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
547 txhdr->padding2 = 0; 587 txhdr->padding2 = 0;
548 588
549 /* TODO: add support for alternate retry TX rates */ 589 /* TODO: add support for alternate retry TX rates */
550 rate = control->tx_rate; 590 rate = control->tx_rate->hw_value;
591 if (control->flags & IEEE80211_TXCTL_SHORT_PREAMBLE)
592 rate |= 0x10;
551 if (control->flags & IEEE80211_TXCTL_USE_RTS_CTS) 593 if (control->flags & IEEE80211_TXCTL_USE_RTS_CTS)
552 rate |= 0x40; 594 rate |= 0x40;
553 else if (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) 595 else if (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
@@ -849,7 +891,7 @@ static int p54_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
849{ 891{
850 int ret; 892 int ret;
851 893
852 ret = p54_set_freq(dev, cpu_to_le16(conf->freq)); 894 ret = p54_set_freq(dev, cpu_to_le16(conf->channel->center_freq));
853 p54_set_vdcf(dev); 895 p54_set_vdcf(dev);
854 return ret; 896 return ret;
855} 897}
@@ -944,7 +986,6 @@ struct ieee80211_hw *p54_init_common(size_t priv_data_len)
944{ 986{
945 struct ieee80211_hw *dev; 987 struct ieee80211_hw *dev;
946 struct p54_common *priv; 988 struct p54_common *priv;
947 int i;
948 989
949 dev = ieee80211_alloc_hw(priv_data_len, &p54_ops); 990 dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
950 if (!dev) 991 if (!dev)
@@ -953,18 +994,7 @@ struct ieee80211_hw *p54_init_common(size_t priv_data_len)
953 priv = dev->priv; 994 priv = dev->priv;
954 priv->mode = IEEE80211_IF_TYPE_INVALID; 995 priv->mode = IEEE80211_IF_TYPE_INVALID;
955 skb_queue_head_init(&priv->tx_queue); 996 skb_queue_head_init(&priv->tx_queue);
956 memcpy(priv->channels, p54_channels, sizeof(p54_channels)); 997 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz;
957 memcpy(priv->rates, p54_rates, sizeof(p54_rates));
958 priv->modes[1].mode = MODE_IEEE80211B;
959 priv->modes[1].num_rates = 4;
960 priv->modes[1].rates = priv->rates;
961 priv->modes[1].num_channels = ARRAY_SIZE(p54_channels);
962 priv->modes[1].channels = priv->channels;
963 priv->modes[0].mode = MODE_IEEE80211G;
964 priv->modes[0].num_rates = ARRAY_SIZE(p54_rates);
965 priv->modes[0].rates = priv->rates;
966 priv->modes[0].num_channels = ARRAY_SIZE(p54_channels);
967 priv->modes[0].channels = priv->channels;
968 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | /* not sure */ 998 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | /* not sure */
969 IEEE80211_HW_RX_INCLUDES_FCS; 999 IEEE80211_HW_RX_INCLUDES_FCS;
970 dev->channel_change_time = 1000; /* TODO: find actual value */ 1000 dev->channel_change_time = 1000; /* TODO: find actual value */
@@ -986,14 +1016,6 @@ struct ieee80211_hw *p54_init_common(size_t priv_data_len)
986 1016
987 p54_init_vdcf(dev); 1017 p54_init_vdcf(dev);
988 1018
989 for (i = 0; i < 2; i++) {
990 if (ieee80211_register_hwmode(dev, &priv->modes[i])) {
991 kfree(priv->cached_vdcf);
992 ieee80211_free_hw(dev);
993 return NULL;
994 }
995 }
996
997 return dev; 1019 return dev;
998} 1020}
999EXPORT_SYMBOL_GPL(p54_init_common); 1021EXPORT_SYMBOL_GPL(p54_init_common);
diff --git a/drivers/net/wireless/p54common.h b/drivers/net/wireless/p54common.h
index a721334e20d9..dc9f4cef585e 100644
--- a/drivers/net/wireless/p54common.h
+++ b/drivers/net/wireless/p54common.h
@@ -251,79 +251,4 @@ struct p54_tx_control_vdcf {
251 __le16 frameburst; 251 __le16 frameburst;
252} __attribute__ ((packed)); 252} __attribute__ ((packed));
253 253
254static const struct ieee80211_rate p54_rates[] = {
255 { .rate = 10,
256 .val = 0,
257 .val2 = 0x10,
258 .flags = IEEE80211_RATE_CCK_2 },
259 { .rate = 20,
260 .val = 1,
261 .val2 = 0x11,
262 .flags = IEEE80211_RATE_CCK_2 },
263 { .rate = 55,
264 .val = 2,
265 .val2 = 0x12,
266 .flags = IEEE80211_RATE_CCK_2 },
267 { .rate = 110,
268 .val = 3,
269 .val2 = 0x13,
270 .flags = IEEE80211_RATE_CCK_2 },
271 { .rate = 60,
272 .val = 4,
273 .flags = IEEE80211_RATE_OFDM },
274 { .rate = 90,
275 .val = 5,
276 .flags = IEEE80211_RATE_OFDM },
277 { .rate = 120,
278 .val = 6,
279 .flags = IEEE80211_RATE_OFDM },
280 { .rate = 180,
281 .val = 7,
282 .flags = IEEE80211_RATE_OFDM },
283 { .rate = 240,
284 .val = 8,
285 .flags = IEEE80211_RATE_OFDM },
286 { .rate = 360,
287 .val = 9,
288 .flags = IEEE80211_RATE_OFDM },
289 { .rate = 480,
290 .val = 10,
291 .flags = IEEE80211_RATE_OFDM },
292 { .rate = 540,
293 .val = 11,
294 .flags = IEEE80211_RATE_OFDM },
295};
296
297// TODO: just generate this..
298static const struct ieee80211_channel p54_channels[] = {
299 { .chan = 1,
300 .freq = 2412},
301 { .chan = 2,
302 .freq = 2417},
303 { .chan = 3,
304 .freq = 2422},
305 { .chan = 4,
306 .freq = 2427},
307 { .chan = 5,
308 .freq = 2432},
309 { .chan = 6,
310 .freq = 2437},
311 { .chan = 7,
312 .freq = 2442},
313 { .chan = 8,
314 .freq = 2447},
315 { .chan = 9,
316 .freq = 2452},
317 { .chan = 10,
318 .freq = 2457},
319 { .chan = 11,
320 .freq = 2462},
321 { .chan = 12,
322 .freq = 2467},
323 { .chan = 13,
324 .freq = 2472},
325 { .chan = 14,
326 .freq = 2484}
327};
328
329#endif /* PRISM54COMMON_H */ 254#endif /* PRISM54COMMON_H */
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index b0e4ea7c9dca..4fa762bdb734 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -390,6 +390,10 @@ static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
390 return (struct rt2x00_intf *)vif->drv_priv; 390 return (struct rt2x00_intf *)vif->drv_priv;
391} 391}
392 392
393#define HWMODE_B 0
394#define HWMODE_G 1
395#define HWMODE_A 2
396
393/* 397/*
394 * Details about the supported modes, rates and channels 398 * Details about the supported modes, rates and channels
395 * of a particular chipset. This is used by rt2x00lib 399 * of a particular chipset. This is used by rt2x00lib
@@ -644,11 +648,8 @@ struct rt2x00_dev {
644 * IEEE80211 control structure. 648 * IEEE80211 control structure.
645 */ 649 */
646 struct ieee80211_hw *hw; 650 struct ieee80211_hw *hw;
647 struct ieee80211_hw_mode *hwmodes; 651 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
648 unsigned int curr_hwmode; 652 enum ieee80211_band curr_band;
649#define HWMODE_B 0
650#define HWMODE_G 1
651#define HWMODE_A 2
652 653
653 /* 654 /*
654 * rfkill structure for RF state switching support. 655 * rfkill structure for RF state switching support.
diff --git a/drivers/net/wireless/rt2x00/rt2x00config.c b/drivers/net/wireless/rt2x00/rt2x00config.c
index 20231e0c53fa..9fba485a40ac 100644
--- a/drivers/net/wireless/rt2x00/rt2x00config.c
+++ b/drivers/net/wireless/rt2x00/rt2x00config.c
@@ -152,7 +152,7 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
152 struct ieee80211_conf *conf, const int force_config) 152 struct ieee80211_conf *conf, const int force_config)
153{ 153{
154 struct rt2x00lib_conf libconf; 154 struct rt2x00lib_conf libconf;
155 struct ieee80211_hw_mode *mode; 155 struct ieee80211_supported_band *band;
156 struct ieee80211_rate *rate; 156 struct ieee80211_rate *rate;
157 struct antenna_setup *default_ant = &rt2x00dev->default_ant; 157 struct antenna_setup *default_ant = &rt2x00dev->default_ant;
158 struct antenna_setup *active_ant = &rt2x00dev->link.ant.active; 158 struct antenna_setup *active_ant = &rt2x00dev->link.ant.active;
@@ -172,9 +172,9 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
172 * Check which configuration options have been 172 * Check which configuration options have been
173 * updated and should be send to the device. 173 * updated and should be send to the device.
174 */ 174 */
175 if (rt2x00dev->rx_status.phymode != conf->phymode) 175 if (rt2x00dev->rx_status.band != conf->channel->band)
176 flags |= CONFIG_UPDATE_PHYMODE; 176 flags |= CONFIG_UPDATE_PHYMODE;
177 if (rt2x00dev->rx_status.channel != conf->channel) 177 if (rt2x00dev->rx_status.freq != conf->channel->center_freq)
178 flags |= CONFIG_UPDATE_CHANNEL; 178 flags |= CONFIG_UPDATE_CHANNEL;
179 if (rt2x00dev->tx_power != conf->power_level) 179 if (rt2x00dev->tx_power != conf->power_level)
180 flags |= CONFIG_UPDATE_TXPOWER; 180 flags |= CONFIG_UPDATE_TXPOWER;
@@ -229,33 +229,31 @@ config:
229 memset(&libconf, 0, sizeof(libconf)); 229 memset(&libconf, 0, sizeof(libconf));
230 230
231 if (flags & CONFIG_UPDATE_PHYMODE) { 231 if (flags & CONFIG_UPDATE_PHYMODE) {
232 switch (conf->phymode) { 232 switch (conf->channel->band) {
233 case MODE_IEEE80211A: 233 case IEEE80211_BAND_5GHZ:
234 libconf.phymode = HWMODE_A; 234 libconf.phymode = HWMODE_A;
235 break; 235 break;
236 case MODE_IEEE80211B: 236 case IEEE80211_BAND_2GHZ:
237 libconf.phymode = HWMODE_B; 237 /* Uh oh. what about B? */
238 break;
239 case MODE_IEEE80211G:
240 libconf.phymode = HWMODE_G; 238 libconf.phymode = HWMODE_G;
241 break; 239 break;
242 default: 240 default:
243 ERROR(rt2x00dev, 241 ERROR(rt2x00dev,
244 "Attempt to configure unsupported mode (%d)" 242 "Attempt to configure unsupported mode (%d)"
245 "Defaulting to 802.11b", conf->phymode); 243 "Defaulting to 802.11b", conf->channel->band);
246 libconf.phymode = HWMODE_B; 244 libconf.phymode = HWMODE_B;
247 } 245 }
248 246
249 mode = &rt2x00dev->hwmodes[libconf.phymode]; 247 band = &rt2x00dev->bands[conf->channel->band];
250 rate = &mode->rates[mode->num_rates - 1]; 248 rate = &band->bitrates[band->n_bitrates - 1];
251 249
252 libconf.basic_rates = 250 libconf.basic_rates =
253 DEVICE_GET_RATE_FIELD(rate->val, RATEMASK) & DEV_BASIC_RATEMASK; 251 DEVICE_GET_RATE_FIELD(rate->hw_value, RATEMASK) & DEV_BASIC_RATEMASK;
254 } 252 }
255 253
256 if (flags & CONFIG_UPDATE_CHANNEL) { 254 if (flags & CONFIG_UPDATE_CHANNEL) {
257 memcpy(&libconf.rf, 255 memcpy(&libconf.rf,
258 &rt2x00dev->spec.channels[conf->channel_val], 256 &rt2x00dev->spec.channels[conf->channel->hw_value],
259 sizeof(libconf.rf)); 257 sizeof(libconf.rf));
260 } 258 }
261 259
@@ -301,12 +299,11 @@ config:
301 rt2x00lib_reset_link_tuner(rt2x00dev); 299 rt2x00lib_reset_link_tuner(rt2x00dev);
302 300
303 if (flags & CONFIG_UPDATE_PHYMODE) { 301 if (flags & CONFIG_UPDATE_PHYMODE) {
304 rt2x00dev->curr_hwmode = libconf.phymode; 302 rt2x00dev->curr_band = conf->channel->band;
305 rt2x00dev->rx_status.phymode = conf->phymode; 303 rt2x00dev->rx_status.band = conf->channel->band;
306 } 304 }
307 305
308 rt2x00dev->rx_status.freq = conf->freq; 306 rt2x00dev->rx_status.freq = conf->channel->center_freq;
309 rt2x00dev->rx_status.channel = conf->channel;
310 rt2x00dev->tx_power = conf->power_level; 307 rt2x00dev->tx_power = conf->power_level;
311 308
312 if (flags & CONFIG_UPDATE_ANTENNA) { 309 if (flags & CONFIG_UPDATE_ANTENNA) {
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index 0df8062b1a8e..83a72ae36638 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -550,19 +550,19 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
550{ 550{
551 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 551 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
552 struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status; 552 struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
553 struct ieee80211_hw_mode *mode; 553 struct ieee80211_supported_band *sband;
554 struct ieee80211_rate *rate; 554 struct ieee80211_rate *rate;
555 struct ieee80211_hdr *hdr; 555 struct ieee80211_hdr *hdr;
556 unsigned int i; 556 unsigned int i;
557 int val = 0; 557 int val = 0, idx = -1;
558 u16 fc; 558 u16 fc;
559 559
560 /* 560 /*
561 * Update RX statistics. 561 * Update RX statistics.
562 */ 562 */
563 mode = &rt2x00dev->hwmodes[rt2x00dev->curr_hwmode]; 563 sband = &rt2x00dev->bands[rt2x00dev->curr_band];
564 for (i = 0; i < mode->num_rates; i++) { 564 for (i = 0; i < sband->n_bitrates; i++) {
565 rate = &mode->rates[i]; 565 rate = &sband->bitrates[i];
566 566
567 /* 567 /*
568 * When frame was received with an OFDM bitrate, 568 * When frame was received with an OFDM bitrate,
@@ -570,12 +570,12 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
570 * a CCK bitrate the signal is the rate in 0.5kbit/s. 570 * a CCK bitrate the signal is the rate in 0.5kbit/s.
571 */ 571 */
572 if (!rxdesc->ofdm) 572 if (!rxdesc->ofdm)
573 val = DEVICE_GET_RATE_FIELD(rate->val, RATE); 573 val = DEVICE_GET_RATE_FIELD(rate->hw_value, RATE);
574 else 574 else
575 val = DEVICE_GET_RATE_FIELD(rate->val, PLCP); 575 val = DEVICE_GET_RATE_FIELD(rate->hw_value, PLCP);
576 576
577 if (val == rxdesc->signal) { 577 if (val == rxdesc->signal) {
578 val = rate->val; 578 idx = i;
579 break; 579 break;
580 } 580 }
581 } 581 }
@@ -590,7 +590,7 @@ void rt2x00lib_rxdone(struct queue_entry *entry,
590 590
591 rt2x00dev->link.qual.rx_success++; 591 rt2x00dev->link.qual.rx_success++;
592 592
593 rx_status->rate = val; 593 rx_status->rate_idx = idx;
594 rx_status->signal = 594 rx_status->signal =
595 rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc->rssi); 595 rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc->rssi);
596 rx_status->ssi = rxdesc->rssi; 596 rx_status->ssi = rxdesc->rssi;
@@ -639,7 +639,7 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
639 frame_control = le16_to_cpu(ieee80211hdr->frame_control); 639 frame_control = le16_to_cpu(ieee80211hdr->frame_control);
640 seq_ctrl = le16_to_cpu(ieee80211hdr->seq_ctrl); 640 seq_ctrl = le16_to_cpu(ieee80211hdr->seq_ctrl);
641 641
642 tx_rate = control->tx_rate; 642 tx_rate = control->tx_rate->hw_value;
643 643
644 /* 644 /*
645 * Check whether this frame is to be acked 645 * Check whether this frame is to be acked
@@ -658,7 +658,7 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
658 } else 658 } else
659 __clear_bit(ENTRY_TXD_ACK, &txdesc.flags); 659 __clear_bit(ENTRY_TXD_ACK, &txdesc.flags);
660 if (control->rts_cts_rate) 660 if (control->rts_cts_rate)
661 tx_rate = control->rts_cts_rate; 661 tx_rate = control->rts_cts_rate->hw_value;
662 } 662 }
663 663
664 /* 664 /*
@@ -760,54 +760,45 @@ static void rt2x00lib_channel(struct ieee80211_channel *entry,
760 const int channel, const int tx_power, 760 const int channel, const int tx_power,
761 const int value) 761 const int value)
762{ 762{
763 entry->chan = channel;
764 if (channel <= 14) 763 if (channel <= 14)
765 entry->freq = 2407 + (5 * channel); 764 entry->center_freq = 2407 + (5 * channel);
766 else 765 else
767 entry->freq = 5000 + (5 * channel); 766 entry->center_freq = 5000 + (5 * channel);
768 entry->val = value; 767 entry->hw_value = value;
769 entry->flag = 768 entry->max_power = tx_power;
770 IEEE80211_CHAN_W_IBSS | 769 entry->max_antenna_gain = 0xff;
771 IEEE80211_CHAN_W_ACTIVE_SCAN |
772 IEEE80211_CHAN_W_SCAN;
773 entry->power_level = tx_power;
774 entry->antenna_max = 0xff;
775} 770}
776 771
777static void rt2x00lib_rate(struct ieee80211_rate *entry, 772static void rt2x00lib_rate(struct ieee80211_rate *entry,
778 const int rate, const int mask, 773 const int rate, const int mask,
779 const int plcp, const int flags) 774 const int plcp, const int flags)
780{ 775{
781 entry->rate = rate; 776 entry->bitrate = rate;
782 entry->val = 777 entry->hw_value =
783 DEVICE_SET_RATE_FIELD(rate, RATE) | 778 DEVICE_SET_RATE_FIELD(rate, RATE) |
784 DEVICE_SET_RATE_FIELD(mask, RATEMASK) | 779 DEVICE_SET_RATE_FIELD(mask, RATEMASK) |
785 DEVICE_SET_RATE_FIELD(plcp, PLCP); 780 DEVICE_SET_RATE_FIELD(plcp, PLCP);
786 entry->flags = flags; 781 entry->flags = flags;
787 entry->val2 = entry->val; 782 entry->hw_value_short = entry->hw_value;
788 if (entry->flags & IEEE80211_RATE_PREAMBLE2) 783 if (entry->flags & IEEE80211_RATE_SHORT_PREAMBLE)
789 entry->val2 |= DEVICE_SET_RATE_FIELD(1, PREAMBLE); 784 entry->hw_value_short |= DEVICE_SET_RATE_FIELD(1, PREAMBLE);
790 entry->min_rssi_ack = 0;
791 entry->min_rssi_ack_delta = 0;
792} 785}
793 786
794static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev, 787static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
795 struct hw_mode_spec *spec) 788 struct hw_mode_spec *spec)
796{ 789{
797 struct ieee80211_hw *hw = rt2x00dev->hw; 790 struct ieee80211_hw *hw = rt2x00dev->hw;
798 struct ieee80211_hw_mode *hwmodes; 791 struct ieee80211_supported_band *sbands;
799 struct ieee80211_channel *channels; 792 struct ieee80211_channel *channels;
800 struct ieee80211_rate *rates; 793 struct ieee80211_rate *rates;
801 unsigned int i; 794 unsigned int i;
802 unsigned char tx_power; 795 unsigned char tx_power;
803 796
804 hwmodes = kzalloc(sizeof(*hwmodes) * spec->num_modes, GFP_KERNEL); 797 sbands = &rt2x00dev->bands[0];
805 if (!hwmodes)
806 goto exit;
807 798
808 channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL); 799 channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL);
809 if (!channels) 800 if (!channels)
810 goto exit_free_modes; 801 return -ENOMEM;
811 802
812 rates = kzalloc(sizeof(*rates) * spec->num_rates, GFP_KERNEL); 803 rates = kzalloc(sizeof(*rates) * spec->num_rates, GFP_KERNEL);
813 if (!rates) 804 if (!rates)
@@ -817,31 +808,31 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
817 * Initialize Rate list. 808 * Initialize Rate list.
818 */ 809 */
819 rt2x00lib_rate(&rates[0], 10, DEV_RATEMASK_1MB, 810 rt2x00lib_rate(&rates[0], 10, DEV_RATEMASK_1MB,
820 0x00, IEEE80211_RATE_CCK); 811 0x00, 0);
821 rt2x00lib_rate(&rates[1], 20, DEV_RATEMASK_2MB, 812 rt2x00lib_rate(&rates[1], 20, DEV_RATEMASK_2MB,
822 0x01, IEEE80211_RATE_CCK_2); 813 0x01, IEEE80211_RATE_SHORT_PREAMBLE);
823 rt2x00lib_rate(&rates[2], 55, DEV_RATEMASK_5_5MB, 814 rt2x00lib_rate(&rates[2], 55, DEV_RATEMASK_5_5MB,
824 0x02, IEEE80211_RATE_CCK_2); 815 0x02, IEEE80211_RATE_SHORT_PREAMBLE);
825 rt2x00lib_rate(&rates[3], 110, DEV_RATEMASK_11MB, 816 rt2x00lib_rate(&rates[3], 110, DEV_RATEMASK_11MB,
826 0x03, IEEE80211_RATE_CCK_2); 817 0x03, IEEE80211_RATE_SHORT_PREAMBLE);
827 818
828 if (spec->num_rates > 4) { 819 if (spec->num_rates > 4) {
829 rt2x00lib_rate(&rates[4], 60, DEV_RATEMASK_6MB, 820 rt2x00lib_rate(&rates[4], 60, DEV_RATEMASK_6MB,
830 0x0b, IEEE80211_RATE_OFDM); 821 0x0b, 0);
831 rt2x00lib_rate(&rates[5], 90, DEV_RATEMASK_9MB, 822 rt2x00lib_rate(&rates[5], 90, DEV_RATEMASK_9MB,
832 0x0f, IEEE80211_RATE_OFDM); 823 0x0f, 0);
833 rt2x00lib_rate(&rates[6], 120, DEV_RATEMASK_12MB, 824 rt2x00lib_rate(&rates[6], 120, DEV_RATEMASK_12MB,
834 0x0a, IEEE80211_RATE_OFDM); 825 0x0a, 0);
835 rt2x00lib_rate(&rates[7], 180, DEV_RATEMASK_18MB, 826 rt2x00lib_rate(&rates[7], 180, DEV_RATEMASK_18MB,
836 0x0e, IEEE80211_RATE_OFDM); 827 0x0e, 0);
837 rt2x00lib_rate(&rates[8], 240, DEV_RATEMASK_24MB, 828 rt2x00lib_rate(&rates[8], 240, DEV_RATEMASK_24MB,
838 0x09, IEEE80211_RATE_OFDM); 829 0x09, 0);
839 rt2x00lib_rate(&rates[9], 360, DEV_RATEMASK_36MB, 830 rt2x00lib_rate(&rates[9], 360, DEV_RATEMASK_36MB,
840 0x0d, IEEE80211_RATE_OFDM); 831 0x0d, 0);
841 rt2x00lib_rate(&rates[10], 480, DEV_RATEMASK_48MB, 832 rt2x00lib_rate(&rates[10], 480, DEV_RATEMASK_48MB,
842 0x08, IEEE80211_RATE_OFDM); 833 0x08, 0);
843 rt2x00lib_rate(&rates[11], 540, DEV_RATEMASK_54MB, 834 rt2x00lib_rate(&rates[11], 540, DEV_RATEMASK_54MB,
844 0x0c, IEEE80211_RATE_OFDM); 835 0x0c, 0);
845 } 836 }
846 837
847 /* 838 /*
@@ -862,27 +853,27 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
862 /* 853 /*
863 * Intitialize 802.11b 854 * Intitialize 802.11b
864 * Rates: CCK. 855 * Rates: CCK.
865 * Channels: OFDM. 856 * Channels: 2.4 GHz
866 */ 857 */
867 if (spec->num_modes > HWMODE_B) { 858 if (spec->num_modes > HWMODE_B) {
868 hwmodes[HWMODE_B].mode = MODE_IEEE80211B; 859 sbands[IEEE80211_BAND_2GHZ].n_channels = 14;
869 hwmodes[HWMODE_B].num_channels = 14; 860 sbands[IEEE80211_BAND_2GHZ].n_bitrates = 4;
870 hwmodes[HWMODE_B].num_rates = 4; 861 sbands[IEEE80211_BAND_2GHZ].channels = channels;
871 hwmodes[HWMODE_B].channels = channels; 862 sbands[IEEE80211_BAND_2GHZ].bitrates = rates;
872 hwmodes[HWMODE_B].rates = rates; 863 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
873 } 864 }
874 865
875 /* 866 /*
876 * Intitialize 802.11g 867 * Intitialize 802.11g
877 * Rates: CCK, OFDM. 868 * Rates: CCK, OFDM.
878 * Channels: OFDM. 869 * Channels: 2.4 GHz
879 */ 870 */
880 if (spec->num_modes > HWMODE_G) { 871 if (spec->num_modes > HWMODE_G) {
881 hwmodes[HWMODE_G].mode = MODE_IEEE80211G; 872 sbands[IEEE80211_BAND_2GHZ].n_channels = 14;
882 hwmodes[HWMODE_G].num_channels = 14; 873 sbands[IEEE80211_BAND_2GHZ].n_bitrates = spec->num_rates;
883 hwmodes[HWMODE_G].num_rates = spec->num_rates; 874 sbands[IEEE80211_BAND_2GHZ].channels = channels;
884 hwmodes[HWMODE_G].channels = channels; 875 sbands[IEEE80211_BAND_2GHZ].bitrates = rates;
885 hwmodes[HWMODE_G].rates = rates; 876 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
886 } 877 }
887 878
888 /* 879 /*
@@ -891,39 +882,17 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
891 * Channels: OFDM, UNII, HiperLAN2. 882 * Channels: OFDM, UNII, HiperLAN2.
892 */ 883 */
893 if (spec->num_modes > HWMODE_A) { 884 if (spec->num_modes > HWMODE_A) {
894 hwmodes[HWMODE_A].mode = MODE_IEEE80211A; 885 sbands[IEEE80211_BAND_5GHZ].n_channels = spec->num_channels - 14;
895 hwmodes[HWMODE_A].num_channels = spec->num_channels - 14; 886 sbands[IEEE80211_BAND_5GHZ].n_bitrates = spec->num_rates - 4;
896 hwmodes[HWMODE_A].num_rates = spec->num_rates - 4; 887 sbands[IEEE80211_BAND_5GHZ].channels = &channels[14];
897 hwmodes[HWMODE_A].channels = &channels[14]; 888 sbands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
898 hwmodes[HWMODE_A].rates = &rates[4]; 889 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
899 } 890 }
900 891
901 if (spec->num_modes > HWMODE_G &&
902 ieee80211_register_hwmode(hw, &hwmodes[HWMODE_G]))
903 goto exit_free_rates;
904
905 if (spec->num_modes > HWMODE_B &&
906 ieee80211_register_hwmode(hw, &hwmodes[HWMODE_B]))
907 goto exit_free_rates;
908
909 if (spec->num_modes > HWMODE_A &&
910 ieee80211_register_hwmode(hw, &hwmodes[HWMODE_A]))
911 goto exit_free_rates;
912
913 rt2x00dev->hwmodes = hwmodes;
914
915 return 0; 892 return 0;
916 893
917exit_free_rates: 894 exit_free_channels:
918 kfree(rates);
919
920exit_free_channels:
921 kfree(channels); 895 kfree(channels);
922
923exit_free_modes:
924 kfree(hwmodes);
925
926exit:
927 ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n"); 896 ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n");
928 return -ENOMEM; 897 return -ENOMEM;
929} 898}
@@ -933,11 +902,11 @@ static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
933 if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags)) 902 if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags))
934 ieee80211_unregister_hw(rt2x00dev->hw); 903 ieee80211_unregister_hw(rt2x00dev->hw);
935 904
936 if (likely(rt2x00dev->hwmodes)) { 905 if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) {
937 kfree(rt2x00dev->hwmodes->channels); 906 kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
938 kfree(rt2x00dev->hwmodes->rates); 907 kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->bitrates);
939 kfree(rt2x00dev->hwmodes); 908 rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
940 rt2x00dev->hwmodes = NULL; 909 rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
941 } 910 }
942} 911}
943 912
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 59e87a1d96a4..1dd30510ed1e 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -426,12 +426,12 @@ static void rt61pci_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
426 case ANTENNA_HW_DIVERSITY: 426 case ANTENNA_HW_DIVERSITY:
427 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2); 427 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
428 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 428 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
429 (rt2x00dev->curr_hwmode != HWMODE_A)); 429 (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ));
430 break; 430 break;
431 case ANTENNA_A: 431 case ANTENNA_A:
432 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 432 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
433 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); 433 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
434 if (rt2x00dev->curr_hwmode == HWMODE_A) 434 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
435 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); 435 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
436 else 436 else
437 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); 437 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
@@ -446,7 +446,7 @@ static void rt61pci_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
446 case ANTENNA_B: 446 case ANTENNA_B:
447 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 447 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
448 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); 448 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
449 if (rt2x00dev->curr_hwmode == HWMODE_A) 449 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
450 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); 450 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
451 else 451 else
452 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); 452 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
@@ -602,7 +602,7 @@ static void rt61pci_config_antenna(struct rt2x00_dev *rt2x00dev,
602 unsigned int i; 602 unsigned int i;
603 u32 reg; 603 u32 reg;
604 604
605 if (rt2x00dev->curr_hwmode == HWMODE_A) { 605 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
606 sel = antenna_sel_a; 606 sel = antenna_sel_a;
607 lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags); 607 lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
608 } else { 608 } else {
@@ -616,10 +616,9 @@ static void rt61pci_config_antenna(struct rt2x00_dev *rt2x00dev,
616 rt2x00pci_register_read(rt2x00dev, PHY_CSR0, &reg); 616 rt2x00pci_register_read(rt2x00dev, PHY_CSR0, &reg);
617 617
618 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG, 618 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
619 (rt2x00dev->curr_hwmode == HWMODE_B || 619 rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
620 rt2x00dev->curr_hwmode == HWMODE_G));
621 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A, 620 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
622 (rt2x00dev->curr_hwmode == HWMODE_A)); 621 rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
623 622
624 rt2x00pci_register_write(rt2x00dev, PHY_CSR0, reg); 623 rt2x00pci_register_write(rt2x00dev, PHY_CSR0, reg);
625 624
@@ -698,9 +697,9 @@ static void rt61pci_enable_led(struct rt2x00_dev *rt2x00dev)
698 697
699 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_RADIO_STATUS, 1); 698 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_RADIO_STATUS, 1);
700 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_A_STATUS, 699 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_A_STATUS,
701 (rt2x00dev->rx_status.phymode == MODE_IEEE80211A)); 700 rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ);
702 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_BG_STATUS, 701 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_BG_STATUS,
703 (rt2x00dev->rx_status.phymode != MODE_IEEE80211A)); 702 rt2x00dev->rx_status.band != IEEE80211_BAND_5GHZ);
704 703
705 arg0 = rt2x00dev->led_reg & 0xff; 704 arg0 = rt2x00dev->led_reg & 0xff;
706 arg1 = (rt2x00dev->led_reg >> 8) & 0xff; 705 arg1 = (rt2x00dev->led_reg >> 8) & 0xff;
@@ -798,7 +797,7 @@ static void rt61pci_link_tuner(struct rt2x00_dev *rt2x00dev)
798 /* 797 /*
799 * Determine r17 bounds. 798 * Determine r17 bounds.
800 */ 799 */
801 if (rt2x00dev->rx_status.phymode == MODE_IEEE80211A) { 800 if (rt2x00dev->rx_status.band == IEEE80211_BAND_2GHZ) {
802 low_bound = 0x28; 801 low_bound = 0x28;
803 up_bound = 0x48; 802 up_bound = 0x48;
804 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) { 803 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
@@ -1544,8 +1543,10 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1544 rt2x00_desc_write(txd, 2, word); 1543 rt2x00_desc_write(txd, 2, word);
1545 1544
1546 rt2x00_desc_read(txd, 5, &word); 1545 rt2x00_desc_read(txd, 5, &word);
1546/* XXX: removed for now
1547 rt2x00_set_field32(&word, TXD_W5_TX_POWER, 1547 rt2x00_set_field32(&word, TXD_W5_TX_POWER,
1548 TXPOWER_TO_DEV(control->power_level)); 1548 TXPOWER_TO_DEV(control->power_level));
1549 */
1549 rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1); 1550 rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
1550 rt2x00_desc_write(txd, 5, word); 1551 rt2x00_desc_write(txd, 5, word);
1551 1552
@@ -1637,7 +1638,7 @@ static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
1637 return 0; 1638 return 0;
1638 } 1639 }
1639 1640
1640 if (rt2x00dev->rx_status.phymode == MODE_IEEE80211A) { 1641 if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
1641 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) 1642 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
1642 offset += 14; 1643 offset += 14;
1643 1644
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 4b5bde8b53de..9cbc879da037 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -439,13 +439,13 @@ static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
439 case ANTENNA_HW_DIVERSITY: 439 case ANTENNA_HW_DIVERSITY:
440 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2); 440 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
441 temp = !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags) 441 temp = !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags)
442 && (rt2x00dev->curr_hwmode != HWMODE_A); 442 && (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ);
443 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp); 443 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp);
444 break; 444 break;
445 case ANTENNA_A: 445 case ANTENNA_A:
446 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 446 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
447 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); 447 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
448 if (rt2x00dev->curr_hwmode == HWMODE_A) 448 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
449 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); 449 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
450 else 450 else
451 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); 451 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
@@ -460,7 +460,7 @@ static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
460 case ANTENNA_B: 460 case ANTENNA_B:
461 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 461 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
462 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); 462 rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
463 if (rt2x00dev->curr_hwmode == HWMODE_A) 463 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
464 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); 464 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
465 else 465 else
466 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); 466 rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
@@ -555,7 +555,7 @@ static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev,
555 unsigned int i; 555 unsigned int i;
556 u32 reg; 556 u32 reg;
557 557
558 if (rt2x00dev->curr_hwmode == HWMODE_A) { 558 if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
559 sel = antenna_sel_a; 559 sel = antenna_sel_a;
560 lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags); 560 lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
561 } else { 561 } else {
@@ -569,10 +569,9 @@ static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev,
569 rt73usb_register_read(rt2x00dev, PHY_CSR0, &reg); 569 rt73usb_register_read(rt2x00dev, PHY_CSR0, &reg);
570 570
571 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG, 571 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
572 (rt2x00dev->curr_hwmode == HWMODE_B || 572 (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ));
573 rt2x00dev->curr_hwmode == HWMODE_G));
574 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A, 573 rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
575 (rt2x00dev->curr_hwmode == HWMODE_A)); 574 (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ));
576 575
577 rt73usb_register_write(rt2x00dev, PHY_CSR0, reg); 576 rt73usb_register_write(rt2x00dev, PHY_CSR0, reg);
578 577
@@ -644,9 +643,9 @@ static void rt73usb_enable_led(struct rt2x00_dev *rt2x00dev)
644 643
645 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_RADIO_STATUS, 1); 644 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_RADIO_STATUS, 1);
646 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_A_STATUS, 645 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_A_STATUS,
647 (rt2x00dev->rx_status.phymode == MODE_IEEE80211A)); 646 (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ));
648 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_BG_STATUS, 647 rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_BG_STATUS,
649 (rt2x00dev->rx_status.phymode != MODE_IEEE80211A)); 648 (rt2x00dev->rx_status.band != IEEE80211_BAND_5GHZ));
650 649
651 rt2x00usb_vendor_request_sw(rt2x00dev, USB_LED_CONTROL, 0x0000, 650 rt2x00usb_vendor_request_sw(rt2x00dev, USB_LED_CONTROL, 0x0000,
652 rt2x00dev->led_reg, REGISTER_TIMEOUT); 651 rt2x00dev->led_reg, REGISTER_TIMEOUT);
@@ -736,7 +735,7 @@ static void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev)
736 /* 735 /*
737 * Determine r17 bounds. 736 * Determine r17 bounds.
738 */ 737 */
739 if (rt2x00dev->rx_status.phymode == MODE_IEEE80211A) { 738 if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
740 low_bound = 0x28; 739 low_bound = 0x28;
741 up_bound = 0x48; 740 up_bound = 0x48;
742 741
@@ -1278,8 +1277,10 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1278 rt2x00_desc_write(txd, 2, word); 1277 rt2x00_desc_write(txd, 2, word);
1279 1278
1280 rt2x00_desc_read(txd, 5, &word); 1279 rt2x00_desc_read(txd, 5, &word);
1280/* XXX: removed for now
1281 rt2x00_set_field32(&word, TXD_W5_TX_POWER, 1281 rt2x00_set_field32(&word, TXD_W5_TX_POWER,
1282 TXPOWER_TO_DEV(control->power_level)); 1282 TXPOWER_TO_DEV(control->power_level));
1283 */
1283 rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1); 1284 rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
1284 rt2x00_desc_write(txd, 5, word); 1285 rt2x00_desc_write(txd, 5, word);
1285 1286
@@ -1370,7 +1371,7 @@ static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
1370 return 0; 1371 return 0;
1371 } 1372 }
1372 1373
1373 if (rt2x00dev->rx_status.phymode == MODE_IEEE80211A) { 1374 if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
1374 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) { 1375 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
1375 if (lna == 3 || lna == 2) 1376 if (lna == 3 || lna == 2)
1376 offset += 10; 1377 offset += 10;
diff --git a/drivers/net/wireless/rtl8180.h b/drivers/net/wireless/rtl8180.h
index 2cbfe3c8081f..082a11f93beb 100644
--- a/drivers/net/wireless/rtl8180.h
+++ b/drivers/net/wireless/rtl8180.h
@@ -102,7 +102,7 @@ struct rtl8180_priv {
102 struct rtl8180_tx_ring tx_ring[4]; 102 struct rtl8180_tx_ring tx_ring[4];
103 struct ieee80211_channel channels[14]; 103 struct ieee80211_channel channels[14];
104 struct ieee80211_rate rates[12]; 104 struct ieee80211_rate rates[12];
105 struct ieee80211_hw_mode modes[2]; 105 struct ieee80211_supported_band band;
106 struct pci_dev *pdev; 106 struct pci_dev *pdev;
107 u32 rx_conf; 107 u32 rx_conf;
108 108
diff --git a/drivers/net/wireless/rtl8180_dev.c b/drivers/net/wireless/rtl8180_dev.c
index 5e9a8ace0d81..d0928c91c21c 100644
--- a/drivers/net/wireless/rtl8180_dev.c
+++ b/drivers/net/wireless/rtl8180_dev.c
@@ -49,6 +49,41 @@ static struct pci_device_id rtl8180_table[] __devinitdata = {
49 49
50MODULE_DEVICE_TABLE(pci, rtl8180_table); 50MODULE_DEVICE_TABLE(pci, rtl8180_table);
51 51
52static const struct ieee80211_rate rtl818x_rates[] = {
53 { .bitrate = 10, .hw_value = 0, },
54 { .bitrate = 20, .hw_value = 1, },
55 { .bitrate = 55, .hw_value = 2, },
56 { .bitrate = 110, .hw_value = 3, },
57 { .bitrate = 60, .hw_value = 4, },
58 { .bitrate = 90, .hw_value = 5, },
59 { .bitrate = 120, .hw_value = 6, },
60 { .bitrate = 180, .hw_value = 7, },
61 { .bitrate = 240, .hw_value = 8, },
62 { .bitrate = 360, .hw_value = 9, },
63 { .bitrate = 480, .hw_value = 10, },
64 { .bitrate = 540, .hw_value = 11, },
65};
66
67static const struct ieee80211_channel rtl818x_channels[] = {
68 { .center_freq = 2412 },
69 { .center_freq = 2417 },
70 { .center_freq = 2422 },
71 { .center_freq = 2427 },
72 { .center_freq = 2432 },
73 { .center_freq = 2437 },
74 { .center_freq = 2442 },
75 { .center_freq = 2447 },
76 { .center_freq = 2452 },
77 { .center_freq = 2457 },
78 { .center_freq = 2462 },
79 { .center_freq = 2467 },
80 { .center_freq = 2472 },
81 { .center_freq = 2484 },
82};
83
84
85
86
52void rtl8180_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data) 87void rtl8180_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data)
53{ 88{
54 struct rtl8180_priv *priv = dev->priv; 89 struct rtl8180_priv *priv = dev->priv;
@@ -99,10 +134,10 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev)
99 /* TODO: improve signal/rssi reporting */ 134 /* TODO: improve signal/rssi reporting */
100 rx_status.signal = flags2 & 0xFF; 135 rx_status.signal = flags2 & 0xFF;
101 rx_status.ssi = (flags2 >> 8) & 0x7F; 136 rx_status.ssi = (flags2 >> 8) & 0x7F;
102 rx_status.rate = (flags >> 20) & 0xF; 137 /* XXX: is this correct? */
103 rx_status.freq = dev->conf.freq; 138 rx_status.rate_idx = (flags >> 20) & 0xF;
104 rx_status.channel = dev->conf.channel; 139 rx_status.freq = dev->conf.channel->center_freq;
105 rx_status.phymode = dev->conf.phymode; 140 rx_status.band = dev->conf.channel->band;
106 rx_status.mactime = le64_to_cpu(entry->tsft); 141 rx_status.mactime = le64_to_cpu(entry->tsft);
107 rx_status.flag |= RX_FLAG_TSFT; 142 rx_status.flag |= RX_FLAG_TSFT;
108 if (flags & RTL8180_RX_DESC_FLAG_CRC32_ERR) 143 if (flags & RTL8180_RX_DESC_FLAG_CRC32_ERR)
@@ -223,8 +258,9 @@ static int rtl8180_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
223 skb->len, PCI_DMA_TODEVICE); 258 skb->len, PCI_DMA_TODEVICE);
224 259
225 tx_flags = RTL8180_TX_DESC_FLAG_OWN | RTL8180_TX_DESC_FLAG_FS | 260 tx_flags = RTL8180_TX_DESC_FLAG_OWN | RTL8180_TX_DESC_FLAG_FS |
226 RTL8180_TX_DESC_FLAG_LS | (control->tx_rate << 24) | 261 RTL8180_TX_DESC_FLAG_LS |
227 (control->rts_cts_rate << 19) | skb->len; 262 (control->tx_rate->hw_value << 24) |
263 (control->rts_cts_rate->hw_value << 19) | skb->len;
228 264
229 if (priv->r8185) 265 if (priv->r8185)
230 tx_flags |= RTL8180_TX_DESC_FLAG_DMA | 266 tx_flags |= RTL8180_TX_DESC_FLAG_DMA |
@@ -246,9 +282,9 @@ static int rtl8180_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
246 unsigned int remainder; 282 unsigned int remainder;
247 283
248 plcp_len = DIV_ROUND_UP(16 * (skb->len + 4), 284 plcp_len = DIV_ROUND_UP(16 * (skb->len + 4),
249 (control->rate->rate * 2) / 10); 285 (control->tx_rate->bitrate * 2) / 10);
250 remainder = (16 * (skb->len + 4)) % 286 remainder = (16 * (skb->len + 4)) %
251 ((control->rate->rate * 2) / 10); 287 ((control->tx_rate->bitrate * 2) / 10);
252 if (remainder > 0 && remainder <= 6) 288 if (remainder > 0 && remainder <= 6)
253 plcp_len |= 1 << 15; 289 plcp_len |= 1 << 15;
254 } 290 }
@@ -261,8 +297,8 @@ static int rtl8180_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
261 entry->plcp_len = cpu_to_le16(plcp_len); 297 entry->plcp_len = cpu_to_le16(plcp_len);
262 entry->tx_buf = cpu_to_le32(mapping); 298 entry->tx_buf = cpu_to_le32(mapping);
263 entry->frame_len = cpu_to_le32(skb->len); 299 entry->frame_len = cpu_to_le32(skb->len);
264 entry->flags2 = control->alt_retry_rate != -1 ? 300 entry->flags2 = control->alt_retry_rate != NULL ?
265 control->alt_retry_rate << 4 : 0; 301 control->alt_retry_rate->bitrate << 4 : 0;
266 entry->retry_limit = control->retry_limit; 302 entry->retry_limit = control->retry_limit;
267 entry->flags = cpu_to_le32(tx_flags); 303 entry->flags = cpu_to_le32(tx_flags);
268 __skb_queue_tail(&ring->queue, skb); 304 __skb_queue_tail(&ring->queue, skb);
@@ -838,19 +874,19 @@ static int __devinit rtl8180_probe(struct pci_dev *pdev,
838 goto err_free_dev; 874 goto err_free_dev;
839 } 875 }
840 876
877 BUILD_BUG_ON(sizeof(priv->channels) != sizeof(rtl818x_channels));
878 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(rtl818x_rates));
879
841 memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels)); 880 memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels));
842 memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates)); 881 memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates));
843 priv->modes[0].mode = MODE_IEEE80211G; 882
844 priv->modes[0].num_rates = ARRAY_SIZE(rtl818x_rates); 883 priv->band.band = IEEE80211_BAND_2GHZ;
845 priv->modes[0].rates = priv->rates; 884 priv->band.channels = priv->channels;
846 priv->modes[0].num_channels = ARRAY_SIZE(rtl818x_channels); 885 priv->band.n_channels = ARRAY_SIZE(rtl818x_channels);
847 priv->modes[0].channels = priv->channels; 886 priv->band.bitrates = priv->rates;
848 priv->modes[1].mode = MODE_IEEE80211B; 887 priv->band.n_bitrates = 4;
849 priv->modes[1].num_rates = 4; 888 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
850 priv->modes[1].rates = priv->rates; 889
851 priv->modes[1].num_channels = ARRAY_SIZE(rtl818x_channels);
852 priv->modes[1].channels = priv->channels;
853 priv->mode = IEEE80211_IF_TYPE_INVALID;
854 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | 890 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
855 IEEE80211_HW_RX_INCLUDES_FCS; 891 IEEE80211_HW_RX_INCLUDES_FCS;
856 dev->queues = 1; 892 dev->queues = 1;
@@ -879,15 +915,10 @@ static int __devinit rtl8180_probe(struct pci_dev *pdev,
879 915
880 priv->r8185 = reg & RTL818X_TX_CONF_R8185_ABC; 916 priv->r8185 = reg & RTL818X_TX_CONF_R8185_ABC;
881 if (priv->r8185) { 917 if (priv->r8185) {
882 if ((err = ieee80211_register_hwmode(dev, &priv->modes[0]))) 918 priv->band.n_bitrates = ARRAY_SIZE(rtl818x_rates);
883 goto err_iounmap;
884
885 pci_try_set_mwi(pdev); 919 pci_try_set_mwi(pdev);
886 } 920 }
887 921
888 if ((err = ieee80211_register_hwmode(dev, &priv->modes[1])))
889 goto err_iounmap;
890
891 eeprom.data = dev; 922 eeprom.data = dev;
892 eeprom.register_read = rtl8180_eeprom_register_read; 923 eeprom.register_read = rtl8180_eeprom_register_read;
893 eeprom.register_write = rtl8180_eeprom_register_write; 924 eeprom.register_write = rtl8180_eeprom_register_write;
@@ -950,8 +981,8 @@ static int __devinit rtl8180_probe(struct pci_dev *pdev,
950 for (i = 0; i < 14; i += 2) { 981 for (i = 0; i < 14; i += 2) {
951 u16 txpwr; 982 u16 txpwr;
952 eeprom_93cx6_read(&eeprom, 0x10 + (i >> 1), &txpwr); 983 eeprom_93cx6_read(&eeprom, 0x10 + (i >> 1), &txpwr);
953 priv->channels[i].val = txpwr & 0xFF; 984 priv->channels[i].hw_value = txpwr & 0xFF;
954 priv->channels[i + 1].val = txpwr >> 8; 985 priv->channels[i + 1].hw_value = txpwr >> 8;
955 } 986 }
956 987
957 /* OFDM TX power */ 988 /* OFDM TX power */
@@ -959,8 +990,8 @@ static int __devinit rtl8180_probe(struct pci_dev *pdev,
959 for (i = 0; i < 14; i += 2) { 990 for (i = 0; i < 14; i += 2) {
960 u16 txpwr; 991 u16 txpwr;
961 eeprom_93cx6_read(&eeprom, 0x20 + (i >> 1), &txpwr); 992 eeprom_93cx6_read(&eeprom, 0x20 + (i >> 1), &txpwr);
962 priv->channels[i].val |= (txpwr & 0xFF) << 8; 993 priv->channels[i].hw_value |= (txpwr & 0xFF) << 8;
963 priv->channels[i + 1].val |= txpwr & 0xFF00; 994 priv->channels[i + 1].hw_value |= txpwr & 0xFF00;
964 } 995 }
965 } 996 }
966 997
diff --git a/drivers/net/wireless/rtl8180_grf5101.c b/drivers/net/wireless/rtl8180_grf5101.c
index 8293e19c4c59..5d47935dbac3 100644
--- a/drivers/net/wireless/rtl8180_grf5101.c
+++ b/drivers/net/wireless/rtl8180_grf5101.c
@@ -73,8 +73,9 @@ static void grf5101_rf_set_channel(struct ieee80211_hw *dev,
73 struct ieee80211_conf *conf) 73 struct ieee80211_conf *conf)
74{ 74{
75 struct rtl8180_priv *priv = dev->priv; 75 struct rtl8180_priv *priv = dev->priv;
76 u32 txpw = priv->channels[conf->channel - 1].val & 0xFF; 76 int channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
77 u32 chan = conf->channel - 1; 77 u32 txpw = priv->channels[channel - 1].hw_value & 0xFF;
78 u32 chan = channel - 1;
78 79
79 /* set TX power */ 80 /* set TX power */
80 write_grf5101(dev, 0x15, 0x0); 81 write_grf5101(dev, 0x15, 0x0);
diff --git a/drivers/net/wireless/rtl8180_max2820.c b/drivers/net/wireless/rtl8180_max2820.c
index 98fe9fd64968..a34dfd382b6d 100644
--- a/drivers/net/wireless/rtl8180_max2820.c
+++ b/drivers/net/wireless/rtl8180_max2820.c
@@ -78,8 +78,9 @@ static void max2820_rf_set_channel(struct ieee80211_hw *dev,
78 struct ieee80211_conf *conf) 78 struct ieee80211_conf *conf)
79{ 79{
80 struct rtl8180_priv *priv = dev->priv; 80 struct rtl8180_priv *priv = dev->priv;
81 unsigned int chan_idx = conf ? conf->channel - 1 : 0; 81 int channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
82 u32 txpw = priv->channels[chan_idx].val & 0xFF; 82 unsigned int chan_idx = channel - 1;
83 u32 txpw = priv->channels[chan_idx].hw_value & 0xFF;
83 u32 chan = max2820_chan[chan_idx]; 84 u32 chan = max2820_chan[chan_idx];
84 85
85 /* While philips SA2400 drive the PA bias from 86 /* While philips SA2400 drive the PA bias from
diff --git a/drivers/net/wireless/rtl8180_rtl8225.c b/drivers/net/wireless/rtl8180_rtl8225.c
index ef3832bee85c..cd22781728a9 100644
--- a/drivers/net/wireless/rtl8180_rtl8225.c
+++ b/drivers/net/wireless/rtl8180_rtl8225.c
@@ -261,8 +261,8 @@ static void rtl8225_rf_set_tx_power(struct ieee80211_hw *dev, int channel)
261 u32 reg; 261 u32 reg;
262 int i; 262 int i;
263 263
264 cck_power = priv->channels[channel - 1].val & 0xFF; 264 cck_power = priv->channels[channel - 1].hw_value & 0xFF;
265 ofdm_power = priv->channels[channel - 1].val >> 8; 265 ofdm_power = priv->channels[channel - 1].hw_value >> 8;
266 266
267 cck_power = min(cck_power, (u8)35); 267 cck_power = min(cck_power, (u8)35);
268 ofdm_power = min(ofdm_power, (u8)35); 268 ofdm_power = min(ofdm_power, (u8)35);
@@ -476,8 +476,8 @@ static void rtl8225z2_rf_set_tx_power(struct ieee80211_hw *dev, int channel)
476 const u8 *tmp; 476 const u8 *tmp;
477 int i; 477 int i;
478 478
479 cck_power = priv->channels[channel - 1].val & 0xFF; 479 cck_power = priv->channels[channel - 1].hw_value & 0xFF;
480 ofdm_power = priv->channels[channel - 1].val >> 8; 480 ofdm_power = priv->channels[channel - 1].hw_value >> 8;
481 481
482 if (channel == 14) 482 if (channel == 14)
483 tmp = rtl8225z2_tx_power_cck_ch14; 483 tmp = rtl8225z2_tx_power_cck_ch14;
@@ -716,13 +716,14 @@ static void rtl8225_rf_set_channel(struct ieee80211_hw *dev,
716 struct ieee80211_conf *conf) 716 struct ieee80211_conf *conf)
717{ 717{
718 struct rtl8180_priv *priv = dev->priv; 718 struct rtl8180_priv *priv = dev->priv;
719 int chan = ieee80211_frequency_to_channel(conf->channel->center_freq);
719 720
720 if (priv->rf->init == rtl8225_rf_init) 721 if (priv->rf->init == rtl8225_rf_init)
721 rtl8225_rf_set_tx_power(dev, conf->channel); 722 rtl8225_rf_set_tx_power(dev, chan);
722 else 723 else
723 rtl8225z2_rf_set_tx_power(dev, conf->channel); 724 rtl8225z2_rf_set_tx_power(dev, chan);
724 725
725 rtl8225_write(dev, 0x7, rtl8225_chan[conf->channel - 1]); 726 rtl8225_write(dev, 0x7, rtl8225_chan[chan - 1]);
726 msleep(10); 727 msleep(10);
727 728
728 if (conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME) { 729 if (conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME) {
diff --git a/drivers/net/wireless/rtl8180_sa2400.c b/drivers/net/wireless/rtl8180_sa2400.c
index e08ace7b1cb7..0311b4ea124c 100644
--- a/drivers/net/wireless/rtl8180_sa2400.c
+++ b/drivers/net/wireless/rtl8180_sa2400.c
@@ -80,8 +80,9 @@ static void sa2400_rf_set_channel(struct ieee80211_hw *dev,
80 struct ieee80211_conf *conf) 80 struct ieee80211_conf *conf)
81{ 81{
82 struct rtl8180_priv *priv = dev->priv; 82 struct rtl8180_priv *priv = dev->priv;
83 u32 txpw = priv->channels[conf->channel - 1].val & 0xFF; 83 int channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
84 u32 chan = sa2400_chan[conf->channel - 1]; 84 u32 txpw = priv->channels[channel - 1].hw_value & 0xFF;
85 u32 chan = sa2400_chan[channel - 1];
85 86
86 write_sa2400(dev, 7, txpw); 87 write_sa2400(dev, 7, txpw);
87 88
diff --git a/drivers/net/wireless/rtl8187.h b/drivers/net/wireless/rtl8187.h
index 8680a0b6433c..076d88b6db0e 100644
--- a/drivers/net/wireless/rtl8187.h
+++ b/drivers/net/wireless/rtl8187.h
@@ -71,7 +71,7 @@ struct rtl8187_priv {
71 /* rtl8187 specific */ 71 /* rtl8187 specific */
72 struct ieee80211_channel channels[14]; 72 struct ieee80211_channel channels[14];
73 struct ieee80211_rate rates[12]; 73 struct ieee80211_rate rates[12];
74 struct ieee80211_hw_mode modes[2]; 74 struct ieee80211_supported_band band;
75 struct usb_device *udev; 75 struct usb_device *udev;
76 u32 rx_conf; 76 u32 rx_conf;
77 u16 txpwr_base; 77 u16 txpwr_base;
diff --git a/drivers/net/wireless/rtl8187_dev.c b/drivers/net/wireless/rtl8187_dev.c
index f44505994a0e..6ef67990692d 100644
--- a/drivers/net/wireless/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl8187_dev.c
@@ -45,6 +45,38 @@ static struct usb_device_id rtl8187_table[] __devinitdata = {
45 45
46MODULE_DEVICE_TABLE(usb, rtl8187_table); 46MODULE_DEVICE_TABLE(usb, rtl8187_table);
47 47
48static const struct ieee80211_rate rtl818x_rates[] = {
49 { .bitrate = 10, .hw_value = 0, },
50 { .bitrate = 20, .hw_value = 1, },
51 { .bitrate = 55, .hw_value = 2, },
52 { .bitrate = 110, .hw_value = 3, },
53 { .bitrate = 60, .hw_value = 4, },
54 { .bitrate = 90, .hw_value = 5, },
55 { .bitrate = 120, .hw_value = 6, },
56 { .bitrate = 180, .hw_value = 7, },
57 { .bitrate = 240, .hw_value = 8, },
58 { .bitrate = 360, .hw_value = 9, },
59 { .bitrate = 480, .hw_value = 10, },
60 { .bitrate = 540, .hw_value = 11, },
61};
62
63static const struct ieee80211_channel rtl818x_channels[] = {
64 { .center_freq = 2412 },
65 { .center_freq = 2417 },
66 { .center_freq = 2422 },
67 { .center_freq = 2427 },
68 { .center_freq = 2432 },
69 { .center_freq = 2437 },
70 { .center_freq = 2442 },
71 { .center_freq = 2447 },
72 { .center_freq = 2452 },
73 { .center_freq = 2457 },
74 { .center_freq = 2462 },
75 { .center_freq = 2467 },
76 { .center_freq = 2472 },
77 { .center_freq = 2484 },
78};
79
48static void rtl8187_iowrite_async_cb(struct urb *urb) 80static void rtl8187_iowrite_async_cb(struct urb *urb)
49{ 81{
50 kfree(urb->context); 82 kfree(urb->context);
@@ -146,8 +178,8 @@ static int rtl8187_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
146 178
147 flags = skb->len; 179 flags = skb->len;
148 flags |= RTL8187_TX_FLAG_NO_ENCRYPT; 180 flags |= RTL8187_TX_FLAG_NO_ENCRYPT;
149 flags |= control->rts_cts_rate << 19; 181 flags |= control->rts_cts_rate->hw_value << 19;
150 flags |= control->tx_rate << 24; 182 flags |= control->tx_rate->hw_value << 24;
151 if (ieee80211_get_morefrag((struct ieee80211_hdr *)skb->data)) 183 if (ieee80211_get_morefrag((struct ieee80211_hdr *)skb->data))
152 flags |= RTL8187_TX_FLAG_MORE_FRAG; 184 flags |= RTL8187_TX_FLAG_MORE_FRAG;
153 if (control->flags & IEEE80211_TXCTL_USE_RTS_CTS) { 185 if (control->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
@@ -225,10 +257,9 @@ static void rtl8187_rx_cb(struct urb *urb)
225 rx_status.antenna = (hdr->signal >> 7) & 1; 257 rx_status.antenna = (hdr->signal >> 7) & 1;
226 rx_status.signal = 64 - min(hdr->noise, (u8)64); 258 rx_status.signal = 64 - min(hdr->noise, (u8)64);
227 rx_status.ssi = signal; 259 rx_status.ssi = signal;
228 rx_status.rate = rate; 260 rx_status.rate_idx = rate;
229 rx_status.freq = dev->conf.freq; 261 rx_status.freq = dev->conf.channel->center_freq;
230 rx_status.channel = dev->conf.channel; 262 rx_status.band = dev->conf.channel->band;
231 rx_status.phymode = dev->conf.phymode;
232 rx_status.mactime = le64_to_cpu(hdr->mac_time); 263 rx_status.mactime = le64_to_cpu(hdr->mac_time);
233 rx_status.flag |= RX_FLAG_TSFT; 264 rx_status.flag |= RX_FLAG_TSFT;
234 if (flags & (1 << 13)) 265 if (flags & (1 << 13))
@@ -682,19 +713,22 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
682 usb_get_dev(udev); 713 usb_get_dev(udev);
683 714
684 skb_queue_head_init(&priv->rx_queue); 715 skb_queue_head_init(&priv->rx_queue);
716
717 BUILD_BUG_ON(sizeof(priv->channels) != sizeof(rtl818x_channels));
718 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(rtl818x_rates));
719
685 memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels)); 720 memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels));
686 memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates)); 721 memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates));
687 priv->map = (struct rtl818x_csr *)0xFF00; 722 priv->map = (struct rtl818x_csr *)0xFF00;
688 priv->modes[0].mode = MODE_IEEE80211G; 723
689 priv->modes[0].num_rates = ARRAY_SIZE(rtl818x_rates); 724 priv->band.band = IEEE80211_BAND_2GHZ;
690 priv->modes[0].rates = priv->rates; 725 priv->band.channels = priv->channels;
691 priv->modes[0].num_channels = ARRAY_SIZE(rtl818x_channels); 726 priv->band.n_channels = ARRAY_SIZE(rtl818x_channels);
692 priv->modes[0].channels = priv->channels; 727 priv->band.bitrates = priv->rates;
693 priv->modes[1].mode = MODE_IEEE80211B; 728 priv->band.n_bitrates = ARRAY_SIZE(rtl818x_rates);
694 priv->modes[1].num_rates = 4; 729 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
695 priv->modes[1].rates = priv->rates; 730
696 priv->modes[1].num_channels = ARRAY_SIZE(rtl818x_channels); 731
697 priv->modes[1].channels = priv->channels;
698 priv->mode = IEEE80211_IF_TYPE_MNTR; 732 priv->mode = IEEE80211_IF_TYPE_MNTR;
699 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | 733 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
700 IEEE80211_HW_RX_INCLUDES_FCS; 734 IEEE80211_HW_RX_INCLUDES_FCS;
@@ -703,10 +737,6 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
703 dev->max_rssi = 65; 737 dev->max_rssi = 65;
704 dev->max_signal = 64; 738 dev->max_signal = 64;
705 739
706 for (i = 0; i < 2; i++)
707 if ((err = ieee80211_register_hwmode(dev, &priv->modes[i])))
708 goto err_free_dev;
709
710 eeprom.data = dev; 740 eeprom.data = dev;
711 eeprom.register_read = rtl8187_eeprom_register_read; 741 eeprom.register_read = rtl8187_eeprom_register_read;
712 eeprom.register_write = rtl8187_eeprom_register_write; 742 eeprom.register_write = rtl8187_eeprom_register_write;
@@ -730,20 +760,20 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
730 for (i = 0; i < 3; i++) { 760 for (i = 0; i < 3; i++) {
731 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_1 + i, 761 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_1 + i,
732 &txpwr); 762 &txpwr);
733 (*channel++).val = txpwr & 0xFF; 763 (*channel++).hw_value = txpwr & 0xFF;
734 (*channel++).val = txpwr >> 8; 764 (*channel++).hw_value = txpwr >> 8;
735 } 765 }
736 for (i = 0; i < 2; i++) { 766 for (i = 0; i < 2; i++) {
737 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_4 + i, 767 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_4 + i,
738 &txpwr); 768 &txpwr);
739 (*channel++).val = txpwr & 0xFF; 769 (*channel++).hw_value = txpwr & 0xFF;
740 (*channel++).val = txpwr >> 8; 770 (*channel++).hw_value = txpwr >> 8;
741 } 771 }
742 for (i = 0; i < 2; i++) { 772 for (i = 0; i < 2; i++) {
743 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_6 + i, 773 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_6 + i,
744 &txpwr); 774 &txpwr);
745 (*channel++).val = txpwr & 0xFF; 775 (*channel++).hw_value = txpwr & 0xFF;
746 (*channel++).val = txpwr >> 8; 776 (*channel++).hw_value = txpwr >> 8;
747 } 777 }
748 778
749 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_BASE, 779 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_BASE,
diff --git a/drivers/net/wireless/rtl8187_rtl8225.c b/drivers/net/wireless/rtl8187_rtl8225.c
index b713de17ba0a..9146387b4c5e 100644
--- a/drivers/net/wireless/rtl8187_rtl8225.c
+++ b/drivers/net/wireless/rtl8187_rtl8225.c
@@ -283,8 +283,8 @@ static void rtl8225_rf_set_tx_power(struct ieee80211_hw *dev, int channel)
283 u32 reg; 283 u32 reg;
284 int i; 284 int i;
285 285
286 cck_power = priv->channels[channel - 1].val & 0xF; 286 cck_power = priv->channels[channel - 1].hw_value & 0xF;
287 ofdm_power = priv->channels[channel - 1].val >> 4; 287 ofdm_power = priv->channels[channel - 1].hw_value >> 4;
288 288
289 cck_power = min(cck_power, (u8)11); 289 cck_power = min(cck_power, (u8)11);
290 ofdm_power = min(ofdm_power, (u8)35); 290 ofdm_power = min(ofdm_power, (u8)35);
@@ -500,8 +500,8 @@ static void rtl8225z2_rf_set_tx_power(struct ieee80211_hw *dev, int channel)
500 u32 reg; 500 u32 reg;
501 int i; 501 int i;
502 502
503 cck_power = priv->channels[channel - 1].val & 0xF; 503 cck_power = priv->channels[channel - 1].hw_value & 0xF;
504 ofdm_power = priv->channels[channel - 1].val >> 4; 504 ofdm_power = priv->channels[channel - 1].hw_value >> 4;
505 505
506 cck_power = min(cck_power, (u8)15); 506 cck_power = min(cck_power, (u8)15);
507 cck_power += priv->txpwr_base & 0xF; 507 cck_power += priv->txpwr_base & 0xF;
@@ -735,13 +735,14 @@ static void rtl8225_rf_set_channel(struct ieee80211_hw *dev,
735 struct ieee80211_conf *conf) 735 struct ieee80211_conf *conf)
736{ 736{
737 struct rtl8187_priv *priv = dev->priv; 737 struct rtl8187_priv *priv = dev->priv;
738 int chan = ieee80211_frequency_to_channel(conf->channel->center_freq);
738 739
739 if (priv->rf->init == rtl8225_rf_init) 740 if (priv->rf->init == rtl8225_rf_init)
740 rtl8225_rf_set_tx_power(dev, conf->channel); 741 rtl8225_rf_set_tx_power(dev, chan);
741 else 742 else
742 rtl8225z2_rf_set_tx_power(dev, conf->channel); 743 rtl8225z2_rf_set_tx_power(dev, chan);
743 744
744 rtl8225_write(dev, 0x7, rtl8225_chan[conf->channel - 1]); 745 rtl8225_write(dev, 0x7, rtl8225_chan[chan - 1]);
745 msleep(10); 746 msleep(10);
746} 747}
747 748
diff --git a/drivers/net/wireless/rtl818x.h b/drivers/net/wireless/rtl818x.h
index 1e7d6f8278d7..4f7d38f506eb 100644
--- a/drivers/net/wireless/rtl818x.h
+++ b/drivers/net/wireless/rtl818x.h
@@ -175,74 +175,4 @@ struct rtl818x_rf_ops {
175 void (*set_chan)(struct ieee80211_hw *, struct ieee80211_conf *); 175 void (*set_chan)(struct ieee80211_hw *, struct ieee80211_conf *);
176}; 176};
177 177
178static const struct ieee80211_rate rtl818x_rates[] = {
179 { .rate = 10,
180 .val = 0,
181 .flags = IEEE80211_RATE_CCK },
182 { .rate = 20,
183 .val = 1,
184 .flags = IEEE80211_RATE_CCK },
185 { .rate = 55,
186 .val = 2,
187 .flags = IEEE80211_RATE_CCK },
188 { .rate = 110,
189 .val = 3,
190 .flags = IEEE80211_RATE_CCK },
191 { .rate = 60,
192 .val = 4,
193 .flags = IEEE80211_RATE_OFDM },
194 { .rate = 90,
195 .val = 5,
196 .flags = IEEE80211_RATE_OFDM },
197 { .rate = 120,
198 .val = 6,
199 .flags = IEEE80211_RATE_OFDM },
200 { .rate = 180,
201 .val = 7,
202 .flags = IEEE80211_RATE_OFDM },
203 { .rate = 240,
204 .val = 8,
205 .flags = IEEE80211_RATE_OFDM },
206 { .rate = 360,
207 .val = 9,
208 .flags = IEEE80211_RATE_OFDM },
209 { .rate = 480,
210 .val = 10,
211 .flags = IEEE80211_RATE_OFDM },
212 { .rate = 540,
213 .val = 11,
214 .flags = IEEE80211_RATE_OFDM },
215};
216
217static const struct ieee80211_channel rtl818x_channels[] = {
218 { .chan = 1,
219 .freq = 2412},
220 { .chan = 2,
221 .freq = 2417},
222 { .chan = 3,
223 .freq = 2422},
224 { .chan = 4,
225 .freq = 2427},
226 { .chan = 5,
227 .freq = 2432},
228 { .chan = 6,
229 .freq = 2437},
230 { .chan = 7,
231 .freq = 2442},
232 { .chan = 8,
233 .freq = 2447},
234 { .chan = 9,
235 .freq = 2452},
236 { .chan = 10,
237 .freq = 2457},
238 { .chan = 11,
239 .freq = 2462},
240 { .chan = 12,
241 .freq = 2467},
242 { .chan = 13,
243 .freq = 2472},
244 { .chan = 14,
245 .freq = 2484}
246};
247
248#endif /* RTL818X_H */ 178#endif /* RTL818X_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c
index 99e5b03b3f51..e3fba6f09455 100644
--- a/drivers/net/wireless/zd1211rw/zd_chip.c
+++ b/drivers/net/wireless/zd1211rw/zd_chip.c
@@ -986,7 +986,7 @@ static int print_fw_version(struct zd_chip *chip)
986 return 0; 986 return 0;
987} 987}
988 988
989static int set_mandatory_rates(struct zd_chip *chip, int mode) 989static int set_mandatory_rates(struct zd_chip *chip, int gmode)
990{ 990{
991 u32 rates; 991 u32 rates;
992 ZD_ASSERT(mutex_is_locked(&chip->mutex)); 992 ZD_ASSERT(mutex_is_locked(&chip->mutex));
@@ -994,17 +994,12 @@ static int set_mandatory_rates(struct zd_chip *chip, int mode)
994 * that the device is supporting. Until further notice we should try 994 * that the device is supporting. Until further notice we should try
995 * to support 802.11g also for full speed USB. 995 * to support 802.11g also for full speed USB.
996 */ 996 */
997 switch (mode) { 997 if (!gmode)
998 case MODE_IEEE80211B:
999 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M; 998 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M;
1000 break; 999 else
1001 case MODE_IEEE80211G:
1002 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M| 1000 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M|
1003 CR_RATE_6M|CR_RATE_12M|CR_RATE_24M; 1001 CR_RATE_6M|CR_RATE_12M|CR_RATE_24M;
1004 break; 1002
1005 default:
1006 return -EINVAL;
1007 }
1008 return zd_iowrite32_locked(chip, rates, CR_MANDATORY_RATE_TBL); 1003 return zd_iowrite32_locked(chip, rates, CR_MANDATORY_RATE_TBL);
1009} 1004}
1010 1005
@@ -1108,7 +1103,7 @@ int zd_chip_init_hw(struct zd_chip *chip)
1108 * It might be discussed, whether we should suppport pure b mode for 1103 * It might be discussed, whether we should suppport pure b mode for
1109 * full speed USB. 1104 * full speed USB.
1110 */ 1105 */
1111 r = set_mandatory_rates(chip, MODE_IEEE80211G); 1106 r = set_mandatory_rates(chip, 1);
1112 if (r) 1107 if (r)
1113 goto out; 1108 goto out;
1114 /* Disabling interrupts is certainly a smart thing here. 1109 /* Disabling interrupts is certainly a smart thing here.
diff --git a/drivers/net/wireless/zd1211rw/zd_ieee80211.c b/drivers/net/wireless/zd1211rw/zd_ieee80211.c
index 7c277ec43f79..d8dc41ec0e5d 100644
--- a/drivers/net/wireless/zd1211rw/zd_ieee80211.c
+++ b/drivers/net/wireless/zd1211rw/zd_ieee80211.c
@@ -65,16 +65,14 @@ static const struct channel_range *zd_channel_range(u8 regdomain)
65 65
66static void unmask_bg_channels(struct ieee80211_hw *hw, 66static void unmask_bg_channels(struct ieee80211_hw *hw,
67 const struct channel_range *range, 67 const struct channel_range *range,
68 struct ieee80211_hw_mode *mode) 68 struct ieee80211_supported_band *sband)
69{ 69{
70 u8 channel; 70 u8 channel;
71 71
72 for (channel = range->start; channel < range->end; channel++) { 72 for (channel = range->start; channel < range->end; channel++) {
73 struct ieee80211_channel *chan = 73 struct ieee80211_channel *chan =
74 &mode->channels[CHAN_TO_IDX(channel)]; 74 &sband->channels[CHAN_TO_IDX(channel)];
75 chan->flag |= IEEE80211_CHAN_W_SCAN | 75 chan->flags = 0;
76 IEEE80211_CHAN_W_ACTIVE_SCAN |
77 IEEE80211_CHAN_W_IBSS;
78 } 76 }
79} 77}
80 78
@@ -97,7 +95,6 @@ void zd_geo_init(struct ieee80211_hw *hw, u8 regdomain)
97 range = zd_channel_range(ZD_REGDOMAIN_FCC); 95 range = zd_channel_range(ZD_REGDOMAIN_FCC);
98 } 96 }
99 97
100 unmask_bg_channels(hw, range, &mac->modes[0]); 98 unmask_bg_channels(hw, range, &mac->band);
101 unmask_bg_channels(hw, range, &mac->modes[1]);
102} 99}
103 100
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index 76ef2d83919d..21b653458831 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -34,76 +34,61 @@
34 34
35/* This table contains the hardware specific values for the modulation rates. */ 35/* This table contains the hardware specific values for the modulation rates. */
36static const struct ieee80211_rate zd_rates[] = { 36static const struct ieee80211_rate zd_rates[] = {
37 { .rate = 10, 37 { .bitrate = 10,
38 .val = ZD_CCK_RATE_1M, 38 .hw_value = ZD_CCK_RATE_1M, },
39 .flags = IEEE80211_RATE_CCK }, 39 { .bitrate = 20,
40 { .rate = 20, 40 .hw_value = ZD_CCK_RATE_2M,
41 .val = ZD_CCK_RATE_2M, 41 .hw_value_short = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT,
42 .val2 = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT, 42 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
43 .flags = IEEE80211_RATE_CCK_2 }, 43 { .bitrate = 55,
44 { .rate = 55, 44 .hw_value = ZD_CCK_RATE_5_5M,
45 .val = ZD_CCK_RATE_5_5M, 45 .hw_value_short = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT,
46 .val2 = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT, 46 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
47 .flags = IEEE80211_RATE_CCK_2 }, 47 { .bitrate = 110,
48 { .rate = 110, 48 .hw_value = ZD_CCK_RATE_11M,
49 .val = ZD_CCK_RATE_11M, 49 .hw_value_short = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT,
50 .val2 = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT, 50 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
51 .flags = IEEE80211_RATE_CCK_2 }, 51 { .bitrate = 60,
52 { .rate = 60, 52 .hw_value = ZD_OFDM_RATE_6M,
53 .val = ZD_OFDM_RATE_6M, 53 .flags = 0 },
54 .flags = IEEE80211_RATE_OFDM }, 54 { .bitrate = 90,
55 { .rate = 90, 55 .hw_value = ZD_OFDM_RATE_9M,
56 .val = ZD_OFDM_RATE_9M, 56 .flags = 0 },
57 .flags = IEEE80211_RATE_OFDM }, 57 { .bitrate = 120,
58 { .rate = 120, 58 .hw_value = ZD_OFDM_RATE_12M,
59 .val = ZD_OFDM_RATE_12M, 59 .flags = 0 },
60 .flags = IEEE80211_RATE_OFDM }, 60 { .bitrate = 180,
61 { .rate = 180, 61 .hw_value = ZD_OFDM_RATE_18M,
62 .val = ZD_OFDM_RATE_18M, 62 .flags = 0 },
63 .flags = IEEE80211_RATE_OFDM }, 63 { .bitrate = 240,
64 { .rate = 240, 64 .hw_value = ZD_OFDM_RATE_24M,
65 .val = ZD_OFDM_RATE_24M, 65 .flags = 0 },
66 .flags = IEEE80211_RATE_OFDM }, 66 { .bitrate = 360,
67 { .rate = 360, 67 .hw_value = ZD_OFDM_RATE_36M,
68 .val = ZD_OFDM_RATE_36M, 68 .flags = 0 },
69 .flags = IEEE80211_RATE_OFDM }, 69 { .bitrate = 480,
70 { .rate = 480, 70 .hw_value = ZD_OFDM_RATE_48M,
71 .val = ZD_OFDM_RATE_48M, 71 .flags = 0 },
72 .flags = IEEE80211_RATE_OFDM }, 72 { .bitrate = 540,
73 { .rate = 540, 73 .hw_value = ZD_OFDM_RATE_54M,
74 .val = ZD_OFDM_RATE_54M, 74 .flags = 0 },
75 .flags = IEEE80211_RATE_OFDM },
76}; 75};
77 76
78static const struct ieee80211_channel zd_channels[] = { 77static const struct ieee80211_channel zd_channels[] = {
79 { .chan = 1, 78 { .center_freq = 2412, .hw_value = 1 },
80 .freq = 2412}, 79 { .center_freq = 2417, .hw_value = 2 },
81 { .chan = 2, 80 { .center_freq = 2422, .hw_value = 3 },
82 .freq = 2417}, 81 { .center_freq = 2427, .hw_value = 4 },
83 { .chan = 3, 82 { .center_freq = 2432, .hw_value = 5 },
84 .freq = 2422}, 83 { .center_freq = 2437, .hw_value = 6 },
85 { .chan = 4, 84 { .center_freq = 2442, .hw_value = 7 },
86 .freq = 2427}, 85 { .center_freq = 2447, .hw_value = 8 },
87 { .chan = 5, 86 { .center_freq = 2452, .hw_value = 9 },
88 .freq = 2432}, 87 { .center_freq = 2457, .hw_value = 10 },
89 { .chan = 6, 88 { .center_freq = 2462, .hw_value = 11 },
90 .freq = 2437}, 89 { .center_freq = 2467, .hw_value = 12 },
91 { .chan = 7, 90 { .center_freq = 2472, .hw_value = 13 },
92 .freq = 2442}, 91 { .center_freq = 2484, .hw_value = 14 },
93 { .chan = 8,
94 .freq = 2447},
95 { .chan = 9,
96 .freq = 2452},
97 { .chan = 10,
98 .freq = 2457},
99 { .chan = 11,
100 .freq = 2462},
101 { .chan = 12,
102 .freq = 2467},
103 { .chan = 13,
104 .freq = 2472},
105 { .chan = 14,
106 .freq = 2484}
107}; 92};
108 93
109static void housekeeping_init(struct zd_mac *mac); 94static void housekeeping_init(struct zd_mac *mac);
@@ -503,7 +488,9 @@ static int fill_ctrlset(struct zd_mac *mac,
503 488
504 ZD_ASSERT(frag_len <= 0xffff); 489 ZD_ASSERT(frag_len <= 0xffff);
505 490
506 cs->modulation = control->tx_rate; 491 cs->modulation = control->tx_rate->hw_value;
492 if (control->flags & IEEE80211_TXCTL_SHORT_PREAMBLE)
493 cs->modulation = control->tx_rate->hw_value_short;
507 494
508 cs->tx_length = cpu_to_le16(frag_len); 495 cs->tx_length = cpu_to_le16(frag_len);
509 496
@@ -631,6 +618,8 @@ int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
631 int bad_frame = 0; 618 int bad_frame = 0;
632 u16 fc; 619 u16 fc;
633 bool is_qos, is_4addr, need_padding; 620 bool is_qos, is_4addr, need_padding;
621 int i;
622 u8 rate;
634 623
635 if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ + 624 if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ +
636 FCS_LEN + sizeof(struct rx_status)) 625 FCS_LEN + sizeof(struct rx_status))
@@ -660,14 +649,19 @@ int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
660 } 649 }
661 } 650 }
662 651
663 stats.channel = _zd_chip_get_channel(&mac->chip); 652 stats.freq = zd_channels[_zd_chip_get_channel(&mac->chip) - 1].center_freq;
664 stats.freq = zd_channels[stats.channel - 1].freq; 653 stats.band = IEEE80211_BAND_2GHZ;
665 stats.phymode = MODE_IEEE80211G;
666 stats.ssi = status->signal_strength; 654 stats.ssi = status->signal_strength;
667 stats.signal = zd_rx_qual_percent(buffer, 655 stats.signal = zd_rx_qual_percent(buffer,
668 length - sizeof(struct rx_status), 656 length - sizeof(struct rx_status),
669 status); 657 status);
670 stats.rate = zd_rx_rate(buffer, status); 658
659 rate = zd_rx_rate(buffer, status);
660
661 /* todo: return index in the big switches in zd_rx_rate instead */
662 for (i = 0; i < mac->band.n_bitrates; i++)
663 if (rate == mac->band.bitrates[i].hw_value)
664 stats.rate_idx = i;
671 665
672 length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status); 666 length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status);
673 buffer += ZD_PLCP_HEADER_SIZE; 667 buffer += ZD_PLCP_HEADER_SIZE;
@@ -736,7 +730,7 @@ static void zd_op_remove_interface(struct ieee80211_hw *hw,
736static int zd_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) 730static int zd_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
737{ 731{
738 struct zd_mac *mac = zd_hw_mac(hw); 732 struct zd_mac *mac = zd_hw_mac(hw);
739 return zd_chip_set_channel(&mac->chip, conf->channel); 733 return zd_chip_set_channel(&mac->chip, conf->channel->hw_value);
740} 734}
741 735
742static int zd_op_config_interface(struct ieee80211_hw *hw, 736static int zd_op_config_interface(struct ieee80211_hw *hw,
@@ -894,7 +888,6 @@ struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
894{ 888{
895 struct zd_mac *mac; 889 struct zd_mac *mac;
896 struct ieee80211_hw *hw; 890 struct ieee80211_hw *hw;
897 int i;
898 891
899 hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops); 892 hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops);
900 if (!hw) { 893 if (!hw) {
@@ -912,19 +905,14 @@ struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
912 905
913 memcpy(mac->channels, zd_channels, sizeof(zd_channels)); 906 memcpy(mac->channels, zd_channels, sizeof(zd_channels));
914 memcpy(mac->rates, zd_rates, sizeof(zd_rates)); 907 memcpy(mac->rates, zd_rates, sizeof(zd_rates));
915 mac->modes[0].mode = MODE_IEEE80211G; 908 mac->band.n_bitrates = ARRAY_SIZE(zd_rates);
916 mac->modes[0].num_rates = ARRAY_SIZE(zd_rates); 909 mac->band.bitrates = mac->rates;
917 mac->modes[0].rates = mac->rates; 910 mac->band.n_channels = ARRAY_SIZE(zd_channels);
918 mac->modes[0].num_channels = ARRAY_SIZE(zd_channels); 911 mac->band.channels = mac->channels;
919 mac->modes[0].channels = mac->channels; 912
920 mac->modes[1].mode = MODE_IEEE80211B; 913 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &mac->band;
921 mac->modes[1].num_rates = 4; 914
922 mac->modes[1].rates = mac->rates; 915 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS;
923 mac->modes[1].num_channels = ARRAY_SIZE(zd_channels);
924 mac->modes[1].channels = mac->channels;
925
926 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
927 IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED;
928 hw->max_rssi = 100; 916 hw->max_rssi = 100;
929 hw->max_signal = 100; 917 hw->max_signal = 100;
930 918
@@ -933,14 +921,6 @@ struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
933 921
934 skb_queue_head_init(&mac->ack_wait_queue); 922 skb_queue_head_init(&mac->ack_wait_queue);
935 923
936 for (i = 0; i < 2; i++) {
937 if (ieee80211_register_hwmode(hw, &mac->modes[i])) {
938 dev_dbg_f(&intf->dev, "cannot register hwmode\n");
939 ieee80211_free_hw(hw);
940 return NULL;
941 }
942 }
943
944 zd_chip_init(&mac->chip, hw, intf); 924 zd_chip_init(&mac->chip, hw, intf);
945 housekeeping_init(mac); 925 housekeeping_init(mac);
946 INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler); 926 INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler);
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.h b/drivers/net/wireless/zd1211rw/zd_mac.h
index 2dde108df767..67dea9739c8f 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.h
+++ b/drivers/net/wireless/zd1211rw/zd_mac.h
@@ -185,7 +185,7 @@ struct zd_mac {
185 struct sk_buff_head ack_wait_queue; 185 struct sk_buff_head ack_wait_queue;
186 struct ieee80211_channel channels[14]; 186 struct ieee80211_channel channels[14];
187 struct ieee80211_rate rates[12]; 187 struct ieee80211_rate rates[12];
188 struct ieee80211_hw_mode modes[2]; 188 struct ieee80211_supported_band band;
189 189
190 /* Short preamble (used for RTS/CTS) */ 190 /* Short preamble (used for RTS/CTS) */
191 unsigned int short_preamble:1; 191 unsigned int short_preamble:1;
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 277488176a44..460da54a0019 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -69,95 +69,6 @@
69 * not do so then mac80211 may add this under certain circumstances. 69 * not do so then mac80211 may add this under certain circumstances.
70 */ 70 */
71 71
72#define IEEE80211_CHAN_W_SCAN 0x00000001
73#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002
74#define IEEE80211_CHAN_W_IBSS 0x00000004
75
76/* Channel information structure. Low-level driver is expected to fill in chan,
77 * freq, and val fields. Other fields will be filled in by 80211.o based on
78 * hostapd information and low-level driver does not need to use them. The
79 * limits for each channel will be provided in 'struct ieee80211_conf' when
80 * configuring the low-level driver with hw->config callback. If a device has
81 * a default regulatory domain, IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
82 * can be set to let the driver configure all fields */
83struct ieee80211_channel {
84 short chan; /* channel number (IEEE 802.11) */
85 short freq; /* frequency in MHz */
86 int val; /* hw specific value for the channel */
87 int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
88 unsigned char power_level;
89 unsigned char antenna_max;
90};
91
92#define IEEE80211_RATE_ERP 0x00000001
93#define IEEE80211_RATE_BASIC 0x00000002
94#define IEEE80211_RATE_PREAMBLE2 0x00000004
95#define IEEE80211_RATE_SUPPORTED 0x00000010
96#define IEEE80211_RATE_OFDM 0x00000020
97#define IEEE80211_RATE_CCK 0x00000040
98#define IEEE80211_RATE_MANDATORY 0x00000100
99
100#define IEEE80211_RATE_CCK_2 (IEEE80211_RATE_CCK | IEEE80211_RATE_PREAMBLE2)
101#define IEEE80211_RATE_MODULATION(f) \
102 (f & (IEEE80211_RATE_CCK | IEEE80211_RATE_OFDM))
103
104/* Low-level driver should set PREAMBLE2, OFDM and CCK flags.
105 * BASIC, SUPPORTED, ERP, and MANDATORY flags are set in 80211.o based on the
106 * configuration. */
107struct ieee80211_rate {
108 int rate; /* rate in 100 kbps */
109 int val; /* hw specific value for the rate */
110 int flags; /* IEEE80211_RATE_ flags */
111 int val2; /* hw specific value for the rate when using short preamble
112 * (only when IEEE80211_RATE_PREAMBLE2 flag is set, i.e., for
113 * 2, 5.5, and 11 Mbps) */
114 signed char min_rssi_ack;
115 unsigned char min_rssi_ack_delta;
116
117 /* following fields are set by 80211.o and need not be filled by the
118 * low-level driver */
119 int rate_inv; /* inverse of the rate (LCM(all rates) / rate) for
120 * optimizing channel utilization estimates */
121};
122
123/**
124 * enum ieee80211_phymode - PHY modes
125 *
126 * @MODE_IEEE80211A: 5GHz as defined by 802.11a/802.11h
127 * @MODE_IEEE80211B: 2.4 GHz as defined by 802.11b
128 * @MODE_IEEE80211G: 2.4 GHz as defined by 802.11g (with OFDM),
129 * backwards compatible with 11b mode
130 * @NUM_IEEE80211_MODES: internal
131 */
132enum ieee80211_phymode {
133 MODE_IEEE80211A,
134 MODE_IEEE80211B,
135 MODE_IEEE80211G,
136
137 /* keep last */
138 NUM_IEEE80211_MODES
139};
140
141/**
142 * struct ieee80211_ht_info - describing STA's HT capabilities
143 *
144 * This structure describes most essential parameters needed
145 * to describe 802.11n HT capabilities for an STA.
146 *
147 * @ht_supported: is HT supported by STA, 0: no, 1: yes
148 * @cap: HT capabilities map as described in 802.11n spec
149 * @ampdu_factor: Maximum A-MPDU length factor
150 * @ampdu_density: Minimum A-MPDU spacing
151 * @supp_mcs_set: Supported MCS set as described in 802.11n spec
152 */
153struct ieee80211_ht_info {
154 u8 ht_supported;
155 u16 cap; /* use IEEE80211_HT_CAP_ */
156 u8 ampdu_factor;
157 u8 ampdu_density;
158 u8 supp_mcs_set[16];
159};
160
161/** 72/**
162 * struct ieee80211_ht_bss_info - describing BSS's HT characteristics 73 * struct ieee80211_ht_bss_info - describing BSS's HT characteristics
163 * 74 *
@@ -175,30 +86,6 @@ struct ieee80211_ht_bss_info {
175}; 86};
176 87
177/** 88/**
178 * struct ieee80211_hw_mode - PHY mode definition
179 *
180 * This structure describes the capabilities supported by the device
181 * in a single PHY mode.
182 *
183 * @list: internal
184 * @channels: pointer to array of supported channels
185 * @rates: pointer to array of supported bitrates
186 * @mode: the PHY mode for this definition
187 * @num_channels: number of supported channels
188 * @num_rates: number of supported bitrates
189 * @ht_info: PHY's 802.11n HT abilities for this mode
190 */
191struct ieee80211_hw_mode {
192 struct list_head list;
193 struct ieee80211_channel *channels;
194 struct ieee80211_rate *rates;
195 enum ieee80211_phymode mode;
196 int num_channels;
197 int num_rates;
198 struct ieee80211_ht_info ht_info;
199};
200
201/**
202 * struct ieee80211_tx_queue_params - transmit queue configuration 89 * struct ieee80211_tx_queue_params - transmit queue configuration
203 * 90 *
204 * The information provided in this structure is required for QoS 91 * The information provided in this structure is required for QoS
@@ -320,11 +207,13 @@ struct ieee80211_bss_conf {
320 207
321struct ieee80211_tx_control { 208struct ieee80211_tx_control {
322 struct ieee80211_vif *vif; 209 struct ieee80211_vif *vif;
323 int tx_rate; /* Transmit rate, given as the hw specific value for the 210 struct ieee80211_rate *tx_rate;
324 * rate (from struct ieee80211_rate) */ 211
325 int rts_cts_rate; /* Transmit rate for RTS/CTS frame, given as the hw 212 /* Transmit rate for RTS/CTS frame */
326 * specific value for the rate (from 213 struct ieee80211_rate *rts_cts_rate;
327 * struct ieee80211_rate) */ 214
215 /* retry rate for the last retries */
216 struct ieee80211_rate *alt_retry_rate;
328 217
329#define IEEE80211_TXCTL_REQ_TX_STATUS (1<<0)/* request TX status callback for 218#define IEEE80211_TXCTL_REQ_TX_STATUS (1<<0)/* request TX status callback for
330 * this frame */ 219 * this frame */
@@ -343,6 +232,7 @@ struct ieee80211_tx_control {
343#define IEEE80211_TXCTL_REQUEUE (1<<7) 232#define IEEE80211_TXCTL_REQUEUE (1<<7)
344#define IEEE80211_TXCTL_FIRST_FRAGMENT (1<<8) /* this is a first fragment of 233#define IEEE80211_TXCTL_FIRST_FRAGMENT (1<<8) /* this is a first fragment of
345 * the frame */ 234 * the frame */
235#define IEEE80211_TXCTL_SHORT_PREAMBLE (1<<9)
346#define IEEE80211_TXCTL_LONG_RETRY_LIMIT (1<<10) /* this frame should be send 236#define IEEE80211_TXCTL_LONG_RETRY_LIMIT (1<<10) /* this frame should be send
347 * using the through 237 * using the through
348 * set_retry_limit configured 238 * set_retry_limit configured
@@ -359,20 +249,11 @@ struct ieee80211_tx_control {
359 u8 retry_limit; /* 1 = only first attempt, 2 = one retry, .. 249 u8 retry_limit; /* 1 = only first attempt, 2 = one retry, ..
360 * This could be used when set_retry_limit 250 * This could be used when set_retry_limit
361 * is not implemented by the driver */ 251 * is not implemented by the driver */
362 u8 power_level; /* per-packet transmit power level, in dBm */
363 u8 antenna_sel_tx; /* 0 = default/diversity, 1 = Ant0, 2 = Ant1 */ 252 u8 antenna_sel_tx; /* 0 = default/diversity, 1 = Ant0, 2 = Ant1 */
364 u8 icv_len; /* length of the ICV/MIC field in octets */ 253 u8 icv_len; /* length of the ICV/MIC field in octets */
365 u8 iv_len; /* length of the IV field in octets */ 254 u8 iv_len; /* length of the IV field in octets */
366 u8 queue; /* hardware queue to use for this frame; 255 u8 queue; /* hardware queue to use for this frame;
367 * 0 = highest, hw->queues-1 = lowest */ 256 * 0 = highest, hw->queues-1 = lowest */
368 struct ieee80211_rate *rate; /* internal 80211.o rate */
369 struct ieee80211_rate *rts_rate; /* internal 80211.o rate
370 * for RTS/CTS */
371 int alt_retry_rate; /* retry rate for the last retries, given as the
372 * hw specific value for the rate (from
373 * struct ieee80211_rate). To be used to limit
374 * packet dropping when probing higher rates, if hw
375 * supports multiple retry rates. -1 = not used */
376 int type; /* internal */ 257 int type; /* internal */
377}; 258};
378 259
@@ -415,26 +296,24 @@ enum mac80211_rx_flags {
415 * supported by hardware) to the 802.11 code with each received 296 * supported by hardware) to the 802.11 code with each received
416 * frame. 297 * frame.
417 * @mactime: MAC timestamp as defined by 802.11 298 * @mactime: MAC timestamp as defined by 802.11
299 * @band: the active band when this frame was received
418 * @freq: frequency the radio was tuned to when receiving this frame, in MHz 300 * @freq: frequency the radio was tuned to when receiving this frame, in MHz
419 * @channel: channel the radio was tuned to
420 * @phymode: active PHY mode
421 * @ssi: signal strength when receiving this frame 301 * @ssi: signal strength when receiving this frame
422 * @signal: used as 'qual' in statistics reporting 302 * @signal: used as 'qual' in statistics reporting
423 * @noise: PHY noise when receiving this frame 303 * @noise: PHY noise when receiving this frame
424 * @antenna: antenna used 304 * @antenna: antenna used
425 * @rate: data rate 305 * @rate_idx: index of data rate into band's supported rates
426 * @flag: %RX_FLAG_* 306 * @flag: %RX_FLAG_*
427 */ 307 */
428struct ieee80211_rx_status { 308struct ieee80211_rx_status {
429 u64 mactime; 309 u64 mactime;
310 enum ieee80211_band band;
430 int freq; 311 int freq;
431 int channel;
432 enum ieee80211_phymode phymode;
433 int ssi; 312 int ssi;
434 int signal; 313 int signal;
435 int noise; 314 int noise;
436 int antenna; 315 int antenna;
437 int rate; 316 int rate_idx;
438 int flag; 317 int flag;
439}; 318};
440 319
@@ -509,41 +388,30 @@ enum ieee80211_conf_flags {
509 * 388 *
510 * @radio_enabled: when zero, driver is required to switch off the radio. 389 * @radio_enabled: when zero, driver is required to switch off the radio.
511 * TODO make a flag 390 * TODO make a flag
512 * @channel: IEEE 802.11 channel number
513 * @freq: frequency in MHz
514 * @channel_val: hardware specific channel value for the channel
515 * @phymode: PHY mode to activate (REMOVE)
516 * @chan: channel to switch to, pointer to the channel information
517 * @mode: pointer to mode definition
518 * @regulatory_domain: ??
519 * @beacon_int: beacon interval (TODO make interface config) 391 * @beacon_int: beacon interval (TODO make interface config)
520 * @flags: configuration flags defined above 392 * @flags: configuration flags defined above
521 * @power_level: transmit power limit for current regulatory domain in dBm 393 * @power_level: requested transmit power (in dBm)
522 * @antenna_max: maximum antenna gain 394 * @max_antenna_gain: maximum antenna gain (in dBi)
523 * @antenna_sel_tx: transmit antenna selection, 0: default/diversity, 395 * @antenna_sel_tx: transmit antenna selection, 0: default/diversity,
524 * 1/2: antenna 0/1 396 * 1/2: antenna 0/1
525 * @antenna_sel_rx: receive antenna selection, like @antenna_sel_tx 397 * @antenna_sel_rx: receive antenna selection, like @antenna_sel_tx
526 * @ht_conf: describes current self configuration of 802.11n HT capabilies 398 * @ht_conf: describes current self configuration of 802.11n HT capabilies
527 * @ht_bss_conf: describes current BSS configuration of 802.11n HT parameters 399 * @ht_bss_conf: describes current BSS configuration of 802.11n HT parameters
400 * @channel: the channel to tune to
528 */ 401 */
529struct ieee80211_conf { 402struct ieee80211_conf {
530 int channel; /* IEEE 802.11 channel number */
531 int freq; /* MHz */
532 int channel_val; /* hw specific value for the channel */
533
534 enum ieee80211_phymode phymode;
535 struct ieee80211_channel *chan;
536 struct ieee80211_hw_mode *mode;
537 unsigned int regulatory_domain; 403 unsigned int regulatory_domain;
538 int radio_enabled; 404 int radio_enabled;
539 405
540 int beacon_int; 406 int beacon_int;
541 u32 flags; 407 u32 flags;
542 u8 power_level; 408 int power_level;
543 u8 antenna_max; 409 int max_antenna_gain;
544 u8 antenna_sel_tx; 410 u8 antenna_sel_tx;
545 u8 antenna_sel_rx; 411 u8 antenna_sel_rx;
546 412
413 struct ieee80211_channel *channel;
414
547 struct ieee80211_ht_info ht_conf; 415 struct ieee80211_ht_info ht_conf;
548 struct ieee80211_ht_bss_info ht_bss_conf; 416 struct ieee80211_ht_bss_info ht_bss_conf;
549}; 417};
@@ -764,15 +632,19 @@ enum sta_notify_cmd {
764 * %IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE is also not set because 632 * %IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE is also not set because
765 * otherwise the stack will not know when the DTIM beacon was sent. 633 * otherwise the stack will not know when the DTIM beacon was sent.
766 * 634 *
767 * @IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED: 635 * @IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE:
768 * Channels are already configured to the default regulatory domain 636 * Hardware is not capable of short slot operation on the 2.4 GHz band.
769 * specified in the device's EEPROM 637 *
638 * @IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE:
639 * Hardware is not capable of receiving frames with short preamble on
640 * the 2.4 GHz band.
770 */ 641 */
771enum ieee80211_hw_flags { 642enum ieee80211_hw_flags {
772 IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE = 1<<0, 643 IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE = 1<<0,
773 IEEE80211_HW_RX_INCLUDES_FCS = 1<<1, 644 IEEE80211_HW_RX_INCLUDES_FCS = 1<<1,
774 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING = 1<<2, 645 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING = 1<<2,
775 IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED = 1<<3, 646 IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE = 1<<3,
647 IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE = 1<<4,
776}; 648};
777 649
778/** 650/**
@@ -784,7 +656,8 @@ enum ieee80211_hw_flags {
784 * @wiphy: This points to the &struct wiphy allocated for this 656 * @wiphy: This points to the &struct wiphy allocated for this
785 * 802.11 PHY. You must fill in the @perm_addr and @dev 657 * 802.11 PHY. You must fill in the @perm_addr and @dev
786 * members of this structure using SET_IEEE80211_DEV() 658 * members of this structure using SET_IEEE80211_DEV()
787 * and SET_IEEE80211_PERM_ADDR(). 659 * and SET_IEEE80211_PERM_ADDR(). Additionally, all supported
660 * bands (with channels, bitrates) are registered here.
788 * 661 *
789 * @conf: &struct ieee80211_conf, device configuration, don't use. 662 * @conf: &struct ieee80211_conf, device configuration, don't use.
790 * 663 *
@@ -1062,7 +935,9 @@ enum ieee80211_ampdu_mlme_action {
1062 * given local_address is enabled. 935 * given local_address is enabled.
1063 * 936 *
1064 * @hw_scan: Ask the hardware to service the scan request, no need to start 937 * @hw_scan: Ask the hardware to service the scan request, no need to start
1065 * the scan state machine in stack. 938 * the scan state machine in stack. The scan must honour the channel
939 * configuration done by the regulatory agent in the wiphy's registered
940 * bands.
1066 * 941 *
1067 * @get_stats: return low-level statistics 942 * @get_stats: return low-level statistics
1068 * 943 *
@@ -1284,10 +1159,6 @@ static inline char *ieee80211_get_radio_led_name(struct ieee80211_hw *hw)
1284#endif 1159#endif
1285} 1160}
1286 1161
1287/* Register a new hardware PHYMODE capability to the stack. */
1288int ieee80211_register_hwmode(struct ieee80211_hw *hw,
1289 struct ieee80211_hw_mode *mode);
1290
1291/** 1162/**
1292 * ieee80211_unregister_hw - Unregister a hardware device 1163 * ieee80211_unregister_hw - Unregister a hardware device
1293 * 1164 *
@@ -1461,7 +1332,7 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
1461 * @hw: pointer obtained from ieee80211_alloc_hw(). 1332 * @hw: pointer obtained from ieee80211_alloc_hw().
1462 * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf. 1333 * @vif: &struct ieee80211_vif pointer from &struct ieee80211_if_init_conf.
1463 * @frame_len: the length of the frame. 1334 * @frame_len: the length of the frame.
1464 * @rate: the rate (in 100kbps) at which the frame is going to be transmitted. 1335 * @rate: the rate at which the frame is going to be transmitted.
1465 * 1336 *
1466 * Calculate the duration field of some generic frame, given its 1337 * Calculate the duration field of some generic frame, given its
1467 * length and transmission rate (in 100kbps). 1338 * length and transmission rate (in 100kbps).
@@ -1469,7 +1340,7 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
1469__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, 1340__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
1470 struct ieee80211_vif *vif, 1341 struct ieee80211_vif *vif,
1471 size_t frame_len, 1342 size_t frame_len,
1472 int rate); 1343 struct ieee80211_rate *rate);
1473 1344
1474/** 1345/**
1475 * ieee80211_get_buffered_bc - accessing buffered broadcast and multicast frames 1346 * ieee80211_get_buffered_bc - accessing buffered broadcast and multicast frames
diff --git a/include/net/wireless.h b/include/net/wireless.h
index d30c4ba8fd99..c7f805ee5545 100644
--- a/include/net/wireless.h
+++ b/include/net/wireless.h
@@ -13,6 +13,162 @@
13#include <net/cfg80211.h> 13#include <net/cfg80211.h>
14 14
15/** 15/**
16 * enum ieee80211_band - supported frequency bands
17 *
18 * The bands are assigned this way because the supported
19 * bitrates differ in these bands.
20 *
21 * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
22 * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
23 */
24enum ieee80211_band {
25 IEEE80211_BAND_2GHZ,
26 IEEE80211_BAND_5GHZ,
27
28 /* keep last */
29 IEEE80211_NUM_BANDS
30};
31
32/**
33 * enum ieee80211_channel_flags - channel flags
34 *
35 * Channel flags set by the regulatory control code.
36 *
37 * @IEEE80211_CHAN_DISABLED: This channel is disabled.
38 * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
39 * on this channel.
40 * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
41 * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
42 */
43enum ieee80211_channel_flags {
44 IEEE80211_CHAN_DISABLED = 1<<0,
45 IEEE80211_CHAN_PASSIVE_SCAN = 1<<1,
46 IEEE80211_CHAN_NO_IBSS = 1<<2,
47 IEEE80211_CHAN_RADAR = 1<<3,
48};
49
50/**
51 * struct ieee80211_channel - channel definition
52 *
53 * This structure describes a single channel for use
54 * with cfg80211.
55 *
56 * @center_freq: center frequency in MHz
57 * @hw_value: hardware-specific value for the channel
58 * @flags: channel flags from &enum ieee80211_channel_flags.
59 * @orig_flags: channel flags at registration time, used by regulatory
60 * code to support devices with additional restrictions
61 * @band: band this channel belongs to.
62 * @max_antenna_gain: maximum antenna gain in dBi
63 * @max_power: maximum transmission power (in dBm)
64 * @orig_mag: internal use
65 * @orig_mpwr: internal use
66 */
67struct ieee80211_channel {
68 enum ieee80211_band band;
69 u16 center_freq;
70 u16 hw_value;
71 u32 flags;
72 int max_antenna_gain;
73 int max_power;
74 u32 orig_flags;
75 int orig_mag, orig_mpwr;
76};
77
78/**
79 * enum ieee80211_rate_flags - rate flags
80 *
81 * Hardware/specification flags for rates. These are structured
82 * in a way that allows using the same bitrate structure for
83 * different bands/PHY modes.
84 *
85 * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
86 * preamble on this bitrate; only relevant in 2.4GHz band and
87 * with CCK rates.
88 * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
89 * when used with 802.11a (on the 5 GHz band); filled by the
90 * core code when registering the wiphy.
91 * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
92 * when used with 802.11b (on the 2.4 GHz band); filled by the
93 * core code when registering the wiphy.
94 * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
95 * when used with 802.11g (on the 2.4 GHz band); filled by the
96 * core code when registering the wiphy.
97 * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
98 */
99enum ieee80211_rate_flags {
100 IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
101 IEEE80211_RATE_MANDATORY_A = 1<<1,
102 IEEE80211_RATE_MANDATORY_B = 1<<2,
103 IEEE80211_RATE_MANDATORY_G = 1<<3,
104 IEEE80211_RATE_ERP_G = 1<<4,
105};
106
107/**
108 * struct ieee80211_rate - bitrate definition
109 *
110 * This structure describes a bitrate that an 802.11 PHY can
111 * operate with. The two values @hw_value and @hw_value_short
112 * are only for driver use when pointers to this structure are
113 * passed around.
114 *
115 * @flags: rate-specific flags
116 * @bitrate: bitrate in units of 100 Kbps
117 * @hw_value: driver/hardware value for this rate
118 * @hw_value_short: driver/hardware value for this rate when
119 * short preamble is used
120 */
121struct ieee80211_rate {
122 u32 flags;
123 u16 bitrate;
124 u16 hw_value, hw_value_short;
125};
126
127/**
128 * struct ieee80211_ht_info - describing STA's HT capabilities
129 *
130 * This structure describes most essential parameters needed
131 * to describe 802.11n HT capabilities for an STA.
132 *
133 * @ht_supported: is HT supported by STA, 0: no, 1: yes
134 * @cap: HT capabilities map as described in 802.11n spec
135 * @ampdu_factor: Maximum A-MPDU length factor
136 * @ampdu_density: Minimum A-MPDU spacing
137 * @supp_mcs_set: Supported MCS set as described in 802.11n spec
138 */
139struct ieee80211_ht_info {
140 u16 cap; /* use IEEE80211_HT_CAP_ */
141 u8 ht_supported;
142 u8 ampdu_factor;
143 u8 ampdu_density;
144 u8 supp_mcs_set[16];
145};
146
147/**
148 * struct ieee80211_supported_band - frequency band definition
149 *
150 * This structure describes a frequency band a wiphy
151 * is able to operate in.
152 *
153 * @channels: Array of channels the hardware can operate in
154 * in this band.
155 * @band: the band this structure represents
156 * @n_channels: Number of channels in @channels
157 * @bitrates: Array of bitrates the hardware can operate with
158 * in this band. Must be sorted to give a valid "supported
159 * rates" IE, i.e. CCK rates first, then OFDM.
160 * @n_bitrates: Number of bitrates in @bitrates
161 */
162struct ieee80211_supported_band {
163 struct ieee80211_channel *channels;
164 struct ieee80211_rate *bitrates;
165 enum ieee80211_band band;
166 int n_channels;
167 int n_bitrates;
168 struct ieee80211_ht_info ht_info;
169};
170
171/**
16 * struct wiphy - wireless hardware description 172 * struct wiphy - wireless hardware description
17 * @idx: the wiphy index assigned to this item 173 * @idx: the wiphy index assigned to this item
18 * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name> 174 * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
@@ -30,6 +186,8 @@ struct wiphy {
30 * help determine whether you own this wiphy or not. */ 186 * help determine whether you own this wiphy or not. */
31 void *privid; 187 void *privid;
32 188
189 struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
190
33 /* fields below are read-only, assigned by cfg80211 */ 191 /* fields below are read-only, assigned by cfg80211 */
34 192
35 /* the item in /sys/class/ieee80211/ points to this, 193 /* the item in /sys/class/ieee80211/ points to this,
@@ -136,4 +294,14 @@ extern void wiphy_unregister(struct wiphy *wiphy);
136 */ 294 */
137extern void wiphy_free(struct wiphy *wiphy); 295extern void wiphy_free(struct wiphy *wiphy);
138 296
297/**
298 * ieee80211_channel_to_frequency - convert channel number to frequency
299 */
300extern int ieee80211_channel_to_frequency(int chan);
301
302/**
303 * ieee80211_frequency_to_channel - convert frequency to channel number
304 */
305extern int ieee80211_frequency_to_channel(int freq);
306
139#endif /* __NET_WIRELESS_H */ 307#endif /* __NET_WIRELESS_H */
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 54f46bc80cfe..9d7a19581a29 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -19,7 +19,6 @@ mac80211-y := \
19 ieee80211_iface.o \ 19 ieee80211_iface.o \
20 ieee80211_rate.o \ 20 ieee80211_rate.o \
21 michael.o \ 21 michael.o \
22 regdomain.o \
23 tkip.o \ 22 tkip.o \
24 aes_ccm.o \ 23 aes_ccm.o \
25 cfg.o \ 24 cfg.o \
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 22c9619ba776..15b8cf94f510 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -498,7 +498,7 @@ static void sta_apply_parameters(struct ieee80211_local *local,
498{ 498{
499 u32 rates; 499 u32 rates;
500 int i, j; 500 int i, j;
501 struct ieee80211_hw_mode *mode; 501 struct ieee80211_supported_band *sband;
502 502
503 if (params->station_flags & STATION_FLAG_CHANGED) { 503 if (params->station_flags & STATION_FLAG_CHANGED) {
504 sta->flags &= ~WLAN_STA_AUTHORIZED; 504 sta->flags &= ~WLAN_STA_AUTHORIZED;
@@ -525,15 +525,16 @@ static void sta_apply_parameters(struct ieee80211_local *local,
525 525
526 if (params->supported_rates) { 526 if (params->supported_rates) {
527 rates = 0; 527 rates = 0;
528 mode = local->oper_hw_mode; 528 sband = local->hw.wiphy->bands[local->oper_channel->band];
529
529 for (i = 0; i < params->supported_rates_len; i++) { 530 for (i = 0; i < params->supported_rates_len; i++) {
530 int rate = (params->supported_rates[i] & 0x7f) * 5; 531 int rate = (params->supported_rates[i] & 0x7f) * 5;
531 for (j = 0; j < mode->num_rates; j++) { 532 for (j = 0; j < sband->n_bitrates; j++) {
532 if (mode->rates[j].rate == rate) 533 if (sband->bitrates[j].bitrate == rate)
533 rates |= BIT(j); 534 rates |= BIT(j);
534 } 535 }
535 } 536 }
536 sta->supp_rates = rates; 537 sta->supp_rates[local->oper_channel->band] = rates;
537 } 538 }
538} 539}
539 540
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 60514b2c97b9..4736c64937b4 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -19,41 +19,6 @@ int mac80211_open_file_generic(struct inode *inode, struct file *file)
19 return 0; 19 return 0;
20} 20}
21 21
22static const char *ieee80211_mode_str(int mode)
23{
24 switch (mode) {
25 case MODE_IEEE80211A:
26 return "IEEE 802.11a";
27 case MODE_IEEE80211B:
28 return "IEEE 802.11b";
29 case MODE_IEEE80211G:
30 return "IEEE 802.11g";
31 default:
32 return "UNKNOWN";
33 }
34}
35
36static ssize_t modes_read(struct file *file, char __user *userbuf,
37 size_t count, loff_t *ppos)
38{
39 struct ieee80211_local *local = file->private_data;
40 struct ieee80211_hw_mode *mode;
41 char buf[150], *p = buf;
42
43 /* FIXME: locking! */
44 list_for_each_entry(mode, &local->modes_list, list) {
45 p += scnprintf(p, sizeof(buf)+buf-p,
46 "%s\n", ieee80211_mode_str(mode->mode));
47 }
48
49 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
50}
51
52static const struct file_operations modes_ops = {
53 .read = modes_read,
54 .open = mac80211_open_file_generic,
55};
56
57#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ 22#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
58static ssize_t name## _read(struct file *file, char __user *userbuf, \ 23static ssize_t name## _read(struct file *file, char __user *userbuf, \
59 size_t count, loff_t *ppos) \ 24 size_t count, loff_t *ppos) \
@@ -80,10 +45,8 @@ static const struct file_operations name## _ops = { \
80 local->debugfs.name = NULL; 45 local->debugfs.name = NULL;
81 46
82 47
83DEBUGFS_READONLY_FILE(channel, 20, "%d",
84 local->hw.conf.channel);
85DEBUGFS_READONLY_FILE(frequency, 20, "%d", 48DEBUGFS_READONLY_FILE(frequency, 20, "%d",
86 local->hw.conf.freq); 49 local->hw.conf.channel->center_freq);
87DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d", 50DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
88 local->hw.conf.antenna_sel_tx); 51 local->hw.conf.antenna_sel_tx);
89DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d", 52DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
@@ -100,8 +63,6 @@ DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
100 local->long_retry_limit); 63 local->long_retry_limit);
101DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 64DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
102 local->total_ps_buffered); 65 local->total_ps_buffered);
103DEBUGFS_READONLY_FILE(mode, 20, "%s",
104 ieee80211_mode_str(local->hw.conf.phymode));
105DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x", 66DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
106 local->wep_iv & 0xffffff); 67 local->wep_iv & 0xffffff);
107DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", 68DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
@@ -294,7 +255,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
294 local->debugfs.stations = debugfs_create_dir("stations", phyd); 255 local->debugfs.stations = debugfs_create_dir("stations", phyd);
295 local->debugfs.keys = debugfs_create_dir("keys", phyd); 256 local->debugfs.keys = debugfs_create_dir("keys", phyd);
296 257
297 DEBUGFS_ADD(channel);
298 DEBUGFS_ADD(frequency); 258 DEBUGFS_ADD(frequency);
299 DEBUGFS_ADD(antenna_sel_tx); 259 DEBUGFS_ADD(antenna_sel_tx);
300 DEBUGFS_ADD(antenna_sel_rx); 260 DEBUGFS_ADD(antenna_sel_rx);
@@ -304,9 +264,7 @@ void debugfs_hw_add(struct ieee80211_local *local)
304 DEBUGFS_ADD(short_retry_limit); 264 DEBUGFS_ADD(short_retry_limit);
305 DEBUGFS_ADD(long_retry_limit); 265 DEBUGFS_ADD(long_retry_limit);
306 DEBUGFS_ADD(total_ps_buffered); 266 DEBUGFS_ADD(total_ps_buffered);
307 DEBUGFS_ADD(mode);
308 DEBUGFS_ADD(wep_iv); 267 DEBUGFS_ADD(wep_iv);
309 DEBUGFS_ADD(modes);
310 268
311 statsd = debugfs_create_dir("statistics", phyd); 269 statsd = debugfs_create_dir("statistics", phyd);
312 local->debugfs.statistics = statsd; 270 local->debugfs.statistics = statsd;
@@ -356,7 +314,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
356 314
357void debugfs_hw_del(struct ieee80211_local *local) 315void debugfs_hw_del(struct ieee80211_local *local)
358{ 316{
359 DEBUGFS_DEL(channel);
360 DEBUGFS_DEL(frequency); 317 DEBUGFS_DEL(frequency);
361 DEBUGFS_DEL(antenna_sel_tx); 318 DEBUGFS_DEL(antenna_sel_tx);
362 DEBUGFS_DEL(antenna_sel_rx); 319 DEBUGFS_DEL(antenna_sel_rx);
@@ -366,9 +323,7 @@ void debugfs_hw_del(struct ieee80211_local *local)
366 DEBUGFS_DEL(short_retry_limit); 323 DEBUGFS_DEL(short_retry_limit);
367 DEBUGFS_DEL(long_retry_limit); 324 DEBUGFS_DEL(long_retry_limit);
368 DEBUGFS_DEL(total_ps_buffered); 325 DEBUGFS_DEL(total_ps_buffered);
369 DEBUGFS_DEL(mode);
370 DEBUGFS_DEL(wep_iv); 326 DEBUGFS_DEL(wep_iv);
371 DEBUGFS_DEL(modes);
372 327
373 DEBUGFS_STATS_DEL(transmitted_fragment_count); 328 DEBUGFS_STATS_DEL(transmitted_fragment_count);
374 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); 329 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index df25abf63137..49660f4e845d 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -33,22 +33,6 @@ static ssize_t sta_ ##name## _read(struct file *file, \
33#define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n") 33#define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n")
34#define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n") 34#define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
35 35
36#define STA_READ_RATE(name, field) \
37static ssize_t sta_##name##_read(struct file *file, \
38 char __user *userbuf, \
39 size_t count, loff_t *ppos) \
40{ \
41 struct sta_info *sta = file->private_data; \
42 struct ieee80211_local *local = wdev_priv(sta->dev->ieee80211_ptr);\
43 struct ieee80211_hw_mode *mode = local->oper_hw_mode; \
44 char buf[20]; \
45 int res = scnprintf(buf, sizeof(buf), "%d\n", \
46 (sta->field >= 0 && \
47 sta->field < mode->num_rates) ? \
48 mode->rates[sta->field].rate : -1); \
49 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
50}
51
52#define STA_OPS(name) \ 36#define STA_OPS(name) \
53static const struct file_operations sta_ ##name## _ops = { \ 37static const struct file_operations sta_ ##name## _ops = { \
54 .read = sta_##name##_read, \ 38 .read = sta_##name##_read, \
@@ -77,8 +61,6 @@ STA_FILE(rx_fragments, rx_fragments, LU);
77STA_FILE(rx_dropped, rx_dropped, LU); 61STA_FILE(rx_dropped, rx_dropped, LU);
78STA_FILE(tx_fragments, tx_fragments, LU); 62STA_FILE(tx_fragments, tx_fragments, LU);
79STA_FILE(tx_filtered, tx_filtered_count, LU); 63STA_FILE(tx_filtered, tx_filtered_count, LU);
80STA_FILE(txrate, txrate, RATE);
81STA_FILE(last_txrate, last_txrate, RATE);
82STA_FILE(tx_retry_failed, tx_retry_failed, LU); 64STA_FILE(tx_retry_failed, tx_retry_failed, LU);
83STA_FILE(tx_retry_count, tx_retry_count, LU); 65STA_FILE(tx_retry_count, tx_retry_count, LU);
84STA_FILE(last_rssi, last_rssi, D); 66STA_FILE(last_rssi, last_rssi, D);
diff --git a/net/mac80211/ieee80211.c b/net/mac80211/ieee80211.c
index 3961d4c4320c..de894b61a23c 100644
--- a/net/mac80211/ieee80211.c
+++ b/net/mac80211/ieee80211.c
@@ -876,37 +876,28 @@ int ieee80211_if_config_beacon(struct net_device *dev)
876 876
877int ieee80211_hw_config(struct ieee80211_local *local) 877int ieee80211_hw_config(struct ieee80211_local *local)
878{ 878{
879 struct ieee80211_hw_mode *mode;
880 struct ieee80211_channel *chan; 879 struct ieee80211_channel *chan;
881 int ret = 0; 880 int ret = 0;
882 881
883 if (local->sta_sw_scanning) { 882 if (local->sta_sw_scanning)
884 chan = local->scan_channel; 883 chan = local->scan_channel;
885 mode = local->scan_hw_mode; 884 else
886 } else {
887 chan = local->oper_channel; 885 chan = local->oper_channel;
888 mode = local->oper_hw_mode;
889 }
890 886
891 local->hw.conf.channel = chan->chan; 887 local->hw.conf.channel = chan;
892 local->hw.conf.channel_val = chan->val; 888
893 if (!local->hw.conf.power_level) { 889 if (!local->hw.conf.power_level)
894 local->hw.conf.power_level = chan->power_level; 890 local->hw.conf.power_level = chan->max_power;
895 } else { 891 else
896 local->hw.conf.power_level = min(chan->power_level, 892 local->hw.conf.power_level = min(chan->max_power,
897 local->hw.conf.power_level); 893 local->hw.conf.power_level);
898 } 894
899 local->hw.conf.freq = chan->freq; 895 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
900 local->hw.conf.phymode = mode->mode;
901 local->hw.conf.antenna_max = chan->antenna_max;
902 local->hw.conf.chan = chan;
903 local->hw.conf.mode = mode;
904 896
905#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 897#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
906 printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d " 898 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
907 "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq, 899 wiphy_name(local->hw.wiphy), chan->center_freq);
908 local->hw.conf.phymode); 900#endif
909#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
910 901
911 if (local->open_count) 902 if (local->open_count)
912 ret = local->ops->config(local_to_hw(local), &local->hw.conf); 903 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
@@ -924,11 +915,13 @@ int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
924 struct ieee80211_ht_bss_info *req_bss_cap) 915 struct ieee80211_ht_bss_info *req_bss_cap)
925{ 916{
926 struct ieee80211_conf *conf = &local->hw.conf; 917 struct ieee80211_conf *conf = &local->hw.conf;
927 struct ieee80211_hw_mode *mode = conf->mode; 918 struct ieee80211_supported_band *sband;
928 int i; 919 int i;
929 920
921 sband = local->hw.wiphy->bands[conf->channel->band];
922
930 /* HT is not supported */ 923 /* HT is not supported */
931 if (!mode->ht_info.ht_supported) { 924 if (!sband->ht_info.ht_supported) {
932 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; 925 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
933 return -EOPNOTSUPP; 926 return -EOPNOTSUPP;
934 } 927 }
@@ -938,17 +931,17 @@ int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
938 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; 931 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
939 } else { 932 } else {
940 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; 933 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
941 conf->ht_conf.cap = req_ht_cap->cap & mode->ht_info.cap; 934 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
942 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS); 935 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
943 conf->ht_conf.cap |= 936 conf->ht_conf.cap |=
944 mode->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS; 937 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
945 conf->ht_bss_conf.primary_channel = 938 conf->ht_bss_conf.primary_channel =
946 req_bss_cap->primary_channel; 939 req_bss_cap->primary_channel;
947 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap; 940 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
948 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; 941 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
949 for (i = 0; i < SUPP_MCS_SET_LEN; i++) 942 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
950 conf->ht_conf.supp_mcs_set[i] = 943 conf->ht_conf.supp_mcs_set[i] =
951 mode->ht_info.supp_mcs_set[i] & 944 sband->ht_info.supp_mcs_set[i] &
952 req_ht_cap->supp_mcs_set[i]; 945 req_ht_cap->supp_mcs_set[i];
953 946
954 /* In STA mode, this gives us indication 947 /* In STA mode, this gives us indication
@@ -1418,10 +1411,6 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1418 local->long_retry_limit = 4; 1411 local->long_retry_limit = 4;
1419 local->hw.conf.radio_enabled = 1; 1412 local->hw.conf.radio_enabled = 1;
1420 1413
1421 local->enabled_modes = ~0;
1422
1423 INIT_LIST_HEAD(&local->modes_list);
1424
1425 INIT_LIST_HEAD(&local->interfaces); 1414 INIT_LIST_HEAD(&local->interfaces);
1426 1415
1427 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work); 1416 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
@@ -1466,6 +1455,25 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1466 struct ieee80211_local *local = hw_to_local(hw); 1455 struct ieee80211_local *local = hw_to_local(hw);
1467 const char *name; 1456 const char *name;
1468 int result; 1457 int result;
1458 enum ieee80211_band band;
1459
1460 /*
1461 * generic code guarantees at least one band,
1462 * set this very early because much code assumes
1463 * that hw.conf.channel is assigned
1464 */
1465 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1466 struct ieee80211_supported_band *sband;
1467
1468 sband = local->hw.wiphy->bands[band];
1469 if (sband) {
1470 /* init channel we're on */
1471 local->hw.conf.channel =
1472 local->oper_channel =
1473 local->scan_channel = &sband->channels[0];
1474 break;
1475 }
1476 }
1469 1477
1470 result = wiphy_register(local->hw.wiphy); 1478 result = wiphy_register(local->hw.wiphy);
1471 if (result < 0) 1479 if (result < 0)
@@ -1567,44 +1575,10 @@ fail_workqueue:
1567} 1575}
1568EXPORT_SYMBOL(ieee80211_register_hw); 1576EXPORT_SYMBOL(ieee80211_register_hw);
1569 1577
1570int ieee80211_register_hwmode(struct ieee80211_hw *hw,
1571 struct ieee80211_hw_mode *mode)
1572{
1573 struct ieee80211_local *local = hw_to_local(hw);
1574 struct ieee80211_rate *rate;
1575 int i;
1576
1577 INIT_LIST_HEAD(&mode->list);
1578 list_add_tail(&mode->list, &local->modes_list);
1579
1580 local->hw_modes |= (1 << mode->mode);
1581 for (i = 0; i < mode->num_rates; i++) {
1582 rate = &(mode->rates[i]);
1583 rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
1584 }
1585 ieee80211_prepare_rates(local, mode);
1586
1587 if (!local->oper_hw_mode) {
1588 /* Default to this mode */
1589 local->hw.conf.phymode = mode->mode;
1590 local->oper_hw_mode = local->scan_hw_mode = mode;
1591 local->oper_channel = local->scan_channel = &mode->channels[0];
1592 local->hw.conf.mode = local->oper_hw_mode;
1593 local->hw.conf.chan = local->oper_channel;
1594 }
1595
1596 if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
1597 ieee80211_set_default_regdomain(mode);
1598
1599 return 0;
1600}
1601EXPORT_SYMBOL(ieee80211_register_hwmode);
1602
1603void ieee80211_unregister_hw(struct ieee80211_hw *hw) 1578void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1604{ 1579{
1605 struct ieee80211_local *local = hw_to_local(hw); 1580 struct ieee80211_local *local = hw_to_local(hw);
1606 struct ieee80211_sub_if_data *sdata, *tmp; 1581 struct ieee80211_sub_if_data *sdata, *tmp;
1607 int i;
1608 1582
1609 tasklet_kill(&local->tx_pending_tasklet); 1583 tasklet_kill(&local->tx_pending_tasklet);
1610 tasklet_kill(&local->tasklet); 1584 tasklet_kill(&local->tasklet);
@@ -1645,11 +1619,6 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1645 rate_control_deinitialize(local); 1619 rate_control_deinitialize(local);
1646 debugfs_hw_del(local); 1620 debugfs_hw_del(local);
1647 1621
1648 for (i = 0; i < NUM_IEEE80211_MODES; i++) {
1649 kfree(local->supp_rates[i]);
1650 kfree(local->basic_rates[i]);
1651 }
1652
1653 if (skb_queue_len(&local->skb_queue) 1622 if (skb_queue_len(&local->skb_queue)
1654 || skb_queue_len(&local->skb_queue_unreliable)) 1623 || skb_queue_len(&local->skb_queue_unreliable))
1655 printk(KERN_WARNING "%s: skb_queue not empty\n", 1624 printk(KERN_WARNING "%s: skb_queue not empty\n",
@@ -1696,7 +1665,6 @@ static int __init ieee80211_init(void)
1696 } 1665 }
1697 1666
1698 ieee80211_debugfs_netdev_init(); 1667 ieee80211_debugfs_netdev_init();
1699 ieee80211_regdomain_init();
1700 1668
1701 return 0; 1669 return 0;
1702 1670
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 9d09ba8cc02b..54eea5f24474 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -79,8 +79,7 @@ struct ieee80211_sta_bss {
79 u8 ssid[IEEE80211_MAX_SSID_LEN]; 79 u8 ssid[IEEE80211_MAX_SSID_LEN];
80 size_t ssid_len; 80 size_t ssid_len;
81 u16 capability; /* host byte order */ 81 u16 capability; /* host byte order */
82 int hw_mode; 82 enum ieee80211_band band;
83 int channel;
84 int freq; 83 int freq;
85 int rssi, signal, noise; 84 int rssi, signal, noise;
86 u8 *wpa_ie; 85 u8 *wpa_ie;
@@ -136,13 +135,12 @@ struct ieee80211_txrx_data {
136 union { 135 union {
137 struct { 136 struct {
138 struct ieee80211_tx_control *control; 137 struct ieee80211_tx_control *control;
139 struct ieee80211_hw_mode *mode; 138 struct ieee80211_channel *channel;
140 struct ieee80211_rate *rate; 139 struct ieee80211_rate *rate;
141 /* use this rate (if set) for last fragment; rate can 140 /* use this rate (if set) for last fragment; rate can
142 * be set to lower rate for the first fragments, e.g., 141 * be set to lower rate for the first fragments, e.g.,
143 * when using CTS protection with IEEE 802.11g. */ 142 * when using CTS protection with IEEE 802.11g. */
144 struct ieee80211_rate *last_frag_rate; 143 struct ieee80211_rate *last_frag_rate;
145 int last_frag_hwrate;
146 144
147 /* Extra fragments (in addition to the first fragment 145 /* Extra fragments (in addition to the first fragment
148 * in skb) */ 146 * in skb) */
@@ -151,6 +149,7 @@ struct ieee80211_txrx_data {
151 } tx; 149 } tx;
152 struct { 150 struct {
153 struct ieee80211_rx_status *status; 151 struct ieee80211_rx_status *status;
152 struct ieee80211_rate *rate;
154 int sent_ps_buffered; 153 int sent_ps_buffered;
155 int queue; 154 int queue;
156 int load; 155 int load;
@@ -179,8 +178,6 @@ struct ieee80211_tx_stored_packet {
179 struct sk_buff *skb; 178 struct sk_buff *skb;
180 int num_extra_frag; 179 int num_extra_frag;
181 struct sk_buff **extra_frag; 180 struct sk_buff **extra_frag;
182 int last_frag_rateidx;
183 int last_frag_hwrate;
184 struct ieee80211_rate *last_frag_rate; 181 struct ieee80211_rate *last_frag_rate;
185 unsigned int last_frag_rate_ctrl_probe; 182 unsigned int last_frag_rate_ctrl_probe;
186}; 183};
@@ -283,7 +280,7 @@ struct ieee80211_if_sta {
283 280
284 unsigned long ibss_join_req; 281 unsigned long ibss_join_req;
285 struct sk_buff *probe_resp; /* ProbeResp template for IBSS */ 282 struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
286 u32 supp_rates_bits; 283 u32 supp_rates_bits[IEEE80211_NUM_BANDS];
287 284
288 int wmm_last_param_set; 285 int wmm_last_param_set;
289}; 286};
@@ -293,6 +290,7 @@ struct ieee80211_if_sta {
293#define IEEE80211_SDATA_ALLMULTI BIT(0) 290#define IEEE80211_SDATA_ALLMULTI BIT(0)
294#define IEEE80211_SDATA_PROMISC BIT(1) 291#define IEEE80211_SDATA_PROMISC BIT(1)
295#define IEEE80211_SDATA_USERSPACE_MLME BIT(2) 292#define IEEE80211_SDATA_USERSPACE_MLME BIT(2)
293#define IEEE80211_SDATA_OPERATING_GMODE BIT(3)
296struct ieee80211_sub_if_data { 294struct ieee80211_sub_if_data {
297 struct list_head list; 295 struct list_head list;
298 296
@@ -313,6 +311,11 @@ struct ieee80211_sub_if_data {
313 */ 311 */
314 int ieee802_1x_pac; 312 int ieee802_1x_pac;
315 313
314 /*
315 * basic rates of this AP or the AP we're associated to
316 */
317 u64 basic_rates;
318
316 u16 sequence; 319 u16 sequence;
317 320
318 /* Fragment table for host-based reassembly */ 321 /* Fragment table for host-based reassembly */
@@ -420,9 +423,6 @@ struct ieee80211_local {
420 423
421 const struct ieee80211_ops *ops; 424 const struct ieee80211_ops *ops;
422 425
423 /* List of registered struct ieee80211_hw_mode */
424 struct list_head modes_list;
425
426 struct net_device *mdev; /* wmaster# - "master" 802.11 device */ 426 struct net_device *mdev; /* wmaster# - "master" 802.11 device */
427 int open_count; 427 int open_count;
428 int monitors; 428 int monitors;
@@ -462,11 +462,6 @@ struct ieee80211_local {
462 462
463 struct rate_control_ref *rate_ctrl; 463 struct rate_control_ref *rate_ctrl;
464 464
465 /* Supported and basic rate filters for different modes. These are
466 * pointers to -1 terminated lists and rates in 100 kbps units. */
467 int *supp_rates[NUM_IEEE80211_MODES];
468 int *basic_rates[NUM_IEEE80211_MODES];
469
470 int rts_threshold; 465 int rts_threshold;
471 int fragmentation_threshold; 466 int fragmentation_threshold;
472 int short_retry_limit; /* dot11ShortRetryLimit */ 467 int short_retry_limit; /* dot11ShortRetryLimit */
@@ -488,12 +483,13 @@ struct ieee80211_local {
488 bool sta_sw_scanning; 483 bool sta_sw_scanning;
489 bool sta_hw_scanning; 484 bool sta_hw_scanning;
490 int scan_channel_idx; 485 int scan_channel_idx;
486 enum ieee80211_band scan_band;
487
491 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state; 488 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
492 unsigned long last_scan_completed; 489 unsigned long last_scan_completed;
493 struct delayed_work scan_work; 490 struct delayed_work scan_work;
494 struct net_device *scan_dev; 491 struct net_device *scan_dev;
495 struct ieee80211_channel *oper_channel, *scan_channel; 492 struct ieee80211_channel *oper_channel, *scan_channel;
496 struct ieee80211_hw_mode *oper_hw_mode, *scan_hw_mode;
497 u8 scan_ssid[IEEE80211_MAX_SSID_LEN]; 493 u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
498 size_t scan_ssid_len; 494 size_t scan_ssid_len;
499 struct list_head sta_bss_list; 495 struct list_head sta_bss_list;
@@ -562,14 +558,8 @@ struct ieee80211_local {
562 int wifi_wme_noack_test; 558 int wifi_wme_noack_test;
563 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */ 559 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
564 560
565 unsigned int enabled_modes; /* bitfield of allowed modes;
566 * (1 << MODE_*) */
567 unsigned int hw_modes; /* bitfield of supported hardware modes;
568 * (1 << MODE_*) */
569
570#ifdef CONFIG_MAC80211_DEBUGFS 561#ifdef CONFIG_MAC80211_DEBUGFS
571 struct local_debugfsdentries { 562 struct local_debugfsdentries {
572 struct dentry *channel;
573 struct dentry *frequency; 563 struct dentry *frequency;
574 struct dentry *antenna_sel_tx; 564 struct dentry *antenna_sel_tx;
575 struct dentry *antenna_sel_rx; 565 struct dentry *antenna_sel_rx;
@@ -579,9 +569,7 @@ struct ieee80211_local {
579 struct dentry *short_retry_limit; 569 struct dentry *short_retry_limit;
580 struct dentry *long_retry_limit; 570 struct dentry *long_retry_limit;
581 struct dentry *total_ps_buffered; 571 struct dentry *total_ps_buffered;
582 struct dentry *mode;
583 struct dentry *wep_iv; 572 struct dentry *wep_iv;
584 struct dentry *modes;
585 struct dentry *statistics; 573 struct dentry *statistics;
586 struct local_debugfsdentries_statsdentries { 574 struct local_debugfsdentries_statsdentries {
587 struct dentry *transmitted_fragment_count; 575 struct dentry *transmitted_fragment_count;
@@ -692,23 +680,6 @@ static inline void bss_tim_clear(struct ieee80211_local *local,
692 read_unlock_bh(&local->sta_lock); 680 read_unlock_bh(&local->sta_lock);
693} 681}
694 682
695/**
696 * ieee80211_is_erp_rate - Check if a rate is an ERP rate
697 * @phymode: The PHY-mode for this rate (MODE_IEEE80211...)
698 * @rate: Transmission rate to check, in 100 kbps
699 *
700 * Check if a given rate is an Extended Rate PHY (ERP) rate.
701 */
702static inline int ieee80211_is_erp_rate(int phymode, int rate)
703{
704 if (phymode == MODE_IEEE80211G) {
705 if (rate != 10 && rate != 20 &&
706 rate != 55 && rate != 110)
707 return 1;
708 }
709 return 0;
710}
711
712static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr) 683static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
713{ 684{
714 return compare_ether_addr(raddr, addr) == 0 || 685 return compare_ether_addr(raddr, addr) == 0 ||
@@ -720,13 +691,9 @@ static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
720int ieee80211_hw_config(struct ieee80211_local *local); 691int ieee80211_hw_config(struct ieee80211_local *local);
721int ieee80211_if_config(struct net_device *dev); 692int ieee80211_if_config(struct net_device *dev);
722int ieee80211_if_config_beacon(struct net_device *dev); 693int ieee80211_if_config_beacon(struct net_device *dev);
723void ieee80211_prepare_rates(struct ieee80211_local *local,
724 struct ieee80211_hw_mode *mode);
725void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx); 694void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
726int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr); 695int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
727void ieee80211_if_setup(struct net_device *dev); 696void ieee80211_if_setup(struct net_device *dev);
728struct ieee80211_rate *ieee80211_get_rate(struct ieee80211_local *local,
729 int phymode, int hwrate);
730int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht, 697int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
731 struct ieee80211_ht_info *req_ht_cap, 698 struct ieee80211_ht_info *req_ht_cap,
732 struct ieee80211_ht_bss_info *req_bss_cap); 699 struct ieee80211_ht_bss_info *req_bss_cap);
@@ -757,7 +724,7 @@ extern const struct iw_handler_def ieee80211_iw_handler_def;
757/* ieee80211_ioctl.c */ 724/* ieee80211_ioctl.c */
758int ieee80211_set_compression(struct ieee80211_local *local, 725int ieee80211_set_compression(struct ieee80211_local *local,
759 struct net_device *dev, struct sta_info *sta); 726 struct net_device *dev, struct sta_info *sta);
760int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq); 727int ieee80211_set_freq(struct ieee80211_local *local, int freq);
761/* ieee80211_sta.c */ 728/* ieee80211_sta.c */
762void ieee80211_sta_timer(unsigned long data); 729void ieee80211_sta_timer(unsigned long data);
763void ieee80211_sta_work(struct work_struct *work); 730void ieee80211_sta_work(struct work_struct *work);
@@ -810,10 +777,6 @@ int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
810void ieee80211_if_free(struct net_device *dev); 777void ieee80211_if_free(struct net_device *dev);
811void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata); 778void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
812 779
813/* regdomain.c */
814void ieee80211_regdomain_init(void);
815void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode);
816
817/* rx handling */ 780/* rx handling */
818extern ieee80211_rx_handler ieee80211_rx_handlers[]; 781extern ieee80211_rx_handler ieee80211_rx_handlers[];
819 782
diff --git a/net/mac80211/ieee80211_iface.c b/net/mac80211/ieee80211_iface.c
index 92f1eb2da311..27cee580f9f1 100644
--- a/net/mac80211/ieee80211_iface.c
+++ b/net/mac80211/ieee80211_iface.c
@@ -118,6 +118,8 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
118 sdata->bss = NULL; 118 sdata->bss = NULL;
119 sdata->vif.type = type; 119 sdata->vif.type = type;
120 120
121 sdata->basic_rates = 0;
122
121 switch (type) { 123 switch (type) {
122 case IEEE80211_IF_TYPE_WDS: 124 case IEEE80211_IF_TYPE_WDS:
123 /* nothing special */ 125 /* nothing special */
diff --git a/net/mac80211/ieee80211_ioctl.c b/net/mac80211/ieee80211_ioctl.c
index 5024d3733834..54ad07aafe2d 100644
--- a/net/mac80211/ieee80211_ioctl.c
+++ b/net/mac80211/ieee80211_ioctl.c
@@ -129,22 +129,7 @@ static int ieee80211_ioctl_giwname(struct net_device *dev,
129 struct iw_request_info *info, 129 struct iw_request_info *info,
130 char *name, char *extra) 130 char *name, char *extra)
131{ 131{
132 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 132 strcpy(name, "IEEE 802.11");
133
134 switch (local->hw.conf.phymode) {
135 case MODE_IEEE80211A:
136 strcpy(name, "IEEE 802.11a");
137 break;
138 case MODE_IEEE80211B:
139 strcpy(name, "IEEE 802.11b");
140 break;
141 case MODE_IEEE80211G:
142 strcpy(name, "IEEE 802.11g");
143 break;
144 default:
145 strcpy(name, "IEEE 802.11");
146 break;
147 }
148 133
149 return 0; 134 return 0;
150} 135}
@@ -156,7 +141,7 @@ static int ieee80211_ioctl_giwrange(struct net_device *dev,
156{ 141{
157 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 142 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
158 struct iw_range *range = (struct iw_range *) extra; 143 struct iw_range *range = (struct iw_range *) extra;
159 struct ieee80211_hw_mode *mode = NULL; 144 enum ieee80211_band band;
160 int c = 0; 145 int c = 0;
161 146
162 data->length = sizeof(struct iw_range); 147 data->length = sizeof(struct iw_range);
@@ -191,24 +176,27 @@ static int ieee80211_ioctl_giwrange(struct net_device *dev,
191 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 176 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
192 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 177 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
193 178
194 list_for_each_entry(mode, &local->modes_list, list) {
195 int i = 0;
196 179
197 if (!(local->enabled_modes & (1 << mode->mode)) || 180 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
198 (local->hw_modes & local->enabled_modes & 181 int i;
199 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B)) 182 struct ieee80211_supported_band *sband;
183
184 sband = local->hw.wiphy->bands[band];
185
186 if (!sband)
200 continue; 187 continue;
201 188
202 while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) { 189 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
203 struct ieee80211_channel *chan = &mode->channels[i]; 190 struct ieee80211_channel *chan = &sband->channels[i];
204 191
205 if (chan->flag & IEEE80211_CHAN_W_SCAN) { 192 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
206 range->freq[c].i = chan->chan; 193 range->freq[c].i =
207 range->freq[c].m = chan->freq * 100000; 194 ieee80211_frequency_to_channel(
208 range->freq[c].e = 1; 195 chan->center_freq);
196 range->freq[c].m = chan->center_freq;
197 range->freq[c].e = 6;
209 c++; 198 c++;
210 } 199 }
211 i++;
212 } 200 }
213 } 201 }
214 range->num_channels = c; 202 range->num_channels = c;
@@ -294,22 +282,29 @@ static int ieee80211_ioctl_giwmode(struct net_device *dev,
294 return 0; 282 return 0;
295} 283}
296 284
297int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq) 285int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
298{ 286{
299 struct ieee80211_hw_mode *mode; 287 int set = 0;
300 int c, set = 0;
301 int ret = -EINVAL; 288 int ret = -EINVAL;
289 enum ieee80211_band band;
290 struct ieee80211_supported_band *sband;
291 int i;
292
293 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
294 sband = local->hw.wiphy->bands[band];
302 295
303 list_for_each_entry(mode, &local->modes_list, list) { 296 if (!sband)
304 if (!(local->enabled_modes & (1 << mode->mode)))
305 continue; 297 continue;
306 for (c = 0; c < mode->num_channels; c++) { 298
307 struct ieee80211_channel *chan = &mode->channels[c]; 299 for (i = 0; i < sband->n_channels; i++) {
308 if (chan->flag & IEEE80211_CHAN_W_SCAN && 300 struct ieee80211_channel *chan = &sband->channels[i];
309 ((chan->chan == channel) || (chan->freq == freq))) { 301
310 local->oper_channel = chan; 302 if (chan->flags & IEEE80211_CHAN_DISABLED)
311 local->oper_hw_mode = mode; 303 continue;
304
305 if (chan->center_freq == freqMHz) {
312 set = 1; 306 set = 1;
307 local->oper_channel = chan;
313 break; 308 break;
314 } 309 }
315 } 310 }
@@ -347,13 +342,14 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
347 IEEE80211_STA_AUTO_CHANNEL_SEL; 342 IEEE80211_STA_AUTO_CHANNEL_SEL;
348 return 0; 343 return 0;
349 } else 344 } else
350 return ieee80211_set_channel(local, freq->m, -1); 345 return ieee80211_set_freq(local,
346 ieee80211_channel_to_frequency(freq->m));
351 } else { 347 } else {
352 int i, div = 1000000; 348 int i, div = 1000000;
353 for (i = 0; i < freq->e; i++) 349 for (i = 0; i < freq->e; i++)
354 div /= 10; 350 div /= 10;
355 if (div > 0) 351 if (div > 0)
356 return ieee80211_set_channel(local, -1, freq->m / div); 352 return ieee80211_set_freq(local, freq->m / div);
357 else 353 else
358 return -EINVAL; 354 return -EINVAL;
359 } 355 }
@@ -366,10 +362,7 @@ static int ieee80211_ioctl_giwfreq(struct net_device *dev,
366{ 362{
367 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 363 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
368 364
369 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level 365 freq->m = local->hw.conf.channel->center_freq;
370 * driver for the current channel with firmware-based management */
371
372 freq->m = local->hw.conf.freq;
373 freq->e = 6; 366 freq->e = 6;
374 367
375 return 0; 368 return 0;
@@ -566,15 +559,17 @@ static int ieee80211_ioctl_siwrate(struct net_device *dev,
566 struct iw_param *rate, char *extra) 559 struct iw_param *rate, char *extra)
567{ 560{
568 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 561 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
569 struct ieee80211_hw_mode *mode; 562 int i, err = -EINVAL;
570 int i;
571 u32 target_rate = rate->value / 100000; 563 u32 target_rate = rate->value / 100000;
572 struct ieee80211_sub_if_data *sdata; 564 struct ieee80211_sub_if_data *sdata;
565 struct ieee80211_supported_band *sband;
573 566
574 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 567 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
575 if (!sdata->bss) 568 if (!sdata->bss)
576 return -ENODEV; 569 return -ENODEV;
577 mode = local->oper_hw_mode; 570
571 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
572
578 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates 573 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
579 * target_rate = X, rate->fixed = 1 means only rate X 574 * target_rate = X, rate->fixed = 1 means only rate X
580 * target_rate = X, rate->fixed = 0 means all rates <= X */ 575 * target_rate = X, rate->fixed = 0 means all rates <= X */
@@ -582,18 +577,20 @@ static int ieee80211_ioctl_siwrate(struct net_device *dev,
582 sdata->bss->force_unicast_rateidx = -1; 577 sdata->bss->force_unicast_rateidx = -1;
583 if (rate->value < 0) 578 if (rate->value < 0)
584 return 0; 579 return 0;
585 for (i=0; i < mode->num_rates; i++) { 580
586 struct ieee80211_rate *rates = &mode->rates[i]; 581 for (i=0; i< sband->n_bitrates; i++) {
587 int this_rate = rates->rate; 582 struct ieee80211_rate *brate = &sband->bitrates[i];
583 int this_rate = brate->bitrate;
588 584
589 if (target_rate == this_rate) { 585 if (target_rate == this_rate) {
590 sdata->bss->max_ratectrl_rateidx = i; 586 sdata->bss->max_ratectrl_rateidx = i;
591 if (rate->fixed) 587 if (rate->fixed)
592 sdata->bss->force_unicast_rateidx = i; 588 sdata->bss->force_unicast_rateidx = i;
593 return 0; 589 err = 0;
590 break;
594 } 591 }
595 } 592 }
596 return -EINVAL; 593 return err;
597} 594}
598 595
599static int ieee80211_ioctl_giwrate(struct net_device *dev, 596static int ieee80211_ioctl_giwrate(struct net_device *dev,
@@ -603,18 +600,24 @@ static int ieee80211_ioctl_giwrate(struct net_device *dev,
603 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 600 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
604 struct sta_info *sta; 601 struct sta_info *sta;
605 struct ieee80211_sub_if_data *sdata; 602 struct ieee80211_sub_if_data *sdata;
603 struct ieee80211_supported_band *sband;
606 604
607 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 605 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
606
608 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) 607 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
609 sta = sta_info_get(local, sdata->u.sta.bssid); 608 sta = sta_info_get(local, sdata->u.sta.bssid);
610 else 609 else
611 return -EOPNOTSUPP; 610 return -EOPNOTSUPP;
612 if (!sta) 611 if (!sta)
613 return -ENODEV; 612 return -ENODEV;
614 if (sta->txrate < local->oper_hw_mode->num_rates) 613
615 rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000; 614 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
615
616 if (sta->txrate_idx < sband->n_bitrates)
617 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
616 else 618 else
617 rate->value = 0; 619 rate->value = 0;
620 rate->value *= 100000;
618 sta_info_put(sta); 621 sta_info_put(sta);
619 return 0; 622 return 0;
620} 623}
@@ -625,7 +628,7 @@ static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
625{ 628{
626 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 629 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
627 bool need_reconfig = 0; 630 bool need_reconfig = 0;
628 u8 new_power_level; 631 int new_power_level;
629 632
630 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) 633 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
631 return -EINVAL; 634 return -EINVAL;
@@ -635,13 +638,15 @@ static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
635 if (data->txpower.fixed) { 638 if (data->txpower.fixed) {
636 new_power_level = data->txpower.value; 639 new_power_level = data->txpower.value;
637 } else { 640 } else {
638 /* Automatic power level. Get the px power from the current 641 /*
639 * channel. */ 642 * Automatic power level. Use maximum power for the current
640 struct ieee80211_channel* chan = local->oper_channel; 643 * channel. Should be part of rate control.
644 */
645 struct ieee80211_channel* chan = local->hw.conf.channel;
641 if (!chan) 646 if (!chan)
642 return -EINVAL; 647 return -EINVAL;
643 648
644 new_power_level = chan->power_level; 649 new_power_level = chan->max_power;
645 } 650 }
646 651
647 if (local->hw.conf.power_level != new_power_level) { 652 if (local->hw.conf.power_level != new_power_level) {
diff --git a/net/mac80211/ieee80211_rate.c b/net/mac80211/ieee80211_rate.c
index b957e67c5fba..ebe29b716b27 100644
--- a/net/mac80211/ieee80211_rate.c
+++ b/net/mac80211/ieee80211_rate.c
@@ -163,7 +163,8 @@ static void rate_control_release(struct kref *kref)
163} 163}
164 164
165void rate_control_get_rate(struct net_device *dev, 165void rate_control_get_rate(struct net_device *dev,
166 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 166 struct ieee80211_supported_band *sband,
167 struct sk_buff *skb,
167 struct rate_selection *sel) 168 struct rate_selection *sel)
168{ 169{
169 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 170 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -174,17 +175,17 @@ void rate_control_get_rate(struct net_device *dev,
174 175
175 memset(sel, 0, sizeof(struct rate_selection)); 176 memset(sel, 0, sizeof(struct rate_selection));
176 177
177 ref->ops->get_rate(ref->priv, dev, mode, skb, sel); 178 ref->ops->get_rate(ref->priv, dev, sband, skb, sel);
178 179
179 /* Select a non-ERP backup rate. */ 180 /* Select a non-ERP backup rate. */
180 if (!sel->nonerp) { 181 if (!sel->nonerp) {
181 for (i = 0; i < mode->num_rates - 1; i++) { 182 for (i = 0; i < sband->n_bitrates; i++) {
182 struct ieee80211_rate *rate = &mode->rates[i]; 183 struct ieee80211_rate *rate = &sband->bitrates[i];
183 if (sel->rate->rate < rate->rate) 184 if (sel->rate->bitrate < rate->bitrate)
184 break; 185 break;
185 186
186 if (rate_supported(sta, mode, i) && 187 if (rate_supported(sta, sband->band, i) &&
187 !(rate->flags & IEEE80211_RATE_ERP)) 188 !(rate->flags & IEEE80211_RATE_ERP_G))
188 sel->nonerp = rate; 189 sel->nonerp = rate;
189 } 190 }
190 } 191 }
diff --git a/net/mac80211/ieee80211_rate.h b/net/mac80211/ieee80211_rate.h
index 73f19e8aa51c..5f9a2ca49a57 100644
--- a/net/mac80211/ieee80211_rate.h
+++ b/net/mac80211/ieee80211_rate.h
@@ -18,6 +18,7 @@
18#include "ieee80211_i.h" 18#include "ieee80211_i.h"
19#include "sta_info.h" 19#include "sta_info.h"
20 20
21/* TODO: kdoc */
21struct rate_selection { 22struct rate_selection {
22 /* Selected transmission rate */ 23 /* Selected transmission rate */
23 struct ieee80211_rate *rate; 24 struct ieee80211_rate *rate;
@@ -34,7 +35,8 @@ struct rate_control_ops {
34 struct sk_buff *skb, 35 struct sk_buff *skb,
35 struct ieee80211_tx_status *status); 36 struct ieee80211_tx_status *status);
36 void (*get_rate)(void *priv, struct net_device *dev, 37 void (*get_rate)(void *priv, struct net_device *dev,
37 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 38 struct ieee80211_supported_band *band,
39 struct sk_buff *skb,
38 struct rate_selection *sel); 40 struct rate_selection *sel);
39 void (*rate_init)(void *priv, void *priv_sta, 41 void (*rate_init)(void *priv, void *priv_sta,
40 struct ieee80211_local *local, struct sta_info *sta); 42 struct ieee80211_local *local, struct sta_info *sta);
@@ -66,7 +68,8 @@ void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
66struct rate_control_ref *rate_control_alloc(const char *name, 68struct rate_control_ref *rate_control_alloc(const char *name,
67 struct ieee80211_local *local); 69 struct ieee80211_local *local);
68void rate_control_get_rate(struct net_device *dev, 70void rate_control_get_rate(struct net_device *dev,
69 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 71 struct ieee80211_supported_band *sband,
72 struct sk_buff *skb,
70 struct rate_selection *sel); 73 struct rate_selection *sel);
71struct rate_control_ref *rate_control_get(struct rate_control_ref *ref); 74struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
72void rate_control_put(struct rate_control_ref *ref); 75void rate_control_put(struct rate_control_ref *ref);
@@ -127,23 +130,23 @@ static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
127#endif 130#endif
128} 131}
129 132
130static inline int 133static inline int rate_supported(struct sta_info *sta,
131rate_supported(struct sta_info *sta, struct ieee80211_hw_mode *mode, int index) 134 enum ieee80211_band band,
135 int index)
132{ 136{
133 return (sta == NULL || sta->supp_rates & BIT(index)) && 137 return (sta == NULL || sta->supp_rates[band] & BIT(index));
134 (mode->rates[index].flags & IEEE80211_RATE_SUPPORTED);
135} 138}
136 139
137static inline int 140static inline int
138rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode *mode, 141rate_lowest_index(struct ieee80211_local *local,
142 struct ieee80211_supported_band *sband,
139 struct sta_info *sta) 143 struct sta_info *sta)
140{ 144{
141 int i; 145 int i;
142 146
143 for (i = 0; i < mode->num_rates; i++) { 147 for (i = 0; i < sband->n_bitrates; i++)
144 if (rate_supported(sta, mode, i)) 148 if (rate_supported(sta, sband->band, i))
145 return i; 149 return i;
146 }
147 150
148 /* warn when we cannot find a rate. */ 151 /* warn when we cannot find a rate. */
149 WARN_ON(1); 152 WARN_ON(1);
@@ -152,10 +155,11 @@ rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode *mode,
152} 155}
153 156
154static inline struct ieee80211_rate * 157static inline struct ieee80211_rate *
155rate_lowest(struct ieee80211_local *local, struct ieee80211_hw_mode *mode, 158rate_lowest(struct ieee80211_local *local,
159 struct ieee80211_supported_band *sband,
156 struct sta_info *sta) 160 struct sta_info *sta)
157{ 161{
158 return &mode->rates[rate_lowest_index(local, mode, sta)]; 162 return &sband->bitrates[rate_lowest_index(local, sband, sta)];
159} 163}
160 164
161 165
diff --git a/net/mac80211/ieee80211_sta.c b/net/mac80211/ieee80211_sta.c
index d0273ccbdbae..2628222a5085 100644
--- a/net/mac80211/ieee80211_sta.c
+++ b/net/mac80211/ieee80211_sta.c
@@ -74,7 +74,7 @@
74static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst, 74static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
75 u8 *ssid, size_t ssid_len); 75 u8 *ssid, size_t ssid_len);
76static struct ieee80211_sta_bss * 76static struct ieee80211_sta_bss *
77ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel, 77ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
78 u8 *ssid, u8 ssid_len); 78 u8 *ssid, u8 ssid_len);
79static void ieee80211_rx_bss_put(struct net_device *dev, 79static void ieee80211_rx_bss_put(struct net_device *dev,
80 struct ieee80211_sta_bss *bss); 80 struct ieee80211_sta_bss *bss);
@@ -466,7 +466,7 @@ static void ieee80211_set_associated(struct net_device *dev,
466 return; 466 return;
467 467
468 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, 468 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
469 local->hw.conf.channel, 469 local->hw.conf.channel->center_freq,
470 ifsta->ssid, ifsta->ssid_len); 470 ifsta->ssid, ifsta->ssid_len);
471 if (bss) { 471 if (bss) {
472 if (bss->has_erp_value) 472 if (bss->has_erp_value)
@@ -593,7 +593,6 @@ static void ieee80211_send_assoc(struct net_device *dev,
593 struct ieee80211_if_sta *ifsta) 593 struct ieee80211_if_sta *ifsta)
594{ 594{
595 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 595 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
596 struct ieee80211_hw_mode *mode;
597 struct sk_buff *skb; 596 struct sk_buff *skb;
598 struct ieee80211_mgmt *mgmt; 597 struct ieee80211_mgmt *mgmt;
599 u8 *pos, *ies; 598 u8 *pos, *ies;
@@ -601,6 +600,7 @@ static void ieee80211_send_assoc(struct net_device *dev,
601 u16 capab; 600 u16 capab;
602 struct ieee80211_sta_bss *bss; 601 struct ieee80211_sta_bss *bss;
603 int wmm = 0; 602 int wmm = 0;
603 struct ieee80211_supported_band *sband;
604 604
605 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 605 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
606 sizeof(*mgmt) + 200 + ifsta->extra_ie_len + 606 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
@@ -612,13 +612,19 @@ static void ieee80211_send_assoc(struct net_device *dev,
612 } 612 }
613 skb_reserve(skb, local->hw.extra_tx_headroom); 613 skb_reserve(skb, local->hw.extra_tx_headroom);
614 614
615 mode = local->oper_hw_mode; 615 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
616
616 capab = ifsta->capab; 617 capab = ifsta->capab;
617 if (mode->mode == MODE_IEEE80211G) { 618
618 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME | 619 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
619 WLAN_CAPABILITY_SHORT_PREAMBLE; 620 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
621 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
622 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
623 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
620 } 624 }
621 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel, 625
626 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
627 local->hw.conf.channel->center_freq,
622 ifsta->ssid, ifsta->ssid_len); 628 ifsta->ssid, ifsta->ssid_len);
623 if (bss) { 629 if (bss) {
624 if (bss->capability & WLAN_CAPABILITY_PRIVACY) 630 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
@@ -657,23 +663,23 @@ static void ieee80211_send_assoc(struct net_device *dev,
657 *pos++ = ifsta->ssid_len; 663 *pos++ = ifsta->ssid_len;
658 memcpy(pos, ifsta->ssid, ifsta->ssid_len); 664 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
659 665
660 len = mode->num_rates; 666 len = sband->n_bitrates;
661 if (len > 8) 667 if (len > 8)
662 len = 8; 668 len = 8;
663 pos = skb_put(skb, len + 2); 669 pos = skb_put(skb, len + 2);
664 *pos++ = WLAN_EID_SUPP_RATES; 670 *pos++ = WLAN_EID_SUPP_RATES;
665 *pos++ = len; 671 *pos++ = len;
666 for (i = 0; i < len; i++) { 672 for (i = 0; i < len; i++) {
667 int rate = mode->rates[i].rate; 673 int rate = sband->bitrates[i].bitrate;
668 *pos++ = (u8) (rate / 5); 674 *pos++ = (u8) (rate / 5);
669 } 675 }
670 676
671 if (mode->num_rates > len) { 677 if (sband->n_bitrates > len) {
672 pos = skb_put(skb, mode->num_rates - len + 2); 678 pos = skb_put(skb, sband->n_bitrates - len + 2);
673 *pos++ = WLAN_EID_EXT_SUPP_RATES; 679 *pos++ = WLAN_EID_EXT_SUPP_RATES;
674 *pos++ = mode->num_rates - len; 680 *pos++ = sband->n_bitrates - len;
675 for (i = len; i < mode->num_rates; i++) { 681 for (i = len; i < sband->n_bitrates; i++) {
676 int rate = mode->rates[i].rate; 682 int rate = sband->bitrates[i].bitrate;
677 *pos++ = (u8) (rate / 5); 683 *pos++ = (u8) (rate / 5);
678 } 684 }
679 } 685 }
@@ -696,17 +702,18 @@ static void ieee80211_send_assoc(struct net_device *dev,
696 *pos++ = 0; 702 *pos++ = 0;
697 } 703 }
698 /* wmm support is a must to HT */ 704 /* wmm support is a must to HT */
699 if (wmm && mode->ht_info.ht_supported) { 705 if (wmm && sband->ht_info.ht_supported) {
700 __le16 tmp = cpu_to_le16(mode->ht_info.cap); 706 __le16 tmp = cpu_to_le16(sband->ht_info.cap);
701 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2); 707 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
702 *pos++ = WLAN_EID_HT_CAPABILITY; 708 *pos++ = WLAN_EID_HT_CAPABILITY;
703 *pos++ = sizeof(struct ieee80211_ht_cap); 709 *pos++ = sizeof(struct ieee80211_ht_cap);
704 memset(pos, 0, sizeof(struct ieee80211_ht_cap)); 710 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
705 memcpy(pos, &tmp, sizeof(u16)); 711 memcpy(pos, &tmp, sizeof(u16));
706 pos += sizeof(u16); 712 pos += sizeof(u16);
707 *pos++ = (mode->ht_info.ampdu_factor | 713 /* TODO: needs a define here for << 2 */
708 (mode->ht_info.ampdu_density << 2)); 714 *pos++ = sband->ht_info.ampdu_factor |
709 memcpy(pos, mode->ht_info.supp_mcs_set, 16); 715 (sband->ht_info.ampdu_density << 2);
716 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
710 } 717 }
711 718
712 kfree(ifsta->assocreq_ies); 719 kfree(ifsta->assocreq_ies);
@@ -789,7 +796,8 @@ static int ieee80211_privacy_mismatch(struct net_device *dev,
789 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL)) 796 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
790 return 0; 797 return 0;
791 798
792 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel, 799 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
800 local->hw.conf.channel->center_freq,
793 ifsta->ssid, ifsta->ssid_len); 801 ifsta->ssid, ifsta->ssid_len);
794 if (!bss) 802 if (!bss)
795 return 0; 803 return 0;
@@ -899,7 +907,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
899 u8 *ssid, size_t ssid_len) 907 u8 *ssid, size_t ssid_len)
900{ 908{
901 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 909 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
902 struct ieee80211_hw_mode *mode; 910 struct ieee80211_supported_band *sband;
903 struct sk_buff *skb; 911 struct sk_buff *skb;
904 struct ieee80211_mgmt *mgmt; 912 struct ieee80211_mgmt *mgmt;
905 u8 *pos, *supp_rates, *esupp_rates = NULL; 913 u8 *pos, *supp_rates, *esupp_rates = NULL;
@@ -933,11 +941,10 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
933 supp_rates = skb_put(skb, 2); 941 supp_rates = skb_put(skb, 2);
934 supp_rates[0] = WLAN_EID_SUPP_RATES; 942 supp_rates[0] = WLAN_EID_SUPP_RATES;
935 supp_rates[1] = 0; 943 supp_rates[1] = 0;
936 mode = local->oper_hw_mode; 944 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
937 for (i = 0; i < mode->num_rates; i++) { 945
938 struct ieee80211_rate *rate = &mode->rates[i]; 946 for (i = 0; i < sband->n_bitrates; i++) {
939 if (!(rate->flags & IEEE80211_RATE_SUPPORTED)) 947 struct ieee80211_rate *rate = &sband->bitrates[i];
940 continue;
941 if (esupp_rates) { 948 if (esupp_rates) {
942 pos = skb_put(skb, 1); 949 pos = skb_put(skb, 1);
943 esupp_rates[1]++; 950 esupp_rates[1]++;
@@ -950,7 +957,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
950 pos = skb_put(skb, 1); 957 pos = skb_put(skb, 1);
951 supp_rates[1]++; 958 supp_rates[1]++;
952 } 959 }
953 *pos = rate->rate / 5; 960 *pos = rate->bitrate / 5;
954 } 961 }
955 962
956 ieee80211_sta_tx(dev, skb, 0); 963 ieee80211_sta_tx(dev, skb, 0);
@@ -1146,9 +1153,11 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
1146 } 1153 }
1147 /* determine default buffer size */ 1154 /* determine default buffer size */
1148 if (buf_size == 0) { 1155 if (buf_size == 0) {
1149 struct ieee80211_hw_mode *mode = conf->mode; 1156 struct ieee80211_supported_band *sband;
1157
1158 sband = local->hw.wiphy->bands[conf->channel->band];
1150 buf_size = IEEE80211_MIN_AMPDU_BUF; 1159 buf_size = IEEE80211_MIN_AMPDU_BUF;
1151 buf_size = buf_size << mode->ht_info.ampdu_factor; 1160 buf_size = buf_size << sband->ht_info.ampdu_factor;
1152 } 1161 }
1153 1162
1154 tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid]; 1163 tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid];
@@ -1718,15 +1727,16 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1718{ 1727{
1719 struct ieee80211_local *local = sdata->local; 1728 struct ieee80211_local *local = sdata->local;
1720 struct net_device *dev = sdata->dev; 1729 struct net_device *dev = sdata->dev;
1721 struct ieee80211_hw_mode *mode; 1730 struct ieee80211_supported_band *sband;
1722 struct sta_info *sta; 1731 struct sta_info *sta;
1723 u32 rates; 1732 u64 rates, basic_rates;
1724 u16 capab_info, status_code, aid; 1733 u16 capab_info, status_code, aid;
1725 struct ieee802_11_elems elems; 1734 struct ieee802_11_elems elems;
1726 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; 1735 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
1727 u8 *pos; 1736 u8 *pos;
1728 int i, j; 1737 int i, j;
1729 DECLARE_MAC_BUF(mac); 1738 DECLARE_MAC_BUF(mac);
1739 bool have_higher_than_11mbit = false;
1730 1740
1731 /* AssocResp and ReassocResp have identical structure, so process both 1741 /* AssocResp and ReassocResp have identical structure, so process both
1732 * of them in this function. */ 1742 * of them in this function. */
@@ -1796,10 +1806,6 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1796 if (ifsta->assocresp_ies) 1806 if (ifsta->assocresp_ies)
1797 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); 1807 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1798 1808
1799 /* set AID, ieee80211_set_associated() will tell the driver */
1800 bss_conf->aid = aid;
1801 ieee80211_set_associated(dev, ifsta, 1);
1802
1803 /* Add STA entry for the AP */ 1809 /* Add STA entry for the AP */
1804 sta = sta_info_get(local, ifsta->bssid); 1810 sta = sta_info_get(local, ifsta->bssid);
1805 if (!sta) { 1811 if (!sta) {
@@ -1811,7 +1817,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1811 return; 1817 return;
1812 } 1818 }
1813 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, 1819 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1814 local->hw.conf.channel, 1820 local->hw.conf.channel->center_freq,
1815 ifsta->ssid, ifsta->ssid_len); 1821 ifsta->ssid, ifsta->ssid_len);
1816 if (bss) { 1822 if (bss) {
1817 sta->last_rssi = bss->rssi; 1823 sta->last_rssi = bss->rssi;
@@ -1825,20 +1831,46 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1825 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP; 1831 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP;
1826 1832
1827 rates = 0; 1833 rates = 0;
1828 mode = local->oper_hw_mode; 1834 basic_rates = 0;
1835 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1836
1829 for (i = 0; i < elems.supp_rates_len; i++) { 1837 for (i = 0; i < elems.supp_rates_len; i++) {
1830 int rate = (elems.supp_rates[i] & 0x7f) * 5; 1838 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1831 for (j = 0; j < mode->num_rates; j++) 1839
1832 if (mode->rates[j].rate == rate) 1840 if (rate > 110)
1841 have_higher_than_11mbit = true;
1842
1843 for (j = 0; j < sband->n_bitrates; j++) {
1844 if (sband->bitrates[j].bitrate == rate)
1833 rates |= BIT(j); 1845 rates |= BIT(j);
1846 if (elems.supp_rates[i] & 0x80)
1847 basic_rates |= BIT(j);
1848 }
1834 } 1849 }
1850
1835 for (i = 0; i < elems.ext_supp_rates_len; i++) { 1851 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1836 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; 1852 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1837 for (j = 0; j < mode->num_rates; j++) 1853
1838 if (mode->rates[j].rate == rate) 1854 if (rate > 110)
1855 have_higher_than_11mbit = true;
1856
1857 for (j = 0; j < sband->n_bitrates; j++) {
1858 if (sband->bitrates[j].bitrate == rate)
1839 rates |= BIT(j); 1859 rates |= BIT(j);
1860 if (elems.ext_supp_rates[i] & 0x80)
1861 basic_rates |= BIT(j);
1862 }
1840 } 1863 }
1841 sta->supp_rates = rates; 1864
1865 sta->supp_rates[local->hw.conf.channel->band] = rates;
1866 sdata->basic_rates = basic_rates;
1867
1868 /* cf. IEEE 802.11 9.2.12 */
1869 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1870 have_higher_than_11mbit)
1871 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1872 else
1873 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1842 1874
1843 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && 1875 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1844 local->ops->conf_ht) { 1876 local->ops->conf_ht) {
@@ -1861,6 +1893,9 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1861 elems.wmm_param_len); 1893 elems.wmm_param_len);
1862 } 1894 }
1863 1895
1896 /* set AID, ieee80211_set_associated() will tell the driver */
1897 bss_conf->aid = aid;
1898 ieee80211_set_associated(dev, ifsta, 1);
1864 1899
1865 sta_info_put(sta); 1900 sta_info_put(sta);
1866 1901
@@ -1901,7 +1936,7 @@ static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
1901 1936
1902 1937
1903static struct ieee80211_sta_bss * 1938static struct ieee80211_sta_bss *
1904ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel, 1939ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
1905 u8 *ssid, u8 ssid_len) 1940 u8 *ssid, u8 ssid_len)
1906{ 1941{
1907 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1942 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1913,7 +1948,7 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
1913 atomic_inc(&bss->users); 1948 atomic_inc(&bss->users);
1914 atomic_inc(&bss->users); 1949 atomic_inc(&bss->users);
1915 memcpy(bss->bssid, bssid, ETH_ALEN); 1950 memcpy(bss->bssid, bssid, ETH_ALEN);
1916 bss->channel = channel; 1951 bss->freq = freq;
1917 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { 1952 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
1918 memcpy(bss->ssid, ssid, ssid_len); 1953 memcpy(bss->ssid, ssid, ssid_len);
1919 bss->ssid_len = ssid_len; 1954 bss->ssid_len = ssid_len;
@@ -1929,7 +1964,7 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
1929 1964
1930 1965
1931static struct ieee80211_sta_bss * 1966static struct ieee80211_sta_bss *
1932ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel, 1967ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
1933 u8 *ssid, u8 ssid_len) 1968 u8 *ssid, u8 ssid_len)
1934{ 1969{
1935 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1970 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1939,7 +1974,7 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
1939 bss = local->sta_bss_hash[STA_HASH(bssid)]; 1974 bss = local->sta_bss_hash[STA_HASH(bssid)];
1940 while (bss) { 1975 while (bss) {
1941 if (!memcmp(bss->bssid, bssid, ETH_ALEN) && 1976 if (!memcmp(bss->bssid, bssid, ETH_ALEN) &&
1942 bss->channel == channel && 1977 bss->freq == freq &&
1943 bss->ssid_len == ssid_len && 1978 bss->ssid_len == ssid_len &&
1944 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { 1979 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
1945 atomic_inc(&bss->users); 1980 atomic_inc(&bss->users);
@@ -2004,7 +2039,7 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2004 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2039 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2005 struct ieee802_11_elems elems; 2040 struct ieee802_11_elems elems;
2006 size_t baselen; 2041 size_t baselen;
2007 int channel, clen; 2042 int freq, clen;
2008 struct ieee80211_sta_bss *bss; 2043 struct ieee80211_sta_bss *bss;
2009 struct sta_info *sta; 2044 struct sta_info *sta;
2010 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -2055,26 +2090,22 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2055 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates && 2090 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
2056 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 && 2091 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2057 (sta = sta_info_get(local, mgmt->sa))) { 2092 (sta = sta_info_get(local, mgmt->sa))) {
2058 struct ieee80211_hw_mode *mode; 2093 struct ieee80211_supported_band *sband;
2059 struct ieee80211_rate *rates; 2094 struct ieee80211_rate *bitrates;
2060 size_t num_rates; 2095 size_t num_rates;
2061 u32 supp_rates, prev_rates; 2096 u64 supp_rates, prev_rates;
2062 int i, j; 2097 int i, j;
2063 2098
2064 mode = local->sta_sw_scanning ? 2099 sband = local->hw.wiphy->bands[rx_status->band];
2065 local->scan_hw_mode : local->oper_hw_mode;
2066
2067 if (local->sta_hw_scanning) {
2068 /* search for the correct mode matches the beacon */
2069 list_for_each_entry(mode, &local->modes_list, list)
2070 if (mode->mode == rx_status->phymode)
2071 break;
2072 2100
2073 if (mode == NULL) 2101 if (!sband) {
2074 mode = local->oper_hw_mode; 2102 WARN_ON(1);
2103 sband = local->hw.wiphy->bands[
2104 local->hw.conf.channel->band];
2075 } 2105 }
2076 rates = mode->rates; 2106
2077 num_rates = mode->num_rates; 2107 bitrates = sband->bitrates;
2108 num_rates = sband->n_bitrates;
2078 2109
2079 supp_rates = 0; 2110 supp_rates = 0;
2080 for (i = 0; i < elems.supp_rates_len + 2111 for (i = 0; i < elems.supp_rates_len +
@@ -2088,24 +2119,27 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2088 [i - elems.supp_rates_len]; 2119 [i - elems.supp_rates_len];
2089 own_rate = 5 * (rate & 0x7f); 2120 own_rate = 5 * (rate & 0x7f);
2090 for (j = 0; j < num_rates; j++) 2121 for (j = 0; j < num_rates; j++)
2091 if (rates[j].rate == own_rate) 2122 if (bitrates[j].bitrate == own_rate)
2092 supp_rates |= BIT(j); 2123 supp_rates |= BIT(j);
2093 } 2124 }
2094 2125
2095 prev_rates = sta->supp_rates; 2126 prev_rates = sta->supp_rates[rx_status->band];
2096 sta->supp_rates &= supp_rates; 2127 sta->supp_rates[rx_status->band] &= supp_rates;
2097 if (sta->supp_rates == 0) { 2128 if (sta->supp_rates[rx_status->band] == 0) {
2098 /* No matching rates - this should not really happen. 2129 /* No matching rates - this should not really happen.
2099 * Make sure that at least one rate is marked 2130 * Make sure that at least one rate is marked
2100 * supported to avoid issues with TX rate ctrl. */ 2131 * supported to avoid issues with TX rate ctrl. */
2101 sta->supp_rates = sdata->u.sta.supp_rates_bits; 2132 sta->supp_rates[rx_status->band] =
2133 sdata->u.sta.supp_rates_bits[rx_status->band];
2102 } 2134 }
2103 if (sta->supp_rates != prev_rates) { 2135 if (sta->supp_rates[rx_status->band] != prev_rates) {
2104 printk(KERN_DEBUG "%s: updated supp_rates set for " 2136 printk(KERN_DEBUG "%s: updated supp_rates set for "
2105 "%s based on beacon info (0x%x & 0x%x -> " 2137 "%s based on beacon info (0x%llx & 0x%llx -> "
2106 "0x%x)\n", 2138 "0x%llx)\n",
2107 dev->name, print_mac(mac, sta->addr), prev_rates, 2139 dev->name, print_mac(mac, sta->addr),
2108 supp_rates, sta->supp_rates); 2140 (unsigned long long) prev_rates,
2141 (unsigned long long) supp_rates,
2142 (unsigned long long) sta->supp_rates[rx_status->band]);
2109 } 2143 }
2110 sta_info_put(sta); 2144 sta_info_put(sta);
2111 } 2145 }
@@ -2114,14 +2148,14 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2114 return; 2148 return;
2115 2149
2116 if (elems.ds_params && elems.ds_params_len == 1) 2150 if (elems.ds_params && elems.ds_params_len == 1)
2117 channel = elems.ds_params[0]; 2151 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
2118 else 2152 else
2119 channel = rx_status->channel; 2153 freq = rx_status->freq;
2120 2154
2121 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel, 2155 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
2122 elems.ssid, elems.ssid_len); 2156 elems.ssid, elems.ssid_len);
2123 if (!bss) { 2157 if (!bss) {
2124 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel, 2158 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2125 elems.ssid, elems.ssid_len); 2159 elems.ssid, elems.ssid_len);
2126 if (!bss) 2160 if (!bss)
2127 return; 2161 return;
@@ -2134,6 +2168,8 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2134#endif 2168#endif
2135 } 2169 }
2136 2170
2171 bss->band = rx_status->band;
2172
2137 if (bss->probe_resp && beacon) { 2173 if (bss->probe_resp && beacon) {
2138 /* Do not allow beacon to override data from Probe Response. */ 2174 /* Do not allow beacon to override data from Probe Response. */
2139 ieee80211_rx_bss_put(dev, bss); 2175 ieee80211_rx_bss_put(dev, bss);
@@ -2232,20 +2268,6 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2232 bss->ht_ie_len = 0; 2268 bss->ht_ie_len = 0;
2233 } 2269 }
2234 2270
2235 bss->hw_mode = rx_status->phymode;
2236 bss->freq = rx_status->freq;
2237 if (channel != rx_status->channel &&
2238 (bss->hw_mode == MODE_IEEE80211G ||
2239 bss->hw_mode == MODE_IEEE80211B) &&
2240 channel >= 1 && channel <= 14) {
2241 static const int freq_list[] = {
2242 2412, 2417, 2422, 2427, 2432, 2437, 2442,
2243 2447, 2452, 2457, 2462, 2467, 2472, 2484
2244 };
2245 /* IEEE 802.11g/b mode can receive packets from neighboring
2246 * channels, so map the channel into frequency. */
2247 bss->freq = freq_list[channel - 1];
2248 }
2249 bss->timestamp = timestamp; 2271 bss->timestamp = timestamp;
2250 bss->last_update = jiffies; 2272 bss->last_update = jiffies;
2251 bss->rssi = rx_status->ssi; 2273 bss->rssi = rx_status->ssi;
@@ -2817,7 +2839,7 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
2817 } 2839 }
2818 2840
2819 spin_lock_bh(&local->sta_bss_lock); 2841 spin_lock_bh(&local->sta_bss_lock);
2820 freq = local->oper_channel->freq; 2842 freq = local->oper_channel->center_freq;
2821 list_for_each_entry(bss, &local->sta_bss_list, list) { 2843 list_for_each_entry(bss, &local->sta_bss_list, list) {
2822 if (!(bss->capability & WLAN_CAPABILITY_ESS)) 2844 if (!(bss->capability & WLAN_CAPABILITY_ESS))
2823 continue; 2845 continue;
@@ -2848,7 +2870,7 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
2848 spin_unlock_bh(&local->sta_bss_lock); 2870 spin_unlock_bh(&local->sta_bss_lock);
2849 2871
2850 if (selected) { 2872 if (selected) {
2851 ieee80211_set_channel(local, -1, selected->freq); 2873 ieee80211_set_freq(local, selected->freq);
2852 if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) 2874 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
2853 ieee80211_sta_set_ssid(dev, selected->ssid, 2875 ieee80211_sta_set_ssid(dev, selected->ssid,
2854 selected->ssid_len); 2876 selected->ssid_len);
@@ -2881,10 +2903,12 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
2881 struct sk_buff *skb; 2903 struct sk_buff *skb;
2882 struct ieee80211_mgmt *mgmt; 2904 struct ieee80211_mgmt *mgmt;
2883 struct ieee80211_tx_control control; 2905 struct ieee80211_tx_control control;
2884 struct ieee80211_hw_mode *mode;
2885 struct rate_selection ratesel; 2906 struct rate_selection ratesel;
2886 u8 *pos; 2907 u8 *pos;
2887 struct ieee80211_sub_if_data *sdata; 2908 struct ieee80211_sub_if_data *sdata;
2909 struct ieee80211_supported_band *sband;
2910
2911 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2888 2912
2889 /* Remove possible STA entries from other IBSS networks. */ 2913 /* Remove possible STA entries from other IBSS networks. */
2890 sta_info_flush(local, NULL); 2914 sta_info_flush(local, NULL);
@@ -2904,12 +2928,11 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
2904 sdata->drop_unencrypted = bss->capability & 2928 sdata->drop_unencrypted = bss->capability &
2905 WLAN_CAPABILITY_PRIVACY ? 1 : 0; 2929 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2906 2930
2907 res = ieee80211_set_channel(local, -1, bss->freq); 2931 res = ieee80211_set_freq(local, bss->freq);
2908 2932
2909 if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) { 2933 if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
2910 printk(KERN_DEBUG "%s: IBSS not allowed on channel %d " 2934 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
2911 "(%d MHz)\n", dev->name, local->hw.conf.channel, 2935 "%d MHz\n", dev->name, local->oper_channel->center_freq);
2912 local->hw.conf.freq);
2913 return -1; 2936 return -1;
2914 } 2937 }
2915 2938
@@ -2946,10 +2969,12 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
2946 *pos++ = rates; 2969 *pos++ = rates;
2947 memcpy(pos, bss->supp_rates, rates); 2970 memcpy(pos, bss->supp_rates, rates);
2948 2971
2949 pos = skb_put(skb, 2 + 1); 2972 if (bss->band == IEEE80211_BAND_2GHZ) {
2950 *pos++ = WLAN_EID_DS_PARAMS; 2973 pos = skb_put(skb, 2 + 1);
2951 *pos++ = 1; 2974 *pos++ = WLAN_EID_DS_PARAMS;
2952 *pos++ = bss->channel; 2975 *pos++ = 1;
2976 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2977 }
2953 2978
2954 pos = skb_put(skb, 2 + 2); 2979 pos = skb_put(skb, 2 + 2);
2955 *pos++ = WLAN_EID_IBSS_PARAMS; 2980 *pos++ = WLAN_EID_IBSS_PARAMS;
@@ -2967,19 +2992,18 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
2967 } 2992 }
2968 2993
2969 memset(&control, 0, sizeof(control)); 2994 memset(&control, 0, sizeof(control));
2970 rate_control_get_rate(dev, local->oper_hw_mode, skb, &ratesel); 2995 rate_control_get_rate(dev, sband, skb, &ratesel);
2971 if (!ratesel.rate) { 2996 if (!ratesel.rate) {
2972 printk(KERN_DEBUG "%s: Failed to determine TX rate " 2997 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2973 "for IBSS beacon\n", dev->name); 2998 "for IBSS beacon\n", dev->name);
2974 break; 2999 break;
2975 } 3000 }
2976 control.vif = &sdata->vif; 3001 control.vif = &sdata->vif;
2977 control.tx_rate = 3002 control.tx_rate = ratesel.rate;
2978 (sdata->bss_conf.use_short_preamble && 3003 if (sdata->bss_conf.use_short_preamble &&
2979 (ratesel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ? 3004 ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2980 ratesel.rate->val2 : ratesel.rate->val; 3005 control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
2981 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx; 3006 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2982 control.power_level = local->hw.conf.power_level;
2983 control.flags |= IEEE80211_TXCTL_NO_ACK; 3007 control.flags |= IEEE80211_TXCTL_NO_ACK;
2984 control.retry_limit = 1; 3008 control.retry_limit = 1;
2985 3009
@@ -3004,14 +3028,14 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
3004 } 3028 }
3005 3029
3006 rates = 0; 3030 rates = 0;
3007 mode = local->oper_hw_mode; 3031 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
3008 for (i = 0; i < bss->supp_rates_len; i++) { 3032 for (i = 0; i < bss->supp_rates_len; i++) {
3009 int bitrate = (bss->supp_rates[i] & 0x7f) * 5; 3033 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
3010 for (j = 0; j < mode->num_rates; j++) 3034 for (j = 0; j < sband->n_bitrates; j++)
3011 if (mode->rates[j].rate == bitrate) 3035 if (sband->bitrates[j].bitrate == bitrate)
3012 rates |= BIT(j); 3036 rates |= BIT(j);
3013 } 3037 }
3014 ifsta->supp_rates_bits = rates; 3038 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
3015 } while (0); 3039 } while (0);
3016 3040
3017 if (skb) { 3041 if (skb) {
@@ -3035,7 +3059,7 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
3035 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 3059 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3036 struct ieee80211_sta_bss *bss; 3060 struct ieee80211_sta_bss *bss;
3037 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3061 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3038 struct ieee80211_hw_mode *mode; 3062 struct ieee80211_supported_band *sband;
3039 u8 bssid[ETH_ALEN], *pos; 3063 u8 bssid[ETH_ALEN], *pos;
3040 int i; 3064 int i;
3041 DECLARE_MAC_BUF(mac); 3065 DECLARE_MAC_BUF(mac);
@@ -3057,28 +3081,28 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
3057 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", 3081 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3058 dev->name, print_mac(mac, bssid)); 3082 dev->name, print_mac(mac, bssid));
3059 3083
3060 bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel, 3084 bss = ieee80211_rx_bss_add(dev, bssid,
3085 local->hw.conf.channel->center_freq,
3061 sdata->u.sta.ssid, sdata->u.sta.ssid_len); 3086 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
3062 if (!bss) 3087 if (!bss)
3063 return -ENOMEM; 3088 return -ENOMEM;
3064 3089
3065 mode = local->oper_hw_mode; 3090 bss->band = local->hw.conf.channel->band;
3091 sband = local->hw.wiphy->bands[bss->band];
3066 3092
3067 if (local->hw.conf.beacon_int == 0) 3093 if (local->hw.conf.beacon_int == 0)
3068 local->hw.conf.beacon_int = 100; 3094 local->hw.conf.beacon_int = 100;
3069 bss->beacon_int = local->hw.conf.beacon_int; 3095 bss->beacon_int = local->hw.conf.beacon_int;
3070 bss->hw_mode = local->hw.conf.phymode;
3071 bss->freq = local->hw.conf.freq;
3072 bss->last_update = jiffies; 3096 bss->last_update = jiffies;
3073 bss->capability = WLAN_CAPABILITY_IBSS; 3097 bss->capability = WLAN_CAPABILITY_IBSS;
3074 if (sdata->default_key) { 3098 if (sdata->default_key) {
3075 bss->capability |= WLAN_CAPABILITY_PRIVACY; 3099 bss->capability |= WLAN_CAPABILITY_PRIVACY;
3076 } else 3100 } else
3077 sdata->drop_unencrypted = 0; 3101 sdata->drop_unencrypted = 0;
3078 bss->supp_rates_len = mode->num_rates; 3102 bss->supp_rates_len = sband->n_bitrates;
3079 pos = bss->supp_rates; 3103 pos = bss->supp_rates;
3080 for (i = 0; i < mode->num_rates; i++) { 3104 for (i = 0; i < sband->n_bitrates; i++) {
3081 int rate = mode->rates[i].rate; 3105 int rate = sband->bitrates[i].bitrate;
3082 *pos++ = (u8) (rate / 5); 3106 *pos++ = (u8) (rate / 5);
3083 } 3107 }
3084 3108
@@ -3127,7 +3151,8 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
3127 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid)); 3151 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
3128#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 3152#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3129 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 && 3153 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
3130 (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel, 3154 (bss = ieee80211_rx_bss_get(dev, bssid,
3155 local->hw.conf.channel->center_freq,
3131 ifsta->ssid, ifsta->ssid_len))) { 3156 ifsta->ssid, ifsta->ssid_len))) {
3132 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" 3157 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
3133 " based on configured SSID\n", 3158 " based on configured SSID\n",
@@ -3155,13 +3180,13 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
3155 if (time_after(jiffies, ifsta->ibss_join_req + 3180 if (time_after(jiffies, ifsta->ibss_join_req +
3156 IEEE80211_IBSS_JOIN_TIMEOUT)) { 3181 IEEE80211_IBSS_JOIN_TIMEOUT)) {
3157 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && 3182 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
3158 local->oper_channel->flag & IEEE80211_CHAN_W_IBSS) 3183 (!(local->oper_channel->flags &
3184 IEEE80211_CHAN_NO_IBSS)))
3159 return ieee80211_sta_create_ibss(dev, ifsta); 3185 return ieee80211_sta_create_ibss(dev, ifsta);
3160 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { 3186 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
3161 printk(KERN_DEBUG "%s: IBSS not allowed on the" 3187 printk(KERN_DEBUG "%s: IBSS not allowed on"
3162 " configured channel %d (%d MHz)\n", 3188 " %d MHz\n", dev->name,
3163 dev->name, local->hw.conf.channel, 3189 local->hw.conf.channel->center_freq);
3164 local->hw.conf.freq);
3165 } 3190 }
3166 3191
3167 /* No IBSS found - decrease scan interval and continue 3192 /* No IBSS found - decrease scan interval and continue
@@ -3180,7 +3205,7 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
3180 3205
3181int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len) 3206int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3182{ 3207{
3183 struct ieee80211_sub_if_data *sdata; 3208 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3184 struct ieee80211_if_sta *ifsta; 3209 struct ieee80211_if_sta *ifsta;
3185 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 3210 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3186 3211
@@ -3194,18 +3219,23 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3194 int i; 3219 int i;
3195 3220
3196 memset(&qparam, 0, sizeof(qparam)); 3221 memset(&qparam, 0, sizeof(qparam));
3197 /* TODO: are these ok defaults for all hw_modes? */ 3222
3198 qparam.aifs = 2; 3223 qparam.aifs = 2;
3199 qparam.cw_min = 3224
3200 local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15; 3225 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
3226 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
3227 qparam.cw_min = 31;
3228 else
3229 qparam.cw_min = 15;
3230
3201 qparam.cw_max = 1023; 3231 qparam.cw_max = 1023;
3202 qparam.burst_time = 0; 3232 qparam.burst_time = 0;
3233
3203 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++) 3234 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
3204 {
3205 local->ops->conf_tx(local_to_hw(local), 3235 local->ops->conf_tx(local_to_hw(local),
3206 i + IEEE80211_TX_QUEUE_DATA0, 3236 i + IEEE80211_TX_QUEUE_DATA0,
3207 &qparam); 3237 &qparam);
3208 } 3238
3209 /* IBSS uses different parameters for Beacon sending */ 3239 /* IBSS uses different parameters for Beacon sending */
3210 qparam.cw_min++; 3240 qparam.cw_min++;
3211 qparam.cw_min *= 2; 3241 qparam.cw_min *= 2;
@@ -3214,7 +3244,6 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3214 IEEE80211_TX_QUEUE_BEACON, &qparam); 3244 IEEE80211_TX_QUEUE_BEACON, &qparam);
3215 } 3245 }
3216 3246
3217 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3218 ifsta = &sdata->u.sta; 3247 ifsta = &sdata->u.sta;
3219 3248
3220 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) 3249 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
@@ -3373,7 +3402,7 @@ void ieee80211_sta_scan_work(struct work_struct *work)
3373 container_of(work, struct ieee80211_local, scan_work.work); 3402 container_of(work, struct ieee80211_local, scan_work.work);
3374 struct net_device *dev = local->scan_dev; 3403 struct net_device *dev = local->scan_dev;
3375 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3404 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3376 struct ieee80211_hw_mode *mode; 3405 struct ieee80211_supported_band *sband;
3377 struct ieee80211_channel *chan; 3406 struct ieee80211_channel *chan;
3378 int skip; 3407 int skip;
3379 unsigned long next_delay = 0; 3408 unsigned long next_delay = 0;
@@ -3383,44 +3412,47 @@ void ieee80211_sta_scan_work(struct work_struct *work)
3383 3412
3384 switch (local->scan_state) { 3413 switch (local->scan_state) {
3385 case SCAN_SET_CHANNEL: 3414 case SCAN_SET_CHANNEL:
3386 mode = local->scan_hw_mode; 3415 /* get current scan band */
3387 if (local->scan_hw_mode->list.next == &local->modes_list && 3416 if (local->scan_band < IEEE80211_NUM_BANDS)
3388 local->scan_channel_idx >= mode->num_channels) { 3417 sband = local->hw.wiphy->bands[local->scan_band];
3418 else
3419 sband = NULL;
3420
3421 /* if we started at an unsupported one, advance */
3422 while (!sband && local->scan_band < IEEE80211_NUM_BANDS) {
3423 local->scan_band++;
3424 sband = local->hw.wiphy->bands[local->scan_band];
3425 local->scan_channel_idx = 0;
3426 }
3427
3428 if (!sband ||
3429 (local->scan_channel_idx >= sband->n_channels &&
3430 local->scan_band >= IEEE80211_NUM_BANDS)) {
3389 ieee80211_scan_completed(local_to_hw(local)); 3431 ieee80211_scan_completed(local_to_hw(local));
3390 return; 3432 return;
3391 } 3433 }
3392 skip = !(local->enabled_modes & (1 << mode->mode)); 3434 skip = 0;
3393 chan = &mode->channels[local->scan_channel_idx]; 3435 chan = &sband->channels[local->scan_channel_idx];
3394 if (!(chan->flag & IEEE80211_CHAN_W_SCAN) || 3436
3437 if (chan->flags & IEEE80211_CHAN_DISABLED ||
3395 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && 3438 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3396 !(chan->flag & IEEE80211_CHAN_W_IBSS)) || 3439 chan->flags & IEEE80211_CHAN_NO_IBSS))
3397 (local->hw_modes & local->enabled_modes &
3398 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
3399 skip = 1; 3440 skip = 1;
3400 3441
3401 if (!skip) { 3442 if (!skip) {
3402#if 0
3403 printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
3404 dev->name, chan->chan, chan->freq);
3405#endif
3406
3407 local->scan_channel = chan; 3443 local->scan_channel = chan;
3408 if (ieee80211_hw_config(local)) { 3444 if (ieee80211_hw_config(local)) {
3409 printk(KERN_DEBUG "%s: failed to set channel " 3445 printk(KERN_DEBUG "%s: failed to set freq to "
3410 "%d (%d MHz) for scan\n", dev->name, 3446 "%d MHz for scan\n", dev->name,
3411 chan->chan, chan->freq); 3447 chan->center_freq);
3412 skip = 1; 3448 skip = 1;
3413 } 3449 }
3414 } 3450 }
3415 3451
3416 local->scan_channel_idx++; 3452 local->scan_channel_idx++;
3417 if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) { 3453 if (local->scan_channel_idx >= sband->n_channels) {
3418 if (local->scan_hw_mode->list.next != &local->modes_list) { 3454 local->scan_band++;
3419 local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next, 3455 local->scan_channel_idx = 0;
3420 struct ieee80211_hw_mode,
3421 list);
3422 local->scan_channel_idx = 0;
3423 }
3424 } 3456 }
3425 3457
3426 if (skip) 3458 if (skip)
@@ -3431,13 +3463,14 @@ void ieee80211_sta_scan_work(struct work_struct *work)
3431 local->scan_state = SCAN_SEND_PROBE; 3463 local->scan_state = SCAN_SEND_PROBE;
3432 break; 3464 break;
3433 case SCAN_SEND_PROBE: 3465 case SCAN_SEND_PROBE:
3434 if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) { 3466 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3435 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3436 local->scan_ssid_len);
3437 next_delay = IEEE80211_CHANNEL_TIME;
3438 } else
3439 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3440 local->scan_state = SCAN_SET_CHANNEL; 3467 local->scan_state = SCAN_SET_CHANNEL;
3468
3469 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3470 break;
3471 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3472 local->scan_ssid_len);
3473 next_delay = IEEE80211_CHANNEL_TIME;
3441 break; 3474 break;
3442 } 3475 }
3443 3476
@@ -3512,10 +3545,8 @@ static int ieee80211_sta_start_scan(struct net_device *dev,
3512 } else 3545 } else
3513 local->scan_ssid_len = 0; 3546 local->scan_ssid_len = 0;
3514 local->scan_state = SCAN_SET_CHANNEL; 3547 local->scan_state = SCAN_SET_CHANNEL;
3515 local->scan_hw_mode = list_entry(local->modes_list.next,
3516 struct ieee80211_hw_mode,
3517 list);
3518 local->scan_channel_idx = 0; 3548 local->scan_channel_idx = 0;
3549 local->scan_band = IEEE80211_BAND_2GHZ;
3519 local->scan_dev = dev; 3550 local->scan_dev = dev;
3520 3551
3521 netif_tx_lock_bh(local->mdev); 3552 netif_tx_lock_bh(local->mdev);
@@ -3570,9 +3601,6 @@ ieee80211_sta_scan_result(struct net_device *dev,
3570 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) 3601 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3571 return current_ev; 3602 return current_ev;
3572 3603
3573 if (!(local->enabled_modes & (1 << bss->hw_mode)))
3574 return current_ev;
3575
3576 memset(&iwe, 0, sizeof(iwe)); 3604 memset(&iwe, 0, sizeof(iwe));
3577 iwe.cmd = SIOCGIWAP; 3605 iwe.cmd = SIOCGIWAP;
3578 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 3606 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
@@ -3600,12 +3628,15 @@ ieee80211_sta_scan_result(struct net_device *dev,
3600 3628
3601 memset(&iwe, 0, sizeof(iwe)); 3629 memset(&iwe, 0, sizeof(iwe));
3602 iwe.cmd = SIOCGIWFREQ; 3630 iwe.cmd = SIOCGIWFREQ;
3603 iwe.u.freq.m = bss->channel; 3631 iwe.u.freq.m = bss->freq;
3604 iwe.u.freq.e = 0; 3632 iwe.u.freq.e = 6;
3605 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 3633 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3606 IW_EV_FREQ_LEN); 3634 IW_EV_FREQ_LEN);
3607 iwe.u.freq.m = bss->freq * 100000; 3635
3608 iwe.u.freq.e = 1; 3636 memset(&iwe, 0, sizeof(iwe));
3637 iwe.cmd = SIOCGIWFREQ;
3638 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
3639 iwe.u.freq.e = 0;
3609 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 3640 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3610 IW_EV_FREQ_LEN); 3641 IW_EV_FREQ_LEN);
3611 3642
@@ -3748,7 +3779,8 @@ struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
3748 if (!sta) 3779 if (!sta)
3749 return NULL; 3780 return NULL;
3750 3781
3751 sta->supp_rates = sdata->u.sta.supp_rates_bits; 3782 sta->supp_rates[local->hw.conf.channel->band] =
3783 sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
3752 3784
3753 rate_control_rate_init(sta, local); 3785 rate_control_rate_init(sta, local);
3754 3786
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index c339571632b2..c5a607ca8440 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -102,23 +102,23 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
102 struct rc_pid_rateinfo *rinfo) 102 struct rc_pid_rateinfo *rinfo)
103{ 103{
104 struct ieee80211_sub_if_data *sdata; 104 struct ieee80211_sub_if_data *sdata;
105 struct ieee80211_hw_mode *mode; 105 struct ieee80211_supported_band *sband;
106 int newidx; 106 int newidx;
107 int maxrate; 107 int maxrate;
108 int back = (adj > 0) ? 1 : -1; 108 int back = (adj > 0) ? 1 : -1;
109 109
110 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 110 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
111 111
112 mode = local->oper_hw_mode; 112 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
113 maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1; 113 maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
114 114
115 newidx = rate_control_pid_shift_adjust(rinfo, adj, sta->txrate, 115 newidx = rate_control_pid_shift_adjust(rinfo, adj, sta->txrate_idx,
116 mode->num_rates); 116 sband->n_bitrates);
117 117
118 while (newidx != sta->txrate) { 118 while (newidx != sta->txrate_idx) {
119 if (rate_supported(sta, mode, newidx) && 119 if (rate_supported(sta, sband->band, newidx) &&
120 (maxrate < 0 || newidx <= maxrate)) { 120 (maxrate < 0 || newidx <= maxrate)) {
121 sta->txrate = newidx; 121 sta->txrate_idx = newidx;
122 break; 122 break;
123 } 123 }
124 124
@@ -128,7 +128,7 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
128#ifdef CONFIG_MAC80211_DEBUGFS 128#ifdef CONFIG_MAC80211_DEBUGFS
129 rate_control_pid_event_rate_change( 129 rate_control_pid_event_rate_change(
130 &((struct rc_pid_sta_info *)sta->rate_ctrl_priv)->events, 130 &((struct rc_pid_sta_info *)sta->rate_ctrl_priv)->events,
131 newidx, mode->rates[newidx].rate); 131 newidx, sband->bitrates[newidx].bitrate);
132#endif 132#endif
133} 133}
134 134
@@ -155,7 +155,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
155{ 155{
156 struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv; 156 struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
157 struct rc_pid_rateinfo *rinfo = pinfo->rinfo; 157 struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
158 struct ieee80211_hw_mode *mode; 158 struct ieee80211_supported_band *sband;
159 u32 pf; 159 u32 pf;
160 s32 err_avg; 160 s32 err_avg;
161 u32 err_prop; 161 u32 err_prop;
@@ -164,7 +164,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
164 int adj, i, j, tmp; 164 int adj, i, j, tmp;
165 unsigned long period; 165 unsigned long period;
166 166
167 mode = local->oper_hw_mode; 167 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
168 spinfo = sta->rate_ctrl_priv; 168 spinfo = sta->rate_ctrl_priv;
169 169
170 /* In case nothing happened during the previous control interval, turn 170 /* In case nothing happened during the previous control interval, turn
@@ -190,18 +190,18 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
190 spinfo->tx_num_failed = 0; 190 spinfo->tx_num_failed = 0;
191 191
192 /* If we just switched rate, update the rate behaviour info. */ 192 /* If we just switched rate, update the rate behaviour info. */
193 if (pinfo->oldrate != sta->txrate) { 193 if (pinfo->oldrate != sta->txrate_idx) {
194 194
195 i = rinfo[pinfo->oldrate].rev_index; 195 i = rinfo[pinfo->oldrate].rev_index;
196 j = rinfo[sta->txrate].rev_index; 196 j = rinfo[sta->txrate_idx].rev_index;
197 197
198 tmp = (pf - spinfo->last_pf); 198 tmp = (pf - spinfo->last_pf);
199 tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT); 199 tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT);
200 200
201 rinfo[j].diff = rinfo[i].diff + tmp; 201 rinfo[j].diff = rinfo[i].diff + tmp;
202 pinfo->oldrate = sta->txrate; 202 pinfo->oldrate = sta->txrate_idx;
203 } 203 }
204 rate_control_pid_normalize(pinfo, mode->num_rates); 204 rate_control_pid_normalize(pinfo, sband->n_bitrates);
205 205
206 /* Compute the proportional, integral and derivative errors. */ 206 /* Compute the proportional, integral and derivative errors. */
207 err_prop = (pinfo->target << RC_PID_ARITH_SHIFT) - pf; 207 err_prop = (pinfo->target << RC_PID_ARITH_SHIFT) - pf;
@@ -242,8 +242,10 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
242 struct sta_info *sta; 242 struct sta_info *sta;
243 struct rc_pid_sta_info *spinfo; 243 struct rc_pid_sta_info *spinfo;
244 unsigned long period; 244 unsigned long period;
245 struct ieee80211_supported_band *sband;
245 246
246 sta = sta_info_get(local, hdr->addr1); 247 sta = sta_info_get(local, hdr->addr1);
248 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
247 249
248 if (!sta) 250 if (!sta)
249 return; 251 return;
@@ -251,13 +253,13 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
251 /* Don't update the state if we're not controlling the rate. */ 253 /* Don't update the state if we're not controlling the rate. */
252 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 254 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
253 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) { 255 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
254 sta->txrate = sdata->bss->max_ratectrl_rateidx; 256 sta->txrate_idx = sdata->bss->max_ratectrl_rateidx;
255 return; 257 return;
256 } 258 }
257 259
258 /* Ignore all frames that were sent with a different rate than the rate 260 /* Ignore all frames that were sent with a different rate than the rate
259 * we currently advise mac80211 to use. */ 261 * we currently advise mac80211 to use. */
260 if (status->control.rate != &local->oper_hw_mode->rates[sta->txrate]) 262 if (status->control.tx_rate != &sband->bitrates[sta->txrate_idx])
261 goto ignore; 263 goto ignore;
262 264
263 spinfo = sta->rate_ctrl_priv; 265 spinfo = sta->rate_ctrl_priv;
@@ -304,7 +306,7 @@ ignore:
304} 306}
305 307
306static void rate_control_pid_get_rate(void *priv, struct net_device *dev, 308static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
307 struct ieee80211_hw_mode *mode, 309 struct ieee80211_supported_band *sband,
308 struct sk_buff *skb, 310 struct sk_buff *skb,
309 struct rate_selection *sel) 311 struct rate_selection *sel)
310{ 312{
@@ -322,7 +324,7 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
322 fc = le16_to_cpu(hdr->frame_control); 324 fc = le16_to_cpu(hdr->frame_control);
323 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 325 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
324 is_multicast_ether_addr(hdr->addr1) || !sta) { 326 is_multicast_ether_addr(hdr->addr1) || !sta) {
325 sel->rate = rate_lowest(local, mode, sta); 327 sel->rate = rate_lowest(local, sband, sta);
326 if (sta) 328 if (sta)
327 sta_info_put(sta); 329 sta_info_put(sta);
328 return; 330 return;
@@ -331,23 +333,23 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
331 /* If a forced rate is in effect, select it. */ 333 /* If a forced rate is in effect, select it. */
332 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 334 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
333 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) 335 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
334 sta->txrate = sdata->bss->force_unicast_rateidx; 336 sta->txrate_idx = sdata->bss->force_unicast_rateidx;
335 337
336 rateidx = sta->txrate; 338 rateidx = sta->txrate_idx;
337 339
338 if (rateidx >= mode->num_rates) 340 if (rateidx >= sband->n_bitrates)
339 rateidx = mode->num_rates - 1; 341 rateidx = sband->n_bitrates - 1;
340 342
341 sta->last_txrate = rateidx; 343 sta->last_txrate_idx = rateidx;
342 344
343 sta_info_put(sta); 345 sta_info_put(sta);
344 346
345 sel->rate = &mode->rates[rateidx]; 347 sel->rate = &sband->bitrates[rateidx];
346 348
347#ifdef CONFIG_MAC80211_DEBUGFS 349#ifdef CONFIG_MAC80211_DEBUGFS
348 rate_control_pid_event_tx_rate( 350 rate_control_pid_event_tx_rate(
349 &((struct rc_pid_sta_info *) sta->rate_ctrl_priv)->events, 351 &((struct rc_pid_sta_info *) sta->rate_ctrl_priv)->events,
350 rateidx, mode->rates[rateidx].rate); 352 rateidx, sband->bitrates[rateidx].bitrate);
351#endif 353#endif
352} 354}
353 355
@@ -359,28 +361,32 @@ static void rate_control_pid_rate_init(void *priv, void *priv_sta,
359 * as we need to have IEEE 802.1X auth succeed immediately after assoc.. 361 * as we need to have IEEE 802.1X auth succeed immediately after assoc..
360 * Until that method is implemented, we will use the lowest supported 362 * Until that method is implemented, we will use the lowest supported
361 * rate as a workaround. */ 363 * rate as a workaround. */
362 sta->txrate = rate_lowest_index(local, local->oper_hw_mode, sta); 364 struct ieee80211_supported_band *sband;
365
366 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
367 sta->txrate_idx = rate_lowest_index(local, sband, sta);
363} 368}
364 369
365static void *rate_control_pid_alloc(struct ieee80211_local *local) 370static void *rate_control_pid_alloc(struct ieee80211_local *local)
366{ 371{
367 struct rc_pid_info *pinfo; 372 struct rc_pid_info *pinfo;
368 struct rc_pid_rateinfo *rinfo; 373 struct rc_pid_rateinfo *rinfo;
369 struct ieee80211_hw_mode *mode; 374 struct ieee80211_supported_band *sband;
370 int i, j, tmp; 375 int i, j, tmp;
371 bool s; 376 bool s;
372#ifdef CONFIG_MAC80211_DEBUGFS 377#ifdef CONFIG_MAC80211_DEBUGFS
373 struct rc_pid_debugfs_entries *de; 378 struct rc_pid_debugfs_entries *de;
374#endif 379#endif
375 380
381 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
382
376 pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC); 383 pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
377 if (!pinfo) 384 if (!pinfo)
378 return NULL; 385 return NULL;
379 386
380 /* We can safely assume that oper_hw_mode won't change unless we get 387 /* We can safely assume that sband won't change unless we get
381 * reinitialized. */ 388 * reinitialized. */
382 mode = local->oper_hw_mode; 389 rinfo = kmalloc(sizeof(*rinfo) * sband->n_bitrates, GFP_ATOMIC);
383 rinfo = kmalloc(sizeof(*rinfo) * mode->num_rates, GFP_ATOMIC);
384 if (!rinfo) { 390 if (!rinfo) {
385 kfree(pinfo); 391 kfree(pinfo);
386 return NULL; 392 return NULL;
@@ -389,7 +395,7 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
389 /* Sort the rates. This is optimized for the most common case (i.e. 395 /* Sort the rates. This is optimized for the most common case (i.e.
390 * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed 396 * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed
391 * mapping too. */ 397 * mapping too. */
392 for (i = 0; i < mode->num_rates; i++) { 398 for (i = 0; i < sband->n_bitrates; i++) {
393 rinfo[i].index = i; 399 rinfo[i].index = i;
394 rinfo[i].rev_index = i; 400 rinfo[i].rev_index = i;
395 if (pinfo->fast_start) 401 if (pinfo->fast_start)
@@ -397,11 +403,11 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
397 else 403 else
398 rinfo[i].diff = i * pinfo->norm_offset; 404 rinfo[i].diff = i * pinfo->norm_offset;
399 } 405 }
400 for (i = 1; i < mode->num_rates; i++) { 406 for (i = 1; i < sband->n_bitrates; i++) {
401 s = 0; 407 s = 0;
402 for (j = 0; j < mode->num_rates - i; j++) 408 for (j = 0; j < sband->n_bitrates - i; j++)
403 if (unlikely(mode->rates[rinfo[j].index].rate > 409 if (unlikely(sband->bitrates[rinfo[j].index].bitrate >
404 mode->rates[rinfo[j + 1].index].rate)) { 410 sband->bitrates[rinfo[j + 1].index].bitrate)) {
405 tmp = rinfo[j].index; 411 tmp = rinfo[j].index;
406 rinfo[j].index = rinfo[j + 1].index; 412 rinfo[j].index = rinfo[j + 1].index;
407 rinfo[j + 1].index = tmp; 413 rinfo[j + 1].index = tmp;
diff --git a/net/mac80211/rc80211_simple.c b/net/mac80211/rc80211_simple.c
index 9a78b116acff..c4678905a142 100644
--- a/net/mac80211/rc80211_simple.c
+++ b/net/mac80211/rc80211_simple.c
@@ -35,8 +35,8 @@ static void rate_control_rate_inc(struct ieee80211_local *local,
35 struct sta_info *sta) 35 struct sta_info *sta)
36{ 36{
37 struct ieee80211_sub_if_data *sdata; 37 struct ieee80211_sub_if_data *sdata;
38 struct ieee80211_hw_mode *mode; 38 struct ieee80211_supported_band *sband;
39 int i = sta->txrate; 39 int i = sta->txrate_idx;
40 int maxrate; 40 int maxrate;
41 41
42 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 42 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
@@ -45,18 +45,17 @@ static void rate_control_rate_inc(struct ieee80211_local *local,
45 return; 45 return;
46 } 46 }
47 47
48 mode = local->oper_hw_mode; 48 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
49 maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1; 49 maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
50 50
51 if (i > mode->num_rates) 51 if (i > sband->n_bitrates)
52 i = mode->num_rates - 2; 52 i = sband->n_bitrates - 2;
53 53
54 while (i + 1 < mode->num_rates) { 54 while (i + 1 < sband->n_bitrates) {
55 i++; 55 i++;
56 if (sta->supp_rates & BIT(i) && 56 if (rate_supported(sta, sband->band, i) &&
57 mode->rates[i].flags & IEEE80211_RATE_SUPPORTED &&
58 (maxrate < 0 || i <= maxrate)) { 57 (maxrate < 0 || i <= maxrate)) {
59 sta->txrate = i; 58 sta->txrate_idx = i;
60 break; 59 break;
61 } 60 }
62 } 61 }
@@ -67,8 +66,8 @@ static void rate_control_rate_dec(struct ieee80211_local *local,
67 struct sta_info *sta) 66 struct sta_info *sta)
68{ 67{
69 struct ieee80211_sub_if_data *sdata; 68 struct ieee80211_sub_if_data *sdata;
70 struct ieee80211_hw_mode *mode; 69 struct ieee80211_supported_band *sband;
71 int i = sta->txrate; 70 int i = sta->txrate_idx;
72 71
73 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 72 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
74 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) { 73 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
@@ -76,15 +75,14 @@ static void rate_control_rate_dec(struct ieee80211_local *local,
76 return; 75 return;
77 } 76 }
78 77
79 mode = local->oper_hw_mode; 78 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
80 if (i > mode->num_rates) 79 if (i > sband->n_bitrates)
81 i = mode->num_rates; 80 i = sband->n_bitrates;
82 81
83 while (i > 0) { 82 while (i > 0) {
84 i--; 83 i--;
85 if (sta->supp_rates & BIT(i) && 84 if (rate_supported(sta, sband->band, i)) {
86 mode->rates[i].flags & IEEE80211_RATE_SUPPORTED) { 85 sta->txrate_idx = i;
87 sta->txrate = i;
88 break; 86 break;
89 } 87 }
90 } 88 }
@@ -168,7 +166,7 @@ static void rate_control_simple_tx_status(void *priv, struct net_device *dev,
168 } else if (per_failed < RATE_CONTROL_NUM_UP) { 166 } else if (per_failed < RATE_CONTROL_NUM_UP) {
169 rate_control_rate_inc(local, sta); 167 rate_control_rate_inc(local, sta);
170 } 168 }
171 srctrl->tx_avg_rate_sum += status->control.rate->rate; 169 srctrl->tx_avg_rate_sum += status->control.tx_rate->bitrate;
172 srctrl->tx_avg_rate_num++; 170 srctrl->tx_avg_rate_num++;
173 srctrl->tx_num_failures = 0; 171 srctrl->tx_num_failures = 0;
174 srctrl->tx_num_xmit = 0; 172 srctrl->tx_num_xmit = 0;
@@ -201,7 +199,7 @@ static void rate_control_simple_tx_status(void *priv, struct net_device *dev,
201 199
202static void 200static void
203rate_control_simple_get_rate(void *priv, struct net_device *dev, 201rate_control_simple_get_rate(void *priv, struct net_device *dev,
204 struct ieee80211_hw_mode *mode, 202 struct ieee80211_supported_band *sband,
205 struct sk_buff *skb, 203 struct sk_buff *skb,
206 struct rate_selection *sel) 204 struct rate_selection *sel)
207{ 205{
@@ -219,7 +217,7 @@ rate_control_simple_get_rate(void *priv, struct net_device *dev,
219 fc = le16_to_cpu(hdr->frame_control); 217 fc = le16_to_cpu(hdr->frame_control);
220 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 218 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
221 is_multicast_ether_addr(hdr->addr1) || !sta) { 219 is_multicast_ether_addr(hdr->addr1) || !sta) {
222 sel->rate = rate_lowest(local, mode, sta); 220 sel->rate = rate_lowest(local, sband, sta);
223 if (sta) 221 if (sta)
224 sta_info_put(sta); 222 sta_info_put(sta);
225 return; 223 return;
@@ -228,18 +226,18 @@ rate_control_simple_get_rate(void *priv, struct net_device *dev,
228 /* If a forced rate is in effect, select it. */ 226 /* If a forced rate is in effect, select it. */
229 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 227 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
230 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) 228 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
231 sta->txrate = sdata->bss->force_unicast_rateidx; 229 sta->txrate_idx = sdata->bss->force_unicast_rateidx;
232 230
233 rateidx = sta->txrate; 231 rateidx = sta->txrate_idx;
234 232
235 if (rateidx >= mode->num_rates) 233 if (rateidx >= sband->n_bitrates)
236 rateidx = mode->num_rates - 1; 234 rateidx = sband->n_bitrates - 1;
237 235
238 sta->last_txrate = rateidx; 236 sta->last_txrate_idx = rateidx;
239 237
240 sta_info_put(sta); 238 sta_info_put(sta);
241 239
242 sel->rate = &mode->rates[rateidx]; 240 sel->rate = &sband->bitrates[rateidx];
243} 241}
244 242
245 243
@@ -247,21 +245,15 @@ static void rate_control_simple_rate_init(void *priv, void *priv_sta,
247 struct ieee80211_local *local, 245 struct ieee80211_local *local,
248 struct sta_info *sta) 246 struct sta_info *sta)
249{ 247{
250 struct ieee80211_hw_mode *mode; 248 struct ieee80211_supported_band *sband;
251 int i; 249
252 sta->txrate = 0; 250 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
253 mode = local->oper_hw_mode; 251
254 /* TODO: This routine should consider using RSSI from previous packets 252 /* TODO: This routine should consider using RSSI from previous packets
255 * as we need to have IEEE 802.1X auth succeed immediately after assoc.. 253 * as we need to have IEEE 802.1X auth succeed immediately after assoc..
256 * Until that method is implemented, we will use the lowest supported rate 254 * Until that method is implemented, we will use the lowest supported rate
257 * as a workaround, */ 255 * as a workaround, */
258 for (i = 0; i < mode->num_rates; i++) { 256 sta->txrate_idx = rate_lowest_index(local, sband, sta);
259 if ((sta->supp_rates & BIT(i)) &&
260 (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED)) {
261 sta->txrate = i;
262 break;
263 }
264 }
265} 257}
266 258
267 259
diff --git a/net/mac80211/regdomain.c b/net/mac80211/regdomain.c
deleted file mode 100644
index f42678fa62d1..000000000000
--- a/net/mac80211/regdomain.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
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 version 2 as
7 * published by the Free Software Foundation.
8 */
9
10/*
11 * This regulatory domain control implementation is known to be incomplete
12 * and confusing. mac80211 regulatory domain control will be significantly
13 * reworked in the not-too-distant future.
14 *
15 * For now, drivers wishing to control which channels are and aren't available
16 * are advised as follows:
17 * - set the IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag
18 * - continue to include *ALL* possible channels in the modes registered
19 * through ieee80211_register_hwmode()
20 * - for each allowable ieee80211_channel structure registered in the above
21 * call, set the flag member to some meaningful value such as
22 * IEEE80211_CHAN_W_SCAN | IEEE80211_CHAN_W_ACTIVE_SCAN |
23 * IEEE80211_CHAN_W_IBSS.
24 * - leave flag as 0 for non-allowable channels
25 *
26 * The usual implementation is for a driver to read a device EEPROM to
27 * determine which regulatory domain it should be operating under, then
28 * looking up the allowable channels in a driver-local table, then performing
29 * the above.
30 */
31
32#include <linux/module.h>
33#include <linux/netdevice.h>
34#include <net/mac80211.h>
35#include "ieee80211_i.h"
36
37static int ieee80211_regdom = 0x10; /* FCC */
38module_param(ieee80211_regdom, int, 0444);
39MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
40
41/*
42 * If firmware is upgraded by the vendor, additional channels can be used based
43 * on the new Japanese regulatory rules. This is indicated by setting
44 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
45 * module.
46 */
47static int ieee80211_japan_5ghz /* = 0 */;
48module_param(ieee80211_japan_5ghz, int, 0444);
49MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
50
51
52struct ieee80211_channel_range {
53 short start_freq;
54 short end_freq;
55 unsigned char power_level;
56 unsigned char antenna_max;
57};
58
59static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
60 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
61 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
62 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
63 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
64 { 0 }
65};
66
67static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
68 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
69 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
70 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
71 { 0 }
72};
73
74
75static const struct ieee80211_channel_range *channel_range =
76 ieee80211_fcc_channels;
77
78
79static void ieee80211_unmask_channel(int mode, struct ieee80211_channel *chan)
80{
81 int i;
82
83 chan->flag = 0;
84
85 for (i = 0; channel_range[i].start_freq; i++) {
86 const struct ieee80211_channel_range *r = &channel_range[i];
87 if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
88 if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
89 chan->freq >= 5260 && chan->freq <= 5320) {
90 /*
91 * Skip new channels in Japan since the
92 * firmware was not marked having been upgraded
93 * by the vendor.
94 */
95 continue;
96 }
97
98 if (ieee80211_regdom == 0x10 &&
99 (chan->freq == 5190 || chan->freq == 5210 ||
100 chan->freq == 5230)) {
101 /* Skip MKK channels when in FCC domain. */
102 continue;
103 }
104
105 chan->flag |= IEEE80211_CHAN_W_SCAN |
106 IEEE80211_CHAN_W_ACTIVE_SCAN |
107 IEEE80211_CHAN_W_IBSS;
108 chan->power_level = r->power_level;
109 chan->antenna_max = r->antenna_max;
110
111 if (ieee80211_regdom == 64 &&
112 (chan->freq == 5170 || chan->freq == 5190 ||
113 chan->freq == 5210 || chan->freq == 5230)) {
114 /*
115 * New regulatory rules in Japan have backwards
116 * compatibility with old channels in 5.15-5.25
117 * GHz band, but the station is not allowed to
118 * use active scan on these old channels.
119 */
120 chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
121 }
122
123 if (ieee80211_regdom == 64 &&
124 (chan->freq == 5260 || chan->freq == 5280 ||
125 chan->freq == 5300 || chan->freq == 5320)) {
126 /*
127 * IBSS is not allowed on 5.25-5.35 GHz band
128 * due to radar detection requirements.
129 */
130 chan->flag &= ~IEEE80211_CHAN_W_IBSS;
131 }
132
133 break;
134 }
135 }
136}
137
138
139void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
140{
141 int c;
142 for (c = 0; c < mode->num_channels; c++)
143 ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
144}
145
146
147void ieee80211_regdomain_init(void)
148{
149 if (ieee80211_regdom == 0x40)
150 channel_range = ieee80211_mkk_channels;
151}
152
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 3aae8e9e4e0a..c9ff98a93211 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -82,10 +82,10 @@ static inline int should_drop_frame(struct ieee80211_rx_status *status,
82 */ 82 */
83static struct sk_buff * 83static struct sk_buff *
84ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, 84ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
85 struct ieee80211_rx_status *status) 85 struct ieee80211_rx_status *status,
86 struct ieee80211_rate *rate)
86{ 87{
87 struct ieee80211_sub_if_data *sdata; 88 struct ieee80211_sub_if_data *sdata;
88 struct ieee80211_rate *rate;
89 int needed_headroom = 0; 89 int needed_headroom = 0;
90 struct ieee80211_radiotap_header *rthdr; 90 struct ieee80211_radiotap_header *rthdr;
91 __le64 *rttsft = NULL; 91 __le64 *rttsft = NULL;
@@ -194,14 +194,11 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
194 rtfixed->rx_flags |= 194 rtfixed->rx_flags |=
195 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS); 195 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
196 196
197 rate = ieee80211_get_rate(local, status->phymode, 197 rtfixed->rate = rate->bitrate / 5;
198 status->rate);
199 if (rate)
200 rtfixed->rate = rate->rate / 5;
201 198
202 rtfixed->chan_freq = cpu_to_le16(status->freq); 199 rtfixed->chan_freq = cpu_to_le16(status->freq);
203 200
204 if (status->phymode == MODE_IEEE80211A) 201 if (status->band == IEEE80211_BAND_5GHZ)
205 rtfixed->chan_flags = 202 rtfixed->chan_flags =
206 cpu_to_le16(IEEE80211_CHAN_OFDM | 203 cpu_to_le16(IEEE80211_CHAN_OFDM |
207 IEEE80211_CHAN_5GHZ); 204 IEEE80211_CHAN_5GHZ);
@@ -320,34 +317,21 @@ static void ieee80211_verify_ip_alignment(struct ieee80211_txrx_data *rx)
320 317
321 318
322static u32 ieee80211_rx_load_stats(struct ieee80211_local *local, 319static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
323 struct sk_buff *skb, 320 struct sk_buff *skb,
324 struct ieee80211_rx_status *status) 321 struct ieee80211_rx_status *status,
322 struct ieee80211_rate *rate)
325{ 323{
326 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 324 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
327 u32 load = 0, hdrtime; 325 u32 load = 0, hdrtime;
328 struct ieee80211_rate *rate;
329 struct ieee80211_hw_mode *mode = local->hw.conf.mode;
330 int i;
331 326
332 /* Estimate total channel use caused by this frame */ 327 /* Estimate total channel use caused by this frame */
333 328
334 if (unlikely(mode->num_rates < 0))
335 return TXRX_CONTINUE;
336
337 rate = &mode->rates[0];
338 for (i = 0; i < mode->num_rates; i++) {
339 if (mode->rates[i].val == status->rate) {
340 rate = &mode->rates[i];
341 break;
342 }
343 }
344
345 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values, 329 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
346 * 1 usec = 1/8 * (1080 / 10) = 13.5 */ 330 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
347 331
348 if (mode->mode == MODE_IEEE80211A || 332 if (status->band == IEEE80211_BAND_5GHZ ||
349 (mode->mode == MODE_IEEE80211G && 333 (status->band == IEEE80211_BAND_5GHZ &&
350 rate->flags & IEEE80211_RATE_ERP)) 334 rate->flags & IEEE80211_RATE_ERP_G))
351 hdrtime = CHAN_UTIL_HDR_SHORT; 335 hdrtime = CHAN_UTIL_HDR_SHORT;
352 else 336 else
353 hdrtime = CHAN_UTIL_HDR_LONG; 337 hdrtime = CHAN_UTIL_HDR_LONG;
@@ -356,7 +340,8 @@ static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
356 if (!is_multicast_ether_addr(hdr->addr1)) 340 if (!is_multicast_ether_addr(hdr->addr1))
357 load += hdrtime; 341 load += hdrtime;
358 342
359 load += skb->len * rate->rate_inv; 343 /* TODO: optimise again */
344 load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
360 345
361 /* Divide channel_use by 8 to avoid wrapping around the counter */ 346 /* Divide channel_use by 8 to avoid wrapping around the counter */
362 load >>= CHAN_UTIL_SHIFT; 347 load >>= CHAN_UTIL_SHIFT;
@@ -1685,7 +1670,8 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1685static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, 1670static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1686 struct sk_buff *skb, 1671 struct sk_buff *skb,
1687 struct ieee80211_rx_status *status, 1672 struct ieee80211_rx_status *status,
1688 u32 load) 1673 u32 load,
1674 struct ieee80211_rate *rate)
1689{ 1675{
1690 struct ieee80211_local *local = hw_to_local(hw); 1676 struct ieee80211_local *local = hw_to_local(hw);
1691 struct ieee80211_sub_if_data *sdata; 1677 struct ieee80211_sub_if_data *sdata;
@@ -1705,6 +1691,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1705 1691
1706 rx.u.rx.status = status; 1692 rx.u.rx.status = status;
1707 rx.u.rx.load = load; 1693 rx.u.rx.load = load;
1694 rx.u.rx.rate = rate;
1708 rx.fc = le16_to_cpu(hdr->frame_control); 1695 rx.fc = le16_to_cpu(hdr->frame_control);
1709 type = rx.fc & IEEE80211_FCTL_FTYPE; 1696 type = rx.fc & IEEE80211_FCTL_FTYPE;
1710 1697
@@ -1837,6 +1824,8 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
1837 u16 head_seq_num, buf_size; 1824 u16 head_seq_num, buf_size;
1838 int index; 1825 int index;
1839 u32 pkt_load; 1826 u32 pkt_load;
1827 struct ieee80211_supported_band *sband;
1828 struct ieee80211_rate *rate;
1840 1829
1841 buf_size = tid_agg_rx->buf_size; 1830 buf_size = tid_agg_rx->buf_size;
1842 head_seq_num = tid_agg_rx->head_seq_num; 1831 head_seq_num = tid_agg_rx->head_seq_num;
@@ -1867,12 +1856,14 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
1867 memcpy(&status, 1856 memcpy(&status,
1868 tid_agg_rx->reorder_buf[index]->cb, 1857 tid_agg_rx->reorder_buf[index]->cb,
1869 sizeof(status)); 1858 sizeof(status));
1859 sband = local->hw.wiphy->bands[status.band];
1860 rate = &sband->bitrates[status.rate_idx];
1870 pkt_load = ieee80211_rx_load_stats(local, 1861 pkt_load = ieee80211_rx_load_stats(local,
1871 tid_agg_rx->reorder_buf[index], 1862 tid_agg_rx->reorder_buf[index],
1872 &status); 1863 &status, rate);
1873 __ieee80211_rx_handle_packet(hw, 1864 __ieee80211_rx_handle_packet(hw,
1874 tid_agg_rx->reorder_buf[index], 1865 tid_agg_rx->reorder_buf[index],
1875 &status, pkt_load); 1866 &status, pkt_load, rate);
1876 tid_agg_rx->stored_mpdu_num--; 1867 tid_agg_rx->stored_mpdu_num--;
1877 tid_agg_rx->reorder_buf[index] = NULL; 1868 tid_agg_rx->reorder_buf[index] = NULL;
1878 } 1869 }
@@ -1912,11 +1903,13 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
1912 /* release the reordered frame back to stack */ 1903 /* release the reordered frame back to stack */
1913 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, 1904 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
1914 sizeof(status)); 1905 sizeof(status));
1906 sband = local->hw.wiphy->bands[status.band];
1907 rate = &sband->bitrates[status.rate_idx];
1915 pkt_load = ieee80211_rx_load_stats(local, 1908 pkt_load = ieee80211_rx_load_stats(local,
1916 tid_agg_rx->reorder_buf[index], 1909 tid_agg_rx->reorder_buf[index],
1917 &status); 1910 &status, rate);
1918 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], 1911 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
1919 &status, pkt_load); 1912 &status, pkt_load, rate);
1920 tid_agg_rx->stored_mpdu_num--; 1913 tid_agg_rx->stored_mpdu_num--;
1921 tid_agg_rx->reorder_buf[index] = NULL; 1914 tid_agg_rx->reorder_buf[index] = NULL;
1922 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); 1915 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
@@ -1997,6 +1990,25 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1997{ 1990{
1998 struct ieee80211_local *local = hw_to_local(hw); 1991 struct ieee80211_local *local = hw_to_local(hw);
1999 u32 pkt_load; 1992 u32 pkt_load;
1993 struct ieee80211_rate *rate = NULL;
1994 struct ieee80211_supported_band *sband;
1995
1996 if (status->band < 0 ||
1997 status->band > IEEE80211_NUM_BANDS) {
1998 WARN_ON(1);
1999 return;
2000 }
2001
2002 sband = local->hw.wiphy->bands[status->band];
2003
2004 if (!sband ||
2005 status->rate_idx < 0 ||
2006 status->rate_idx >= sband->n_bitrates) {
2007 WARN_ON(1);
2008 return;
2009 }
2010
2011 rate = &sband->bitrates[status->rate_idx];
2000 2012
2001 /* 2013 /*
2002 * key references and virtual interfaces are protected using RCU 2014 * key references and virtual interfaces are protected using RCU
@@ -2011,17 +2023,17 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2011 * if it was previously present. 2023 * if it was previously present.
2012 * Also, frames with less than 16 bytes are dropped. 2024 * Also, frames with less than 16 bytes are dropped.
2013 */ 2025 */
2014 skb = ieee80211_rx_monitor(local, skb, status); 2026 skb = ieee80211_rx_monitor(local, skb, status, rate);
2015 if (!skb) { 2027 if (!skb) {
2016 rcu_read_unlock(); 2028 rcu_read_unlock();
2017 return; 2029 return;
2018 } 2030 }
2019 2031
2020 pkt_load = ieee80211_rx_load_stats(local, skb, status); 2032 pkt_load = ieee80211_rx_load_stats(local, skb, status, rate);
2021 local->channel_use_raw += pkt_load; 2033 local->channel_use_raw += pkt_load;
2022 2034
2023 if (!ieee80211_rx_reorder_ampdu(local, skb)) 2035 if (!ieee80211_rx_reorder_ampdu(local, skb))
2024 __ieee80211_rx_handle_packet(hw, skb, status, pkt_load); 2036 __ieee80211_rx_handle_packet(hw, skb, status, pkt_load, rate);
2025 2037
2026 rcu_read_unlock(); 2038 rcu_read_unlock();
2027} 2039}
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index ddc1f47194dd..746bbdea6b4c 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -74,30 +74,6 @@ struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
74} 74}
75EXPORT_SYMBOL(sta_info_get); 75EXPORT_SYMBOL(sta_info_get);
76 76
77int sta_info_min_txrate_get(struct ieee80211_local *local)
78{
79 struct sta_info *sta;
80 struct ieee80211_hw_mode *mode;
81 int min_txrate = 9999999;
82 int i;
83
84 read_lock_bh(&local->sta_lock);
85 mode = local->oper_hw_mode;
86 for (i = 0; i < STA_HASH_SIZE; i++) {
87 sta = local->sta_hash[i];
88 while (sta) {
89 if (sta->txrate < min_txrate)
90 min_txrate = sta->txrate;
91 sta = sta->hnext;
92 }
93 }
94 read_unlock_bh(&local->sta_lock);
95 if (min_txrate == 9999999)
96 min_txrate = 0;
97
98 return mode->rates[min_txrate].rate;
99}
100
101 77
102static void sta_info_release(struct kref *kref) 78static void sta_info_release(struct kref *kref)
103{ 79{
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 75573dc79d7a..3573743dfa59 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -133,10 +133,11 @@ struct sta_info {
133 unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */ 133 unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
134 134
135 unsigned long last_rx; 135 unsigned long last_rx;
136 u32 supp_rates; /* bitmap of supported rates in local->curr_rates */ 136 /* bitmap of supported rates per band */
137 int txrate; /* index in local->curr_rates */ 137 u64 supp_rates[IEEE80211_NUM_BANDS];
138 int last_txrate; /* last rate used to send a frame to this STA */ 138 int txrate_idx;
139 int last_nonerp_idx; 139 /* last rates used to send a frame to this STA */
140 int last_txrate_idx, last_nonerp_txrate_idx;
140 141
141 struct net_device *dev; /* which net device is this station associated 142 struct net_device *dev; /* which net device is this station associated
142 * to */ 143 * to */
@@ -222,7 +223,6 @@ static inline void __sta_info_get(struct sta_info *sta)
222} 223}
223 224
224struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr); 225struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr);
225int sta_info_min_txrate_get(struct ieee80211_local *local);
226void sta_info_put(struct sta_info *sta); 226void sta_info_put(struct sta_info *sta);
227struct sta_info * sta_info_add(struct ieee80211_local *local, 227struct sta_info * sta_info_add(struct ieee80211_local *local,
228 struct net_device *dev, u8 *addr, gfp_t gfp); 228 struct net_device *dev, u8 *addr, gfp_t gfp);
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 38e1b2bd8245..9e5359991985 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -92,9 +92,13 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
92 int rate, mrate, erp, dur, i; 92 int rate, mrate, erp, dur, i;
93 struct ieee80211_rate *txrate = tx->u.tx.rate; 93 struct ieee80211_rate *txrate = tx->u.tx.rate;
94 struct ieee80211_local *local = tx->local; 94 struct ieee80211_local *local = tx->local;
95 struct ieee80211_hw_mode *mode = tx->u.tx.mode; 95 struct ieee80211_supported_band *sband;
96 96
97 erp = txrate->flags & IEEE80211_RATE_ERP; 97 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
98
99 erp = 0;
100 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
101 erp = txrate->flags & IEEE80211_RATE_ERP_G;
98 102
99 /* 103 /*
100 * data and mgmt (except PS Poll): 104 * data and mgmt (except PS Poll):
@@ -150,20 +154,36 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
150 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps 154 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
151 */ 155 */
152 rate = -1; 156 rate = -1;
153 mrate = 10; /* use 1 Mbps if everything fails */ 157 /* use lowest available if everything fails */
154 for (i = 0; i < mode->num_rates; i++) { 158 mrate = sband->bitrates[0].bitrate;
155 struct ieee80211_rate *r = &mode->rates[i]; 159 for (i = 0; i < sband->n_bitrates; i++) {
156 if (r->rate > txrate->rate) 160 struct ieee80211_rate *r = &sband->bitrates[i];
157 break;
158 161
159 if (IEEE80211_RATE_MODULATION(txrate->flags) != 162 if (r->bitrate > txrate->bitrate)
160 IEEE80211_RATE_MODULATION(r->flags)) 163 break;
161 continue;
162 164
163 if (r->flags & IEEE80211_RATE_BASIC) 165 if (tx->sdata->basic_rates & BIT(i))
164 rate = r->rate; 166 rate = r->bitrate;
165 else if (r->flags & IEEE80211_RATE_MANDATORY) 167
166 mrate = r->rate; 168 switch (sband->band) {
169 case IEEE80211_BAND_2GHZ: {
170 u32 flag;
171 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
172 flag = IEEE80211_RATE_MANDATORY_G;
173 else
174 flag = IEEE80211_RATE_MANDATORY_B;
175 if (r->flags & flag)
176 mrate = r->bitrate;
177 break;
178 }
179 case IEEE80211_BAND_5GHZ:
180 if (r->flags & IEEE80211_RATE_MANDATORY_A)
181 mrate = r->bitrate;
182 break;
183 case IEEE80211_NUM_BANDS:
184 WARN_ON(1);
185 break;
186 }
167 } 187 }
168 if (rate == -1) { 188 if (rate == -1) {
169 /* No matching basic rate found; use highest suitable mandatory 189 /* No matching basic rate found; use highest suitable mandatory
@@ -184,7 +204,7 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
184 dur *= 2; /* ACK + SIFS */ 204 dur *= 2; /* ACK + SIFS */
185 /* next fragment */ 205 /* next fragment */
186 dur += ieee80211_frame_duration(local, next_frag_len, 206 dur += ieee80211_frame_duration(local, next_frag_len,
187 txrate->rate, erp, 207 txrate->bitrate, erp,
188 tx->sdata->bss_conf.use_short_preamble); 208 tx->sdata->bss_conf.use_short_preamble);
189 } 209 }
190 210
@@ -585,26 +605,28 @@ static ieee80211_txrx_result
585ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx) 605ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
586{ 606{
587 struct rate_selection rsel; 607 struct rate_selection rsel;
608 struct ieee80211_supported_band *sband;
609
610 sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
588 611
589 if (likely(!tx->u.tx.rate)) { 612 if (likely(!tx->u.tx.rate)) {
590 rate_control_get_rate(tx->dev, tx->u.tx.mode, tx->skb, &rsel); 613 rate_control_get_rate(tx->dev, sband, tx->skb, &rsel);
591 tx->u.tx.rate = rsel.rate; 614 tx->u.tx.rate = rsel.rate;
592 if (unlikely(rsel.probe != NULL)) { 615 if (unlikely(rsel.probe)) {
593 tx->u.tx.control->flags |= 616 tx->u.tx.control->flags |=
594 IEEE80211_TXCTL_RATE_CTRL_PROBE; 617 IEEE80211_TXCTL_RATE_CTRL_PROBE;
595 tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG; 618 tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
596 tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val; 619 tx->u.tx.control->alt_retry_rate = tx->u.tx.rate;
597 tx->u.tx.rate = rsel.probe; 620 tx->u.tx.rate = rsel.probe;
598 } else 621 } else
599 tx->u.tx.control->alt_retry_rate = -1; 622 tx->u.tx.control->alt_retry_rate = NULL;
600 623
601 if (!tx->u.tx.rate) 624 if (!tx->u.tx.rate)
602 return TXRX_DROP; 625 return TXRX_DROP;
603 } else 626 } else
604 tx->u.tx.control->alt_retry_rate = -1; 627 tx->u.tx.control->alt_retry_rate = NULL;
605 628
606 if (tx->u.tx.mode->mode == MODE_IEEE80211G && 629 if (tx->sdata->bss_conf.use_cts_prot &&
607 tx->sdata->bss_conf.use_cts_prot &&
608 (tx->flags & IEEE80211_TXRXD_FRAGMENTED) && rsel.nonerp) { 630 (tx->flags & IEEE80211_TXRXD_FRAGMENTED) && rsel.nonerp) {
609 tx->u.tx.last_frag_rate = tx->u.tx.rate; 631 tx->u.tx.last_frag_rate = tx->u.tx.rate;
610 if (rsel.probe) 632 if (rsel.probe)
@@ -612,13 +634,13 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
612 else 634 else
613 tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG; 635 tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
614 tx->u.tx.rate = rsel.nonerp; 636 tx->u.tx.rate = rsel.nonerp;
615 tx->u.tx.control->rate = rsel.nonerp; 637 tx->u.tx.control->tx_rate = rsel.nonerp;
616 tx->u.tx.control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE; 638 tx->u.tx.control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
617 } else { 639 } else {
618 tx->u.tx.last_frag_rate = tx->u.tx.rate; 640 tx->u.tx.last_frag_rate = tx->u.tx.rate;
619 tx->u.tx.control->rate = tx->u.tx.rate; 641 tx->u.tx.control->tx_rate = tx->u.tx.rate;
620 } 642 }
621 tx->u.tx.control->tx_rate = tx->u.tx.rate->val; 643 tx->u.tx.control->tx_rate = tx->u.tx.rate;
622 644
623 return TXRX_CONTINUE; 645 return TXRX_CONTINUE;
624} 646}
@@ -630,7 +652,6 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
630 u16 fc = le16_to_cpu(hdr->frame_control); 652 u16 fc = le16_to_cpu(hdr->frame_control);
631 u16 dur; 653 u16 dur;
632 struct ieee80211_tx_control *control = tx->u.tx.control; 654 struct ieee80211_tx_control *control = tx->u.tx.control;
633 struct ieee80211_hw_mode *mode = tx->u.tx.mode;
634 655
635 if (!control->retry_limit) { 656 if (!control->retry_limit) {
636 if (!is_multicast_ether_addr(hdr->addr1)) { 657 if (!is_multicast_ether_addr(hdr->addr1)) {
@@ -657,14 +678,14 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
657 * frames. 678 * frames.
658 * TODO: The last fragment could still use multiple retry 679 * TODO: The last fragment could still use multiple retry
659 * rates. */ 680 * rates. */
660 control->alt_retry_rate = -1; 681 control->alt_retry_rate = NULL;
661 } 682 }
662 683
663 /* Use CTS protection for unicast frames sent using extended rates if 684 /* Use CTS protection for unicast frames sent using extended rates if
664 * there are associated non-ERP stations and RTS/CTS is not configured 685 * there are associated non-ERP stations and RTS/CTS is not configured
665 * for the frame. */ 686 * for the frame. */
666 if (mode->mode == MODE_IEEE80211G && 687 if ((tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) &&
667 (tx->u.tx.rate->flags & IEEE80211_RATE_ERP) && 688 (tx->u.tx.rate->flags & IEEE80211_RATE_ERP_G) &&
668 (tx->flags & IEEE80211_TXRXD_TXUNICAST) && 689 (tx->flags & IEEE80211_TXRXD_TXUNICAST) &&
669 tx->sdata->bss_conf.use_cts_prot && 690 tx->sdata->bss_conf.use_cts_prot &&
670 !(control->flags & IEEE80211_TXCTL_USE_RTS_CTS)) 691 !(control->flags & IEEE80211_TXCTL_USE_RTS_CTS))
@@ -674,10 +695,10 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
674 * short preambles at the selected rate and short preambles are 695 * short preambles at the selected rate and short preambles are
675 * available on the network at the current point in time. */ 696 * available on the network at the current point in time. */
676 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && 697 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
677 (tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) && 698 (tx->u.tx.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
678 tx->sdata->bss_conf.use_short_preamble && 699 tx->sdata->bss_conf.use_short_preamble &&
679 (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) { 700 (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
680 tx->u.tx.control->tx_rate = tx->u.tx.rate->val2; 701 tx->u.tx.control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
681 } 702 }
682 703
683 /* Setup duration field for the first fragment of the frame. Duration 704 /* Setup duration field for the first fragment of the frame. Duration
@@ -690,19 +711,33 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
690 711
691 if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) || 712 if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
692 (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) { 713 (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
693 struct ieee80211_rate *rate; 714 struct ieee80211_supported_band *sband;
715 struct ieee80211_rate *rate, *baserate;
716 int idx;
717
718 sband = tx->local->hw.wiphy->bands[
719 tx->local->hw.conf.channel->band];
694 720
695 /* Do not use multiple retry rates when using RTS/CTS */ 721 /* Do not use multiple retry rates when using RTS/CTS */
696 control->alt_retry_rate = -1; 722 control->alt_retry_rate = NULL;
697 723
698 /* Use min(data rate, max base rate) as CTS/RTS rate */ 724 /* Use min(data rate, max base rate) as CTS/RTS rate */
699 rate = tx->u.tx.rate; 725 rate = tx->u.tx.rate;
700 while (rate > mode->rates && 726 baserate = NULL;
701 !(rate->flags & IEEE80211_RATE_BASIC)) 727
702 rate--; 728 for (idx = 0; idx < sband->n_bitrates; idx++) {
729 if (sband->bitrates[idx].bitrate > rate->bitrate)
730 continue;
731 if (tx->sdata->basic_rates & BIT(idx) &&
732 (!baserate ||
733 (baserate->bitrate < sband->bitrates[idx].bitrate)))
734 baserate = &sband->bitrates[idx];
735 }
703 736
704 control->rts_cts_rate = rate->val; 737 if (baserate)
705 control->rts_rate = rate; 738 control->rts_cts_rate = baserate;
739 else
740 control->rts_cts_rate = &sband->bitrates[0];
706 } 741 }
707 742
708 if (tx->sta) { 743 if (tx->sta) {
@@ -726,10 +761,10 @@ static ieee80211_txrx_result
726ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx) 761ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
727{ 762{
728 struct ieee80211_local *local = tx->local; 763 struct ieee80211_local *local = tx->local;
729 struct ieee80211_hw_mode *mode = tx->u.tx.mode;
730 struct sk_buff *skb = tx->skb; 764 struct sk_buff *skb = tx->skb;
731 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 765 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
732 u32 load = 0, hdrtime; 766 u32 load = 0, hdrtime;
767 struct ieee80211_rate *rate = tx->u.tx.rate;
733 768
734 /* TODO: this could be part of tx_status handling, so that the number 769 /* TODO: this could be part of tx_status handling, so that the number
735 * of retries would be known; TX rate should in that case be stored 770 * of retries would be known; TX rate should in that case be stored
@@ -740,9 +775,9 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
740 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values, 775 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
741 * 1 usec = 1/8 * (1080 / 10) = 13.5 */ 776 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
742 777
743 if (mode->mode == MODE_IEEE80211A || 778 if (tx->u.tx.channel->band == IEEE80211_BAND_5GHZ ||
744 (mode->mode == MODE_IEEE80211G && 779 (tx->u.tx.channel->band == IEEE80211_BAND_2GHZ &&
745 tx->u.tx.rate->flags & IEEE80211_RATE_ERP)) 780 rate->flags & IEEE80211_RATE_ERP_G))
746 hdrtime = CHAN_UTIL_HDR_SHORT; 781 hdrtime = CHAN_UTIL_HDR_SHORT;
747 else 782 else
748 hdrtime = CHAN_UTIL_HDR_LONG; 783 hdrtime = CHAN_UTIL_HDR_LONG;
@@ -756,14 +791,15 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
756 else if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) 791 else if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
757 load += hdrtime; 792 load += hdrtime;
758 793
759 load += skb->len * tx->u.tx.rate->rate_inv; 794 /* TODO: optimise again */
795 load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
760 796
761 if (tx->u.tx.extra_frag) { 797 if (tx->u.tx.extra_frag) {
762 int i; 798 int i;
763 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 799 for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
764 load += 2 * hdrtime; 800 load += 2 * hdrtime;
765 load += tx->u.tx.extra_frag[i]->len * 801 load += tx->u.tx.extra_frag[i]->len *
766 tx->u.tx.rate->rate; 802 tx->u.tx.rate->bitrate;
767 } 803 }
768 } 804 }
769 805
@@ -816,10 +852,12 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
816 struct ieee80211_radiotap_iterator iterator; 852 struct ieee80211_radiotap_iterator iterator;
817 struct ieee80211_radiotap_header *rthdr = 853 struct ieee80211_radiotap_header *rthdr =
818 (struct ieee80211_radiotap_header *) skb->data; 854 (struct ieee80211_radiotap_header *) skb->data;
819 struct ieee80211_hw_mode *mode = tx->local->hw.conf.mode; 855 struct ieee80211_supported_band *sband;
820 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); 856 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
821 struct ieee80211_tx_control *control = tx->u.tx.control; 857 struct ieee80211_tx_control *control = tx->u.tx.control;
822 858
859 sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
860
823 control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT; 861 control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
824 tx->flags |= IEEE80211_TXRXD_TX_INJECTED; 862 tx->flags |= IEEE80211_TXRXD_TX_INJECTED;
825 tx->flags &= ~IEEE80211_TXRXD_FRAGMENTED; 863 tx->flags &= ~IEEE80211_TXRXD_FRAGMENTED;
@@ -852,10 +890,12 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
852 * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps 890 * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
853 */ 891 */
854 target_rate = (*iterator.this_arg) * 5; 892 target_rate = (*iterator.this_arg) * 5;
855 for (i = 0; i < mode->num_rates; i++) { 893 for (i = 0; i < sband->n_bitrates; i++) {
856 struct ieee80211_rate *r = &mode->rates[i]; 894 struct ieee80211_rate *r;
857 895
858 if (r->rate == target_rate) { 896 r = &sband->bitrates[i];
897
898 if (r->bitrate == target_rate) {
859 tx->u.tx.rate = r; 899 tx->u.tx.rate = r;
860 break; 900 break;
861 } 901 }
@@ -870,9 +910,11 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
870 control->antenna_sel_tx = (*iterator.this_arg) + 1; 910 control->antenna_sel_tx = (*iterator.this_arg) + 1;
871 break; 911 break;
872 912
913#if 0
873 case IEEE80211_RADIOTAP_DBM_TX_POWER: 914 case IEEE80211_RADIOTAP_DBM_TX_POWER:
874 control->power_level = *iterator.this_arg; 915 control->power_level = *iterator.this_arg;
875 break; 916 break;
917#endif
876 918
877 case IEEE80211_RADIOTAP_FLAGS: 919 case IEEE80211_RADIOTAP_FLAGS:
878 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { 920 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
@@ -1054,8 +1096,8 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1054 if (__ieee80211_queue_stopped(local, control->queue)) 1096 if (__ieee80211_queue_stopped(local, control->queue))
1055 return IEEE80211_TX_FRAG_AGAIN; 1097 return IEEE80211_TX_FRAG_AGAIN;
1056 if (i == tx->u.tx.num_extra_frag) { 1098 if (i == tx->u.tx.num_extra_frag) {
1057 control->tx_rate = tx->u.tx.last_frag_hwrate; 1099 control->tx_rate = tx->u.tx.last_frag_rate;
1058 control->rate = tx->u.tx.last_frag_rate; 1100
1059 if (tx->flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG) 1101 if (tx->flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG)
1060 control->flags |= 1102 control->flags |=
1061 IEEE80211_TXCTL_RATE_CTRL_PROBE; 1103 IEEE80211_TXCTL_RATE_CTRL_PROBE;
@@ -1114,7 +1156,7 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1114 rcu_read_lock(); 1156 rcu_read_lock();
1115 1157
1116 sta = tx.sta; 1158 sta = tx.sta;
1117 tx.u.tx.mode = local->hw.conf.mode; 1159 tx.u.tx.channel = local->hw.conf.channel;
1118 1160
1119 for (handler = local->tx_handlers; *handler != NULL; 1161 for (handler = local->tx_handlers; *handler != NULL;
1120 handler++) { 1162 handler++) {
@@ -1151,7 +1193,6 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1151 } else { 1193 } else {
1152 next_len = 0; 1194 next_len = 0;
1153 tx.u.tx.rate = tx.u.tx.last_frag_rate; 1195 tx.u.tx.rate = tx.u.tx.last_frag_rate;
1154 tx.u.tx.last_frag_hwrate = tx.u.tx.rate->val;
1155 } 1196 }
1156 dur = ieee80211_duration(&tx, 0, next_len); 1197 dur = ieee80211_duration(&tx, 0, next_len);
1157 hdr->duration_id = cpu_to_le16(dur); 1198 hdr->duration_id = cpu_to_le16(dur);
@@ -1188,7 +1229,6 @@ retry:
1188 store->skb = skb; 1229 store->skb = skb;
1189 store->extra_frag = tx.u.tx.extra_frag; 1230 store->extra_frag = tx.u.tx.extra_frag;
1190 store->num_extra_frag = tx.u.tx.num_extra_frag; 1231 store->num_extra_frag = tx.u.tx.num_extra_frag;
1191 store->last_frag_hwrate = tx.u.tx.last_frag_hwrate;
1192 store->last_frag_rate = tx.u.tx.last_frag_rate; 1232 store->last_frag_rate = tx.u.tx.last_frag_rate;
1193 store->last_frag_rate_ctrl_probe = 1233 store->last_frag_rate_ctrl_probe =
1194 !!(tx.flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG); 1234 !!(tx.flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG);
@@ -1609,7 +1649,6 @@ void ieee80211_tx_pending(unsigned long data)
1609 tx.u.tx.control = &store->control; 1649 tx.u.tx.control = &store->control;
1610 tx.u.tx.extra_frag = store->extra_frag; 1650 tx.u.tx.extra_frag = store->extra_frag;
1611 tx.u.tx.num_extra_frag = store->num_extra_frag; 1651 tx.u.tx.num_extra_frag = store->num_extra_frag;
1612 tx.u.tx.last_frag_hwrate = store->last_frag_hwrate;
1613 tx.u.tx.last_frag_rate = store->last_frag_rate; 1652 tx.u.tx.last_frag_rate = store->last_frag_rate;
1614 tx.flags = 0; 1653 tx.flags = 0;
1615 if (store->last_frag_rate_ctrl_probe) 1654 if (store->last_frag_rate_ctrl_probe)
@@ -1712,6 +1751,9 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1712 struct ieee80211_if_ap *ap = NULL; 1751 struct ieee80211_if_ap *ap = NULL;
1713 struct rate_selection rsel; 1752 struct rate_selection rsel;
1714 struct beacon_data *beacon; 1753 struct beacon_data *beacon;
1754 struct ieee80211_supported_band *sband;
1755
1756 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1715 1757
1716 rcu_read_lock(); 1758 rcu_read_lock();
1717 1759
@@ -1750,8 +1792,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1750 beacon->tail_len); 1792 beacon->tail_len);
1751 1793
1752 if (control) { 1794 if (control) {
1753 rate_control_get_rate(local->mdev, local->oper_hw_mode, skb, 1795 rate_control_get_rate(local->mdev, sband, skb, &rsel);
1754 &rsel);
1755 if (!rsel.rate) { 1796 if (!rsel.rate) {
1756 if (net_ratelimit()) { 1797 if (net_ratelimit()) {
1757 printk(KERN_DEBUG "%s: ieee80211_beacon_get: " 1798 printk(KERN_DEBUG "%s: ieee80211_beacon_get: "
@@ -1764,12 +1805,11 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1764 } 1805 }
1765 1806
1766 control->vif = vif; 1807 control->vif = vif;
1767 control->tx_rate = 1808 control->tx_rate = rsel.rate;
1768 (sdata->bss_conf.use_short_preamble && 1809 if (sdata->bss_conf.use_short_preamble &&
1769 (rsel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ? 1810 rsel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
1770 rsel.rate->val2 : rsel.rate->val; 1811 control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
1771 control->antenna_sel_tx = local->hw.conf.antenna_sel_tx; 1812 control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
1772 control->power_level = local->hw.conf.power_level;
1773 control->flags |= IEEE80211_TXCTL_NO_ACK; 1813 control->flags |= IEEE80211_TXCTL_NO_ACK;
1774 control->retry_limit = 1; 1814 control->retry_limit = 1;
1775 control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK; 1815 control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
@@ -1874,7 +1914,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
1874 } 1914 }
1875 sta = tx.sta; 1915 sta = tx.sta;
1876 tx.flags |= IEEE80211_TXRXD_TXPS_BUFFERED; 1916 tx.flags |= IEEE80211_TXRXD_TXPS_BUFFERED;
1877 tx.u.tx.mode = local->hw.conf.mode; 1917 tx.u.tx.channel = local->hw.conf.channel;
1878 1918
1879 for (handler = local->tx_handlers; *handler != NULL; handler++) { 1919 for (handler = local->tx_handlers; *handler != NULL; handler++) {
1880 res = (*handler)(&tx); 1920 res = (*handler)(&tx);
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 5e631ce98d7e..f64804fed0a9 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -41,92 +41,6 @@ const unsigned char bridge_tunnel_header[] =
41 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 41 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
42 42
43 43
44static int rate_list_match(const int *rate_list, int rate)
45{
46 int i;
47
48 if (!rate_list)
49 return 0;
50
51 for (i = 0; rate_list[i] >= 0; i++)
52 if (rate_list[i] == rate)
53 return 1;
54
55 return 0;
56}
57
58void ieee80211_prepare_rates(struct ieee80211_local *local,
59 struct ieee80211_hw_mode *mode)
60{
61 int i;
62
63 for (i = 0; i < mode->num_rates; i++) {
64 struct ieee80211_rate *rate = &mode->rates[i];
65
66 rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
67 IEEE80211_RATE_BASIC);
68
69 if (local->supp_rates[mode->mode]) {
70 if (!rate_list_match(local->supp_rates[mode->mode],
71 rate->rate))
72 continue;
73 }
74
75 rate->flags |= IEEE80211_RATE_SUPPORTED;
76
77 /* Use configured basic rate set if it is available. If not,
78 * use defaults that are sane for most cases. */
79 if (local->basic_rates[mode->mode]) {
80 if (rate_list_match(local->basic_rates[mode->mode],
81 rate->rate))
82 rate->flags |= IEEE80211_RATE_BASIC;
83 } else switch (mode->mode) {
84 case MODE_IEEE80211A:
85 if (rate->rate == 60 || rate->rate == 120 ||
86 rate->rate == 240)
87 rate->flags |= IEEE80211_RATE_BASIC;
88 break;
89 case MODE_IEEE80211B:
90 if (rate->rate == 10 || rate->rate == 20)
91 rate->flags |= IEEE80211_RATE_BASIC;
92 break;
93 case MODE_IEEE80211G:
94 if (rate->rate == 10 || rate->rate == 20 ||
95 rate->rate == 55 || rate->rate == 110)
96 rate->flags |= IEEE80211_RATE_BASIC;
97 break;
98 case NUM_IEEE80211_MODES:
99 /* not useful */
100 break;
101 }
102
103 /* Set ERP and MANDATORY flags based on phymode */
104 switch (mode->mode) {
105 case MODE_IEEE80211A:
106 if (rate->rate == 60 || rate->rate == 120 ||
107 rate->rate == 240)
108 rate->flags |= IEEE80211_RATE_MANDATORY;
109 break;
110 case MODE_IEEE80211B:
111 if (rate->rate == 10)
112 rate->flags |= IEEE80211_RATE_MANDATORY;
113 break;
114 case MODE_IEEE80211G:
115 if (rate->rate == 10 || rate->rate == 20 ||
116 rate->rate == 55 || rate->rate == 110 ||
117 rate->rate == 60 || rate->rate == 120 ||
118 rate->rate == 240)
119 rate->flags |= IEEE80211_RATE_MANDATORY;
120 break;
121 case NUM_IEEE80211_MODES:
122 /* not useful */
123 break;
124 }
125 if (ieee80211_is_erp_rate(mode->mode, rate->rate))
126 rate->flags |= IEEE80211_RATE_ERP;
127 }
128}
129
130u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, 44u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
131 enum ieee80211_if_types type) 45 enum ieee80211_if_types type)
132{ 46{
@@ -262,7 +176,7 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
262 * DIV_ROUND_UP() operations. 176 * DIV_ROUND_UP() operations.
263 */ 177 */
264 178
265 if (local->hw.conf.phymode == MODE_IEEE80211A || erp) { 179 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
266 /* 180 /*
267 * OFDM: 181 * OFDM:
268 * 182 *
@@ -304,15 +218,19 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
304/* Exported duration function for driver use */ 218/* Exported duration function for driver use */
305__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, 219__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
306 struct ieee80211_vif *vif, 220 struct ieee80211_vif *vif,
307 size_t frame_len, int rate) 221 size_t frame_len,
222 struct ieee80211_rate *rate)
308{ 223{
309 struct ieee80211_local *local = hw_to_local(hw); 224 struct ieee80211_local *local = hw_to_local(hw);
310 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 225 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
311 u16 dur; 226 u16 dur;
312 int erp; 227 int erp;
313 228
314 erp = ieee80211_is_erp_rate(hw->conf.phymode, rate); 229 erp = 0;
315 dur = ieee80211_frame_duration(local, frame_len, rate, erp, 230 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
231 erp = rate->flags & IEEE80211_RATE_ERP_G;
232
233 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
316 sdata->bss_conf.use_short_preamble); 234 sdata->bss_conf.use_short_preamble);
317 235
318 return cpu_to_le16(dur); 236 return cpu_to_le16(dur);
@@ -332,17 +250,20 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
332 250
333 short_preamble = sdata->bss_conf.use_short_preamble; 251 short_preamble = sdata->bss_conf.use_short_preamble;
334 252
335 rate = frame_txctl->rts_rate; 253 rate = frame_txctl->rts_cts_rate;
336 erp = !!(rate->flags & IEEE80211_RATE_ERP); 254
255 erp = 0;
256 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
257 erp = rate->flags & IEEE80211_RATE_ERP_G;
337 258
338 /* CTS duration */ 259 /* CTS duration */
339 dur = ieee80211_frame_duration(local, 10, rate->rate, 260 dur = ieee80211_frame_duration(local, 10, rate->bitrate,
340 erp, short_preamble); 261 erp, short_preamble);
341 /* Data frame duration */ 262 /* Data frame duration */
342 dur += ieee80211_frame_duration(local, frame_len, rate->rate, 263 dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
343 erp, short_preamble); 264 erp, short_preamble);
344 /* ACK duration */ 265 /* ACK duration */
345 dur += ieee80211_frame_duration(local, 10, rate->rate, 266 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
346 erp, short_preamble); 267 erp, short_preamble);
347 268
348 return cpu_to_le16(dur); 269 return cpu_to_le16(dur);
@@ -363,15 +284,17 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
363 284
364 short_preamble = sdata->bss_conf.use_short_preamble; 285 short_preamble = sdata->bss_conf.use_short_preamble;
365 286
366 rate = frame_txctl->rts_rate; 287 rate = frame_txctl->rts_cts_rate;
367 erp = !!(rate->flags & IEEE80211_RATE_ERP); 288 erp = 0;
289 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
290 erp = rate->flags & IEEE80211_RATE_ERP_G;
368 291
369 /* Data frame duration */ 292 /* Data frame duration */
370 dur = ieee80211_frame_duration(local, frame_len, rate->rate, 293 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
371 erp, short_preamble); 294 erp, short_preamble);
372 if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) { 295 if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) {
373 /* ACK duration */ 296 /* ACK duration */
374 dur += ieee80211_frame_duration(local, 10, rate->rate, 297 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
375 erp, short_preamble); 298 erp, short_preamble);
376 } 299 }
377 300
@@ -379,27 +302,6 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
379} 302}
380EXPORT_SYMBOL(ieee80211_ctstoself_duration); 303EXPORT_SYMBOL(ieee80211_ctstoself_duration);
381 304
382struct ieee80211_rate *
383ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
384{
385 struct ieee80211_hw_mode *mode;
386 int r;
387
388 list_for_each_entry(mode, &local->modes_list, list) {
389 if (mode->mode != phymode)
390 continue;
391 for (r = 0; r < mode->num_rates; r++) {
392 struct ieee80211_rate *rate = &mode->rates[r];
393 if (rate->val == hw_rate ||
394 (rate->flags & IEEE80211_RATE_PREAMBLE2 &&
395 rate->val2 == hw_rate))
396 return rate;
397 }
398 }
399
400 return NULL;
401}
402
403void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) 305void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
404{ 306{
405 struct ieee80211_local *local = hw_to_local(hw); 307 struct ieee80211_local *local = hw_to_local(hw);
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index 65710a42e5a7..b9f943c45f3b 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -1,5 +1,5 @@
1obj-$(CONFIG_WIRELESS_EXT) += wext.o 1obj-$(CONFIG_WIRELESS_EXT) += wext.o
2obj-$(CONFIG_CFG80211) += cfg80211.o 2obj-$(CONFIG_CFG80211) += cfg80211.o
3 3
4cfg80211-y += core.o sysfs.o radiotap.o 4cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o
5cfg80211-$(CONFIG_NL80211) += nl80211.o 5cfg80211-$(CONFIG_NL80211) += nl80211.o
diff --git a/net/wireless/core.c b/net/wireless/core.c
index cfc5fc5f9e75..80afacdae46c 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -232,6 +232,47 @@ int wiphy_register(struct wiphy *wiphy)
232{ 232{
233 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 233 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
234 int res; 234 int res;
235 enum ieee80211_band band;
236 struct ieee80211_supported_band *sband;
237 bool have_band = false;
238 int i;
239
240 /* sanity check supported bands/channels */
241 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
242 sband = wiphy->bands[band];
243 if (!sband)
244 continue;
245
246 sband->band = band;
247
248 if (!sband->n_channels || !sband->n_bitrates) {
249 WARN_ON(1);
250 return -EINVAL;
251 }
252
253 for (i = 0; i < sband->n_channels; i++) {
254 sband->channels[i].orig_flags =
255 sband->channels[i].flags;
256 sband->channels[i].orig_mag =
257 sband->channels[i].max_antenna_gain;
258 sband->channels[i].orig_mpwr =
259 sband->channels[i].max_power;
260 sband->channels[i].band = band;
261 }
262
263 have_band = true;
264 }
265
266 if (!have_band) {
267 WARN_ON(1);
268 return -EINVAL;
269 }
270
271 /* check and set up bitrates */
272 ieee80211_set_bitrate_flags(wiphy);
273
274 /* set up regulatory info */
275 wiphy_update_regulatory(wiphy);
235 276
236 mutex_lock(&cfg80211_drv_mutex); 277 mutex_lock(&cfg80211_drv_mutex);
237 278
diff --git a/net/wireless/core.h b/net/wireless/core.h
index eb0f846b40df..7a02c356d63d 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -78,4 +78,7 @@ extern void cfg80211_dev_free(struct cfg80211_registered_device *drv);
78extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv, 78extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv,
79 char *newname); 79 char *newname);
80 80
81void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
82void wiphy_update_regulatory(struct wiphy *wiphy);
83
81#endif /* __NET_WIRELESS_CORE_H */ 84#endif /* __NET_WIRELESS_CORE_H */
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
new file mode 100644
index 000000000000..2b63c96dcf19
--- /dev/null
+++ b/net/wireless/reg.c
@@ -0,0 +1,153 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11/*
12 * This regulatory domain control implementation is highly incomplete, it
13 * only exists for the purpose of not regressing mac80211.
14 *
15 * For now, drivers can restrict the set of allowed channels by either
16 * not registering those channels or setting the IEEE80211_CHAN_DISABLED
17 * flag; that flag will only be *set* by this code, never *cleared.
18 *
19 * The usual implementation is for a driver to read a device EEPROM to
20 * determine which regulatory domain it should be operating under, then
21 * looking up the allowable channels in a driver-local table and finally
22 * registering those channels in the wiphy structure.
23 *
24 * Alternatively, drivers that trust the regulatory domain control here
25 * will register a complete set of capabilities and the control code
26 * will restrict the set by setting the IEEE80211_CHAN_* flags.
27 */
28#include <linux/kernel.h>
29#include <net/wireless.h>
30#include "core.h"
31
32static char *ieee80211_regdom = "US";
33module_param(ieee80211_regdom, charp, 0444);
34MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
35
36struct ieee80211_channel_range {
37 short start_freq;
38 short end_freq;
39 int max_power;
40 int max_antenna_gain;
41 u32 flags;
42};
43
44struct ieee80211_regdomain {
45 const char *code;
46 const struct ieee80211_channel_range *ranges;
47 int n_ranges;
48};
49
50#define RANGE_PWR(_start, _end, _pwr, _ag, _flags) \
51 { _start, _end, _pwr, _ag, _flags }
52
53
54/*
55 * Ideally, in the future, these definitions will be loaded from a
56 * userspace table via some daemon.
57 */
58static const struct ieee80211_channel_range ieee80211_US_channels[] = {
59 /* IEEE 802.11b/g, channels 1..11 */
60 RANGE_PWR(2412, 2462, 27, 6, 0),
61 /* IEEE 802.11a, channels 52..64 */
62 RANGE_PWR(5260, 5320, 23, 6, 0),
63 /* IEEE 802.11a, channels 149..165, outdoor */
64 RANGE_PWR(5745, 5825, 30, 6, 0),
65};
66
67static const struct ieee80211_channel_range ieee80211_JP_channels[] = {
68 /* IEEE 802.11b/g, channels 1..14 */
69 RANGE_PWR(2412, 2484, 20, 6, 0),
70 /* IEEE 802.11a, channels 34..48 */
71 RANGE_PWR(5170, 5240, 20, 6, IEEE80211_CHAN_PASSIVE_SCAN),
72 /* IEEE 802.11a, channels 52..64 */
73 RANGE_PWR(5260, 5320, 20, 6, IEEE80211_CHAN_NO_IBSS |
74 IEEE80211_CHAN_RADAR),
75};
76
77#define REGDOM(_code) \
78 { \
79 .code = __stringify(_code), \
80 .ranges = ieee80211_ ##_code## _channels, \
81 .n_ranges = ARRAY_SIZE(ieee80211_ ##_code## _channels), \
82 }
83
84static const struct ieee80211_regdomain ieee80211_regdoms[] = {
85 REGDOM(US),
86 REGDOM(JP),
87};
88
89
90static const struct ieee80211_regdomain *get_regdom(void)
91{
92 static const struct ieee80211_channel_range
93 ieee80211_world_channels[] = {
94 /* IEEE 802.11b/g, channels 1..11 */
95 RANGE_PWR(2412, 2462, 27, 6, 0),
96 };
97 static const struct ieee80211_regdomain regdom_world = REGDOM(world);
98 int i;
99
100 for (i = 0; i < ARRAY_SIZE(ieee80211_regdoms); i++)
101 if (strcmp(ieee80211_regdom, ieee80211_regdoms[i].code) == 0)
102 return &ieee80211_regdoms[i];
103
104 return &regdom_world;
105}
106
107
108static void handle_channel(struct ieee80211_channel *chan,
109 const struct ieee80211_regdomain *rd)
110{
111 int i;
112 u32 flags = chan->orig_flags;
113 const struct ieee80211_channel_range *rg = NULL;
114
115 for (i = 0; i < rd->n_ranges; i++) {
116 if (rd->ranges[i].start_freq <= chan->center_freq &&
117 chan->center_freq <= rd->ranges[i].end_freq) {
118 rg = &rd->ranges[i];
119 break;
120 }
121 }
122
123 if (!rg) {
124 /* not found */
125 flags |= IEEE80211_CHAN_DISABLED;
126 chan->flags = flags;
127 return;
128 }
129
130 chan->flags = flags;
131 chan->max_antenna_gain = min(chan->orig_mag,
132 rg->max_antenna_gain);
133 chan->max_power = min(chan->orig_mpwr, rg->max_power);
134}
135
136static void handle_band(struct ieee80211_supported_band *sband,
137 const struct ieee80211_regdomain *rd)
138{
139 int i;
140
141 for (i = 0; i < sband->n_channels; i++)
142 handle_channel(&sband->channels[i], rd);
143}
144
145void wiphy_update_regulatory(struct wiphy *wiphy)
146{
147 enum ieee80211_band band;
148 const struct ieee80211_regdomain *rd = get_regdom();
149
150 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
151 if (wiphy->bands[band])
152 handle_band(wiphy->bands[band], rd);
153}
diff --git a/net/wireless/util.c b/net/wireless/util.c
new file mode 100644
index 000000000000..0dcccbf3eb57
--- /dev/null
+++ b/net/wireless/util.c
@@ -0,0 +1,98 @@
1/*
2 * Wireless utility functions
3 *
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 */
6#include <net/wireless.h>
7#include <asm/bitops.h>
8#include "core.h"
9
10int ieee80211_channel_to_frequency(int chan)
11{
12 if (chan < 14)
13 return 2407 + chan * 5;
14
15 if (chan == 14)
16 return 2484;
17
18 /* FIXME: 802.11j 17.3.8.3.2 */
19 return (chan + 1000) * 5;
20}
21EXPORT_SYMBOL(ieee80211_channel_to_frequency);
22
23int ieee80211_frequency_to_channel(int freq)
24{
25 if (freq == 2484)
26 return 14;
27
28 if (freq < 2484)
29 return (freq - 2407) / 5;
30
31 /* FIXME: 802.11j 17.3.8.3.2 */
32 return freq/5 - 1000;
33}
34EXPORT_SYMBOL(ieee80211_frequency_to_channel);
35
36static void set_mandatory_flags_band(struct ieee80211_supported_band *sband,
37 enum ieee80211_band band)
38{
39 int i, want;
40
41 switch (band) {
42 case IEEE80211_BAND_5GHZ:
43 want = 3;
44 for (i = 0; i < sband->n_bitrates; i++) {
45 if (sband->bitrates[i].bitrate == 60 ||
46 sband->bitrates[i].bitrate == 120 ||
47 sband->bitrates[i].bitrate == 240) {
48 sband->bitrates[i].flags |=
49 IEEE80211_RATE_MANDATORY_A;
50 want--;
51 }
52 }
53 WARN_ON(want);
54 break;
55 case IEEE80211_BAND_2GHZ:
56 want = 7;
57 for (i = 0; i < sband->n_bitrates; i++) {
58 if (sband->bitrates[i].bitrate == 10) {
59 sband->bitrates[i].flags |=
60 IEEE80211_RATE_MANDATORY_B |
61 IEEE80211_RATE_MANDATORY_G;
62 want--;
63 }
64
65 if (sband->bitrates[i].bitrate == 20 ||
66 sband->bitrates[i].bitrate == 55 ||
67 sband->bitrates[i].bitrate == 110 ||
68 sband->bitrates[i].bitrate == 60 ||
69 sband->bitrates[i].bitrate == 120 ||
70 sband->bitrates[i].bitrate == 240) {
71 sband->bitrates[i].flags |=
72 IEEE80211_RATE_MANDATORY_G;
73 want--;
74 }
75
76 if (sband->bitrates[i].bitrate == 10 ||
77 sband->bitrates[i].bitrate == 20 ||
78 sband->bitrates[i].bitrate == 55 ||
79 sband->bitrates[i].bitrate == 110)
80 sband->bitrates[i].flags |=
81 IEEE80211_RATE_ERP_G;
82 }
83 WARN_ON(want != 0 && want != 6);
84 break;
85 case IEEE80211_NUM_BANDS:
86 WARN_ON(1);
87 break;
88 }
89}
90
91void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
92{
93 enum ieee80211_band band;
94
95 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
96 if (wiphy->bands[band])
97 set_mandatory_flags_band(wiphy->bands[band], band);
98}