aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2500usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2500usb.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c207
1 files changed, 116 insertions, 91 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index edc16a5fc754..31258ee24ee3 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -285,70 +285,65 @@ static const struct rt2x00debug rt2500usb_rt2x00debug = {
285/* 285/*
286 * Configuration handlers. 286 * Configuration handlers.
287 */ 287 */
288static void rt2500usb_config_mac_addr(struct rt2x00_dev *rt2x00dev, 288static void rt2500usb_config_intf(struct rt2x00_dev *rt2x00dev,
289 __le32 *mac) 289 struct rt2x00_intf *intf,
290{ 290 struct rt2x00intf_conf *conf,
291 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, mac, 291 const unsigned int flags)
292 (3 * sizeof(__le16)));
293}
294
295static void rt2500usb_config_bssid(struct rt2x00_dev *rt2x00dev,
296 __le32 *bssid)
297{
298 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, bssid,
299 (3 * sizeof(__le16)));
300}
301
302static void rt2500usb_config_type(struct rt2x00_dev *rt2x00dev, const int type,
303 const int tsf_sync)
304{ 292{
293 unsigned int bcn_preload;
305 u16 reg; 294 u16 reg;
306 295
307 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0); 296 if (flags & CONFIG_UPDATE_TYPE) {
297 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
308 298
309 /* 299 /*
310 * Enable beacon config 300 * Enable beacon config
311 */ 301 */
312 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg); 302 bcn_preload = PREAMBLE + get_duration(IEEE80211_HEADER, 20);
313 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, 303 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
314 (PREAMBLE + get_duration(IEEE80211_HEADER, 20)) >> 6); 304 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, bcn_preload >> 6);
315 if (type == IEEE80211_IF_TYPE_STA) 305 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW,
316 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW, 0); 306 2 * (conf->type != IEEE80211_IF_TYPE_STA));
317 else 307 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
318 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW, 2);
319 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
320 308
321 /* 309 /*
322 * Enable synchronisation. 310 * Enable synchronisation.
323 */ 311 */
324 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg); 312 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
325 rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0); 313 rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0);
326 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg); 314 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
315
316 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
317 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
318 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN,
319 (conf->sync == TSF_SYNC_BEACON));
320 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
321 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, conf->sync);
322 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
323 }
327 324
328 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg); 325 if (flags & CONFIG_UPDATE_MAC)
329 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1); 326 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, conf->mac,
330 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 327 (3 * sizeof(__le16)));
331 (tsf_sync == TSF_SYNC_BEACON)); 328
332 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0); 329 if (flags & CONFIG_UPDATE_BSSID)
333 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, tsf_sync); 330 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, conf->bssid,
334 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg); 331 (3 * sizeof(__le16)));
335} 332}
336 333
337static void rt2500usb_config_preamble(struct rt2x00_dev *rt2x00dev, 334static int rt2500usb_config_preamble(struct rt2x00_dev *rt2x00dev,
338 const int short_preamble, 335 const int short_preamble,
339 const int ack_timeout, 336 const int ack_timeout,
340 const int ack_consume_time) 337 const int ack_consume_time)
341{ 338{
342 u16 reg; 339 u16 reg;
343 340
344 /* 341 /*
345 * When in atomic context, reschedule and let rt2x00lib 342 * When in atomic context, we should let rt2x00lib
346 * call this function again. 343 * try this configuration again later.
347 */ 344 */
348 if (in_atomic()) { 345 if (in_atomic())
349 queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->config_work); 346 return -EAGAIN;
350 return;
351 }
352 347
353 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg); 348 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
354 rt2x00_set_field16(&reg, TXRX_CSR1_ACK_TIMEOUT, ack_timeout); 349 rt2x00_set_field16(&reg, TXRX_CSR1_ACK_TIMEOUT, ack_timeout);
@@ -358,6 +353,8 @@ static void rt2500usb_config_preamble(struct rt2x00_dev *rt2x00dev,
358 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE, 353 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
359 !!short_preamble); 354 !!short_preamble);
360 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg); 355 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
356
357 return 0;
361} 358}
362 359
363static void rt2500usb_config_phymode(struct rt2x00_dev *rt2x00dev, 360static void rt2500usb_config_phymode(struct rt2x00_dev *rt2x00dev,
@@ -518,8 +515,8 @@ static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
518} 515}
519 516
520static void rt2500usb_config(struct rt2x00_dev *rt2x00dev, 517static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
521 const unsigned int flags, 518 struct rt2x00lib_conf *libconf,
522 struct rt2x00lib_conf *libconf) 519 const unsigned int flags)
523{ 520{
524 if (flags & CONFIG_UPDATE_PHYMODE) 521 if (flags & CONFIG_UPDATE_PHYMODE)
525 rt2500usb_config_phymode(rt2x00dev, libconf->phymode, 522 rt2500usb_config_phymode(rt2x00dev, libconf->phymode,
@@ -626,6 +623,24 @@ static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
626 u8 low_bound; 623 u8 low_bound;
627 624
628 /* 625 /*
626 * Read current r17 value, as well as the sensitivity values
627 * for the r17 register.
628 */
629 rt2500usb_bbp_read(rt2x00dev, 17, &r17);
630 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
631
632 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
633 up_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
634 low_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCLOWER);
635
636 /*
637 * If we are not associated, we should go straight to the
638 * dynamic CCA tuning.
639 */
640 if (!rt2x00dev->intf_associated)
641 goto dynamic_cca_tune;
642
643 /*
629 * Determine the BBP tuning threshold and correctly 644 * Determine the BBP tuning threshold and correctly
630 * set BBP 24, 25 and 61. 645 * set BBP 24, 25 and 61.
631 */ 646 */
@@ -651,13 +666,6 @@ static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
651 rt2500usb_bbp_write(rt2x00dev, 61, r61); 666 rt2500usb_bbp_write(rt2x00dev, 61, r61);
652 667
653 /* 668 /*
654 * Read current r17 value, as well as the sensitivity values
655 * for the r17 register.
656 */
657 rt2500usb_bbp_read(rt2x00dev, 17, &r17);
658 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
659
660 /*
661 * A too low RSSI will cause too much false CCA which will 669 * A too low RSSI will cause too much false CCA which will
662 * then corrupt the R17 tuning. To remidy this the tuning should 670 * then corrupt the R17 tuning. To remidy this the tuning should
663 * be stopped (While making sure the R17 value will not exceed limits) 671 * be stopped (While making sure the R17 value will not exceed limits)
@@ -692,14 +700,9 @@ static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
692 * Leave short or middle distance condition, restore r17 700 * Leave short or middle distance condition, restore r17
693 * to the dynamic tuning range. 701 * to the dynamic tuning range.
694 */ 702 */
695 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
696 vgc_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
697
698 low_bound = 0x32; 703 low_bound = 0x32;
699 if (rssi >= -77) 704 if (rssi < -77)
700 up_bound = vgc_bound; 705 up_bound -= (-77 - rssi);
701 else
702 up_bound = vgc_bound - (-77 - rssi);
703 706
704 if (up_bound < low_bound) 707 if (up_bound < low_bound)
705 up_bound = low_bound; 708 up_bound = low_bound;
@@ -707,7 +710,16 @@ static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
707 if (r17 > up_bound) { 710 if (r17 > up_bound) {
708 rt2500usb_bbp_write(rt2x00dev, 17, up_bound); 711 rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
709 rt2x00dev->link.vgc_level = up_bound; 712 rt2x00dev->link.vgc_level = up_bound;
710 } else if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) { 713 return;
714 }
715
716dynamic_cca_tune:
717
718 /*
719 * R17 is inside the dynamic tuning range,
720 * start tuning the link based on the false cca counter.
721 */
722 if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
711 rt2500usb_bbp_write(rt2x00dev, 17, ++r17); 723 rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
712 rt2x00dev->link.vgc_level = r17; 724 rt2x00dev->link.vgc_level = r17;
713 } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) { 725 } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
@@ -1203,6 +1215,7 @@ static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1203{ 1215{
1204 u16 word; 1216 u16 word;
1205 u8 *mac; 1217 u8 *mac;
1218 u8 bbp;
1206 1219
1207 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE); 1220 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
1208 1221
@@ -1257,9 +1270,17 @@ static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1257 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word); 1270 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
1258 } 1271 }
1259 1272
1273 /*
1274 * Switch lower vgc bound to current BBP R17 value,
1275 * lower the value a bit for better quality.
1276 */
1277 rt2500usb_bbp_read(rt2x00dev, 17, &bbp);
1278 bbp -= 6;
1279
1260 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word); 1280 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
1261 if (word == 0xffff) { 1281 if (word == 0xffff) {
1262 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40); 1282 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
1283 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1263 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word); 1284 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1264 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word); 1285 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
1265 } 1286 }
@@ -1270,6 +1291,9 @@ static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1270 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41); 1291 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
1271 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word); 1292 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
1272 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word); 1293 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
1294 } else {
1295 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1296 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1273 } 1297 }
1274 1298
1275 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word); 1299 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
@@ -1705,40 +1729,40 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1705{ 1729{
1706 struct rt2x00_dev *rt2x00dev = hw->priv; 1730 struct rt2x00_dev *rt2x00dev = hw->priv;
1707 struct usb_device *usb_dev = rt2x00dev_usb_dev(rt2x00dev); 1731 struct usb_device *usb_dev = rt2x00dev_usb_dev(rt2x00dev);
1732 struct rt2x00_intf *intf = vif_to_intf(control->vif);
1708 struct queue_entry_priv_usb_bcn *priv_bcn; 1733 struct queue_entry_priv_usb_bcn *priv_bcn;
1709 struct skb_frame_desc *skbdesc; 1734 struct skb_frame_desc *skbdesc;
1710 struct data_queue *queue;
1711 struct queue_entry *entry;
1712 int pipe = usb_sndbulkpipe(usb_dev, 1); 1735 int pipe = usb_sndbulkpipe(usb_dev, 1);
1713 int length; 1736 int length;
1714 1737
1715 /* 1738 if (unlikely(!intf->beacon))
1716 * Just in case the ieee80211 doesn't set this, 1739 return -ENOBUFS;
1717 * but we need this queue set for the descriptor 1740
1718 * initialization. 1741 priv_bcn = intf->beacon->priv_data;
1719 */
1720 control->queue = IEEE80211_TX_QUEUE_BEACON;
1721 queue = rt2x00queue_get_queue(rt2x00dev, control->queue);
1722 entry = rt2x00queue_get_entry(queue, Q_INDEX);
1723 priv_bcn = entry->priv_data;
1724 1742
1725 /* 1743 /*
1726 * Add the descriptor in front of the skb. 1744 * Add the descriptor in front of the skb.
1727 */ 1745 */
1728 skb_push(skb, queue->desc_size); 1746 skb_push(skb, intf->beacon->queue->desc_size);
1729 memset(skb->data, 0, queue->desc_size); 1747 memset(skb->data, 0, intf->beacon->queue->desc_size);
1730 1748
1731 /* 1749 /*
1732 * Fill in skb descriptor 1750 * Fill in skb descriptor
1733 */ 1751 */
1734 skbdesc = get_skb_frame_desc(skb); 1752 skbdesc = get_skb_frame_desc(skb);
1735 memset(skbdesc, 0, sizeof(*skbdesc)); 1753 memset(skbdesc, 0, sizeof(*skbdesc));
1736 skbdesc->data = skb->data + queue->desc_size; 1754 skbdesc->data = skb->data + intf->beacon->queue->desc_size;
1737 skbdesc->data_len = queue->data_size; 1755 skbdesc->data_len = skb->len - intf->beacon->queue->desc_size;
1738 skbdesc->desc = skb->data; 1756 skbdesc->desc = skb->data;
1739 skbdesc->desc_len = queue->desc_size; 1757 skbdesc->desc_len = intf->beacon->queue->desc_size;
1740 skbdesc->entry = entry; 1758 skbdesc->entry = intf->beacon;
1741 1759
1760 /*
1761 * Just in case mac80211 doesn't set this correctly,
1762 * but we need this queue set for the descriptor
1763 * initialization.
1764 */
1765 control->queue = IEEE80211_TX_QUEUE_BEACON;
1742 rt2x00lib_write_tx_desc(rt2x00dev, skb, control); 1766 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
1743 1767
1744 /* 1768 /*
@@ -1749,7 +1773,8 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1749 length = rt2500usb_get_tx_data_len(rt2x00dev, skb); 1773 length = rt2500usb_get_tx_data_len(rt2x00dev, skb);
1750 1774
1751 usb_fill_bulk_urb(priv_bcn->urb, usb_dev, pipe, 1775 usb_fill_bulk_urb(priv_bcn->urb, usb_dev, pipe,
1752 skb->data, length, rt2500usb_beacondone, entry); 1776 skb->data, length, rt2500usb_beacondone,
1777 intf->beacon);
1753 1778
1754 /* 1779 /*
1755 * Second we need to create the guardian byte. 1780 * Second we need to create the guardian byte.
@@ -1759,7 +1784,7 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1759 priv_bcn->guardian_data = 0; 1784 priv_bcn->guardian_data = 0;
1760 usb_fill_bulk_urb(priv_bcn->guardian_urb, usb_dev, pipe, 1785 usb_fill_bulk_urb(priv_bcn->guardian_urb, usb_dev, pipe,
1761 &priv_bcn->guardian_data, 1, rt2500usb_beacondone, 1786 &priv_bcn->guardian_data, 1, rt2500usb_beacondone,
1762 entry); 1787 intf->beacon);
1763 1788
1764 /* 1789 /*
1765 * Send out the guardian byte. 1790 * Send out the guardian byte.
@@ -1769,7 +1794,7 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1769 /* 1794 /*
1770 * Enable beacon generation. 1795 * Enable beacon generation.
1771 */ 1796 */
1772 rt2500usb_kick_tx_queue(rt2x00dev, IEEE80211_TX_QUEUE_BEACON); 1797 rt2500usb_kick_tx_queue(rt2x00dev, control->queue);
1773 1798
1774 return 0; 1799 return 0;
1775} 1800}
@@ -1805,9 +1830,7 @@ static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1805 .get_tx_data_len = rt2500usb_get_tx_data_len, 1830 .get_tx_data_len = rt2500usb_get_tx_data_len,
1806 .kick_tx_queue = rt2500usb_kick_tx_queue, 1831 .kick_tx_queue = rt2500usb_kick_tx_queue,
1807 .fill_rxdone = rt2500usb_fill_rxdone, 1832 .fill_rxdone = rt2500usb_fill_rxdone,
1808 .config_mac_addr = rt2500usb_config_mac_addr, 1833 .config_intf = rt2500usb_config_intf,
1809 .config_bssid = rt2500usb_config_bssid,
1810 .config_type = rt2500usb_config_type,
1811 .config_preamble = rt2500usb_config_preamble, 1834 .config_preamble = rt2500usb_config_preamble,
1812 .config = rt2500usb_config, 1835 .config = rt2500usb_config,
1813}; 1836};
@@ -1842,6 +1865,8 @@ static const struct data_queue_desc rt2500usb_queue_atim = {
1842 1865
1843static const struct rt2x00_ops rt2500usb_ops = { 1866static const struct rt2x00_ops rt2500usb_ops = {
1844 .name = KBUILD_MODNAME, 1867 .name = KBUILD_MODNAME,
1868 .max_sta_intf = 1,
1869 .max_ap_intf = 1,
1845 .eeprom_size = EEPROM_SIZE, 1870 .eeprom_size = EEPROM_SIZE,
1846 .rf_size = RF_SIZE, 1871 .rf_size = RF_SIZE,
1847 .rx = &rt2500usb_queue_rx, 1872 .rx = &rt2500usb_queue_rx,