forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/net/wireless/marvell/mwifiex/pcie.c
....@@ -1,10 +1,10 @@
11 /*
2
- * Marvell Wireless LAN device driver: PCIE specific handling
2
+ * NXP Wireless LAN device driver: PCIE specific handling
33 *
4
- * Copyright (C) 2011-2014, Marvell International Ltd.
4
+ * Copyright 2011-2020 NXP
55 *
6
- * This software file (the "File") is distributed by Marvell International
7
- * Ltd. under the terms of the GNU General Public License Version 2, June 1991
6
+ * This software file (the "File") is distributed by NXP
7
+ * under the terms of the GNU General Public License Version 2, June 1991
88 * (the "License"). You may use, redistribute and/or modify this File in
99 * accordance with the terms and conditions of the License, a copy of which
1010 * is available by writing to the Free Software Foundation, Inc.,
....@@ -17,6 +17,7 @@
1717 * this warranty disclaimer.
1818 */
1919
20
+#include <linux/iopoll.h>
2021 #include <linux/firmware.h>
2122
2223 #include "decl.h"
....@@ -32,6 +33,155 @@
3233 #define DRV_NAME "Marvell mwifiex PCIe"
3334
3435 static struct mwifiex_if_ops pcie_ops;
36
+
37
+static const struct mwifiex_pcie_card_reg mwifiex_reg_8766 = {
38
+ .cmd_addr_lo = PCIE_SCRATCH_0_REG,
39
+ .cmd_addr_hi = PCIE_SCRATCH_1_REG,
40
+ .cmd_size = PCIE_SCRATCH_2_REG,
41
+ .fw_status = PCIE_SCRATCH_3_REG,
42
+ .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
43
+ .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
44
+ .tx_rdptr = PCIE_SCRATCH_6_REG,
45
+ .tx_wrptr = PCIE_SCRATCH_7_REG,
46
+ .rx_rdptr = PCIE_SCRATCH_8_REG,
47
+ .rx_wrptr = PCIE_SCRATCH_9_REG,
48
+ .evt_rdptr = PCIE_SCRATCH_10_REG,
49
+ .evt_wrptr = PCIE_SCRATCH_11_REG,
50
+ .drv_rdy = PCIE_SCRATCH_12_REG,
51
+ .tx_start_ptr = 0,
52
+ .tx_mask = MWIFIEX_TXBD_MASK,
53
+ .tx_wrap_mask = 0,
54
+ .rx_mask = MWIFIEX_RXBD_MASK,
55
+ .rx_wrap_mask = 0,
56
+ .tx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
57
+ .rx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
58
+ .evt_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
59
+ .ring_flag_sop = 0,
60
+ .ring_flag_eop = 0,
61
+ .ring_flag_xs_sop = 0,
62
+ .ring_flag_xs_eop = 0,
63
+ .ring_tx_start_ptr = 0,
64
+ .pfu_enabled = 0,
65
+ .sleep_cookie = 1,
66
+ .msix_support = 0,
67
+};
68
+
69
+static const struct mwifiex_pcie_card_reg mwifiex_reg_8897 = {
70
+ .cmd_addr_lo = PCIE_SCRATCH_0_REG,
71
+ .cmd_addr_hi = PCIE_SCRATCH_1_REG,
72
+ .cmd_size = PCIE_SCRATCH_2_REG,
73
+ .fw_status = PCIE_SCRATCH_3_REG,
74
+ .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
75
+ .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
76
+ .tx_rdptr = PCIE_RD_DATA_PTR_Q0_Q1,
77
+ .tx_wrptr = PCIE_WR_DATA_PTR_Q0_Q1,
78
+ .rx_rdptr = PCIE_WR_DATA_PTR_Q0_Q1,
79
+ .rx_wrptr = PCIE_RD_DATA_PTR_Q0_Q1,
80
+ .evt_rdptr = PCIE_SCRATCH_10_REG,
81
+ .evt_wrptr = PCIE_SCRATCH_11_REG,
82
+ .drv_rdy = PCIE_SCRATCH_12_REG,
83
+ .tx_start_ptr = 16,
84
+ .tx_mask = 0x03FF0000,
85
+ .tx_wrap_mask = 0x07FF0000,
86
+ .rx_mask = 0x000003FF,
87
+ .rx_wrap_mask = 0x000007FF,
88
+ .tx_rollover_ind = MWIFIEX_BD_FLAG_TX_ROLLOVER_IND,
89
+ .rx_rollover_ind = MWIFIEX_BD_FLAG_RX_ROLLOVER_IND,
90
+ .evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
91
+ .ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
92
+ .ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
93
+ .ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
94
+ .ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
95
+ .ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
96
+ .pfu_enabled = 1,
97
+ .sleep_cookie = 0,
98
+ .fw_dump_ctrl = PCIE_SCRATCH_13_REG,
99
+ .fw_dump_start = PCIE_SCRATCH_14_REG,
100
+ .fw_dump_end = 0xcff,
101
+ .fw_dump_host_ready = 0xee,
102
+ .fw_dump_read_done = 0xfe,
103
+ .msix_support = 0,
104
+};
105
+
106
+static const struct mwifiex_pcie_card_reg mwifiex_reg_8997 = {
107
+ .cmd_addr_lo = PCIE_SCRATCH_0_REG,
108
+ .cmd_addr_hi = PCIE_SCRATCH_1_REG,
109
+ .cmd_size = PCIE_SCRATCH_2_REG,
110
+ .fw_status = PCIE_SCRATCH_3_REG,
111
+ .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
112
+ .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
113
+ .tx_rdptr = 0xC1A4,
114
+ .tx_wrptr = 0xC174,
115
+ .rx_rdptr = 0xC174,
116
+ .rx_wrptr = 0xC1A4,
117
+ .evt_rdptr = PCIE_SCRATCH_10_REG,
118
+ .evt_wrptr = PCIE_SCRATCH_11_REG,
119
+ .drv_rdy = PCIE_SCRATCH_12_REG,
120
+ .tx_start_ptr = 16,
121
+ .tx_mask = 0x0FFF0000,
122
+ .tx_wrap_mask = 0x1FFF0000,
123
+ .rx_mask = 0x00000FFF,
124
+ .rx_wrap_mask = 0x00001FFF,
125
+ .tx_rollover_ind = BIT(28),
126
+ .rx_rollover_ind = BIT(12),
127
+ .evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
128
+ .ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
129
+ .ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
130
+ .ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
131
+ .ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
132
+ .ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
133
+ .pfu_enabled = 1,
134
+ .sleep_cookie = 0,
135
+ .fw_dump_ctrl = PCIE_SCRATCH_13_REG,
136
+ .fw_dump_start = PCIE_SCRATCH_14_REG,
137
+ .fw_dump_end = 0xcff,
138
+ .fw_dump_host_ready = 0xcc,
139
+ .fw_dump_read_done = 0xdd,
140
+ .msix_support = 0,
141
+};
142
+
143
+static struct memory_type_mapping mem_type_mapping_tbl_w8897[] = {
144
+ {"ITCM", NULL, 0, 0xF0},
145
+ {"DTCM", NULL, 0, 0xF1},
146
+ {"SQRAM", NULL, 0, 0xF2},
147
+ {"IRAM", NULL, 0, 0xF3},
148
+ {"APU", NULL, 0, 0xF4},
149
+ {"CIU", NULL, 0, 0xF5},
150
+ {"ICU", NULL, 0, 0xF6},
151
+ {"MAC", NULL, 0, 0xF7},
152
+};
153
+
154
+static struct memory_type_mapping mem_type_mapping_tbl_w8997[] = {
155
+ {"DUMP", NULL, 0, 0xDD},
156
+};
157
+
158
+static const struct mwifiex_pcie_device mwifiex_pcie8766 = {
159
+ .reg = &mwifiex_reg_8766,
160
+ .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
161
+ .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
162
+ .can_dump_fw = false,
163
+ .can_ext_scan = true,
164
+};
165
+
166
+static const struct mwifiex_pcie_device mwifiex_pcie8897 = {
167
+ .reg = &mwifiex_reg_8897,
168
+ .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
169
+ .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
170
+ .can_dump_fw = true,
171
+ .mem_type_mapping_tbl = mem_type_mapping_tbl_w8897,
172
+ .num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl_w8897),
173
+ .can_ext_scan = true,
174
+};
175
+
176
+static const struct mwifiex_pcie_device mwifiex_pcie8997 = {
177
+ .reg = &mwifiex_reg_8997,
178
+ .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
179
+ .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
180
+ .can_dump_fw = true,
181
+ .mem_type_mapping_tbl = mem_type_mapping_tbl_w8997,
182
+ .num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl_w8997),
183
+ .can_ext_scan = true,
184
+};
35185
36186 static const struct of_device_id mwifiex_pcie_of_match_table[] = {
37187 { .compatible = "pci11ab,2b42" },
....@@ -58,8 +208,8 @@
58208 struct pcie_service_card *card = adapter->card;
59209 struct mwifiex_dma_mapping mapping;
60210
61
- mapping.addr = pci_map_single(card->dev, skb->data, size, flags);
62
- if (pci_dma_mapping_error(card->dev, mapping.addr)) {
211
+ mapping.addr = dma_map_single(&card->dev->dev, skb->data, size, flags);
212
+ if (dma_mapping_error(&card->dev->dev, mapping.addr)) {
63213 mwifiex_dbg(adapter, ERROR, "failed to map pci memory!\n");
64214 return -1;
65215 }
....@@ -75,7 +225,7 @@
75225 struct mwifiex_dma_mapping mapping;
76226
77227 mwifiex_get_mapping(skb, &mapping);
78
- pci_unmap_single(card->dev, mapping.addr, mapping.len, flags);
228
+ dma_unmap_single(&card->dev->dev, mapping.addr, mapping.len, flags);
79229 }
80230
81231 /*
....@@ -150,10 +300,8 @@
150300 static int mwifiex_pcie_suspend(struct device *dev)
151301 {
152302 struct mwifiex_adapter *adapter;
153
- struct pcie_service_card *card;
154
- struct pci_dev *pdev = to_pci_dev(dev);
303
+ struct pcie_service_card *card = dev_get_drvdata(dev);
155304
156
- card = pci_get_drvdata(pdev);
157305
158306 /* Might still be loading firmware */
159307 wait_for_completion(&card->fw_done);
....@@ -195,10 +343,8 @@
195343 static int mwifiex_pcie_resume(struct device *dev)
196344 {
197345 struct mwifiex_adapter *adapter;
198
- struct pcie_service_card *card;
199
- struct pci_dev *pdev = to_pci_dev(dev);
346
+ struct pcie_service_card *card = dev_get_drvdata(dev);
200347
201
- card = pci_get_drvdata(pdev);
202348
203349 if (!card->adapter) {
204350 dev_err(dev, "adapter structure is not valid\n");
....@@ -469,10 +615,9 @@
469615 struct sk_buff *cmdrsp = card->cmdrsp_buf;
470616
471617 for (count = 0; count < max_delay_loop_cnt; count++) {
472
- pci_dma_sync_single_for_cpu(card->dev,
473
- MWIFIEX_SKB_DMA_ADDR(cmdrsp),
474
- sizeof(sleep_cookie),
475
- PCI_DMA_FROMDEVICE);
618
+ dma_sync_single_for_cpu(&card->dev->dev,
619
+ MWIFIEX_SKB_DMA_ADDR(cmdrsp),
620
+ sizeof(sleep_cookie), DMA_FROM_DEVICE);
476621 buffer = cmdrsp->data;
477622 sleep_cookie = get_unaligned_le32(buffer);
478623
....@@ -481,10 +626,10 @@
481626 "sleep cookie found at count %d\n", count);
482627 break;
483628 }
484
- pci_dma_sync_single_for_device(card->dev,
485
- MWIFIEX_SKB_DMA_ADDR(cmdrsp),
486
- sizeof(sleep_cookie),
487
- PCI_DMA_FROMDEVICE);
629
+ dma_sync_single_for_device(&card->dev->dev,
630
+ MWIFIEX_SKB_DMA_ADDR(cmdrsp),
631
+ sizeof(sleep_cookie),
632
+ DMA_FROM_DEVICE);
488633 usleep_range(20, 30);
489634 }
490635
....@@ -493,11 +638,15 @@
493638 "max count reached while accessing sleep cookie\n");
494639 }
495640
641
+#define N_WAKEUP_TRIES_SHORT_INTERVAL 15
642
+#define N_WAKEUP_TRIES_LONG_INTERVAL 35
643
+
496644 /* This function wakes up the card by reading fw_status register. */
497645 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
498646 {
499647 struct pcie_service_card *card = adapter->card;
500648 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
649
+ int retval;
501650
502651 mwifiex_dbg(adapter, EVENT,
503652 "event: Wakeup device...\n");
....@@ -505,11 +654,24 @@
505654 if (reg->sleep_cookie)
506655 mwifiex_pcie_dev_wakeup_delay(adapter);
507656
508
- /* Accessing fw_status register will wakeup device */
509
- if (mwifiex_write_reg(adapter, reg->fw_status, FIRMWARE_READY_PCIE)) {
510
- mwifiex_dbg(adapter, ERROR,
511
- "Writing fw_status register failed\n");
512
- return -1;
657
+ /* The 88W8897 PCIe+USB firmware (latest version 15.68.19.p21) sometimes
658
+ * appears to ignore or miss our wakeup request, so we continue trying
659
+ * until we receive an interrupt from the card.
660
+ */
661
+ if (read_poll_timeout(mwifiex_write_reg, retval,
662
+ READ_ONCE(adapter->int_status) != 0,
663
+ 500, 500 * N_WAKEUP_TRIES_SHORT_INTERVAL,
664
+ false,
665
+ adapter, reg->fw_status, FIRMWARE_READY_PCIE)) {
666
+ if (read_poll_timeout(mwifiex_write_reg, retval,
667
+ READ_ONCE(adapter->int_status) != 0,
668
+ 10000, 10000 * N_WAKEUP_TRIES_LONG_INTERVAL,
669
+ false,
670
+ adapter, reg->fw_status, FIRMWARE_READY_PCIE)) {
671
+ mwifiex_dbg(adapter, ERROR,
672
+ "Firmware didn't wake up\n");
673
+ return -EIO;
674
+ }
513675 }
514676
515677 if (reg->sleep_cookie) {
....@@ -638,7 +800,7 @@
638800
639801 if (mwifiex_map_pci_memory(adapter, skb,
640802 MWIFIEX_RX_DATA_BUF_SIZE,
641
- PCI_DMA_FROMDEVICE))
803
+ DMA_FROM_DEVICE))
642804 return -1;
643805
644806 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
....@@ -695,7 +857,7 @@
695857 skb_put(skb, MAX_EVENT_SIZE);
696858
697859 if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE,
698
- PCI_DMA_FROMDEVICE)) {
860
+ DMA_FROM_DEVICE)) {
699861 kfree_skb(skb);
700862 kfree(card->evtbd_ring_vbase);
701863 return -1;
....@@ -738,7 +900,7 @@
738900 if (card->tx_buf_list[i]) {
739901 skb = card->tx_buf_list[i];
740902 mwifiex_unmap_pci_memory(adapter, skb,
741
- PCI_DMA_TODEVICE);
903
+ DMA_TO_DEVICE);
742904 dev_kfree_skb_any(skb);
743905 }
744906 memset(desc2, 0, sizeof(*desc2));
....@@ -747,7 +909,7 @@
747909 if (card->tx_buf_list[i]) {
748910 skb = card->tx_buf_list[i];
749911 mwifiex_unmap_pci_memory(adapter, skb,
750
- PCI_DMA_TODEVICE);
912
+ DMA_TO_DEVICE);
751913 dev_kfree_skb_any(skb);
752914 }
753915 memset(desc, 0, sizeof(*desc));
....@@ -777,7 +939,7 @@
777939 if (card->rx_buf_list[i]) {
778940 skb = card->rx_buf_list[i];
779941 mwifiex_unmap_pci_memory(adapter, skb,
780
- PCI_DMA_FROMDEVICE);
942
+ DMA_FROM_DEVICE);
781943 dev_kfree_skb_any(skb);
782944 }
783945 memset(desc2, 0, sizeof(*desc2));
....@@ -786,7 +948,7 @@
786948 if (card->rx_buf_list[i]) {
787949 skb = card->rx_buf_list[i];
788950 mwifiex_unmap_pci_memory(adapter, skb,
789
- PCI_DMA_FROMDEVICE);
951
+ DMA_FROM_DEVICE);
790952 dev_kfree_skb_any(skb);
791953 }
792954 memset(desc, 0, sizeof(*desc));
....@@ -812,7 +974,7 @@
812974 if (card->evt_buf_list[i]) {
813975 skb = card->evt_buf_list[i];
814976 mwifiex_unmap_pci_memory(adapter, skb,
815
- PCI_DMA_FROMDEVICE);
977
+ DMA_FROM_DEVICE);
816978 dev_kfree_skb_any(skb);
817979 }
818980 card->evt_buf_list[i] = NULL;
....@@ -853,18 +1015,20 @@
8531015 mwifiex_dbg(adapter, INFO,
8541016 "info: txbd_ring: Allocating %d bytes\n",
8551017 card->txbd_ring_size);
856
- card->txbd_ring_vbase = pci_alloc_consistent(card->dev,
857
- card->txbd_ring_size,
858
- &card->txbd_ring_pbase);
1018
+ card->txbd_ring_vbase = dma_alloc_coherent(&card->dev->dev,
1019
+ card->txbd_ring_size,
1020
+ &card->txbd_ring_pbase,
1021
+ GFP_KERNEL);
8591022 if (!card->txbd_ring_vbase) {
8601023 mwifiex_dbg(adapter, ERROR,
861
- "allocate consistent memory (%d bytes) failed!\n",
1024
+ "allocate coherent memory (%d bytes) failed!\n",
8621025 card->txbd_ring_size);
8631026 return -ENOMEM;
8641027 }
1028
+
8651029 mwifiex_dbg(adapter, DATA,
866
- "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n",
867
- card->txbd_ring_vbase, (unsigned int)card->txbd_ring_pbase,
1030
+ "info: txbd_ring - base: %p, pbase: %#x:%x, len: %#x\n",
1031
+ card->txbd_ring_vbase, (u32)card->txbd_ring_pbase,
8681032 (u32)((u64)card->txbd_ring_pbase >> 32),
8691033 card->txbd_ring_size);
8701034
....@@ -879,9 +1043,9 @@
8791043 mwifiex_cleanup_txq_ring(adapter);
8801044
8811045 if (card->txbd_ring_vbase)
882
- pci_free_consistent(card->dev, card->txbd_ring_size,
883
- card->txbd_ring_vbase,
884
- card->txbd_ring_pbase);
1046
+ dma_free_coherent(&card->dev->dev, card->txbd_ring_size,
1047
+ card->txbd_ring_vbase,
1048
+ card->txbd_ring_pbase);
8851049 card->txbd_ring_size = 0;
8861050 card->txbd_wrptr = 0;
8871051 card->txbd_rdptr = 0 | reg->tx_rollover_ind;
....@@ -917,12 +1081,13 @@
9171081 mwifiex_dbg(adapter, INFO,
9181082 "info: rxbd_ring: Allocating %d bytes\n",
9191083 card->rxbd_ring_size);
920
- card->rxbd_ring_vbase = pci_alloc_consistent(card->dev,
921
- card->rxbd_ring_size,
922
- &card->rxbd_ring_pbase);
1084
+ card->rxbd_ring_vbase = dma_alloc_coherent(&card->dev->dev,
1085
+ card->rxbd_ring_size,
1086
+ &card->rxbd_ring_pbase,
1087
+ GFP_KERNEL);
9231088 if (!card->rxbd_ring_vbase) {
9241089 mwifiex_dbg(adapter, ERROR,
925
- "allocate consistent memory (%d bytes) failed!\n",
1090
+ "allocate coherent memory (%d bytes) failed!\n",
9261091 card->rxbd_ring_size);
9271092 return -ENOMEM;
9281093 }
....@@ -947,9 +1112,9 @@
9471112 mwifiex_cleanup_rxq_ring(adapter);
9481113
9491114 if (card->rxbd_ring_vbase)
950
- pci_free_consistent(card->dev, card->rxbd_ring_size,
951
- card->rxbd_ring_vbase,
952
- card->rxbd_ring_pbase);
1115
+ dma_free_coherent(&card->dev->dev, card->rxbd_ring_size,
1116
+ card->rxbd_ring_vbase,
1117
+ card->rxbd_ring_pbase);
9531118 card->rxbd_ring_size = 0;
9541119 card->rxbd_wrptr = 0;
9551120 card->rxbd_rdptr = 0 | reg->rx_rollover_ind;
....@@ -980,13 +1145,14 @@
9801145
9811146 mwifiex_dbg(adapter, INFO,
9821147 "info: evtbd_ring: Allocating %d bytes\n",
983
- card->evtbd_ring_size);
984
- card->evtbd_ring_vbase = pci_alloc_consistent(card->dev,
985
- card->evtbd_ring_size,
986
- &card->evtbd_ring_pbase);
1148
+ card->evtbd_ring_size);
1149
+ card->evtbd_ring_vbase = dma_alloc_coherent(&card->dev->dev,
1150
+ card->evtbd_ring_size,
1151
+ &card->evtbd_ring_pbase,
1152
+ GFP_KERNEL);
9871153 if (!card->evtbd_ring_vbase) {
9881154 mwifiex_dbg(adapter, ERROR,
989
- "allocate consistent memory (%d bytes) failed!\n",
1155
+ "allocate coherent memory (%d bytes) failed!\n",
9901156 card->evtbd_ring_size);
9911157 return -ENOMEM;
9921158 }
....@@ -1011,9 +1177,9 @@
10111177 mwifiex_cleanup_evt_ring(adapter);
10121178
10131179 if (card->evtbd_ring_vbase)
1014
- pci_free_consistent(card->dev, card->evtbd_ring_size,
1015
- card->evtbd_ring_vbase,
1016
- card->evtbd_ring_pbase);
1180
+ dma_free_coherent(&card->dev->dev, card->evtbd_ring_size,
1181
+ card->evtbd_ring_vbase,
1182
+ card->evtbd_ring_pbase);
10171183 card->evtbd_wrptr = 0;
10181184 card->evtbd_rdptr = 0 | reg->evt_rollover_ind;
10191185 card->evtbd_ring_size = 0;
....@@ -1040,7 +1206,7 @@
10401206 }
10411207 skb_put(skb, MWIFIEX_UPLD_SIZE);
10421208 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1043
- PCI_DMA_FROMDEVICE)) {
1209
+ DMA_FROM_DEVICE)) {
10441210 kfree_skb(skb);
10451211 return -1;
10461212 }
....@@ -1064,14 +1230,14 @@
10641230
10651231 if (card && card->cmdrsp_buf) {
10661232 mwifiex_unmap_pci_memory(adapter, card->cmdrsp_buf,
1067
- PCI_DMA_FROMDEVICE);
1233
+ DMA_FROM_DEVICE);
10681234 dev_kfree_skb_any(card->cmdrsp_buf);
10691235 card->cmdrsp_buf = NULL;
10701236 }
10711237
10721238 if (card && card->cmd_buf) {
10731239 mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
1074
- PCI_DMA_TODEVICE);
1240
+ DMA_TO_DEVICE);
10751241 dev_kfree_skb_any(card->cmd_buf);
10761242 card->cmd_buf = NULL;
10771243 }
....@@ -1086,11 +1252,13 @@
10861252 struct pcie_service_card *card = adapter->card;
10871253 u32 *cookie;
10881254
1089
- card->sleep_cookie_vbase = pci_alloc_consistent(card->dev, sizeof(u32),
1090
- &card->sleep_cookie_pbase);
1255
+ card->sleep_cookie_vbase = dma_alloc_coherent(&card->dev->dev,
1256
+ sizeof(u32),
1257
+ &card->sleep_cookie_pbase,
1258
+ GFP_KERNEL);
10911259 if (!card->sleep_cookie_vbase) {
10921260 mwifiex_dbg(adapter, ERROR,
1093
- "pci_alloc_consistent failed!\n");
1261
+ "dma_alloc_coherent failed!\n");
10941262 return -ENOMEM;
10951263 }
10961264 cookie = (u32 *)card->sleep_cookie_vbase;
....@@ -1115,9 +1283,9 @@
11151283 card = adapter->card;
11161284
11171285 if (card && card->sleep_cookie_vbase) {
1118
- pci_free_consistent(card->dev, sizeof(u32),
1119
- card->sleep_cookie_vbase,
1120
- card->sleep_cookie_pbase);
1286
+ dma_free_coherent(&card->dev->dev, sizeof(u32),
1287
+ card->sleep_cookie_vbase,
1288
+ card->sleep_cookie_pbase);
11211289 card->sleep_cookie_vbase = NULL;
11221290 }
11231291
....@@ -1189,7 +1357,7 @@
11891357 "SEND COMP: Detach skb %p at txbd_rdidx=%d\n",
11901358 skb, wrdoneidx);
11911359 mwifiex_unmap_pci_memory(adapter, skb,
1192
- PCI_DMA_TODEVICE);
1360
+ DMA_TO_DEVICE);
11931361
11941362 unmap_count++;
11951363
....@@ -1282,7 +1450,7 @@
12821450 put_unaligned_le16(MWIFIEX_TYPE_DATA, payload + 2);
12831451
12841452 if (mwifiex_map_pci_memory(adapter, skb, skb->len,
1285
- PCI_DMA_TODEVICE))
1453
+ DMA_TO_DEVICE))
12861454 return -1;
12871455
12881456 wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;
....@@ -1372,7 +1540,7 @@
13721540
13731541 return -EINPROGRESS;
13741542 done_unmap:
1375
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1543
+ mwifiex_unmap_pci_memory(adapter, skb, DMA_TO_DEVICE);
13761544 card->tx_buf_list[wrindx] = NULL;
13771545 atomic_dec(&adapter->tx_hw_pending);
13781546 if (reg->pfu_enabled)
....@@ -1426,7 +1594,7 @@
14261594 if (!skb_data)
14271595 return -ENOMEM;
14281596
1429
- mwifiex_unmap_pci_memory(adapter, skb_data, PCI_DMA_FROMDEVICE);
1597
+ mwifiex_unmap_pci_memory(adapter, skb_data, DMA_FROM_DEVICE);
14301598 card->rx_buf_list[rd_index] = NULL;
14311599
14321600 /* Get data length from interface header -
....@@ -1464,7 +1632,7 @@
14641632
14651633 if (mwifiex_map_pci_memory(adapter, skb_tmp,
14661634 MWIFIEX_RX_DATA_BUF_SIZE,
1467
- PCI_DMA_FROMDEVICE))
1635
+ DMA_FROM_DEVICE))
14681636 return -1;
14691637
14701638 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb_tmp);
....@@ -1541,7 +1709,7 @@
15411709 return -1;
15421710 }
15431711
1544
- if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE))
1712
+ if (mwifiex_map_pci_memory(adapter, skb, skb->len, DMA_TO_DEVICE))
15451713 return -1;
15461714
15471715 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
....@@ -1553,7 +1721,7 @@
15531721 mwifiex_dbg(adapter, ERROR,
15541722 "%s: failed to write download command to boot code.\n",
15551723 __func__);
1556
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1724
+ mwifiex_unmap_pci_memory(adapter, skb, DMA_TO_DEVICE);
15571725 return -1;
15581726 }
15591727
....@@ -1565,7 +1733,7 @@
15651733 mwifiex_dbg(adapter, ERROR,
15661734 "%s: failed to write download command to boot code.\n",
15671735 __func__);
1568
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1736
+ mwifiex_unmap_pci_memory(adapter, skb, DMA_TO_DEVICE);
15691737 return -1;
15701738 }
15711739
....@@ -1574,7 +1742,7 @@
15741742 mwifiex_dbg(adapter, ERROR,
15751743 "%s: failed to write command len to cmd_size scratch reg\n",
15761744 __func__);
1577
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1745
+ mwifiex_unmap_pci_memory(adapter, skb, DMA_TO_DEVICE);
15781746 return -1;
15791747 }
15801748
....@@ -1583,7 +1751,7 @@
15831751 CPU_INTR_DOOR_BELL)) {
15841752 mwifiex_dbg(adapter, ERROR,
15851753 "%s: failed to assert door-bell intr\n", __func__);
1586
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1754
+ mwifiex_unmap_pci_memory(adapter, skb, DMA_TO_DEVICE);
15871755 return -1;
15881756 }
15891757
....@@ -1642,7 +1810,7 @@
16421810 put_unaligned_le16((u16)skb->len, &payload[0]);
16431811 put_unaligned_le16(MWIFIEX_TYPE_CMD, &payload[2]);
16441812
1645
- if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE))
1813
+ if (mwifiex_map_pci_memory(adapter, skb, skb->len, DMA_TO_DEVICE))
16461814 return -1;
16471815
16481816 card->cmd_buf = skb;
....@@ -1742,17 +1910,16 @@
17421910 "info: Rx CMD Response\n");
17431911
17441912 if (adapter->curr_cmd)
1745
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_FROMDEVICE);
1913
+ mwifiex_unmap_pci_memory(adapter, skb, DMA_FROM_DEVICE);
17461914 else
1747
- pci_dma_sync_single_for_cpu(card->dev,
1748
- MWIFIEX_SKB_DMA_ADDR(skb),
1749
- MWIFIEX_UPLD_SIZE,
1750
- PCI_DMA_FROMDEVICE);
1915
+ dma_sync_single_for_cpu(&card->dev->dev,
1916
+ MWIFIEX_SKB_DMA_ADDR(skb),
1917
+ MWIFIEX_UPLD_SIZE, DMA_FROM_DEVICE);
17511918
17521919 /* Unmap the command as a response has been received. */
17531920 if (card->cmd_buf) {
17541921 mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
1755
- PCI_DMA_TODEVICE);
1922
+ DMA_TO_DEVICE);
17561923 dev_kfree_skb_any(card->cmd_buf);
17571924 card->cmd_buf = NULL;
17581925 }
....@@ -1763,10 +1930,10 @@
17631930
17641931 if (!adapter->curr_cmd) {
17651932 if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
1766
- pci_dma_sync_single_for_device(card->dev,
1767
- MWIFIEX_SKB_DMA_ADDR(skb),
1768
- MWIFIEX_SLEEP_COOKIE_SIZE,
1769
- PCI_DMA_FROMDEVICE);
1933
+ dma_sync_single_for_device(&card->dev->dev,
1934
+ MWIFIEX_SKB_DMA_ADDR(skb),
1935
+ MWIFIEX_SLEEP_COOKIE_SIZE,
1936
+ DMA_FROM_DEVICE);
17701937 if (mwifiex_write_reg(adapter,
17711938 PCIE_CPU_INT_EVENT,
17721939 CPU_INTR_SLEEP_CFM_DONE)) {
....@@ -1777,7 +1944,7 @@
17771944 mwifiex_delay_for_sleep_cookie(adapter,
17781945 MWIFIEX_MAX_DELAY_COUNT);
17791946 mwifiex_unmap_pci_memory(adapter, skb,
1780
- PCI_DMA_FROMDEVICE);
1947
+ DMA_FROM_DEVICE);
17811948 skb_pull(skb, adapter->intf_hdr_len);
17821949 while (reg->sleep_cookie && (count++ < 10) &&
17831950 mwifiex_pcie_ok_to_access_hw(adapter))
....@@ -1793,7 +1960,7 @@
17931960 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len));
17941961 skb_push(skb, adapter->intf_hdr_len);
17951962 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1796
- PCI_DMA_FROMDEVICE))
1963
+ DMA_FROM_DEVICE))
17971964 return -1;
17981965 } else if (mwifiex_pcie_ok_to_access_hw(adapter)) {
17991966 skb_pull(skb, adapter->intf_hdr_len);
....@@ -1835,7 +2002,7 @@
18352002 card->cmdrsp_buf = skb;
18362003 skb_push(card->cmdrsp_buf, adapter->intf_hdr_len);
18372004 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1838
- PCI_DMA_FROMDEVICE))
2005
+ DMA_FROM_DEVICE))
18392006 return -1;
18402007 }
18412008
....@@ -1890,7 +2057,7 @@
18902057 mwifiex_dbg(adapter, INFO,
18912058 "info: Read Index: %d\n", rdptr);
18922059 skb_cmd = card->evt_buf_list[rdptr];
1893
- mwifiex_unmap_pci_memory(adapter, skb_cmd, PCI_DMA_FROMDEVICE);
2060
+ mwifiex_unmap_pci_memory(adapter, skb_cmd, DMA_FROM_DEVICE);
18942061
18952062 /* Take the pointer and set it to event pointer in adapter
18962063 and will return back after event handling callback */
....@@ -1970,7 +2137,7 @@
19702137 skb_put(skb, MAX_EVENT_SIZE - skb->len);
19712138 if (mwifiex_map_pci_memory(adapter, skb,
19722139 MAX_EVENT_SIZE,
1973
- PCI_DMA_FROMDEVICE))
2140
+ DMA_FROM_DEVICE))
19742141 return -1;
19752142 card->evt_buf_list[rdptr] = skb;
19762143 desc = card->evtbd_ring[rdptr];
....@@ -2252,7 +2419,7 @@
22522419 "interrupt status during fw dnld.\n",
22532420 __func__);
22542421 mwifiex_unmap_pci_memory(adapter, skb,
2255
- PCI_DMA_TODEVICE);
2422
+ DMA_TO_DEVICE);
22562423 ret = -1;
22572424 goto done;
22582425 }
....@@ -2264,12 +2431,12 @@
22642431 mwifiex_dbg(adapter, ERROR, "%s: Card failed to ACK download\n",
22652432 __func__);
22662433 mwifiex_unmap_pci_memory(adapter, skb,
2267
- PCI_DMA_TODEVICE);
2434
+ DMA_TO_DEVICE);
22682435 ret = -1;
22692436 goto done;
22702437 }
22712438
2272
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
2439
+ mwifiex_unmap_pci_memory(adapter, skb, DMA_TO_DEVICE);
22732440
22742441 offset += txlen;
22752442 } while (true);
....@@ -2939,16 +3106,9 @@
29393106
29403107 pci_set_master(pdev);
29413108
2942
- pr_notice("try set_consistent_dma_mask(32)\n");
2943
- ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
3109
+ ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
29443110 if (ret) {
2945
- pr_err("set_dma_mask(32) failed\n");
2946
- goto err_set_dma_mask;
2947
- }
2948
-
2949
- ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2950
- if (ret) {
2951
- pr_err("set_consistent_dma_mask(64) failed\n");
3111
+ pr_err("dma_set_mask(32) failed: %d\n", ret);
29523112 goto err_set_dma_mask;
29533113 }
29543114
....@@ -2975,13 +3135,16 @@
29753135 goto err_iomap2;
29763136 }
29773137
2978
- pr_notice("PCI memory map Virt0: %p PCI memory map Virt2: %p\n",
3138
+ pr_notice("PCI memory map Virt0: %pK PCI memory map Virt2: %pK\n",
29793139 card->pci_mmap, card->pci_mmap1);
29803140
29813141 ret = mwifiex_pcie_alloc_buffers(adapter);
29823142 if (ret)
29833143 goto err_alloc_buffers;
29843144
3145
+ if (pdev->device == PCIE_DEVICE_ID_MARVELL_88W8897)
3146
+ adapter->ignore_btcoex_events = true;
3147
+
29853148 return 0;
29863149
29873150 err_alloc_buffers: