aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath5k
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/ath5k')
-rw-r--r--drivers/net/wireless/ath5k/ath5k.h162
-rw-r--r--drivers/net/wireless/ath5k/base.c254
-rw-r--r--drivers/net/wireless/ath5k/base.h8
-rw-r--r--drivers/net/wireless/ath5k/hw.c76
4 files changed, 171 insertions, 329 deletions
diff --git a/drivers/net/wireless/ath5k/ath5k.h b/drivers/net/wireless/ath5k/ath5k.h
index 9102eea3c8bf..c1b497873668 100644
--- a/drivers/net/wireless/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath5k/ath5k.h
@@ -271,11 +271,6 @@ enum ath5k_driver_mode {
271/* adding this flag to rate_code enables short preamble, see ar5212_reg.h */ 271/* adding this flag to rate_code enables short preamble, see ar5212_reg.h */
272#define AR5K_SET_SHORT_PREAMBLE 0x04 272#define AR5K_SET_SHORT_PREAMBLE 0x04
273 273
274#define HAS_SHPREAMBLE(_ix) \
275 (rt->rates[_ix].modulation == IEEE80211_RATE_SHORT_PREAMBLE)
276#define SHPREAMBLE_FLAG(_ix) \
277 (HAS_SHPREAMBLE(_ix) ? AR5K_SET_SHORT_PREAMBLE : 0)
278
279 274
280/****************\ 275/****************\
281 TX DEFINITIONS 276 TX DEFINITIONS
@@ -568,152 +563,61 @@ struct ath5k_athchan_2ghz {
568 u16 a2_athchan; 563 u16 a2_athchan;
569}; 564};
570 565
566
571/* 567/*
572 * Rate definitions 568 * Rate definitions
573 * TODO: Clean them up or move them on mac80211 -most of these infos are
574 * used by the rate control algorytm on MadWiFi.
575 */ 569 */
576 570
577/* Max number of rates on the rate table and what it seems
578 * Atheros hardware supports */
579#define AR5K_MAX_RATES 32
580
581/** 571/**
582 * struct ath5k_rate - rate structure 572 * Seems the ar5xxx harware supports up to 32 rates, indexed by 1-32.
583 * @valid: is this a valid rate for rate control (remove)
584 * @modulation: respective mac80211 modulation
585 * @rate_kbps: rate in kbit/s
586 * @rate_code: hardware rate value, used in &struct ath5k_desc, on RX on
587 * &struct ath5k_rx_status.rs_rate and on TX on
588 * &struct ath5k_tx_status.ts_rate. Seems the ar5xxx harware supports
589 * up to 32 rates, indexed by 1-32. This means we really only need
590 * 6 bits for the rate_code.
591 * @dot11_rate: respective IEEE-802.11 rate value
592 * @control_rate: index of rate assumed to be used to send control frames.
593 * This can be used to set override the value on the rate duration
594 * registers. This is only useful if we can override in the harware at
595 * what rate we want to send control frames at. Note that IEEE-802.11
596 * Ch. 9.6 (after IEEE 802.11g changes) defines the rate at which we
597 * should send ACK/CTS, if we change this value we can be breaking
598 * the spec.
599 * 573 *
600 * This structure is used to get the RX rate or set the TX rate on the 574 * The rate code is used to get the RX rate or set the TX rate on the
601 * hardware descriptors. It is also used for internal modulation control 575 * hardware descriptors. It is also used for internal modulation control
602 * and settings. 576 * and settings.
603 * 577 *
604 * On RX after the &struct ath5k_desc is parsed by the appropriate 578 * This is the hardware rate map we are aware of:
605 * ah_proc_rx_desc() the respective hardware rate value is set in
606 * &struct ath5k_rx_status.rs_rate. On TX the desired rate is set in
607 * &struct ath5k_tx_status.ts_rate which is later used to setup the
608 * &struct ath5k_desc correctly. This is the hardware rate map we are
609 * aware of:
610 * 579 *
611 * rate_code 1 2 3 4 5 6 7 8 580 * rate_code 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08
612 * rate_kbps 3000 1000 ? ? ? 2000 500 48000 581 * rate_kbps 3000 1000 ? ? ? 2000 500 48000
613 * 582 *
614 * rate_code 9 10 11 12 13 14 15 16 583 * rate_code 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10
615 * rate_kbps 24000 12000 6000 54000 36000 18000 9000 ? 584 * rate_kbps 24000 12000 6000 54000 36000 18000 9000 ?
616 * 585 *
617 * rate_code 17 18 19 20 21 22 23 24 586 * rate_code 17 18 19 20 21 22 23 24
618 * rate_kbps ? ? ? ? ? ? ? 11000 587 * rate_kbps ? ? ? ? ? ? ? 11000
619 * 588 *
620 * rate_code 25 26 27 28 29 30 31 32 589 * rate_code 25 26 27 28 29 30 31 32
621 * rate_kbps 5500 2000 1000 ? ? ? ? ? 590 * rate_kbps 5500 2000 1000 11000S 5500S 2000S ? ?
622 * 591 *
592 * "S" indicates CCK rates with short preamble.
593 *
594 * AR5211 has different rate codes for CCK (802.11B) rates. It only uses the
595 * lowest 4 bits, so they are the same as below with a 0xF mask.
596 * (0xB, 0xA, 0x9 and 0x8 for 1M, 2M, 5.5M and 11M).
597 * We handle this in ath5k_setup_bands().
623 */ 598 */
624struct ath5k_rate { 599#define AR5K_MAX_RATES 32
625 u8 valid;
626 u32 modulation;
627 u16 rate_kbps;
628 u8 rate_code;
629 u8 dot11_rate;
630 u8 control_rate;
631};
632
633/* XXX: GRR all this stuff to get leds blinking ??? (check out setcurmode) */
634struct ath5k_rate_table {
635 u16 rate_count;
636 u8 rate_code_to_index[AR5K_MAX_RATES]; /* Back-mapping */
637 struct ath5k_rate rates[AR5K_MAX_RATES];
638};
639
640/*
641 * Rate tables...
642 * TODO: CLEAN THIS !!!
643 */
644#define AR5K_RATES_11A { 8, { \
645 255, 255, 255, 255, 255, 255, 255, 255, 6, 4, 2, 0, \
646 7, 5, 3, 1, 255, 255, 255, 255, 255, 255, 255, 255, \
647 255, 255, 255, 255, 255, 255, 255, 255 }, { \
648 { 1, 0, 6000, 11, 140, 0 }, \
649 { 1, 0, 9000, 15, 18, 0 }, \
650 { 1, 0, 12000, 10, 152, 2 }, \
651 { 1, 0, 18000, 14, 36, 2 }, \
652 { 1, 0, 24000, 9, 176, 4 }, \
653 { 1, 0, 36000, 13, 72, 4 }, \
654 { 1, 0, 48000, 8, 96, 4 }, \
655 { 1, 0, 54000, 12, 108, 4 } } \
656}
657
658#define AR5K_RATES_11B { 4, { \
659 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, \
660 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, \
661 3, 2, 1, 0, 255, 255, 255, 255 }, { \
662 { 1, 0, 1000, 27, 130, 0 }, \
663 { 1, IEEE80211_RATE_SHORT_PREAMBLE, 2000, 26, 132, 1 }, \
664 { 1, IEEE80211_RATE_SHORT_PREAMBLE, 5500, 25, 139, 1 }, \
665 { 1, IEEE80211_RATE_SHORT_PREAMBLE, 11000, 24, 150, 1 } } \
666}
667
668#define AR5K_RATES_11G { 12, { \
669 255, 255, 255, 255, 255, 255, 255, 255, 10, 8, 6, 4, \
670 11, 9, 7, 5, 255, 255, 255, 255, 255, 255, 255, 255, \
671 3, 2, 1, 0, 255, 255, 255, 255 }, { \
672 { 1, 0, 1000, 27, 2, 0 }, \
673 { 1, IEEE80211_RATE_SHORT_PREAMBLE, 2000, 26, 4, 1 }, \
674 { 1, IEEE80211_RATE_SHORT_PREAMBLE, 5500, 25, 11, 1 }, \
675 { 1, IEEE80211_RATE_SHORT_PREAMBLE, 11000, 24, 22, 1 }, \
676 { 0, 0, 6000, 11, 12, 4 }, \
677 { 0, 0, 9000, 15, 18, 4 }, \
678 { 1, 0, 12000, 10, 24, 6 }, \
679 { 1, 0, 18000, 14, 36, 6 }, \
680 { 1, 0, 24000, 9, 48, 8 }, \
681 { 1, 0, 36000, 13, 72, 8 }, \
682 { 1, 0, 48000, 8, 96, 8 }, \
683 { 1, 0, 54000, 12, 108, 8 } } \
684}
685 600
686#define AR5K_RATES_TURBO { 8, { \ 601/* B */
687 255, 255, 255, 255, 255, 255, 255, 255, 6, 4, 2, 0, \ 602#define ATH5K_RATE_CODE_1M 0x1B
688 7, 5, 3, 1, 255, 255, 255, 255, 255, 255, 255, 255, \ 603#define ATH5K_RATE_CODE_2M 0x1A
689 255, 255, 255, 255, 255, 255, 255, 255 }, { \ 604#define ATH5K_RATE_CODE_5_5M 0x19
690 { 1, MODULATION_TURBO, 6000, 11, 140, 0 }, \ 605#define ATH5K_RATE_CODE_11M 0x18
691 { 1, MODULATION_TURBO, 9000, 15, 18, 0 }, \ 606/* A and G */
692 { 1, MODULATION_TURBO, 12000, 10, 152, 2 }, \ 607#define ATH5K_RATE_CODE_6M 0x0B
693 { 1, MODULATION_TURBO, 18000, 14, 36, 2 }, \ 608#define ATH5K_RATE_CODE_9M 0x0F
694 { 1, MODULATION_TURBO, 24000, 9, 176, 4 }, \ 609#define ATH5K_RATE_CODE_12M 0x0A
695 { 1, MODULATION_TURBO, 36000, 13, 72, 4 }, \ 610#define ATH5K_RATE_CODE_18M 0x0E
696 { 1, MODULATION_TURBO, 48000, 8, 96, 4 }, \ 611#define ATH5K_RATE_CODE_24M 0x09
697 { 1, MODULATION_TURBO, 54000, 12, 108, 4 } } \ 612#define ATH5K_RATE_CODE_36M 0x0D
698} 613#define ATH5K_RATE_CODE_48M 0x08
614#define ATH5K_RATE_CODE_54M 0x0C
615/* XR */
616#define ATH5K_RATE_CODE_XR_500K 0x07
617#define ATH5K_RATE_CODE_XR_1M 0x02
618#define ATH5K_RATE_CODE_XR_2M 0x06
619#define ATH5K_RATE_CODE_XR_3M 0x01
699 620
700#define AR5K_RATES_XR { 12, { \
701 255, 3, 1, 255, 255, 255, 2, 0, 10, 8, 6, 4, \
702 11, 9, 7, 5, 255, 255, 255, 255, 255, 255, 255, 255, \
703 255, 255, 255, 255, 255, 255, 255, 255 }, { \
704 { 1, MODULATION_XR, 500, 7, 129, 0 }, \
705 { 1, MODULATION_XR, 1000, 2, 139, 1 }, \
706 { 1, MODULATION_XR, 2000, 6, 150, 2 }, \
707 { 1, MODULATION_XR, 3000, 1, 150, 3 }, \
708 { 1, 0, 6000, 11, 140, 4 }, \
709 { 1, 0, 9000, 15, 18, 4 }, \
710 { 1, 0, 12000, 10, 152, 6 }, \
711 { 1, 0, 18000, 14, 36, 6 }, \
712 { 1, 0, 24000, 9, 176, 8 }, \
713 { 1, 0, 36000, 13, 72, 8 }, \
714 { 1, 0, 48000, 8, 96, 8 }, \
715 { 1, 0, 54000, 12, 108, 8 } } \
716}
717 621
718/* 622/*
719 * Crypto definitions 623 * Crypto definitions
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c
index e8564095b2f8..114520258b78 100644
--- a/drivers/net/wireless/ath5k/base.c
+++ b/drivers/net/wireless/ath5k/base.c
@@ -132,6 +132,48 @@ static struct ath5k_srev_name srev_names[] = {
132 { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN }, 132 { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN },
133}; 133};
134 134
135static struct ieee80211_rate ath5k_rates[] = {
136 { .bitrate = 10,
137 .hw_value = ATH5K_RATE_CODE_1M, },
138 { .bitrate = 20,
139 .hw_value = ATH5K_RATE_CODE_2M,
140 .hw_value_short = ATH5K_RATE_CODE_2M | AR5K_SET_SHORT_PREAMBLE,
141 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
142 { .bitrate = 55,
143 .hw_value = ATH5K_RATE_CODE_5_5M,
144 .hw_value_short = ATH5K_RATE_CODE_5_5M | AR5K_SET_SHORT_PREAMBLE,
145 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
146 { .bitrate = 110,
147 .hw_value = ATH5K_RATE_CODE_11M,
148 .hw_value_short = ATH5K_RATE_CODE_11M | AR5K_SET_SHORT_PREAMBLE,
149 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
150 { .bitrate = 60,
151 .hw_value = ATH5K_RATE_CODE_6M,
152 .flags = 0 },
153 { .bitrate = 90,
154 .hw_value = ATH5K_RATE_CODE_9M,
155 .flags = 0 },
156 { .bitrate = 120,
157 .hw_value = ATH5K_RATE_CODE_12M,
158 .flags = 0 },
159 { .bitrate = 180,
160 .hw_value = ATH5K_RATE_CODE_18M,
161 .flags = 0 },
162 { .bitrate = 240,
163 .hw_value = ATH5K_RATE_CODE_24M,
164 .flags = 0 },
165 { .bitrate = 360,
166 .hw_value = ATH5K_RATE_CODE_36M,
167 .flags = 0 },
168 { .bitrate = 480,
169 .hw_value = ATH5K_RATE_CODE_48M,
170 .flags = 0 },
171 { .bitrate = 540,
172 .hw_value = ATH5K_RATE_CODE_54M,
173 .flags = 0 },
174 /* XR missing */
175};
176
135/* 177/*
136 * Prototypes - PCI stack related functions 178 * Prototypes - PCI stack related functions
137 */ 179 */
@@ -219,20 +261,16 @@ static void ath5k_detach(struct pci_dev *pdev,
219 struct ieee80211_hw *hw); 261 struct ieee80211_hw *hw);
220/* Channel/mode setup */ 262/* Channel/mode setup */
221static inline short ath5k_ieee2mhz(short chan); 263static inline short ath5k_ieee2mhz(short chan);
222static unsigned int ath5k_copy_rates(struct ieee80211_rate *rates,
223 const struct ath5k_rate_table *rt,
224 unsigned int max);
225static unsigned int ath5k_copy_channels(struct ath5k_hw *ah, 264static unsigned int ath5k_copy_channels(struct ath5k_hw *ah,
226 struct ieee80211_channel *channels, 265 struct ieee80211_channel *channels,
227 unsigned int mode, 266 unsigned int mode,
228 unsigned int max); 267 unsigned int max);
229static int ath5k_getchannels(struct ieee80211_hw *hw); 268static int ath5k_setup_bands(struct ieee80211_hw *hw);
230static int ath5k_chan_set(struct ath5k_softc *sc, 269static int ath5k_chan_set(struct ath5k_softc *sc,
231 struct ieee80211_channel *chan); 270 struct ieee80211_channel *chan);
232static void ath5k_setcurmode(struct ath5k_softc *sc, 271static void ath5k_setcurmode(struct ath5k_softc *sc,
233 unsigned int mode); 272 unsigned int mode);
234static void ath5k_mode_setup(struct ath5k_softc *sc); 273static void ath5k_mode_setup(struct ath5k_softc *sc);
235static void ath5k_set_total_hw_rates(struct ath5k_softc *sc);
236 274
237/* Descriptor setup */ 275/* Descriptor setup */
238static int ath5k_desc_alloc(struct ath5k_softc *sc, 276static int ath5k_desc_alloc(struct ath5k_softc *sc,
@@ -646,7 +684,6 @@ err_no_irq:
646#endif /* CONFIG_PM */ 684#endif /* CONFIG_PM */
647 685
648 686
649
650/***********************\ 687/***********************\
651* Driver Initialization * 688* Driver Initialization *
652\***********************/ 689\***********************/
@@ -688,15 +725,12 @@ ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
688 * on settings like the phy mode and regulatory 725 * on settings like the phy mode and regulatory
689 * domain restrictions. 726 * domain restrictions.
690 */ 727 */
691 ret = ath5k_getchannels(hw); 728 ret = ath5k_setup_bands(hw);
692 if (ret) { 729 if (ret) {
693 ATH5K_ERR(sc, "can't get channels\n"); 730 ATH5K_ERR(sc, "can't get channels\n");
694 goto err; 731 goto err;
695 } 732 }
696 733
697 /* Set *_rates so we can map hw rate index */
698 ath5k_set_total_hw_rates(sc);
699
700 /* NB: setup here so ath5k_rate_update is happy */ 734 /* NB: setup here so ath5k_rate_update is happy */
701 if (test_bit(AR5K_MODE_11A, ah->ah_modes)) 735 if (test_bit(AR5K_MODE_11A, ah->ah_modes))
702 ath5k_setcurmode(sc, AR5K_MODE_11A); 736 ath5k_setcurmode(sc, AR5K_MODE_11A);
@@ -813,27 +847,6 @@ ath5k_ieee2mhz(short chan)
813} 847}
814 848
815static unsigned int 849static unsigned int
816ath5k_copy_rates(struct ieee80211_rate *rates,
817 const struct ath5k_rate_table *rt,
818 unsigned int max)
819{
820 unsigned int i, count;
821
822 if (rt == NULL)
823 return 0;
824
825 for (i = 0, count = 0; i < rt->rate_count && max > 0; i++) {
826 rates[count].bitrate = rt->rates[i].rate_kbps / 100;
827 rates[count].hw_value = rt->rates[i].rate_code;
828 rates[count].flags = rt->rates[i].modulation;
829 count++;
830 max--;
831 }
832
833 return count;
834}
835
836static unsigned int
837ath5k_copy_channels(struct ath5k_hw *ah, 850ath5k_copy_channels(struct ath5k_hw *ah,
838 struct ieee80211_channel *channels, 851 struct ieee80211_channel *channels,
839 unsigned int mode, 852 unsigned int mode,
@@ -895,74 +908,97 @@ ath5k_copy_channels(struct ath5k_hw *ah,
895 return count; 908 return count;
896} 909}
897 910
911static void
912ath5k_setup_rate_idx(struct ath5k_softc *sc, struct ieee80211_supported_band *b)
913{
914 u8 i;
915
916 for (i = 0; i < AR5K_MAX_RATES; i++)
917 sc->rate_idx[b->band][i] = -1;
918
919 for (i = 0; i < b->n_bitrates; i++) {
920 sc->rate_idx[b->band][b->bitrates[i].hw_value] = i;
921 if (b->bitrates[i].hw_value_short)
922 sc->rate_idx[b->band][b->bitrates[i].hw_value_short] = i;
923 }
924}
925
898static int 926static int
899ath5k_getchannels(struct ieee80211_hw *hw) 927ath5k_setup_bands(struct ieee80211_hw *hw)
900{ 928{
901 struct ath5k_softc *sc = hw->priv; 929 struct ath5k_softc *sc = hw->priv;
902 struct ath5k_hw *ah = sc->ah; 930 struct ath5k_hw *ah = sc->ah;
903 struct ieee80211_supported_band *sbands = sc->sbands; 931 struct ieee80211_supported_band *sband;
904 const struct ath5k_rate_table *hw_rates; 932 int max_c, count_c = 0;
905 unsigned int max_r, max_c, count_r, count_c; 933 int i;
906 int mode2g = AR5K_MODE_11G;
907 934
908 BUILD_BUG_ON(ARRAY_SIZE(sc->sbands) < IEEE80211_NUM_BANDS); 935 BUILD_BUG_ON(ARRAY_SIZE(sc->sbands) < IEEE80211_NUM_BANDS);
909
910 max_r = ARRAY_SIZE(sc->rates);
911 max_c = ARRAY_SIZE(sc->channels); 936 max_c = ARRAY_SIZE(sc->channels);
912 count_r = count_c = 0;
913 937
914 /* 2GHz band */ 938 /* 2GHz band */
915 if (!test_bit(AR5K_MODE_11G, sc->ah->ah_capabilities.cap_mode)) { 939 sband = &sc->sbands[IEEE80211_BAND_2GHZ];
916 mode2g = AR5K_MODE_11B; 940 sband->band = IEEE80211_BAND_2GHZ;
917 if (!test_bit(AR5K_MODE_11B, 941 sband->bitrates = &sc->rates[IEEE80211_BAND_2GHZ][0];
918 sc->ah->ah_capabilities.cap_mode))
919 mode2g = -1;
920 }
921 942
922 if (mode2g > 0) { 943 if (test_bit(AR5K_MODE_11G, sc->ah->ah_capabilities.cap_mode)) {
923 struct ieee80211_supported_band *sband = 944 /* G mode */
924 &sbands[IEEE80211_BAND_2GHZ]; 945 memcpy(sband->bitrates, &ath5k_rates[0],
946 sizeof(struct ieee80211_rate) * 12);
947 sband->n_bitrates = 12;
925 948
926 sband->bitrates = sc->rates;
927 sband->channels = sc->channels; 949 sband->channels = sc->channels;
928
929 sband->band = IEEE80211_BAND_2GHZ;
930 sband->n_channels = ath5k_copy_channels(ah, sband->channels, 950 sband->n_channels = ath5k_copy_channels(ah, sband->channels,
931 mode2g, max_c); 951 AR5K_MODE_11G, max_c);
932
933 hw_rates = ath5k_hw_get_rate_table(ah, mode2g);
934 sband->n_bitrates = ath5k_copy_rates(sband->bitrates,
935 hw_rates, max_r);
936 952
953 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
937 count_c = sband->n_channels; 954 count_c = sband->n_channels;
938 count_r = sband->n_bitrates; 955 max_c -= count_c;
956 } else if (test_bit(AR5K_MODE_11B, sc->ah->ah_capabilities.cap_mode)) {
957 /* B mode */
958 memcpy(sband->bitrates, &ath5k_rates[0],
959 sizeof(struct ieee80211_rate) * 4);
960 sband->n_bitrates = 4;
961
962 /* 5211 only supports B rates and uses 4bit rate codes
963 * (e.g normally we have 0x1B for 1M, but on 5211 we have 0x0B)
964 * fix them up here:
965 */
966 if (ah->ah_version == AR5K_AR5211) {
967 for (i = 0; i < 4; i++) {
968 sband->bitrates[i].hw_value =
969 sband->bitrates[i].hw_value & 0xF;
970 sband->bitrates[i].hw_value_short =
971 sband->bitrates[i].hw_value_short & 0xF;
972 }
973 }
939 974
940 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; 975 sband->channels = sc->channels;
976 sband->n_channels = ath5k_copy_channels(ah, sband->channels,
977 AR5K_MODE_11B, max_c);
941 978
942 max_r -= count_r; 979 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
980 count_c = sband->n_channels;
943 max_c -= count_c; 981 max_c -= count_c;
944
945 } 982 }
983 ath5k_setup_rate_idx(sc, sband);
946 984
947 /* 5GHz band */ 985 /* 5GHz band, A mode */
948
949 if (test_bit(AR5K_MODE_11A, sc->ah->ah_capabilities.cap_mode)) { 986 if (test_bit(AR5K_MODE_11A, sc->ah->ah_capabilities.cap_mode)) {
950 struct ieee80211_supported_band *sband = 987 sband = &sc->sbands[IEEE80211_BAND_5GHZ];
951 &sbands[IEEE80211_BAND_5GHZ]; 988 sband->band = IEEE80211_BAND_5GHZ;
989 sband->bitrates = &sc->rates[IEEE80211_BAND_5GHZ][0];
952 990
953 sband->bitrates = &sc->rates[count_r]; 991 memcpy(sband->bitrates, &ath5k_rates[4],
954 sband->channels = &sc->channels[count_c]; 992 sizeof(struct ieee80211_rate) * 8);
993 sband->n_bitrates = 8;
955 994
956 sband->band = IEEE80211_BAND_5GHZ; 995 sband->channels = &sc->channels[count_c];
957 sband->n_channels = ath5k_copy_channels(ah, sband->channels, 996 sband->n_channels = ath5k_copy_channels(ah, sband->channels,
958 AR5K_MODE_11A, max_c); 997 AR5K_MODE_11A, max_c);
959 998
960 hw_rates = ath5k_hw_get_rate_table(ah, AR5K_MODE_11A);
961 sband->n_bitrates = ath5k_copy_rates(sband->bitrates,
962 hw_rates, max_r);
963
964 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; 999 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
965 } 1000 }
1001 ath5k_setup_rate_idx(sc, sband);
966 1002
967 ath5k_debug_dump_bands(sc); 1003 ath5k_debug_dump_bands(sc);
968 1004
@@ -1031,75 +1067,13 @@ ath5k_mode_setup(struct ath5k_softc *sc)
1031 ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt); 1067 ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt);
1032} 1068}
1033 1069
1034/*
1035 * Match the hw provided rate index (through descriptors)
1036 * to an index for sc->curband->bitrates, so it can be used
1037 * by the stack.
1038 *
1039 * This one is a little bit tricky but i think i'm right
1040 * about this...
1041 *
1042 * We have 4 rate tables in the following order:
1043 * XR (4 rates)
1044 * 802.11a (8 rates)
1045 * 802.11b (4 rates)
1046 * 802.11g (12 rates)
1047 * that make the hw rate table.
1048 *
1049 * Lets take a 5211 for example that supports a and b modes only.
1050 * First comes the 802.11a table and then 802.11b (total 12 rates).
1051 * When hw returns eg. 11 it points to the last 802.11b rate (11Mbit),
1052 * if it returns 2 it points to the second 802.11a rate etc.
1053 *
1054 * Same goes for 5212 who has xr/a/b/g support (total 28 rates).
1055 * First comes the XR table, then 802.11a, 802.11b and 802.11g.
1056 * When hw returns eg. 27 it points to the last 802.11g rate (54Mbits) etc
1057 */
1058static void
1059ath5k_set_total_hw_rates(struct ath5k_softc *sc) {
1060
1061 struct ath5k_hw *ah = sc->ah;
1062
1063 if (test_bit(AR5K_MODE_11A, ah->ah_modes))
1064 sc->a_rates = 8;
1065
1066 if (test_bit(AR5K_MODE_11B, ah->ah_modes))
1067 sc->b_rates = 4;
1068
1069 if (test_bit(AR5K_MODE_11G, ah->ah_modes))
1070 sc->g_rates = 12;
1071
1072 /* XXX: Need to see what what happens when
1073 xr disable bits in eeprom are set */
1074 if (ah->ah_version >= AR5K_AR5212)
1075 sc->xr_rates = 4;
1076
1077}
1078
1079static inline int 1070static inline int
1080ath5k_hw_to_driver_rix(struct ath5k_softc *sc, int hw_rix) { 1071ath5k_hw_to_driver_rix(struct ath5k_softc *sc, int hw_rix)
1081 1072{
1082 int mac80211_rix; 1073 WARN_ON(hw_rix < 0 || hw_rix > AR5K_MAX_RATES);
1083 1074 return sc->rate_idx[sc->curband->band][hw_rix];
1084 if(sc->curband->band == IEEE80211_BAND_2GHZ) {
1085 /* We setup a g ratetable for both b/g modes */
1086 mac80211_rix =
1087 hw_rix - sc->b_rates - sc->a_rates - sc->xr_rates;
1088 } else {
1089 mac80211_rix = hw_rix - sc->xr_rates;
1090 }
1091
1092 /* Something went wrong, fallback to basic rate for this band */
1093 if ((mac80211_rix >= sc->curband->n_bitrates) ||
1094 (mac80211_rix <= 0 ))
1095 mac80211_rix = 1;
1096
1097 return mac80211_rix;
1098} 1075}
1099 1076
1100
1101
1102
1103/***************\ 1077/***************\
1104* Buffers setup * 1078* Buffers setup *
1105\***************/ 1079\***************/
@@ -1788,6 +1762,12 @@ accept:
1788 rxs.rate_idx = ath5k_hw_to_driver_rix(sc, rs.rs_rate); 1762 rxs.rate_idx = ath5k_hw_to_driver_rix(sc, rs.rs_rate);
1789 rxs.flag |= ath5k_rx_decrypted(sc, ds, skb, &rs); 1763 rxs.flag |= ath5k_rx_decrypted(sc, ds, skb, &rs);
1790 1764
1765#if 0 /* add rxs.flag SHORTPRE once it is in mac80211 */
1766 if (rs.rs_rate >= ATH5K_RATE_CODE_2M &&
1767 rs.rs_rate <= ATH5K_RATE_CODE_11M &&
1768 rs.rs_rate & AR5K_SET_SHORT_PREAMBLE)
1769 rxs.flag |= RX_FLAG_SHORTPRE;
1770#endif
1791 ath5k_debug_dump_skb(sc, skb, "RX ", 0); 1771 ath5k_debug_dump_skb(sc, skb, "RX ", 0);
1792 1772
1793 /* check beacons in IBSS mode */ 1773 /* check beacons in IBSS mode */
diff --git a/drivers/net/wireless/ath5k/base.h b/drivers/net/wireless/ath5k/base.h
index d7e03e6b8271..248e32eb6cb3 100644
--- a/drivers/net/wireless/ath5k/base.h
+++ b/drivers/net/wireless/ath5k/base.h
@@ -111,17 +111,13 @@ struct ath5k_softc {
111 struct ieee80211_hw *hw; /* IEEE 802.11 common */ 111 struct ieee80211_hw *hw; /* IEEE 802.11 common */
112 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS]; 112 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
113 struct ieee80211_channel channels[ATH_CHAN_MAX]; 113 struct ieee80211_channel channels[ATH_CHAN_MAX];
114 struct ieee80211_rate rates[AR5K_MAX_RATES * IEEE80211_NUM_BANDS]; 114 struct ieee80211_rate rates[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
115 u8 rate_idx[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
115 enum ieee80211_if_types opmode; 116 enum ieee80211_if_types opmode;
116 struct ath5k_hw *ah; /* Atheros HW */ 117 struct ath5k_hw *ah; /* Atheros HW */
117 118
118 struct ieee80211_supported_band *curband; 119 struct ieee80211_supported_band *curband;
119 120
120 u8 a_rates;
121 u8 b_rates;
122 u8 g_rates;
123 u8 xr_rates;
124
125#ifdef CONFIG_ATH5K_DEBUG 121#ifdef CONFIG_ATH5K_DEBUG
126 struct ath5k_dbg_info debug; /* debug info */ 122 struct ath5k_dbg_info debug; /* debug info */
127#endif /* CONFIG_ATH5K_DEBUG */ 123#endif /* CONFIG_ATH5K_DEBUG */
diff --git a/drivers/net/wireless/ath5k/hw.c b/drivers/net/wireless/ath5k/hw.c
index b335d3323057..b987aa1e0f77 100644
--- a/drivers/net/wireless/ath5k/hw.c
+++ b/drivers/net/wireless/ath5k/hw.c
@@ -31,13 +31,6 @@
31#include "base.h" 31#include "base.h"
32#include "debug.h" 32#include "debug.h"
33 33
34/* Rate tables */
35static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
36static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
37static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
38static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
39static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
40
41/* Prototypes */ 34/* Prototypes */
42static int ath5k_hw_nic_reset(struct ath5k_hw *, u32); 35static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
43static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool); 36static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
@@ -521,34 +514,6 @@ static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
521} 514}
522 515
523/* 516/*
524 * Get the rate table for a specific operation mode
525 */
526const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
527 unsigned int mode)
528{
529 ATH5K_TRACE(ah->ah_sc);
530
531 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
532 return NULL;
533
534 /* Get rate tables */
535 switch (mode) {
536 case AR5K_MODE_11A:
537 return &ath5k_rt_11a;
538 case AR5K_MODE_11A_TURBO:
539 return &ath5k_rt_turbo;
540 case AR5K_MODE_11B:
541 return &ath5k_rt_11b;
542 case AR5K_MODE_11G:
543 return &ath5k_rt_11g;
544 case AR5K_MODE_11G_TURBO:
545 return &ath5k_rt_xr;
546 }
547
548 return NULL;
549}
550
551/*
552 * Free the ath5k_hw struct 517 * Free the ath5k_hw struct
553 */ 518 */
554void ath5k_hw_detach(struct ath5k_hw *ah) 519void ath5k_hw_detach(struct ath5k_hw *ah)
@@ -618,45 +583,42 @@ static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
618 return 0; 583 return 0;
619} 584}
620 585
586
587/*
588 * index into rates for control rates, we can set it up like this because
589 * this is only used for AR5212 and we know it supports G mode
590 */
591static int control_rates[] =
592 { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
593
621/** 594/**
622 * ath5k_hw_write_rate_duration - set rate duration during hw resets 595 * ath5k_hw_write_rate_duration - set rate duration during hw resets
623 * 596 *
624 * @ah: the &struct ath5k_hw 597 * @ah: the &struct ath5k_hw
625 * @mode: one of enum ath5k_driver_mode 598 * @mode: one of enum ath5k_driver_mode
626 * 599 *
627 * Write the rate duration table for the current mode upon hw reset. This 600 * Write the rate duration table upon hw reset. This is a helper for
628 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting 601 * ath5k_hw_reset(). It seems all this is doing is setting an ACK timeout for
629 * an ACK timeout for the hardware for the current mode for each rate. The 602 * the hardware for the current mode for each rate. The rates which are capable
630 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, 603 * of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have another
631 * and 11Mbps) have another register for the short preamble ACK timeout 604 * register for the short preamble ACK timeout calculation.
632 * calculation.
633 *
634 */ 605 */
635static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah, 606static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
636 unsigned int mode) 607 unsigned int mode)
637{ 608{
638 struct ath5k_softc *sc = ah->ah_sc; 609 struct ath5k_softc *sc = ah->ah_sc;
639 const struct ath5k_rate_table *rt; 610 struct ieee80211_rate *rate;
640 struct ieee80211_rate srate = {};
641 unsigned int i; 611 unsigned int i;
642 612
643 /* Get rate table for the current operating mode */
644 rt = ath5k_hw_get_rate_table(ah, mode);
645
646 /* Write rate duration table */ 613 /* Write rate duration table */
647 for (i = 0; i < rt->rate_count; i++) { 614 for (i = 0; i < sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates; i++) {
648 const struct ath5k_rate *rate, *control_rate;
649
650 u32 reg; 615 u32 reg;
651 u16 tx_time; 616 u16 tx_time;
652 617
653 rate = &rt->rates[i]; 618 rate = &sc->sbands[IEEE80211_BAND_2GHZ].bitrates[control_rates[i]];
654 control_rate = &rt->rates[rate->control_rate];
655 619
656 /* Set ACK timeout */ 620 /* Set ACK timeout */
657 reg = AR5K_RATE_DUR(rate->rate_code); 621 reg = AR5K_RATE_DUR(rate->hw_value);
658
659 srate.bitrate = control_rate->rate_kbps/100;
660 622
661 /* An ACK frame consists of 10 bytes. If you add the FCS, 623 /* An ACK frame consists of 10 bytes. If you add the FCS,
662 * which ieee80211_generic_frame_duration() adds, 624 * which ieee80211_generic_frame_duration() adds,
@@ -665,11 +627,11 @@ static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
665 * ieee80211_duration() for a brief description of 627 * ieee80211_duration() for a brief description of
666 * what rate we should choose to TX ACKs. */ 628 * what rate we should choose to TX ACKs. */
667 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw, 629 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
668 sc->vif, 10, &srate)); 630 sc->vif, 10, rate));
669 631
670 ath5k_hw_reg_write(ah, tx_time, reg); 632 ath5k_hw_reg_write(ah, tx_time, reg);
671 633
672 if (!HAS_SHPREAMBLE(i)) 634 if (!(rate->flags & IEEE80211_RATE_SHORT_PREAMBLE))
673 continue; 635 continue;
674 636
675 /* 637 /*