31 #define PCIE_VERSION "1.0"
32 #define DRV_NAME "Marvell mwifiex PCIe"
38 static struct semaphore add_remove_card_sem;
40 static int mwifiex_pcie_resume(
struct pci_dev *pdev);
65 dev_dbg(adapter->
dev,
"info: ACCESS_HW: sleep cookie=0x%x\n",
80 static int mwifiex_pcie_probe(
struct pci_dev *pdev,
85 pr_debug(
"info: vendor=0x%4.04X device=0x%4.04X rev=%d\n",
96 pr_err(
"%s failed\n", __func__);
107 static void mwifiex_pcie_remove(
struct pci_dev *pdev)
114 card = pci_get_drvdata(pdev);
128 mwifiex_pcie_resume(pdev);
131 for (i = 0; i < adapter->
priv_num; i++)
134 adapter->
priv[i]->media_connected)
165 pr_err(
"Card or adapter structure is not valid\n");
169 pr_err(
"PCIE device is not specified\n");
180 for (i = 0; i < adapter->
priv_num; i++)
194 static int mwifiex_pcie_resume(
struct pci_dev *pdev)
203 pr_err(
"Card or adapter structure is not valid\n");
207 pr_err(
"PCIE device is not specified\n");
214 dev_warn(adapter->
dev,
"Device already resumed\n");
220 for (i = 0; i < adapter->
priv_num; i++)
221 if (adapter->
priv[i]->media_connected)
230 #define PCIE_VENDOR_ID_MARVELL (0x11ab)
231 #define PCIE_DEVICE_ID_MARVELL_88W8766P (0x2b30)
245 .name =
"mwifiex_pcie",
246 .id_table = mwifiex_ids,
247 .probe = mwifiex_pcie_probe,
248 .remove = mwifiex_pcie_remove,
251 .suspend = mwifiex_pcie_suspend,
252 .resume = mwifiex_pcie_resume,
290 while (mwifiex_pcie_ok_to_access_hw(adapter)) {
298 dev_dbg(adapter->
dev,
"event: Wakeup device...\n");
302 dev_warn(adapter->
dev,
"Enable host interrupt failed\n");
306 dev_dbg(adapter->
dev,
"PCIE wakeup: Setting PS_STATE_AWAKE\n");
317 static int mwifiex_pm_wakeup_card_complete(
struct mwifiex_adapter *adapter)
319 dev_dbg(adapter->
dev,
"cmd: Wakeup device completed\n");
330 static int mwifiex_pcie_disable_host_int(
struct mwifiex_adapter *adapter)
332 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
335 dev_warn(adapter->
dev,
"Disable host interrupt failed\n");
349 static int mwifiex_pcie_enable_host_int(
struct mwifiex_adapter *adapter)
351 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
355 dev_warn(adapter->
dev,
"Enable host interrupt failed\n");
366 static int mwifiex_pcie_create_txbd_ring(
struct mwifiex_adapter *adapter)
385 dev_dbg(adapter->
dev,
"info: txbd_ring: Allocating %d bytes\n",
389 dev_err(adapter->
dev,
"Unable to alloc buffer for txbd ring\n");
395 "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n",
408 dev_err(adapter->
dev,
"Unable to allocate skb for TX ring.\n");
412 buf_pa = mwifiex_update_sk_buff_pa(skb);
415 dev_dbg(adapter->
dev,
"info: TX ring: add new skb base: %p, "
416 "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n",
429 static int mwifiex_pcie_delete_txbd_ring(
struct mwifiex_adapter *adapter)
456 static int mwifiex_pcie_create_rxbd_ring(
struct mwifiex_adapter *adapter)
473 dev_dbg(adapter->
dev,
"info: rxbd_ring: Allocating %d bytes\n",
477 dev_err(adapter->
dev,
"Unable to allocate buffer for "
484 "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n",
499 "Unable to allocate skb for RX ring.\n");
503 buf_pa = mwifiex_update_sk_buff_pa(skb);
506 dev_dbg(adapter->
dev,
"info: RX ring: add new skb base: %p, "
507 "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n",
523 static int mwifiex_pcie_delete_rxbd_ring(
struct mwifiex_adapter *adapter)
550 static int mwifiex_pcie_create_evtbd_ring(
struct mwifiex_adapter *adapter)
567 dev_dbg(adapter->
dev,
"info: evtbd_ring: Allocating %d bytes\n",
572 "Unable to allocate buffer. Terminating download\n");
578 "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n",
593 "Unable to allocate skb for EVENT buf.\n");
597 buf_pa = mwifiex_update_sk_buff_pa(skb);
600 dev_dbg(adapter->
dev,
"info: Evt ring: add new skb. base: %p, "
601 "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n",
617 static int mwifiex_pcie_delete_evtbd_ring(
struct mwifiex_adapter *adapter)
644 static int mwifiex_pcie_alloc_cmdrsp_buf(
struct mwifiex_adapter *adapter)
653 "Unable to allocate skb for command response data.\n");
656 mwifiex_update_sk_buff_pa(skb);
665 "Unable to allocate skb for command data.\n");
668 mwifiex_update_sk_buff_pa(skb);
678 static int mwifiex_pcie_delete_cmdrsp_buf(
struct mwifiex_adapter *adapter)
685 card = adapter->
card;
699 static int mwifiex_pcie_alloc_sleep_cookie_buf(
struct mwifiex_adapter *adapter)
705 skb = dev_alloc_skb(
sizeof(
u32));
708 "Unable to allocate skb for sleep cookie!\n");
711 mwifiex_update_sk_buff_pa(skb);
717 dev_dbg(adapter->
dev,
"alloc_scook: sleep cookie=0x%x\n",
729 static int mwifiex_pcie_delete_sleep_cookie_buf(
struct mwifiex_adapter *adapter)
736 card = adapter->
card;
757 if (!mwifiex_pcie_ok_to_access_hw(adapter))
758 mwifiex_pm_wakeup_card(adapter);
763 "SEND DATA: failed to read REG_TXBD_RDPTR\n");
769 dev_dbg(adapter->
dev,
"info: SEND DATA: <Rd: %#x, Wr: %#x>\n", rdptr,
781 payload = skb_data->
data;
782 tmp = (
__le16 *)&payload[0];
784 tmp = (
__le16 *)&payload[2];
788 buf_pa = MWIFIEX_SKB_PACB(skb_data);
789 card->
txbd_ring[wrindx]->paddr = *buf_pa;
797 MWIFIEX_BD_FLAG_ROLLOVER_IND) ^
804 "SEND DATA: failed to write REG_TXBD_WRPTR\n");
812 "SEND DATA: failed to assert door-bell intr\n");
815 dev_dbg(adapter->
dev,
"info: SEND DATA: Updated <Rd: %#x, Wr: "
816 "%#x> and sent packet to firmware successfully\n",
820 "info: TX Ring full, can't send packets to fw\n");
826 "SEND DATA: failed to assert door-bell intr\n");
837 static int mwifiex_pcie_process_recv_data(
struct mwifiex_adapter *adapter)
847 "RECV DATA: failed to read REG_TXBD_RDPTR\n");
854 ((wrptr & MWIFIEX_BD_FLAG_ROLLOVER_IND) ==
855 (card->
rxbd_rdptr & MWIFIEX_BD_FLAG_ROLLOVER_IND))) {
864 rx_len = *((
u16 *)skb_data->
data);
866 "info: RECV DATA: Rd=%#x, Wr=%#x, Len=%d\n",
868 skb_tmp = dev_alloc_skb(rx_len);
871 "info: Failed to alloc skb for RX\n");
879 if ((++card->
rxbd_rdptr & MWIFIEX_RXBD_MASK) ==
880 MWIFIEX_MAX_TXRX_BD) {
883 MWIFIEX_BD_FLAG_ROLLOVER_IND);
885 dev_dbg(adapter->
dev,
"info: RECV DATA: <Rd: %#x, Wr: %#x>\n",
892 "RECV DATA: failed to write REG_RXBD_RDPTR\n");
900 "RECV DATA: failed to read REG_TXBD_RDPTR\n");
905 "info: RECV DATA: Rcvd packet from fw successfully\n");
923 if (!(skb->
data && skb->
len && *buf_pa)) {
925 "Invalid parameter in %s <%p, %#x:%x, %x>\n",
927 (
u32)*buf_pa, (
u32)((
u64)*buf_pa >> 32));
935 "%s: failed to write download command to boot code.\n",
943 (
u32)((
u64)*buf_pa >> 32))) {
945 "%s: failed to write download command to boot code.\n",
953 "%s: failed to write command len to scratch reg 2\n",
962 "%s: failed to assert door-bell intr\n", __func__);
980 if (!(skb->
data && skb->
len)) {
981 dev_err(adapter->
dev,
"Invalid parameter in %s <%p, %#x>\n",
982 __func__, skb->
data, skb->
len);
989 "No response buffer available, send command failed\n");
995 dev_err(adapter->
dev,
"Command buffer not available\n");
1016 cmdrsp_buf_pa = MWIFIEX_SKB_PACB(card->
cmdrsp_buf);
1020 (
u32)*cmdrsp_buf_pa)) {
1022 "Failed to write download cmd to boot code.\n");
1029 (
u32)((
u64)*cmdrsp_buf_pa >> 32))) {
1031 "Failed to write download cmd to boot code.\n");
1037 cmd_buf_pa = MWIFIEX_SKB_PACB(card->
cmd_buf);
1041 "Failed to write download cmd to boot code.\n");
1047 (
u32)((
u64)*cmd_buf_pa >> 32))) {
1049 "Failed to write download cmd to boot code.\n");
1057 "Failed to write cmd len to REG_CMD_SIZE\n");
1066 "Failed to assert door-bell intr\n");
1081 static int mwifiex_pcie_process_cmd_complete(
struct mwifiex_adapter *adapter)
1087 dev_dbg(adapter->
dev,
"info: Rx CMD Response\n");
1094 while (mwifiex_pcie_ok_to_access_hw(adapter) &&
1099 "There is no command but got cmdrsp\n");
1104 }
else if (mwifiex_pcie_ok_to_access_hw(adapter)) {
1117 "cmd_done: failed to clear cmd_rsp_addr_lo\n");
1124 "cmd_done: failed to clear cmd_rsp_addr_hi\n");
1135 static int mwifiex_pcie_cmdrsp_complete(
struct mwifiex_adapter *adapter,
1151 static int mwifiex_pcie_process_event_ready(
struct mwifiex_adapter *adapter)
1158 dev_dbg(adapter->
dev,
"info: Event being processed, "
1159 "do not process this interrupt just yet\n");
1163 if (rdptr >= MWIFIEX_MAX_EVT_BD) {
1164 dev_dbg(adapter->
dev,
"info: Invalid read pointer...\n");
1171 "EventReady: failed to read REG_EVTBD_WRPTR\n");
1175 dev_dbg(adapter->
dev,
"info: EventReady: Initial <Rd: 0x%x, Wr: 0x%x>",
1178 & MWIFIEX_EVTBD_MASK)) ||
1179 ((wrptr & MWIFIEX_BD_FLAG_ROLLOVER_IND) ==
1180 (card->
evtbd_rdptr & MWIFIEX_BD_FLAG_ROLLOVER_IND))) {
1185 dev_dbg(adapter->
dev,
"info: Read Index: %d\n", rdptr);
1202 dev_dbg(adapter->
dev,
"info: Event length: %d\n", evt_len);
1224 static int mwifiex_pcie_event_complete(
struct mwifiex_adapter *adapter,
1236 if (rdptr >= MWIFIEX_MAX_EVT_BD) {
1237 dev_err(adapter->
dev,
"event_complete: Invalid rdptr 0x%x\n",
1245 "event_complete: failed to read REG_EVTBD_WRPTR\n");
1252 buf_pa = MWIFIEX_SKB_PACB(skb);
1259 "info: ERROR: buf still valid at index %d, <%p, %p>\n",
1263 if ((++card->
evtbd_rdptr & MWIFIEX_EVTBD_MASK) == MWIFIEX_MAX_EVT_BD) {
1266 MWIFIEX_BD_FLAG_ROLLOVER_IND);
1269 dev_dbg(adapter->
dev,
"info: Updated <Rd: 0x%x, Wr: 0x%x>",
1275 "event_complete: failed to read REG_EVTBD_RDPTR\n");
1279 dev_dbg(adapter->
dev,
"info: Check Events Again\n");
1280 ret = mwifiex_pcie_process_event_ready(adapter);
1301 u32 block_retry_cnt = 0;
1304 pr_err(
"adapter structure is not valid\n");
1308 if (!firmware || !firmware_len) {
1310 "No firmware image found! Terminating download\n");
1314 dev_dbg(adapter->
dev,
"info: Downloading FW image (%d bytes)\n",
1317 if (mwifiex_pcie_disable_host_int(adapter)) {
1319 "%s: Disabling interrupts failed.\n", __func__);
1328 mwifiex_update_sk_buff_pa(skb);
1335 if (offset >= firmware_len)
1343 "Failed reading len from boot code\n");
1354 pr_err(
"FW download failure @ %d, invalid length %d\n",
1365 pr_err(
"FW download failure @ %d, over max "
1366 "retry count\n", offset);
1370 dev_err(adapter->
dev,
"FW CRC error indicated by the "
1371 "helper: len = 0x%04X, txlen = %d\n",
1377 block_retry_cnt = 0;
1380 if (firmware_len - offset < txlen)
1381 txlen = firmware_len -
offset;
1385 tx_blocks = (txlen +
1397 if (mwifiex_pcie_send_boot_cmd(adapter, skb)) {
1399 "Failed to send firmware download command\n");
1408 "interrupt status during fw dnld.\n",
1414 CPU_INTR_DOOR_BELL);
1418 dev_dbg(adapter->
dev,
"info:\nFW download over, size %d bytes\n",
1437 u32 firmware_stat, winner_status;
1443 dev_warn(adapter->
dev,
"Write register failed\n");
1447 dev_dbg(adapter->
dev,
"Setting driver ready signature\n");
1450 "Failed to write driver ready signature\n");
1455 for (tries = 0; tries < poll_num; tries++) {
1476 else if (!winner_status) {
1477 dev_err(adapter->
dev,
"PCI-E is the winner\n");
1482 "PCI-E is not the winner <%#x,%d>, exit dnld\n",
1497 unsigned long flags;
1499 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1507 if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
1509 mwifiex_pcie_disable_host_int(adapter);
1514 dev_warn(adapter->
dev,
"Write register failed\n");
1519 spin_unlock_irqrestore(&adapter->
int_lock, flags);
1524 mwifiex_pcie_enable_host_int(adapter);
1525 if (mwifiex_write_reg(adapter,
1530 "Write register failed\n");
1540 if (mwifiex_pcie_ok_to_access_hw(adapter))
1559 pr_debug(
"info: %s: pdev is NULL\n", (
u8 *)pdev);
1564 if (!card || !card->
adapter) {
1565 pr_debug(
"info: %s: card=%p adapter=%p\n", __func__, card,
1574 mwifiex_interrupt_status(adapter);
1594 static int mwifiex_process_int_status(
struct mwifiex_adapter *adapter)
1598 unsigned long flags;
1603 spin_unlock_irqrestore(&adapter->
int_lock, flags);
1609 dev_dbg(adapter->
dev,
"info: DATA sent intr\n");
1616 ret = mwifiex_pcie_process_recv_data(adapter);
1623 ret = mwifiex_pcie_process_event_ready(adapter);
1628 if (adapter->
int_status & HOST_INTR_CMD_DONE) {
1632 "info: CMD sent Interrupt\n");
1636 ret = mwifiex_pcie_process_cmd_complete(adapter);
1641 if (mwifiex_pcie_ok_to_access_hw(adapter)) {
1645 "Read register failed\n");
1649 if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
1650 if (mwifiex_write_reg(adapter,
1654 "Write register failed\n");
1663 dev_dbg(adapter->
dev,
"info: cmd_sent=%d data_sent=%d\n",
1665 mwifiex_pcie_enable_host_int(adapter);
1685 dev_err(adapter->
dev,
"Passed NULL skb to %s\n", __func__);
1690 return mwifiex_pcie_send_data(adapter, skb);
1692 return mwifiex_pcie_send_cmd(adapter, skb);
1713 pci_set_drvdata(pdev, card);
1717 goto err_enable_dev;
1721 dev_dbg(adapter->
dev,
"try set_consistent_dma_mask(32)\n");
1724 dev_err(adapter->
dev,
"set_dma_mask(32) failed\n");
1725 goto err_set_dma_mask;
1728 ret = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
1730 dev_err(adapter->
dev,
"set_consistent_dma_mask(64) failed\n");
1731 goto err_set_dma_mask;
1737 goto err_req_region0;
1739 card->
pci_mmap = pci_iomap(pdev, 0, 0);
1747 goto err_req_region2;
1749 card->
pci_mmap1 = pci_iomap(pdev, 2, 0);
1756 "PCI memory map Virt0: %p PCI memory map Virt2: %p\n",
1760 ret = mwifiex_pcie_create_txbd_ring(adapter);
1763 ret = mwifiex_pcie_create_rxbd_ring(adapter);
1766 ret = mwifiex_pcie_create_evtbd_ring(adapter);
1769 ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter);
1771 goto err_alloc_cmdbuf;
1772 ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter);
1774 goto err_alloc_cookie;
1779 mwifiex_pcie_delete_cmdrsp_buf(adapter);
1781 mwifiex_pcie_delete_evtbd_ring(adapter);
1783 mwifiex_pcie_delete_rxbd_ring(adapter);
1785 mwifiex_pcie_delete_txbd_ring(adapter);
1798 pci_set_drvdata(pdev,
NULL);
1817 mwifiex_pcie_delete_sleep_cookie_buf(adapter);
1818 mwifiex_pcie_delete_cmdrsp_buf(adapter);
1819 mwifiex_pcie_delete_evtbd_ring(adapter);
1820 mwifiex_pcie_delete_rxbd_ring(adapter);
1821 mwifiex_pcie_delete_txbd_ring(adapter);
1824 dev_dbg(adapter->
dev,
"Clearing driver ready signature\n");
1828 "Failed to write driver not-ready signature\n");
1837 pci_set_drvdata(pdev,
NULL);
1858 pr_err(
"request_irq failed: ret=%d\n", ret);
1863 adapter->
dev = &pdev->
dev;
1880 dev_dbg(adapter->
dev,
"%s(): calling free_irq()\n", __func__);
1886 .init_if = mwifiex_pcie_init,
1887 .cleanup_if = mwifiex_pcie_cleanup,
1888 .check_fw_status = mwifiex_check_fw_status,
1889 .prog_fw = mwifiex_prog_fw_w_helper,
1890 .register_dev = mwifiex_register_dev,
1891 .unregister_dev = mwifiex_unregister_dev,
1892 .enable_int = mwifiex_pcie_enable_host_int,
1893 .process_int_status = mwifiex_process_int_status,
1894 .host_to_card = mwifiex_pcie_host_to_card,
1895 .wakeup = mwifiex_pm_wakeup_card,
1896 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
1899 .cmdrsp_complete = mwifiex_pcie_cmdrsp_complete,
1900 .event_complete = mwifiex_pcie_event_complete,
1901 .update_mp_end_port =
NULL,
1902 .cleanup_mpa_buf =
NULL,
1911 static int mwifiex_pcie_init_module(
void)
1915 pr_debug(
"Marvell 8766 PCIe Driver\n");
1917 sema_init(&add_remove_card_sem, 1);
1922 ret = pci_register_driver(&mwifiex_pcie);
1924 pr_err(
"Driver register failed!\n");
1926 pr_debug(
"info: Driver registered successfully!\n");
1940 static void mwifiex_pcie_cleanup_module(
void)
1943 up(&add_remove_card_sem);