aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorChristian Lamparter <chunkeey@web.de>2008-11-29 16:37:31 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-12-05 09:35:44 -0500
commitb2023ddcfa6b79f26ef459867324f3d32b91aa07 (patch)
tree751a6f5593ef90732067132ad7b446460c9057e0 /drivers/net
parent64c354ddcd65c98d9a1e2a8f7fb5cc80c7fa488e (diff)
p54: refactoring
Thanks to the introduction of "changed" flags, we no longer have to do the bookkeeping of p54's firmware state for everything. Thus we can cut down redundancy code. Signed-off-by: Christian Lamparter <chunkeey@web.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/p54/p54.h2
-rw-r--r--drivers/net/wireless/p54/p54common.c158
2 files changed, 79 insertions, 81 deletions
diff --git a/drivers/net/wireless/p54/p54.h b/drivers/net/wireless/p54/p54.h
index ebe1ea1f565b..d2dbb9e15d97 100644
--- a/drivers/net/wireless/p54/p54.h
+++ b/drivers/net/wireless/p54/p54.h
@@ -85,7 +85,6 @@ struct p54_common {
85 struct mutex conf_mutex; 85 struct mutex conf_mutex;
86 u8 mac_addr[ETH_ALEN]; 86 u8 mac_addr[ETH_ALEN];
87 u8 bssid[ETH_ALEN]; 87 u8 bssid[ETH_ALEN];
88 u16 mac_mode;
89 struct pda_iq_autocal_entry *iq_autocal; 88 struct pda_iq_autocal_entry *iq_autocal;
90 unsigned int iq_autocal_len; 89 unsigned int iq_autocal_len;
91 struct pda_channel_output_limit *output_limit; 90 struct pda_channel_output_limit *output_limit;
@@ -95,7 +94,6 @@ struct p54_common {
95 bool use_short_slot; 94 bool use_short_slot;
96 u16 rxhw; 95 u16 rxhw;
97 u8 version; 96 u8 version;
98 u8 rx_antenna;
99 unsigned int tx_hdr_len; 97 unsigned int tx_hdr_len;
100 unsigned int fw_var; 98 unsigned int fw_var;
101 unsigned int fw_interface; 99 unsigned int fw_interface;
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
index 1b5627d4062e..06c8321f4e3e 100644
--- a/drivers/net/wireless/p54/p54common.c
+++ b/drivers/net/wireless/p54/p54common.c
@@ -1334,11 +1334,12 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
1334 return NETDEV_TX_BUSY; 1334 return NETDEV_TX_BUSY;
1335} 1335}
1336 1336
1337static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid) 1337static int p54_setup_mac(struct ieee80211_hw *dev)
1338{ 1338{
1339 struct p54_common *priv = dev->priv; 1339 struct p54_common *priv = dev->priv;
1340 struct sk_buff *skb; 1340 struct sk_buff *skb;
1341 struct p54_setup_mac *setup; 1341 struct p54_setup_mac *setup;
1342 u16 mode;
1342 1343
1343 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) + 1344 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) +
1344 sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP, 1345 sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP,
@@ -1347,14 +1348,31 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid)
1347 return -ENOMEM; 1348 return -ENOMEM;
1348 1349
1349 setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup)); 1350 setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
1350 priv->mac_mode = mode; 1351 if (dev->conf.radio_enabled) {
1352 switch (priv->mode) {
1353 case NL80211_IFTYPE_STATION:
1354 mode = P54_FILTER_TYPE_STATION;
1355 break;
1356 case NL80211_IFTYPE_AP:
1357 mode = P54_FILTER_TYPE_AP;
1358 break;
1359 case NL80211_IFTYPE_ADHOC:
1360 case NL80211_IFTYPE_MESH_POINT:
1361 mode = P54_FILTER_TYPE_IBSS;
1362 break;
1363 default:
1364 mode = P54_FILTER_TYPE_NONE;
1365 break;
1366 }
1367 if (priv->filter_flags & FIF_PROMISC_IN_BSS)
1368 mode |= P54_FILTER_TYPE_TRANSPARENT;
1369 } else
1370 mode = P54_FILTER_TYPE_RX_DISABLED;
1371
1351 setup->mac_mode = cpu_to_le16(mode); 1372 setup->mac_mode = cpu_to_le16(mode);
1352 memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN); 1373 memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
1353 if (!bssid) 1374 memcpy(setup->bssid, priv->bssid, ETH_ALEN);
1354 memset(setup->bssid, ~0, ETH_ALEN); 1375 setup->rx_antenna = 2; /* automatic */
1355 else
1356 memcpy(setup->bssid, bssid, ETH_ALEN);
1357 setup->rx_antenna = priv->rx_antenna;
1358 setup->rx_align = 0; 1376 setup->rx_align = 0;
1359 if (priv->fw_var < 0x500) { 1377 if (priv->fw_var < 0x500) {
1360 setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask); 1378 setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
@@ -1383,7 +1401,8 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid)
1383 return 0; 1401 return 0;
1384} 1402}
1385 1403
1386static int p54_set_freq(struct ieee80211_hw *dev, u16 frequency) 1404static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell,
1405 u16 frequency)
1387{ 1406{
1388 struct p54_common *priv = dev->priv; 1407 struct p54_common *priv = dev->priv;
1389 struct sk_buff *skb; 1408 struct sk_buff *skb;
@@ -1400,8 +1419,8 @@ static int p54_set_freq(struct ieee80211_hw *dev, u16 frequency)
1400 1419
1401 chan = (struct p54_scan *) skb_put(skb, sizeof(*chan)); 1420 chan = (struct p54_scan *) skb_put(skb, sizeof(*chan));
1402 memset(chan->padding1, 0, sizeof(chan->padding1)); 1421 memset(chan->padding1, 0, sizeof(chan->padding1));
1403 chan->mode = cpu_to_le16(P54_SCAN_EXIT); 1422 chan->mode = cpu_to_le16(mode);
1404 chan->dwell = cpu_to_le16(0x0); 1423 chan->dwell = cpu_to_le16(dwell);
1405 1424
1406 for (i = 0; i < priv->iq_autocal_len; i++) { 1425 for (i = 0; i < priv->iq_autocal_len; i++) {
1407 if (priv->iq_autocal[i].freq != freq) 1426 if (priv->iq_autocal[i].freq != freq)
@@ -1644,10 +1663,14 @@ static int p54_start(struct ieee80211_hw *dev)
1644 err = p54_init_stats(dev); 1663 err = p54_init_stats(dev);
1645 if (err) 1664 if (err)
1646 goto out; 1665 goto out;
1647 err = p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL); 1666
1648 if (err) 1667 memset(priv->bssid, ~0, ETH_ALEN);
1649 goto out;
1650 priv->mode = NL80211_IFTYPE_MONITOR; 1668 priv->mode = NL80211_IFTYPE_MONITOR;
1669 err = p54_setup_mac(dev);
1670 if (err) {
1671 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
1672 goto out;
1673 }
1651 1674
1652out: 1675out:
1653 mutex_unlock(&priv->conf_mutex); 1676 mutex_unlock(&priv->conf_mutex);
@@ -1700,27 +1723,8 @@ static int p54_add_interface(struct ieee80211_hw *dev,
1700 } 1723 }
1701 1724
1702 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); 1725 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
1703 1726 p54_setup_mac(dev);
1704 p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL);
1705
1706 switch (conf->type) {
1707 case NL80211_IFTYPE_STATION:
1708 p54_setup_mac(dev, P54_FILTER_TYPE_STATION, NULL);
1709 break;
1710 case NL80211_IFTYPE_AP:
1711 p54_setup_mac(dev, P54_FILTER_TYPE_AP, priv->mac_addr);
1712 break;
1713 case NL80211_IFTYPE_ADHOC:
1714 case NL80211_IFTYPE_MESH_POINT:
1715 p54_setup_mac(dev, P54_FILTER_TYPE_IBSS, NULL);
1716 break;
1717 default:
1718 BUG(); /* impossible */
1719 break;
1720 }
1721
1722 p54_set_leds(dev, 1, 0, 0); 1727 p54_set_leds(dev, 1, 0, 0);
1723
1724 mutex_unlock(&priv->conf_mutex); 1728 mutex_unlock(&priv->conf_mutex);
1725 return 0; 1729 return 0;
1726} 1730}
@@ -1733,9 +1737,10 @@ static void p54_remove_interface(struct ieee80211_hw *dev,
1733 mutex_lock(&priv->conf_mutex); 1737 mutex_lock(&priv->conf_mutex);
1734 if (priv->cached_beacon) 1738 if (priv->cached_beacon)
1735 p54_tx_cancel(dev, priv->cached_beacon); 1739 p54_tx_cancel(dev, priv->cached_beacon);
1736 p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL);
1737 priv->mode = NL80211_IFTYPE_MONITOR; 1740 priv->mode = NL80211_IFTYPE_MONITOR;
1738 memset(priv->mac_addr, 0, ETH_ALEN); 1741 memset(priv->mac_addr, 0, ETH_ALEN);
1742 memset(priv->bssid, 0, ETH_ALEN);
1743 p54_setup_mac(dev);
1739 mutex_unlock(&priv->conf_mutex); 1744 mutex_unlock(&priv->conf_mutex);
1740} 1745}
1741 1746
@@ -1746,11 +1751,21 @@ static int p54_config(struct ieee80211_hw *dev, u32 changed)
1746 struct ieee80211_conf *conf = &dev->conf; 1751 struct ieee80211_conf *conf = &dev->conf;
1747 1752
1748 mutex_lock(&priv->conf_mutex); 1753 mutex_lock(&priv->conf_mutex);
1749 priv->rx_antenna = 2; /* automatic */ 1754 if (changed & IEEE80211_CONF_CHANGE_POWER)
1750 priv->output_power = conf->power_level << 2; 1755 priv->output_power = conf->power_level << 2;
1751 ret = p54_set_freq(dev, conf->channel->center_freq); 1756 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
1752 if (!ret) 1757 ret = p54_setup_mac(dev);
1753 ret = p54_set_edcf(dev); 1758 if (ret)
1759 goto out;
1760 }
1761 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1762 ret = p54_scan(dev, P54_SCAN_EXIT, 0,
1763 conf->channel->center_freq);
1764 if (ret)
1765 goto out;
1766 }
1767
1768out:
1754 mutex_unlock(&priv->conf_mutex); 1769 mutex_unlock(&priv->conf_mutex);
1755 return ret; 1770 return ret;
1756} 1771}
@@ -1763,36 +1778,31 @@ static int p54_config_interface(struct ieee80211_hw *dev,
1763 int ret = 0; 1778 int ret = 0;
1764 1779
1765 mutex_lock(&priv->conf_mutex); 1780 mutex_lock(&priv->conf_mutex);
1766 switch (priv->mode) { 1781 if (conf->changed & IEEE80211_IFCC_BSSID) {
1767 case NL80211_IFTYPE_STATION: 1782 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
1768 ret = p54_setup_mac(dev, P54_FILTER_TYPE_STATION, conf->bssid); 1783 ret = p54_setup_mac(dev);
1769 if (ret) 1784 if (ret)
1770 goto out; 1785 goto out;
1771 ret = p54_set_leds(dev, 1, 1786 }
1772 !is_multicast_ether_addr(conf->bssid), 0); 1787
1788 if (conf->changed & IEEE80211_IFCC_BEACON) {
1789 ret = p54_scan(dev, P54_SCAN_EXIT, 0,
1790 dev->conf.channel->center_freq);
1773 if (ret) 1791 if (ret)
1774 goto out; 1792 goto out;
1775 memcpy(priv->bssid, conf->bssid, ETH_ALEN); 1793 ret = p54_setup_mac(dev);
1776 break;
1777 case NL80211_IFTYPE_AP:
1778 case NL80211_IFTYPE_ADHOC:
1779 case NL80211_IFTYPE_MESH_POINT:
1780 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
1781 ret = p54_set_freq(dev, dev->conf.channel->center_freq);
1782 if (ret) 1794 if (ret)
1783 goto out; 1795 goto out;
1784 ret = p54_setup_mac(dev, priv->mac_mode, priv->bssid); 1796 ret = p54_beacon_update(dev, vif);
1797 if (ret)
1798 goto out;
1799 ret = p54_set_edcf(dev);
1785 if (ret) 1800 if (ret)
1786 goto out; 1801 goto out;
1787 if (conf->changed & IEEE80211_IFCC_BEACON) {
1788 ret = p54_beacon_update(dev, vif);
1789 if (ret)
1790 goto out;
1791 ret = p54_set_edcf(dev);
1792 if (ret)
1793 goto out;
1794 }
1795 } 1802 }
1803
1804 ret = p54_set_leds(dev, 1, !is_multicast_ether_addr(priv->bssid), 0);
1805
1796out: 1806out:
1797 mutex_unlock(&priv->conf_mutex); 1807 mutex_unlock(&priv->conf_mutex);
1798 return ret; 1808 return ret;
@@ -1805,25 +1815,14 @@ static void p54_configure_filter(struct ieee80211_hw *dev,
1805{ 1815{
1806 struct p54_common *priv = dev->priv; 1816 struct p54_common *priv = dev->priv;
1807 1817
1808 *total_flags &= FIF_BCN_PRBRESP_PROMISC | 1818 *total_flags &= FIF_PROMISC_IN_BSS |
1809 FIF_PROMISC_IN_BSS | 1819 (*total_flags & FIF_PROMISC_IN_BSS) ?
1810 FIF_FCSFAIL; 1820 FIF_FCSFAIL : 0;
1811 1821
1812 priv->filter_flags = *total_flags; 1822 priv->filter_flags = *total_flags;
1813 1823
1814 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { 1824 if (changed_flags & FIF_PROMISC_IN_BSS)
1815 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) 1825 p54_setup_mac(dev);
1816 p54_setup_mac(dev, priv->mac_mode, NULL);
1817 else
1818 p54_setup_mac(dev, priv->mac_mode, priv->bssid);
1819 }
1820
1821 if (changed_flags & FIF_PROMISC_IN_BSS) {
1822 if (*total_flags & FIF_PROMISC_IN_BSS)
1823 p54_setup_mac(dev, priv->mac_mode | 0x8, NULL);
1824 else
1825 p54_setup_mac(dev, priv->mac_mode & ~0x8, priv->bssid);
1826 }
1827} 1826}
1828 1827
1829static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue, 1828static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
@@ -1920,16 +1919,17 @@ static void p54_bss_info_changed(struct ieee80211_hw *dev,
1920 priv->basic_rate_mask = (info->basic_rates << 4); 1919 priv->basic_rate_mask = (info->basic_rates << 4);
1921 else 1920 else
1922 priv->basic_rate_mask = info->basic_rates; 1921 priv->basic_rate_mask = info->basic_rates;
1923 p54_setup_mac(dev, priv->mac_mode, priv->bssid); 1922 p54_setup_mac(dev);
1924 if (priv->fw_var >= 0x500) 1923 if (priv->fw_var >= 0x500)
1925 p54_set_freq(dev, dev->conf.channel->center_freq); 1924 p54_scan(dev, P54_SCAN_EXIT, 0,
1925 dev->conf.channel->center_freq);
1926 } 1926 }
1927 if (changed & BSS_CHANGED_ASSOC) { 1927 if (changed & BSS_CHANGED_ASSOC) {
1928 if (info->assoc) { 1928 if (info->assoc) {
1929 priv->aid = info->aid; 1929 priv->aid = info->aid;
1930 priv->wakeup_timer = info->beacon_int * 1930 priv->wakeup_timer = info->beacon_int *
1931 info->dtim_period * 5; 1931 info->dtim_period * 5;
1932 p54_setup_mac(dev, priv->mac_mode, priv->bssid); 1932 p54_setup_mac(dev);
1933 } 1933 }
1934 } 1934 }
1935 1935