2 * Marvell Wireless LAN device driver: PCIE specific handling
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
20 #include <linux/firmware.h>
31 #define PCIE_VERSION "1.0"
32 #define DRV_NAME "Marvell mwifiex PCIe"
36 static struct mwifiex_if_ops pcie_ops;
38 static const struct of_device_id mwifiex_pcie_of_match_table[] = {
39 { .compatible = "pci11ab,2b42" },
40 { .compatible = "pci1b4b,2b42" },
44 static int mwifiex_pcie_probe_of(struct device *dev)
46 if (!of_match_node(mwifiex_pcie_of_match_table, dev->of_node)) {
47 dev_err(dev, "required compatible string missing\n");
55 mwifiex_map_pci_memory(struct mwifiex_adapter *adapter, struct sk_buff *skb,
56 size_t size, int flags)
58 struct pcie_service_card *card = adapter->card;
59 struct mwifiex_dma_mapping mapping;
61 mapping.addr = pci_map_single(card->dev, skb->data, size, flags);
62 if (pci_dma_mapping_error(card->dev, mapping.addr)) {
63 mwifiex_dbg(adapter, ERROR, "failed to map pci memory!\n");
67 mwifiex_store_mapping(skb, &mapping);
71 static void mwifiex_unmap_pci_memory(struct mwifiex_adapter *adapter,
72 struct sk_buff *skb, int flags)
74 struct pcie_service_card *card = adapter->card;
75 struct mwifiex_dma_mapping mapping;
77 mwifiex_get_mapping(skb, &mapping);
78 pci_unmap_single(card->dev, mapping.addr, mapping.len, flags);
82 * This function reads sleep cookie and checks if FW is ready
84 static bool mwifiex_pcie_ok_to_access_hw(struct mwifiex_adapter *adapter)
87 struct pcie_service_card *card = adapter->card;
88 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
90 if (!reg->sleep_cookie)
93 if (card->sleep_cookie_vbase) {
94 cookie_addr = (u32 *)card->sleep_cookie_vbase;
95 mwifiex_dbg(adapter, INFO,
96 "info: ACCESS_HW: sleep cookie=0x%x\n",
98 if (*cookie_addr == FW_AWAKE_COOKIE)
105 #ifdef CONFIG_PM_SLEEP
107 * Kernel needs to suspend all functions separately. Therefore all
108 * registered functions must have drivers with suspend and resume
109 * methods. Failing that the kernel simply removes the whole card.
111 * If already not suspended, this function allocates and sends a host
112 * sleep activate request to the firmware and turns off the traffic.
114 static int mwifiex_pcie_suspend(struct device *dev)
116 struct mwifiex_adapter *adapter;
117 struct pcie_service_card *card;
118 struct pci_dev *pdev = to_pci_dev(dev);
120 card = pci_get_drvdata(pdev);
122 /* Might still be loading firmware */
123 wait_for_completion(&card->fw_done);
125 adapter = card->adapter;
127 dev_err(dev, "adapter is not valid\n");
131 mwifiex_enable_wake(adapter);
133 /* Enable the Host Sleep */
134 if (!mwifiex_enable_hs(adapter)) {
135 mwifiex_dbg(adapter, ERROR,
136 "cmd: failed to suspend\n");
137 adapter->hs_enabling = false;
138 mwifiex_disable_wake(adapter);
142 flush_workqueue(adapter->workqueue);
144 /* Indicate device suspended */
145 adapter->is_suspended = true;
146 adapter->hs_enabling = false;
152 * Kernel needs to suspend all functions separately. Therefore all
153 * registered functions must have drivers with suspend and resume
154 * methods. Failing that the kernel simply removes the whole card.
156 * If already not resumed, this function turns on the traffic and
157 * sends a host sleep cancel request to the firmware.
159 static int mwifiex_pcie_resume(struct device *dev)
161 struct mwifiex_adapter *adapter;
162 struct pcie_service_card *card;
163 struct pci_dev *pdev = to_pci_dev(dev);
165 card = pci_get_drvdata(pdev);
167 if (!card->adapter) {
168 dev_err(dev, "adapter structure is not valid\n");
172 adapter = card->adapter;
174 if (!adapter->is_suspended) {
175 mwifiex_dbg(adapter, WARN,
176 "Device already resumed\n");
180 adapter->is_suspended = false;
182 mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
184 mwifiex_disable_wake(adapter);
191 * This function probes an mwifiex device and registers it. It allocates
192 * the card structure, enables PCIE function number and initiates the
193 * device registration and initialization procedure by adding a logical
196 static int mwifiex_pcie_probe(struct pci_dev *pdev,
197 const struct pci_device_id *ent)
199 struct pcie_service_card *card;
202 pr_debug("info: vendor=0x%4.04X device=0x%4.04X rev=%d\n",
203 pdev->vendor, pdev->device, pdev->revision);
205 card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL);
209 init_completion(&card->fw_done);
213 if (ent->driver_data) {
214 struct mwifiex_pcie_device *data = (void *)ent->driver_data;
215 card->pcie.reg = data->reg;
216 card->pcie.blksz_fw_dl = data->blksz_fw_dl;
217 card->pcie.tx_buf_size = data->tx_buf_size;
218 card->pcie.can_dump_fw = data->can_dump_fw;
219 card->pcie.mem_type_mapping_tbl = data->mem_type_mapping_tbl;
220 card->pcie.num_mem_types = data->num_mem_types;
221 card->pcie.can_ext_scan = data->can_ext_scan;
224 /* device tree node parsing and platform specific configuration*/
225 if (pdev->dev.of_node) {
226 ret = mwifiex_pcie_probe_of(&pdev->dev);
231 if (mwifiex_add_card(card, &card->fw_done, &pcie_ops,
232 MWIFIEX_PCIE, &pdev->dev)) {
233 pr_err("%s failed\n", __func__);
241 * This function removes the interface and frees up the card structure.
243 static void mwifiex_pcie_remove(struct pci_dev *pdev)
245 struct pcie_service_card *card;
246 struct mwifiex_adapter *adapter;
247 struct mwifiex_private *priv;
249 card = pci_get_drvdata(pdev);
251 wait_for_completion(&card->fw_done);
253 adapter = card->adapter;
254 if (!adapter || !adapter->priv_num)
257 if (user_rmmod && !adapter->mfg_mode) {
258 mwifiex_deauthenticate_all(adapter);
260 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
262 mwifiex_disable_auto_ds(priv);
264 mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
267 mwifiex_remove_card(adapter);
270 static void mwifiex_pcie_shutdown(struct pci_dev *pdev)
273 mwifiex_pcie_remove(pdev);
278 static const struct pci_device_id mwifiex_ids[] = {
280 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8766P,
281 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
282 .driver_data = (unsigned long)&mwifiex_pcie8766,
285 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8897,
286 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
287 .driver_data = (unsigned long)&mwifiex_pcie8897,
290 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8997,
291 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
292 .driver_data = (unsigned long)&mwifiex_pcie8997,
295 PCIE_VENDOR_ID_V2_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8997,
296 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
297 .driver_data = (unsigned long)&mwifiex_pcie8997,
302 MODULE_DEVICE_TABLE(pci, mwifiex_ids);
304 static void mwifiex_pcie_reset_notify(struct pci_dev *pdev, bool prepare)
306 struct mwifiex_adapter *adapter;
307 struct pcie_service_card *card;
310 pr_err("%s: PCIe device is not specified\n", __func__);
314 card = (struct pcie_service_card *)pci_get_drvdata(pdev);
315 if (!card || !card->adapter) {
316 pr_err("%s: Card or adapter structure is not valid (%ld)\n",
317 __func__, (long)card);
321 adapter = card->adapter;
322 mwifiex_dbg(adapter, INFO,
323 "%s: vendor=0x%4.04x device=0x%4.04x rev=%d %s\n",
324 __func__, pdev->vendor, pdev->device,
326 prepare ? "Pre-FLR" : "Post-FLR");
329 /* Kernel would be performing FLR after this notification.
330 * Cleanup all software without cleaning anything related to
333 mwifiex_do_flr(adapter, prepare);
334 adapter->surprise_removed = true;
336 /* Kernel stores and restores PCIe function context before and
337 * after performing FLR respectively. Reconfigure the software
338 * and firmware including firmware redownload
340 adapter->surprise_removed = false;
341 mwifiex_do_flr(adapter, prepare);
343 mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
346 static const struct pci_error_handlers mwifiex_pcie_err_handler[] = {
347 { .reset_notify = mwifiex_pcie_reset_notify, },
350 #ifdef CONFIG_PM_SLEEP
351 /* Power Management Hooks */
352 static SIMPLE_DEV_PM_OPS(mwifiex_pcie_pm_ops, mwifiex_pcie_suspend,
353 mwifiex_pcie_resume);
356 /* PCI Device Driver */
357 static struct pci_driver __refdata mwifiex_pcie = {
358 .name = "mwifiex_pcie",
359 .id_table = mwifiex_ids,
360 .probe = mwifiex_pcie_probe,
361 .remove = mwifiex_pcie_remove,
362 #ifdef CONFIG_PM_SLEEP
364 .pm = &mwifiex_pcie_pm_ops,
367 .shutdown = mwifiex_pcie_shutdown,
368 .err_handler = mwifiex_pcie_err_handler,
372 * This function writes data into PCIE card register.
374 static int mwifiex_write_reg(struct mwifiex_adapter *adapter, int reg, u32 data)
376 struct pcie_service_card *card = adapter->card;
378 iowrite32(data, card->pci_mmap1 + reg);
384 * This function reads data from PCIE card register.
386 static int mwifiex_read_reg(struct mwifiex_adapter *adapter, int reg, u32 *data)
388 struct pcie_service_card *card = adapter->card;
390 *data = ioread32(card->pci_mmap1 + reg);
391 if (*data == 0xffffffff)
397 /* This function reads u8 data from PCIE card register. */
398 static int mwifiex_read_reg_byte(struct mwifiex_adapter *adapter,
401 struct pcie_service_card *card = adapter->card;
403 *data = ioread8(card->pci_mmap1 + reg);
409 * This function adds delay loop to ensure FW is awake before proceeding.
411 static void mwifiex_pcie_dev_wakeup_delay(struct mwifiex_adapter *adapter)
415 while (mwifiex_pcie_ok_to_access_hw(adapter)) {
417 usleep_range(10, 20);
426 static void mwifiex_delay_for_sleep_cookie(struct mwifiex_adapter *adapter,
427 u32 max_delay_loop_cnt)
429 struct pcie_service_card *card = adapter->card;
431 u32 sleep_cookie, count;
433 for (count = 0; count < max_delay_loop_cnt; count++) {
434 buffer = card->cmdrsp_buf->data - INTF_HEADER_LEN;
435 sleep_cookie = *(u32 *)buffer;
437 if (sleep_cookie == MWIFIEX_DEF_SLEEP_COOKIE) {
438 mwifiex_dbg(adapter, INFO,
439 "sleep cookie found at count %d\n", count);
442 usleep_range(20, 30);
445 if (count >= max_delay_loop_cnt)
446 mwifiex_dbg(adapter, INFO,
447 "max count reached while accessing sleep cookie\n");
450 /* This function wakes up the card by reading fw_status register. */
451 static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
454 struct pcie_service_card *card = adapter->card;
455 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
457 mwifiex_dbg(adapter, EVENT,
458 "event: Wakeup device...\n");
460 if (reg->sleep_cookie)
461 mwifiex_pcie_dev_wakeup_delay(adapter);
463 /* Reading fw_status register will wakeup device */
464 if (mwifiex_read_reg(adapter, reg->fw_status, &fw_status)) {
465 mwifiex_dbg(adapter, ERROR,
466 "Reading fw_status register failed\n");
470 if (reg->sleep_cookie) {
471 mwifiex_pcie_dev_wakeup_delay(adapter);
472 mwifiex_dbg(adapter, INFO,
473 "PCIE wakeup: Setting PS_STATE_AWAKE\n");
474 adapter->ps_state = PS_STATE_AWAKE;
481 * This function is called after the card has woken up.
483 * The card configuration register is reset.
485 static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
487 mwifiex_dbg(adapter, CMD,
488 "cmd: Wakeup device completed\n");
494 * This function disables the host interrupt.
496 * The host interrupt mask is read, the disable bit is reset and
497 * written back to the card host interrupt mask register.
499 static int mwifiex_pcie_disable_host_int(struct mwifiex_adapter *adapter)
501 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
502 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK,
504 mwifiex_dbg(adapter, ERROR,
505 "Disable host interrupt failed\n");
510 atomic_set(&adapter->tx_hw_pending, 0);
514 static void mwifiex_pcie_disable_host_int_noerr(struct mwifiex_adapter *adapter)
516 WARN_ON(mwifiex_pcie_disable_host_int(adapter));
520 * This function enables the host interrupt.
522 * The host interrupt enable mask is written to the card
523 * host interrupt mask register.
525 static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter)
527 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
528 /* Simply write the mask to the register */
529 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK,
531 mwifiex_dbg(adapter, ERROR,
532 "Enable host interrupt failed\n");
541 * This function initializes TX buffer ring descriptors
543 static int mwifiex_init_txq_ring(struct mwifiex_adapter *adapter)
545 struct pcie_service_card *card = adapter->card;
546 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
547 struct mwifiex_pcie_buf_desc *desc;
548 struct mwifiex_pfu_buf_desc *desc2;
551 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
552 card->tx_buf_list[i] = NULL;
553 if (reg->pfu_enabled) {
554 card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
555 (sizeof(*desc2) * i);
556 desc2 = card->txbd_ring[i];
557 memset(desc2, 0, sizeof(*desc2));
559 card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
561 desc = card->txbd_ring[i];
562 memset(desc, 0, sizeof(*desc));
569 /* This function initializes RX buffer ring descriptors. Each SKB is allocated
570 * here and after mapping PCI memory, its physical address is assigned to
571 * PCIE Rx buffer descriptor's physical address.
573 static int mwifiex_init_rxq_ring(struct mwifiex_adapter *adapter)
575 struct pcie_service_card *card = adapter->card;
576 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
578 struct mwifiex_pcie_buf_desc *desc;
579 struct mwifiex_pfu_buf_desc *desc2;
583 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
584 /* Allocate skb here so that firmware can DMA data from it */
585 skb = mwifiex_alloc_dma_align_buf(MWIFIEX_RX_DATA_BUF_SIZE,
588 mwifiex_dbg(adapter, ERROR,
589 "Unable to allocate skb for RX ring.\n");
590 kfree(card->rxbd_ring_vbase);
594 if (mwifiex_map_pci_memory(adapter, skb,
595 MWIFIEX_RX_DATA_BUF_SIZE,
599 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
601 mwifiex_dbg(adapter, INFO,
602 "info: RX ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
603 skb, skb->len, skb->data, (u32)buf_pa,
604 (u32)((u64)buf_pa >> 32));
606 card->rx_buf_list[i] = skb;
607 if (reg->pfu_enabled) {
608 card->rxbd_ring[i] = (void *)card->rxbd_ring_vbase +
609 (sizeof(*desc2) * i);
610 desc2 = card->rxbd_ring[i];
611 desc2->paddr = buf_pa;
612 desc2->len = (u16)skb->len;
613 desc2->frag_len = (u16)skb->len;
614 desc2->flags = reg->ring_flag_eop | reg->ring_flag_sop;
617 card->rxbd_ring[i] = (void *)(card->rxbd_ring_vbase +
618 (sizeof(*desc) * i));
619 desc = card->rxbd_ring[i];
620 desc->paddr = buf_pa;
621 desc->len = (u16)skb->len;
629 /* This function initializes event buffer ring descriptors. Each SKB is
630 * allocated here and after mapping PCI memory, its physical address is assigned
631 * to PCIE Rx buffer descriptor's physical address
633 static int mwifiex_pcie_init_evt_ring(struct mwifiex_adapter *adapter)
635 struct pcie_service_card *card = adapter->card;
636 struct mwifiex_evt_buf_desc *desc;
641 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
642 /* Allocate skb here so that firmware can DMA data from it */
643 skb = dev_alloc_skb(MAX_EVENT_SIZE);
645 mwifiex_dbg(adapter, ERROR,
646 "Unable to allocate skb for EVENT buf.\n");
647 kfree(card->evtbd_ring_vbase);
650 skb_put(skb, MAX_EVENT_SIZE);
652 if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE,
656 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
658 mwifiex_dbg(adapter, EVENT,
659 "info: EVT ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
660 skb, skb->len, skb->data, (u32)buf_pa,
661 (u32)((u64)buf_pa >> 32));
663 card->evt_buf_list[i] = skb;
664 card->evtbd_ring[i] = (void *)(card->evtbd_ring_vbase +
665 (sizeof(*desc) * i));
666 desc = card->evtbd_ring[i];
667 desc->paddr = buf_pa;
668 desc->len = (u16)skb->len;
675 /* This function cleans up TX buffer rings. If any of the buffer list has valid
676 * SKB address, associated SKB is freed.
678 static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter)
680 struct pcie_service_card *card = adapter->card;
681 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
683 struct mwifiex_pcie_buf_desc *desc;
684 struct mwifiex_pfu_buf_desc *desc2;
687 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
688 if (reg->pfu_enabled) {
689 desc2 = card->txbd_ring[i];
690 if (card->tx_buf_list[i]) {
691 skb = card->tx_buf_list[i];
692 mwifiex_unmap_pci_memory(adapter, skb,
694 dev_kfree_skb_any(skb);
696 memset(desc2, 0, sizeof(*desc2));
698 desc = card->txbd_ring[i];
699 if (card->tx_buf_list[i]) {
700 skb = card->tx_buf_list[i];
701 mwifiex_unmap_pci_memory(adapter, skb,
703 dev_kfree_skb_any(skb);
705 memset(desc, 0, sizeof(*desc));
707 card->tx_buf_list[i] = NULL;
710 atomic_set(&adapter->tx_hw_pending, 0);
714 /* This function cleans up RX buffer rings. If any of the buffer list has valid
715 * SKB address, associated SKB is freed.
717 static void mwifiex_cleanup_rxq_ring(struct mwifiex_adapter *adapter)
719 struct pcie_service_card *card = adapter->card;
720 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
721 struct mwifiex_pcie_buf_desc *desc;
722 struct mwifiex_pfu_buf_desc *desc2;
726 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
727 if (reg->pfu_enabled) {
728 desc2 = card->rxbd_ring[i];
729 if (card->rx_buf_list[i]) {
730 skb = card->rx_buf_list[i];
731 mwifiex_unmap_pci_memory(adapter, skb,
733 dev_kfree_skb_any(skb);
735 memset(desc2, 0, sizeof(*desc2));
737 desc = card->rxbd_ring[i];
738 if (card->rx_buf_list[i]) {
739 skb = card->rx_buf_list[i];
740 mwifiex_unmap_pci_memory(adapter, skb,
742 dev_kfree_skb_any(skb);
744 memset(desc, 0, sizeof(*desc));
746 card->rx_buf_list[i] = NULL;
752 /* This function cleans up event buffer rings. If any of the buffer list has
753 * valid SKB address, associated SKB is freed.
755 static void mwifiex_cleanup_evt_ring(struct mwifiex_adapter *adapter)
757 struct pcie_service_card *card = adapter->card;
758 struct mwifiex_evt_buf_desc *desc;
762 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
763 desc = card->evtbd_ring[i];
764 if (card->evt_buf_list[i]) {
765 skb = card->evt_buf_list[i];
766 mwifiex_unmap_pci_memory(adapter, skb,
768 dev_kfree_skb_any(skb);
770 card->evt_buf_list[i] = NULL;
771 memset(desc, 0, sizeof(*desc));
777 /* This function creates buffer descriptor ring for TX
779 static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter)
781 struct pcie_service_card *card = adapter->card;
782 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
785 * driver maintaines the write pointer and firmware maintaines the read
786 * pointer. The write pointer starts at 0 (zero) while the read pointer
787 * starts at zero with rollover bit set
789 card->txbd_wrptr = 0;
791 if (reg->pfu_enabled)
792 card->txbd_rdptr = 0;
794 card->txbd_rdptr |= reg->tx_rollover_ind;
796 /* allocate shared memory for the BD ring and divide the same in to
797 several descriptors */
798 if (reg->pfu_enabled)
799 card->txbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
802 card->txbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
805 mwifiex_dbg(adapter, INFO,
806 "info: txbd_ring: Allocating %d bytes\n",
807 card->txbd_ring_size);
808 card->txbd_ring_vbase = pci_alloc_consistent(card->dev,
809 card->txbd_ring_size,
810 &card->txbd_ring_pbase);
811 if (!card->txbd_ring_vbase) {
812 mwifiex_dbg(adapter, ERROR,
813 "allocate consistent memory (%d bytes) failed!\n",
814 card->txbd_ring_size);
817 mwifiex_dbg(adapter, DATA,
818 "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n",
819 card->txbd_ring_vbase, (unsigned int)card->txbd_ring_pbase,
820 (u32)((u64)card->txbd_ring_pbase >> 32),
821 card->txbd_ring_size);
823 return mwifiex_init_txq_ring(adapter);
826 static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter)
828 struct pcie_service_card *card = adapter->card;
829 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
831 mwifiex_cleanup_txq_ring(adapter);
833 if (card->txbd_ring_vbase)
834 pci_free_consistent(card->dev, card->txbd_ring_size,
835 card->txbd_ring_vbase,
836 card->txbd_ring_pbase);
837 card->txbd_ring_size = 0;
838 card->txbd_wrptr = 0;
839 card->txbd_rdptr = 0 | reg->tx_rollover_ind;
840 card->txbd_ring_vbase = NULL;
841 card->txbd_ring_pbase = 0;
847 * This function creates buffer descriptor ring for RX
849 static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter)
851 struct pcie_service_card *card = adapter->card;
852 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
855 * driver maintaines the read pointer and firmware maintaines the write
856 * pointer. The write pointer starts at 0 (zero) while the read pointer
857 * starts at zero with rollover bit set
859 card->rxbd_wrptr = 0;
860 card->rxbd_rdptr = reg->rx_rollover_ind;
862 if (reg->pfu_enabled)
863 card->rxbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
866 card->rxbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
869 mwifiex_dbg(adapter, INFO,
870 "info: rxbd_ring: Allocating %d bytes\n",
871 card->rxbd_ring_size);
872 card->rxbd_ring_vbase = pci_alloc_consistent(card->dev,
873 card->rxbd_ring_size,
874 &card->rxbd_ring_pbase);
875 if (!card->rxbd_ring_vbase) {
876 mwifiex_dbg(adapter, ERROR,
877 "allocate consistent memory (%d bytes) failed!\n",
878 card->rxbd_ring_size);
882 mwifiex_dbg(adapter, DATA,
883 "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n",
884 card->rxbd_ring_vbase, (u32)card->rxbd_ring_pbase,
885 (u32)((u64)card->rxbd_ring_pbase >> 32),
886 card->rxbd_ring_size);
888 return mwifiex_init_rxq_ring(adapter);
892 * This function deletes Buffer descriptor ring for RX
894 static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter)
896 struct pcie_service_card *card = adapter->card;
897 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
899 mwifiex_cleanup_rxq_ring(adapter);
901 if (card->rxbd_ring_vbase)
902 pci_free_consistent(card->dev, card->rxbd_ring_size,
903 card->rxbd_ring_vbase,
904 card->rxbd_ring_pbase);
905 card->rxbd_ring_size = 0;
906 card->rxbd_wrptr = 0;
907 card->rxbd_rdptr = 0 | reg->rx_rollover_ind;
908 card->rxbd_ring_vbase = NULL;
909 card->rxbd_ring_pbase = 0;
915 * This function creates buffer descriptor ring for Events
917 static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter)
919 struct pcie_service_card *card = adapter->card;
920 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
923 * driver maintaines the read pointer and firmware maintaines the write
924 * pointer. The write pointer starts at 0 (zero) while the read pointer
925 * starts at zero with rollover bit set
927 card->evtbd_wrptr = 0;
928 card->evtbd_rdptr = reg->evt_rollover_ind;
930 card->evtbd_ring_size = sizeof(struct mwifiex_evt_buf_desc) *
933 mwifiex_dbg(adapter, INFO,
934 "info: evtbd_ring: Allocating %d bytes\n",
935 card->evtbd_ring_size);
936 card->evtbd_ring_vbase = pci_alloc_consistent(card->dev,
937 card->evtbd_ring_size,
938 &card->evtbd_ring_pbase);
939 if (!card->evtbd_ring_vbase) {
940 mwifiex_dbg(adapter, ERROR,
941 "allocate consistent memory (%d bytes) failed!\n",
942 card->evtbd_ring_size);
946 mwifiex_dbg(adapter, EVENT,
947 "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n",
948 card->evtbd_ring_vbase, (u32)card->evtbd_ring_pbase,
949 (u32)((u64)card->evtbd_ring_pbase >> 32),
950 card->evtbd_ring_size);
952 return mwifiex_pcie_init_evt_ring(adapter);
956 * This function deletes Buffer descriptor ring for Events
958 static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter)
960 struct pcie_service_card *card = adapter->card;
961 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
963 mwifiex_cleanup_evt_ring(adapter);
965 if (card->evtbd_ring_vbase)
966 pci_free_consistent(card->dev, card->evtbd_ring_size,
967 card->evtbd_ring_vbase,
968 card->evtbd_ring_pbase);
969 card->evtbd_wrptr = 0;
970 card->evtbd_rdptr = 0 | reg->evt_rollover_ind;
971 card->evtbd_ring_size = 0;
972 card->evtbd_ring_vbase = NULL;
973 card->evtbd_ring_pbase = 0;
979 * This function allocates a buffer for CMDRSP
981 static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter)
983 struct pcie_service_card *card = adapter->card;
986 /* Allocate memory for receiving command response data */
987 skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE);
989 mwifiex_dbg(adapter, ERROR,
990 "Unable to allocate skb for command response data.\n");
993 skb_put(skb, MWIFIEX_UPLD_SIZE);
994 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
998 card->cmdrsp_buf = skb;
1004 * This function deletes a buffer for CMDRSP
1006 static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter)
1008 struct pcie_service_card *card;
1013 card = adapter->card;
1015 if (card && card->cmdrsp_buf) {
1016 mwifiex_unmap_pci_memory(adapter, card->cmdrsp_buf,
1017 PCI_DMA_FROMDEVICE);
1018 dev_kfree_skb_any(card->cmdrsp_buf);
1021 if (card && card->cmd_buf) {
1022 mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
1029 * This function allocates a buffer for sleep cookie
1031 static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter)
1033 struct pcie_service_card *card = adapter->card;
1035 card->sleep_cookie_vbase = pci_alloc_consistent(card->dev, sizeof(u32),
1036 &card->sleep_cookie_pbase);
1037 if (!card->sleep_cookie_vbase) {
1038 mwifiex_dbg(adapter, ERROR,
1039 "pci_alloc_consistent failed!\n");
1042 /* Init val of Sleep Cookie */
1043 *(u32 *)card->sleep_cookie_vbase = FW_AWAKE_COOKIE;
1045 mwifiex_dbg(adapter, INFO,
1046 "alloc_scook: sleep cookie=0x%x\n",
1047 *((u32 *)card->sleep_cookie_vbase));
1053 * This function deletes buffer for sleep cookie
1055 static int mwifiex_pcie_delete_sleep_cookie_buf(struct mwifiex_adapter *adapter)
1057 struct pcie_service_card *card;
1062 card = adapter->card;
1064 if (card && card->sleep_cookie_vbase) {
1065 pci_free_consistent(card->dev, sizeof(u32),
1066 card->sleep_cookie_vbase,
1067 card->sleep_cookie_pbase);
1068 card->sleep_cookie_vbase = NULL;
1074 /* This function flushes the TX buffer descriptor ring
1075 * This function defined as handler is also called while cleaning TXRX
1076 * during disconnect/ bss stop.
1078 static int mwifiex_clean_pcie_ring_buf(struct mwifiex_adapter *adapter)
1080 struct pcie_service_card *card = adapter->card;
1082 if (!mwifiex_pcie_txbd_empty(card, card->txbd_rdptr)) {
1083 card->txbd_flush = 1;
1084 /* write pointer already set at last send
1085 * send dnld-rdy intr again, wait for completion.
1087 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1088 CPU_INTR_DNLD_RDY)) {
1089 mwifiex_dbg(adapter, ERROR,
1090 "failed to assert dnld-rdy interrupt.\n");
1098 * This function unmaps and frees downloaded data buffer
1100 static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter)
1102 struct sk_buff *skb;
1103 u32 wrdoneidx, rdptr, num_tx_buffs, unmap_count = 0;
1104 struct mwifiex_pcie_buf_desc *desc;
1105 struct mwifiex_pfu_buf_desc *desc2;
1106 struct pcie_service_card *card = adapter->card;
1107 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1109 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1110 mwifiex_pm_wakeup_card(adapter);
1112 /* Read the TX ring read pointer set by firmware */
1113 if (mwifiex_read_reg(adapter, reg->tx_rdptr, &rdptr)) {
1114 mwifiex_dbg(adapter, ERROR,
1115 "SEND COMP: failed to read reg->tx_rdptr\n");
1119 mwifiex_dbg(adapter, DATA,
1120 "SEND COMP: rdptr_prev=0x%x, rdptr=0x%x\n",
1121 card->txbd_rdptr, rdptr);
1123 num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
1124 /* free from previous txbd_rdptr to current txbd_rdptr */
1125 while (((card->txbd_rdptr & reg->tx_mask) !=
1126 (rdptr & reg->tx_mask)) ||
1127 ((card->txbd_rdptr & reg->tx_rollover_ind) !=
1128 (rdptr & reg->tx_rollover_ind))) {
1129 wrdoneidx = (card->txbd_rdptr & reg->tx_mask) >>
1132 skb = card->tx_buf_list[wrdoneidx];
1135 mwifiex_dbg(adapter, DATA,
1136 "SEND COMP: Detach skb %p at txbd_rdidx=%d\n",
1138 mwifiex_unmap_pci_memory(adapter, skb,
1143 if (card->txbd_flush)
1144 mwifiex_write_data_complete(adapter, skb, 0,
1147 mwifiex_write_data_complete(adapter, skb, 0, 0);
1148 atomic_dec(&adapter->tx_hw_pending);
1151 card->tx_buf_list[wrdoneidx] = NULL;
1153 if (reg->pfu_enabled) {
1154 desc2 = card->txbd_ring[wrdoneidx];
1155 memset(desc2, 0, sizeof(*desc2));
1157 desc = card->txbd_ring[wrdoneidx];
1158 memset(desc, 0, sizeof(*desc));
1160 switch (card->dev->device) {
1161 case PCIE_DEVICE_ID_MARVELL_88W8766P:
1164 case PCIE_DEVICE_ID_MARVELL_88W8897:
1165 case PCIE_DEVICE_ID_MARVELL_88W8997:
1166 card->txbd_rdptr += reg->ring_tx_start_ptr;
1171 if ((card->txbd_rdptr & reg->tx_mask) == num_tx_buffs)
1172 card->txbd_rdptr = ((card->txbd_rdptr &
1173 reg->tx_rollover_ind) ^
1174 reg->tx_rollover_ind);
1178 adapter->data_sent = false;
1180 if (card->txbd_flush) {
1181 if (mwifiex_pcie_txbd_empty(card, card->txbd_rdptr))
1182 card->txbd_flush = 0;
1184 mwifiex_clean_pcie_ring_buf(adapter);
1190 /* This function sends data buffer to device. First 4 bytes of payload
1191 * are filled with payload length and payload type. Then this payload
1192 * is mapped to PCI device memory. Tx ring pointers are advanced accordingly.
1193 * Download ready interrupt to FW is deffered if Tx ring is not full and
1194 * additional payload can be accomodated.
1195 * Caller must ensure tx_param parameter to this function is not NULL.
1198 mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
1199 struct mwifiex_tx_param *tx_param)
1201 struct pcie_service_card *card = adapter->card;
1202 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1203 u32 wrindx, num_tx_buffs, rx_val;
1206 struct mwifiex_pcie_buf_desc *desc = NULL;
1207 struct mwifiex_pfu_buf_desc *desc2 = NULL;
1210 if (!(skb->data && skb->len)) {
1211 mwifiex_dbg(adapter, ERROR,
1212 "%s(): invalid parameter <%p, %#x>\n",
1213 __func__, skb->data, skb->len);
1217 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1218 mwifiex_pm_wakeup_card(adapter);
1220 num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
1221 mwifiex_dbg(adapter, DATA,
1222 "info: SEND DATA: <Rd: %#x, Wr: %#x>\n",
1223 card->txbd_rdptr, card->txbd_wrptr);
1224 if (mwifiex_pcie_txbd_not_full(card)) {
1227 adapter->data_sent = true;
1228 payload = skb->data;
1229 tmp = (__le16 *)&payload[0];
1230 *tmp = cpu_to_le16((u16)skb->len);
1231 tmp = (__le16 *)&payload[2];
1232 *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA);
1234 if (mwifiex_map_pci_memory(adapter, skb, skb->len,
1238 wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;
1239 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
1240 card->tx_buf_list[wrindx] = skb;
1241 atomic_inc(&adapter->tx_hw_pending);
1243 if (reg->pfu_enabled) {
1244 desc2 = card->txbd_ring[wrindx];
1245 desc2->paddr = buf_pa;
1246 desc2->len = (u16)skb->len;
1247 desc2->frag_len = (u16)skb->len;
1249 desc2->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
1250 MWIFIEX_BD_FLAG_LAST_DESC;
1252 desc = card->txbd_ring[wrindx];
1253 desc->paddr = buf_pa;
1254 desc->len = (u16)skb->len;
1255 desc->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
1256 MWIFIEX_BD_FLAG_LAST_DESC;
1259 switch (card->dev->device) {
1260 case PCIE_DEVICE_ID_MARVELL_88W8766P:
1263 case PCIE_DEVICE_ID_MARVELL_88W8897:
1264 case PCIE_DEVICE_ID_MARVELL_88W8997:
1265 card->txbd_wrptr += reg->ring_tx_start_ptr;
1269 if ((card->txbd_wrptr & reg->tx_mask) == num_tx_buffs)
1270 card->txbd_wrptr = ((card->txbd_wrptr &
1271 reg->tx_rollover_ind) ^
1272 reg->tx_rollover_ind);
1274 rx_val = card->rxbd_rdptr & reg->rx_wrap_mask;
1275 /* Write the TX ring write pointer in to reg->tx_wrptr */
1276 if (mwifiex_write_reg(adapter, reg->tx_wrptr,
1277 card->txbd_wrptr | rx_val)) {
1278 mwifiex_dbg(adapter, ERROR,
1279 "SEND DATA: failed to write reg->tx_wrptr\n");
1283 if ((mwifiex_pcie_txbd_not_full(card)) &&
1284 tx_param->next_pkt_len) {
1285 /* have more packets and TxBD still can hold more */
1286 mwifiex_dbg(adapter, DATA,
1287 "SEND DATA: delay dnld-rdy interrupt.\n");
1288 adapter->data_sent = false;
1290 /* Send the TX ready interrupt */
1291 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1292 CPU_INTR_DNLD_RDY)) {
1293 mwifiex_dbg(adapter, ERROR,
1294 "SEND DATA: failed to assert dnld-rdy interrupt.\n");
1299 mwifiex_dbg(adapter, DATA,
1300 "info: SEND DATA: Updated <Rd: %#x, Wr:\t"
1301 "%#x> and sent packet to firmware successfully\n",
1302 card->txbd_rdptr, card->txbd_wrptr);
1304 mwifiex_dbg(adapter, DATA,
1305 "info: TX Ring full, can't send packets to fw\n");
1306 adapter->data_sent = true;
1307 /* Send the TX ready interrupt */
1308 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1310 mwifiex_dbg(adapter, ERROR,
1311 "SEND DATA: failed to assert door-bell intr\n");
1315 return -EINPROGRESS;
1317 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1318 card->tx_buf_list[wrindx] = NULL;
1319 atomic_dec(&adapter->tx_hw_pending);
1320 if (reg->pfu_enabled)
1321 memset(desc2, 0, sizeof(*desc2));
1323 memset(desc, 0, sizeof(*desc));
1329 * This function handles received buffer ring and
1330 * dispatches packets to upper
1332 static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter)
1334 struct pcie_service_card *card = adapter->card;
1335 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1336 u32 wrptr, rd_index, tx_val;
1339 struct sk_buff *skb_tmp = NULL;
1340 struct mwifiex_pcie_buf_desc *desc;
1341 struct mwifiex_pfu_buf_desc *desc2;
1343 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1344 mwifiex_pm_wakeup_card(adapter);
1346 /* Read the RX ring Write pointer set by firmware */
1347 if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
1348 mwifiex_dbg(adapter, ERROR,
1349 "RECV DATA: failed to read reg->rx_wrptr\n");
1353 card->rxbd_wrptr = wrptr;
1355 while (((wrptr & reg->rx_mask) !=
1356 (card->rxbd_rdptr & reg->rx_mask)) ||
1357 ((wrptr & reg->rx_rollover_ind) ==
1358 (card->rxbd_rdptr & reg->rx_rollover_ind))) {
1359 struct sk_buff *skb_data;
1363 rd_index = card->rxbd_rdptr & reg->rx_mask;
1364 skb_data = card->rx_buf_list[rd_index];
1366 /* If skb allocation was failed earlier for Rx packet,
1367 * rx_buf_list[rd_index] would have been left with a NULL.
1372 mwifiex_unmap_pci_memory(adapter, skb_data, PCI_DMA_FROMDEVICE);
1373 card->rx_buf_list[rd_index] = NULL;
1375 /* Get data length from interface header -
1376 * first 2 bytes for len, next 2 bytes is for type
1378 pkt_len = *((__le16 *)skb_data->data);
1379 rx_len = le16_to_cpu(pkt_len);
1380 if (WARN_ON(rx_len <= INTF_HEADER_LEN ||
1381 rx_len > MWIFIEX_RX_DATA_BUF_SIZE)) {
1382 mwifiex_dbg(adapter, ERROR,
1383 "Invalid RX len %d, Rd=%#x, Wr=%#x\n",
1384 rx_len, card->rxbd_rdptr, wrptr);
1385 dev_kfree_skb_any(skb_data);
1387 skb_put(skb_data, rx_len);
1388 mwifiex_dbg(adapter, DATA,
1389 "info: RECV DATA: Rd=%#x, Wr=%#x, Len=%d\n",
1390 card->rxbd_rdptr, wrptr, rx_len);
1391 skb_pull(skb_data, INTF_HEADER_LEN);
1392 if (adapter->rx_work_enabled) {
1393 skb_queue_tail(&adapter->rx_data_q, skb_data);
1394 adapter->data_received = true;
1395 atomic_inc(&adapter->rx_pending);
1397 mwifiex_handle_rx_packet(adapter, skb_data);
1401 skb_tmp = mwifiex_alloc_dma_align_buf(MWIFIEX_RX_DATA_BUF_SIZE,
1404 mwifiex_dbg(adapter, ERROR,
1405 "Unable to allocate skb.\n");
1409 if (mwifiex_map_pci_memory(adapter, skb_tmp,
1410 MWIFIEX_RX_DATA_BUF_SIZE,
1411 PCI_DMA_FROMDEVICE))
1414 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb_tmp);
1416 mwifiex_dbg(adapter, INFO,
1417 "RECV DATA: Attach new sk_buff %p at rxbd_rdidx=%d\n",
1419 card->rx_buf_list[rd_index] = skb_tmp;
1421 if (reg->pfu_enabled) {
1422 desc2 = card->rxbd_ring[rd_index];
1423 desc2->paddr = buf_pa;
1424 desc2->len = skb_tmp->len;
1425 desc2->frag_len = skb_tmp->len;
1427 desc2->flags = reg->ring_flag_sop | reg->ring_flag_eop;
1429 desc = card->rxbd_ring[rd_index];
1430 desc->paddr = buf_pa;
1431 desc->len = skb_tmp->len;
1435 if ((++card->rxbd_rdptr & reg->rx_mask) ==
1436 MWIFIEX_MAX_TXRX_BD) {
1437 card->rxbd_rdptr = ((card->rxbd_rdptr &
1438 reg->rx_rollover_ind) ^
1439 reg->rx_rollover_ind);
1441 mwifiex_dbg(adapter, DATA,
1442 "info: RECV DATA: <Rd: %#x, Wr: %#x>\n",
1443 card->rxbd_rdptr, wrptr);
1445 tx_val = card->txbd_wrptr & reg->tx_wrap_mask;
1446 /* Write the RX ring read pointer in to reg->rx_rdptr */
1447 if (mwifiex_write_reg(adapter, reg->rx_rdptr,
1448 card->rxbd_rdptr | tx_val)) {
1449 mwifiex_dbg(adapter, DATA,
1450 "RECV DATA: failed to write reg->rx_rdptr\n");
1455 /* Read the RX ring Write pointer set by firmware */
1456 if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
1457 mwifiex_dbg(adapter, ERROR,
1458 "RECV DATA: failed to read reg->rx_wrptr\n");
1462 mwifiex_dbg(adapter, DATA,
1463 "info: RECV DATA: Rcvd packet from fw successfully\n");
1464 card->rxbd_wrptr = wrptr;
1472 * This function downloads the boot command to device
1475 mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
1478 struct pcie_service_card *card = adapter->card;
1479 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1481 if (!(skb->data && skb->len)) {
1482 mwifiex_dbg(adapter, ERROR,
1483 "Invalid parameter in %s <%p. len %d>\n",
1484 __func__, skb->data, skb->len);
1488 if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE))
1491 buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
1493 /* Write the lower 32bits of the physical address to low command
1494 * address scratch register
1496 if (mwifiex_write_reg(adapter, reg->cmd_addr_lo, (u32)buf_pa)) {
1497 mwifiex_dbg(adapter, ERROR,
1498 "%s: failed to write download command to boot code.\n",
1500 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1504 /* Write the upper 32bits of the physical address to high command
1505 * address scratch register
1507 if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
1508 (u32)((u64)buf_pa >> 32))) {
1509 mwifiex_dbg(adapter, ERROR,
1510 "%s: failed to write download command to boot code.\n",
1512 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1516 /* Write the command length to cmd_size scratch register */
1517 if (mwifiex_write_reg(adapter, reg->cmd_size, skb->len)) {
1518 mwifiex_dbg(adapter, ERROR,
1519 "%s: failed to write command len to cmd_size scratch reg\n",
1521 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1525 /* Ring the door bell */
1526 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1527 CPU_INTR_DOOR_BELL)) {
1528 mwifiex_dbg(adapter, ERROR,
1529 "%s: failed to assert door-bell intr\n", __func__);
1530 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
1537 /* This function init rx port in firmware which in turn enables to receive data
1538 * from device before transmitting any packet.
1540 static int mwifiex_pcie_init_fw_port(struct mwifiex_adapter *adapter)
1542 struct pcie_service_card *card = adapter->card;
1543 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1544 int tx_wrap = card->txbd_wrptr & reg->tx_wrap_mask;
1546 /* Write the RX ring read pointer in to reg->rx_rdptr */
1547 if (mwifiex_write_reg(adapter, reg->rx_rdptr, card->rxbd_rdptr |
1549 mwifiex_dbg(adapter, ERROR,
1550 "RECV DATA: failed to write reg->rx_rdptr\n");
1556 /* This function downloads commands to the device
1559 mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
1561 struct pcie_service_card *card = adapter->card;
1562 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1564 dma_addr_t cmd_buf_pa, cmdrsp_buf_pa;
1565 u8 *payload = (u8 *)skb->data;
1567 if (!(skb->data && skb->len)) {
1568 mwifiex_dbg(adapter, ERROR,
1569 "Invalid parameter in %s <%p, %#x>\n",
1570 __func__, skb->data, skb->len);
1574 /* Make sure a command response buffer is available */
1575 if (!card->cmdrsp_buf) {
1576 mwifiex_dbg(adapter, ERROR,
1577 "No response buffer available, send command failed\n");
1581 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1582 mwifiex_pm_wakeup_card(adapter);
1584 adapter->cmd_sent = true;
1586 *(__le16 *)&payload[0] = cpu_to_le16((u16)skb->len);
1587 *(__le16 *)&payload[2] = cpu_to_le16(MWIFIEX_TYPE_CMD);
1589 if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE))
1592 card->cmd_buf = skb;
1594 /* To send a command, the driver will:
1595 1. Write the 64bit physical address of the data buffer to
1596 cmd response address low + cmd response address high
1597 2. Ring the door bell (i.e. set the door bell interrupt)
1599 In response to door bell interrupt, the firmware will perform
1600 the DMA of the command packet (first header to obtain the total
1601 length and then rest of the command).
1604 if (card->cmdrsp_buf) {
1605 cmdrsp_buf_pa = MWIFIEX_SKB_DMA_ADDR(card->cmdrsp_buf);
1606 /* Write the lower 32bits of the cmdrsp buffer physical
1608 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo,
1609 (u32)cmdrsp_buf_pa)) {
1610 mwifiex_dbg(adapter, ERROR,
1611 "Failed to write download cmd to boot code.\n");
1615 /* Write the upper 32bits of the cmdrsp buffer physical
1617 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi,
1618 (u32)((u64)cmdrsp_buf_pa >> 32))) {
1619 mwifiex_dbg(adapter, ERROR,
1620 "Failed to write download cmd to boot code.\n");
1626 cmd_buf_pa = MWIFIEX_SKB_DMA_ADDR(card->cmd_buf);
1627 /* Write the lower 32bits of the physical address to reg->cmd_addr_lo */
1628 if (mwifiex_write_reg(adapter, reg->cmd_addr_lo,
1630 mwifiex_dbg(adapter, ERROR,
1631 "Failed to write download cmd to boot code.\n");
1635 /* Write the upper 32bits of the physical address to reg->cmd_addr_hi */
1636 if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
1637 (u32)((u64)cmd_buf_pa >> 32))) {
1638 mwifiex_dbg(adapter, ERROR,
1639 "Failed to write download cmd to boot code.\n");
1644 /* Write the command length to reg->cmd_size */
1645 if (mwifiex_write_reg(adapter, reg->cmd_size,
1646 card->cmd_buf->len)) {
1647 mwifiex_dbg(adapter, ERROR,
1648 "Failed to write cmd len to reg->cmd_size\n");
1653 /* Ring the door bell */
1654 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1655 CPU_INTR_DOOR_BELL)) {
1656 mwifiex_dbg(adapter, ERROR,
1657 "Failed to assert door-bell intr\n");
1664 adapter->cmd_sent = false;
1670 * This function handles command complete interrupt
1672 static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
1674 struct pcie_service_card *card = adapter->card;
1675 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1676 struct sk_buff *skb = card->cmdrsp_buf;
1681 mwifiex_dbg(adapter, CMD,
1682 "info: Rx CMD Response\n");
1684 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_FROMDEVICE);
1686 /* Unmap the command as a response has been received. */
1687 if (card->cmd_buf) {
1688 mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
1690 card->cmd_buf = NULL;
1693 pkt_len = *((__le16 *)skb->data);
1694 rx_len = le16_to_cpu(pkt_len);
1695 skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len);
1696 skb_trim(skb, rx_len);
1697 skb_pull(skb, INTF_HEADER_LEN);
1699 if (!adapter->curr_cmd) {
1700 if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
1701 if (mwifiex_write_reg(adapter,
1703 CPU_INTR_SLEEP_CFM_DONE)) {
1704 mwifiex_dbg(adapter, ERROR,
1705 "Write register failed\n");
1708 mwifiex_delay_for_sleep_cookie(adapter,
1709 MWIFIEX_MAX_DELAY_COUNT);
1710 while (reg->sleep_cookie && (count++ < 10) &&
1711 mwifiex_pcie_ok_to_access_hw(adapter))
1712 usleep_range(50, 60);
1713 mwifiex_pcie_enable_host_int(adapter);
1714 mwifiex_process_sleep_confirm_resp(adapter, skb->data,
1717 mwifiex_dbg(adapter, ERROR,
1718 "There is no command but got cmdrsp\n");
1720 memcpy(adapter->upld_buf, skb->data,
1721 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len));
1722 skb_push(skb, INTF_HEADER_LEN);
1723 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1724 PCI_DMA_FROMDEVICE))
1726 } else if (mwifiex_pcie_ok_to_access_hw(adapter)) {
1727 adapter->curr_cmd->resp_skb = skb;
1728 adapter->cmd_resp_received = true;
1729 /* Take the pointer and set it to CMD node and will
1730 return in the response complete callback */
1731 card->cmdrsp_buf = NULL;
1733 /* Clear the cmd-rsp buffer address in scratch registers. This
1734 will prevent firmware from writing to the same response
1736 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo, 0)) {
1737 mwifiex_dbg(adapter, ERROR,
1738 "cmd_done: failed to clear cmd_rsp_addr_lo\n");
1741 /* Write the upper 32bits of the cmdrsp buffer physical
1743 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi, 0)) {
1744 mwifiex_dbg(adapter, ERROR,
1745 "cmd_done: failed to clear cmd_rsp_addr_hi\n");
1754 * Command Response processing complete handler
1756 static int mwifiex_pcie_cmdrsp_complete(struct mwifiex_adapter *adapter,
1757 struct sk_buff *skb)
1759 struct pcie_service_card *card = adapter->card;
1762 card->cmdrsp_buf = skb;
1763 skb_push(card->cmdrsp_buf, INTF_HEADER_LEN);
1764 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1765 PCI_DMA_FROMDEVICE))
1773 * This function handles firmware event ready interrupt
1775 static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter)
1777 struct pcie_service_card *card = adapter->card;
1778 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1779 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
1781 struct mwifiex_evt_buf_desc *desc;
1783 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1784 mwifiex_pm_wakeup_card(adapter);
1786 if (adapter->event_received) {
1787 mwifiex_dbg(adapter, EVENT,
1788 "info: Event being processed,\t"
1789 "do not process this interrupt just yet\n");
1793 if (rdptr >= MWIFIEX_MAX_EVT_BD) {
1794 mwifiex_dbg(adapter, ERROR,
1795 "info: Invalid read pointer...\n");
1799 /* Read the event ring write pointer set by firmware */
1800 if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
1801 mwifiex_dbg(adapter, ERROR,
1802 "EventReady: failed to read reg->evt_wrptr\n");
1806 mwifiex_dbg(adapter, EVENT,
1807 "info: EventReady: Initial <Rd: 0x%x, Wr: 0x%x>",
1808 card->evtbd_rdptr, wrptr);
1809 if (((wrptr & MWIFIEX_EVTBD_MASK) != (card->evtbd_rdptr
1810 & MWIFIEX_EVTBD_MASK)) ||
1811 ((wrptr & reg->evt_rollover_ind) ==
1812 (card->evtbd_rdptr & reg->evt_rollover_ind))) {
1813 struct sk_buff *skb_cmd;
1814 __le16 data_len = 0;
1817 mwifiex_dbg(adapter, INFO,
1818 "info: Read Index: %d\n", rdptr);
1819 skb_cmd = card->evt_buf_list[rdptr];
1820 mwifiex_unmap_pci_memory(adapter, skb_cmd, PCI_DMA_FROMDEVICE);
1822 /* Take the pointer and set it to event pointer in adapter
1823 and will return back after event handling callback */
1824 card->evt_buf_list[rdptr] = NULL;
1825 desc = card->evtbd_ring[rdptr];
1826 memset(desc, 0, sizeof(*desc));
1828 event = *(u32 *) &skb_cmd->data[INTF_HEADER_LEN];
1829 adapter->event_cause = event;
1830 /* The first 4bytes will be the event transfer header
1831 len is 2 bytes followed by type which is 2 bytes */
1832 memcpy(&data_len, skb_cmd->data, sizeof(__le16));
1833 evt_len = le16_to_cpu(data_len);
1834 skb_trim(skb_cmd, evt_len);
1835 skb_pull(skb_cmd, INTF_HEADER_LEN);
1836 mwifiex_dbg(adapter, EVENT,
1837 "info: Event length: %d\n", evt_len);
1839 if ((evt_len > 0) && (evt_len < MAX_EVENT_SIZE))
1840 memcpy(adapter->event_body, skb_cmd->data +
1841 MWIFIEX_EVENT_HEADER_LEN, evt_len -
1842 MWIFIEX_EVENT_HEADER_LEN);
1844 adapter->event_received = true;
1845 adapter->event_skb = skb_cmd;
1847 /* Do not update the event read pointer here, wait till the
1848 buffer is released. This is just to make things simpler,
1849 we need to find a better method of managing these buffers.
1852 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1853 CPU_INTR_EVENT_DONE)) {
1854 mwifiex_dbg(adapter, ERROR,
1855 "Write register failed\n");
1864 * Event processing complete handler
1866 static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,
1867 struct sk_buff *skb)
1869 struct pcie_service_card *card = adapter->card;
1870 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1872 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
1874 struct mwifiex_evt_buf_desc *desc;
1879 if (rdptr >= MWIFIEX_MAX_EVT_BD) {
1880 mwifiex_dbg(adapter, ERROR,
1881 "event_complete: Invalid rdptr 0x%x\n",
1886 /* Read the event ring write pointer set by firmware */
1887 if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
1888 mwifiex_dbg(adapter, ERROR,
1889 "event_complete: failed to read reg->evt_wrptr\n");
1893 if (!card->evt_buf_list[rdptr]) {
1894 skb_push(skb, INTF_HEADER_LEN);
1895 skb_put(skb, MAX_EVENT_SIZE - skb->len);
1896 if (mwifiex_map_pci_memory(adapter, skb,
1898 PCI_DMA_FROMDEVICE))
1900 card->evt_buf_list[rdptr] = skb;
1901 desc = card->evtbd_ring[rdptr];
1902 desc->paddr = MWIFIEX_SKB_DMA_ADDR(skb);
1903 desc->len = (u16)skb->len;
1907 mwifiex_dbg(adapter, ERROR,
1908 "info: ERROR: buf still valid at index %d, <%p, %p>\n",
1909 rdptr, card->evt_buf_list[rdptr], skb);
1912 if ((++card->evtbd_rdptr & MWIFIEX_EVTBD_MASK) == MWIFIEX_MAX_EVT_BD) {
1913 card->evtbd_rdptr = ((card->evtbd_rdptr &
1914 reg->evt_rollover_ind) ^
1915 reg->evt_rollover_ind);
1918 mwifiex_dbg(adapter, EVENT,
1919 "info: Updated <Rd: 0x%x, Wr: 0x%x>",
1920 card->evtbd_rdptr, wrptr);
1922 /* Write the event ring read pointer in to reg->evt_rdptr */
1923 if (mwifiex_write_reg(adapter, reg->evt_rdptr,
1924 card->evtbd_rdptr)) {
1925 mwifiex_dbg(adapter, ERROR,
1926 "event_complete: failed to read reg->evt_rdptr\n");
1930 mwifiex_dbg(adapter, EVENT,
1931 "info: Check Events Again\n");
1932 ret = mwifiex_pcie_process_event_ready(adapter);
1938 * This function downloads the firmware to the card.
1940 * Firmware is downloaded to the card in blocks. Every block download
1941 * is tested for CRC errors, and retried a number of times before
1942 * returning failure.
1944 static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1945 struct mwifiex_fw_image *fw)
1948 u8 *firmware = fw->fw_buf;
1949 u32 firmware_len = fw->fw_len;
1951 struct sk_buff *skb;
1952 u32 txlen, tx_blocks = 0, tries, len;
1953 u32 block_retry_cnt = 0;
1954 struct pcie_service_card *card = adapter->card;
1955 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1957 if (!firmware || !firmware_len) {
1958 mwifiex_dbg(adapter, ERROR,
1959 "No firmware image found! Terminating download\n");
1963 mwifiex_dbg(adapter, INFO,
1964 "info: Downloading FW image (%d bytes)\n",
1967 if (mwifiex_pcie_disable_host_int(adapter)) {
1968 mwifiex_dbg(adapter, ERROR,
1969 "%s: Disabling interrupts failed.\n", __func__);
1973 skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE);
1979 /* Perform firmware data transfer */
1984 if (offset >= firmware_len)
1987 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
1988 ret = mwifiex_read_reg(adapter, reg->cmd_size,
1991 mwifiex_dbg(adapter, FATAL,
1992 "Failed reading len from boot code\n");
1997 usleep_range(10, 20);
2002 } else if (len > MWIFIEX_UPLD_SIZE) {
2003 mwifiex_dbg(adapter, ERROR,
2004 "FW download failure @ %d, invalid length %d\n",
2014 if (block_retry_cnt > MAX_WRITE_IOMEM_RETRY) {
2015 mwifiex_dbg(adapter, ERROR,
2016 "FW download failure @ %d, over max\t"
2017 "retry count\n", offset);
2021 mwifiex_dbg(adapter, ERROR,
2022 "FW CRC error indicated by the\t"
2023 "helper: len = 0x%04X, txlen = %d\n",
2026 /* Setting this to 0 to resend from same offset */
2029 block_retry_cnt = 0;
2030 /* Set blocksize to transfer - checking for
2032 if (firmware_len - offset < txlen)
2033 txlen = firmware_len - offset;
2035 tx_blocks = (txlen + card->pcie.blksz_fw_dl - 1) /
2036 card->pcie.blksz_fw_dl;
2038 /* Copy payload to buffer */
2039 memmove(skb->data, &firmware[offset], txlen);
2042 skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len);
2043 skb_trim(skb, tx_blocks * card->pcie.blksz_fw_dl);
2045 /* Send the boot command to device */
2046 if (mwifiex_pcie_send_boot_cmd(adapter, skb)) {
2047 mwifiex_dbg(adapter, ERROR,
2048 "Failed to send firmware download command\n");
2053 /* Wait for the command done interrupt */
2054 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
2055 if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS,
2057 mwifiex_dbg(adapter, ERROR,
2058 "%s: Failed to read\t"
2059 "interrupt status during fw dnld.\n",
2061 mwifiex_unmap_pci_memory(adapter, skb,
2066 if (!(ireg_intr & CPU_INTR_DOOR_BELL))
2068 usleep_range(10, 20);
2070 if (ireg_intr & CPU_INTR_DOOR_BELL) {
2071 mwifiex_dbg(adapter, ERROR, "%s: Card failed to ACK download\n",
2073 mwifiex_unmap_pci_memory(adapter, skb,
2079 mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
2084 mwifiex_dbg(adapter, MSG,
2085 "info: FW download over, size %d bytes\n", offset);
2090 dev_kfree_skb_any(skb);
2095 * This function checks the firmware status in card.
2098 mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num)
2102 struct pcie_service_card *card = adapter->card;
2103 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
2106 /* Mask spurios interrupts */
2107 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS_MASK,
2109 mwifiex_dbg(adapter, ERROR,
2110 "Write register failed\n");
2114 mwifiex_dbg(adapter, INFO,
2115 "Setting driver ready signature\n");
2116 if (mwifiex_write_reg(adapter, reg->drv_rdy,
2117 FIRMWARE_READY_PCIE)) {
2118 mwifiex_dbg(adapter, ERROR,
2119 "Failed to write driver ready signature\n");
2123 /* Wait for firmware initialization event */
2124 for (tries = 0; tries < poll_num; tries++) {
2125 if (mwifiex_read_reg(adapter, reg->fw_status,
2131 mwifiex_dbg(adapter, INFO, "Try %d if FW is ready <%d,%#x>",
2132 tries, ret, firmware_stat);
2136 if (firmware_stat == FIRMWARE_READY_PCIE) {
2148 /* This function checks if WLAN is the winner.
2151 mwifiex_check_winner_status(struct mwifiex_adapter *adapter)
2155 struct pcie_service_card *card = adapter->card;
2156 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
2158 if (mwifiex_read_reg(adapter, reg->fw_status, &winner)) {
2160 } else if (!winner) {
2161 mwifiex_dbg(adapter, INFO, "PCI-E is the winner\n");
2162 adapter->winner = 1;
2164 mwifiex_dbg(adapter, ERROR,
2165 "PCI-E is not the winner <%#x>", winner);
2172 * This function reads the interrupt status from card.
2174 static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter,
2178 unsigned long flags;
2179 struct pcie_service_card *card = adapter->card;
2181 if (card->msi_enable) {
2182 spin_lock_irqsave(&adapter->int_lock, flags);
2183 adapter->int_status = 1;
2184 spin_unlock_irqrestore(&adapter->int_lock, flags);
2188 if (!mwifiex_pcie_ok_to_access_hw(adapter))
2191 if (card->msix_enable && msg_id >= 0) {
2192 pcie_ireg = BIT(msg_id);
2194 if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS,
2196 mwifiex_dbg(adapter, ERROR, "Read register failed\n");
2200 if ((pcie_ireg == 0xFFFFFFFF) || !pcie_ireg)
2204 mwifiex_pcie_disable_host_int(adapter);
2206 /* Clear the pending interrupts */
2207 if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS,
2209 mwifiex_dbg(adapter, ERROR,
2210 "Write register failed\n");
2215 if (!adapter->pps_uapsd_mode &&
2216 adapter->ps_state == PS_STATE_SLEEP &&
2217 mwifiex_pcie_ok_to_access_hw(adapter)) {
2218 /* Potentially for PCIe we could get other
2219 * interrupts like shared. Don't change power
2220 * state until cookie is set
2222 adapter->ps_state = PS_STATE_AWAKE;
2223 adapter->pm_wakeup_fw_try = false;
2224 del_timer(&adapter->wakeup_timer);
2227 spin_lock_irqsave(&adapter->int_lock, flags);
2228 adapter->int_status |= pcie_ireg;
2229 spin_unlock_irqrestore(&adapter->int_lock, flags);
2230 mwifiex_dbg(adapter, INTR, "ireg: 0x%08x\n", pcie_ireg);
2234 * Interrupt handler for PCIe root port
2236 * This function reads the interrupt status from firmware and assigns
2237 * the main process in workqueue which will handle the interrupt.
2239 static irqreturn_t mwifiex_pcie_interrupt(int irq, void *context)
2241 struct mwifiex_msix_context *ctx = context;
2242 struct pci_dev *pdev = ctx->dev;
2243 struct pcie_service_card *card;
2244 struct mwifiex_adapter *adapter;
2247 pr_err("info: %s: pdev is NULL\n", __func__);
2251 card = pci_get_drvdata(pdev);
2253 if (!card->adapter) {
2254 pr_err("info: %s: card=%p adapter=%p\n", __func__, card,
2255 card ? card->adapter : NULL);
2258 adapter = card->adapter;
2260 if (adapter->surprise_removed)
2263 if (card->msix_enable)
2264 mwifiex_interrupt_status(adapter, ctx->msg_id);
2266 mwifiex_interrupt_status(adapter, -1);
2268 mwifiex_queue_main_work(adapter);
2275 * This function checks the current interrupt status.
2277 * The following interrupts are checked and handled by this function -
2280 * - Command received
2281 * - Packets received
2284 * In case of Rx packets received, the packets are uploaded from card to
2285 * host and processed accordingly.
2287 static int mwifiex_process_pcie_int(struct mwifiex_adapter *adapter)
2291 unsigned long flags;
2292 struct pcie_service_card *card = adapter->card;
2294 spin_lock_irqsave(&adapter->int_lock, flags);
2295 if (!card->msi_enable) {
2296 /* Clear out unused interrupts */
2297 pcie_ireg = adapter->int_status;
2299 adapter->int_status = 0;
2300 spin_unlock_irqrestore(&adapter->int_lock, flags);
2302 if (card->msi_enable) {
2303 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
2304 if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS,
2306 mwifiex_dbg(adapter, ERROR,
2307 "Read register failed\n");
2311 if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
2312 if (mwifiex_write_reg(adapter,
2313 PCIE_HOST_INT_STATUS,
2315 mwifiex_dbg(adapter, ERROR,
2316 "Write register failed\n");
2319 if (!adapter->pps_uapsd_mode &&
2320 adapter->ps_state == PS_STATE_SLEEP) {
2321 adapter->ps_state = PS_STATE_AWAKE;
2322 adapter->pm_wakeup_fw_try = false;
2323 del_timer(&adapter->wakeup_timer);
2328 while (pcie_ireg & HOST_INTR_MASK) {
2329 if (pcie_ireg & HOST_INTR_DNLD_DONE) {
2330 pcie_ireg &= ~HOST_INTR_DNLD_DONE;
2331 mwifiex_dbg(adapter, INTR,
2332 "info: TX DNLD Done\n");
2333 ret = mwifiex_pcie_send_data_complete(adapter);
2337 if (pcie_ireg & HOST_INTR_UPLD_RDY) {
2338 pcie_ireg &= ~HOST_INTR_UPLD_RDY;
2339 mwifiex_dbg(adapter, INTR,
2341 ret = mwifiex_pcie_process_recv_data(adapter);
2345 if (pcie_ireg & HOST_INTR_EVENT_RDY) {
2346 pcie_ireg &= ~HOST_INTR_EVENT_RDY;
2347 mwifiex_dbg(adapter, INTR,
2348 "info: Rx EVENT\n");
2349 ret = mwifiex_pcie_process_event_ready(adapter);
2354 if (pcie_ireg & HOST_INTR_CMD_DONE) {
2355 pcie_ireg &= ~HOST_INTR_CMD_DONE;
2356 if (adapter->cmd_sent) {
2357 mwifiex_dbg(adapter, INTR,
2358 "info: CMD sent Interrupt\n");
2359 adapter->cmd_sent = false;
2361 /* Handle command response */
2362 ret = mwifiex_pcie_process_cmd_complete(adapter);
2365 if (adapter->hs_activated)
2369 if (card->msi_enable) {
2370 spin_lock_irqsave(&adapter->int_lock, flags);
2371 adapter->int_status = 0;
2372 spin_unlock_irqrestore(&adapter->int_lock, flags);
2375 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
2376 if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS,
2378 mwifiex_dbg(adapter, ERROR,
2379 "Read register failed\n");
2383 if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
2384 if (mwifiex_write_reg(adapter,
2385 PCIE_HOST_INT_STATUS,
2387 mwifiex_dbg(adapter, ERROR,
2388 "Write register failed\n");
2394 if (!card->msi_enable) {
2395 spin_lock_irqsave(&adapter->int_lock, flags);
2396 pcie_ireg |= adapter->int_status;
2397 adapter->int_status = 0;
2398 spin_unlock_irqrestore(&adapter->int_lock, flags);
2401 mwifiex_dbg(adapter, INTR,
2402 "info: cmd_sent=%d data_sent=%d\n",
2403 adapter->cmd_sent, adapter->data_sent);
2404 if (!card->msi_enable && adapter->ps_state != PS_STATE_SLEEP)
2405 mwifiex_pcie_enable_host_int(adapter);
2410 static int mwifiex_process_msix_int(struct mwifiex_adapter *adapter)
2414 unsigned long flags;
2416 spin_lock_irqsave(&adapter->int_lock, flags);
2417 /* Clear out unused interrupts */
2418 pcie_ireg = adapter->int_status;
2419 adapter->int_status = 0;
2420 spin_unlock_irqrestore(&adapter->int_lock, flags);
2422 if (pcie_ireg & HOST_INTR_DNLD_DONE) {
2423 mwifiex_dbg(adapter, INTR,
2424 "info: TX DNLD Done\n");
2425 ret = mwifiex_pcie_send_data_complete(adapter);
2429 if (pcie_ireg & HOST_INTR_UPLD_RDY) {
2430 mwifiex_dbg(adapter, INTR,
2432 ret = mwifiex_pcie_process_recv_data(adapter);
2436 if (pcie_ireg & HOST_INTR_EVENT_RDY) {
2437 mwifiex_dbg(adapter, INTR,
2438 "info: Rx EVENT\n");
2439 ret = mwifiex_pcie_process_event_ready(adapter);
2444 if (pcie_ireg & HOST_INTR_CMD_DONE) {
2445 if (adapter->cmd_sent) {
2446 mwifiex_dbg(adapter, INTR,
2447 "info: CMD sent Interrupt\n");
2448 adapter->cmd_sent = false;
2450 /* Handle command response */
2451 ret = mwifiex_pcie_process_cmd_complete(adapter);
2456 mwifiex_dbg(adapter, INTR,
2457 "info: cmd_sent=%d data_sent=%d\n",
2458 adapter->cmd_sent, adapter->data_sent);
2463 static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
2465 struct pcie_service_card *card = adapter->card;
2467 if (card->msix_enable)
2468 return mwifiex_process_msix_int(adapter);
2470 return mwifiex_process_pcie_int(adapter);
2474 * This function downloads data from driver to card.
2476 * Both commands and data packets are transferred to the card by this
2479 * This function adds the PCIE specific header to the front of the buffer
2480 * before transferring. The header contains the length of the packet and
2481 * the type. The firmware handles the packets based upon this set type.
2483 static int mwifiex_pcie_host_to_card(struct mwifiex_adapter *adapter, u8 type,
2484 struct sk_buff *skb,
2485 struct mwifiex_tx_param *tx_param)
2488 mwifiex_dbg(adapter, ERROR,
2489 "Passed NULL skb to %s\n", __func__);
2493 if (type == MWIFIEX_TYPE_DATA)
2494 return mwifiex_pcie_send_data(adapter, skb, tx_param);
2495 else if (type == MWIFIEX_TYPE_CMD)
2496 return mwifiex_pcie_send_cmd(adapter, skb);
2501 /* Function to dump PCIE scratch registers in case of FW crash
2504 mwifiex_pcie_reg_dump(struct mwifiex_adapter *adapter, char *drv_buf)
2507 char buf[256], *ptr;
2510 struct pcie_service_card *card = adapter->card;
2511 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
2512 int pcie_scratch_reg[] = {PCIE_SCRATCH_12_REG,
2513 PCIE_SCRATCH_13_REG,
2514 PCIE_SCRATCH_14_REG};
2519 mwifiex_dbg(adapter, MSG, "PCIE register dump start\n");
2521 if (mwifiex_read_reg(adapter, reg->fw_status, &value)) {
2522 mwifiex_dbg(adapter, ERROR, "failed to read firmware status");
2527 mwifiex_dbg(adapter, MSG, "pcie scratch register:");
2528 for (i = 0; i < ARRAY_SIZE(pcie_scratch_reg); i++) {
2529 mwifiex_read_reg(adapter, pcie_scratch_reg[i], &value);
2530 ptr += sprintf(ptr, "reg:0x%x, value=0x%x\n",
2531 pcie_scratch_reg[i], value);
2534 mwifiex_dbg(adapter, MSG, "%s\n", buf);
2535 p += sprintf(p, "%s\n", buf);
2537 mwifiex_dbg(adapter, MSG, "PCIE register dump end\n");
2542 /* This function read/write firmware */
2543 static enum rdwr_status
2544 mwifiex_pcie_rdwr_firmware(struct mwifiex_adapter *adapter, u8 doneflag)
2549 struct pcie_service_card *card = adapter->card;
2550 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
2552 if (mwifiex_read_reg(adapter, reg->fw_status, &fw_status))
2553 return RDWR_STATUS_FAILURE;
2555 ret = mwifiex_write_reg(adapter, reg->fw_dump_ctrl,
2556 reg->fw_dump_host_ready);
2558 mwifiex_dbg(adapter, ERROR,
2559 "PCIE write err\n");
2560 return RDWR_STATUS_FAILURE;
2563 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
2564 mwifiex_read_reg_byte(adapter, reg->fw_dump_ctrl, &ctrl_data);
2565 if (ctrl_data == FW_DUMP_DONE)
2566 return RDWR_STATUS_SUCCESS;
2567 if (doneflag && ctrl_data == doneflag)
2568 return RDWR_STATUS_DONE;
2569 if (ctrl_data != reg->fw_dump_host_ready) {
2570 mwifiex_dbg(adapter, WARN,
2571 "The ctrl reg was changed, re-try again!\n");
2572 ret = mwifiex_write_reg(adapter, reg->fw_dump_ctrl,
2573 reg->fw_dump_host_ready);
2575 mwifiex_dbg(adapter, ERROR,
2576 "PCIE write err\n");
2577 return RDWR_STATUS_FAILURE;
2580 usleep_range(100, 200);
2583 mwifiex_dbg(adapter, ERROR, "Fail to pull ctrl_data\n");
2584 return RDWR_STATUS_FAILURE;
2587 /* This function dump firmware memory to file */
2588 static void mwifiex_pcie_fw_dump(struct mwifiex_adapter *adapter)
2590 struct pcie_service_card *card = adapter->card;
2591 const struct mwifiex_pcie_card_reg *creg = card->pcie.reg;
2592 unsigned int reg, reg_start, reg_end;
2593 u8 *dbg_ptr, *end_ptr, *tmp_ptr, fw_dump_num, dump_num;
2594 u8 idx, i, read_reg, doneflag = 0;
2595 enum rdwr_status stat;
2599 if (!card->pcie.can_dump_fw)
2602 for (idx = 0; idx < adapter->num_mem_types; idx++) {
2603 struct memory_type_mapping *entry =
2604 &adapter->mem_type_mapping_tbl[idx];
2606 if (entry->mem_ptr) {
2607 vfree(entry->mem_ptr);
2608 entry->mem_ptr = NULL;
2610 entry->mem_size = 0;
2613 mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump start ==\n");
2615 /* Read the number of the memories which will dump */
2616 stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
2617 if (stat == RDWR_STATUS_FAILURE)
2620 reg = creg->fw_dump_start;
2621 mwifiex_read_reg_byte(adapter, reg, &fw_dump_num);
2623 /* W8997 chipset firmware dump will be restore in single region*/
2624 if (fw_dump_num == 0)
2627 dump_num = fw_dump_num;
2629 /* Read the length of every memory which will dump */
2630 for (idx = 0; idx < dump_num; idx++) {
2631 struct memory_type_mapping *entry =
2632 &adapter->mem_type_mapping_tbl[idx];
2634 if (fw_dump_num != 0) {
2635 stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
2636 if (stat == RDWR_STATUS_FAILURE)
2639 reg = creg->fw_dump_start;
2640 for (i = 0; i < 4; i++) {
2641 mwifiex_read_reg_byte(adapter, reg, &read_reg);
2642 memory_size |= (read_reg << (i * 8));
2646 memory_size = MWIFIEX_FW_DUMP_MAX_MEMSIZE;
2649 if (memory_size == 0) {
2650 mwifiex_dbg(adapter, MSG, "Firmware dump Finished!\n");
2651 ret = mwifiex_write_reg(adapter, creg->fw_dump_ctrl,
2652 creg->fw_dump_read_done);
2654 mwifiex_dbg(adapter, ERROR, "PCIE write err\n");
2660 mwifiex_dbg(adapter, DUMP,
2661 "%s_SIZE=0x%x\n", entry->mem_name, memory_size);
2662 entry->mem_ptr = vmalloc(memory_size + 1);
2663 entry->mem_size = memory_size;
2664 if (!entry->mem_ptr) {
2665 mwifiex_dbg(adapter, ERROR,
2666 "Vmalloc %s failed\n", entry->mem_name);
2669 dbg_ptr = entry->mem_ptr;
2670 end_ptr = dbg_ptr + memory_size;
2672 doneflag = entry->done_flag;
2673 mwifiex_dbg(adapter, DUMP, "Start %s output, please wait...\n",
2677 stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
2678 if (RDWR_STATUS_FAILURE == stat)
2681 reg_start = creg->fw_dump_start;
2682 reg_end = creg->fw_dump_end;
2683 for (reg = reg_start; reg <= reg_end; reg++) {
2684 mwifiex_read_reg_byte(adapter, reg, dbg_ptr);
2685 if (dbg_ptr < end_ptr) {
2689 mwifiex_dbg(adapter, ERROR,
2690 "pre-allocated buf not enough\n");
2692 vzalloc(memory_size + MWIFIEX_SIZE_4K);
2695 memcpy(tmp_ptr, entry->mem_ptr, memory_size);
2696 vfree(entry->mem_ptr);
2697 entry->mem_ptr = tmp_ptr;
2699 dbg_ptr = entry->mem_ptr + memory_size;
2700 memory_size += MWIFIEX_SIZE_4K;
2701 end_ptr = entry->mem_ptr + memory_size;
2704 if (stat != RDWR_STATUS_DONE)
2707 mwifiex_dbg(adapter, DUMP,
2708 "%s done: size=0x%tx\n",
2709 entry->mem_name, dbg_ptr - entry->mem_ptr);
2713 mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump end ==\n");
2716 static void mwifiex_pcie_device_dump_work(struct mwifiex_adapter *adapter)
2718 mwifiex_drv_info_dump(adapter);
2719 mwifiex_pcie_fw_dump(adapter);
2720 mwifiex_upload_device_dump(adapter);
2723 static unsigned long iface_work_flags;
2724 static struct mwifiex_adapter *save_adapter;
2725 static void mwifiex_pcie_work(struct work_struct *work)
2727 if (test_and_clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
2729 mwifiex_pcie_device_dump_work(save_adapter);
2732 static DECLARE_WORK(pcie_work, mwifiex_pcie_work);
2733 /* This function dumps FW information */
2734 static void mwifiex_pcie_device_dump(struct mwifiex_adapter *adapter)
2736 save_adapter = adapter;
2737 if (test_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &iface_work_flags))
2740 set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &iface_work_flags);
2742 schedule_work(&pcie_work);
2746 * This function initializes the PCI-E host memory space, WCB rings, etc.
2748 * The following initializations steps are followed -
2749 * - Allocate TXBD ring buffers
2750 * - Allocate RXBD ring buffers
2751 * - Allocate event BD ring buffers
2752 * - Allocate command response ring buffer
2753 * - Allocate sleep cookie buffer
2755 static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
2757 struct pcie_service_card *card = adapter->card;
2759 struct pci_dev *pdev = card->dev;
2760 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
2762 pci_set_drvdata(pdev, card);
2764 ret = pci_enable_device(pdev);
2766 goto err_enable_dev;
2768 pci_set_master(pdev);
2770 pr_notice("try set_consistent_dma_mask(32)\n");
2771 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2773 pr_err("set_dma_mask(32) failed\n");
2774 goto err_set_dma_mask;
2777 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2779 pr_err("set_consistent_dma_mask(64) failed\n");
2780 goto err_set_dma_mask;
2783 ret = pci_request_region(pdev, 0, DRV_NAME);
2785 pr_err("req_reg(0) error\n");
2786 goto err_req_region0;
2788 card->pci_mmap = pci_iomap(pdev, 0, 0);
2789 if (!card->pci_mmap) {
2790 pr_err("iomap(0) error\n");
2794 ret = pci_request_region(pdev, 2, DRV_NAME);
2796 pr_err("req_reg(2) error\n");
2797 goto err_req_region2;
2799 card->pci_mmap1 = pci_iomap(pdev, 2, 0);
2800 if (!card->pci_mmap1) {
2801 pr_err("iomap(2) error\n");
2806 pr_notice("PCI memory map Virt0: %p PCI memory map Virt2: %p\n",
2807 card->pci_mmap, card->pci_mmap1);
2809 card->cmdrsp_buf = NULL;
2810 ret = mwifiex_pcie_create_txbd_ring(adapter);
2813 ret = mwifiex_pcie_create_rxbd_ring(adapter);
2816 ret = mwifiex_pcie_create_evtbd_ring(adapter);
2819 ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter);
2821 goto err_alloc_cmdbuf;
2822 if (reg->sleep_cookie) {
2823 ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter);
2825 goto err_alloc_cookie;
2827 card->sleep_cookie_vbase = NULL;
2832 mwifiex_pcie_delete_cmdrsp_buf(adapter);
2834 mwifiex_pcie_delete_evtbd_ring(adapter);
2836 mwifiex_pcie_delete_rxbd_ring(adapter);
2838 mwifiex_pcie_delete_txbd_ring(adapter);
2840 pci_iounmap(pdev, card->pci_mmap1);
2842 pci_release_region(pdev, 2);
2844 pci_iounmap(pdev, card->pci_mmap);
2846 pci_release_region(pdev, 0);
2849 pci_disable_device(pdev);
2855 * This function cleans up the allocated card buffers.
2857 * The following are freed by this function -
2858 * - TXBD ring buffers
2859 * - RXBD ring buffers
2860 * - Event BD ring buffers
2861 * - Command response ring buffer
2862 * - Sleep cookie buffer
2864 static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter)
2866 struct pcie_service_card *card = adapter->card;
2867 struct pci_dev *pdev = card->dev;
2868 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
2871 mwifiex_dbg(adapter, INFO,
2872 "Clearing driver ready signature\n");
2873 if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000))
2874 mwifiex_dbg(adapter, ERROR,
2875 "Failed to write driver not-ready signature\n");
2879 pci_iounmap(pdev, card->pci_mmap);
2880 pci_iounmap(pdev, card->pci_mmap1);
2881 pci_disable_device(pdev);
2882 pci_release_region(pdev, 2);
2883 pci_release_region(pdev, 0);
2887 static int mwifiex_pcie_request_irq(struct mwifiex_adapter *adapter)
2890 struct pcie_service_card *card = adapter->card;
2891 struct pci_dev *pdev = card->dev;
2893 if (card->pcie.reg->msix_support) {
2894 for (i = 0; i < MWIFIEX_NUM_MSIX_VECTORS; i++)
2895 card->msix_entries[i].entry = i;
2896 ret = pci_enable_msix_exact(pdev, card->msix_entries,
2897 MWIFIEX_NUM_MSIX_VECTORS);
2899 for (i = 0; i < MWIFIEX_NUM_MSIX_VECTORS; i++) {
2900 card->msix_ctx[i].dev = pdev;
2901 card->msix_ctx[i].msg_id = i;
2903 ret = request_irq(card->msix_entries[i].vector,
2904 mwifiex_pcie_interrupt, 0,
2905 "MWIFIEX_PCIE_MSIX",
2906 &card->msix_ctx[i]);
2912 mwifiex_dbg(adapter, INFO, "request_irq fail: %d\n",
2914 for (j = 0; j < i; j++)
2915 free_irq(card->msix_entries[j].vector,
2916 &card->msix_ctx[i]);
2917 pci_disable_msix(pdev);
2919 mwifiex_dbg(adapter, MSG, "MSIx enabled!");
2920 card->msix_enable = 1;
2926 if (pci_enable_msi(pdev) != 0)
2927 pci_disable_msi(pdev);
2929 card->msi_enable = 1;
2931 mwifiex_dbg(adapter, INFO, "msi_enable = %d\n", card->msi_enable);
2933 card->share_irq_ctx.dev = pdev;
2934 card->share_irq_ctx.msg_id = -1;
2935 ret = request_irq(pdev->irq, mwifiex_pcie_interrupt, IRQF_SHARED,
2936 "MRVL_PCIE", &card->share_irq_ctx);
2938 pr_err("request_irq failed: ret=%d\n", ret);
2946 * This function gets the firmware name for downloading by revision id
2948 * Read revision id register to get revision id
2950 static void mwifiex_pcie_get_fw_name(struct mwifiex_adapter *adapter)
2952 int revision_id = 0;
2954 struct pcie_service_card *card = adapter->card;
2956 switch (card->dev->device) {
2957 case PCIE_DEVICE_ID_MARVELL_88W8766P:
2958 strcpy(adapter->fw_name, PCIE8766_DEFAULT_FW_NAME);
2960 case PCIE_DEVICE_ID_MARVELL_88W8897:
2961 mwifiex_write_reg(adapter, 0x0c58, 0x80c00000);
2962 mwifiex_read_reg(adapter, 0x0c58, &revision_id);
2963 revision_id &= 0xff00;
2964 switch (revision_id) {
2966 strcpy(adapter->fw_name, PCIE8897_A0_FW_NAME);
2969 strcpy(adapter->fw_name, PCIE8897_B0_FW_NAME);
2972 strcpy(adapter->fw_name, PCIE8897_DEFAULT_FW_NAME);
2977 case PCIE_DEVICE_ID_MARVELL_88W8997:
2978 mwifiex_read_reg(adapter, 0x8, &revision_id);
2979 mwifiex_read_reg(adapter, 0x0cd0, &version);
2980 mwifiex_read_reg(adapter, 0x0cd4, &magic);
2981 revision_id &= 0xff;
2984 if (revision_id == PCIE8997_A1 &&
2985 magic == CHIP_MAGIC_VALUE &&
2986 version == CHIP_VER_PCIEUART)
2987 strcpy(adapter->fw_name, PCIEUART8997_FW_NAME_V4);
2989 strcpy(adapter->fw_name, PCIEUSB8997_FW_NAME_V4);
2997 * This function registers the PCIE device.
2999 * PCIE IRQ is claimed, block size is set and driver data is initialized.
3001 static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
3003 struct pcie_service_card *card = adapter->card;
3005 /* save adapter pointer in card */
3006 card->adapter = adapter;
3008 if (mwifiex_pcie_request_irq(adapter))
3011 adapter->tx_buf_size = card->pcie.tx_buf_size;
3012 adapter->mem_type_mapping_tbl = card->pcie.mem_type_mapping_tbl;
3013 adapter->num_mem_types = card->pcie.num_mem_types;
3014 adapter->ext_scan = card->pcie.can_ext_scan;
3015 mwifiex_pcie_get_fw_name(adapter);
3021 * This function unregisters the PCIE device.
3023 * The PCIE IRQ is released, the function is disabled and driver
3024 * data is set to null.
3026 static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
3028 struct pcie_service_card *card = adapter->card;
3029 struct pci_dev *pdev = card->dev;
3032 if (card->msix_enable) {
3033 for (i = 0; i < MWIFIEX_NUM_MSIX_VECTORS; i++)
3034 synchronize_irq(card->msix_entries[i].vector);
3036 for (i = 0; i < MWIFIEX_NUM_MSIX_VECTORS; i++)
3037 free_irq(card->msix_entries[i].vector,
3038 &card->msix_ctx[i]);
3040 card->msix_enable = 0;
3041 pci_disable_msix(pdev);
3043 mwifiex_dbg(adapter, INFO,
3044 "%s(): calling free_irq()\n", __func__);
3045 free_irq(card->dev->irq, &card->share_irq_ctx);
3047 if (card->msi_enable)
3048 pci_disable_msi(pdev);
3050 card->adapter = NULL;
3053 /* This function initializes the PCI-E host memory space, WCB rings, etc.
3055 * The following initializations steps are followed -
3056 * - Allocate TXBD ring buffers
3057 * - Allocate RXBD ring buffers
3058 * - Allocate event BD ring buffers
3059 * - Allocate command response ring buffer
3060 * - Allocate sleep cookie buffer
3061 * Part of mwifiex_pcie_init(), not reset the PCIE registers
3063 static void mwifiex_pcie_up_dev(struct mwifiex_adapter *adapter)
3065 struct pcie_service_card *card = adapter->card;
3067 struct pci_dev *pdev = card->dev;
3068 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
3070 card->cmdrsp_buf = NULL;
3071 ret = mwifiex_pcie_create_txbd_ring(adapter);
3073 mwifiex_dbg(adapter, ERROR, "Failed to create txbd ring\n");
3077 ret = mwifiex_pcie_create_rxbd_ring(adapter);
3079 mwifiex_dbg(adapter, ERROR, "Failed to create rxbd ring\n");
3083 ret = mwifiex_pcie_create_evtbd_ring(adapter);
3085 mwifiex_dbg(adapter, ERROR, "Failed to create evtbd ring\n");
3089 ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter);
3091 mwifiex_dbg(adapter, ERROR, "Failed to allocate cmdbuf buffer\n");
3092 goto err_alloc_cmdbuf;
3095 if (reg->sleep_cookie) {
3096 ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter);
3098 mwifiex_dbg(adapter, ERROR, "Failed to allocate sleep_cookie buffer\n");
3099 goto err_alloc_cookie;
3102 card->sleep_cookie_vbase = NULL;
3107 mwifiex_pcie_delete_cmdrsp_buf(adapter);
3109 mwifiex_pcie_delete_evtbd_ring(adapter);
3111 mwifiex_pcie_delete_rxbd_ring(adapter);
3113 mwifiex_pcie_delete_txbd_ring(adapter);
3115 pci_iounmap(pdev, card->pci_mmap1);
3118 /* This function cleans up the PCI-E host memory space.
3119 * Some code is extracted from mwifiex_unregister_dev()
3122 static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter)
3124 struct pcie_service_card *card = adapter->card;
3125 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
3127 if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000))
3128 mwifiex_dbg(adapter, ERROR, "Failed to write driver not-ready signature\n");
3130 adapter->seq_num = 0;
3131 adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
3133 if (reg->sleep_cookie)
3134 mwifiex_pcie_delete_sleep_cookie_buf(adapter);
3136 mwifiex_pcie_delete_cmdrsp_buf(adapter);
3137 mwifiex_pcie_delete_evtbd_ring(adapter);
3138 mwifiex_pcie_delete_rxbd_ring(adapter);
3139 mwifiex_pcie_delete_txbd_ring(adapter);
3140 card->cmdrsp_buf = NULL;
3143 static struct mwifiex_if_ops pcie_ops = {
3144 .init_if = mwifiex_pcie_init,
3145 .cleanup_if = mwifiex_pcie_cleanup,
3146 .check_fw_status = mwifiex_check_fw_status,
3147 .check_winner_status = mwifiex_check_winner_status,
3148 .prog_fw = mwifiex_prog_fw_w_helper,
3149 .register_dev = mwifiex_register_dev,
3150 .unregister_dev = mwifiex_unregister_dev,
3151 .enable_int = mwifiex_pcie_enable_host_int,
3152 .disable_int = mwifiex_pcie_disable_host_int_noerr,
3153 .process_int_status = mwifiex_process_int_status,
3154 .host_to_card = mwifiex_pcie_host_to_card,
3155 .wakeup = mwifiex_pm_wakeup_card,
3156 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
3159 .cmdrsp_complete = mwifiex_pcie_cmdrsp_complete,
3160 .event_complete = mwifiex_pcie_event_complete,
3161 .update_mp_end_port = NULL,
3162 .cleanup_mpa_buf = NULL,
3163 .init_fw_port = mwifiex_pcie_init_fw_port,
3164 .clean_pcie_ring = mwifiex_clean_pcie_ring_buf,
3165 .reg_dump = mwifiex_pcie_reg_dump,
3166 .device_dump = mwifiex_pcie_device_dump,
3167 .down_dev = mwifiex_pcie_down_dev,
3168 .up_dev = mwifiex_pcie_up_dev,
3172 * This function initializes the PCIE driver module.
3174 * This registers the device with PCIE bus.
3176 static int mwifiex_pcie_init_module(void)
3180 pr_debug("Marvell PCIe Driver\n");
3182 /* Clear the flag in case user removes the card. */
3185 ret = pci_register_driver(&mwifiex_pcie);
3187 pr_err("Driver register failed!\n");
3189 pr_debug("info: Driver registered successfully!\n");
3195 * This function cleans up the PCIE driver.
3197 * The following major steps are followed for cleanup -
3198 * - Resume the device if its suspended
3199 * - Disconnect the device if connected
3200 * - Shutdown the firmware
3201 * - Unregister the device from PCIE bus.
3203 static void mwifiex_pcie_cleanup_module(void)
3205 /* Set the flag as user is removing this module. */
3208 cancel_work_sync(&pcie_work);
3209 pci_unregister_driver(&mwifiex_pcie);
3212 module_init(mwifiex_pcie_init_module);
3213 module_exit(mwifiex_pcie_cleanup_module);
3215 MODULE_AUTHOR("Marvell International Ltd.");
3216 MODULE_DESCRIPTION("Marvell WiFi-Ex PCI-Express Driver version " PCIE_VERSION);
3217 MODULE_VERSION(PCIE_VERSION);
3218 MODULE_LICENSE("GPL v2");