b43: Workaround DMA quirks
[safe/jmp/linux-2.6] / drivers / net / wireless / ipw2100.c
index 9137a4d..5bf9e00 100644 (file)
@@ -28,8 +28,8 @@
 
   Portions of this file are based on the Host AP project,
   Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
-    <jkmaline@cc.hut.fi>
-  Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
+    <j@w1.fi>
+  Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
 
   Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
   ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
@@ -162,7 +162,7 @@ that only one external action is invoked at a time.
 #include <linux/firmware.h>
 #include <linux/acpi.h>
 #include <linux/ctype.h>
-#include <linux/latency.h>
+#include <linux/pm_qos_params.h>
 
 #include "ipw2100.h"
 
@@ -1267,7 +1267,7 @@ static int ipw2100_start_adapter(struct ipw2100_priv *priv)
                                       IPW2100_INTA_FATAL_ERROR |
                                       IPW2100_INTA_PARITY_ERROR);
                }
-       } while (i--);
+       } while (--i);
 
        /* Clear out any pending INTAs since we aren't supposed to have
         * interrupts enabled at this point... */
@@ -1339,7 +1339,7 @@ static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
 
                if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
                        break;
-       } while (i--);
+       } while (--i);
 
        priv->status &= ~STATUS_RESET_PENDING;
 
@@ -1701,7 +1701,7 @@ static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
        /* the ipw2100 hardware really doesn't want power management delays
         * longer than 175usec
         */
-       modify_acceptable_latency("ipw2100", 175);
+       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", 175);
 
        /* If the interrupt is enabled, turn it off... */
        spin_lock_irqsave(&priv->low_lock, flags);
@@ -1768,7 +1768,8 @@ static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
 
                if (priv->stop_rf_kill) {
                        priv->stop_rf_kill = 0;
-                       queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
+                       queue_delayed_work(priv->workqueue, &priv->rf_kill,
+                                          round_jiffies_relative(HZ));
                }
 
                deferred = 1;
@@ -1855,15 +1856,8 @@ static void ipw2100_down(struct ipw2100_priv *priv)
        ipw2100_disable_interrupts(priv);
        spin_unlock_irqrestore(&priv->low_lock, flags);
 
-       modify_acceptable_latency("ipw2100", INFINITE_LATENCY);
-
-#ifdef ACPI_CSTATE_LIMIT_DEFINED
-       if (priv->config & CFG_C3_DISABLED) {
-               IPW_DEBUG_INFO(": Resetting C3 transitions.\n");
-               acpi_set_cstate_limit(priv->cstate_limit);
-               priv->config &= ~CFG_C3_DISABLED;
-       }
-#endif
+       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
+                       PM_QOS_DEFAULT_VALUE);
 
        /* We have to signal any supplicant if we are disassociating */
        if (associated)
@@ -1921,6 +1915,7 @@ static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
        u32 chan;
        char *txratename;
        u8 bssid[ETH_ALEN];
+       DECLARE_MAC_BUF(mac);
 
        /*
         * TBD: BSSID is usually 00:00:00:00:00:00 here and not
@@ -1982,9 +1977,9 @@ static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
        }
 
        IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
-                      MAC_FMT ")\n",
+                      "%s)\n",
                       priv->net_dev->name, escape_essid(essid, essid_len),
-                      txratename, chan, MAC_ARG(bssid));
+                      txratename, chan, print_mac(mac, bssid));
 
        /* now we copy read ssid into dev */
        if (!(priv->config & CFG_STATIC_ESSID)) {
@@ -2052,10 +2047,12 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
 
 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
 {
+       DECLARE_MAC_BUF(mac);
+
        IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
-                 "disassociated: '%s' " MAC_FMT " \n",
+                 "disassociated: '%s' %s \n",
                  escape_essid(priv->essid, priv->essid_len),
-                 MAC_ARG(priv->bssid));
+                 print_mac(mac, priv->bssid));
 
        priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
 
@@ -2087,18 +2084,33 @@ static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
        /* RF_KILL is now enabled (else we wouldn't be here) */
        priv->status |= STATUS_RF_KILL_HW;
 
-#ifdef ACPI_CSTATE_LIMIT_DEFINED
-       if (priv->config & CFG_C3_DISABLED) {
-               IPW_DEBUG_INFO(": Resetting C3 transitions.\n");
-               acpi_set_cstate_limit(priv->cstate_limit);
-               priv->config &= ~CFG_C3_DISABLED;
-       }
-#endif
-
        /* Make sure the RF Kill check timer is running */
        priv->stop_rf_kill = 0;
        cancel_delayed_work(&priv->rf_kill);
-       queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
+       queue_delayed_work(priv->workqueue, &priv->rf_kill,
+                          round_jiffies_relative(HZ));
+}
+
+static void send_scan_event(void *data)
+{
+       struct ipw2100_priv *priv = data;
+       union iwreq_data wrqu;
+
+       wrqu.data.length = 0;
+       wrqu.data.flags = 0;
+       wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
+}
+
+static void ipw2100_scan_event_later(struct work_struct *work)
+{
+       send_scan_event(container_of(work, struct ipw2100_priv,
+                                       scan_event_later.work));
+}
+
+static void ipw2100_scan_event_now(struct work_struct *work)
+{
+       send_scan_event(container_of(work, struct ipw2100_priv,
+                                       scan_event_now));
 }
 
 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
@@ -2107,6 +2119,18 @@ static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
        /* Age the scan results... */
        priv->ieee->scans++;
        priv->status &= ~STATUS_SCANNING;
+
+       /* Only userspace-requested scan completion events go out immediately */
+       if (!priv->user_requested_scan) {
+               if (!delayed_work_pending(&priv->scan_event_later))
+                       queue_delayed_work(priv->workqueue,
+                                       &priv->scan_event_later,
+                                       round_jiffies_relative(msecs_to_jiffies(4000)));
+       } else {
+               priv->user_requested_scan = 0;
+               cancel_delayed_work(&priv->scan_event_later);
+               queue_work(priv->workqueue, &priv->scan_event_now);
+       }
 }
 
 #ifdef CONFIG_IPW2100_DEBUG
@@ -2325,23 +2349,10 @@ static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
        u32 match, reg;
        int j;
 #endif
-#ifdef ACPI_CSTATE_LIMIT_DEFINED
-       int limit;
-#endif
 
        IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
                       i * sizeof(struct ipw2100_status));
 
-#ifdef ACPI_CSTATE_LIMIT_DEFINED
-       IPW_DEBUG_INFO(": Disabling C3 transitions.\n");
-       limit = acpi_get_cstate_limit();
-       if (limit > 2) {
-               priv->cstate_limit = limit;
-               acpi_set_cstate_limit(2);
-               priv->config |= CFG_C3_DISABLED;
-       }
-#endif
-
 #ifdef IPW2100_DEBUG_C3
        /* Halt the fimrware so we can get a good image */
        write_register(priv->net_dev, IPW_REG_RESET_REG,
@@ -2499,9 +2510,9 @@ static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
 
        ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
        ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
-       ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total hdr+data */
+       ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */
 
-       ipw_rt->rt_hdr.it_present = 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL;
+       ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
 
        ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
 
@@ -2548,7 +2559,7 @@ static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
 #ifdef CONFIG_IPW2100_MONITOR
                return 0;
 #else
-               switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
+               switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
                case IEEE80211_FTYPE_MGMT:
                case IEEE80211_FTYPE_CTL:
                        return 0;
@@ -2667,7 +2678,7 @@ static void __ipw2100_rx_process(struct ipw2100_priv *priv)
 #endif
                        if (stats.len < sizeof(struct ieee80211_hdr_3addr))
                                break;
-                       switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
+                       switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
                        case IEEE80211_FTYPE_MGMT:
                                ieee80211_rx_mgt(priv->ieee,
                                                 &u->rx_data.header, &stats);
@@ -4048,6 +4059,7 @@ static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
        char *out = buf;
        int length;
        int ret;
+       DECLARE_MAC_BUF(mac);
 
        if (priv->status & STATUS_RF_KILL_MASK)
                return 0;
@@ -4075,9 +4087,7 @@ static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
                               __LINE__);
 
        out += sprintf(out, "ESSID: %s\n", essid);
-       out += sprintf(out, "BSSID:   %02x:%02x:%02x:%02x:%02x:%02x\n",
-                      bssid[0], bssid[1], bssid[2],
-                      bssid[3], bssid[4], bssid[5]);
+       out += sprintf(out, "BSSID:   %s\n", print_mac(mac, bssid));
        out += sprintf(out, "Channel: %d\n", chan);
 
        return out - buf;
@@ -4233,7 +4243,8 @@ static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
                        /* Make sure the RF_KILL check timer is running */
                        priv->stop_rf_kill = 0;
                        cancel_delayed_work(&priv->rf_kill);
-                       queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
+                       queue_delayed_work(priv->workqueue, &priv->rf_kill,
+                                          round_jiffies_relative(HZ));
                } else
                        schedule_reset(priv);
        }
@@ -4374,6 +4385,7 @@ static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
                cancel_delayed_work(&priv->wx_event_work);
                cancel_delayed_work(&priv->hang_check);
                cancel_delayed_work(&priv->rf_kill);
+               cancel_delayed_work(&priv->scan_event_later);
                destroy_workqueue(priv->workqueue);
                priv->workqueue = NULL;
        }
@@ -4650,19 +4662,20 @@ static void ipw2100_rx_free(struct ipw2100_priv *priv)
 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
 {
        u32 length = ETH_ALEN;
-       u8 mac[ETH_ALEN];
+       u8 addr[ETH_ALEN];
+       DECLARE_MAC_BUF(mac);
 
        int err;
 
-       err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, mac, &length);
+       err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length);
        if (err) {
                IPW_DEBUG_INFO("MAC address read failed\n");
                return -EIO;
        }
-       IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
-                      mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 
-       memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
+       memcpy(priv->net_dev->dev_addr, addr, ETH_ALEN);
+       IPW_DEBUG_INFO("card MAC is %s\n",
+                      print_mac(mac, priv->net_dev->dev_addr));
 
        return 0;
 }
@@ -5041,10 +5054,10 @@ static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
        int err;
 
 #ifdef CONFIG_IPW2100_DEBUG
+       DECLARE_MAC_BUF(mac);
        if (bssid != NULL)
-               IPW_DEBUG_HC("MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
-                            bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
-                            bssid[5]);
+               IPW_DEBUG_HC("MANDATORY_BSSID: %s\n",
+                            print_mac(mac, bssid));
        else
                IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
 #endif
@@ -5969,7 +5982,8 @@ static void ipw2100_rf_kill(struct work_struct *work)
        if (rf_kill_active(priv)) {
                IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
                if (!priv->stop_rf_kill)
-                       queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
+                       queue_delayed_work(priv->workqueue, &priv->rf_kill,
+                                          round_jiffies_relative(HZ));
                goto exit_unlock;
        }
 
@@ -6035,7 +6049,7 @@ static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
         * ends up causing problems.  So, we just handle
         * the WX extensions through the ipw2100_ioctl interface */
 
-       /* memset() puts everything to 0, so we only have explicitely set
+       /* memset() puts everything to 0, so we only have explicitly set
         * those values that need to be something else */
 
        /* If power management is turned on, default to AUTO mode */
@@ -6115,6 +6129,8 @@ static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
        INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work);
        INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check);
        INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill);
+       INIT_WORK(&priv->scan_event_now, ipw2100_scan_event_now);
+       INIT_DELAYED_WORK(&priv->scan_event_later, ipw2100_scan_event_later);
 
        tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
                     ipw2100_irq_tasklet, (unsigned long)priv);
@@ -6236,8 +6252,6 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
 
        IPW_DEBUG_INFO("Attempting to register device...\n");
 
-       SET_MODULE_OWNER(dev);
-
        printk(KERN_INFO DRV_NAME
               ": Detected Intel PRO/Wireless 2100 Network Connection\n");
 
@@ -6541,7 +6555,8 @@ static int __init ipw2100_init(void)
        if (ret)
                goto out;
 
-       set_acceptable_latency("ipw2100", INFINITE_LATENCY);
+       pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
+                       PM_QOS_DEFAULT_VALUE);
 #ifdef CONFIG_IPW2100_DEBUG
        ipw2100_debug_level = debug;
        ret = driver_create_file(&ipw2100_pci_driver.driver,
@@ -6563,7 +6578,7 @@ static void __exit ipw2100_exit(void)
                           &driver_attr_debug_level);
 #endif
        pci_unregister_driver(&ipw2100_pci_driver);
-       remove_acceptable_latency("ipw2100");
+       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100");
 }
 
 module_init(ipw2100_init);
@@ -6578,8 +6593,7 @@ static const long ipw2100_frequencies[] = {
        2472, 2484
 };
 
-#define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
-                    sizeof(ipw2100_frequencies[0]))
+#define FREQ_COUNT     ARRAY_SIZE(ipw2100_frequencies)
 
 static const long ipw2100_rates_11b[] = {
        1000000,
@@ -6891,6 +6905,7 @@ static int ipw2100_wx_set_wap(struct net_device *dev,
        static const unsigned char off[] = {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        };
+       DECLARE_MAC_BUF(mac);
 
        // sanity checks
        if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
@@ -6916,13 +6931,8 @@ static int ipw2100_wx_set_wap(struct net_device *dev,
 
        err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
 
-       IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
-                    wrqu->ap_addr.sa_data[0] & 0xff,
-                    wrqu->ap_addr.sa_data[1] & 0xff,
-                    wrqu->ap_addr.sa_data[2] & 0xff,
-                    wrqu->ap_addr.sa_data[3] & 0xff,
-                    wrqu->ap_addr.sa_data[4] & 0xff,
-                    wrqu->ap_addr.sa_data[5] & 0xff);
+       IPW_DEBUG_WX("SET BSSID -> %s\n",
+                    print_mac(mac, wrqu->ap_addr.sa_data));
 
       done:
        mutex_unlock(&priv->action_mutex);
@@ -6938,6 +6948,7 @@ static int ipw2100_wx_get_wap(struct net_device *dev,
         */
 
        struct ipw2100_priv *priv = ieee80211_priv(dev);
+       DECLARE_MAC_BUF(mac);
 
        /* If we are associated, trying to associate, or have a statically
         * configured BSSID then return that; otherwise return ANY */
@@ -6947,8 +6958,8 @@ static int ipw2100_wx_get_wap(struct net_device *dev,
        } else
                memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
 
-       IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
-                    MAC_ARG(wrqu->ap_addr.sa_data));
+       IPW_DEBUG_WX("Getting WAP BSSID: %s\n",
+                    print_mac(mac, wrqu->ap_addr.sa_data));
        return 0;
 }
 
@@ -7424,6 +7435,8 @@ static int ipw2100_wx_set_scan(struct net_device *dev,
        }
 
        IPW_DEBUG_WX("Initiating scan...\n");
+
+       priv->user_requested_scan = 1;
        if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
                IPW_DEBUG_WX("Start scan failed.\n");
 
@@ -7498,7 +7511,7 @@ static int ipw2100_wx_set_power(struct net_device *dev,
        switch (wrqu->power.flags & IW_POWER_MODE) {
        case IW_POWER_ON:       /* If not specified */
        case IW_POWER_MODE:     /* If set all mask */
-       case IW_POWER_ALL_R:    /* If explicitely state all */
+       case IW_POWER_ALL_R:    /* If explicitly state all */
                break;
        default:                /* Otherwise we don't support it */
                IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
@@ -7784,7 +7797,7 @@ static int ipw2100_wx_set_mlme(struct net_device *dev,
 {
        struct ipw2100_priv *priv = ieee80211_priv(dev);
        struct iw_mlme *mlme = (struct iw_mlme *)extra;
-       u16 reason;
+       __le16 reason;
 
        reason = cpu_to_le16(mlme->reason_code);
 
@@ -7865,10 +7878,10 @@ static int ipw2100_wx_set_powermode(struct net_device *dev,
                goto done;
        }
 
-       if ((mode < 1) || (mode > POWER_MODES))
+       if ((mode < 0) || (mode > POWER_MODES))
                mode = IPW_POWER_AUTO;
 
-       if (priv->power_mode != mode)
+       if (IPW_POWER_LEVEL(priv->power_mode) != mode)
                err = ipw2100_set_power_mode(priv, mode);
       done:
        mutex_unlock(&priv->action_mutex);
@@ -7899,7 +7912,7 @@ static int ipw2100_wx_get_powermode(struct net_device *dev,
                        break;
                case IPW_POWER_AUTO:
                        snprintf(extra, MAX_POWER_STRING,
-                                "Power save level: %d (Auto)", 0);
+                                "Power save level: %d (Auto)", level);
                        break;
                default:
                        timeout = timeout_duration[level - 1] / 1000;
@@ -8276,10 +8289,9 @@ static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
 
 static struct iw_handler_def ipw2100_wx_handler_def = {
        .standard = ipw2100_wx_handlers,
-       .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
-       .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
-       .num_private_args = sizeof(ipw2100_private_args) /
-           sizeof(struct iw_priv_args),
+       .num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
+       .num_private = ARRAY_SIZE(ipw2100_private_handler),
+       .num_private_args = ARRAY_SIZE(ipw2100_private_args),
        .private = (iw_handler *) ipw2100_private_handler,
        .private_args = (struct iw_priv_args *)ipw2100_private_args,
        .get_wireless_stats = ipw2100_wx_wireless_stats,