mwifiex: fix simultaneous scan and Tx traffic problem
authorAmitkumar Karwar <akarwar@marvell.com>
Thu, 7 Jun 2012 04:12:41 +0000 (21:12 -0700)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 11 Jun 2012 18:59:43 +0000 (14:59 -0400)
If scan operation is started when Tx traffic is already running,
driver locks Tx queue until it gets completed. With this logic
there is a delay for Tx packets.

This patch implements new approach to give Tx path higher priority
in this case. Driver internally sends multiple synchronous scan
commands to firmware when scan is requested by user. Now we will
make sure that Tx queue is empty everytime before sending next scan
command. If Tx queue isn't empty scan command will be postponsed by
20msec. This rule will be followed until Tx queue becomes empty or
timeout of 1 second happens. In case of timeout scan operation will
be aborted.

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/mwifiex/init.c
drivers/net/wireless/mwifiex/main.c
drivers/net/wireless/mwifiex/main.h
drivers/net/wireless/mwifiex/scan.c

index c1cb004db913cd0064c55758962900f2ed5aa04f..0f18ef6a30c813d716f4cacd2bf65ba68a1515e3 100644 (file)
@@ -57,6 +57,68 @@ static int mwifiex_add_bss_prio_tbl(struct mwifiex_private *priv)
        return 0;
 }
 
+static void scan_delay_timer_fn(unsigned long data)
+{
+       struct mwifiex_private *priv = (struct mwifiex_private *)data;
+       struct mwifiex_adapter *adapter = priv->adapter;
+       struct cmd_ctrl_node *cmd_node, *tmp_node;
+       unsigned long flags;
+
+       if (!mwifiex_wmm_lists_empty(adapter)) {
+               if (adapter->scan_delay_cnt == MWIFIEX_MAX_SCAN_DELAY_CNT) {
+                       /*
+                        * Abort scan operation by cancelling all pending scan
+                        * command
+                        */
+                       spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
+                       list_for_each_entry_safe(cmd_node, tmp_node,
+                                                &adapter->scan_pending_q,
+                                                list) {
+                               list_del(&cmd_node->list);
+                               cmd_node->wait_q_enabled = false;
+                               mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
+                       }
+                       spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
+                                              flags);
+
+                       spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
+                       adapter->scan_processing = false;
+                       spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock,
+                                              flags);
+
+                       if (priv->user_scan_cfg) {
+                               dev_dbg(priv->adapter->dev,
+                                       "info: %s: scan aborted\n", __func__);
+                               cfg80211_scan_done(priv->scan_request, 1);
+                               priv->scan_request = NULL;
+                               kfree(priv->user_scan_cfg);
+                               priv->user_scan_cfg = NULL;
+                       }
+               } else {
+                       /*
+                        * Tx data queue is still not empty, delay scan
+                        * operation further by 20msec.
+                        */
+                       mod_timer(&priv->scan_delay_timer, jiffies +
+                                 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
+                       adapter->scan_delay_cnt++;
+               }
+       } else {
+               /*
+                * Tx data queue is empty. Get scan command from scan_pending_q
+                * and put to cmd_pending_q to resume scan operation
+                */
+               adapter->scan_delay_cnt = 0;
+               spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
+               cmd_node = list_first_entry(&adapter->scan_pending_q,
+                                           struct cmd_ctrl_node, list);
+               list_del(&cmd_node->list);
+               spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
+
+               mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
+       }
+}
+
 /*
  * This function initializes the private structure and sets default
  * values to the members.
@@ -136,6 +198,9 @@ static int mwifiex_init_priv(struct mwifiex_private *priv)
 
        priv->scan_block = false;
 
+       setup_timer(&priv->scan_delay_timer, scan_delay_timer_fn,
+                   (unsigned long)priv);
+
        return mwifiex_add_bss_prio_tbl(priv);
 }
 
index 3192855c31c05df94e55360824f463ff0fbccfb8..0f06f07a70e67d7b3d76d12bcfdcab203cf29d3a 100644 (file)
@@ -244,8 +244,8 @@ process_start:
                        }
                }
 
-               if (!adapter->scan_processing && !adapter->data_sent &&
-                   !mwifiex_wmm_lists_empty(adapter)) {
+               if ((!adapter->scan_processing || adapter->scan_delay_cnt) &&
+                   !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
                        mwifiex_wmm_process_tx(adapter);
                        if (adapter->hs_activated) {
                                adapter->is_hs_configured = false;
index cbad00d7eb11bb6168fc0264b3f811abe6ff19ac..5b32221077c488526e5b3f86125ae5eac179c12b 100644 (file)
@@ -87,6 +87,9 @@ enum {
 
 #define MWIFIEX_MAX_TOTAL_SCAN_TIME    (MWIFIEX_TIMER_10S - MWIFIEX_TIMER_1S)
 
+#define MWIFIEX_MAX_SCAN_DELAY_CNT                     50
+#define MWIFIEX_SCAN_DELAY_MSEC                                20
+
 #define RSN_GTK_OUI_OFFSET                             2
 
 #define MWIFIEX_OUI_NOT_PRESENT                        0
@@ -482,6 +485,7 @@ struct mwifiex_private {
        u16 proberesp_idx;
        u16 assocresp_idx;
        u16 rsn_idx;
+       struct timer_list scan_delay_timer;
 };
 
 enum mwifiex_ba_status {
@@ -686,6 +690,7 @@ struct mwifiex_adapter {
        struct completion fw_load;
        u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
        u16 max_mgmt_ie_index;
+       u8 scan_delay_cnt;
 };
 
 int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
index 74f0457157235d8a3100eb95e66027976493b19c..ea2f1bdef8a2eefa499fb50bffa39a4702c9cc0b 100644 (file)
@@ -1772,14 +1772,23 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
                        priv->user_scan_cfg = NULL;
                }
        } else {
-               /* Get scan command from scan_pending_q and put to
-                  cmd_pending_q */
-               cmd_node = list_first_entry(&adapter->scan_pending_q,
-                                           struct cmd_ctrl_node, list);
-               list_del(&cmd_node->list);
-               spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
-
-               mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
+               if (!mwifiex_wmm_lists_empty(adapter)) {
+                       spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
+                                              flags);
+                       adapter->scan_delay_cnt = 1;
+                       mod_timer(&priv->scan_delay_timer, jiffies +
+                                 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
+               } else {
+                       /* Get scan command from scan_pending_q and put to
+                          cmd_pending_q */
+                       cmd_node = list_first_entry(&adapter->scan_pending_q,
+                                                   struct cmd_ctrl_node, list);
+                       list_del(&cmd_node->list);
+                       spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
+                                              flags);
+                       mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
+                                                       true);
+               }
        }
 
 done: