]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/ps3_gelic_wireless.c
bnx2x: New statistics code
[linux-2.6-omap-h63xx.git] / drivers / net / ps3_gelic_wireless.c
index e5e02339a5cc32aa929a5154a15abe610f5b3610..aa963ac1e37b2086bc677724664f7a7368bef3d0 100644 (file)
@@ -45,7 +45,8 @@
 #include "ps3_gelic_wireless.h"
 
 
-static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan);
+static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
+                              u8 *essid, size_t essid_len);
 static int gelic_wl_try_associate(struct net_device *netdev);
 
 /*
@@ -105,6 +106,7 @@ static const struct eurus_cmd_arg_info cmd_info[GELIC_EURUS_CMD_MAX_INDEX] = {
        [GELIC_EURUS_CMD_GET_WEP_CFG]    = { .post_arg = 1},
        [GELIC_EURUS_CMD_GET_WPA_CFG]    = { .post_arg = 1},
        [GELIC_EURUS_CMD_GET_RSSI_CFG]   = { .post_arg = 1},
+       [GELIC_EURUS_CMD_START_SCAN]     = { .pre_arg = 1},
        [GELIC_EURUS_CMD_GET_SCAN]       = { .post_arg = 1},
 };
 
@@ -163,7 +165,9 @@ static void gelic_eurus_sync_cmd_worker(struct work_struct *work)
        card = port_to_card(wl_port(wl));
 
        if (cmd_info[cmd->cmd].pre_arg) {
-               arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
+               arg1 = (cmd->buffer) ?
+                       ps3_mm_phys_to_lpar(__pa(cmd->buffer)) :
+                       0;
                arg2 = cmd->buf_size;
        } else {
                arg1 = 0;
@@ -350,7 +354,8 @@ static int gelic_wl_get_range(struct net_device *netdev,
 
        /* encryption capability */
        range->enc_capa = IW_ENC_CAPA_WPA |
-               IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
+               IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP |
+               IW_ENC_CAPA_4WAY_HANDSHAKE;
        if (wpa2_capable())
                range->enc_capa |= IW_ENC_CAPA_WPA2;
        range->encoding_size[0] = 5;    /* 40bit WEP */
@@ -359,6 +364,9 @@ static int gelic_wl_get_range(struct net_device *netdev,
        range->num_encoding_sizes = 3;
        range->max_encoding_tokens = GELIC_WEP_KEYS;
 
+       /* scan capability */
+       range->scan_capa = IW_SCAN_CAPA_ESSID;
+
        pr_debug("%s: ->\n", __func__);
        return 0;
 
@@ -370,8 +378,18 @@ static int gelic_wl_set_scan(struct net_device *netdev,
                           union iwreq_data *wrqu, char *extra)
 {
        struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
-
-       return gelic_wl_start_scan(wl, 1);
+       struct iw_scan_req *req;
+       u8 *essid = NULL;
+       size_t essid_len = 0;
+
+       if (wrqu->data.length == sizeof(struct iw_scan_req) &&
+           wrqu->data.flags & IW_SCAN_THIS_ESSID) {
+               req = (struct iw_scan_req*)extra;
+               essid = req->essid;
+               essid_len = req->essid_len;
+               pr_debug("%s: ESSID scan =%s\n", __func__, essid);
+       }
+       return gelic_wl_start_scan(wl, 1, essid, essid_len);
 }
 
 #define OUI_LEN 3
@@ -1256,42 +1274,19 @@ static int gelic_wl_set_encodeext(struct net_device *netdev,
                set_bit(key_index, &wl->key_enabled);
                /* remember wep info changed */
                set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
-       } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
-               pr_debug("%s: TKIP/CCMP requested alg=%d\n", __func__, alg);
-               /* check key length */
-               if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
-                       pr_info("%s: key is too long %d\n", __func__,
-                               ext->key_len);
+       } else if (alg == IW_ENCODE_ALG_PMK) {
+               if (ext->key_len != WPA_PSK_LEN) {
+                       pr_err("%s: PSK length wrong %d\n", __func__,
+                              ext->key_len);
                        ret = -EINVAL;
                        goto done;
                }
-               if (alg == IW_ENCODE_ALG_CCMP) {
-                       pr_debug("%s: AES selected\n", __func__);
-                       wl->group_cipher_method = GELIC_WL_CIPHER_AES;
-                       wl->pairwise_cipher_method = GELIC_WL_CIPHER_AES;
-                       wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
-               } else {
-                       pr_debug("%s: TKIP selected, WPA forced\n", __func__);
-                       wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
-                       wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
-                       /* FIXME: how do we do if WPA2 + TKIP? */
-                       wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
-               }
-               if (flags & IW_ENCODE_RESTRICTED)
-                       BUG();
-               wl->auth_method = GELIC_EURUS_AUTH_OPEN;
-               /* We should use same key for both and unicast */
-               if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
-                       pr_debug("%s: group key \n", __func__);
-               else
-                       pr_debug("%s: unicast key \n", __func__);
-               /* OK, update the key */
-               wl->key_len[key_index] = ext->key_len;
-               memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
-               memcpy(wl->key[key_index], ext->key, ext->key_len);
-               set_bit(key_index, &wl->key_enabled);
-               /* remember info changed */
-               set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
+               memset(wl->psk, 0, sizeof(wl->psk));
+               memcpy(wl->psk, ext->key, ext->key_len);
+               wl->psk_len = ext->key_len;
+               wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
+               /* remember PSK configured */
+               set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
        }
 done:
        spin_unlock_irqrestore(&wl->lock, irqflag);
@@ -1397,6 +1392,7 @@ static int gelic_wl_get_mode(struct net_device *netdev,
        return 0;
 }
 
+#ifdef CONFIG_GELIC_WIRELESS_OLD_PSK_INTERFACE
 /* SIOCIWFIRSTPRIV */
 static int hex2bin(u8 *str, u8 *bin, unsigned int len)
 {
@@ -1501,6 +1497,7 @@ static int gelic_wl_priv_get_psk(struct net_device *net_dev,
        pr_debug("%s:-> %d\n", __func__, data->data.length);
        return 0;
 }
+#endif
 
 /* SIOCGIWNICKN */
 static int gelic_wl_get_nick(struct net_device *net_dev,
@@ -1524,15 +1521,20 @@ static struct iw_statistics *gelic_wl_get_wireless_stats(
        struct gelic_eurus_cmd *cmd;
        struct iw_statistics *is;
        struct gelic_eurus_rssi_info *rssi;
+       void *buf;
 
        pr_debug("%s: <-\n", __func__);
 
+       buf = (void *)__get_free_page(GFP_KERNEL);
+       if (!buf)
+               return NULL;
+
        is = &wl->iwstat;
        memset(is, 0, sizeof(*is));
        cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_RSSI_CFG,
-                                  wl->buf, sizeof(*rssi));
+                                  buf, sizeof(*rssi));
        if (cmd && !cmd->status && !cmd->cmd_status) {
-               rssi = wl->buf;
+               rssi = buf;
                is->qual.level = be16_to_cpu(rssi->rssi);
                is->qual.updated = IW_QUAL_LEVEL_UPDATED |
                        IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
@@ -1541,6 +1543,7 @@ static struct iw_statistics *gelic_wl_get_wireless_stats(
                is->qual.updated = IW_QUAL_ALL_INVALID;
 
        kfree(cmd);
+       free_page((unsigned long)buf);
        pr_debug("%s: ->\n", __func__);
        return is;
 }
@@ -1548,10 +1551,13 @@ static struct iw_statistics *gelic_wl_get_wireless_stats(
 /*
  *  scanning helpers
  */
-static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan)
+static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
+                              u8 *essid, size_t essid_len)
 {
        struct gelic_eurus_cmd *cmd;
        int ret = 0;
+       void *buf = NULL;
+       size_t len;
 
        pr_debug("%s: <- always=%d\n", __func__, always_scan);
        if (mutex_lock_interruptible(&wl->scan_lock))
@@ -1574,12 +1580,27 @@ static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan)
                complete(&wl->scan_done);
                goto out;
        }
+
+       /* ESSID scan ? */
+       if (essid_len && essid) {
+               buf = (void *)__get_free_page(GFP_KERNEL);
+               if (!buf) {
+                       ret = -ENOMEM;
+                       goto out;
+               }
+               len = IW_ESSID_MAX_SIZE; /* hypervisor always requires 32 */
+               memset(buf, 0, len);
+               memcpy(buf, essid, essid_len);
+               pr_debug("%s: essid scan='%s'\n", __func__, (char *)buf);
+       } else
+               len = 0;
+
        /*
         * issue start scan request
         */
        wl->scan_stat = GELIC_WL_SCAN_STAT_SCANNING;
        cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_START_SCAN,
-                                  NULL, 0);
+                                  buf, len);
        if (!cmd || cmd->status || cmd->cmd_status) {
                wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
                complete(&wl->scan_done);
@@ -1588,6 +1609,7 @@ static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan)
        }
        kfree(cmd);
 out:
+       free_page((unsigned long)buf);
        mutex_unlock(&wl->scan_lock);
        pr_debug("%s: ->\n", __func__);
        return ret;
@@ -1607,11 +1629,18 @@ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
        union iwreq_data data;
        unsigned long this_time = jiffies;
        unsigned int data_len, i, found, r;
+       void *buf;
        DECLARE_MAC_BUF(mac);
 
        pr_debug("%s:start\n", __func__);
        mutex_lock(&wl->scan_lock);
 
+       buf = (void *)__get_free_page(GFP_KERNEL);
+       if (!buf) {
+               pr_info("%s: scan buffer alloc failed\n", __func__);
+               goto out;
+       }
+
        if (wl->scan_stat != GELIC_WL_SCAN_STAT_SCANNING) {
                /*
                 * stop() may be called while scanning, ignore result
@@ -1622,7 +1651,7 @@ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
        }
 
        cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_SCAN,
-                                  wl->buf, PAGE_SIZE);
+                                  buf, PAGE_SIZE);
        if (!cmd || cmd->status || cmd->cmd_status) {
                wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
                pr_info("%s:cmd failed\n", __func__);
@@ -1649,7 +1678,7 @@ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
        }
 
        /* put them in the newtork_list */
-       for (i = 0, scan_info_size = 0, scan_info = wl->buf;
+       for (i = 0, scan_info_size = 0, scan_info = buf;
             scan_info_size < data_len;
             i++, scan_info_size += be16_to_cpu(scan_info->size),
             scan_info = (void *)scan_info + be16_to_cpu(scan_info->size)) {
@@ -1726,6 +1755,7 @@ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
        wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWSCAN, &data,
                            NULL);
 out:
+       free_page((unsigned long)buf);
        complete(&wl->scan_done);
        mutex_unlock(&wl->scan_lock);
        pr_debug("%s:end\n", __func__);
@@ -1848,7 +1878,10 @@ static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
 
        pr_debug("%s: <-\n", __func__);
        /* we can assume no one should uses the buffer */
-       wep = wl->buf;
+       wep = (struct gelic_eurus_wep_cfg *)__get_free_page(GFP_KERNEL);
+       if (!wep)
+               return -ENOMEM;
+
        memset(wep, 0, sizeof(*wep));
 
        if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
@@ -1898,6 +1931,7 @@ static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
 
        kfree(cmd);
 out:
+       free_page((unsigned long)wep);
        pr_debug("%s: ->\n", __func__);
        return ret;
 }
@@ -1941,7 +1975,10 @@ static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
 
        pr_debug("%s: <-\n", __func__);
        /* we can assume no one should uses the buffer */
-       wpa = wl->buf;
+       wpa = (struct gelic_eurus_wpa_cfg *)__get_free_page(GFP_KERNEL);
+       if (!wpa)
+               return -ENOMEM;
+
        memset(wpa, 0, sizeof(*wpa));
 
        if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat))
@@ -2000,6 +2037,7 @@ static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
        else if (cmd->status || cmd->cmd_status)
                ret = -ENXIO;
        kfree(cmd);
+       free_page((unsigned long)wpa);
        pr_debug("%s: --> %d\n", __func__, ret);
        return ret;
 }
@@ -2018,7 +2056,10 @@ static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
        pr_debug("%s: <-\n", __func__);
 
        /* do common config */
-       common = wl->buf;
+       common = (struct gelic_eurus_common_cfg *)__get_free_page(GFP_KERNEL);
+       if (!common)
+               return -ENOMEM;
+
        memset(common, 0, sizeof(*common));
        common->bss_type = cpu_to_be16(GELIC_EURUS_BSS_INFRA);
        common->op_mode = cpu_to_be16(GELIC_EURUS_OPMODE_11BG);
@@ -2104,6 +2145,7 @@ static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
                pr_info("%s: connected\n", __func__);
        }
 out:
+       free_page((unsigned long)common);
        pr_debug("%s: ->\n", __func__);
        return ret;
 }
@@ -2255,6 +2297,9 @@ static void gelic_wl_assoc_worker(struct work_struct *work)
 
        struct gelic_wl_scan_info *best_bss;
        int ret;
+       unsigned long irqflag;
+       u8 *essid;
+       size_t essid_len;
 
        wl = container_of(work, struct gelic_wl_info, assoc_work.work);
 
@@ -2263,7 +2308,19 @@ static void gelic_wl_assoc_worker(struct work_struct *work)
        if (wl->assoc_stat != GELIC_WL_ASSOC_STAT_DISCONN)
                goto out;
 
-       ret = gelic_wl_start_scan(wl, 0);
+       spin_lock_irqsave(&wl->lock, irqflag);
+       if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
+               pr_debug("%s: assoc ESSID configured %s\n", __func__,
+                        wl->essid);
+               essid = wl->essid;
+               essid_len = wl->essid_len;
+       } else {
+               essid = NULL;
+               essid_len = 0;
+       }
+       spin_unlock_irqrestore(&wl->lock, irqflag);
+
+       ret = gelic_wl_start_scan(wl, 0, essid, essid_len);
        if (ret == -ERESTARTSYS) {
                pr_debug("%s: scan start failed association\n", __func__);
                schedule_delayed_work(&wl->assoc_work, HZ/10); /*FIXME*/
@@ -2351,6 +2408,7 @@ static const iw_handler gelic_wl_wext_handler[] =
        IW_IOCTL(SIOCGIWNICKN)          = gelic_wl_get_nick,
 };
 
+#ifdef CONFIG_GELIC_WIRELESS_OLD_PSK_INTERFACE
 static struct iw_priv_args gelic_wl_private_args[] =
 {
        {
@@ -2372,15 +2430,18 @@ static const iw_handler gelic_wl_private_handler[] =
        gelic_wl_priv_set_psk,
        gelic_wl_priv_get_psk,
 };
+#endif
 
 static const struct iw_handler_def gelic_wl_wext_handler_def = {
        .num_standard           = ARRAY_SIZE(gelic_wl_wext_handler),
        .standard               = gelic_wl_wext_handler,
        .get_wireless_stats     = gelic_wl_get_wireless_stats,
+#ifdef CONFIG_GELIC_WIRELESS_OLD_PSK_INTERFACE
        .num_private            = ARRAY_SIZE(gelic_wl_private_handler),
        .num_private_args       = ARRAY_SIZE(gelic_wl_private_args),
        .private                = gelic_wl_private_handler,
        .private_args           = gelic_wl_private_args,
+#endif
 };
 
 static struct net_device *gelic_wl_alloc(struct gelic_card *card)
@@ -2446,16 +2507,9 @@ static struct net_device *gelic_wl_alloc(struct gelic_card *card)
        BUILD_BUG_ON(PAGE_SIZE <
                     sizeof(struct gelic_eurus_scan_info) *
                     GELIC_EURUS_MAX_SCAN);
-       wl->buf = (void *)get_zeroed_page(GFP_KERNEL);
-       if (!wl->buf) {
-               pr_info("%s:buffer allocation failed\n", __func__);
-               goto fail_getpage;
-       }
        pr_debug("%s:end\n", __func__);
        return netdev;
 
-fail_getpage:
-       destroy_workqueue(wl->event_queue);
 fail_event_workqueue:
        destroy_workqueue(wl->eurus_cmd_queue);
 fail_cmd_workqueue:
@@ -2474,8 +2528,6 @@ static void gelic_wl_free(struct gelic_wl_info *wl)
 
        pr_debug("%s: <-\n", __func__);
 
-       free_page((unsigned long)wl->buf);
-
        pr_debug("%s: destroy queues\n", __func__);
        destroy_workqueue(wl->eurus_cmd_queue);
        destroy_workqueue(wl->event_queue);