aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath5k/base.c
diff options
context:
space:
mode:
authorBruno Randolf <br1@einfach.org>2008-07-30 11:12:58 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-08-22 16:29:50 -0400
commit63266a653589e1a237527479f10212ea77ce7844 (patch)
treee2e9318a310d2cc8bec79168c6a3df1f673f27c7 /drivers/net/wireless/ath5k/base.c
parent92ab85354993ac3a364c65cab45745af470ffc67 (diff)
ath5k: rates cleanup
cleanup the rates structures used by ath5k. instead of separate driver and mac80211 rate structures we now setup a static ieee80211_rate array and use it directly. no conversion between two different rate structures has to be done any more. a lot of unused and confusing junk was deleted. renamed ath5k_getchannels into ath5k_setup_bands because this is what it does. rewrote it to copy the bitrates correctly for each band. this is necessary for running different hardware with the same driver (e.g. 5211 and 5212 based cards). add special handling of rates for AR5211 chipsets: it uses different rate codes for CCK rates (which are actually like the other chips but with a 0xF mask). setup a hardware code to rate index reverse mapping table for getting the rate index of received frames. the rates for control frames which have to be set in ath5k_hw_write_rate_duration are now in one single array. drivers/net/wireless/ath5k/ath5k.h: Changes-licensed-under: ISC drivers/net/wireless/ath5k/base.c: Changes-licensed-under: 3-Clause-BSD drivers/net/wireless/ath5k/base.h: Changes-licensed-under: 3-Clause-BSD drivers/net/wireless/ath5k/hw.c: Changes-licensed-under: ISC Signed-off-by: Bruno Randolf <br1@einfach.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ath5k/base.c')
-rw-r--r--drivers/net/wireless/ath5k/base.c254
1 files changed, 117 insertions, 137 deletions
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 */