Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6.git] / drivers / net / wireless / mwifiex / wmm.c
index 52d2185..67b2d0b 100644 (file)
@@ -121,6 +121,7 @@ mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter *adapter, u8 *ra)
        memcpy(ra_list->ra, ra, ETH_ALEN);
 
        ra_list->total_pkts_size = 0;
+       ra_list->total_pkts = 0;
 
        dev_dbg(adapter->dev, "info: allocated ra_list %p\n", ra_list);
 
@@ -177,14 +178,20 @@ static void mwifiex_wmm_default_queue_priorities(struct mwifiex_private *priv)
  * This function map ACs to TIDs.
  */
 static void
-mwifiex_wmm_queue_priorities_tid(u8 queue_priority[])
+mwifiex_wmm_queue_priorities_tid(struct mwifiex_wmm_desc *wmm)
 {
+       u8 *queue_priority = wmm->queue_priority;
        int i;
 
        for (i = 0; i < 4; ++i) {
                tos_to_tid[7 - (i * 2)] = ac_to_tid[queue_priority[i]][1];
                tos_to_tid[6 - (i * 2)] = ac_to_tid[queue_priority[i]][0];
        }
+
+       for (i = 0; i < MAX_NUM_TID; ++i)
+               tos_to_tid_inv[tos_to_tid[i]] = (u8)i;
+
+       atomic_set(&wmm->highest_queued_prio, HIGH_PRIO_TID);
 }
 
 /*
@@ -246,7 +253,7 @@ mwifiex_wmm_setup_queue_priorities(struct mwifiex_private *priv,
                }
        }
 
-       mwifiex_wmm_queue_priorities_tid(priv->wmm.queue_priority);
+       mwifiex_wmm_queue_priorities_tid(&priv->wmm);
 }
 
 /*
@@ -401,6 +408,7 @@ mwifiex_wmm_init(struct mwifiex_adapter *adapter)
                priv->add_ba_param.rx_win_size = MWIFIEX_AMPDU_DEF_RXWINSIZE;
 
                atomic_set(&priv->wmm.tx_pkts_queued, 0);
+               atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
        }
 }
 
@@ -468,6 +476,7 @@ static void mwifiex_wmm_cleanup_queues(struct mwifiex_private *priv)
                                                     ra_list);
 
        atomic_set(&priv->wmm.tx_pkts_queued, 0);
+       atomic_set(&priv->wmm.highest_queued_prio, HIGH_PRIO_TID);
 }
 
 /*
@@ -637,9 +646,15 @@ mwifiex_wmm_add_buf_txqueue(struct mwifiex_adapter *adapter,
        skb_queue_tail(&ra_list->skb_head, skb);
 
        ra_list->total_pkts_size += skb->len;
+       ra_list->total_pkts++;
 
        atomic_inc(&priv->wmm.tx_pkts_queued);
 
+       if (atomic_read(&priv->wmm.highest_queued_prio) <
+                                               tos_to_tid_inv[tid_down])
+               atomic_set(&priv->wmm.highest_queued_prio,
+                                               tos_to_tid_inv[tid_down]);
+
        spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
 }
 
@@ -865,9 +880,14 @@ mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
                }
 
                do {
+                       atomic_t *hqp;
+                       spinlock_t *lock;
+
                        priv_tmp = bssprio_node->priv;
+                       hqp = &priv_tmp->wmm.highest_queued_prio;
+                       lock = &priv_tmp->wmm.ra_list_spinlock;
 
-                       for (i = HIGH_PRIO_TID; i >= LOW_PRIO_TID; --i) {
+                       for (i = atomic_read(hqp); i >= LOW_PRIO_TID; --i) {
 
                                tid_ptr = &(priv_tmp)->wmm.
                                        tid_tbl_ptr[tos_to_tid[i]];
@@ -905,6 +925,11 @@ mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
                                        is_list_empty =
                                                skb_queue_empty(&ptr->skb_head);
                                        if (!is_list_empty) {
+                                               spin_lock_irqsave(lock, flags);
+                                               if (atomic_read(hqp) > i)
+                                                       atomic_set(hqp, i);
+                                               spin_unlock_irqrestore(lock,
+                                                                       flags);
                                                *priv = priv_tmp;
                                                *tid = tos_to_tid[i];
                                                return ptr;
@@ -923,6 +948,12 @@ mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
                                } while (ptr != head);
                        }
 
+                       /* No packet at any TID for this priv. Mark as such
+                        * to skip checking TIDs for this priv (until pkt is
+                        * added).
+                        */
+                       atomic_set(hqp, NO_PKT_PRIO_TID);
+
                        /* Get next bss priority node */
                        bssprio_node = list_first_entry(&bssprio_node->list,
                                                struct mwifiex_bss_prio_node,
@@ -942,28 +973,6 @@ mwifiex_wmm_get_highest_priolist_ptr(struct mwifiex_adapter *adapter,
 }
 
 /*
- * This function gets the number of packets in the Tx queue of a
- * particular RA list.
- */
-static int
-mwifiex_num_pkts_in_txq(struct mwifiex_private *priv,
-                       struct mwifiex_ra_list_tbl *ptr, int max_buf_size)
-{
-       int count = 0, total_size = 0;
-       struct sk_buff *skb, *tmp;
-
-       skb_queue_walk_safe(&ptr->skb_head, skb, tmp) {
-               total_size += skb->len;
-               if (total_size < max_buf_size)
-                       ++count;
-               else
-                       break;
-       }
-
-       return count;
-}
-
-/*
  * This function sends a single packet to firmware for transmission.
  */
 static void
@@ -990,6 +999,7 @@ mwifiex_send_single_packet(struct mwifiex_private *priv,
        dev_dbg(adapter->dev, "data: dequeuing the packet %p %p\n", ptr, skb);
 
        ptr->total_pkts_size -= skb->len;
+       ptr->total_pkts--;
 
        if (!skb_queue_empty(&ptr->skb_head))
                skb_next = skb_peek(&ptr->skb_head);
@@ -1015,6 +1025,7 @@ mwifiex_send_single_packet(struct mwifiex_private *priv,
                skb_queue_tail(&ptr->skb_head, skb);
 
                ptr->total_pkts_size += skb->len;
+               ptr->total_pkts++;
                tx_info->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
                spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
                                       ra_list_flags);
@@ -1202,9 +1213,9 @@ mwifiex_dequeue_tx_packet(struct mwifiex_adapter *adapter)
                }
 /* Minimum number of AMSDU */
 #define MIN_NUM_AMSDU 2
+
                if (mwifiex_is_amsdu_allowed(priv, tid) &&
-                   (mwifiex_num_pkts_in_txq(priv, ptr, adapter->tx_buf_size) >=
-                    MIN_NUM_AMSDU))
+                               (ptr->total_pkts >= MIN_NUM_AMSDU))
                        mwifiex_11n_aggregate_pkt(priv, ptr, INTF_HEADER_LEN,
                                                  ptr_index, flags);
                        /* ra_list_spinlock has been freed in
@@ -1231,5 +1242,5 @@ mwifiex_wmm_process_tx(struct mwifiex_adapter *adapter)
 
                if (mwifiex_dequeue_tx_packet(adapter))
                        break;
-       } while (true);
+       } while (!mwifiex_wmm_lists_empty(adapter));
 }