diff options
author | Avinash Patil <patila@marvell.com> | 2013-01-04 00:21:30 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2013-01-07 15:18:30 -0500 |
commit | fc3314609047daf472b3ffc49f9a1c5608068713 (patch) | |
tree | 8e5c9a01fb61337e7f7a996ff78d31f749d47112 /drivers | |
parent | c6d1d87a10d1e5317701676c39bbec20e4651b91 (diff) |
mwifiex: use pci_alloc/free_consistent APIs for PCIe
This patch uses pci_alloc_consistent and pci_free_consistent
APIs for mwifiex_pcie driver. Consistent DMA memory is allocated
for TX, RX and event rings. Command buffer and command response
buffer also uses map/unmap memory APIs to download commands and
get command responses.
Signed-off-by: Avinash Patil <patila@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/wireless/mwifiex/pcie.c | 362 | ||||
-rw-r--r-- | drivers/net/wireless/mwifiex/pcie.h | 9 | ||||
-rw-r--r-- | drivers/net/wireless/mwifiex/sta_cmd.c | 10 | ||||
-rw-r--r-- | drivers/net/wireless/mwifiex/util.h | 8 |
4 files changed, 235 insertions, 154 deletions
diff --git a/drivers/net/wireless/mwifiex/pcie.c b/drivers/net/wireless/mwifiex/pcie.c index 191c6825a6b6..ac20bc4bc1a0 100644 --- a/drivers/net/wireless/mwifiex/pcie.c +++ b/drivers/net/wireless/mwifiex/pcie.c | |||
@@ -39,17 +39,20 @@ static struct semaphore add_remove_card_sem; | |||
39 | static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter); | 39 | static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter); |
40 | static int mwifiex_pcie_resume(struct pci_dev *pdev); | 40 | static int mwifiex_pcie_resume(struct pci_dev *pdev); |
41 | 41 | ||
42 | /* | 42 | static int |
43 | * This function is called after skb allocation to update | 43 | mwifiex_map_pci_memory(struct mwifiex_adapter *adapter, struct sk_buff *skb, |
44 | * "skb->cb" with physical address of data pointer. | 44 | int size, int flags) |
45 | */ | ||
46 | static phys_addr_t *mwifiex_update_sk_buff_pa(struct sk_buff *skb) | ||
47 | { | 45 | { |
48 | phys_addr_t *buf_pa = MWIFIEX_SKB_PACB(skb); | 46 | struct pcie_service_card *card = adapter->card; |
49 | 47 | dma_addr_t buf_pa; | |
50 | *buf_pa = (phys_addr_t)virt_to_phys(skb->data); | ||
51 | 48 | ||
52 | return buf_pa; | 49 | buf_pa = pci_map_single(card->dev, skb->data, size, flags); |
50 | if (pci_dma_mapping_error(card->dev, buf_pa)) { | ||
51 | dev_err(adapter->dev, "failed to map pci memory!\n"); | ||
52 | return -1; | ||
53 | } | ||
54 | memcpy(skb->cb, &buf_pa, sizeof(dma_addr_t)); | ||
55 | return 0; | ||
53 | } | 56 | } |
54 | 57 | ||
55 | /* | 58 | /* |
@@ -60,8 +63,8 @@ static bool mwifiex_pcie_ok_to_access_hw(struct mwifiex_adapter *adapter) | |||
60 | u32 *cookie_addr; | 63 | u32 *cookie_addr; |
61 | struct pcie_service_card *card = adapter->card; | 64 | struct pcie_service_card *card = adapter->card; |
62 | 65 | ||
63 | if (card->sleep_cookie) { | 66 | if (card->sleep_cookie_vbase) { |
64 | cookie_addr = (u32 *)card->sleep_cookie->data; | 67 | cookie_addr = (u32 *)card->sleep_cookie_vbase; |
65 | dev_dbg(adapter->dev, "info: ACCESS_HW: sleep cookie=0x%x\n", | 68 | dev_dbg(adapter->dev, "info: ACCESS_HW: sleep cookie=0x%x\n", |
66 | *cookie_addr); | 69 | *cookie_addr); |
67 | if (*cookie_addr == FW_AWAKE_COOKIE) | 70 | if (*cookie_addr == FW_AWAKE_COOKIE) |
@@ -366,9 +369,7 @@ static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter) | |||
366 | static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter) | 369 | static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter) |
367 | { | 370 | { |
368 | struct pcie_service_card *card = adapter->card; | 371 | struct pcie_service_card *card = adapter->card; |
369 | struct sk_buff *skb; | ||
370 | int i; | 372 | int i; |
371 | phys_addr_t *buf_pa; | ||
372 | 373 | ||
373 | /* | 374 | /* |
374 | * driver maintaines the write pointer and firmware maintaines the read | 375 | * driver maintaines the write pointer and firmware maintaines the read |
@@ -384,16 +385,18 @@ static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter) | |||
384 | MWIFIEX_MAX_TXRX_BD; | 385 | MWIFIEX_MAX_TXRX_BD; |
385 | dev_dbg(adapter->dev, "info: txbd_ring: Allocating %d bytes\n", | 386 | dev_dbg(adapter->dev, "info: txbd_ring: Allocating %d bytes\n", |
386 | card->txbd_ring_size); | 387 | card->txbd_ring_size); |
387 | card->txbd_ring_vbase = kzalloc(card->txbd_ring_size, GFP_KERNEL); | 388 | card->txbd_ring_vbase = pci_alloc_consistent(card->dev, |
389 | card->txbd_ring_size, | ||
390 | &card->txbd_ring_pbase); | ||
388 | if (!card->txbd_ring_vbase) { | 391 | if (!card->txbd_ring_vbase) { |
389 | dev_err(adapter->dev, "Unable to alloc buffer for txbd ring\n"); | 392 | dev_err(adapter->dev, |
393 | "allocate consistent memory (%d bytes) failed!\n", | ||
394 | card->txbd_ring_size); | ||
390 | return -ENOMEM; | 395 | return -ENOMEM; |
391 | } | 396 | } |
392 | card->txbd_ring_pbase = virt_to_phys(card->txbd_ring_vbase); | ||
393 | |||
394 | dev_dbg(adapter->dev, | 397 | dev_dbg(adapter->dev, |
395 | "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n", | 398 | "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n", |
396 | card->txbd_ring_vbase, (u32)card->txbd_ring_pbase, | 399 | card->txbd_ring_vbase, (unsigned int)card->txbd_ring_pbase, |
397 | (u32)((u64)card->txbd_ring_pbase >> 32), card->txbd_ring_size); | 400 | (u32)((u64)card->txbd_ring_pbase >> 32), card->txbd_ring_size); |
398 | 401 | ||
399 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { | 402 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { |
@@ -402,24 +405,9 @@ static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter) | |||
402 | (sizeof(struct mwifiex_pcie_buf_desc) | 405 | (sizeof(struct mwifiex_pcie_buf_desc) |
403 | * i)); | 406 | * i)); |
404 | 407 | ||
405 | /* Allocate buffer here so that firmware can DMA data from it */ | 408 | card->tx_buf_list[i] = NULL; |
406 | skb = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE); | 409 | card->txbd_ring[i]->paddr = 0; |
407 | if (!skb) { | 410 | card->txbd_ring[i]->len = 0; |
408 | dev_err(adapter->dev, "Unable to allocate skb for TX ring.\n"); | ||
409 | kfree(card->txbd_ring_vbase); | ||
410 | return -ENOMEM; | ||
411 | } | ||
412 | buf_pa = mwifiex_update_sk_buff_pa(skb); | ||
413 | |||
414 | skb_put(skb, MWIFIEX_RX_DATA_BUF_SIZE); | ||
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", | ||
417 | skb, skb->data, (u32)*buf_pa, | ||
418 | (u32)(((u64)*buf_pa >> 32)), skb->len); | ||
419 | |||
420 | card->tx_buf_list[i] = skb; | ||
421 | card->txbd_ring[i]->paddr = *buf_pa; | ||
422 | card->txbd_ring[i]->len = (u16)skb->len; | ||
423 | card->txbd_ring[i]->flags = 0; | 411 | card->txbd_ring[i]->flags = 0; |
424 | } | 412 | } |
425 | 413 | ||
@@ -429,11 +417,16 @@ static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter) | |||
429 | static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter) | 417 | static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter) |
430 | { | 418 | { |
431 | struct pcie_service_card *card = adapter->card; | 419 | struct pcie_service_card *card = adapter->card; |
420 | struct sk_buff *skb; | ||
432 | int i; | 421 | int i; |
433 | 422 | ||
434 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { | 423 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { |
435 | if (card->tx_buf_list[i]) | 424 | if (card->tx_buf_list[i]) { |
436 | dev_kfree_skb_any(card->tx_buf_list[i]); | 425 | skb = card->tx_buf_list[i]; |
426 | pci_unmap_single(card->dev, card->txbd_ring[i]->paddr, | ||
427 | skb->len, PCI_DMA_TODEVICE); | ||
428 | dev_kfree_skb_any(skb); | ||
429 | } | ||
437 | card->tx_buf_list[i] = NULL; | 430 | card->tx_buf_list[i] = NULL; |
438 | card->txbd_ring[i]->paddr = 0; | 431 | card->txbd_ring[i]->paddr = 0; |
439 | card->txbd_ring[i]->len = 0; | 432 | card->txbd_ring[i]->len = 0; |
@@ -441,11 +434,15 @@ static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter) | |||
441 | card->txbd_ring[i] = NULL; | 434 | card->txbd_ring[i] = NULL; |
442 | } | 435 | } |
443 | 436 | ||
444 | kfree(card->txbd_ring_vbase); | 437 | if (card->txbd_ring_vbase) |
438 | pci_free_consistent(card->dev, card->txbd_ring_size, | ||
439 | card->txbd_ring_vbase, | ||
440 | card->txbd_ring_pbase); | ||
445 | card->txbd_ring_size = 0; | 441 | card->txbd_ring_size = 0; |
446 | card->txbd_wrptr = 0; | 442 | card->txbd_wrptr = 0; |
447 | card->txbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; | 443 | card->txbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; |
448 | card->txbd_ring_vbase = NULL; | 444 | card->txbd_ring_vbase = NULL; |
445 | card->txbd_ring_pbase = 0; | ||
449 | 446 | ||
450 | return 0; | 447 | return 0; |
451 | } | 448 | } |
@@ -458,7 +455,7 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) | |||
458 | struct pcie_service_card *card = adapter->card; | 455 | struct pcie_service_card *card = adapter->card; |
459 | struct sk_buff *skb; | 456 | struct sk_buff *skb; |
460 | int i; | 457 | int i; |
461 | phys_addr_t *buf_pa; | 458 | dma_addr_t buf_pa; |
462 | 459 | ||
463 | /* | 460 | /* |
464 | * driver maintaines the read pointer and firmware maintaines the write | 461 | * driver maintaines the read pointer and firmware maintaines the write |
@@ -472,13 +469,15 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) | |||
472 | MWIFIEX_MAX_TXRX_BD; | 469 | MWIFIEX_MAX_TXRX_BD; |
473 | dev_dbg(adapter->dev, "info: rxbd_ring: Allocating %d bytes\n", | 470 | dev_dbg(adapter->dev, "info: rxbd_ring: Allocating %d bytes\n", |
474 | card->rxbd_ring_size); | 471 | card->rxbd_ring_size); |
475 | card->rxbd_ring_vbase = kzalloc(card->rxbd_ring_size, GFP_KERNEL); | 472 | card->rxbd_ring_vbase = pci_alloc_consistent(card->dev, |
473 | card->rxbd_ring_size, | ||
474 | &card->rxbd_ring_pbase); | ||
476 | if (!card->rxbd_ring_vbase) { | 475 | if (!card->rxbd_ring_vbase) { |
477 | dev_err(adapter->dev, "Unable to allocate buffer for " | 476 | dev_err(adapter->dev, |
478 | "rxbd_ring.\n"); | 477 | "allocate consistent memory (%d bytes) failed!\n", |
478 | card->rxbd_ring_size); | ||
479 | return -ENOMEM; | 479 | return -ENOMEM; |
480 | } | 480 | } |
481 | card->rxbd_ring_pbase = virt_to_phys(card->rxbd_ring_vbase); | ||
482 | 481 | ||
483 | dev_dbg(adapter->dev, | 482 | dev_dbg(adapter->dev, |
484 | "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n", | 483 | "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n", |
@@ -500,16 +499,20 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) | |||
500 | kfree(card->rxbd_ring_vbase); | 499 | kfree(card->rxbd_ring_vbase); |
501 | return -ENOMEM; | 500 | return -ENOMEM; |
502 | } | 501 | } |
503 | buf_pa = mwifiex_update_sk_buff_pa(skb); | 502 | if (mwifiex_map_pci_memory(adapter, skb, |
504 | skb_put(skb, MWIFIEX_RX_DATA_BUF_SIZE); | 503 | MWIFIEX_RX_DATA_BUF_SIZE, |
504 | PCI_DMA_FROMDEVICE)) | ||
505 | return -1; | ||
506 | |||
507 | MWIFIEX_SKB_PACB(skb, &buf_pa); | ||
505 | 508 | ||
506 | dev_dbg(adapter->dev, "info: RX ring: add new skb base: %p, " | 509 | dev_dbg(adapter->dev, "info: RX ring: add new skb base: %p, " |
507 | "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n", | 510 | "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n", |
508 | skb, skb->data, (u32)*buf_pa, (u32)((u64)*buf_pa >> 32), | 511 | skb, skb->data, (u32)buf_pa, (u32)((u64)buf_pa >> 32), |
509 | skb->len); | 512 | skb->len); |
510 | 513 | ||
511 | card->rx_buf_list[i] = skb; | 514 | card->rx_buf_list[i] = skb; |
512 | card->rxbd_ring[i]->paddr = *buf_pa; | 515 | card->rxbd_ring[i]->paddr = buf_pa; |
513 | card->rxbd_ring[i]->len = (u16)skb->len; | 516 | card->rxbd_ring[i]->len = (u16)skb->len; |
514 | card->rxbd_ring[i]->flags = 0; | 517 | card->rxbd_ring[i]->flags = 0; |
515 | } | 518 | } |
@@ -523,11 +526,17 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) | |||
523 | static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter) | 526 | static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter) |
524 | { | 527 | { |
525 | struct pcie_service_card *card = adapter->card; | 528 | struct pcie_service_card *card = adapter->card; |
529 | struct sk_buff *skb; | ||
526 | int i; | 530 | int i; |
527 | 531 | ||
528 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { | 532 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { |
529 | if (card->rx_buf_list[i]) | 533 | if (card->rx_buf_list[i]) { |
530 | dev_kfree_skb_any(card->rx_buf_list[i]); | 534 | skb = card->rx_buf_list[i]; |
535 | pci_unmap_single(card->dev, card->rxbd_ring[i]->paddr , | ||
536 | MWIFIEX_RX_DATA_BUF_SIZE, | ||
537 | PCI_DMA_FROMDEVICE); | ||
538 | dev_kfree_skb_any(skb); | ||
539 | } | ||
531 | card->rx_buf_list[i] = NULL; | 540 | card->rx_buf_list[i] = NULL; |
532 | card->rxbd_ring[i]->paddr = 0; | 541 | card->rxbd_ring[i]->paddr = 0; |
533 | card->rxbd_ring[i]->len = 0; | 542 | card->rxbd_ring[i]->len = 0; |
@@ -535,11 +544,15 @@ static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter) | |||
535 | card->rxbd_ring[i] = NULL; | 544 | card->rxbd_ring[i] = NULL; |
536 | } | 545 | } |
537 | 546 | ||
538 | kfree(card->rxbd_ring_vbase); | 547 | if (card->rxbd_ring_vbase) |
548 | pci_free_consistent(card->dev, card->rxbd_ring_size, | ||
549 | card->rxbd_ring_vbase, | ||
550 | card->rxbd_ring_pbase); | ||
539 | card->rxbd_ring_size = 0; | 551 | card->rxbd_ring_size = 0; |
540 | card->rxbd_wrptr = 0; | 552 | card->rxbd_wrptr = 0; |
541 | card->rxbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; | 553 | card->rxbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; |
542 | card->rxbd_ring_vbase = NULL; | 554 | card->rxbd_ring_vbase = NULL; |
555 | card->rxbd_ring_pbase = 0; | ||
543 | 556 | ||
544 | return 0; | 557 | return 0; |
545 | } | 558 | } |
@@ -552,7 +565,7 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) | |||
552 | struct pcie_service_card *card = adapter->card; | 565 | struct pcie_service_card *card = adapter->card; |
553 | struct sk_buff *skb; | 566 | struct sk_buff *skb; |
554 | int i; | 567 | int i; |
555 | phys_addr_t *buf_pa; | 568 | dma_addr_t buf_pa; |
556 | 569 | ||
557 | /* | 570 | /* |
558 | * driver maintaines the read pointer and firmware maintaines the write | 571 | * driver maintaines the read pointer and firmware maintaines the write |
@@ -566,13 +579,15 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) | |||
566 | MWIFIEX_MAX_EVT_BD; | 579 | MWIFIEX_MAX_EVT_BD; |
567 | dev_dbg(adapter->dev, "info: evtbd_ring: Allocating %d bytes\n", | 580 | dev_dbg(adapter->dev, "info: evtbd_ring: Allocating %d bytes\n", |
568 | card->evtbd_ring_size); | 581 | card->evtbd_ring_size); |
569 | card->evtbd_ring_vbase = kzalloc(card->evtbd_ring_size, GFP_KERNEL); | 582 | card->evtbd_ring_vbase = pci_alloc_consistent(card->dev, |
583 | card->evtbd_ring_size, | ||
584 | &card->evtbd_ring_pbase); | ||
570 | if (!card->evtbd_ring_vbase) { | 585 | if (!card->evtbd_ring_vbase) { |
571 | dev_err(adapter->dev, | 586 | dev_err(adapter->dev, |
572 | "Unable to allocate buffer. Terminating download\n"); | 587 | "allocate consistent memory (%d bytes) failed!\n", |
588 | card->evtbd_ring_size); | ||
573 | return -ENOMEM; | 589 | return -ENOMEM; |
574 | } | 590 | } |
575 | card->evtbd_ring_pbase = virt_to_phys(card->evtbd_ring_vbase); | ||
576 | 591 | ||
577 | dev_dbg(adapter->dev, | 592 | dev_dbg(adapter->dev, |
578 | "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n", | 593 | "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n", |
@@ -594,16 +609,20 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) | |||
594 | kfree(card->evtbd_ring_vbase); | 609 | kfree(card->evtbd_ring_vbase); |
595 | return -ENOMEM; | 610 | return -ENOMEM; |
596 | } | 611 | } |
597 | buf_pa = mwifiex_update_sk_buff_pa(skb); | ||
598 | skb_put(skb, MAX_EVENT_SIZE); | 612 | skb_put(skb, MAX_EVENT_SIZE); |
599 | 613 | ||
614 | if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE, | ||
615 | PCI_DMA_FROMDEVICE)) | ||
616 | return -1; | ||
617 | |||
618 | MWIFIEX_SKB_PACB(skb, &buf_pa); | ||
600 | dev_dbg(adapter->dev, "info: Evt ring: add new skb. base: %p, " | 619 | dev_dbg(adapter->dev, "info: Evt ring: add new skb. base: %p, " |
601 | "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n", | 620 | "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n", |
602 | skb, skb->data, (u32)*buf_pa, (u32)((u64)*buf_pa >> 32), | 621 | skb, skb->data, (u32)buf_pa, (u32)((u64)buf_pa >> 32), |
603 | skb->len); | 622 | skb->len); |
604 | 623 | ||
605 | card->evt_buf_list[i] = skb; | 624 | card->evt_buf_list[i] = skb; |
606 | card->evtbd_ring[i]->paddr = *buf_pa; | 625 | card->evtbd_ring[i]->paddr = buf_pa; |
607 | card->evtbd_ring[i]->len = (u16)skb->len; | 626 | card->evtbd_ring[i]->len = (u16)skb->len; |
608 | card->evtbd_ring[i]->flags = 0; | 627 | card->evtbd_ring[i]->flags = 0; |
609 | } | 628 | } |
@@ -617,11 +636,16 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) | |||
617 | static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter) | 636 | static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter) |
618 | { | 637 | { |
619 | struct pcie_service_card *card = adapter->card; | 638 | struct pcie_service_card *card = adapter->card; |
639 | struct sk_buff *skb; | ||
620 | int i; | 640 | int i; |
621 | 641 | ||
622 | for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) { | 642 | for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) { |
623 | if (card->evt_buf_list[i]) | 643 | if (card->evt_buf_list[i]) { |
624 | dev_kfree_skb_any(card->evt_buf_list[i]); | 644 | skb = card->evt_buf_list[i]; |
645 | pci_unmap_single(card->dev, card->evtbd_ring[i]->paddr, | ||
646 | MAX_EVENT_SIZE, PCI_DMA_FROMDEVICE); | ||
647 | dev_kfree_skb_any(skb); | ||
648 | } | ||
625 | card->evt_buf_list[i] = NULL; | 649 | card->evt_buf_list[i] = NULL; |
626 | card->evtbd_ring[i]->paddr = 0; | 650 | card->evtbd_ring[i]->paddr = 0; |
627 | card->evtbd_ring[i]->len = 0; | 651 | card->evtbd_ring[i]->len = 0; |
@@ -629,11 +653,15 @@ static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter) | |||
629 | card->evtbd_ring[i] = NULL; | 653 | card->evtbd_ring[i] = NULL; |
630 | } | 654 | } |
631 | 655 | ||
632 | kfree(card->evtbd_ring_vbase); | 656 | if (card->evtbd_ring_vbase) |
657 | pci_free_consistent(card->dev, card->evtbd_ring_size, | ||
658 | card->evtbd_ring_vbase, | ||
659 | card->evtbd_ring_pbase); | ||
633 | card->evtbd_wrptr = 0; | 660 | card->evtbd_wrptr = 0; |
634 | card->evtbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; | 661 | card->evtbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; |
635 | card->evtbd_ring_size = 0; | 662 | card->evtbd_ring_size = 0; |
636 | card->evtbd_ring_vbase = NULL; | 663 | card->evtbd_ring_vbase = NULL; |
664 | card->evtbd_ring_pbase = 0; | ||
637 | 665 | ||
638 | return 0; | 666 | return 0; |
639 | } | 667 | } |
@@ -653,21 +681,12 @@ static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter) | |||
653 | "Unable to allocate skb for command response data.\n"); | 681 | "Unable to allocate skb for command response data.\n"); |
654 | return -ENOMEM; | 682 | return -ENOMEM; |
655 | } | 683 | } |
656 | mwifiex_update_sk_buff_pa(skb); | ||
657 | skb_put(skb, MWIFIEX_UPLD_SIZE); | 684 | skb_put(skb, MWIFIEX_UPLD_SIZE); |
658 | card->cmdrsp_buf = skb; | 685 | if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE, |
686 | PCI_DMA_FROMDEVICE)) | ||
687 | return -1; | ||
659 | 688 | ||
660 | skb = NULL; | 689 | card->cmdrsp_buf = skb; |
661 | /* Allocate memory for sending command to firmware */ | ||
662 | skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER); | ||
663 | if (!skb) { | ||
664 | dev_err(adapter->dev, | ||
665 | "Unable to allocate skb for command data.\n"); | ||
666 | return -ENOMEM; | ||
667 | } | ||
668 | mwifiex_update_sk_buff_pa(skb); | ||
669 | skb_put(skb, MWIFIEX_SIZE_OF_CMD_BUFFER); | ||
670 | card->cmd_buf = skb; | ||
671 | 690 | ||
672 | return 0; | 691 | return 0; |
673 | } | 692 | } |
@@ -678,18 +697,26 @@ static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter) | |||
678 | static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter) | 697 | static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter) |
679 | { | 698 | { |
680 | struct pcie_service_card *card; | 699 | struct pcie_service_card *card; |
700 | dma_addr_t buf_pa; | ||
681 | 701 | ||
682 | if (!adapter) | 702 | if (!adapter) |
683 | return 0; | 703 | return 0; |
684 | 704 | ||
685 | card = adapter->card; | 705 | card = adapter->card; |
686 | 706 | ||
687 | if (card && card->cmdrsp_buf) | 707 | if (card && card->cmdrsp_buf) { |
708 | MWIFIEX_SKB_PACB(card->cmdrsp_buf, &buf_pa); | ||
709 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, | ||
710 | PCI_DMA_FROMDEVICE); | ||
688 | dev_kfree_skb_any(card->cmdrsp_buf); | 711 | dev_kfree_skb_any(card->cmdrsp_buf); |
712 | } | ||
689 | 713 | ||
690 | if (card && card->cmd_buf) | 714 | if (card && card->cmd_buf) { |
715 | MWIFIEX_SKB_PACB(card->cmd_buf, &buf_pa); | ||
716 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_SIZE_OF_CMD_BUFFER, | ||
717 | PCI_DMA_TODEVICE); | ||
691 | dev_kfree_skb_any(card->cmd_buf); | 718 | dev_kfree_skb_any(card->cmd_buf); |
692 | 719 | } | |
693 | return 0; | 720 | return 0; |
694 | } | 721 | } |
695 | 722 | ||
@@ -698,27 +725,19 @@ static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter) | |||
698 | */ | 725 | */ |
699 | static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter) | 726 | static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter) |
700 | { | 727 | { |
701 | struct sk_buff *skb; | ||
702 | struct pcie_service_card *card = adapter->card; | 728 | struct pcie_service_card *card = adapter->card; |
703 | 729 | ||
704 | /* Allocate memory for sleep cookie */ | 730 | card->sleep_cookie_vbase = pci_alloc_consistent(card->dev, sizeof(u32), |
705 | skb = dev_alloc_skb(sizeof(u32)); | 731 | &card->sleep_cookie_pbase); |
706 | if (!skb) { | 732 | if (!card->sleep_cookie_vbase) { |
707 | dev_err(adapter->dev, | 733 | dev_err(adapter->dev, "pci_alloc_consistent failed!\n"); |
708 | "Unable to allocate skb for sleep cookie!\n"); | ||
709 | return -ENOMEM; | 734 | return -ENOMEM; |
710 | } | 735 | } |
711 | mwifiex_update_sk_buff_pa(skb); | ||
712 | skb_put(skb, sizeof(u32)); | ||
713 | |||
714 | /* Init val of Sleep Cookie */ | 736 | /* Init val of Sleep Cookie */ |
715 | *(u32 *)skb->data = FW_AWAKE_COOKIE; | 737 | *(u32 *)card->sleep_cookie_vbase = FW_AWAKE_COOKIE; |
716 | 738 | ||
717 | dev_dbg(adapter->dev, "alloc_scook: sleep cookie=0x%x\n", | 739 | dev_dbg(adapter->dev, "alloc_scook: sleep cookie=0x%x\n", |
718 | *((u32 *)skb->data)); | 740 | *((u32 *)card->sleep_cookie_vbase)); |
719 | |||
720 | /* Save the sleep cookie */ | ||
721 | card->sleep_cookie = skb; | ||
722 | 741 | ||
723 | return 0; | 742 | return 0; |
724 | } | 743 | } |
@@ -735,9 +754,11 @@ static int mwifiex_pcie_delete_sleep_cookie_buf(struct mwifiex_adapter *adapter) | |||
735 | 754 | ||
736 | card = adapter->card; | 755 | card = adapter->card; |
737 | 756 | ||
738 | if (card && card->sleep_cookie) { | 757 | if (card && card->sleep_cookie_vbase) { |
739 | dev_kfree_skb_any(card->sleep_cookie); | 758 | pci_free_consistent(card->dev, sizeof(u32), |
740 | card->sleep_cookie = NULL; | 759 | card->sleep_cookie_vbase, |
760 | card->sleep_cookie_pbase); | ||
761 | card->sleep_cookie_vbase = NULL; | ||
741 | } | 762 | } |
742 | 763 | ||
743 | return 0; | 764 | return 0; |
@@ -751,7 +772,7 @@ mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
751 | { | 772 | { |
752 | struct pcie_service_card *card = adapter->card; | 773 | struct pcie_service_card *card = adapter->card; |
753 | u32 wrindx, rdptr; | 774 | u32 wrindx, rdptr; |
754 | phys_addr_t *buf_pa; | 775 | phys_addr_t buf_pa; |
755 | __le16 *tmp; | 776 | __le16 *tmp; |
756 | 777 | ||
757 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) | 778 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
@@ -785,8 +806,8 @@ mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
785 | *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA); | 806 | *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA); |
786 | skb_put(skb_data, MWIFIEX_RX_DATA_BUF_SIZE - skb_data->len); | 807 | skb_put(skb_data, MWIFIEX_RX_DATA_BUF_SIZE - skb_data->len); |
787 | skb_trim(skb_data, skb->len); | 808 | skb_trim(skb_data, skb->len); |
788 | buf_pa = MWIFIEX_SKB_PACB(skb_data); | 809 | MWIFIEX_SKB_PACB(skb_data, &buf_pa); |
789 | card->txbd_ring[wrindx]->paddr = *buf_pa; | 810 | card->txbd_ring[wrindx]->paddr = buf_pa; |
790 | card->txbd_ring[wrindx]->len = (u16)skb_data->len; | 811 | card->txbd_ring[wrindx]->len = (u16)skb_data->len; |
791 | card->txbd_ring[wrindx]->flags = MWIFIEX_BD_FLAG_FIRST_DESC | | 812 | card->txbd_ring[wrindx]->flags = MWIFIEX_BD_FLAG_FIRST_DESC | |
792 | MWIFIEX_BD_FLAG_LAST_DESC; | 813 | MWIFIEX_BD_FLAG_LAST_DESC; |
@@ -918,32 +939,41 @@ done: | |||
918 | static int | 939 | static int |
919 | mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | 940 | mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) |
920 | { | 941 | { |
921 | phys_addr_t *buf_pa = MWIFIEX_SKB_PACB(skb); | 942 | dma_addr_t buf_pa; |
943 | struct pcie_service_card *card = adapter->card; | ||
922 | 944 | ||
923 | if (!(skb->data && skb->len && *buf_pa)) { | 945 | if (!(skb->data && skb->len)) { |
924 | dev_err(adapter->dev, | 946 | dev_err(adapter->dev, |
925 | "Invalid parameter in %s <%p, %#x:%x, %x>\n", | 947 | "Invalid parameter in %s <%p. len %d>\n", |
926 | __func__, skb->data, skb->len, | 948 | __func__, skb->data, skb->len); |
927 | (u32)*buf_pa, (u32)((u64)*buf_pa >> 32)); | ||
928 | return -1; | 949 | return -1; |
929 | } | 950 | } |
930 | 951 | ||
952 | if (mwifiex_map_pci_memory(adapter, skb, skb->len , PCI_DMA_TODEVICE)) | ||
953 | return -1; | ||
954 | |||
955 | MWIFIEX_SKB_PACB(skb, &buf_pa); | ||
956 | |||
931 | /* Write the lower 32bits of the physical address to scratch | 957 | /* Write the lower 32bits of the physical address to scratch |
932 | * register 0 */ | 958 | * register 0 */ |
933 | if (mwifiex_write_reg(adapter, PCIE_SCRATCH_0_REG, (u32)*buf_pa)) { | 959 | if (mwifiex_write_reg(adapter, PCIE_SCRATCH_0_REG, (u32)buf_pa)) { |
934 | dev_err(adapter->dev, | 960 | dev_err(adapter->dev, |
935 | "%s: failed to write download command to boot code.\n", | 961 | "%s: failed to write download command to boot code.\n", |
936 | __func__); | 962 | __func__); |
963 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, | ||
964 | PCI_DMA_TODEVICE); | ||
937 | return -1; | 965 | return -1; |
938 | } | 966 | } |
939 | 967 | ||
940 | /* Write the upper 32bits of the physical address to scratch | 968 | /* Write the upper 32bits of the physical address to scratch |
941 | * register 1 */ | 969 | * register 1 */ |
942 | if (mwifiex_write_reg(adapter, PCIE_SCRATCH_1_REG, | 970 | if (mwifiex_write_reg(adapter, PCIE_SCRATCH_1_REG, |
943 | (u32)((u64)*buf_pa >> 32))) { | 971 | (u32)((u64)buf_pa >> 32))) { |
944 | dev_err(adapter->dev, | 972 | dev_err(adapter->dev, |
945 | "%s: failed to write download command to boot code.\n", | 973 | "%s: failed to write download command to boot code.\n", |
946 | __func__); | 974 | __func__); |
975 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, | ||
976 | PCI_DMA_TODEVICE); | ||
947 | return -1; | 977 | return -1; |
948 | } | 978 | } |
949 | 979 | ||
@@ -952,6 +982,8 @@ mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
952 | dev_err(adapter->dev, | 982 | dev_err(adapter->dev, |
953 | "%s: failed to write command len to scratch reg 2\n", | 983 | "%s: failed to write command len to scratch reg 2\n", |
954 | __func__); | 984 | __func__); |
985 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, | ||
986 | PCI_DMA_TODEVICE); | ||
955 | return -1; | 987 | return -1; |
956 | } | 988 | } |
957 | 989 | ||
@@ -960,6 +992,8 @@ mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
960 | CPU_INTR_DOOR_BELL)) { | 992 | CPU_INTR_DOOR_BELL)) { |
961 | dev_err(adapter->dev, | 993 | dev_err(adapter->dev, |
962 | "%s: failed to assert door-bell intr\n", __func__); | 994 | "%s: failed to assert door-bell intr\n", __func__); |
995 | pci_unmap_single(card->dev, buf_pa, | ||
996 | MWIFIEX_UPLD_SIZE, PCI_DMA_TODEVICE); | ||
963 | return -1; | 997 | return -1; |
964 | } | 998 | } |
965 | 999 | ||
@@ -989,8 +1023,8 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
989 | { | 1023 | { |
990 | struct pcie_service_card *card = adapter->card; | 1024 | struct pcie_service_card *card = adapter->card; |
991 | int ret = 0; | 1025 | int ret = 0; |
992 | phys_addr_t *cmd_buf_pa; | 1026 | dma_addr_t cmd_buf_pa, cmdrsp_buf_pa; |
993 | phys_addr_t *cmdrsp_buf_pa; | 1027 | u8 *payload = (u8 *)skb->data; |
994 | 1028 | ||
995 | if (!(skb->data && skb->len)) { | 1029 | if (!(skb->data && skb->len)) { |
996 | dev_err(adapter->dev, "Invalid parameter in %s <%p, %#x>\n", | 1030 | dev_err(adapter->dev, "Invalid parameter in %s <%p, %#x>\n", |
@@ -1005,17 +1039,18 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
1005 | return -EBUSY; | 1039 | return -EBUSY; |
1006 | } | 1040 | } |
1007 | 1041 | ||
1008 | /* Make sure a command buffer is available */ | 1042 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
1009 | if (!card->cmd_buf) { | 1043 | mwifiex_pm_wakeup_card(adapter); |
1010 | dev_err(adapter->dev, "Command buffer not available\n"); | ||
1011 | return -EBUSY; | ||
1012 | } | ||
1013 | 1044 | ||
1014 | adapter->cmd_sent = true; | 1045 | adapter->cmd_sent = true; |
1015 | /* Copy the given skb in to DMA accessable shared buffer */ | 1046 | |
1016 | skb_put(card->cmd_buf, MWIFIEX_SIZE_OF_CMD_BUFFER - card->cmd_buf->len); | 1047 | *(__le16 *)&payload[0] = cpu_to_le16((u16)skb->len); |
1017 | skb_trim(card->cmd_buf, skb->len); | 1048 | *(__le16 *)&payload[2] = cpu_to_le16(MWIFIEX_TYPE_CMD); |
1018 | memcpy(card->cmd_buf->data, skb->data, skb->len); | 1049 | |
1050 | if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE)) | ||
1051 | return -1; | ||
1052 | |||
1053 | card->cmd_buf = skb; | ||
1019 | 1054 | ||
1020 | /* To send a command, the driver will: | 1055 | /* To send a command, the driver will: |
1021 | 1. Write the 64bit physical address of the data buffer to | 1056 | 1. Write the 64bit physical address of the data buffer to |
@@ -1028,11 +1063,11 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
1028 | */ | 1063 | */ |
1029 | 1064 | ||
1030 | if (card->cmdrsp_buf) { | 1065 | if (card->cmdrsp_buf) { |
1031 | cmdrsp_buf_pa = MWIFIEX_SKB_PACB(card->cmdrsp_buf); | 1066 | MWIFIEX_SKB_PACB(card->cmdrsp_buf, &cmdrsp_buf_pa); |
1032 | /* Write the lower 32bits of the cmdrsp buffer physical | 1067 | /* Write the lower 32bits of the cmdrsp buffer physical |
1033 | address */ | 1068 | address */ |
1034 | if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_LO, | 1069 | if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_LO, |
1035 | (u32)*cmdrsp_buf_pa)) { | 1070 | (u32)cmdrsp_buf_pa)) { |
1036 | dev_err(adapter->dev, | 1071 | dev_err(adapter->dev, |
1037 | "Failed to write download cmd to boot code.\n"); | 1072 | "Failed to write download cmd to boot code.\n"); |
1038 | ret = -1; | 1073 | ret = -1; |
@@ -1041,7 +1076,7 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
1041 | /* Write the upper 32bits of the cmdrsp buffer physical | 1076 | /* Write the upper 32bits of the cmdrsp buffer physical |
1042 | address */ | 1077 | address */ |
1043 | if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_HI, | 1078 | if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_HI, |
1044 | (u32)((u64)*cmdrsp_buf_pa >> 32))) { | 1079 | (u32)((u64)cmdrsp_buf_pa >> 32))) { |
1045 | dev_err(adapter->dev, | 1080 | dev_err(adapter->dev, |
1046 | "Failed to write download cmd to boot code.\n"); | 1081 | "Failed to write download cmd to boot code.\n"); |
1047 | ret = -1; | 1082 | ret = -1; |
@@ -1049,9 +1084,9 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
1049 | } | 1084 | } |
1050 | } | 1085 | } |
1051 | 1086 | ||
1052 | cmd_buf_pa = MWIFIEX_SKB_PACB(card->cmd_buf); | 1087 | MWIFIEX_SKB_PACB(card->cmd_buf, &cmd_buf_pa); |
1053 | /* Write the lower 32bits of the physical address to REG_CMD_ADDR_LO */ | 1088 | /* Write the lower 32bits of the physical address to REG_CMD_ADDR_LO */ |
1054 | if (mwifiex_write_reg(adapter, REG_CMD_ADDR_LO, (u32)*cmd_buf_pa)) { | 1089 | if (mwifiex_write_reg(adapter, REG_CMD_ADDR_LO, (u32)cmd_buf_pa)) { |
1055 | dev_err(adapter->dev, | 1090 | dev_err(adapter->dev, |
1056 | "Failed to write download cmd to boot code.\n"); | 1091 | "Failed to write download cmd to boot code.\n"); |
1057 | ret = -1; | 1092 | ret = -1; |
@@ -1059,7 +1094,7 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) | |||
1059 | } | 1094 | } |
1060 | /* Write the upper 32bits of the physical address to REG_CMD_ADDR_HI */ | 1095 | /* Write the upper 32bits of the physical address to REG_CMD_ADDR_HI */ |
1061 | if (mwifiex_write_reg(adapter, REG_CMD_ADDR_HI, | 1096 | if (mwifiex_write_reg(adapter, REG_CMD_ADDR_HI, |
1062 | (u32)((u64)*cmd_buf_pa >> 32))) { | 1097 | (u32)((u64)cmd_buf_pa >> 32))) { |
1063 | dev_err(adapter->dev, | 1098 | dev_err(adapter->dev, |
1064 | "Failed to write download cmd to boot code.\n"); | 1099 | "Failed to write download cmd to boot code.\n"); |
1065 | ret = -1; | 1100 | ret = -1; |
@@ -1098,11 +1133,22 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter) | |||
1098 | struct pcie_service_card *card = adapter->card; | 1133 | struct pcie_service_card *card = adapter->card; |
1099 | struct sk_buff *skb = card->cmdrsp_buf; | 1134 | struct sk_buff *skb = card->cmdrsp_buf; |
1100 | int count = 0; | 1135 | int count = 0; |
1136 | u16 rx_len; | ||
1137 | __le16 pkt_len; | ||
1138 | dma_addr_t buf_pa; | ||
1101 | 1139 | ||
1102 | dev_dbg(adapter->dev, "info: Rx CMD Response\n"); | 1140 | dev_dbg(adapter->dev, "info: Rx CMD Response\n"); |
1103 | 1141 | ||
1142 | MWIFIEX_SKB_PACB(skb, &buf_pa); | ||
1143 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, | ||
1144 | PCI_DMA_FROMDEVICE); | ||
1145 | |||
1146 | pkt_len = *((__le16 *)skb->data); | ||
1147 | rx_len = le16_to_cpu(pkt_len); | ||
1148 | skb_trim(skb, rx_len); | ||
1149 | skb_pull(skb, INTF_HEADER_LEN); | ||
1150 | |||
1104 | if (!adapter->curr_cmd) { | 1151 | if (!adapter->curr_cmd) { |
1105 | skb_pull(skb, INTF_HEADER_LEN); | ||
1106 | if (adapter->ps_state == PS_STATE_SLEEP_CFM) { | 1152 | if (adapter->ps_state == PS_STATE_SLEEP_CFM) { |
1107 | mwifiex_process_sleep_confirm_resp(adapter, skb->data, | 1153 | mwifiex_process_sleep_confirm_resp(adapter, skb->data, |
1108 | skb->len); | 1154 | skb->len); |
@@ -1115,9 +1161,12 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter) | |||
1115 | } | 1161 | } |
1116 | memcpy(adapter->upld_buf, skb->data, | 1162 | memcpy(adapter->upld_buf, skb->data, |
1117 | min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len)); | 1163 | min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len)); |
1118 | skb_push(skb, INTF_HEADER_LEN); | 1164 | if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE, |
1165 | PCI_DMA_FROMDEVICE)) | ||
1166 | return -1; | ||
1167 | |||
1168 | MWIFIEX_SKB_PACB(skb, &buf_pa); | ||
1119 | } else if (mwifiex_pcie_ok_to_access_hw(adapter)) { | 1169 | } else if (mwifiex_pcie_ok_to_access_hw(adapter)) { |
1120 | skb_pull(skb, INTF_HEADER_LEN); | ||
1121 | adapter->curr_cmd->resp_skb = skb; | 1170 | adapter->curr_cmd->resp_skb = skb; |
1122 | adapter->cmd_resp_received = true; | 1171 | adapter->cmd_resp_received = true; |
1123 | /* Take the pointer and set it to CMD node and will | 1172 | /* Take the pointer and set it to CMD node and will |
@@ -1151,10 +1200,23 @@ static int mwifiex_pcie_cmdrsp_complete(struct mwifiex_adapter *adapter, | |||
1151 | struct sk_buff *skb) | 1200 | struct sk_buff *skb) |
1152 | { | 1201 | { |
1153 | struct pcie_service_card *card = adapter->card; | 1202 | struct pcie_service_card *card = adapter->card; |
1203 | dma_addr_t buf_pa; | ||
1204 | struct sk_buff *skb_tmp; | ||
1154 | 1205 | ||
1155 | if (skb) { | 1206 | if (skb) { |
1156 | card->cmdrsp_buf = skb; | 1207 | card->cmdrsp_buf = skb; |
1157 | skb_push(card->cmdrsp_buf, INTF_HEADER_LEN); | 1208 | skb_push(card->cmdrsp_buf, INTF_HEADER_LEN); |
1209 | if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE, | ||
1210 | PCI_DMA_FROMDEVICE)) | ||
1211 | return -1; | ||
1212 | } | ||
1213 | |||
1214 | skb_tmp = card->cmd_buf; | ||
1215 | if (skb_tmp) { | ||
1216 | MWIFIEX_SKB_PACB(skb_tmp, &buf_pa); | ||
1217 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, | ||
1218 | PCI_DMA_FROMDEVICE); | ||
1219 | card->cmd_buf = NULL; | ||
1158 | } | 1220 | } |
1159 | 1221 | ||
1160 | return 0; | 1222 | return 0; |
@@ -1168,6 +1230,10 @@ static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter) | |||
1168 | struct pcie_service_card *card = adapter->card; | 1230 | struct pcie_service_card *card = adapter->card; |
1169 | u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; | 1231 | u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; |
1170 | u32 wrptr, event; | 1232 | u32 wrptr, event; |
1233 | dma_addr_t buf_pa; | ||
1234 | |||
1235 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) | ||
1236 | mwifiex_pm_wakeup_card(adapter); | ||
1171 | 1237 | ||
1172 | if (adapter->event_received) { | 1238 | if (adapter->event_received) { |
1173 | dev_dbg(adapter->dev, "info: Event being processed, " | 1239 | dev_dbg(adapter->dev, "info: Event being processed, " |
@@ -1199,6 +1265,10 @@ static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter) | |||
1199 | 1265 | ||
1200 | dev_dbg(adapter->dev, "info: Read Index: %d\n", rdptr); | 1266 | dev_dbg(adapter->dev, "info: Read Index: %d\n", rdptr); |
1201 | skb_cmd = card->evt_buf_list[rdptr]; | 1267 | skb_cmd = card->evt_buf_list[rdptr]; |
1268 | MWIFIEX_SKB_PACB(skb_cmd, &buf_pa); | ||
1269 | pci_unmap_single(card->dev, buf_pa, MAX_EVENT_SIZE, | ||
1270 | PCI_DMA_FROMDEVICE); | ||
1271 | |||
1202 | /* Take the pointer and set it to event pointer in adapter | 1272 | /* Take the pointer and set it to event pointer in adapter |
1203 | and will return back after event handling callback */ | 1273 | and will return back after event handling callback */ |
1204 | card->evt_buf_list[rdptr] = NULL; | 1274 | card->evt_buf_list[rdptr] = NULL; |
@@ -1243,7 +1313,7 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter, | |||
1243 | int ret = 0; | 1313 | int ret = 0; |
1244 | u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; | 1314 | u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; |
1245 | u32 wrptr; | 1315 | u32 wrptr; |
1246 | phys_addr_t *buf_pa; | 1316 | dma_addr_t buf_pa; |
1247 | 1317 | ||
1248 | if (!skb) | 1318 | if (!skb) |
1249 | return 0; | 1319 | return 0; |
@@ -1263,9 +1333,14 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter, | |||
1263 | 1333 | ||
1264 | if (!card->evt_buf_list[rdptr]) { | 1334 | if (!card->evt_buf_list[rdptr]) { |
1265 | skb_push(skb, INTF_HEADER_LEN); | 1335 | skb_push(skb, INTF_HEADER_LEN); |
1336 | if (mwifiex_map_pci_memory(adapter, skb, | ||
1337 | MAX_EVENT_SIZE, | ||
1338 | PCI_DMA_FROMDEVICE)) | ||
1339 | return -1; | ||
1340 | MWIFIEX_SKB_PACB(skb, &buf_pa); | ||
1266 | card->evt_buf_list[rdptr] = skb; | 1341 | card->evt_buf_list[rdptr] = skb; |
1267 | buf_pa = MWIFIEX_SKB_PACB(skb); | 1342 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
1268 | card->evtbd_ring[rdptr]->paddr = *buf_pa; | 1343 | card->evtbd_ring[rdptr]->paddr = buf_pa; |
1269 | card->evtbd_ring[rdptr]->len = (u16)skb->len; | 1344 | card->evtbd_ring[rdptr]->len = (u16)skb->len; |
1270 | card->evtbd_ring[rdptr]->flags = 0; | 1345 | card->evtbd_ring[rdptr]->flags = 0; |
1271 | skb = NULL; | 1346 | skb = NULL; |
@@ -1314,11 +1389,8 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, | |||
1314 | struct sk_buff *skb; | 1389 | struct sk_buff *skb; |
1315 | u32 txlen, tx_blocks = 0, tries, len; | 1390 | u32 txlen, tx_blocks = 0, tries, len; |
1316 | u32 block_retry_cnt = 0; | 1391 | u32 block_retry_cnt = 0; |
1317 | 1392 | dma_addr_t buf_pa; | |
1318 | if (!adapter) { | 1393 | struct pcie_service_card *card = adapter->card; |
1319 | pr_err("adapter structure is not valid\n"); | ||
1320 | return -1; | ||
1321 | } | ||
1322 | 1394 | ||
1323 | if (!firmware || !firmware_len) { | 1395 | if (!firmware || !firmware_len) { |
1324 | dev_err(adapter->dev, | 1396 | dev_err(adapter->dev, |
@@ -1340,7 +1412,6 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, | |||
1340 | ret = -ENOMEM; | 1412 | ret = -ENOMEM; |
1341 | goto done; | 1413 | goto done; |
1342 | } | 1414 | } |
1343 | mwifiex_update_sk_buff_pa(skb); | ||
1344 | 1415 | ||
1345 | /* Perform firmware data transfer */ | 1416 | /* Perform firmware data transfer */ |
1346 | do { | 1417 | do { |
@@ -1415,6 +1486,9 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, | |||
1415 | ret = -1; | 1486 | ret = -1; |
1416 | goto done; | 1487 | goto done; |
1417 | } | 1488 | } |
1489 | |||
1490 | MWIFIEX_SKB_PACB(skb, &buf_pa); | ||
1491 | |||
1418 | /* Wait for the command done interrupt */ | 1492 | /* Wait for the command done interrupt */ |
1419 | do { | 1493 | do { |
1420 | if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS, | 1494 | if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS, |
@@ -1422,11 +1496,17 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, | |||
1422 | dev_err(adapter->dev, "%s: Failed to read " | 1496 | dev_err(adapter->dev, "%s: Failed to read " |
1423 | "interrupt status during fw dnld.\n", | 1497 | "interrupt status during fw dnld.\n", |
1424 | __func__); | 1498 | __func__); |
1499 | pci_unmap_single(card->dev, buf_pa, skb->len, | ||
1500 | PCI_DMA_TODEVICE); | ||
1425 | ret = -1; | 1501 | ret = -1; |
1426 | goto done; | 1502 | goto done; |
1427 | } | 1503 | } |
1428 | } while ((ireg_intr & CPU_INTR_DOOR_BELL) == | 1504 | } while ((ireg_intr & CPU_INTR_DOOR_BELL) == |
1429 | CPU_INTR_DOOR_BELL); | 1505 | CPU_INTR_DOOR_BELL); |
1506 | |||
1507 | pci_unmap_single(card->dev, buf_pa, skb->len, | ||
1508 | PCI_DMA_TODEVICE); | ||
1509 | |||
1430 | offset += txlen; | 1510 | offset += txlen; |
1431 | } while (true); | 1511 | } while (true); |
1432 | 1512 | ||
@@ -1828,15 +1908,8 @@ static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter) | |||
1828 | struct pcie_service_card *card = adapter->card; | 1908 | struct pcie_service_card *card = adapter->card; |
1829 | struct pci_dev *pdev = card->dev; | 1909 | struct pci_dev *pdev = card->dev; |
1830 | 1910 | ||
1831 | mwifiex_pcie_delete_sleep_cookie_buf(adapter); | ||
1832 | mwifiex_pcie_delete_cmdrsp_buf(adapter); | ||
1833 | mwifiex_pcie_delete_evtbd_ring(adapter); | ||
1834 | mwifiex_pcie_delete_rxbd_ring(adapter); | ||
1835 | mwifiex_pcie_delete_txbd_ring(adapter); | ||
1836 | card->cmdrsp_buf = NULL; | ||
1837 | |||
1838 | dev_dbg(adapter->dev, "Clearing driver ready signature\n"); | ||
1839 | if (user_rmmod) { | 1911 | if (user_rmmod) { |
1912 | dev_dbg(adapter->dev, "Clearing driver ready signature\n"); | ||
1840 | if (mwifiex_write_reg(adapter, REG_DRV_READY, 0x00000000)) | 1913 | if (mwifiex_write_reg(adapter, REG_DRV_READY, 0x00000000)) |
1841 | dev_err(adapter->dev, | 1914 | dev_err(adapter->dev, |
1842 | "Failed to write driver not-ready signature\n"); | 1915 | "Failed to write driver not-ready signature\n"); |
@@ -1893,6 +1966,13 @@ static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter) | |||
1893 | if (card) { | 1966 | if (card) { |
1894 | dev_dbg(adapter->dev, "%s(): calling free_irq()\n", __func__); | 1967 | dev_dbg(adapter->dev, "%s(): calling free_irq()\n", __func__); |
1895 | free_irq(card->dev->irq, card->dev); | 1968 | free_irq(card->dev->irq, card->dev); |
1969 | |||
1970 | mwifiex_pcie_delete_sleep_cookie_buf(adapter); | ||
1971 | mwifiex_pcie_delete_cmdrsp_buf(adapter); | ||
1972 | mwifiex_pcie_delete_evtbd_ring(adapter); | ||
1973 | mwifiex_pcie_delete_rxbd_ring(adapter); | ||
1974 | mwifiex_pcie_delete_txbd_ring(adapter); | ||
1975 | card->cmdrsp_buf = NULL; | ||
1896 | } | 1976 | } |
1897 | } | 1977 | } |
1898 | 1978 | ||
diff --git a/drivers/net/wireless/mwifiex/pcie.h b/drivers/net/wireless/mwifiex/pcie.h index 2f218f9a3fd3..87201f554d2e 100644 --- a/drivers/net/wireless/mwifiex/pcie.h +++ b/drivers/net/wireless/mwifiex/pcie.h | |||
@@ -118,7 +118,7 @@ struct pcie_service_card { | |||
118 | u32 txbd_rdptr; | 118 | u32 txbd_rdptr; |
119 | u32 txbd_ring_size; | 119 | u32 txbd_ring_size; |
120 | u8 *txbd_ring_vbase; | 120 | u8 *txbd_ring_vbase; |
121 | phys_addr_t txbd_ring_pbase; | 121 | dma_addr_t txbd_ring_pbase; |
122 | struct mwifiex_pcie_buf_desc *txbd_ring[MWIFIEX_MAX_TXRX_BD]; | 122 | struct mwifiex_pcie_buf_desc *txbd_ring[MWIFIEX_MAX_TXRX_BD]; |
123 | struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD]; | 123 | struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD]; |
124 | 124 | ||
@@ -126,7 +126,7 @@ struct pcie_service_card { | |||
126 | u32 rxbd_rdptr; | 126 | u32 rxbd_rdptr; |
127 | u32 rxbd_ring_size; | 127 | u32 rxbd_ring_size; |
128 | u8 *rxbd_ring_vbase; | 128 | u8 *rxbd_ring_vbase; |
129 | phys_addr_t rxbd_ring_pbase; | 129 | dma_addr_t rxbd_ring_pbase; |
130 | struct mwifiex_pcie_buf_desc *rxbd_ring[MWIFIEX_MAX_TXRX_BD]; | 130 | struct mwifiex_pcie_buf_desc *rxbd_ring[MWIFIEX_MAX_TXRX_BD]; |
131 | struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD]; | 131 | struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD]; |
132 | 132 | ||
@@ -134,13 +134,14 @@ struct pcie_service_card { | |||
134 | u32 evtbd_rdptr; | 134 | u32 evtbd_rdptr; |
135 | u32 evtbd_ring_size; | 135 | u32 evtbd_ring_size; |
136 | u8 *evtbd_ring_vbase; | 136 | u8 *evtbd_ring_vbase; |
137 | phys_addr_t evtbd_ring_pbase; | 137 | dma_addr_t evtbd_ring_pbase; |
138 | struct mwifiex_pcie_buf_desc *evtbd_ring[MWIFIEX_MAX_EVT_BD]; | 138 | struct mwifiex_pcie_buf_desc *evtbd_ring[MWIFIEX_MAX_EVT_BD]; |
139 | struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD]; | 139 | struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD]; |
140 | 140 | ||
141 | struct sk_buff *cmd_buf; | 141 | struct sk_buff *cmd_buf; |
142 | struct sk_buff *cmdrsp_buf; | 142 | struct sk_buff *cmdrsp_buf; |
143 | struct sk_buff *sleep_cookie; | 143 | u8 *sleep_cookie_vbase; |
144 | dma_addr_t sleep_cookie_pbase; | ||
144 | void __iomem *pci_mmap; | 145 | void __iomem *pci_mmap; |
145 | void __iomem *pci_mmap1; | 146 | void __iomem *pci_mmap1; |
146 | }; | 147 | }; |
diff --git a/drivers/net/wireless/mwifiex/sta_cmd.c b/drivers/net/wireless/mwifiex/sta_cmd.c index 5d87195390f8..c4607859d59d 100644 --- a/drivers/net/wireless/mwifiex/sta_cmd.c +++ b/drivers/net/wireless/mwifiex/sta_cmd.c | |||
@@ -931,7 +931,6 @@ mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv, | |||
931 | struct host_cmd_ds_pcie_details *host_spec = | 931 | struct host_cmd_ds_pcie_details *host_spec = |
932 | &cmd->params.pcie_host_spec; | 932 | &cmd->params.pcie_host_spec; |
933 | struct pcie_service_card *card = priv->adapter->card; | 933 | struct pcie_service_card *card = priv->adapter->card; |
934 | phys_addr_t *buf_pa; | ||
935 | 934 | ||
936 | cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS); | 935 | cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS); |
937 | cmd->size = cpu_to_le16(sizeof(struct | 936 | cmd->size = cpu_to_le16(sizeof(struct |
@@ -953,10 +952,11 @@ mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv, | |||
953 | host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase); | 952 | host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase); |
954 | host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32); | 953 | host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32); |
955 | host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD; | 954 | host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD; |
956 | if (card->sleep_cookie) { | 955 | if (card->sleep_cookie_vbase) { |
957 | buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie); | 956 | host_spec->sleep_cookie_addr_lo = |
958 | host_spec->sleep_cookie_addr_lo = (u32) *buf_pa; | 957 | (u32)(card->sleep_cookie_pbase); |
959 | host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32); | 958 | host_spec->sleep_cookie_addr_hi = |
959 | (u32)(((u64)(card->sleep_cookie_pbase)) >> 32); | ||
960 | dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n", | 960 | dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n", |
961 | host_spec->sleep_cookie_addr_lo); | 961 | host_spec->sleep_cookie_addr_lo); |
962 | } | 962 | } |
diff --git a/drivers/net/wireless/mwifiex/util.h b/drivers/net/wireless/mwifiex/util.h index f6d36b9654a0..cb2d0582bd36 100644 --- a/drivers/net/wireless/mwifiex/util.h +++ b/drivers/net/wireless/mwifiex/util.h | |||
@@ -22,16 +22,16 @@ | |||
22 | 22 | ||
23 | static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb) | 23 | static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb) |
24 | { | 24 | { |
25 | return (struct mwifiex_rxinfo *)(skb->cb + sizeof(phys_addr_t)); | 25 | return (struct mwifiex_rxinfo *)(skb->cb + sizeof(dma_addr_t)); |
26 | } | 26 | } |
27 | 27 | ||
28 | static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb) | 28 | static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb) |
29 | { | 29 | { |
30 | return (struct mwifiex_txinfo *)(skb->cb + sizeof(phys_addr_t)); | 30 | return (struct mwifiex_txinfo *)(skb->cb + sizeof(dma_addr_t)); |
31 | } | 31 | } |
32 | 32 | ||
33 | static inline phys_addr_t *MWIFIEX_SKB_PACB(struct sk_buff *skb) | 33 | static inline void MWIFIEX_SKB_PACB(struct sk_buff *skb, dma_addr_t *buf_pa) |
34 | { | 34 | { |
35 | return (phys_addr_t *)skb->cb; | 35 | memcpy(buf_pa, skb->cb, sizeof(dma_addr_t)); |
36 | } | 36 | } |
37 | #endif /* !_MWIFIEX_UTIL_H_ */ | 37 | #endif /* !_MWIFIEX_UTIL_H_ */ |