]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/ipw2200.c
ath5k: Misc fixes/cleanups
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / ipw2200.c
index 7ac57f1fc18b637564e52e657cb91e91e9df9001..fa87c5c2ae0bf9d8fe1937965dc09750387f52ba 100644 (file)
@@ -2352,27 +2352,13 @@ static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
 static int ipw_send_associate(struct ipw_priv *priv,
                              struct ipw_associate *associate)
 {
-       struct ipw_associate tmp_associate;
-
        if (!priv || !associate) {
                IPW_ERROR("Invalid args\n");
                return -1;
        }
 
-       memcpy(&tmp_associate, associate, sizeof(*associate));
-       tmp_associate.policy_support =
-           cpu_to_le16(tmp_associate.policy_support);
-       tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
-       tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
-       tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
-       tmp_associate.listen_interval =
-           cpu_to_le16(tmp_associate.listen_interval);
-       tmp_associate.beacon_interval =
-           cpu_to_le16(tmp_associate.beacon_interval);
-       tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
-
-       return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
-                               &tmp_associate);
+       return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
+                               associate);
 }
 
 static int ipw_send_supported_rates(struct ipw_priv *priv,
@@ -3379,7 +3365,6 @@ static void ipw_rx_queue_reset(struct ipw_priv *priv,
        /* Set us so that we have processed and used all buffers, but have
         * not restocked the Rx queue with fresh buffers */
        rxq->read = rxq->write = 0;
-       rxq->processed = RX_QUEUE_SIZE - 1;
        rxq->free_count = 0;
        spin_unlock_irqrestore(&rxq->lock, flags);
 }
@@ -3621,7 +3606,22 @@ static int ipw_load(struct ipw_priv *priv)
  * Driver allocates buffers of this size for Rx
  */
 
-static inline int ipw_queue_space(const struct clx2_queue *q)
+/**
+ * ipw_rx_queue_space - Return number of free slots available in queue.
+ */
+static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
+{
+       int s = q->read - q->write;
+       if (s <= 0)
+               s += RX_QUEUE_SIZE;
+       /* keep some buffer to not confuse full and empty queue */
+       s -= 2;
+       if (s < 0)
+               s = 0;
+       return s;
+}
+
+static inline int ipw_tx_queue_space(const struct clx2_queue *q)
 {
        int s = q->last_used - q->first_empty;
        if (s <= 0)
@@ -4168,7 +4168,7 @@ static void ipw_gather_stats(struct ipw_priv *priv)
        priv->last_missed_beacons = priv->missed_beacons;
        if (priv->assoc_request.beacon_interval) {
                missed_beacons_percent = missed_beacons_delta *
-                   (HZ * priv->assoc_request.beacon_interval) /
+                   (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
                    (IPW_STATS_INTERVAL * 10);
        } else {
                missed_beacons_percent = 0;
@@ -4432,9 +4432,9 @@ static void ipw_rx_notification(struct ipw_priv *priv,
                                                                   workqueue,
                                                                   &priv->
                                                                   adhoc_check,
-                                                                  priv->
+                                                                  le16_to_cpu(priv->
                                                                   assoc_request.
-                                                                  beacon_interval);
+                                                                  beacon_interval));
                                                break;
                                        }
 
@@ -4495,9 +4495,9 @@ static void ipw_rx_notification(struct ipw_priv *priv,
                                                                       priv->
                                                                       essid_len),
                                                          print_mac(mac, priv->bssid),
-                                                         ntohs(auth->status),
+                                                         le16_to_cpu(auth->status),
                                                          ipw_get_status_code
-                                                         (ntohs
+                                                         (le16_to_cpu
                                                           (auth->status)));
 
                                                priv->status &=
@@ -4532,9 +4532,9 @@ static void ipw_rx_notification(struct ipw_priv *priv,
                                                          IPW_DL_STATE |
                                                          IPW_DL_ASSOC,
                                                          "association failed (0x%04X): %s\n",
-                                                         ntohs(resp->status),
+                                                         le16_to_cpu(resp->status),
                                                          ipw_get_status_code
-                                                         (ntohs
+                                                         (le16_to_cpu
                                                           (resp->status)));
                                        }
 
@@ -4591,8 +4591,8 @@ static void ipw_rx_notification(struct ipw_priv *priv,
                                        IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
                                                  IPW_DL_ASSOC,
                                                  "authentication failed (0x%04X): %s\n",
-                                                 ntohs(auth->status),
-                                                 ipw_get_status_code(ntohs
+                                                 le16_to_cpu(auth->status),
+                                                 ipw_get_status_code(le16_to_cpu
                                                                      (auth->
                                                                       status)));
                                }
@@ -4961,7 +4961,7 @@ static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
                priv->tx_packets++;
        }
       done:
-       if ((ipw_queue_space(q) > q->low_mark) &&
+       if ((ipw_tx_queue_space(q) > q->low_mark) &&
            (qindex >= 0) &&
            (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
                netif_wake_queue(priv->net_dev);
@@ -4979,7 +4979,7 @@ static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
        struct clx2_queue *q = &txq->q;
        struct tfd_frame *tfd;
 
-       if (ipw_queue_space(q) < (sync ? 1 : 2)) {
+       if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
                IPW_ERROR("No space for Tx\n");
                return -EBUSY;
        }
@@ -5084,7 +5084,7 @@ static void ipw_rx_queue_restock(struct ipw_priv *priv)
 
        spin_lock_irqsave(&rxq->lock, flags);
        write = rxq->write;
-       while ((rxq->write != rxq->processed) && (rxq->free_count)) {
+       while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
                element = rxq->rx_free.next;
                rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
                list_del(element);
@@ -5201,7 +5201,6 @@ static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
        /* Set us so that we have processed and used all buffers, but have
         * not restocked the Rx queue with fresh buffers */
        rxq->read = rxq->write = 0;
-       rxq->processed = RX_QUEUE_SIZE - 1;
        rxq->free_count = 0;
 
        return rxq;
@@ -6044,7 +6043,7 @@ static void ipw_adhoc_check(void *data)
        }
 
        queue_delayed_work(priv->workqueue, &priv->adhoc_check,
-                          priv->assoc_request.beacon_interval);
+                          le16_to_cpu(priv->assoc_request.beacon_interval));
 }
 
 static void ipw_bg_adhoc_check(struct work_struct *work)
@@ -7287,7 +7286,7 @@ static int ipw_associate_network(struct ipw_priv *priv,
                priv->assoc_request.auth_type = AUTH_OPEN;
 
        if (priv->ieee->wpa_ie_len) {
-               priv->assoc_request.policy_support = 0x02;      /* RSN active */
+               priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
                ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
                                 priv->ieee->wpa_ie_len);
        }
@@ -7304,7 +7303,7 @@ static int ipw_associate_network(struct ipw_priv *priv,
        else if (network->mode & priv->ieee->mode & IEEE_B)
                priv->assoc_request.ieee_mode = IPW_B_MODE;
 
-       priv->assoc_request.capability = network->capability;
+       priv->assoc_request.capability = cpu_to_le16(network->capability);
        if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
            && !(priv->config & CFG_PREAMBLE_LONG)) {
                priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
@@ -7313,13 +7312,13 @@ static int ipw_associate_network(struct ipw_priv *priv,
 
                /* Clear the short preamble if we won't be supporting it */
                priv->assoc_request.capability &=
-                   ~WLAN_CAPABILITY_SHORT_PREAMBLE;
+                   ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
        }
 
        /* Clear capability bits that aren't used in Ad Hoc */
        if (priv->ieee->iw_mode == IW_MODE_ADHOC)
                priv->assoc_request.capability &=
-                   ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
+                   ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
 
        IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
                        "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
@@ -7341,7 +7340,7 @@ static int ipw_associate_network(struct ipw_priv *priv,
                        '1' + priv->ieee->sec.active_key : '.',
                        priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
 
-       priv->assoc_request.beacon_interval = network->beacon_interval;
+       priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
        if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
            (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
                priv->assoc_request.assoc_type = HC_IBSS_START;
@@ -7352,21 +7351,21 @@ static int ipw_associate_network(struct ipw_priv *priv,
                        priv->assoc_request.assoc_type = HC_REASSOCIATE;
                else
                        priv->assoc_request.assoc_type = HC_ASSOCIATE;
-               priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
-               priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
+               priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
+               priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
        }
 
        memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
 
        if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
                memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
-               priv->assoc_request.atim_window = network->atim_window;
+               priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
        } else {
                memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
                priv->assoc_request.atim_window = 0;
        }
 
-       priv->assoc_request.listen_interval = network->listen_interval;
+       priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
 
        err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
        if (err) {
@@ -8237,13 +8236,17 @@ static void ipw_rx(struct ipw_priv *priv)
        struct ieee80211_hdr_4addr *header;
        u32 r, w, i;
        u8 network_packet;
+       u8 fill_rx = 0;
        DECLARE_MAC_BUF(mac);
        DECLARE_MAC_BUF(mac2);
        DECLARE_MAC_BUF(mac3);
 
        r = ipw_read32(priv, IPW_RX_READ_INDEX);
        w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
-       i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
+       i = priv->rxq->read;
+
+       if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
+               fill_rx = 1;
 
        while (i != r) {
                rxb = priv->rxq->queue[i];
@@ -8418,11 +8421,17 @@ static void ipw_rx(struct ipw_priv *priv)
                list_add_tail(&rxb->list, &priv->rxq->rx_used);
 
                i = (i + 1) % RX_QUEUE_SIZE;
+
+               /* If there are a lot of unsued frames, restock the Rx queue
+                * so the ucode won't assert */
+               if (fill_rx) {
+                       priv->rxq->read = i;
+                       ipw_rx_queue_replenish(priv);
+               }
        }
 
        /* Backtrack one entry */
-       priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
-
+       priv->rxq->read = i;
        ipw_rx_queue_restock(priv);
 }
 
@@ -10183,7 +10192,6 @@ static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
        u8 id, hdr_len, unicast;
        u16 remaining_bytes;
        int fc;
-       DECLARE_MAC_BUF(mac);
 
        hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
        switch (priv->ieee->iw_mode) {
@@ -10194,8 +10202,10 @@ static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
                        id = ipw_add_station(priv, hdr->addr1);
                        if (id == IPW_INVALID_STATION) {
                                IPW_WARNING("Attempt to send data to "
-                                           "invalid cell: %s\n",
-                                           print_mac(mac, hdr->addr1));
+                                           "invalid cell: " MAC_FMT "\n",
+                                           hdr->addr1[0], hdr->addr1[1],
+                                           hdr->addr1[2], hdr->addr1[3],
+                                           hdr->addr1[4], hdr->addr1[5]);
                                goto drop;
                        }
                }
@@ -10340,9 +10350,7 @@ static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
                                         remaining_bytes,
                                         PCI_DMA_TODEVICE));
 
-                       tfd->u.data.num_chunks =
-                           cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
-                                       1);
+                       le32_add_cpu(&tfd->u.data.num_chunks, 1);
                }
        }
 
@@ -10350,7 +10358,7 @@ static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
        q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
        ipw_write32(priv, q->reg_w, q->first_empty);
 
-       if (ipw_queue_space(q) < q->high_mark)
+       if (ipw_tx_queue_space(q) < q->high_mark)
                netif_stop_queue(priv->net_dev);
 
        return NETDEV_TX_OK;
@@ -10371,7 +10379,7 @@ static int ipw_net_is_queue_full(struct net_device *dev, int pri)
        struct clx2_tx_queue *txq = &priv->txq[0];
 #endif                         /* CONFIG_IPW2200_QOS */
 
-       if (ipw_queue_space(&txq->q) < txq->q.high_mark)
+       if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
                return 1;
 
        return 0;
@@ -10862,9 +10870,9 @@ static void shim__set_security(struct net_device *dev,
 #if 0
        if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
            (((priv->assoc_request.capability &
-              WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
+              cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
             (!(priv->assoc_request.capability &
-               WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
+               cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
                IPW_DEBUG_ASSOC("Disassociating due to capability "
                                "change.\n");
                ipw_disassociate(priv);
@@ -11567,6 +11575,7 @@ static int ipw_prom_alloc(struct ipw_priv *priv)
        priv->prom_priv->priv = priv;
 
        strcpy(priv->prom_net_dev->name, "rtap%d");
+       memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
 
        priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
        priv->prom_net_dev->open = ipw_prom_open;