Commit ba2ab471 authored by Ivo van Doorn's avatar Ivo van Doorn Committed by John W. Linville

rt2x00: Move lna_gain calculation to config() callback

We can optimize lna calculation in IRQ context by
calculating most of the value during the config() callback
when most of the value is actually influenced.

This will be required later by rt2800pci and rt2800usb as
well, since they need the lna_gain value during config().
Signed-off-by: default avatarIvo van Doorn <IvDoorn@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 48c2fc59
...@@ -803,6 +803,11 @@ struct rt2x00_dev { ...@@ -803,6 +803,11 @@ struct rt2x00_dev {
*/ */
u32 *rf; u32 *rf;
/*
* LNA gain
*/
short lna_gain;
/* /*
* USB Max frame size (for rt2500usb & rt73usb). * USB Max frame size (for rt2500usb & rt73usb).
*/ */
......
...@@ -638,6 +638,30 @@ static void rt61pci_config_erp(struct rt2x00_dev *rt2x00dev, ...@@ -638,6 +638,30 @@ static void rt61pci_config_erp(struct rt2x00_dev *rt2x00dev,
rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg); rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
} }
static void rt61pci_config_lna_gain(struct rt2x00_dev *rt2x00dev,
struct rt2x00lib_conf *libconf)
{
u16 eeprom;
short lna_gain = 0;
if (libconf->band == IEEE80211_BAND_2GHZ) {
if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
lna_gain += 14;
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
} else {
if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
lna_gain += 14;
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
}
rt2x00dev->lna_gain = lna_gain;
}
static void rt61pci_config_phymode(struct rt2x00_dev *rt2x00dev, static void rt61pci_config_phymode(struct rt2x00_dev *rt2x00dev,
const int basic_rate_mask) const int basic_rate_mask)
{ {
...@@ -956,6 +980,9 @@ static void rt61pci_config(struct rt2x00_dev *rt2x00dev, ...@@ -956,6 +980,9 @@ static void rt61pci_config(struct rt2x00_dev *rt2x00dev,
struct rt2x00lib_conf *libconf, struct rt2x00lib_conf *libconf,
const unsigned int flags) const unsigned int flags)
{ {
/* Always recalculate LNA gain before changing configuration */
rt61pci_config_lna_gain(rt2x00dev, libconf);
if (flags & CONFIG_UPDATE_PHYMODE) if (flags & CONFIG_UPDATE_PHYMODE)
rt61pci_config_phymode(rt2x00dev, libconf->basic_rates); rt61pci_config_phymode(rt2x00dev, libconf->basic_rates);
if (flags & CONFIG_UPDATE_CHANNEL) if (flags & CONFIG_UPDATE_CHANNEL)
...@@ -1883,40 +1910,27 @@ static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev, ...@@ -1883,40 +1910,27 @@ static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
*/ */
static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1) static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
{ {
u16 eeprom; u8 offset = rt2x00dev->lna_gain;
u8 offset;
u8 lna; u8 lna;
lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA); lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
switch (lna) { switch (lna) {
case 3: case 3:
offset = 90; offset += 90;
break; break;
case 2: case 2:
offset = 74; offset += 74;
break; break;
case 1: case 1:
offset = 64; offset += 64;
break; break;
default: default:
return 0; return 0;
} }
if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) { if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
offset += 14;
if (lna == 3 || lna == 2) if (lna == 3 || lna == 2)
offset += 10; offset += 10;
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
} else {
if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
offset += 14;
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
} }
return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset; return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
......
...@@ -664,6 +664,26 @@ static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev, ...@@ -664,6 +664,26 @@ static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg); rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
} }
static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
struct rt2x00lib_conf *libconf)
{
u16 eeprom;
short lna_gain = 0;
if (libconf->band == IEEE80211_BAND_2GHZ) {
if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
lna_gain += 14;
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
} else {
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
}
rt2x00dev->lna_gain = lna_gain;
}
static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev, static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev,
const int basic_rate_mask) const int basic_rate_mask)
{ {
...@@ -918,6 +938,9 @@ static void rt73usb_config(struct rt2x00_dev *rt2x00dev, ...@@ -918,6 +938,9 @@ static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
struct rt2x00lib_conf *libconf, struct rt2x00lib_conf *libconf,
const unsigned int flags) const unsigned int flags)
{ {
/* Always recalculate LNA gain before changing configuration */
rt73usb_config_lna_gain(rt2x00dev, libconf);
if (flags & CONFIG_UPDATE_PHYMODE) if (flags & CONFIG_UPDATE_PHYMODE)
rt73usb_config_phymode(rt2x00dev, libconf->basic_rates); rt73usb_config_phymode(rt2x00dev, libconf->basic_rates);
if (flags & CONFIG_UPDATE_CHANNEL) if (flags & CONFIG_UPDATE_CHANNEL)
...@@ -1644,20 +1667,19 @@ static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev, ...@@ -1644,20 +1667,19 @@ static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
*/ */
static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1) static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
{ {
u16 eeprom; u8 offset = rt2x00dev->lna_gain;
u8 offset;
u8 lna; u8 lna;
lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA); lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
switch (lna) { switch (lna) {
case 3: case 3:
offset = 90; offset += 90;
break; break;
case 2: case 2:
offset = 74; offset += 74;
break; break;
case 1: case 1:
offset = 64; offset += 64;
break; break;
default: default:
return 0; return 0;
...@@ -1673,15 +1695,6 @@ static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1) ...@@ -1673,15 +1695,6 @@ static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
else if (lna == 2) else if (lna == 2)
offset += 8; offset += 8;
} }
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
} else {
if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
offset += 14;
rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
} }
return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset; return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment