aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt73usb.c
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2008-10-29 12:17:57 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-11-10 15:17:33 -0500
commite4ea1c403acece78c271bf9cd6f797d1cb093df9 (patch)
tree4356693a16f2596de08f6afee76490f1ebe6b066 /drivers/net/wireless/rt2x00/rt73usb.c
parent3f64b435ab76e79bfb3b4d36f043e6f892093b71 (diff)
rt2x00: Optimize configuration handling
Implement latest changed from mac80211 configuration handling to optmize configuration handling in rt2x00. * Remove set_retry_limit callback function, handled through config() * Move config_antenna to its own callback function, it isn't handled by mac80211 anymore * Use IEEE80211_CONF_CHANGED_* flags and remove manual checks * Removed deprecated short slot setting through config() and put it in config_erp() through which mac80211 now configures it * Remove config_phymode() and move contents to config_erp() since it only managed the basic rates which is now determined by mac80211 through config_erp(). Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt73usb.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c216
1 files changed, 105 insertions, 111 deletions
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 69a4931a2fd3..5be49ed4ecf9 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -669,87 +669,18 @@ static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
669 rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE, 669 rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
670 !!erp->short_preamble); 670 !!erp->short_preamble);
671 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg); 671 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
672}
673
674static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
675 struct rt2x00lib_conf *libconf)
676{
677 u16 eeprom;
678 short lna_gain = 0;
679
680 if (libconf->band == IEEE80211_BAND_2GHZ) {
681 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
682 lna_gain += 14;
683
684 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
685 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
686 } else {
687 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
688 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
689 }
690
691 rt2x00dev->lna_gain = lna_gain;
692}
693
694static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev,
695 const int basic_rate_mask)
696{
697 rt73usb_register_write(rt2x00dev, TXRX_CSR5, basic_rate_mask);
698}
699
700static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
701 struct rf_channel *rf, const int txpower)
702{
703 u8 r3;
704 u8 r94;
705 u8 smart;
706
707 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
708 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
709
710 smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
711 rt2x00_rf(&rt2x00dev->chip, RF2527));
712
713 rt73usb_bbp_read(rt2x00dev, 3, &r3);
714 rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
715 rt73usb_bbp_write(rt2x00dev, 3, r3);
716
717 r94 = 6;
718 if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
719 r94 += txpower - MAX_TXPOWER;
720 else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
721 r94 += txpower;
722 rt73usb_bbp_write(rt2x00dev, 94, r94);
723
724 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
725 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
726 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
727 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
728
729 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
730 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
731 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
732 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
733 672
734 rt73usb_rf_write(rt2x00dev, 1, rf->rf1); 673 rt73usb_register_write(rt2x00dev, TXRX_CSR5, erp->basic_rates);
735 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
736 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
737 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
738
739 udelay(10);
740}
741
742static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
743 const int txpower)
744{
745 struct rf_channel rf;
746 674
747 rt2x00_rf_read(rt2x00dev, 1, &rf.rf1); 675 rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg);
748 rt2x00_rf_read(rt2x00dev, 2, &rf.rf2); 676 rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
749 rt2x00_rf_read(rt2x00dev, 3, &rf.rf3); 677 rt73usb_register_write(rt2x00dev, MAC_CSR9, reg);
750 rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
751 678
752 rt73usb_config_channel(rt2x00dev, &rf, txpower); 679 rt73usb_register_read(rt2x00dev, MAC_CSR8, &reg);
680 rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
681 rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
682 rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
683 rt73usb_register_write(rt2x00dev, MAC_CSR8, reg);
753} 684}
754 685
755static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev, 686static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
@@ -869,8 +800,8 @@ static const struct antenna_sel antenna_sel_bg[] = {
869 { 98, { 0x48, 0x48 } }, 800 { 98, { 0x48, 0x48 } },
870}; 801};
871 802
872static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev, 803static void rt73usb_config_ant(struct rt2x00_dev *rt2x00dev,
873 struct antenna_setup *ant) 804 struct antenna_setup *ant)
874{ 805{
875 const struct antenna_sel *sel; 806 const struct antenna_sel *sel;
876 unsigned int lna; 807 unsigned int lna;
@@ -912,20 +843,98 @@ static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev,
912 rt73usb_config_antenna_2x(rt2x00dev, ant); 843 rt73usb_config_antenna_2x(rt2x00dev, ant);
913} 844}
914 845
915static void rt73usb_config_duration(struct rt2x00_dev *rt2x00dev, 846static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
916 struct rt2x00lib_conf *libconf) 847 struct rt2x00lib_conf *libconf)
917{ 848{
849 u16 eeprom;
850 short lna_gain = 0;
851
852 if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
853 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
854 lna_gain += 14;
855
856 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
857 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
858 } else {
859 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
860 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
861 }
862
863 rt2x00dev->lna_gain = lna_gain;
864}
865
866static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
867 struct rf_channel *rf, const int txpower)
868{
869 u8 r3;
870 u8 r94;
871 u8 smart;
872
873 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
874 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
875
876 smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
877 rt2x00_rf(&rt2x00dev->chip, RF2527));
878
879 rt73usb_bbp_read(rt2x00dev, 3, &r3);
880 rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
881 rt73usb_bbp_write(rt2x00dev, 3, r3);
882
883 r94 = 6;
884 if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
885 r94 += txpower - MAX_TXPOWER;
886 else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
887 r94 += txpower;
888 rt73usb_bbp_write(rt2x00dev, 94, r94);
889
890 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
891 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
892 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
893 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
894
895 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
896 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
897 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
898 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
899
900 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
901 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
902 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
903 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
904
905 udelay(10);
906}
907
908static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
909 const int txpower)
910{
911 struct rf_channel rf;
912
913 rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
914 rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
915 rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
916 rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
917
918 rt73usb_config_channel(rt2x00dev, &rf, txpower);
919}
920
921static void rt73usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
922 struct rt2x00lib_conf *libconf)
923{
918 u32 reg; 924 u32 reg;
919 925
920 rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg); 926 rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
921 rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, libconf->slot_time); 927 rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
922 rt73usb_register_write(rt2x00dev, MAC_CSR9, reg); 928 libconf->conf->long_frame_max_tx_count);
929 rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
930 libconf->conf->short_frame_max_tx_count);
931 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
932}
923 933
924 rt73usb_register_read(rt2x00dev, MAC_CSR8, &reg); 934static void rt73usb_config_duration(struct rt2x00_dev *rt2x00dev,
925 rt2x00_set_field32(&reg, MAC_CSR8_SIFS, libconf->sifs); 935 struct rt2x00lib_conf *libconf)
926 rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3); 936{
927 rt2x00_set_field32(&reg, MAC_CSR8_EIFS, libconf->eifs); 937 u32 reg;
928 rt73usb_register_write(rt2x00dev, MAC_CSR8, reg);
929 938
930 rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg); 939 rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
931 rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER); 940 rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
@@ -948,16 +957,15 @@ static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
948 /* Always recalculate LNA gain before changing configuration */ 957 /* Always recalculate LNA gain before changing configuration */
949 rt73usb_config_lna_gain(rt2x00dev, libconf); 958 rt73usb_config_lna_gain(rt2x00dev, libconf);
950 959
951 if (flags & CONFIG_UPDATE_PHYMODE) 960 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
952 rt73usb_config_phymode(rt2x00dev, libconf->basic_rates);
953 if (flags & CONFIG_UPDATE_CHANNEL)
954 rt73usb_config_channel(rt2x00dev, &libconf->rf, 961 rt73usb_config_channel(rt2x00dev, &libconf->rf,
955 libconf->conf->power_level); 962 libconf->conf->power_level);
956 if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL)) 963 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
964 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
957 rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level); 965 rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level);
958 if (flags & CONFIG_UPDATE_ANTENNA) 966 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
959 rt73usb_config_antenna(rt2x00dev, &libconf->ant); 967 rt73usb_config_retry_limit(rt2x00dev, libconf);
960 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT)) 968 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
961 rt73usb_config_duration(rt2x00dev, libconf); 969 rt73usb_config_duration(rt2x00dev, libconf);
962} 970}
963 971
@@ -2209,20 +2217,6 @@ static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2209/* 2217/*
2210 * IEEE80211 stack callback functions. 2218 * IEEE80211 stack callback functions.
2211 */ 2219 */
2212static int rt73usb_set_retry_limit(struct ieee80211_hw *hw,
2213 u32 short_retry, u32 long_retry)
2214{
2215 struct rt2x00_dev *rt2x00dev = hw->priv;
2216 u32 reg;
2217
2218 rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
2219 rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT, long_retry);
2220 rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT, short_retry);
2221 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
2222
2223 return 0;
2224}
2225
2226static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx, 2220static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2227 const struct ieee80211_tx_queue_params *params) 2221 const struct ieee80211_tx_queue_params *params)
2228{ 2222{
@@ -2345,8 +2339,8 @@ static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
2345 .config_filter = rt73usb_config_filter, 2339 .config_filter = rt73usb_config_filter,
2346 .config_intf = rt73usb_config_intf, 2340 .config_intf = rt73usb_config_intf,
2347 .config_erp = rt73usb_config_erp, 2341 .config_erp = rt73usb_config_erp,
2342 .config_ant = rt73usb_config_ant,
2348 .config = rt73usb_config, 2343 .config = rt73usb_config,
2349 .set_retry_limit = rt73usb_set_retry_limit,
2350}; 2344};
2351 2345
2352static const struct data_queue_desc rt73usb_queue_rx = { 2346static const struct data_queue_desc rt73usb_queue_rx = {