diff options
author | Guo-Fu Tseng <cooldavid@cooldavid.org> | 2009-07-06 00:39:46 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-07-06 16:05:06 -0400 |
commit | 47bd10d14b3341004266395014007c120a359c9d (patch) | |
tree | 06a3cf03233476936a5e7ee9af8a980a588a480f /drivers/net | |
parent | 44d8d2e9f0dfa52bb1aebdbaa510669bff61c9dc (diff) |
jme: Change bufinf memory location
Instead of using a large chunk of memory space preserved for
for modules, using kmalloc to obtain the needed memory.
Signed-off-by: Guo-Fu Tseng <cooldavid@cooldavid.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/jme.c | 86 | ||||
-rw-r--r-- | drivers/net/jme.h | 3 |
2 files changed, 63 insertions, 26 deletions
diff --git a/drivers/net/jme.c b/drivers/net/jme.c index 8de394021a5..4a55b055bcb 100644 --- a/drivers/net/jme.c +++ b/drivers/net/jme.c | |||
@@ -522,12 +522,8 @@ jme_setup_tx_resources(struct jme_adapter *jme) | |||
522 | &(txring->dmaalloc), | 522 | &(txring->dmaalloc), |
523 | GFP_ATOMIC); | 523 | GFP_ATOMIC); |
524 | 524 | ||
525 | if (!txring->alloc) { | 525 | if (!txring->alloc) |
526 | txring->desc = NULL; | 526 | goto err_set_null; |
527 | txring->dmaalloc = 0; | ||
528 | txring->dma = 0; | ||
529 | return -ENOMEM; | ||
530 | } | ||
531 | 527 | ||
532 | /* | 528 | /* |
533 | * 16 Bytes align | 529 | * 16 Bytes align |
@@ -539,6 +535,11 @@ jme_setup_tx_resources(struct jme_adapter *jme) | |||
539 | atomic_set(&txring->next_to_clean, 0); | 535 | atomic_set(&txring->next_to_clean, 0); |
540 | atomic_set(&txring->nr_free, jme->tx_ring_size); | 536 | atomic_set(&txring->nr_free, jme->tx_ring_size); |
541 | 537 | ||
538 | txring->bufinf = kmalloc(sizeof(struct jme_buffer_info) * | ||
539 | jme->tx_ring_size, GFP_ATOMIC); | ||
540 | if (unlikely(!(txring->bufinf))) | ||
541 | goto err_free_txring; | ||
542 | |||
542 | /* | 543 | /* |
543 | * Initialize Transmit Descriptors | 544 | * Initialize Transmit Descriptors |
544 | */ | 545 | */ |
@@ -547,6 +548,20 @@ jme_setup_tx_resources(struct jme_adapter *jme) | |||
547 | sizeof(struct jme_buffer_info) * jme->tx_ring_size); | 548 | sizeof(struct jme_buffer_info) * jme->tx_ring_size); |
548 | 549 | ||
549 | return 0; | 550 | return 0; |
551 | |||
552 | err_free_txring: | ||
553 | dma_free_coherent(&(jme->pdev->dev), | ||
554 | TX_RING_ALLOC_SIZE(jme->tx_ring_size), | ||
555 | txring->alloc, | ||
556 | txring->dmaalloc); | ||
557 | |||
558 | err_set_null: | ||
559 | txring->desc = NULL; | ||
560 | txring->dmaalloc = 0; | ||
561 | txring->dma = 0; | ||
562 | txring->bufinf = NULL; | ||
563 | |||
564 | return -ENOMEM; | ||
550 | } | 565 | } |
551 | 566 | ||
552 | static void | 567 | static void |
@@ -557,16 +572,19 @@ jme_free_tx_resources(struct jme_adapter *jme) | |||
557 | struct jme_buffer_info *txbi; | 572 | struct jme_buffer_info *txbi; |
558 | 573 | ||
559 | if (txring->alloc) { | 574 | if (txring->alloc) { |
560 | for (i = 0 ; i < jme->tx_ring_size ; ++i) { | 575 | if (txring->bufinf) { |
561 | txbi = txring->bufinf + i; | 576 | for (i = 0 ; i < jme->tx_ring_size ; ++i) { |
562 | if (txbi->skb) { | 577 | txbi = txring->bufinf + i; |
563 | dev_kfree_skb(txbi->skb); | 578 | if (txbi->skb) { |
564 | txbi->skb = NULL; | 579 | dev_kfree_skb(txbi->skb); |
580 | txbi->skb = NULL; | ||
581 | } | ||
582 | txbi->mapping = 0; | ||
583 | txbi->len = 0; | ||
584 | txbi->nr_desc = 0; | ||
585 | txbi->start_xmit = 0; | ||
565 | } | 586 | } |
566 | txbi->mapping = 0; | 587 | kfree(txring->bufinf); |
567 | txbi->len = 0; | ||
568 | txbi->nr_desc = 0; | ||
569 | txbi->start_xmit = 0; | ||
570 | } | 588 | } |
571 | 589 | ||
572 | dma_free_coherent(&(jme->pdev->dev), | 590 | dma_free_coherent(&(jme->pdev->dev), |
@@ -578,11 +596,11 @@ jme_free_tx_resources(struct jme_adapter *jme) | |||
578 | txring->desc = NULL; | 596 | txring->desc = NULL; |
579 | txring->dmaalloc = 0; | 597 | txring->dmaalloc = 0; |
580 | txring->dma = 0; | 598 | txring->dma = 0; |
599 | txring->bufinf = NULL; | ||
581 | } | 600 | } |
582 | txring->next_to_use = 0; | 601 | txring->next_to_use = 0; |
583 | atomic_set(&txring->next_to_clean, 0); | 602 | atomic_set(&txring->next_to_clean, 0); |
584 | atomic_set(&txring->nr_free, 0); | 603 | atomic_set(&txring->nr_free, 0); |
585 | |||
586 | } | 604 | } |
587 | 605 | ||
588 | static inline void | 606 | static inline void |
@@ -720,8 +738,11 @@ jme_free_rx_resources(struct jme_adapter *jme) | |||
720 | struct jme_ring *rxring = &(jme->rxring[0]); | 738 | struct jme_ring *rxring = &(jme->rxring[0]); |
721 | 739 | ||
722 | if (rxring->alloc) { | 740 | if (rxring->alloc) { |
723 | for (i = 0 ; i < jme->rx_ring_size ; ++i) | 741 | if (rxring->bufinf) { |
724 | jme_free_rx_buf(jme, i); | 742 | for (i = 0 ; i < jme->rx_ring_size ; ++i) |
743 | jme_free_rx_buf(jme, i); | ||
744 | kfree(rxring->bufinf); | ||
745 | } | ||
725 | 746 | ||
726 | dma_free_coherent(&(jme->pdev->dev), | 747 | dma_free_coherent(&(jme->pdev->dev), |
727 | RX_RING_ALLOC_SIZE(jme->rx_ring_size), | 748 | RX_RING_ALLOC_SIZE(jme->rx_ring_size), |
@@ -731,6 +752,7 @@ jme_free_rx_resources(struct jme_adapter *jme) | |||
731 | rxring->desc = NULL; | 752 | rxring->desc = NULL; |
732 | rxring->dmaalloc = 0; | 753 | rxring->dmaalloc = 0; |
733 | rxring->dma = 0; | 754 | rxring->dma = 0; |
755 | rxring->bufinf = NULL; | ||
734 | } | 756 | } |
735 | rxring->next_to_use = 0; | 757 | rxring->next_to_use = 0; |
736 | atomic_set(&rxring->next_to_clean, 0); | 758 | atomic_set(&rxring->next_to_clean, 0); |
@@ -746,12 +768,8 @@ jme_setup_rx_resources(struct jme_adapter *jme) | |||
746 | RX_RING_ALLOC_SIZE(jme->rx_ring_size), | 768 | RX_RING_ALLOC_SIZE(jme->rx_ring_size), |
747 | &(rxring->dmaalloc), | 769 | &(rxring->dmaalloc), |
748 | GFP_ATOMIC); | 770 | GFP_ATOMIC); |
749 | if (!rxring->alloc) { | 771 | if (!rxring->alloc) |
750 | rxring->desc = NULL; | 772 | goto err_set_null; |
751 | rxring->dmaalloc = 0; | ||
752 | rxring->dma = 0; | ||
753 | return -ENOMEM; | ||
754 | } | ||
755 | 773 | ||
756 | /* | 774 | /* |
757 | * 16 Bytes align | 775 | * 16 Bytes align |
@@ -762,9 +780,16 @@ jme_setup_rx_resources(struct jme_adapter *jme) | |||
762 | rxring->next_to_use = 0; | 780 | rxring->next_to_use = 0; |
763 | atomic_set(&rxring->next_to_clean, 0); | 781 | atomic_set(&rxring->next_to_clean, 0); |
764 | 782 | ||
783 | rxring->bufinf = kmalloc(sizeof(struct jme_buffer_info) * | ||
784 | jme->rx_ring_size, GFP_ATOMIC); | ||
785 | if (unlikely(!(rxring->bufinf))) | ||
786 | goto err_free_rxring; | ||
787 | |||
765 | /* | 788 | /* |
766 | * Initiallize Receive Descriptors | 789 | * Initiallize Receive Descriptors |
767 | */ | 790 | */ |
791 | memset(rxring->bufinf, 0, | ||
792 | sizeof(struct jme_buffer_info) * jme->rx_ring_size); | ||
768 | for (i = 0 ; i < jme->rx_ring_size ; ++i) { | 793 | for (i = 0 ; i < jme->rx_ring_size ; ++i) { |
769 | if (unlikely(jme_make_new_rx_buf(jme, i))) { | 794 | if (unlikely(jme_make_new_rx_buf(jme, i))) { |
770 | jme_free_rx_resources(jme); | 795 | jme_free_rx_resources(jme); |
@@ -775,6 +800,19 @@ jme_setup_rx_resources(struct jme_adapter *jme) | |||
775 | } | 800 | } |
776 | 801 | ||
777 | return 0; | 802 | return 0; |
803 | |||
804 | err_free_rxring: | ||
805 | dma_free_coherent(&(jme->pdev->dev), | ||
806 | RX_RING_ALLOC_SIZE(jme->rx_ring_size), | ||
807 | rxring->alloc, | ||
808 | rxring->dmaalloc); | ||
809 | err_set_null: | ||
810 | rxring->desc = NULL; | ||
811 | rxring->dmaalloc = 0; | ||
812 | rxring->dma = 0; | ||
813 | rxring->bufinf = NULL; | ||
814 | |||
815 | return -ENOMEM; | ||
778 | } | 816 | } |
779 | 817 | ||
780 | static inline void | 818 | static inline void |
diff --git a/drivers/net/jme.h b/drivers/net/jme.h index 0025e68aeb5..9d3cedd394a 100644 --- a/drivers/net/jme.h +++ b/drivers/net/jme.h | |||
@@ -372,7 +372,6 @@ struct jme_buffer_info { | |||
372 | /* | 372 | /* |
373 | * The structure holding buffer information and ring descriptors all together. | 373 | * The structure holding buffer information and ring descriptors all together. |
374 | */ | 374 | */ |
375 | #define MAX_RING_DESC_NR 1024 | ||
376 | struct jme_ring { | 375 | struct jme_ring { |
377 | void *alloc; /* pointer to allocated memory */ | 376 | void *alloc; /* pointer to allocated memory */ |
378 | void *desc; /* pointer to ring memory */ | 377 | void *desc; /* pointer to ring memory */ |
@@ -380,7 +379,7 @@ struct jme_ring { | |||
380 | dma_addr_t dma; /* phys address for ring dma */ | 379 | dma_addr_t dma; /* phys address for ring dma */ |
381 | 380 | ||
382 | /* Buffer information corresponding to each descriptor */ | 381 | /* Buffer information corresponding to each descriptor */ |
383 | struct jme_buffer_info bufinf[MAX_RING_DESC_NR]; | 382 | struct jme_buffer_info *bufinf; |
384 | 383 | ||
385 | int next_to_use; | 384 | int next_to_use; |
386 | atomic_t next_to_clean; | 385 | atomic_t next_to_clean; |