wl12xx: schedule TX packets according to FW occupancy
authorArik Nemtsov <arik@wizery.com>
Fri, 24 Jun 2011 10:03:35 +0000 (13:03 +0300)
committerLuciano Coelho <coelho@ti.com>
Tue, 5 Jul 2011 18:33:44 +0000 (21:33 +0300)
When selecting packets for transmission, prefer the ACs that are least
occupied in the FW. When packets for multiple ACs are present in the FW,
it decides which to transmit according to WMM QoS parameters.

With these changes, lower priority ACs should not be starved when higher
priority traffic is present.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
Signed-off-by: Luciano Coelho <coelho@ti.com>
drivers/net/wireless/wl12xx/debugfs.c
drivers/net/wireless/wl12xx/main.c
drivers/net/wireless/wl12xx/tx.c
drivers/net/wireless/wl12xx/wl12xx.h

index 3f6314143ef801837467c86ed1c513374218420f..4d9c8cc076ec47fdc8aeb6abe11192f816aecf6c 100644 (file)
@@ -338,7 +338,10 @@ static ssize_t driver_state_read(struct file *file, char __user *user_buf,
 #define DRIVER_STATE_PRINT_HEX(x)  DRIVER_STATE_PRINT(x, "0x%x")
 
        DRIVER_STATE_PRINT_INT(tx_blocks_available);
-       DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
+       DRIVER_STATE_PRINT_INT(tx_allocated_blocks[0]);
+       DRIVER_STATE_PRINT_INT(tx_allocated_blocks[1]);
+       DRIVER_STATE_PRINT_INT(tx_allocated_blocks[2]);
+       DRIVER_STATE_PRINT_INT(tx_allocated_blocks[3]);
        DRIVER_STATE_PRINT_INT(tx_frames_cnt);
        DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
        DRIVER_STATE_PRINT_INT(tx_queue_count);
index 8b929fa0d3c3f5031bde1955c06ba2e5c073a1d4..08eb81e698fa0f5e1f5ce486232cde4e81f77b8f 100644 (file)
@@ -824,13 +824,24 @@ static void wl1271_irq_update_links_status(struct wl1271 *wl,
        }
 }
 
+static u32 wl1271_tx_allocated_blocks(struct wl1271 *wl)
+{
+       int i;
+       u32 total_alloc_blocks = 0;
+
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               total_alloc_blocks += wl->tx_allocated_blocks[i];
+
+       return total_alloc_blocks;
+}
+
 static void wl1271_fw_status(struct wl1271 *wl,
                             struct wl1271_fw_full_status *full_status)
 {
        struct wl1271_fw_common_status *status = &full_status->common;
        struct timespec ts;
        u32 old_tx_blk_count = wl->tx_blocks_available;
-       u32 freed_blocks = 0;
+       u32 freed_blocks = 0, ac_freed_blocks;
        int i;
 
        if (wl->bss_type == BSS_TYPE_AP_BSS) {
@@ -850,21 +861,23 @@ static void wl1271_fw_status(struct wl1271 *wl,
 
        /* update number of available TX blocks */
        for (i = 0; i < NUM_TX_QUEUES; i++) {
-               freed_blocks += le32_to_cpu(status->tx_released_blks[i]) -
-                               wl->tx_blocks_freed[i];
+               ac_freed_blocks = le32_to_cpu(status->tx_released_blks[i]) -
+                                 wl->tx_blocks_freed[i];
+               freed_blocks += ac_freed_blocks;
+
+               wl->tx_allocated_blocks[i] -= ac_freed_blocks;
 
                wl->tx_blocks_freed[i] =
                        le32_to_cpu(status->tx_released_blks[i]);
        }
 
-       wl->tx_allocated_blocks -= freed_blocks;
-
        if (wl->bss_type == BSS_TYPE_AP_BSS) {
                /* Update num of allocated TX blocks per link and ps status */
                wl1271_irq_update_links_status(wl, &full_status->ap);
                wl->tx_blocks_available += freed_blocks;
        } else {
-               int avail = full_status->sta.tx_total - wl->tx_allocated_blocks;
+               int avail = full_status->sta.tx_total -
+                           wl1271_tx_allocated_blocks(wl);
 
                /*
                 * The FW might change the total number of TX memblocks before
@@ -1987,7 +2000,6 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
        wl->psm_entry_retry = 0;
        wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
        wl->tx_blocks_available = 0;
-       wl->tx_allocated_blocks = 0;
        wl->tx_results_count = 0;
        wl->tx_packets_count = 0;
        wl->time_offset = 0;
@@ -2008,8 +2020,10 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
         */
        wl->flags = 0;
 
-       for (i = 0; i < NUM_TX_QUEUES; i++)
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
                wl->tx_blocks_freed[i] = 0;
+               wl->tx_allocated_blocks[i] = 0;
+       }
 
        wl1271_debugfs_reset(wl);
 
index 5c618c5ceda9db589eb7cee992a8a29d9c5ac775..e6e5f54b8e490caae4a74b465777adc583cb266f 100644 (file)
@@ -168,7 +168,7 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
        u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
        u32 len;
        u32 total_blocks;
-       int id, ret = -EBUSY;
+       int id, ret = -EBUSY, ac;
        u32 spare_blocks;
 
        if (unlikely(wl->quirks & WL12XX_QUIRK_USE_2_SPARE_BLOCKS))
@@ -206,7 +206,9 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
                desc->id = id;
 
                wl->tx_blocks_available -= total_blocks;
-               wl->tx_allocated_blocks += total_blocks;
+
+               ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
+               wl->tx_allocated_blocks[ac] += total_blocks;
 
                if (wl->bss_type == BSS_TYPE_AP_BSS)
                        wl->links[hlid].allocated_blks += total_blocks;
@@ -453,21 +455,41 @@ void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
        }
 }
 
+static struct sk_buff_head *wl1271_select_queue(struct wl1271 *wl,
+                                               struct sk_buff_head *queues)
+{
+       int i, q = -1;
+       u32 min_blks = 0xffffffff;
+
+       /*
+        * Find a non-empty ac where:
+        * 1. There are packets to transmit
+        * 2. The FW has the least allocated blocks
+        */
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               if (!skb_queue_empty(&queues[i]) &&
+                   (wl->tx_allocated_blocks[i] < min_blks)) {
+                       q = i;
+                       min_blks = wl->tx_allocated_blocks[q];
+               }
+
+       if (q == -1)
+               return NULL;
+
+       return &queues[q];
+}
+
 static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl)
 {
        struct sk_buff *skb = NULL;
        unsigned long flags;
+       struct sk_buff_head *queue;
 
-       skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]);
-       if (skb)
-               goto out;
-       skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]);
-       if (skb)
+       queue = wl1271_select_queue(wl, wl->tx_queue);
+       if (!queue)
                goto out;
-       skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]);
-       if (skb)
-               goto out;
-       skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]);
+
+       skb = skb_dequeue(queue);
 
 out:
        if (skb) {
@@ -484,6 +506,7 @@ static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
        struct sk_buff *skb = NULL;
        unsigned long flags;
        int i, h, start_hlid;
+       struct sk_buff_head *queue;
 
        /* start from the link after the last one */
        start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS;
@@ -492,21 +515,20 @@ static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
        for (i = 0; i < AP_MAX_LINKS; i++) {
                h = (start_hlid + i) % AP_MAX_LINKS;
 
-               skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VO]);
-               if (skb)
-                       goto out;
-               skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VI]);
-               if (skb)
-                       goto out;
-               skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BE]);
-               if (skb)
-                       goto out;
-               skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BK]);
+               /* only consider connected stations */
+               if (h >= WL1271_AP_STA_HLID_START &&
+                   !test_bit(h - WL1271_AP_STA_HLID_START, wl->ap_hlid_map))
+                       continue;
+
+               queue = wl1271_select_queue(wl, wl->links[h].tx_queue);
+               if (!queue)
+                       continue;
+
+               skb = skb_dequeue(queue);
                if (skb)
-                       goto out;
+                       break;
        }
 
-out:
        if (skb) {
                wl->last_tx_hlid = h;
                spin_lock_irqsave(&wl->wl_lock, flags);
index 63be7f214bf8fda938729e160619b35e200abcc2..c6bf4b4e15d8d638a4a0968b95dae23716fbffb2 100644 (file)
@@ -424,7 +424,7 @@ struct wl1271 {
        /* Accounting for allocated / available TX blocks on HW */
        u32 tx_blocks_freed[NUM_TX_QUEUES];
        u32 tx_blocks_available;
-       u32 tx_allocated_blocks;
+       u32 tx_allocated_blocks[NUM_TX_QUEUES];
        u32 tx_results_count;
 
        /* Transmitted TX packets counter for chipset interface */