mwifiex: mwifiex_unmap_pci_memory() handling for sleep confirm
authorAmitkumar Karwar <akarwar@marvell.com>
Tue, 24 Jan 2017 13:35:44 +0000 (19:05 +0530)
committerKalle Valo <kvalo@codeaurora.org>
Sat, 28 Jan 2017 07:10:03 +0000 (09:10 +0200)
Sleep confirm is a special command for which "adapter->cur_cmd" pointer
is not set. When it's response is received, host writes SLEEP confirm done
to a register. Firmware will perform DMA for writing sleep cookie signature
on same buffer after this.

Let's not immediately call mwifiex_unmap_pci_memory() for this special
command. Unmapping will be done when firmware completes writing sleep
cookie signature.

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/marvell/mwifiex/pcie.c
drivers/net/wireless/marvell/mwifiex/pcie.h

index ca51411e4a4c7a3386452b7c18210ee9f55e4535..3f4ca28356acb683c06e44923325941a152dddee 100644 (file)
@@ -441,7 +441,7 @@ static void mwifiex_delay_for_sleep_cookie(struct mwifiex_adapter *adapter,
        u32 sleep_cookie, count;
 
        for (count = 0; count < max_delay_loop_cnt; count++) {
-               buffer = card->cmdrsp_buf->data - INTF_HEADER_LEN;
+               buffer = card->cmdrsp_buf->data;
                sleep_cookie = READ_ONCE(*(u32 *)buffer);
 
                if (sleep_cookie == MWIFIEX_DEF_SLEEP_COOKIE) {
@@ -1690,7 +1690,13 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
        mwifiex_dbg(adapter, CMD,
                    "info: Rx CMD Response\n");
 
-       mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_FROMDEVICE);
+       if (adapter->curr_cmd)
+               mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_FROMDEVICE);
+       else
+               pci_dma_sync_single_for_cpu(card->dev,
+                                           MWIFIEX_SKB_DMA_ADDR(skb),
+                                           MWIFIEX_UPLD_SIZE,
+                                           PCI_DMA_FROMDEVICE);
 
        /* Unmap the command as a response has been received. */
        if (card->cmd_buf) {
@@ -1703,10 +1709,13 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
        rx_len = le16_to_cpu(pkt_len);
        skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len);
        skb_trim(skb, rx_len);
-       skb_pull(skb, INTF_HEADER_LEN);
 
        if (!adapter->curr_cmd) {
                if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
+                       pci_dma_sync_single_for_device(card->dev,
+                                               MWIFIEX_SKB_DMA_ADDR(skb),
+                                               MWIFIEX_SLEEP_COOKIE_SIZE,
+                                               PCI_DMA_FROMDEVICE);
                        if (mwifiex_write_reg(adapter,
                                              PCIE_CPU_INT_EVENT,
                                              CPU_INTR_SLEEP_CFM_DONE)) {
@@ -1716,6 +1725,9 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
                        }
                        mwifiex_delay_for_sleep_cookie(adapter,
                                                       MWIFIEX_MAX_DELAY_COUNT);
+                       mwifiex_unmap_pci_memory(adapter, skb,
+                                                PCI_DMA_FROMDEVICE);
+                       skb_pull(skb, INTF_HEADER_LEN);
                        while (reg->sleep_cookie && (count++ < 10) &&
                               mwifiex_pcie_ok_to_access_hw(adapter))
                                usleep_range(50, 60);
@@ -1733,6 +1745,7 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
                                           PCI_DMA_FROMDEVICE))
                        return -1;
        } else if (mwifiex_pcie_ok_to_access_hw(adapter)) {
+               skb_pull(skb, INTF_HEADER_LEN);
                adapter->curr_cmd->resp_skb = skb;
                adapter->cmd_resp_received = true;
                /* Take the pointer and set it to CMD node and will
index 21ba5e6a4c2ac2966e42a97ee9bcfc753cef9073..00e8ee5ad4a834ed1905c5b98acee85be3ca1a32 100644 (file)
 /* FW awake cookie after FW ready */
 #define FW_AWAKE_COOKIE                                                (0xAA55AA55)
 #define MWIFIEX_DEF_SLEEP_COOKIE                       0xBEEFBEEF
+#define MWIFIEX_SLEEP_COOKIE_SIZE                      4
 #define MWIFIEX_MAX_DELAY_COUNT                                100
 
 struct mwifiex_pcie_card_reg {