mwifiex: add support for sleep cookie in PCIe
authorAvinash Patil <patila@marvell.com>
Wed, 19 Mar 2014 05:19:17 +0000 (22:19 -0700)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 19 Mar 2014 19:15:47 +0000 (15:15 -0400)
This patch adds support to read sleep cookie for command
response before accessing buffer.

Signed-off-by: Avinash Patil <patila@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/mwifiex/pcie.c
drivers/net/wireless/mwifiex/pcie.h

index 9f1683b5f28f8e7c385751c8a34b239b2c2ff903..57c353a94b29784f990c7e62c5e8e2dd2bb36b46 100644 (file)
@@ -327,6 +327,30 @@ static void mwifiex_pcie_dev_wakeup_delay(struct mwifiex_adapter *adapter)
        return;
 }
 
+static void mwifiex_delay_for_sleep_cookie(struct mwifiex_adapter *adapter,
+                                          u32 max_delay_loop_cnt)
+{
+       struct pcie_service_card *card = adapter->card;
+       u8 *buffer;
+       u32 sleep_cookie, count;
+
+       for (count = 0; count < max_delay_loop_cnt; count++) {
+               buffer = card->cmdrsp_buf->data - INTF_HEADER_LEN;
+               sleep_cookie = *(u32 *)buffer;
+
+               if (sleep_cookie == MWIFIEX_DEF_SLEEP_COOKIE) {
+                       dev_dbg(adapter->dev,
+                               "sleep cookie found at count %d\n", count);
+                       break;
+               }
+               usleep_range(20, 30);
+       }
+
+       if (count >= max_delay_loop_cnt)
+               dev_dbg(adapter->dev,
+                       "max count reached while accessing sleep cookie\n");
+}
+
 /* This function wakes up the card by reading fw_status register. */
 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
 {
@@ -1539,6 +1563,8 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
                                         "Write register failed\n");
                                return -1;
                        }
+                       mwifiex_delay_for_sleep_cookie(adapter,
+                                                      MWIFIEX_MAX_DELAY_COUNT);
                        while (reg->sleep_cookie && (count++ < 10) &&
                               mwifiex_pcie_ok_to_access_hw(adapter))
                                usleep_range(50, 60);
index 193af75bf5828a798adf55de6124854f05011fc5..e8ec561f8a642495e410793539a0f2b808435cdf 100644 (file)
@@ -97,6 +97,8 @@
 #define MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD                256
 /* FW awake cookie after FW ready */
 #define FW_AWAKE_COOKIE                                                (0xAA55AA55)
+#define MWIFIEX_DEF_SLEEP_COOKIE                       0xBEEFBEEF
+#define MWIFIEX_MAX_DELAY_COUNT                                5
 
 struct mwifiex_pcie_card_reg {
        u16 cmd_addr_lo;