aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2800lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2800lib.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c198
1 files changed, 164 insertions, 34 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index dbf74d07d947..6331c61957a3 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -687,6 +687,9 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status)
687 mcs = real_mcs; 687 mcs = real_mcs;
688 } 688 }
689 689
690 if (aggr == 1 || ampdu == 1)
691 __set_bit(TXDONE_AMPDU, &txdesc.flags);
692
690 /* 693 /*
691 * Ralink has a retry mechanism using a global fallback 694 * Ralink has a retry mechanism using a global fallback
692 * table. We setup this fallback table to try the immediate 695 * table. We setup this fallback table to try the immediate
@@ -1813,17 +1816,131 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
1813 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &reg); 1816 rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &reg);
1814} 1817}
1815 1818
1819static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev)
1820{
1821 u8 tssi_bounds[9];
1822 u8 current_tssi;
1823 u16 eeprom;
1824 u8 step;
1825 int i;
1826
1827 /*
1828 * Read TSSI boundaries for temperature compensation from
1829 * the EEPROM.
1830 *
1831 * Array idx 0 1 2 3 4 5 6 7 8
1832 * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4
1833 * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00
1834 */
1835 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
1836 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom);
1837 tssi_bounds[0] = rt2x00_get_field16(eeprom,
1838 EEPROM_TSSI_BOUND_BG1_MINUS4);
1839 tssi_bounds[1] = rt2x00_get_field16(eeprom,
1840 EEPROM_TSSI_BOUND_BG1_MINUS3);
1841
1842 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom);
1843 tssi_bounds[2] = rt2x00_get_field16(eeprom,
1844 EEPROM_TSSI_BOUND_BG2_MINUS2);
1845 tssi_bounds[3] = rt2x00_get_field16(eeprom,
1846 EEPROM_TSSI_BOUND_BG2_MINUS1);
1847
1848 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom);
1849 tssi_bounds[4] = rt2x00_get_field16(eeprom,
1850 EEPROM_TSSI_BOUND_BG3_REF);
1851 tssi_bounds[5] = rt2x00_get_field16(eeprom,
1852 EEPROM_TSSI_BOUND_BG3_PLUS1);
1853
1854 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom);
1855 tssi_bounds[6] = rt2x00_get_field16(eeprom,
1856 EEPROM_TSSI_BOUND_BG4_PLUS2);
1857 tssi_bounds[7] = rt2x00_get_field16(eeprom,
1858 EEPROM_TSSI_BOUND_BG4_PLUS3);
1859
1860 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom);
1861 tssi_bounds[8] = rt2x00_get_field16(eeprom,
1862 EEPROM_TSSI_BOUND_BG5_PLUS4);
1863
1864 step = rt2x00_get_field16(eeprom,
1865 EEPROM_TSSI_BOUND_BG5_AGC_STEP);
1866 } else {
1867 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom);
1868 tssi_bounds[0] = rt2x00_get_field16(eeprom,
1869 EEPROM_TSSI_BOUND_A1_MINUS4);
1870 tssi_bounds[1] = rt2x00_get_field16(eeprom,
1871 EEPROM_TSSI_BOUND_A1_MINUS3);
1872
1873 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom);
1874 tssi_bounds[2] = rt2x00_get_field16(eeprom,
1875 EEPROM_TSSI_BOUND_A2_MINUS2);
1876 tssi_bounds[3] = rt2x00_get_field16(eeprom,
1877 EEPROM_TSSI_BOUND_A2_MINUS1);
1878
1879 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom);
1880 tssi_bounds[4] = rt2x00_get_field16(eeprom,
1881 EEPROM_TSSI_BOUND_A3_REF);
1882 tssi_bounds[5] = rt2x00_get_field16(eeprom,
1883 EEPROM_TSSI_BOUND_A3_PLUS1);
1884
1885 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom);
1886 tssi_bounds[6] = rt2x00_get_field16(eeprom,
1887 EEPROM_TSSI_BOUND_A4_PLUS2);
1888 tssi_bounds[7] = rt2x00_get_field16(eeprom,
1889 EEPROM_TSSI_BOUND_A4_PLUS3);
1890
1891 rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom);
1892 tssi_bounds[8] = rt2x00_get_field16(eeprom,
1893 EEPROM_TSSI_BOUND_A5_PLUS4);
1894
1895 step = rt2x00_get_field16(eeprom,
1896 EEPROM_TSSI_BOUND_A5_AGC_STEP);
1897 }
1898
1899 /*
1900 * Check if temperature compensation is supported.
1901 */
1902 if (tssi_bounds[4] == 0xff)
1903 return 0;
1904
1905 /*
1906 * Read current TSSI (BBP 49).
1907 */
1908 rt2800_bbp_read(rt2x00dev, 49, &current_tssi);
1909
1910 /*
1911 * Compare TSSI value (BBP49) with the compensation boundaries
1912 * from the EEPROM and increase or decrease tx power.
1913 */
1914 for (i = 0; i <= 3; i++) {
1915 if (current_tssi > tssi_bounds[i])
1916 break;
1917 }
1918
1919 if (i == 4) {
1920 for (i = 8; i >= 5; i--) {
1921 if (current_tssi < tssi_bounds[i])
1922 break;
1923 }
1924 }
1925
1926 return (i - 4) * step;
1927}
1928
1816static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev, 1929static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
1817 enum ieee80211_band band) 1930 enum ieee80211_band band)
1818{ 1931{
1819 u16 eeprom; 1932 u16 eeprom;
1820 u8 comp_en; 1933 u8 comp_en;
1821 u8 comp_type; 1934 u8 comp_type;
1822 int comp_value; 1935 int comp_value = 0;
1823 1936
1824 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom); 1937 rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom);
1825 1938
1826 if (eeprom == 0xffff) 1939 /*
1940 * HT40 compensation not required.
1941 */
1942 if (eeprom == 0xffff ||
1943 !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1827 return 0; 1944 return 0;
1828 1945
1829 if (band == IEEE80211_BAND_2GHZ) { 1946 if (band == IEEE80211_BAND_2GHZ) {
@@ -1853,11 +1970,9 @@ static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
1853 return comp_value; 1970 return comp_value;
1854} 1971}
1855 1972
1856static u8 rt2800_compesate_txpower(struct rt2x00_dev *rt2x00dev, 1973static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b,
1857 int is_rate_b, 1974 enum ieee80211_band band, int power_level,
1858 enum ieee80211_band band, 1975 u8 txpower, int delta)
1859 int power_level,
1860 u8 txpower)
1861{ 1976{
1862 u32 reg; 1977 u32 reg;
1863 u16 eeprom; 1978 u16 eeprom;
@@ -1865,14 +1980,10 @@ static u8 rt2800_compesate_txpower(struct rt2x00_dev *rt2x00dev,
1865 u8 eirp_txpower; 1980 u8 eirp_txpower;
1866 u8 eirp_txpower_criterion; 1981 u8 eirp_txpower_criterion;
1867 u8 reg_limit; 1982 u8 reg_limit;
1868 int bw_comp = 0;
1869 1983
1870 if (!((band == IEEE80211_BAND_5GHZ) && is_rate_b)) 1984 if (!((band == IEEE80211_BAND_5GHZ) && is_rate_b))
1871 return txpower; 1985 return txpower;
1872 1986
1873 if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1874 bw_comp = rt2800_get_txpower_bw_comp(rt2x00dev, band);
1875
1876 if (test_bit(CONFIG_SUPPORT_POWER_LIMIT, &rt2x00dev->flags)) { 1987 if (test_bit(CONFIG_SUPPORT_POWER_LIMIT, &rt2x00dev->flags)) {
1877 /* 1988 /*
1878 * Check if eirp txpower exceed txpower_limit. 1989 * Check if eirp txpower exceed txpower_limit.
@@ -1895,18 +2006,19 @@ static u8 rt2800_compesate_txpower(struct rt2x00_dev *rt2x00dev,
1895 EEPROM_EIRP_MAX_TX_POWER_5GHZ); 2006 EEPROM_EIRP_MAX_TX_POWER_5GHZ);
1896 2007
1897 eirp_txpower = eirp_txpower_criterion + (txpower - criterion) + 2008 eirp_txpower = eirp_txpower_criterion + (txpower - criterion) +
1898 (is_rate_b ? 4 : 0) + bw_comp; 2009 (is_rate_b ? 4 : 0) + delta;
1899 2010
1900 reg_limit = (eirp_txpower > power_level) ? 2011 reg_limit = (eirp_txpower > power_level) ?
1901 (eirp_txpower - power_level) : 0; 2012 (eirp_txpower - power_level) : 0;
1902 } else 2013 } else
1903 reg_limit = 0; 2014 reg_limit = 0;
1904 2015
1905 return txpower + bw_comp - reg_limit; 2016 return txpower + delta - reg_limit;
1906} 2017}
1907 2018
1908static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev, 2019static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1909 struct ieee80211_conf *conf) 2020 enum ieee80211_band band,
2021 int power_level)
1910{ 2022{
1911 u8 txpower; 2023 u8 txpower;
1912 u16 eeprom; 2024 u16 eeprom;
@@ -1914,8 +2026,17 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1914 u32 reg; 2026 u32 reg;
1915 u8 r1; 2027 u8 r1;
1916 u32 offset; 2028 u32 offset;
1917 enum ieee80211_band band = conf->channel->band; 2029 int delta;
1918 int power_level = conf->power_level; 2030
2031 /*
2032 * Calculate HT40 compensation delta
2033 */
2034 delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
2035
2036 /*
2037 * calculate temperature compensation delta
2038 */
2039 delta += rt2800_get_gain_calibration_delta(rt2x00dev);
1919 2040
1920 /* 2041 /*
1921 * set to normal bbp tx power control mode: +/- 0dBm 2042 * set to normal bbp tx power control mode: +/- 0dBm
@@ -1944,8 +2065,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1944 */ 2065 */
1945 txpower = rt2x00_get_field16(eeprom, 2066 txpower = rt2x00_get_field16(eeprom,
1946 EEPROM_TXPOWER_BYRATE_RATE0); 2067 EEPROM_TXPOWER_BYRATE_RATE0);
1947 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2068 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
1948 power_level, txpower); 2069 power_level, txpower, delta);
1949 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE0, txpower); 2070 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE0, txpower);
1950 2071
1951 /* 2072 /*
@@ -1955,8 +2076,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1955 */ 2076 */
1956 txpower = rt2x00_get_field16(eeprom, 2077 txpower = rt2x00_get_field16(eeprom,
1957 EEPROM_TXPOWER_BYRATE_RATE1); 2078 EEPROM_TXPOWER_BYRATE_RATE1);
1958 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2079 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
1959 power_level, txpower); 2080 power_level, txpower, delta);
1960 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE1, txpower); 2081 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE1, txpower);
1961 2082
1962 /* 2083 /*
@@ -1966,8 +2087,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1966 */ 2087 */
1967 txpower = rt2x00_get_field16(eeprom, 2088 txpower = rt2x00_get_field16(eeprom,
1968 EEPROM_TXPOWER_BYRATE_RATE2); 2089 EEPROM_TXPOWER_BYRATE_RATE2);
1969 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2090 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
1970 power_level, txpower); 2091 power_level, txpower, delta);
1971 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE2, txpower); 2092 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE2, txpower);
1972 2093
1973 /* 2094 /*
@@ -1977,8 +2098,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1977 */ 2098 */
1978 txpower = rt2x00_get_field16(eeprom, 2099 txpower = rt2x00_get_field16(eeprom,
1979 EEPROM_TXPOWER_BYRATE_RATE3); 2100 EEPROM_TXPOWER_BYRATE_RATE3);
1980 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2101 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
1981 power_level, txpower); 2102 power_level, txpower, delta);
1982 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE3, txpower); 2103 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE3, txpower);
1983 2104
1984 /* read the next four txpower values */ 2105 /* read the next four txpower values */
@@ -1993,8 +2114,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
1993 */ 2114 */
1994 txpower = rt2x00_get_field16(eeprom, 2115 txpower = rt2x00_get_field16(eeprom,
1995 EEPROM_TXPOWER_BYRATE_RATE0); 2116 EEPROM_TXPOWER_BYRATE_RATE0);
1996 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2117 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
1997 power_level, txpower); 2118 power_level, txpower, delta);
1998 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE4, txpower); 2119 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE4, txpower);
1999 2120
2000 /* 2121 /*
@@ -2004,8 +2125,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
2004 */ 2125 */
2005 txpower = rt2x00_get_field16(eeprom, 2126 txpower = rt2x00_get_field16(eeprom,
2006 EEPROM_TXPOWER_BYRATE_RATE1); 2127 EEPROM_TXPOWER_BYRATE_RATE1);
2007 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2128 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
2008 power_level, txpower); 2129 power_level, txpower, delta);
2009 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE5, txpower); 2130 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE5, txpower);
2010 2131
2011 /* 2132 /*
@@ -2015,8 +2136,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
2015 */ 2136 */
2016 txpower = rt2x00_get_field16(eeprom, 2137 txpower = rt2x00_get_field16(eeprom,
2017 EEPROM_TXPOWER_BYRATE_RATE2); 2138 EEPROM_TXPOWER_BYRATE_RATE2);
2018 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2139 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
2019 power_level, txpower); 2140 power_level, txpower, delta);
2020 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE6, txpower); 2141 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE6, txpower);
2021 2142
2022 /* 2143 /*
@@ -2026,8 +2147,8 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
2026 */ 2147 */
2027 txpower = rt2x00_get_field16(eeprom, 2148 txpower = rt2x00_get_field16(eeprom,
2028 EEPROM_TXPOWER_BYRATE_RATE3); 2149 EEPROM_TXPOWER_BYRATE_RATE3);
2029 txpower = rt2800_compesate_txpower(rt2x00dev, is_rate_b, band, 2150 txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
2030 power_level, txpower); 2151 power_level, txpower, delta);
2031 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE7, txpower); 2152 rt2x00_set_field32(&reg, TX_PWR_CFG_RATE7, txpower);
2032 2153
2033 rt2800_register_write(rt2x00dev, offset, reg); 2154 rt2800_register_write(rt2x00dev, offset, reg);
@@ -2037,6 +2158,13 @@ static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
2037 } 2158 }
2038} 2159}
2039 2160
2161void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev)
2162{
2163 rt2800_config_txpower(rt2x00dev, rt2x00dev->curr_band,
2164 rt2x00dev->tx_power);
2165}
2166EXPORT_SYMBOL_GPL(rt2800_gain_calibration);
2167
2040static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev, 2168static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev,
2041 struct rt2x00lib_conf *libconf) 2169 struct rt2x00lib_conf *libconf)
2042{ 2170{
@@ -2090,10 +2218,12 @@ void rt2800_config(struct rt2x00_dev *rt2x00dev,
2090 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) { 2218 if (flags & IEEE80211_CONF_CHANGE_CHANNEL) {
2091 rt2800_config_channel(rt2x00dev, libconf->conf, 2219 rt2800_config_channel(rt2x00dev, libconf->conf,
2092 &libconf->rf, &libconf->channel); 2220 &libconf->rf, &libconf->channel);
2093 rt2800_config_txpower(rt2x00dev, libconf->conf); 2221 rt2800_config_txpower(rt2x00dev, libconf->conf->channel->band,
2222 libconf->conf->power_level);
2094 } 2223 }
2095 if (flags & IEEE80211_CONF_CHANGE_POWER) 2224 if (flags & IEEE80211_CONF_CHANGE_POWER)
2096 rt2800_config_txpower(rt2x00dev, libconf->conf); 2225 rt2800_config_txpower(rt2x00dev, libconf->conf->channel->band,
2226 libconf->conf->power_level);
2097 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) 2227 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
2098 rt2800_config_retry_limit(rt2x00dev, libconf); 2228 rt2800_config_retry_limit(rt2x00dev, libconf);
2099 if (flags & IEEE80211_CONF_CHANGE_PS) 2229 if (flags & IEEE80211_CONF_CHANGE_PS)