blob: 3c224a793b820a234bfeb6b573394cc884fbce6a [file] [log] [blame]
Amitkumar Karward930fae2011-10-11 17:41:21 -07001/*
2 * Marvell Wireless LAN device driver: PCIE specific handling
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Amitkumar Karward930fae2011-10-11 17:41:21 -07005 *
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
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include <linux/firmware.h>
21
22#include "decl.h"
23#include "ioctl.h"
24#include "util.h"
25#include "fw.h"
26#include "main.h"
27#include "wmm.h"
28#include "11n.h"
29#include "pcie.h"
30
31#define PCIE_VERSION "1.0"
32#define DRV_NAME "Marvell mwifiex PCIe"
33
34static u8 user_rmmod;
35
36static struct mwifiex_if_ops pcie_ops;
37
38static struct semaphore add_remove_card_sem;
Amitkumar Karward930fae2011-10-11 17:41:21 -070039
Amitkumar Karwar92c25382014-06-19 21:38:52 -070040static struct memory_type_mapping mem_type_mapping_tbl[] = {
41 {"ITCM", NULL, 0, 0xF0},
42 {"DTCM", NULL, 0, 0xF1},
43 {"SQRAM", NULL, 0, 0xF2},
44 {"IRAM", NULL, 0, 0xF3},
45};
46
Avinash Patilfc331462013-01-03 21:21:30 -080047static int
48mwifiex_map_pci_memory(struct mwifiex_adapter *adapter, struct sk_buff *skb,
Aaron Durbindbccc922014-02-07 16:25:50 -080049 size_t size, int flags)
Amitkumar Karward930fae2011-10-11 17:41:21 -070050{
Avinash Patilfc331462013-01-03 21:21:30 -080051 struct pcie_service_card *card = adapter->card;
Aaron Durbindbccc922014-02-07 16:25:50 -080052 struct mwifiex_dma_mapping mapping;
Amitkumar Karward930fae2011-10-11 17:41:21 -070053
Aaron Durbindbccc922014-02-07 16:25:50 -080054 mapping.addr = pci_map_single(card->dev, skb->data, size, flags);
55 if (pci_dma_mapping_error(card->dev, mapping.addr)) {
Avinash Patilfc331462013-01-03 21:21:30 -080056 dev_err(adapter->dev, "failed to map pci memory!\n");
57 return -1;
58 }
Aaron Durbindbccc922014-02-07 16:25:50 -080059 mapping.len = size;
60 memcpy(skb->cb, &mapping, sizeof(mapping));
Avinash Patilfc331462013-01-03 21:21:30 -080061 return 0;
Amitkumar Karward930fae2011-10-11 17:41:21 -070062}
63
Aaron Durbindbccc922014-02-07 16:25:50 -080064static void mwifiex_unmap_pci_memory(struct mwifiex_adapter *adapter,
65 struct sk_buff *skb, int flags)
66{
67 struct pcie_service_card *card = adapter->card;
68 struct mwifiex_dma_mapping mapping;
69
70 MWIFIEX_SKB_PACB(skb, &mapping);
71 pci_unmap_single(card->dev, mapping.addr, mapping.len, flags);
72}
73
Amitkumar Karward930fae2011-10-11 17:41:21 -070074/*
75 * This function reads sleep cookie and checks if FW is ready
76 */
77static bool mwifiex_pcie_ok_to_access_hw(struct mwifiex_adapter *adapter)
78{
79 u32 *cookie_addr;
80 struct pcie_service_card *card = adapter->card;
Avinash Patil52301a82013-02-12 14:38:32 -080081 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
82
83 if (!reg->sleep_cookie)
84 return true;
Amitkumar Karward930fae2011-10-11 17:41:21 -070085
Avinash Patilfc331462013-01-03 21:21:30 -080086 if (card->sleep_cookie_vbase) {
87 cookie_addr = (u32 *)card->sleep_cookie_vbase;
Amitkumar Karward930fae2011-10-11 17:41:21 -070088 dev_dbg(adapter->dev, "info: ACCESS_HW: sleep cookie=0x%x\n",
89 *cookie_addr);
90 if (*cookie_addr == FW_AWAKE_COOKIE)
91 return true;
92 }
93
94 return false;
95}
96
Shuah Khan3266d732013-07-03 10:47:10 -060097#ifdef CONFIG_PM_SLEEP
Amitkumar Karward930fae2011-10-11 17:41:21 -070098/*
Bing Zhaofcca8d52013-03-04 16:27:53 -080099 * Kernel needs to suspend all functions separately. Therefore all
100 * registered functions must have drivers with suspend and resume
101 * methods. Failing that the kernel simply removes the whole card.
102 *
103 * If already not suspended, this function allocates and sends a host
104 * sleep activate request to the firmware and turns off the traffic.
105 */
Shuah Khan3266d732013-07-03 10:47:10 -0600106static int mwifiex_pcie_suspend(struct device *dev)
Bing Zhaofcca8d52013-03-04 16:27:53 -0800107{
108 struct mwifiex_adapter *adapter;
109 struct pcie_service_card *card;
110 int hs_actived;
Shuah Khan3266d732013-07-03 10:47:10 -0600111 struct pci_dev *pdev = to_pci_dev(dev);
Bing Zhaofcca8d52013-03-04 16:27:53 -0800112
113 if (pdev) {
Jingoo Hanb2a31202013-09-09 14:26:51 +0900114 card = pci_get_drvdata(pdev);
Bing Zhaofcca8d52013-03-04 16:27:53 -0800115 if (!card || !card->adapter) {
116 pr_err("Card or adapter structure is not valid\n");
117 return 0;
118 }
119 } else {
120 pr_err("PCIE device is not specified\n");
121 return 0;
122 }
123
124 adapter = card->adapter;
125
126 hs_actived = mwifiex_enable_hs(adapter);
127
128 /* Indicate device suspended */
129 adapter->is_suspended = true;
Amitkumar Karwarc0dbba62014-03-25 19:01:20 -0700130 adapter->hs_enabling = false;
Bing Zhaofcca8d52013-03-04 16:27:53 -0800131
132 return 0;
133}
134
135/*
136 * Kernel needs to suspend all functions separately. Therefore all
137 * registered functions must have drivers with suspend and resume
138 * methods. Failing that the kernel simply removes the whole card.
139 *
140 * If already not resumed, this function turns on the traffic and
141 * sends a host sleep cancel request to the firmware.
142 */
Shuah Khan3266d732013-07-03 10:47:10 -0600143static int mwifiex_pcie_resume(struct device *dev)
Bing Zhaofcca8d52013-03-04 16:27:53 -0800144{
145 struct mwifiex_adapter *adapter;
146 struct pcie_service_card *card;
Shuah Khan3266d732013-07-03 10:47:10 -0600147 struct pci_dev *pdev = to_pci_dev(dev);
Bing Zhaofcca8d52013-03-04 16:27:53 -0800148
149 if (pdev) {
Jingoo Hanb2a31202013-09-09 14:26:51 +0900150 card = pci_get_drvdata(pdev);
Bing Zhaofcca8d52013-03-04 16:27:53 -0800151 if (!card || !card->adapter) {
152 pr_err("Card or adapter structure is not valid\n");
153 return 0;
154 }
155 } else {
156 pr_err("PCIE device is not specified\n");
157 return 0;
158 }
159
160 adapter = card->adapter;
161
162 if (!adapter->is_suspended) {
163 dev_warn(adapter->dev, "Device already resumed\n");
164 return 0;
165 }
166
167 adapter->is_suspended = false;
168
169 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
170 MWIFIEX_ASYNC_CMD);
171
172 return 0;
173}
Bing Zhao8509e822013-03-04 16:27:54 -0800174#endif
Bing Zhaofcca8d52013-03-04 16:27:53 -0800175
176/*
Amitkumar Karward930fae2011-10-11 17:41:21 -0700177 * This function probes an mwifiex device and registers it. It allocates
178 * the card structure, enables PCIE function number and initiates the
179 * device registration and initialization procedure by adding a logical
180 * interface.
181 */
182static int mwifiex_pcie_probe(struct pci_dev *pdev,
183 const struct pci_device_id *ent)
184{
185 struct pcie_service_card *card;
186
187 pr_debug("info: vendor=0x%4.04X device=0x%4.04X rev=%d\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700188 pdev->vendor, pdev->device, pdev->revision);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700189
190 card = kzalloc(sizeof(struct pcie_service_card), GFP_KERNEL);
Joe Perchese404dec2012-01-29 12:56:23 +0000191 if (!card)
Amitkumar Karward930fae2011-10-11 17:41:21 -0700192 return -ENOMEM;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700193
194 card->dev = pdev;
195
Avinash Patildd04e6a2013-02-08 18:18:06 -0800196 if (ent->driver_data) {
197 struct mwifiex_pcie_device *data = (void *)ent->driver_data;
198 card->pcie.firmware = data->firmware;
199 card->pcie.reg = data->reg;
200 card->pcie.blksz_fw_dl = data->blksz_fw_dl;
Amitkumar Karwar828cf222014-02-27 19:35:13 -0800201 card->pcie.tx_buf_size = data->tx_buf_size;
Amitkumar Karwar92c25382014-06-19 21:38:52 -0700202 card->pcie.supports_fw_dump = data->supports_fw_dump;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800203 }
204
Amitkumar Karward930fae2011-10-11 17:41:21 -0700205 if (mwifiex_add_card(card, &add_remove_card_sem, &pcie_ops,
206 MWIFIEX_PCIE)) {
207 pr_err("%s failed\n", __func__);
208 kfree(card);
209 return -1;
210 }
211
212 return 0;
213}
214
215/*
216 * This function removes the interface and frees up the card structure.
217 */
218static void mwifiex_pcie_remove(struct pci_dev *pdev)
219{
220 struct pcie_service_card *card;
221 struct mwifiex_adapter *adapter;
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700222 struct mwifiex_private *priv;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700223
224 card = pci_get_drvdata(pdev);
225 if (!card)
226 return;
227
228 adapter = card->adapter;
229 if (!adapter || !adapter->priv_num)
230 return;
231
Amitkumar Karwar92c25382014-06-19 21:38:52 -0700232 cancel_work_sync(&adapter->iface_work);
233
Amitkumar Karward930fae2011-10-11 17:41:21 -0700234 if (user_rmmod) {
Shuah Khan3266d732013-07-03 10:47:10 -0600235#ifdef CONFIG_PM_SLEEP
Amitkumar Karward930fae2011-10-11 17:41:21 -0700236 if (adapter->is_suspended)
Shuah Khan3266d732013-07-03 10:47:10 -0600237 mwifiex_pcie_resume(&pdev->dev);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700238#endif
239
Amitkumar Karwar848819f2014-02-27 19:35:17 -0800240 mwifiex_deauthenticate_all(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700241
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700242 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700243
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700244 mwifiex_disable_auto_ds(priv);
245
246 mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700247 }
248
249 mwifiex_remove_card(card->adapter, &add_remove_card_sem);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700250}
251
Amitkumar Karwar43ba6b92013-07-22 19:17:47 -0700252static void mwifiex_pcie_shutdown(struct pci_dev *pdev)
253{
254 user_rmmod = 1;
255 mwifiex_pcie_remove(pdev);
256
257 return;
258}
259
Amitkumar Karward930fae2011-10-11 17:41:21 -0700260static DEFINE_PCI_DEVICE_TABLE(mwifiex_ids) = {
261 {
262 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8766P,
263 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
Avinash Patildd04e6a2013-02-08 18:18:06 -0800264 .driver_data = (unsigned long) &mwifiex_pcie8766,
Amitkumar Karward930fae2011-10-11 17:41:21 -0700265 },
Avinash Patilca8f2112013-02-08 18:18:09 -0800266 {
267 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8897,
268 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
269 .driver_data = (unsigned long) &mwifiex_pcie8897,
270 },
Amitkumar Karward930fae2011-10-11 17:41:21 -0700271 {},
272};
273
274MODULE_DEVICE_TABLE(pci, mwifiex_ids);
275
Shuah Khan3266d732013-07-03 10:47:10 -0600276#ifdef CONFIG_PM_SLEEP
277/* Power Management Hooks */
278static SIMPLE_DEV_PM_OPS(mwifiex_pcie_pm_ops, mwifiex_pcie_suspend,
279 mwifiex_pcie_resume);
280#endif
281
Amitkumar Karward930fae2011-10-11 17:41:21 -0700282/* PCI Device Driver */
283static struct pci_driver __refdata mwifiex_pcie = {
284 .name = "mwifiex_pcie",
285 .id_table = mwifiex_ids,
286 .probe = mwifiex_pcie_probe,
287 .remove = mwifiex_pcie_remove,
Shuah Khan3266d732013-07-03 10:47:10 -0600288#ifdef CONFIG_PM_SLEEP
289 .driver = {
290 .pm = &mwifiex_pcie_pm_ops,
291 },
Amitkumar Karward930fae2011-10-11 17:41:21 -0700292#endif
Amitkumar Karwar43ba6b92013-07-22 19:17:47 -0700293 .shutdown = mwifiex_pcie_shutdown,
Amitkumar Karward930fae2011-10-11 17:41:21 -0700294};
295
296/*
297 * This function writes data into PCIE card register.
298 */
299static int mwifiex_write_reg(struct mwifiex_adapter *adapter, int reg, u32 data)
300{
301 struct pcie_service_card *card = adapter->card;
302
303 iowrite32(data, card->pci_mmap1 + reg);
304
305 return 0;
306}
307
308/*
309 * This function reads data from PCIE card register.
310 */
311static int mwifiex_read_reg(struct mwifiex_adapter *adapter, int reg, u32 *data)
312{
313 struct pcie_service_card *card = adapter->card;
314
315 *data = ioread32(card->pci_mmap1 + reg);
316
317 return 0;
318}
319
Amitkumar Karwar92c25382014-06-19 21:38:52 -0700320/* This function reads u8 data from PCIE card register. */
321static int mwifiex_read_reg_byte(struct mwifiex_adapter *adapter,
322 int reg, u8 *data)
323{
324 struct pcie_service_card *card = adapter->card;
325
326 *data = ioread8(card->pci_mmap1 + reg);
327
328 return 0;
329}
330
Amitkumar Karward930fae2011-10-11 17:41:21 -0700331/*
Avinash Patilc0880a22013-03-22 21:49:07 -0700332 * This function adds delay loop to ensure FW is awake before proceeding.
Amitkumar Karward930fae2011-10-11 17:41:21 -0700333 */
Avinash Patilc0880a22013-03-22 21:49:07 -0700334static void mwifiex_pcie_dev_wakeup_delay(struct mwifiex_adapter *adapter)
Amitkumar Karward930fae2011-10-11 17:41:21 -0700335{
336 int i = 0;
337
Avinash Patilc0880a22013-03-22 21:49:07 -0700338 while (mwifiex_pcie_ok_to_access_hw(adapter)) {
Amitkumar Karward930fae2011-10-11 17:41:21 -0700339 i++;
Yogesh Ashok Poware7891ba2012-03-12 19:35:11 -0700340 usleep_range(10, 20);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700341 /* 50ms max wait */
Avinash Patil3e7a4ff2013-02-25 16:01:34 -0800342 if (i == 5000)
Amitkumar Karward930fae2011-10-11 17:41:21 -0700343 break;
344 }
345
Avinash Patilc0880a22013-03-22 21:49:07 -0700346 return;
347}
348
Avinash Patilc4bc9802014-03-18 22:19:17 -0700349static void mwifiex_delay_for_sleep_cookie(struct mwifiex_adapter *adapter,
350 u32 max_delay_loop_cnt)
351{
352 struct pcie_service_card *card = adapter->card;
353 u8 *buffer;
354 u32 sleep_cookie, count;
355
356 for (count = 0; count < max_delay_loop_cnt; count++) {
357 buffer = card->cmdrsp_buf->data - INTF_HEADER_LEN;
358 sleep_cookie = *(u32 *)buffer;
359
360 if (sleep_cookie == MWIFIEX_DEF_SLEEP_COOKIE) {
361 dev_dbg(adapter->dev,
362 "sleep cookie found at count %d\n", count);
363 break;
364 }
365 usleep_range(20, 30);
366 }
367
368 if (count >= max_delay_loop_cnt)
369 dev_dbg(adapter->dev,
370 "max count reached while accessing sleep cookie\n");
371}
372
Avinash Patilc0880a22013-03-22 21:49:07 -0700373/* This function wakes up the card by reading fw_status register. */
374static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
375{
376 u32 fw_status;
377 struct pcie_service_card *card = adapter->card;
378 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
379
Amitkumar Karward930fae2011-10-11 17:41:21 -0700380 dev_dbg(adapter->dev, "event: Wakeup device...\n");
381
Avinash Patilc0880a22013-03-22 21:49:07 -0700382 if (reg->sleep_cookie)
383 mwifiex_pcie_dev_wakeup_delay(adapter);
384
385 /* Reading fw_status register will wakeup device */
386 if (mwifiex_read_reg(adapter, reg->fw_status, &fw_status)) {
387 dev_warn(adapter->dev, "Reading fw_status register failed\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -0700388 return -1;
389 }
390
Avinash Patilc0880a22013-03-22 21:49:07 -0700391 if (reg->sleep_cookie) {
392 mwifiex_pcie_dev_wakeup_delay(adapter);
393 dev_dbg(adapter->dev, "PCIE wakeup: Setting PS_STATE_AWAKE\n");
394 adapter->ps_state = PS_STATE_AWAKE;
395 }
Amitkumar Karward930fae2011-10-11 17:41:21 -0700396
397 return 0;
398}
399
400/*
401 * This function is called after the card has woken up.
402 *
403 * The card configuration register is reset.
404 */
405static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
406{
407 dev_dbg(adapter->dev, "cmd: Wakeup device completed\n");
408
409 return 0;
410}
411
412/*
413 * This function disables the host interrupt.
414 *
415 * The host interrupt mask is read, the disable bit is reset and
416 * written back to the card host interrupt mask register.
417 */
418static int mwifiex_pcie_disable_host_int(struct mwifiex_adapter *adapter)
419{
420 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
421 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK,
422 0x00000000)) {
423 dev_warn(adapter->dev, "Disable host interrupt failed\n");
424 return -1;
425 }
426 }
427
428 return 0;
429}
430
431/*
432 * This function enables the host interrupt.
433 *
434 * The host interrupt enable mask is written to the card
435 * host interrupt mask register.
436 */
437static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter)
438{
439 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
440 /* Simply write the mask to the register */
441 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK,
442 HOST_INTR_MASK)) {
443 dev_warn(adapter->dev, "Enable host interrupt failed\n");
444 return -1;
445 }
446 }
447
448 return 0;
449}
450
451/*
Avinash Patil07324842013-02-08 18:18:07 -0800452 * This function initializes TX buffer ring descriptors
453 */
454static int mwifiex_init_txq_ring(struct mwifiex_adapter *adapter)
455{
456 struct pcie_service_card *card = adapter->card;
Avinash Patilca8f2112013-02-08 18:18:09 -0800457 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Avinash Patil07324842013-02-08 18:18:07 -0800458 struct mwifiex_pcie_buf_desc *desc;
Avinash Patilca8f2112013-02-08 18:18:09 -0800459 struct mwifiex_pfu_buf_desc *desc2;
Avinash Patil07324842013-02-08 18:18:07 -0800460 int i;
461
462 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
463 card->tx_buf_list[i] = NULL;
Avinash Patilca8f2112013-02-08 18:18:09 -0800464 if (reg->pfu_enabled) {
465 card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
466 (sizeof(*desc2) * i);
467 desc2 = card->txbd_ring[i];
468 memset(desc2, 0, sizeof(*desc2));
469 } else {
470 card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
471 (sizeof(*desc) * i);
472 desc = card->txbd_ring[i];
473 memset(desc, 0, sizeof(*desc));
474 }
Avinash Patil07324842013-02-08 18:18:07 -0800475 }
476
477 return 0;
478}
479
480/* This function initializes RX buffer ring descriptors. Each SKB is allocated
481 * here and after mapping PCI memory, its physical address is assigned to
482 * PCIE Rx buffer descriptor's physical address.
483 */
484static int mwifiex_init_rxq_ring(struct mwifiex_adapter *adapter)
485{
486 struct pcie_service_card *card = adapter->card;
Avinash Patilca8f2112013-02-08 18:18:09 -0800487 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Avinash Patil07324842013-02-08 18:18:07 -0800488 struct sk_buff *skb;
489 struct mwifiex_pcie_buf_desc *desc;
Avinash Patilca8f2112013-02-08 18:18:09 -0800490 struct mwifiex_pfu_buf_desc *desc2;
Avinash Patil07324842013-02-08 18:18:07 -0800491 dma_addr_t buf_pa;
492 int i;
493
494 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
495 /* Allocate skb here so that firmware can DMA data from it */
496 skb = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE);
497 if (!skb) {
498 dev_err(adapter->dev,
499 "Unable to allocate skb for RX ring.\n");
500 kfree(card->rxbd_ring_vbase);
501 return -ENOMEM;
502 }
503
504 if (mwifiex_map_pci_memory(adapter, skb,
505 MWIFIEX_RX_DATA_BUF_SIZE,
506 PCI_DMA_FROMDEVICE))
507 return -1;
508
Aaron Durbindbccc922014-02-07 16:25:50 -0800509 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
Avinash Patil07324842013-02-08 18:18:07 -0800510
511 dev_dbg(adapter->dev,
512 "info: RX ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
513 skb, skb->len, skb->data, (u32)buf_pa,
514 (u32)((u64)buf_pa >> 32));
515
516 card->rx_buf_list[i] = skb;
Avinash Patilca8f2112013-02-08 18:18:09 -0800517 if (reg->pfu_enabled) {
518 card->rxbd_ring[i] = (void *)card->rxbd_ring_vbase +
519 (sizeof(*desc2) * i);
520 desc2 = card->rxbd_ring[i];
521 desc2->paddr = buf_pa;
522 desc2->len = (u16)skb->len;
523 desc2->frag_len = (u16)skb->len;
524 desc2->flags = reg->ring_flag_eop | reg->ring_flag_sop;
525 desc2->offset = 0;
526 } else {
527 card->rxbd_ring[i] = (void *)(card->rxbd_ring_vbase +
528 (sizeof(*desc) * i));
529 desc = card->rxbd_ring[i];
530 desc->paddr = buf_pa;
531 desc->len = (u16)skb->len;
532 desc->flags = 0;
533 }
Avinash Patil07324842013-02-08 18:18:07 -0800534 }
535
536 return 0;
537}
538
539/* This function initializes event buffer ring descriptors. Each SKB is
540 * allocated here and after mapping PCI memory, its physical address is assigned
541 * to PCIE Rx buffer descriptor's physical address
542 */
543static int mwifiex_pcie_init_evt_ring(struct mwifiex_adapter *adapter)
544{
545 struct pcie_service_card *card = adapter->card;
Avinash Patile05dc3e2013-02-08 18:18:08 -0800546 struct mwifiex_evt_buf_desc *desc;
Avinash Patil07324842013-02-08 18:18:07 -0800547 struct sk_buff *skb;
548 dma_addr_t buf_pa;
549 int i;
550
551 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
552 /* Allocate skb here so that firmware can DMA data from it */
553 skb = dev_alloc_skb(MAX_EVENT_SIZE);
554 if (!skb) {
555 dev_err(adapter->dev,
556 "Unable to allocate skb for EVENT buf.\n");
557 kfree(card->evtbd_ring_vbase);
558 return -ENOMEM;
559 }
560 skb_put(skb, MAX_EVENT_SIZE);
561
562 if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE,
563 PCI_DMA_FROMDEVICE))
564 return -1;
565
Aaron Durbindbccc922014-02-07 16:25:50 -0800566 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
Avinash Patil07324842013-02-08 18:18:07 -0800567
568 dev_dbg(adapter->dev,
569 "info: EVT ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
570 skb, skb->len, skb->data, (u32)buf_pa,
571 (u32)((u64)buf_pa >> 32));
572
573 card->evt_buf_list[i] = skb;
574 card->evtbd_ring[i] = (void *)(card->evtbd_ring_vbase +
575 (sizeof(*desc) * i));
Avinash Patil07324842013-02-08 18:18:07 -0800576 desc = card->evtbd_ring[i];
577 desc->paddr = buf_pa;
578 desc->len = (u16)skb->len;
579 desc->flags = 0;
580 }
581
582 return 0;
583}
584
585/* This function cleans up TX buffer rings. If any of the buffer list has valid
586 * SKB address, associated SKB is freed.
587 */
588static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter)
589{
590 struct pcie_service_card *card = adapter->card;
Avinash Patilca8f2112013-02-08 18:18:09 -0800591 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Avinash Patil07324842013-02-08 18:18:07 -0800592 struct sk_buff *skb;
593 struct mwifiex_pcie_buf_desc *desc;
Avinash Patilca8f2112013-02-08 18:18:09 -0800594 struct mwifiex_pfu_buf_desc *desc2;
Avinash Patil07324842013-02-08 18:18:07 -0800595 int i;
596
597 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
Avinash Patilca8f2112013-02-08 18:18:09 -0800598 if (reg->pfu_enabled) {
599 desc2 = card->txbd_ring[i];
600 if (card->tx_buf_list[i]) {
601 skb = card->tx_buf_list[i];
Aaron Durbindbccc922014-02-07 16:25:50 -0800602 mwifiex_unmap_pci_memory(adapter, skb,
603 PCI_DMA_TODEVICE);
Avinash Patilca8f2112013-02-08 18:18:09 -0800604 dev_kfree_skb_any(skb);
605 }
606 memset(desc2, 0, sizeof(*desc2));
607 } else {
608 desc = card->txbd_ring[i];
609 if (card->tx_buf_list[i]) {
610 skb = card->tx_buf_list[i];
Aaron Durbindbccc922014-02-07 16:25:50 -0800611 mwifiex_unmap_pci_memory(adapter, skb,
612 PCI_DMA_TODEVICE);
Avinash Patilca8f2112013-02-08 18:18:09 -0800613 dev_kfree_skb_any(skb);
614 }
615 memset(desc, 0, sizeof(*desc));
Avinash Patil07324842013-02-08 18:18:07 -0800616 }
617 card->tx_buf_list[i] = NULL;
Avinash Patil07324842013-02-08 18:18:07 -0800618 }
619
620 return;
621}
622
623/* This function cleans up RX buffer rings. If any of the buffer list has valid
624 * SKB address, associated SKB is freed.
625 */
626static void mwifiex_cleanup_rxq_ring(struct mwifiex_adapter *adapter)
627{
628 struct pcie_service_card *card = adapter->card;
Avinash Patilca8f2112013-02-08 18:18:09 -0800629 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Avinash Patil07324842013-02-08 18:18:07 -0800630 struct mwifiex_pcie_buf_desc *desc;
Avinash Patilca8f2112013-02-08 18:18:09 -0800631 struct mwifiex_pfu_buf_desc *desc2;
Avinash Patil07324842013-02-08 18:18:07 -0800632 struct sk_buff *skb;
633 int i;
634
635 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
Avinash Patilca8f2112013-02-08 18:18:09 -0800636 if (reg->pfu_enabled) {
637 desc2 = card->rxbd_ring[i];
638 if (card->rx_buf_list[i]) {
639 skb = card->rx_buf_list[i];
Aaron Durbindbccc922014-02-07 16:25:50 -0800640 mwifiex_unmap_pci_memory(adapter, skb,
641 PCI_DMA_FROMDEVICE);
Avinash Patilca8f2112013-02-08 18:18:09 -0800642 dev_kfree_skb_any(skb);
643 }
644 memset(desc2, 0, sizeof(*desc2));
645 } else {
646 desc = card->rxbd_ring[i];
647 if (card->rx_buf_list[i]) {
648 skb = card->rx_buf_list[i];
Aaron Durbindbccc922014-02-07 16:25:50 -0800649 mwifiex_unmap_pci_memory(adapter, skb,
650 PCI_DMA_FROMDEVICE);
Avinash Patilca8f2112013-02-08 18:18:09 -0800651 dev_kfree_skb_any(skb);
652 }
653 memset(desc, 0, sizeof(*desc));
Avinash Patil07324842013-02-08 18:18:07 -0800654 }
Avinash Patilca8f2112013-02-08 18:18:09 -0800655 card->rx_buf_list[i] = NULL;
Avinash Patil07324842013-02-08 18:18:07 -0800656 }
657
658 return;
659}
660
661/* This function cleans up event buffer rings. If any of the buffer list has
662 * valid SKB address, associated SKB is freed.
663 */
664static void mwifiex_cleanup_evt_ring(struct mwifiex_adapter *adapter)
665{
666 struct pcie_service_card *card = adapter->card;
Avinash Patile05dc3e2013-02-08 18:18:08 -0800667 struct mwifiex_evt_buf_desc *desc;
Avinash Patil07324842013-02-08 18:18:07 -0800668 struct sk_buff *skb;
669 int i;
670
671 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
672 desc = card->evtbd_ring[i];
673 if (card->evt_buf_list[i]) {
674 skb = card->evt_buf_list[i];
Aaron Durbindbccc922014-02-07 16:25:50 -0800675 mwifiex_unmap_pci_memory(adapter, skb,
676 PCI_DMA_FROMDEVICE);
Avinash Patil07324842013-02-08 18:18:07 -0800677 dev_kfree_skb_any(skb);
678 }
679 card->evt_buf_list[i] = NULL;
680 memset(desc, 0, sizeof(*desc));
681 }
682
683 return;
684}
685
686/* This function creates buffer descriptor ring for TX
Amitkumar Karward930fae2011-10-11 17:41:21 -0700687 */
688static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter)
689{
690 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800691 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700692
693 /*
694 * driver maintaines the write pointer and firmware maintaines the read
695 * pointer. The write pointer starts at 0 (zero) while the read pointer
696 * starts at zero with rollover bit set
697 */
698 card->txbd_wrptr = 0;
Avinash Patilca8f2112013-02-08 18:18:09 -0800699
700 if (reg->pfu_enabled)
701 card->txbd_rdptr = 0;
702 else
703 card->txbd_rdptr |= reg->tx_rollover_ind;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700704
705 /* allocate shared memory for the BD ring and divide the same in to
706 several descriptors */
Avinash Patilca8f2112013-02-08 18:18:09 -0800707 if (reg->pfu_enabled)
708 card->txbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
709 MWIFIEX_MAX_TXRX_BD;
710 else
711 card->txbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
712 MWIFIEX_MAX_TXRX_BD;
713
Amitkumar Karward930fae2011-10-11 17:41:21 -0700714 dev_dbg(adapter->dev, "info: txbd_ring: Allocating %d bytes\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700715 card->txbd_ring_size);
Avinash Patilfc331462013-01-03 21:21:30 -0800716 card->txbd_ring_vbase = pci_alloc_consistent(card->dev,
717 card->txbd_ring_size,
718 &card->txbd_ring_pbase);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700719 if (!card->txbd_ring_vbase) {
Avinash Patilfc331462013-01-03 21:21:30 -0800720 dev_err(adapter->dev,
721 "allocate consistent memory (%d bytes) failed!\n",
722 card->txbd_ring_size);
Amitkumar Karwar8c53e422011-12-08 20:41:03 -0800723 return -ENOMEM;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700724 }
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700725 dev_dbg(adapter->dev,
726 "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n",
Avinash Patilfc331462013-01-03 21:21:30 -0800727 card->txbd_ring_vbase, (unsigned int)card->txbd_ring_pbase,
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700728 (u32)((u64)card->txbd_ring_pbase >> 32), card->txbd_ring_size);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700729
Avinash Patil07324842013-02-08 18:18:07 -0800730 return mwifiex_init_txq_ring(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700731}
732
733static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter)
734{
735 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800736 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700737
Avinash Patil07324842013-02-08 18:18:07 -0800738 mwifiex_cleanup_txq_ring(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700739
Avinash Patilfc331462013-01-03 21:21:30 -0800740 if (card->txbd_ring_vbase)
741 pci_free_consistent(card->dev, card->txbd_ring_size,
742 card->txbd_ring_vbase,
743 card->txbd_ring_pbase);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700744 card->txbd_ring_size = 0;
745 card->txbd_wrptr = 0;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800746 card->txbd_rdptr = 0 | reg->tx_rollover_ind;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700747 card->txbd_ring_vbase = NULL;
Avinash Patilfc331462013-01-03 21:21:30 -0800748 card->txbd_ring_pbase = 0;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700749
750 return 0;
751}
752
753/*
754 * This function creates buffer descriptor ring for RX
755 */
756static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter)
757{
758 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800759 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700760
761 /*
762 * driver maintaines the read pointer and firmware maintaines the write
763 * pointer. The write pointer starts at 0 (zero) while the read pointer
764 * starts at zero with rollover bit set
765 */
766 card->rxbd_wrptr = 0;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800767 card->rxbd_rdptr = reg->rx_rollover_ind;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700768
Avinash Patilca8f2112013-02-08 18:18:09 -0800769 if (reg->pfu_enabled)
770 card->rxbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
771 MWIFIEX_MAX_TXRX_BD;
772 else
773 card->rxbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
774 MWIFIEX_MAX_TXRX_BD;
775
Amitkumar Karward930fae2011-10-11 17:41:21 -0700776 dev_dbg(adapter->dev, "info: rxbd_ring: Allocating %d bytes\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700777 card->rxbd_ring_size);
Avinash Patilfc331462013-01-03 21:21:30 -0800778 card->rxbd_ring_vbase = pci_alloc_consistent(card->dev,
779 card->rxbd_ring_size,
780 &card->rxbd_ring_pbase);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700781 if (!card->rxbd_ring_vbase) {
Avinash Patilfc331462013-01-03 21:21:30 -0800782 dev_err(adapter->dev,
783 "allocate consistent memory (%d bytes) failed!\n",
784 card->rxbd_ring_size);
Amitkumar Karwar8c53e422011-12-08 20:41:03 -0800785 return -ENOMEM;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700786 }
Amitkumar Karward930fae2011-10-11 17:41:21 -0700787
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700788 dev_dbg(adapter->dev,
789 "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n",
790 card->rxbd_ring_vbase, (u32)card->rxbd_ring_pbase,
791 (u32)((u64)card->rxbd_ring_pbase >> 32),
792 card->rxbd_ring_size);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700793
Avinash Patil07324842013-02-08 18:18:07 -0800794 return mwifiex_init_rxq_ring(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700795}
796
797/*
798 * This function deletes Buffer descriptor ring for RX
799 */
800static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter)
801{
802 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800803 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700804
Avinash Patil07324842013-02-08 18:18:07 -0800805 mwifiex_cleanup_rxq_ring(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700806
Avinash Patilfc331462013-01-03 21:21:30 -0800807 if (card->rxbd_ring_vbase)
808 pci_free_consistent(card->dev, card->rxbd_ring_size,
809 card->rxbd_ring_vbase,
810 card->rxbd_ring_pbase);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700811 card->rxbd_ring_size = 0;
812 card->rxbd_wrptr = 0;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800813 card->rxbd_rdptr = 0 | reg->rx_rollover_ind;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700814 card->rxbd_ring_vbase = NULL;
Avinash Patilfc331462013-01-03 21:21:30 -0800815 card->rxbd_ring_pbase = 0;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700816
817 return 0;
818}
819
820/*
821 * This function creates buffer descriptor ring for Events
822 */
823static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter)
824{
825 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800826 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700827
828 /*
829 * driver maintaines the read pointer and firmware maintaines the write
830 * pointer. The write pointer starts at 0 (zero) while the read pointer
831 * starts at zero with rollover bit set
832 */
833 card->evtbd_wrptr = 0;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800834 card->evtbd_rdptr = reg->evt_rollover_ind;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700835
Avinash Patile05dc3e2013-02-08 18:18:08 -0800836 card->evtbd_ring_size = sizeof(struct mwifiex_evt_buf_desc) *
Avinash Patilca8f2112013-02-08 18:18:09 -0800837 MWIFIEX_MAX_EVT_BD;
838
Amitkumar Karward930fae2011-10-11 17:41:21 -0700839 dev_dbg(adapter->dev, "info: evtbd_ring: Allocating %d bytes\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700840 card->evtbd_ring_size);
Avinash Patilfc331462013-01-03 21:21:30 -0800841 card->evtbd_ring_vbase = pci_alloc_consistent(card->dev,
842 card->evtbd_ring_size,
843 &card->evtbd_ring_pbase);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700844 if (!card->evtbd_ring_vbase) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700845 dev_err(adapter->dev,
Avinash Patilfc331462013-01-03 21:21:30 -0800846 "allocate consistent memory (%d bytes) failed!\n",
847 card->evtbd_ring_size);
Amitkumar Karwar8c53e422011-12-08 20:41:03 -0800848 return -ENOMEM;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700849 }
Amitkumar Karward930fae2011-10-11 17:41:21 -0700850
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700851 dev_dbg(adapter->dev,
852 "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n",
853 card->evtbd_ring_vbase, (u32)card->evtbd_ring_pbase,
854 (u32)((u64)card->evtbd_ring_pbase >> 32),
855 card->evtbd_ring_size);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700856
Avinash Patil07324842013-02-08 18:18:07 -0800857 return mwifiex_pcie_init_evt_ring(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700858}
859
860/*
861 * This function deletes Buffer descriptor ring for Events
862 */
863static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter)
864{
865 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800866 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700867
Avinash Patil07324842013-02-08 18:18:07 -0800868 mwifiex_cleanup_evt_ring(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700869
Avinash Patilfc331462013-01-03 21:21:30 -0800870 if (card->evtbd_ring_vbase)
871 pci_free_consistent(card->dev, card->evtbd_ring_size,
872 card->evtbd_ring_vbase,
873 card->evtbd_ring_pbase);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700874 card->evtbd_wrptr = 0;
Avinash Patildd04e6a2013-02-08 18:18:06 -0800875 card->evtbd_rdptr = 0 | reg->evt_rollover_ind;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700876 card->evtbd_ring_size = 0;
877 card->evtbd_ring_vbase = NULL;
Avinash Patilfc331462013-01-03 21:21:30 -0800878 card->evtbd_ring_pbase = 0;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700879
880 return 0;
881}
882
883/*
884 * This function allocates a buffer for CMDRSP
885 */
886static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter)
887{
888 struct pcie_service_card *card = adapter->card;
889 struct sk_buff *skb;
890
891 /* Allocate memory for receiving command response data */
892 skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE);
893 if (!skb) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -0700894 dev_err(adapter->dev,
895 "Unable to allocate skb for command response data.\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -0700896 return -ENOMEM;
897 }
Amitkumar Karward930fae2011-10-11 17:41:21 -0700898 skb_put(skb, MWIFIEX_UPLD_SIZE);
Avinash Patilfc331462013-01-03 21:21:30 -0800899 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
900 PCI_DMA_FROMDEVICE))
901 return -1;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700902
Avinash Patilfc331462013-01-03 21:21:30 -0800903 card->cmdrsp_buf = skb;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700904
905 return 0;
906}
907
908/*
909 * This function deletes a buffer for CMDRSP
910 */
911static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter)
912{
913 struct pcie_service_card *card;
914
915 if (!adapter)
916 return 0;
917
918 card = adapter->card;
919
Avinash Patilfc331462013-01-03 21:21:30 -0800920 if (card && card->cmdrsp_buf) {
Aaron Durbindbccc922014-02-07 16:25:50 -0800921 mwifiex_unmap_pci_memory(adapter, card->cmdrsp_buf,
922 PCI_DMA_FROMDEVICE);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700923 dev_kfree_skb_any(card->cmdrsp_buf);
Avinash Patilfc331462013-01-03 21:21:30 -0800924 }
Amitkumar Karward930fae2011-10-11 17:41:21 -0700925
Avinash Patilfc331462013-01-03 21:21:30 -0800926 if (card && card->cmd_buf) {
Aaron Durbindbccc922014-02-07 16:25:50 -0800927 mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
928 PCI_DMA_TODEVICE);
Avinash Patilfc331462013-01-03 21:21:30 -0800929 }
Amitkumar Karward930fae2011-10-11 17:41:21 -0700930 return 0;
931}
932
933/*
934 * This function allocates a buffer for sleep cookie
935 */
936static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter)
937{
Amitkumar Karward930fae2011-10-11 17:41:21 -0700938 struct pcie_service_card *card = adapter->card;
939
Avinash Patilfc331462013-01-03 21:21:30 -0800940 card->sleep_cookie_vbase = pci_alloc_consistent(card->dev, sizeof(u32),
941 &card->sleep_cookie_pbase);
942 if (!card->sleep_cookie_vbase) {
943 dev_err(adapter->dev, "pci_alloc_consistent failed!\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -0700944 return -ENOMEM;
945 }
Amitkumar Karward930fae2011-10-11 17:41:21 -0700946 /* Init val of Sleep Cookie */
Avinash Patilfc331462013-01-03 21:21:30 -0800947 *(u32 *)card->sleep_cookie_vbase = FW_AWAKE_COOKIE;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700948
949 dev_dbg(adapter->dev, "alloc_scook: sleep cookie=0x%x\n",
Avinash Patilfc331462013-01-03 21:21:30 -0800950 *((u32 *)card->sleep_cookie_vbase));
Amitkumar Karward930fae2011-10-11 17:41:21 -0700951
952 return 0;
953}
954
955/*
956 * This function deletes buffer for sleep cookie
957 */
958static int mwifiex_pcie_delete_sleep_cookie_buf(struct mwifiex_adapter *adapter)
959{
960 struct pcie_service_card *card;
961
962 if (!adapter)
963 return 0;
964
965 card = adapter->card;
966
Avinash Patilfc331462013-01-03 21:21:30 -0800967 if (card && card->sleep_cookie_vbase) {
968 pci_free_consistent(card->dev, sizeof(u32),
969 card->sleep_cookie_vbase,
970 card->sleep_cookie_pbase);
971 card->sleep_cookie_vbase = NULL;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700972 }
973
974 return 0;
975}
976
Avinash Patilfbd7e7a2013-01-03 21:21:31 -0800977/* This function flushes the TX buffer descriptor ring
978 * This function defined as handler is also called while cleaning TXRX
979 * during disconnect/ bss stop.
980 */
981static int mwifiex_clean_pcie_ring_buf(struct mwifiex_adapter *adapter)
982{
983 struct pcie_service_card *card = adapter->card;
Avinash Patilfbd7e7a2013-01-03 21:21:31 -0800984
Avinash Patil48f4d912013-02-20 21:12:58 -0800985 if (!mwifiex_pcie_txbd_empty(card, card->txbd_rdptr)) {
Avinash Patilfbd7e7a2013-01-03 21:21:31 -0800986 card->txbd_flush = 1;
987 /* write pointer already set at last send
988 * send dnld-rdy intr again, wait for completion.
989 */
990 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
991 CPU_INTR_DNLD_RDY)) {
992 dev_err(adapter->dev,
993 "failed to assert dnld-rdy interrupt.\n");
994 return -1;
995 }
996 }
997 return 0;
998}
999
Amitkumar Karward930fae2011-10-11 17:41:21 -07001000/*
Avinash Patile7f767a2013-01-03 21:21:32 -08001001 * This function unmaps and frees downloaded data buffer
Amitkumar Karward930fae2011-10-11 17:41:21 -07001002 */
Avinash Patile7f767a2013-01-03 21:21:32 -08001003static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter)
Amitkumar Karward930fae2011-10-11 17:41:21 -07001004{
Avinash Patile7f767a2013-01-03 21:21:32 -08001005 struct sk_buff *skb;
Avinash Patilca8f2112013-02-08 18:18:09 -08001006 u32 wrdoneidx, rdptr, num_tx_buffs, unmap_count = 0;
Avinash Patile05dc3e2013-02-08 18:18:08 -08001007 struct mwifiex_pcie_buf_desc *desc;
Avinash Patilca8f2112013-02-08 18:18:09 -08001008 struct mwifiex_pfu_buf_desc *desc2;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001009 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001010 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001011
1012 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1013 mwifiex_pm_wakeup_card(adapter);
1014
1015 /* Read the TX ring read pointer set by firmware */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001016 if (mwifiex_read_reg(adapter, reg->tx_rdptr, &rdptr)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001017 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001018 "SEND COMP: failed to read reg->tx_rdptr\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001019 return -1;
1020 }
1021
Avinash Patile7f767a2013-01-03 21:21:32 -08001022 dev_dbg(adapter->dev, "SEND COMP: rdptr_prev=0x%x, rdptr=0x%x\n",
1023 card->txbd_rdptr, rdptr);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001024
Avinash Patilca8f2112013-02-08 18:18:09 -08001025 num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
Avinash Patile7f767a2013-01-03 21:21:32 -08001026 /* free from previous txbd_rdptr to current txbd_rdptr */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001027 while (((card->txbd_rdptr & reg->tx_mask) !=
1028 (rdptr & reg->tx_mask)) ||
1029 ((card->txbd_rdptr & reg->tx_rollover_ind) !=
1030 (rdptr & reg->tx_rollover_ind))) {
Avinash Patilca8f2112013-02-08 18:18:09 -08001031 wrdoneidx = (card->txbd_rdptr & reg->tx_mask) >>
1032 reg->tx_start_ptr;
Avinash Patile7f767a2013-01-03 21:21:32 -08001033
1034 skb = card->tx_buf_list[wrdoneidx];
Aaron Durbindbccc922014-02-07 16:25:50 -08001035
Avinash Patile7f767a2013-01-03 21:21:32 -08001036 if (skb) {
1037 dev_dbg(adapter->dev,
1038 "SEND COMP: Detach skb %p at txbd_rdidx=%d\n",
1039 skb, wrdoneidx);
Aaron Durbindbccc922014-02-07 16:25:50 -08001040 mwifiex_unmap_pci_memory(adapter, skb,
1041 PCI_DMA_TODEVICE);
Avinash Patile7f767a2013-01-03 21:21:32 -08001042
1043 unmap_count++;
1044
1045 if (card->txbd_flush)
1046 mwifiex_write_data_complete(adapter, skb, 0,
1047 -1);
1048 else
1049 mwifiex_write_data_complete(adapter, skb, 0, 0);
1050 }
1051
1052 card->tx_buf_list[wrdoneidx] = NULL;
Avinash Patilca8f2112013-02-08 18:18:09 -08001053
1054 if (reg->pfu_enabled) {
Joe Perches45d18c52014-03-24 13:15:39 -07001055 desc2 = card->txbd_ring[wrdoneidx];
Avinash Patilca8f2112013-02-08 18:18:09 -08001056 memset(desc2, 0, sizeof(*desc2));
1057 } else {
1058 desc = card->txbd_ring[wrdoneidx];
1059 memset(desc, 0, sizeof(*desc));
1060 }
1061 switch (card->dev->device) {
1062 case PCIE_DEVICE_ID_MARVELL_88W8766P:
1063 card->txbd_rdptr++;
1064 break;
1065 case PCIE_DEVICE_ID_MARVELL_88W8897:
1066 card->txbd_rdptr += reg->ring_tx_start_ptr;
1067 break;
1068 }
1069
Avinash Patile7f767a2013-01-03 21:21:32 -08001070
Avinash Patildd04e6a2013-02-08 18:18:06 -08001071 if ((card->txbd_rdptr & reg->tx_mask) == num_tx_buffs)
Avinash Patile7f767a2013-01-03 21:21:32 -08001072 card->txbd_rdptr = ((card->txbd_rdptr &
Avinash Patildd04e6a2013-02-08 18:18:06 -08001073 reg->tx_rollover_ind) ^
1074 reg->tx_rollover_ind);
Avinash Patile7f767a2013-01-03 21:21:32 -08001075 }
1076
1077 if (unmap_count)
1078 adapter->data_sent = false;
1079
1080 if (card->txbd_flush) {
Avinash Patil3d482032013-02-15 21:37:54 -08001081 if (mwifiex_pcie_txbd_empty(card, card->txbd_rdptr))
Avinash Patile7f767a2013-01-03 21:21:32 -08001082 card->txbd_flush = 0;
1083 else
1084 mwifiex_clean_pcie_ring_buf(adapter);
1085 }
1086
1087 return 0;
1088}
1089
1090/* This function sends data buffer to device. First 4 bytes of payload
1091 * are filled with payload length and payload type. Then this payload
1092 * is mapped to PCI device memory. Tx ring pointers are advanced accordingly.
1093 * Download ready interrupt to FW is deffered if Tx ring is not full and
1094 * additional payload can be accomodated.
Avinash Patil8d767dc2014-05-13 19:50:13 -07001095 * Caller must ensure tx_param parameter to this function is not NULL.
Avinash Patile7f767a2013-01-03 21:21:32 -08001096 */
1097static int
1098mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
1099 struct mwifiex_tx_param *tx_param)
1100{
1101 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001102 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Avinash Patilca8f2112013-02-08 18:18:09 -08001103 u32 wrindx, num_tx_buffs, rx_val;
Avinash Patile7f767a2013-01-03 21:21:32 -08001104 int ret;
1105 dma_addr_t buf_pa;
Bing Zhao99310782013-03-04 16:27:55 -08001106 struct mwifiex_pcie_buf_desc *desc = NULL;
1107 struct mwifiex_pfu_buf_desc *desc2 = NULL;
Avinash Patile7f767a2013-01-03 21:21:32 -08001108 __le16 *tmp;
1109
1110 if (!(skb->data && skb->len)) {
1111 dev_err(adapter->dev, "%s(): invalid parameter <%p, %#x>\n",
1112 __func__, skb->data, skb->len);
1113 return -1;
1114 }
1115
1116 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1117 mwifiex_pm_wakeup_card(adapter);
1118
Avinash Patilca8f2112013-02-08 18:18:09 -08001119 num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
Avinash Patile7f767a2013-01-03 21:21:32 -08001120 dev_dbg(adapter->dev, "info: SEND DATA: <Rd: %#x, Wr: %#x>\n",
1121 card->txbd_rdptr, card->txbd_wrptr);
1122 if (mwifiex_pcie_txbd_not_full(card)) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001123 u8 *payload;
1124
1125 adapter->data_sent = true;
Avinash Patile7f767a2013-01-03 21:21:32 -08001126 payload = skb->data;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001127 tmp = (__le16 *)&payload[0];
1128 *tmp = cpu_to_le16((u16)skb->len);
1129 tmp = (__le16 *)&payload[2];
1130 *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA);
Avinash Patile7f767a2013-01-03 21:21:32 -08001131
Aaron Durbindbccc922014-02-07 16:25:50 -08001132 if (mwifiex_map_pci_memory(adapter, skb, skb->len,
Avinash Patile7f767a2013-01-03 21:21:32 -08001133 PCI_DMA_TODEVICE))
1134 return -1;
1135
Avinash Patilca8f2112013-02-08 18:18:09 -08001136 wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;
Aaron Durbindbccc922014-02-07 16:25:50 -08001137 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
Avinash Patile7f767a2013-01-03 21:21:32 -08001138 card->tx_buf_list[wrindx] = skb;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001139
Avinash Patilca8f2112013-02-08 18:18:09 -08001140 if (reg->pfu_enabled) {
Joe Perches45d18c52014-03-24 13:15:39 -07001141 desc2 = card->txbd_ring[wrindx];
Avinash Patilca8f2112013-02-08 18:18:09 -08001142 desc2->paddr = buf_pa;
1143 desc2->len = (u16)skb->len;
1144 desc2->frag_len = (u16)skb->len;
1145 desc2->offset = 0;
1146 desc2->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
1147 MWIFIEX_BD_FLAG_LAST_DESC;
1148 } else {
1149 desc = card->txbd_ring[wrindx];
1150 desc->paddr = buf_pa;
1151 desc->len = (u16)skb->len;
1152 desc->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
1153 MWIFIEX_BD_FLAG_LAST_DESC;
1154 }
1155
1156 switch (card->dev->device) {
1157 case PCIE_DEVICE_ID_MARVELL_88W8766P:
1158 card->txbd_wrptr++;
1159 break;
1160 case PCIE_DEVICE_ID_MARVELL_88W8897:
1161 card->txbd_wrptr += reg->ring_tx_start_ptr;
1162 break;
1163 }
1164
1165 if ((card->txbd_wrptr & reg->tx_mask) == num_tx_buffs)
Amitkumar Karward930fae2011-10-11 17:41:21 -07001166 card->txbd_wrptr = ((card->txbd_wrptr &
Avinash Patildd04e6a2013-02-08 18:18:06 -08001167 reg->tx_rollover_ind) ^
1168 reg->tx_rollover_ind);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001169
Avinash Patilca8f2112013-02-08 18:18:09 -08001170 rx_val = card->rxbd_rdptr & reg->rx_wrap_mask;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001171 /* Write the TX ring write pointer in to reg->tx_wrptr */
1172 if (mwifiex_write_reg(adapter, reg->tx_wrptr,
Avinash Patilca8f2112013-02-08 18:18:09 -08001173 card->txbd_wrptr | rx_val)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001174 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001175 "SEND DATA: failed to write reg->tx_wrptr\n");
Avinash Patile7f767a2013-01-03 21:21:32 -08001176 ret = -1;
1177 goto done_unmap;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001178 }
Avinash Patile7f767a2013-01-03 21:21:32 -08001179 if ((mwifiex_pcie_txbd_not_full(card)) &&
1180 tx_param->next_pkt_len) {
1181 /* have more packets and TxBD still can hold more */
1182 dev_dbg(adapter->dev,
1183 "SEND DATA: delay dnld-rdy interrupt.\n");
1184 adapter->data_sent = false;
1185 } else {
1186 /* Send the TX ready interrupt */
1187 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1188 CPU_INTR_DNLD_RDY)) {
1189 dev_err(adapter->dev,
1190 "SEND DATA: failed to assert dnld-rdy interrupt.\n");
1191 ret = -1;
1192 goto done_unmap;
1193 }
Amitkumar Karward930fae2011-10-11 17:41:21 -07001194 }
1195 dev_dbg(adapter->dev, "info: SEND DATA: Updated <Rd: %#x, Wr: "
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001196 "%#x> and sent packet to firmware successfully\n",
Avinash Patile7f767a2013-01-03 21:21:32 -08001197 card->txbd_rdptr, card->txbd_wrptr);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001198 } else {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001199 dev_dbg(adapter->dev,
1200 "info: TX Ring full, can't send packets to fw\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001201 adapter->data_sent = true;
1202 /* Send the TX ready interrupt */
1203 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1204 CPU_INTR_DNLD_RDY))
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001205 dev_err(adapter->dev,
1206 "SEND DATA: failed to assert door-bell intr\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001207 return -EBUSY;
1208 }
1209
Avinash Patile7f767a2013-01-03 21:21:32 -08001210 return -EINPROGRESS;
1211done_unmap:
Aaron Durbindbccc922014-02-07 16:25:50 -08001212 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
Avinash Patile7f767a2013-01-03 21:21:32 -08001213 card->tx_buf_list[wrindx] = NULL;
Avinash Patilca8f2112013-02-08 18:18:09 -08001214 if (reg->pfu_enabled)
1215 memset(desc2, 0, sizeof(*desc2));
1216 else
1217 memset(desc, 0, sizeof(*desc));
1218
Avinash Patile7f767a2013-01-03 21:21:32 -08001219 return ret;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001220}
1221
1222/*
1223 * This function handles received buffer ring and
1224 * dispatches packets to upper
1225 */
1226static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter)
1227{
1228 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001229 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Avinash Patilca8f2112013-02-08 18:18:09 -08001230 u32 wrptr, rd_index, tx_val;
Avinash Patile7f767a2013-01-03 21:21:32 -08001231 dma_addr_t buf_pa;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001232 int ret = 0;
1233 struct sk_buff *skb_tmp = NULL;
Avinash Patile05dc3e2013-02-08 18:18:08 -08001234 struct mwifiex_pcie_buf_desc *desc;
Avinash Patilca8f2112013-02-08 18:18:09 -08001235 struct mwifiex_pfu_buf_desc *desc2;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001236
Avinash Patile7f767a2013-01-03 21:21:32 -08001237 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1238 mwifiex_pm_wakeup_card(adapter);
1239
Amitkumar Karward930fae2011-10-11 17:41:21 -07001240 /* Read the RX ring Write pointer set by firmware */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001241 if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001242 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001243 "RECV DATA: failed to read reg->rx_wrptr\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001244 ret = -1;
1245 goto done;
1246 }
Avinash Patile7f767a2013-01-03 21:21:32 -08001247 card->rxbd_wrptr = wrptr;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001248
Avinash Patildd04e6a2013-02-08 18:18:06 -08001249 while (((wrptr & reg->rx_mask) !=
1250 (card->rxbd_rdptr & reg->rx_mask)) ||
1251 ((wrptr & reg->rx_rollover_ind) ==
1252 (card->rxbd_rdptr & reg->rx_rollover_ind))) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001253 struct sk_buff *skb_data;
1254 u16 rx_len;
Avinash Patile7f767a2013-01-03 21:21:32 -08001255 __le16 pkt_len;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001256
Avinash Patildd04e6a2013-02-08 18:18:06 -08001257 rd_index = card->rxbd_rdptr & reg->rx_mask;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001258 skb_data = card->rx_buf_list[rd_index];
1259
Amitkumar Karwarbb8e6a12014-02-18 15:41:55 -08001260 /* If skb allocation was failed earlier for Rx packet,
1261 * rx_buf_list[rd_index] would have been left with a NULL.
1262 */
1263 if (!skb_data)
1264 return -ENOMEM;
1265
Aaron Durbindbccc922014-02-07 16:25:50 -08001266 mwifiex_unmap_pci_memory(adapter, skb_data, PCI_DMA_FROMDEVICE);
Avinash Patile7f767a2013-01-03 21:21:32 -08001267 card->rx_buf_list[rd_index] = NULL;
1268
Amitkumar Karward930fae2011-10-11 17:41:21 -07001269 /* Get data length from interface header -
Avinash Patile7f767a2013-01-03 21:21:32 -08001270 * first 2 bytes for len, next 2 bytes is for type
1271 */
1272 pkt_len = *((__le16 *)skb_data->data);
1273 rx_len = le16_to_cpu(pkt_len);
1274 skb_put(skb_data, rx_len);
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001275 dev_dbg(adapter->dev,
1276 "info: RECV DATA: Rd=%#x, Wr=%#x, Len=%d\n",
1277 card->rxbd_rdptr, wrptr, rx_len);
Avinash Patile7f767a2013-01-03 21:21:32 -08001278 skb_pull(skb_data, INTF_HEADER_LEN);
1279 mwifiex_handle_rx_packet(adapter, skb_data);
1280
1281 skb_tmp = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001282 if (!skb_tmp) {
Avinash Patile7f767a2013-01-03 21:21:32 -08001283 dev_err(adapter->dev,
1284 "Unable to allocate skb.\n");
1285 return -ENOMEM;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001286 }
1287
Avinash Patile7f767a2013-01-03 21:21:32 -08001288 if (mwifiex_map_pci_memory(adapter, skb_tmp,
1289 MWIFIEX_RX_DATA_BUF_SIZE,
1290 PCI_DMA_FROMDEVICE))
1291 return -1;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001292
Aaron Durbindbccc922014-02-07 16:25:50 -08001293 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb_tmp);
Avinash Patile7f767a2013-01-03 21:21:32 -08001294
1295 dev_dbg(adapter->dev,
1296 "RECV DATA: Attach new sk_buff %p at rxbd_rdidx=%d\n",
1297 skb_tmp, rd_index);
1298 card->rx_buf_list[rd_index] = skb_tmp;
Avinash Patilca8f2112013-02-08 18:18:09 -08001299
1300 if (reg->pfu_enabled) {
Joe Perches45d18c52014-03-24 13:15:39 -07001301 desc2 = card->rxbd_ring[rd_index];
Avinash Patilca8f2112013-02-08 18:18:09 -08001302 desc2->paddr = buf_pa;
1303 desc2->len = skb_tmp->len;
1304 desc2->frag_len = skb_tmp->len;
1305 desc2->offset = 0;
1306 desc2->flags = reg->ring_flag_sop | reg->ring_flag_eop;
1307 } else {
1308 desc = card->rxbd_ring[rd_index];
1309 desc->paddr = buf_pa;
1310 desc->len = skb_tmp->len;
1311 desc->flags = 0;
1312 }
Avinash Patile7f767a2013-01-03 21:21:32 -08001313
Avinash Patildd04e6a2013-02-08 18:18:06 -08001314 if ((++card->rxbd_rdptr & reg->rx_mask) ==
Amitkumar Karward930fae2011-10-11 17:41:21 -07001315 MWIFIEX_MAX_TXRX_BD) {
1316 card->rxbd_rdptr = ((card->rxbd_rdptr &
Avinash Patildd04e6a2013-02-08 18:18:06 -08001317 reg->rx_rollover_ind) ^
1318 reg->rx_rollover_ind);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001319 }
1320 dev_dbg(adapter->dev, "info: RECV DATA: <Rd: %#x, Wr: %#x>\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001321 card->rxbd_rdptr, wrptr);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001322
Avinash Patilca8f2112013-02-08 18:18:09 -08001323 tx_val = card->txbd_wrptr & reg->tx_wrap_mask;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001324 /* Write the RX ring read pointer in to reg->rx_rdptr */
1325 if (mwifiex_write_reg(adapter, reg->rx_rdptr,
Avinash Patilca8f2112013-02-08 18:18:09 -08001326 card->rxbd_rdptr | tx_val)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001327 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001328 "RECV DATA: failed to write reg->rx_rdptr\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001329 ret = -1;
1330 goto done;
1331 }
1332
1333 /* Read the RX ring Write pointer set by firmware */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001334 if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001335 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001336 "RECV DATA: failed to read reg->rx_wrptr\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001337 ret = -1;
1338 goto done;
1339 }
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001340 dev_dbg(adapter->dev,
1341 "info: RECV DATA: Rcvd packet from fw successfully\n");
Avinash Patile7f767a2013-01-03 21:21:32 -08001342 card->rxbd_wrptr = wrptr;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001343 }
1344
1345done:
Amitkumar Karward930fae2011-10-11 17:41:21 -07001346 return ret;
1347}
1348
1349/*
1350 * This function downloads the boot command to device
1351 */
1352static int
1353mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
1354{
Avinash Patilfc331462013-01-03 21:21:30 -08001355 dma_addr_t buf_pa;
1356 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001357 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001358
Avinash Patilfc331462013-01-03 21:21:30 -08001359 if (!(skb->data && skb->len)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001360 dev_err(adapter->dev,
Avinash Patilfc331462013-01-03 21:21:30 -08001361 "Invalid parameter in %s <%p. len %d>\n",
1362 __func__, skb->data, skb->len);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001363 return -1;
1364 }
1365
Avinash Patilfc331462013-01-03 21:21:30 -08001366 if (mwifiex_map_pci_memory(adapter, skb, skb->len , PCI_DMA_TODEVICE))
1367 return -1;
1368
Aaron Durbindbccc922014-02-07 16:25:50 -08001369 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
Avinash Patilfc331462013-01-03 21:21:30 -08001370
Avinash Patildd04e6a2013-02-08 18:18:06 -08001371 /* Write the lower 32bits of the physical address to low command
1372 * address scratch register
1373 */
1374 if (mwifiex_write_reg(adapter, reg->cmd_addr_lo, (u32)buf_pa)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001375 dev_err(adapter->dev,
1376 "%s: failed to write download command to boot code.\n",
1377 __func__);
Aaron Durbindbccc922014-02-07 16:25:50 -08001378 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001379 return -1;
1380 }
1381
Avinash Patildd04e6a2013-02-08 18:18:06 -08001382 /* Write the upper 32bits of the physical address to high command
1383 * address scratch register
1384 */
1385 if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
Avinash Patilfc331462013-01-03 21:21:30 -08001386 (u32)((u64)buf_pa >> 32))) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001387 dev_err(adapter->dev,
1388 "%s: failed to write download command to boot code.\n",
1389 __func__);
Aaron Durbindbccc922014-02-07 16:25:50 -08001390 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001391 return -1;
1392 }
1393
Avinash Patildd04e6a2013-02-08 18:18:06 -08001394 /* Write the command length to cmd_size scratch register */
1395 if (mwifiex_write_reg(adapter, reg->cmd_size, skb->len)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001396 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001397 "%s: failed to write command len to cmd_size scratch reg\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001398 __func__);
Aaron Durbindbccc922014-02-07 16:25:50 -08001399 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001400 return -1;
1401 }
1402
1403 /* Ring the door bell */
1404 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1405 CPU_INTR_DOOR_BELL)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001406 dev_err(adapter->dev,
1407 "%s: failed to assert door-bell intr\n", __func__);
Aaron Durbindbccc922014-02-07 16:25:50 -08001408 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001409 return -1;
1410 }
1411
1412 return 0;
1413}
1414
Avinash Patilc6d1d872013-01-03 21:21:29 -08001415/* This function init rx port in firmware which in turn enables to receive data
1416 * from device before transmitting any packet.
1417 */
1418static int mwifiex_pcie_init_fw_port(struct mwifiex_adapter *adapter)
1419{
1420 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001421 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Avinash Patilca8f2112013-02-08 18:18:09 -08001422 int tx_wrap = card->txbd_wrptr & reg->tx_wrap_mask;
Avinash Patilc6d1d872013-01-03 21:21:29 -08001423
Avinash Patildd04e6a2013-02-08 18:18:06 -08001424 /* Write the RX ring read pointer in to reg->rx_rdptr */
Avinash Patilca8f2112013-02-08 18:18:09 -08001425 if (mwifiex_write_reg(adapter, reg->rx_rdptr, card->rxbd_rdptr |
1426 tx_wrap)) {
Avinash Patilc6d1d872013-01-03 21:21:29 -08001427 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001428 "RECV DATA: failed to write reg->rx_rdptr\n");
Avinash Patilc6d1d872013-01-03 21:21:29 -08001429 return -1;
1430 }
1431 return 0;
1432}
1433
1434/* This function downloads commands to the device
Amitkumar Karward930fae2011-10-11 17:41:21 -07001435 */
1436static int
1437mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
1438{
1439 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001440 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001441 int ret = 0;
Avinash Patilfc331462013-01-03 21:21:30 -08001442 dma_addr_t cmd_buf_pa, cmdrsp_buf_pa;
1443 u8 *payload = (u8 *)skb->data;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001444
1445 if (!(skb->data && skb->len)) {
1446 dev_err(adapter->dev, "Invalid parameter in %s <%p, %#x>\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001447 __func__, skb->data, skb->len);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001448 return -1;
1449 }
1450
1451 /* Make sure a command response buffer is available */
1452 if (!card->cmdrsp_buf) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001453 dev_err(adapter->dev,
1454 "No response buffer available, send command failed\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001455 return -EBUSY;
1456 }
1457
Avinash Patilfc331462013-01-03 21:21:30 -08001458 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1459 mwifiex_pm_wakeup_card(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001460
1461 adapter->cmd_sent = true;
Avinash Patilfc331462013-01-03 21:21:30 -08001462
1463 *(__le16 *)&payload[0] = cpu_to_le16((u16)skb->len);
1464 *(__le16 *)&payload[2] = cpu_to_le16(MWIFIEX_TYPE_CMD);
1465
1466 if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE))
1467 return -1;
1468
1469 card->cmd_buf = skb;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001470
1471 /* To send a command, the driver will:
1472 1. Write the 64bit physical address of the data buffer to
Avinash Patildd04e6a2013-02-08 18:18:06 -08001473 cmd response address low + cmd response address high
Amitkumar Karward930fae2011-10-11 17:41:21 -07001474 2. Ring the door bell (i.e. set the door bell interrupt)
1475
1476 In response to door bell interrupt, the firmware will perform
1477 the DMA of the command packet (first header to obtain the total
1478 length and then rest of the command).
1479 */
1480
1481 if (card->cmdrsp_buf) {
Aaron Durbindbccc922014-02-07 16:25:50 -08001482 cmdrsp_buf_pa = MWIFIEX_SKB_DMA_ADDR(card->cmdrsp_buf);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001483 /* Write the lower 32bits of the cmdrsp buffer physical
1484 address */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001485 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo,
Avinash Patilfc331462013-01-03 21:21:30 -08001486 (u32)cmdrsp_buf_pa)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001487 dev_err(adapter->dev,
1488 "Failed to write download cmd to boot code.\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001489 ret = -1;
1490 goto done;
1491 }
1492 /* Write the upper 32bits of the cmdrsp buffer physical
1493 address */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001494 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi,
Avinash Patilfc331462013-01-03 21:21:30 -08001495 (u32)((u64)cmdrsp_buf_pa >> 32))) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001496 dev_err(adapter->dev,
1497 "Failed to write download cmd to boot code.\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001498 ret = -1;
1499 goto done;
1500 }
1501 }
1502
Aaron Durbindbccc922014-02-07 16:25:50 -08001503 cmd_buf_pa = MWIFIEX_SKB_DMA_ADDR(card->cmd_buf);
Avinash Patildd04e6a2013-02-08 18:18:06 -08001504 /* Write the lower 32bits of the physical address to reg->cmd_addr_lo */
1505 if (mwifiex_write_reg(adapter, reg->cmd_addr_lo,
1506 (u32)cmd_buf_pa)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001507 dev_err(adapter->dev,
1508 "Failed to write download cmd to boot code.\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001509 ret = -1;
1510 goto done;
1511 }
Avinash Patildd04e6a2013-02-08 18:18:06 -08001512 /* Write the upper 32bits of the physical address to reg->cmd_addr_hi */
1513 if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
Avinash Patilfc331462013-01-03 21:21:30 -08001514 (u32)((u64)cmd_buf_pa >> 32))) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001515 dev_err(adapter->dev,
1516 "Failed to write download cmd to boot code.\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001517 ret = -1;
1518 goto done;
1519 }
1520
Avinash Patildd04e6a2013-02-08 18:18:06 -08001521 /* Write the command length to reg->cmd_size */
1522 if (mwifiex_write_reg(adapter, reg->cmd_size,
1523 card->cmd_buf->len)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001524 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001525 "Failed to write cmd len to reg->cmd_size\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001526 ret = -1;
1527 goto done;
1528 }
1529
1530 /* Ring the door bell */
1531 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1532 CPU_INTR_DOOR_BELL)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001533 dev_err(adapter->dev,
1534 "Failed to assert door-bell intr\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001535 ret = -1;
1536 goto done;
1537 }
1538
1539done:
1540 if (ret)
1541 adapter->cmd_sent = false;
1542
1543 return 0;
1544}
1545
1546/*
1547 * This function handles command complete interrupt
1548 */
1549static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
1550{
1551 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001552 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001553 struct sk_buff *skb = card->cmdrsp_buf;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001554 int count = 0;
Avinash Patilfc331462013-01-03 21:21:30 -08001555 u16 rx_len;
1556 __le16 pkt_len;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001557
1558 dev_dbg(adapter->dev, "info: Rx CMD Response\n");
1559
Aaron Durbindbccc922014-02-07 16:25:50 -08001560 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_FROMDEVICE);
Avinash Patilfc331462013-01-03 21:21:30 -08001561
Aaron Durbin189b3292014-02-07 16:25:51 -08001562 /* Unmap the command as a response has been received. */
1563 if (card->cmd_buf) {
1564 mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
1565 PCI_DMA_TODEVICE);
1566 card->cmd_buf = NULL;
1567 }
1568
Avinash Patilfc331462013-01-03 21:21:30 -08001569 pkt_len = *((__le16 *)skb->data);
1570 rx_len = le16_to_cpu(pkt_len);
1571 skb_trim(skb, rx_len);
1572 skb_pull(skb, INTF_HEADER_LEN);
1573
Amitkumar Karward930fae2011-10-11 17:41:21 -07001574 if (!adapter->curr_cmd) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001575 if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001576 mwifiex_process_sleep_confirm_resp(adapter, skb->data,
1577 skb->len);
Amitkumar Karwar1c975602014-02-18 15:41:56 -08001578 mwifiex_pcie_enable_host_int(adapter);
1579 if (mwifiex_write_reg(adapter,
1580 PCIE_CPU_INT_EVENT,
1581 CPU_INTR_SLEEP_CFM_DONE)) {
1582 dev_warn(adapter->dev,
1583 "Write register failed\n");
1584 return -1;
1585 }
Avinash Patilc4bc9802014-03-18 22:19:17 -07001586 mwifiex_delay_for_sleep_cookie(adapter,
1587 MWIFIEX_MAX_DELAY_COUNT);
Avinash Patil52301a82013-02-12 14:38:32 -08001588 while (reg->sleep_cookie && (count++ < 10) &&
1589 mwifiex_pcie_ok_to_access_hw(adapter))
Yogesh Ashok Poware7891ba2012-03-12 19:35:11 -07001590 usleep_range(50, 60);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001591 } else {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001592 dev_err(adapter->dev,
1593 "There is no command but got cmdrsp\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001594 }
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001595 memcpy(adapter->upld_buf, skb->data,
1596 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len));
Avinash Patil0f49d642013-03-20 17:56:23 -07001597 skb_push(skb, INTF_HEADER_LEN);
Avinash Patilfc331462013-01-03 21:21:30 -08001598 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1599 PCI_DMA_FROMDEVICE))
1600 return -1;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001601 } else if (mwifiex_pcie_ok_to_access_hw(adapter)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001602 adapter->curr_cmd->resp_skb = skb;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001603 adapter->cmd_resp_received = true;
1604 /* Take the pointer and set it to CMD node and will
1605 return in the response complete callback */
1606 card->cmdrsp_buf = NULL;
1607
1608 /* Clear the cmd-rsp buffer address in scratch registers. This
1609 will prevent firmware from writing to the same response
1610 buffer again. */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001611 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo, 0)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001612 dev_err(adapter->dev,
1613 "cmd_done: failed to clear cmd_rsp_addr_lo\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001614 return -1;
1615 }
1616 /* Write the upper 32bits of the cmdrsp buffer physical
1617 address */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001618 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi, 0)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001619 dev_err(adapter->dev,
1620 "cmd_done: failed to clear cmd_rsp_addr_hi\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001621 return -1;
1622 }
1623 }
1624
1625 return 0;
1626}
1627
1628/*
1629 * Command Response processing complete handler
1630 */
1631static int mwifiex_pcie_cmdrsp_complete(struct mwifiex_adapter *adapter,
1632 struct sk_buff *skb)
1633{
1634 struct pcie_service_card *card = adapter->card;
1635
1636 if (skb) {
1637 card->cmdrsp_buf = skb;
1638 skb_push(card->cmdrsp_buf, INTF_HEADER_LEN);
Avinash Patilfc331462013-01-03 21:21:30 -08001639 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1640 PCI_DMA_FROMDEVICE))
1641 return -1;
1642 }
1643
Amitkumar Karward930fae2011-10-11 17:41:21 -07001644 return 0;
1645}
1646
1647/*
1648 * This function handles firmware event ready interrupt
1649 */
1650static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter)
1651{
1652 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001653 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001654 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
1655 u32 wrptr, event;
Avinash Patile05dc3e2013-02-08 18:18:08 -08001656 struct mwifiex_evt_buf_desc *desc;
Avinash Patilfc331462013-01-03 21:21:30 -08001657
1658 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1659 mwifiex_pm_wakeup_card(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001660
1661 if (adapter->event_received) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001662 dev_dbg(adapter->dev, "info: Event being processed, "
1663 "do not process this interrupt just yet\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001664 return 0;
1665 }
1666
1667 if (rdptr >= MWIFIEX_MAX_EVT_BD) {
1668 dev_dbg(adapter->dev, "info: Invalid read pointer...\n");
1669 return -1;
1670 }
1671
1672 /* Read the event ring write pointer set by firmware */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001673 if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001674 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001675 "EventReady: failed to read reg->evt_wrptr\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001676 return -1;
1677 }
1678
1679 dev_dbg(adapter->dev, "info: EventReady: Initial <Rd: 0x%x, Wr: 0x%x>",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001680 card->evtbd_rdptr, wrptr);
1681 if (((wrptr & MWIFIEX_EVTBD_MASK) != (card->evtbd_rdptr
1682 & MWIFIEX_EVTBD_MASK)) ||
Avinash Patildd04e6a2013-02-08 18:18:06 -08001683 ((wrptr & reg->evt_rollover_ind) ==
1684 (card->evtbd_rdptr & reg->evt_rollover_ind))) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001685 struct sk_buff *skb_cmd;
1686 __le16 data_len = 0;
1687 u16 evt_len;
1688
1689 dev_dbg(adapter->dev, "info: Read Index: %d\n", rdptr);
1690 skb_cmd = card->evt_buf_list[rdptr];
Aaron Durbindbccc922014-02-07 16:25:50 -08001691 mwifiex_unmap_pci_memory(adapter, skb_cmd, PCI_DMA_FROMDEVICE);
Avinash Patilfc331462013-01-03 21:21:30 -08001692
Amitkumar Karward930fae2011-10-11 17:41:21 -07001693 /* Take the pointer and set it to event pointer in adapter
1694 and will return back after event handling callback */
1695 card->evt_buf_list[rdptr] = NULL;
Avinash Patile05dc3e2013-02-08 18:18:08 -08001696 desc = card->evtbd_ring[rdptr];
1697 memset(desc, 0, sizeof(*desc));
Amitkumar Karward930fae2011-10-11 17:41:21 -07001698
1699 event = *(u32 *) &skb_cmd->data[INTF_HEADER_LEN];
1700 adapter->event_cause = event;
1701 /* The first 4bytes will be the event transfer header
1702 len is 2 bytes followed by type which is 2 bytes */
1703 memcpy(&data_len, skb_cmd->data, sizeof(__le16));
1704 evt_len = le16_to_cpu(data_len);
1705
1706 skb_pull(skb_cmd, INTF_HEADER_LEN);
1707 dev_dbg(adapter->dev, "info: Event length: %d\n", evt_len);
1708
1709 if ((evt_len > 0) && (evt_len < MAX_EVENT_SIZE))
1710 memcpy(adapter->event_body, skb_cmd->data +
1711 MWIFIEX_EVENT_HEADER_LEN, evt_len -
1712 MWIFIEX_EVENT_HEADER_LEN);
1713
1714 adapter->event_received = true;
1715 adapter->event_skb = skb_cmd;
1716
1717 /* Do not update the event read pointer here, wait till the
1718 buffer is released. This is just to make things simpler,
1719 we need to find a better method of managing these buffers.
1720 */
1721 }
1722
1723 return 0;
1724}
1725
1726/*
1727 * Event processing complete handler
1728 */
1729static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,
1730 struct sk_buff *skb)
1731{
1732 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001733 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001734 int ret = 0;
1735 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
1736 u32 wrptr;
Avinash Patile05dc3e2013-02-08 18:18:08 -08001737 struct mwifiex_evt_buf_desc *desc;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001738
1739 if (!skb)
1740 return 0;
1741
Dan Carpenter1eb54c82011-11-07 19:31:47 -08001742 if (rdptr >= MWIFIEX_MAX_EVT_BD) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001743 dev_err(adapter->dev, "event_complete: Invalid rdptr 0x%x\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001744 rdptr);
Amitkumar Karwar8c53e422011-12-08 20:41:03 -08001745 return -EINVAL;
Dan Carpenter1eb54c82011-11-07 19:31:47 -08001746 }
Amitkumar Karward930fae2011-10-11 17:41:21 -07001747
1748 /* Read the event ring write pointer set by firmware */
Avinash Patildd04e6a2013-02-08 18:18:06 -08001749 if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001750 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001751 "event_complete: failed to read reg->evt_wrptr\n");
Amitkumar Karwar8c53e422011-12-08 20:41:03 -08001752 return -1;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001753 }
1754
1755 if (!card->evt_buf_list[rdptr]) {
1756 skb_push(skb, INTF_HEADER_LEN);
Avinash Patilfc331462013-01-03 21:21:30 -08001757 if (mwifiex_map_pci_memory(adapter, skb,
1758 MAX_EVENT_SIZE,
1759 PCI_DMA_FROMDEVICE))
1760 return -1;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001761 card->evt_buf_list[rdptr] = skb;
Avinash Patile05dc3e2013-02-08 18:18:08 -08001762 desc = card->evtbd_ring[rdptr];
Aaron Durbindbccc922014-02-07 16:25:50 -08001763 desc->paddr = MWIFIEX_SKB_DMA_ADDR(skb);
Avinash Patile05dc3e2013-02-08 18:18:08 -08001764 desc->len = (u16)skb->len;
1765 desc->flags = 0;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001766 skb = NULL;
1767 } else {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001768 dev_dbg(adapter->dev,
1769 "info: ERROR: buf still valid at index %d, <%p, %p>\n",
1770 rdptr, card->evt_buf_list[rdptr], skb);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001771 }
1772
1773 if ((++card->evtbd_rdptr & MWIFIEX_EVTBD_MASK) == MWIFIEX_MAX_EVT_BD) {
1774 card->evtbd_rdptr = ((card->evtbd_rdptr &
Avinash Patildd04e6a2013-02-08 18:18:06 -08001775 reg->evt_rollover_ind) ^
1776 reg->evt_rollover_ind);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001777 }
1778
1779 dev_dbg(adapter->dev, "info: Updated <Rd: 0x%x, Wr: 0x%x>",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001780 card->evtbd_rdptr, wrptr);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001781
Avinash Patildd04e6a2013-02-08 18:18:06 -08001782 /* Write the event ring read pointer in to reg->evt_rdptr */
1783 if (mwifiex_write_reg(adapter, reg->evt_rdptr,
1784 card->evtbd_rdptr)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001785 dev_err(adapter->dev,
Avinash Patildd04e6a2013-02-08 18:18:06 -08001786 "event_complete: failed to read reg->evt_rdptr\n");
Amitkumar Karwar8c53e422011-12-08 20:41:03 -08001787 return -1;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001788 }
1789
Amitkumar Karward930fae2011-10-11 17:41:21 -07001790 dev_dbg(adapter->dev, "info: Check Events Again\n");
1791 ret = mwifiex_pcie_process_event_ready(adapter);
1792
1793 return ret;
1794}
1795
1796/*
1797 * This function downloads the firmware to the card.
1798 *
1799 * Firmware is downloaded to the card in blocks. Every block download
1800 * is tested for CRC errors, and retried a number of times before
1801 * returning failure.
1802 */
1803static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1804 struct mwifiex_fw_image *fw)
1805{
1806 int ret;
1807 u8 *firmware = fw->fw_buf;
1808 u32 firmware_len = fw->fw_len;
1809 u32 offset = 0;
1810 struct sk_buff *skb;
1811 u32 txlen, tx_blocks = 0, tries, len;
1812 u32 block_retry_cnt = 0;
Avinash Patilfc331462013-01-03 21:21:30 -08001813 struct pcie_service_card *card = adapter->card;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001814 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001815
1816 if (!firmware || !firmware_len) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001817 dev_err(adapter->dev,
1818 "No firmware image found! Terminating download\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001819 return -1;
1820 }
1821
1822 dev_dbg(adapter->dev, "info: Downloading FW image (%d bytes)\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001823 firmware_len);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001824
1825 if (mwifiex_pcie_disable_host_int(adapter)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001826 dev_err(adapter->dev,
1827 "%s: Disabling interrupts failed.\n", __func__);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001828 return -1;
1829 }
1830
1831 skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE);
1832 if (!skb) {
1833 ret = -ENOMEM;
1834 goto done;
1835 }
Amitkumar Karward930fae2011-10-11 17:41:21 -07001836
1837 /* Perform firmware data transfer */
1838 do {
1839 u32 ireg_intr = 0;
1840
1841 /* More data? */
1842 if (offset >= firmware_len)
1843 break;
1844
1845 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
Avinash Patildd04e6a2013-02-08 18:18:06 -08001846 ret = mwifiex_read_reg(adapter, reg->cmd_size,
Amitkumar Karward930fae2011-10-11 17:41:21 -07001847 &len);
1848 if (ret) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001849 dev_warn(adapter->dev,
1850 "Failed reading len from boot code\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001851 goto done;
1852 }
1853 if (len)
1854 break;
Yogesh Ashok Poware7891ba2012-03-12 19:35:11 -07001855 usleep_range(10, 20);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001856 }
1857
1858 if (!len) {
1859 break;
1860 } else if (len > MWIFIEX_UPLD_SIZE) {
1861 pr_err("FW download failure @ %d, invalid length %d\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001862 offset, len);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001863 ret = -1;
1864 goto done;
1865 }
1866
1867 txlen = len;
1868
1869 if (len & BIT(0)) {
1870 block_retry_cnt++;
1871 if (block_retry_cnt > MAX_WRITE_IOMEM_RETRY) {
1872 pr_err("FW download failure @ %d, over max "
1873 "retry count\n", offset);
1874 ret = -1;
1875 goto done;
1876 }
1877 dev_err(adapter->dev, "FW CRC error indicated by the "
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001878 "helper: len = 0x%04X, txlen = %d\n",
1879 len, txlen);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001880 len &= ~BIT(0);
1881 /* Setting this to 0 to resend from same offset */
1882 txlen = 0;
1883 } else {
1884 block_retry_cnt = 0;
1885 /* Set blocksize to transfer - checking for
1886 last block */
1887 if (firmware_len - offset < txlen)
1888 txlen = firmware_len - offset;
1889
1890 dev_dbg(adapter->dev, ".");
1891
Avinash Patildd04e6a2013-02-08 18:18:06 -08001892 tx_blocks = (txlen + card->pcie.blksz_fw_dl - 1) /
1893 card->pcie.blksz_fw_dl;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001894
1895 /* Copy payload to buffer */
1896 memmove(skb->data, &firmware[offset], txlen);
1897 }
1898
1899 skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len);
Avinash Patildd04e6a2013-02-08 18:18:06 -08001900 skb_trim(skb, tx_blocks * card->pcie.blksz_fw_dl);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001901
1902 /* Send the boot command to device */
1903 if (mwifiex_pcie_send_boot_cmd(adapter, skb)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001904 dev_err(adapter->dev,
1905 "Failed to send firmware download command\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001906 ret = -1;
1907 goto done;
1908 }
Avinash Patilfc331462013-01-03 21:21:30 -08001909
Amitkumar Karward930fae2011-10-11 17:41:21 -07001910 /* Wait for the command done interrupt */
1911 do {
1912 if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS,
1913 &ireg_intr)) {
1914 dev_err(adapter->dev, "%s: Failed to read "
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001915 "interrupt status during fw dnld.\n",
1916 __func__);
Aaron Durbindbccc922014-02-07 16:25:50 -08001917 mwifiex_unmap_pci_memory(adapter, skb,
1918 PCI_DMA_TODEVICE);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001919 ret = -1;
1920 goto done;
1921 }
1922 } while ((ireg_intr & CPU_INTR_DOOR_BELL) ==
1923 CPU_INTR_DOOR_BELL);
Avinash Patilfc331462013-01-03 21:21:30 -08001924
Aaron Durbindbccc922014-02-07 16:25:50 -08001925 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
Avinash Patilfc331462013-01-03 21:21:30 -08001926
Amitkumar Karward930fae2011-10-11 17:41:21 -07001927 offset += txlen;
1928 } while (true);
1929
1930 dev_dbg(adapter->dev, "info:\nFW download over, size %d bytes\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001931 offset);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001932
1933 ret = 0;
1934
1935done:
1936 dev_kfree_skb_any(skb);
1937 return ret;
1938}
1939
1940/*
1941 * This function checks the firmware status in card.
1942 *
1943 * The winner interface is also determined by this function.
1944 */
1945static int
1946mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num)
1947{
1948 int ret = 0;
1949 u32 firmware_stat, winner_status;
Avinash Patildd04e6a2013-02-08 18:18:06 -08001950 struct pcie_service_card *card = adapter->card;
1951 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001952 u32 tries;
1953
1954 /* Mask spurios interrupts */
1955 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS_MASK,
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001956 HOST_INTR_MASK)) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001957 dev_warn(adapter->dev, "Write register failed\n");
1958 return -1;
1959 }
1960
1961 dev_dbg(adapter->dev, "Setting driver ready signature\n");
Avinash Patildd04e6a2013-02-08 18:18:06 -08001962 if (mwifiex_write_reg(adapter, reg->drv_rdy,
1963 FIRMWARE_READY_PCIE)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001964 dev_err(adapter->dev,
1965 "Failed to write driver ready signature\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07001966 return -1;
1967 }
1968
1969 /* Wait for firmware initialization event */
1970 for (tries = 0; tries < poll_num; tries++) {
Avinash Patildd04e6a2013-02-08 18:18:06 -08001971 if (mwifiex_read_reg(adapter, reg->fw_status,
Amitkumar Karward930fae2011-10-11 17:41:21 -07001972 &firmware_stat))
1973 ret = -1;
1974 else
1975 ret = 0;
1976 if (ret)
1977 continue;
1978 if (firmware_stat == FIRMWARE_READY_PCIE) {
1979 ret = 0;
1980 break;
1981 } else {
Amitkumar Karwara76b20e2013-07-22 19:17:53 -07001982 msleep(100);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001983 ret = -1;
1984 }
1985 }
1986
1987 if (ret) {
Avinash Patildd04e6a2013-02-08 18:18:06 -08001988 if (mwifiex_read_reg(adapter, reg->fw_status,
Amitkumar Karward930fae2011-10-11 17:41:21 -07001989 &winner_status))
1990 ret = -1;
1991 else if (!winner_status) {
1992 dev_err(adapter->dev, "PCI-E is the winner\n");
1993 adapter->winner = 1;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001994 } else {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07001995 dev_err(adapter->dev,
1996 "PCI-E is not the winner <%#x,%d>, exit dnld\n",
1997 ret, adapter->winner);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001998 }
1999 }
2000
2001 return ret;
2002}
2003
2004/*
2005 * This function reads the interrupt status from card.
2006 */
2007static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
2008{
2009 u32 pcie_ireg;
2010 unsigned long flags;
2011
2012 if (!mwifiex_pcie_ok_to_access_hw(adapter))
2013 return;
2014
2015 if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS, &pcie_ireg)) {
2016 dev_warn(adapter->dev, "Read register failed\n");
2017 return;
2018 }
2019
2020 if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
2021
2022 mwifiex_pcie_disable_host_int(adapter);
2023
2024 /* Clear the pending interrupts */
2025 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS,
2026 ~pcie_ireg)) {
2027 dev_warn(adapter->dev, "Write register failed\n");
2028 return;
2029 }
2030 spin_lock_irqsave(&adapter->int_lock, flags);
2031 adapter->int_status |= pcie_ireg;
2032 spin_unlock_irqrestore(&adapter->int_lock, flags);
2033
Amitkumar Karwar1c975602014-02-18 15:41:56 -08002034 if (!adapter->pps_uapsd_mode &&
2035 adapter->ps_state == PS_STATE_SLEEP &&
2036 mwifiex_pcie_ok_to_access_hw(adapter)) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07002037 /* Potentially for PCIe we could get other
2038 * interrupts like shared. Don't change power
2039 * state until cookie is set */
Avinash Patilc24d9922013-03-22 21:49:06 -07002040 adapter->ps_state = PS_STATE_AWAKE;
2041 adapter->pm_wakeup_fw_try = false;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002042 }
2043 }
2044}
2045
2046/*
2047 * Interrupt handler for PCIe root port
2048 *
2049 * This function reads the interrupt status from firmware and assigns
2050 * the main process in workqueue which will handle the interrupt.
2051 */
2052static irqreturn_t mwifiex_pcie_interrupt(int irq, void *context)
2053{
2054 struct pci_dev *pdev = (struct pci_dev *)context;
2055 struct pcie_service_card *card;
2056 struct mwifiex_adapter *adapter;
2057
2058 if (!pdev) {
2059 pr_debug("info: %s: pdev is NULL\n", (u8 *)pdev);
2060 goto exit;
2061 }
2062
Jingoo Hanb2a31202013-09-09 14:26:51 +09002063 card = pci_get_drvdata(pdev);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002064 if (!card || !card->adapter) {
2065 pr_debug("info: %s: card=%p adapter=%p\n", __func__, card,
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07002066 card ? card->adapter : NULL);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002067 goto exit;
2068 }
2069 adapter = card->adapter;
2070
2071 if (adapter->surprise_removed)
2072 goto exit;
2073
2074 mwifiex_interrupt_status(adapter);
2075 queue_work(adapter->workqueue, &adapter->main_work);
2076
2077exit:
2078 return IRQ_HANDLED;
2079}
2080
2081/*
2082 * This function checks the current interrupt status.
2083 *
2084 * The following interrupts are checked and handled by this function -
2085 * - Data sent
2086 * - Command sent
2087 * - Command received
2088 * - Packets received
2089 * - Events received
2090 *
2091 * In case of Rx packets received, the packets are uploaded from card to
2092 * host and processed accordingly.
2093 */
2094static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
2095{
2096 int ret;
Avinash Patil659c4782013-01-03 21:21:28 -08002097 u32 pcie_ireg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002098 unsigned long flags;
2099
2100 spin_lock_irqsave(&adapter->int_lock, flags);
2101 /* Clear out unused interrupts */
Avinash Patil659c4782013-01-03 21:21:28 -08002102 pcie_ireg = adapter->int_status;
2103 adapter->int_status = 0;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002104 spin_unlock_irqrestore(&adapter->int_lock, flags);
2105
Avinash Patil659c4782013-01-03 21:21:28 -08002106 while (pcie_ireg & HOST_INTR_MASK) {
2107 if (pcie_ireg & HOST_INTR_DNLD_DONE) {
2108 pcie_ireg &= ~HOST_INTR_DNLD_DONE;
Avinash Patile7f767a2013-01-03 21:21:32 -08002109 dev_dbg(adapter->dev, "info: TX DNLD Done\n");
2110 ret = mwifiex_pcie_send_data_complete(adapter);
2111 if (ret)
2112 return ret;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002113 }
Avinash Patil659c4782013-01-03 21:21:28 -08002114 if (pcie_ireg & HOST_INTR_UPLD_RDY) {
2115 pcie_ireg &= ~HOST_INTR_UPLD_RDY;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002116 dev_dbg(adapter->dev, "info: Rx DATA\n");
2117 ret = mwifiex_pcie_process_recv_data(adapter);
2118 if (ret)
2119 return ret;
2120 }
Avinash Patil659c4782013-01-03 21:21:28 -08002121 if (pcie_ireg & HOST_INTR_EVENT_RDY) {
2122 pcie_ireg &= ~HOST_INTR_EVENT_RDY;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002123 dev_dbg(adapter->dev, "info: Rx EVENT\n");
2124 ret = mwifiex_pcie_process_event_ready(adapter);
2125 if (ret)
2126 return ret;
2127 }
2128
Avinash Patil659c4782013-01-03 21:21:28 -08002129 if (pcie_ireg & HOST_INTR_CMD_DONE) {
2130 pcie_ireg &= ~HOST_INTR_CMD_DONE;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002131 if (adapter->cmd_sent) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07002132 dev_dbg(adapter->dev,
2133 "info: CMD sent Interrupt\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07002134 adapter->cmd_sent = false;
2135 }
2136 /* Handle command response */
2137 ret = mwifiex_pcie_process_cmd_complete(adapter);
2138 if (ret)
2139 return ret;
2140 }
2141
2142 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
2143 if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS,
2144 &pcie_ireg)) {
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07002145 dev_warn(adapter->dev,
2146 "Read register failed\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07002147 return -1;
2148 }
2149
2150 if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
2151 if (mwifiex_write_reg(adapter,
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07002152 PCIE_HOST_INT_STATUS,
2153 ~pcie_ireg)) {
2154 dev_warn(adapter->dev,
2155 "Write register failed\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07002156 return -1;
2157 }
Amitkumar Karward930fae2011-10-11 17:41:21 -07002158 }
2159
2160 }
2161 }
2162 dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n",
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07002163 adapter->cmd_sent, adapter->data_sent);
Avinash Patilb2fda1f2013-03-22 21:49:05 -07002164 if (adapter->ps_state != PS_STATE_SLEEP)
2165 mwifiex_pcie_enable_host_int(adapter);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002166
2167 return 0;
2168}
2169
2170/*
2171 * This function downloads data from driver to card.
2172 *
2173 * Both commands and data packets are transferred to the card by this
2174 * function.
2175 *
2176 * This function adds the PCIE specific header to the front of the buffer
2177 * before transferring. The header contains the length of the packet and
2178 * the type. The firmware handles the packets based upon this set type.
2179 */
2180static int mwifiex_pcie_host_to_card(struct mwifiex_adapter *adapter, u8 type,
2181 struct sk_buff *skb,
2182 struct mwifiex_tx_param *tx_param)
2183{
Dan Carpenterfa161cb2011-11-07 19:31:45 -08002184 if (!skb) {
2185 dev_err(adapter->dev, "Passed NULL skb to %s\n", __func__);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002186 return -1;
2187 }
2188
2189 if (type == MWIFIEX_TYPE_DATA)
Avinash Patile7f767a2013-01-03 21:21:32 -08002190 return mwifiex_pcie_send_data(adapter, skb, tx_param);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002191 else if (type == MWIFIEX_TYPE_CMD)
2192 return mwifiex_pcie_send_cmd(adapter, skb);
2193
2194 return 0;
2195}
2196
Amitkumar Karwar92c25382014-06-19 21:38:52 -07002197/* This function read/write firmware */
2198static enum rdwr_status
2199mwifiex_pcie_rdwr_firmware(struct mwifiex_adapter *adapter, u8 doneflag)
2200{
2201 int ret, tries;
2202 u8 ctrl_data;
2203 struct pcie_service_card *card = adapter->card;
2204 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
2205
2206 ret = mwifiex_write_reg(adapter, reg->fw_dump_ctrl, FW_DUMP_HOST_READY);
2207 if (ret) {
2208 dev_err(adapter->dev, "PCIE write err\n");
2209 return RDWR_STATUS_FAILURE;
2210 }
2211
2212 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
2213 mwifiex_read_reg_byte(adapter, reg->fw_dump_ctrl, &ctrl_data);
2214 if (ctrl_data == FW_DUMP_DONE)
2215 return RDWR_STATUS_SUCCESS;
2216 if (doneflag && ctrl_data == doneflag)
2217 return RDWR_STATUS_DONE;
2218 if (ctrl_data != FW_DUMP_HOST_READY) {
2219 dev_info(adapter->dev,
2220 "The ctrl reg was changed, re-try again!\n");
2221 mwifiex_write_reg(adapter, reg->fw_dump_ctrl,
2222 FW_DUMP_HOST_READY);
2223 if (ret) {
2224 dev_err(adapter->dev, "PCIE write err\n");
2225 return RDWR_STATUS_FAILURE;
2226 }
2227 }
2228 usleep_range(100, 200);
2229 }
2230
2231 dev_err(adapter->dev, "Fail to pull ctrl_data\n");
2232 return RDWR_STATUS_FAILURE;
2233}
2234
2235/* This function dump firmware memory to file */
2236static void mwifiex_pcie_fw_dump_work(struct mwifiex_adapter *adapter)
2237{
2238 struct pcie_service_card *card = adapter->card;
2239 const struct mwifiex_pcie_card_reg *creg = card->pcie.reg;
2240 unsigned int reg, reg_start, reg_end;
2241 struct timeval t;
2242 u8 *dbg_ptr, *end_ptr, dump_num, idx, i, read_reg, doneflag = 0;
2243 enum rdwr_status stat;
2244 u32 memory_size;
2245 static char *env[] = { "DRIVER=mwifiex_pcie", "EVENT=fw_dump", NULL };
2246
2247 if (!card->pcie.supports_fw_dump)
2248 return;
2249
2250 for (idx = 0; idx < ARRAY_SIZE(mem_type_mapping_tbl); idx++) {
2251 struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx];
2252
2253 if (entry->mem_ptr) {
2254 vfree(entry->mem_ptr);
2255 entry->mem_ptr = NULL;
2256 }
2257 entry->mem_size = 0;
2258 }
2259
2260 do_gettimeofday(&t);
2261 dev_info(adapter->dev, "== mwifiex firmware dump start: %u.%06u ==\n",
2262 (u32)t.tv_sec, (u32)t.tv_usec);
2263
2264 /* Read the number of the memories which will dump */
2265 stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
2266 if (stat == RDWR_STATUS_FAILURE)
2267 goto done;
2268
2269 reg = creg->fw_dump_start;
2270 mwifiex_read_reg_byte(adapter, reg, &dump_num);
2271
2272 /* Read the length of every memory which will dump */
2273 for (idx = 0; idx < dump_num; idx++) {
2274 struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx];
2275
2276 stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
2277 if (stat == RDWR_STATUS_FAILURE)
2278 goto done;
2279
2280 memory_size = 0;
2281 reg = creg->fw_dump_start;
2282 for (i = 0; i < 4; i++) {
2283 mwifiex_read_reg_byte(adapter, reg, &read_reg);
2284 memory_size |= (read_reg << (i * 8));
2285 reg++;
2286 }
2287
2288 if (memory_size == 0) {
2289 dev_info(adapter->dev, "Firmware dump Finished!\n");
2290 break;
2291 }
2292
2293 dev_info(adapter->dev,
2294 "%s_SIZE=0x%x\n", entry->mem_name, memory_size);
2295 entry->mem_ptr = vmalloc(memory_size + 1);
2296 entry->mem_size = memory_size;
2297 if (!entry->mem_ptr) {
2298 dev_err(adapter->dev,
2299 "Vmalloc %s failed\n", entry->mem_name);
2300 goto done;
2301 }
2302 dbg_ptr = entry->mem_ptr;
2303 end_ptr = dbg_ptr + memory_size;
2304
2305 doneflag = entry->done_flag;
2306 do_gettimeofday(&t);
2307 dev_info(adapter->dev, "Start %s output %u.%06u, please wait...\n",
2308 entry->mem_name, (u32)t.tv_sec, (u32)t.tv_usec);
2309
2310 do {
2311 stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
2312 if (RDWR_STATUS_FAILURE == stat)
2313 goto done;
2314
2315 reg_start = creg->fw_dump_start;
2316 reg_end = creg->fw_dump_end;
2317 for (reg = reg_start; reg <= reg_end; reg++) {
2318 mwifiex_read_reg_byte(adapter, reg, dbg_ptr);
2319 if (dbg_ptr < end_ptr)
2320 dbg_ptr++;
2321 else
2322 dev_err(adapter->dev,
2323 "Allocated buf not enough\n");
2324 }
2325
2326 if (stat != RDWR_STATUS_DONE)
2327 continue;
2328
2329 dev_info(adapter->dev, "%s done: size=0x%tx\n",
2330 entry->mem_name, dbg_ptr - entry->mem_ptr);
2331 break;
2332 } while (true);
2333 }
2334 do_gettimeofday(&t);
2335 dev_info(adapter->dev, "== mwifiex firmware dump end: %u.%06u ==\n",
2336 (u32)t.tv_sec, (u32)t.tv_usec);
2337
2338 kobject_uevent_env(&adapter->wiphy->dev.kobj, KOBJ_CHANGE, env);
2339
2340done:
2341 adapter->curr_mem_idx = 0;
2342}
2343
2344static void mwifiex_pcie_work(struct work_struct *work)
2345{
2346 struct mwifiex_adapter *adapter =
2347 container_of(work, struct mwifiex_adapter, iface_work);
2348
2349 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_FW_DUMP,
2350 &adapter->iface_work_flags))
2351 mwifiex_pcie_fw_dump_work(adapter);
2352}
2353
2354/* This function dumps FW information */
2355static void mwifiex_pcie_fw_dump(struct mwifiex_adapter *adapter)
2356{
2357 if (test_bit(MWIFIEX_IFACE_WORK_FW_DUMP, &adapter->iface_work_flags))
2358 return;
2359
2360 set_bit(MWIFIEX_IFACE_WORK_FW_DUMP, &adapter->iface_work_flags);
2361
2362 schedule_work(&adapter->iface_work);
2363}
2364
Amitkumar Karward930fae2011-10-11 17:41:21 -07002365/*
2366 * This function initializes the PCI-E host memory space, WCB rings, etc.
2367 *
2368 * The following initializations steps are followed -
2369 * - Allocate TXBD ring buffers
2370 * - Allocate RXBD ring buffers
2371 * - Allocate event BD ring buffers
2372 * - Allocate command response ring buffer
2373 * - Allocate sleep cookie buffer
2374 */
2375static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
2376{
2377 struct pcie_service_card *card = adapter->card;
2378 int ret;
2379 struct pci_dev *pdev = card->dev;
Avinash Patil52301a82013-02-12 14:38:32 -08002380 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002381
2382 pci_set_drvdata(pdev, card);
2383
2384 ret = pci_enable_device(pdev);
2385 if (ret)
2386 goto err_enable_dev;
2387
2388 pci_set_master(pdev);
2389
2390 dev_dbg(adapter->dev, "try set_consistent_dma_mask(32)\n");
2391 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2392 if (ret) {
2393 dev_err(adapter->dev, "set_dma_mask(32) failed\n");
2394 goto err_set_dma_mask;
2395 }
2396
2397 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2398 if (ret) {
2399 dev_err(adapter->dev, "set_consistent_dma_mask(64) failed\n");
2400 goto err_set_dma_mask;
2401 }
2402
2403 ret = pci_request_region(pdev, 0, DRV_NAME);
2404 if (ret) {
2405 dev_err(adapter->dev, "req_reg(0) error\n");
2406 goto err_req_region0;
2407 }
2408 card->pci_mmap = pci_iomap(pdev, 0, 0);
2409 if (!card->pci_mmap) {
2410 dev_err(adapter->dev, "iomap(0) error\n");
Alexey Khoroshilov32207122013-01-26 00:56:03 +04002411 ret = -EIO;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002412 goto err_iomap0;
2413 }
2414 ret = pci_request_region(pdev, 2, DRV_NAME);
2415 if (ret) {
2416 dev_err(adapter->dev, "req_reg(2) error\n");
2417 goto err_req_region2;
2418 }
2419 card->pci_mmap1 = pci_iomap(pdev, 2, 0);
2420 if (!card->pci_mmap1) {
2421 dev_err(adapter->dev, "iomap(2) error\n");
Alexey Khoroshilov32207122013-01-26 00:56:03 +04002422 ret = -EIO;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002423 goto err_iomap2;
2424 }
2425
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07002426 dev_dbg(adapter->dev,
2427 "PCI memory map Virt0: %p PCI memory map Virt2: %p\n",
2428 card->pci_mmap, card->pci_mmap1);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002429
2430 card->cmdrsp_buf = NULL;
2431 ret = mwifiex_pcie_create_txbd_ring(adapter);
2432 if (ret)
2433 goto err_cre_txbd;
2434 ret = mwifiex_pcie_create_rxbd_ring(adapter);
2435 if (ret)
2436 goto err_cre_rxbd;
2437 ret = mwifiex_pcie_create_evtbd_ring(adapter);
2438 if (ret)
2439 goto err_cre_evtbd;
2440 ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter);
2441 if (ret)
2442 goto err_alloc_cmdbuf;
Avinash Patil52301a82013-02-12 14:38:32 -08002443 if (reg->sleep_cookie) {
2444 ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter);
2445 if (ret)
2446 goto err_alloc_cookie;
2447 } else {
2448 card->sleep_cookie_vbase = NULL;
2449 }
Amitkumar Karward930fae2011-10-11 17:41:21 -07002450 return ret;
2451
2452err_alloc_cookie:
2453 mwifiex_pcie_delete_cmdrsp_buf(adapter);
2454err_alloc_cmdbuf:
2455 mwifiex_pcie_delete_evtbd_ring(adapter);
2456err_cre_evtbd:
2457 mwifiex_pcie_delete_rxbd_ring(adapter);
2458err_cre_rxbd:
2459 mwifiex_pcie_delete_txbd_ring(adapter);
2460err_cre_txbd:
2461 pci_iounmap(pdev, card->pci_mmap1);
2462err_iomap2:
2463 pci_release_region(pdev, 2);
2464err_req_region2:
2465 pci_iounmap(pdev, card->pci_mmap);
2466err_iomap0:
2467 pci_release_region(pdev, 0);
2468err_req_region0:
2469err_set_dma_mask:
2470 pci_disable_device(pdev);
2471err_enable_dev:
2472 pci_set_drvdata(pdev, NULL);
2473 return ret;
2474}
2475
2476/*
2477 * This function cleans up the allocated card buffers.
2478 *
2479 * The following are freed by this function -
2480 * - TXBD ring buffers
2481 * - RXBD ring buffers
2482 * - Event BD ring buffers
2483 * - Command response ring buffer
2484 * - Sleep cookie buffer
2485 */
2486static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter)
2487{
2488 struct pcie_service_card *card = adapter->card;
2489 struct pci_dev *pdev = card->dev;
Avinash Patildd04e6a2013-02-08 18:18:06 -08002490 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002491
Amitkumar Karward930fae2011-10-11 17:41:21 -07002492 if (user_rmmod) {
Avinash Patilfc331462013-01-03 21:21:30 -08002493 dev_dbg(adapter->dev, "Clearing driver ready signature\n");
Avinash Patildd04e6a2013-02-08 18:18:06 -08002494 if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000))
Yogesh Ashok Powarf57c1ed2012-03-13 19:22:37 -07002495 dev_err(adapter->dev,
2496 "Failed to write driver not-ready signature\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07002497 }
2498
2499 if (pdev) {
2500 pci_iounmap(pdev, card->pci_mmap);
2501 pci_iounmap(pdev, card->pci_mmap1);
Yogesh Ashok Powar5b0d9b22013-04-23 16:49:48 -07002502 pci_disable_device(pdev);
Yogesh Ashok Powarc380aaf2013-04-23 16:49:47 -07002503 pci_release_region(pdev, 2);
2504 pci_release_region(pdev, 0);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002505 pci_set_drvdata(pdev, NULL);
2506 }
Amitkumar Karwar3c59e322013-11-14 19:10:41 -08002507 kfree(card);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002508}
2509
2510/*
2511 * This function registers the PCIE device.
2512 *
2513 * PCIE IRQ is claimed, block size is set and driver data is initialized.
2514 */
2515static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
2516{
2517 int ret;
2518 struct pcie_service_card *card = adapter->card;
2519 struct pci_dev *pdev = card->dev;
2520
2521 /* save adapter pointer in card */
2522 card->adapter = adapter;
2523
2524 ret = request_irq(pdev->irq, mwifiex_pcie_interrupt, IRQF_SHARED,
2525 "MRVL_PCIE", pdev);
2526 if (ret) {
2527 pr_err("request_irq failed: ret=%d\n", ret);
2528 adapter->card = NULL;
2529 return -1;
2530 }
2531
2532 adapter->dev = &pdev->dev;
Amitkumar Karwar828cf222014-02-27 19:35:13 -08002533 adapter->tx_buf_size = card->pcie.tx_buf_size;
Amitkumar Karwar92c25382014-06-19 21:38:52 -07002534 adapter->mem_type_mapping_tbl = mem_type_mapping_tbl;
2535 adapter->num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl);
Avinash Patildd04e6a2013-02-08 18:18:06 -08002536 strcpy(adapter->fw_name, card->pcie.firmware);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002537
2538 return 0;
2539}
2540
2541/*
2542 * This function unregisters the PCIE device.
2543 *
2544 * The PCIE IRQ is released, the function is disabled and driver
2545 * data is set to null.
2546 */
2547static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
2548{
2549 struct pcie_service_card *card = adapter->card;
Avinash Patil52301a82013-02-12 14:38:32 -08002550 const struct mwifiex_pcie_card_reg *reg;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002551
2552 if (card) {
2553 dev_dbg(adapter->dev, "%s(): calling free_irq()\n", __func__);
2554 free_irq(card->dev->irq, card->dev);
Avinash Patilfc331462013-01-03 21:21:30 -08002555
Avinash Patil52301a82013-02-12 14:38:32 -08002556 reg = card->pcie.reg;
2557 if (reg->sleep_cookie)
2558 mwifiex_pcie_delete_sleep_cookie_buf(adapter);
2559
Avinash Patilfc331462013-01-03 21:21:30 -08002560 mwifiex_pcie_delete_cmdrsp_buf(adapter);
2561 mwifiex_pcie_delete_evtbd_ring(adapter);
2562 mwifiex_pcie_delete_rxbd_ring(adapter);
2563 mwifiex_pcie_delete_txbd_ring(adapter);
2564 card->cmdrsp_buf = NULL;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002565 }
2566}
2567
2568static struct mwifiex_if_ops pcie_ops = {
2569 .init_if = mwifiex_pcie_init,
2570 .cleanup_if = mwifiex_pcie_cleanup,
2571 .check_fw_status = mwifiex_check_fw_status,
2572 .prog_fw = mwifiex_prog_fw_w_helper,
2573 .register_dev = mwifiex_register_dev,
2574 .unregister_dev = mwifiex_unregister_dev,
2575 .enable_int = mwifiex_pcie_enable_host_int,
2576 .process_int_status = mwifiex_process_int_status,
2577 .host_to_card = mwifiex_pcie_host_to_card,
2578 .wakeup = mwifiex_pm_wakeup_card,
2579 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
2580
2581 /* PCIE specific */
2582 .cmdrsp_complete = mwifiex_pcie_cmdrsp_complete,
2583 .event_complete = mwifiex_pcie_event_complete,
2584 .update_mp_end_port = NULL,
2585 .cleanup_mpa_buf = NULL,
Avinash Patilc6d1d872013-01-03 21:21:29 -08002586 .init_fw_port = mwifiex_pcie_init_fw_port,
Avinash Patilfbd7e7a2013-01-03 21:21:31 -08002587 .clean_pcie_ring = mwifiex_clean_pcie_ring_buf,
Amitkumar Karwar92c25382014-06-19 21:38:52 -07002588 .fw_dump = mwifiex_pcie_fw_dump,
2589 .iface_work = mwifiex_pcie_work,
Amitkumar Karward930fae2011-10-11 17:41:21 -07002590};
2591
2592/*
2593 * This function initializes the PCIE driver module.
2594 *
2595 * This initiates the semaphore and registers the device with
2596 * PCIE bus.
2597 */
2598static int mwifiex_pcie_init_module(void)
2599{
2600 int ret;
2601
Avinash Patilca8f2112013-02-08 18:18:09 -08002602 pr_debug("Marvell PCIe Driver\n");
Amitkumar Karward930fae2011-10-11 17:41:21 -07002603
2604 sema_init(&add_remove_card_sem, 1);
2605
2606 /* Clear the flag in case user removes the card. */
2607 user_rmmod = 0;
2608
2609 ret = pci_register_driver(&mwifiex_pcie);
2610 if (ret)
2611 pr_err("Driver register failed!\n");
2612 else
2613 pr_debug("info: Driver registered successfully!\n");
2614
2615 return ret;
2616}
2617
2618/*
2619 * This function cleans up the PCIE driver.
2620 *
2621 * The following major steps are followed for cleanup -
2622 * - Resume the device if its suspended
2623 * - Disconnect the device if connected
2624 * - Shutdown the firmware
2625 * - Unregister the device from PCIE bus.
2626 */
2627static void mwifiex_pcie_cleanup_module(void)
2628{
2629 if (!down_interruptible(&add_remove_card_sem))
2630 up(&add_remove_card_sem);
2631
2632 /* Set the flag as user is removing this module. */
2633 user_rmmod = 1;
2634
2635 pci_unregister_driver(&mwifiex_pcie);
2636}
2637
2638module_init(mwifiex_pcie_init_module);
2639module_exit(mwifiex_pcie_cleanup_module);
2640
2641MODULE_AUTHOR("Marvell International Ltd.");
2642MODULE_DESCRIPTION("Marvell WiFi-Ex PCI-Express Driver version " PCIE_VERSION);
2643MODULE_VERSION(PCIE_VERSION);
2644MODULE_LICENSE("GPL v2");
Avinash Patilca8f2112013-02-08 18:18:09 -08002645MODULE_FIRMWARE(PCIE8766_DEFAULT_FW_NAME);
2646MODULE_FIRMWARE(PCIE8897_DEFAULT_FW_NAME);