6767#include <linux/timer.h>
6868#include <linux/interrupt.h>
6969#include <linux/dma-mapping.h>
70+ #include <linux/bitmap.h>
7071#include <linux/slab.h>
7172#include <asm/io.h>
7273#include <asm/byteorder.h>
@@ -778,6 +779,8 @@ he_init_cs_block_rcm(struct he_dev *he_dev)
778779static int __devinit
779780he_init_group (struct he_dev * he_dev , int group )
780781{
782+ struct he_buff * heb , * next ;
783+ dma_addr_t mapping ;
781784 int i ;
782785
783786 he_writel (he_dev , 0x0 , G0_RBPS_S + (group * 32 ));
@@ -786,12 +789,29 @@ he_init_group(struct he_dev *he_dev, int group)
786789 he_writel (he_dev , RBP_THRESH (0x1 ) | RBP_QSIZE (0x0 ),
787790 G0_RBPS_BS + (group * 32 ));
788791
792+ /* bitmap table */
793+ he_dev -> rbpl_table = kmalloc (BITS_TO_LONGS (RBPL_TABLE_SIZE )
794+ * sizeof (unsigned long ), GFP_KERNEL );
795+ if (!he_dev -> rbpl_table ) {
796+ hprintk ("unable to allocate rbpl bitmap table\n" );
797+ return - ENOMEM ;
798+ }
799+ bitmap_zero (he_dev -> rbpl_table , RBPL_TABLE_SIZE );
800+
801+ /* rbpl_virt 64-bit pointers */
802+ he_dev -> rbpl_virt = kmalloc (RBPL_TABLE_SIZE
803+ * sizeof (struct he_buff * ), GFP_KERNEL );
804+ if (!he_dev -> rbpl_virt ) {
805+ hprintk ("unable to allocate rbpl virt table\n" );
806+ goto out_free_rbpl_table ;
807+ }
808+
789809 /* large buffer pool */
790810 he_dev -> rbpl_pool = pci_pool_create ("rbpl" , he_dev -> pci_dev ,
791- CONFIG_RBPL_BUFSIZE , 8 , 0 );
811+ CONFIG_RBPL_BUFSIZE , 64 , 0 );
792812 if (he_dev -> rbpl_pool == NULL ) {
793813 hprintk ("unable to create rbpl pool\n" );
794- return - ENOMEM ;
814+ goto out_free_rbpl_virt ;
795815 }
796816
797817 he_dev -> rbpl_base = pci_alloc_consistent (he_dev -> pci_dev ,
@@ -801,30 +821,29 @@ he_init_group(struct he_dev *he_dev, int group)
801821 goto out_destroy_rbpl_pool ;
802822 }
803823 memset (he_dev -> rbpl_base , 0 , CONFIG_RBPL_SIZE * sizeof (struct he_rbp ));
804- he_dev -> rbpl_virt = kmalloc (CONFIG_RBPL_SIZE * sizeof (struct he_virt ), GFP_KERNEL );
805- if (he_dev -> rbpl_virt == NULL ) {
806- hprintk ("failed to alloc rbpl_virt\n" );
807- goto out_free_rbpl_base ;
808- }
824+
825+ INIT_LIST_HEAD (& he_dev -> rbpl_outstanding );
809826
810827 for (i = 0 ; i < CONFIG_RBPL_SIZE ; ++ i ) {
811- dma_addr_t dma_handle ;
812- void * cpuaddr ;
813828
814- cpuaddr = pci_pool_alloc (he_dev -> rbpl_pool , GFP_KERNEL |GFP_DMA , & dma_handle );
815- if (cpuaddr == NULL )
816- goto out_free_rbpl_virt ;
829+ heb = pci_pool_alloc (he_dev -> rbpl_pool , GFP_KERNEL |GFP_DMA , & mapping );
830+ if (!heb )
831+ goto out_free_rbpl ;
832+ heb -> mapping = mapping ;
833+ list_add (& heb -> entry , & he_dev -> rbpl_outstanding );
817834
818- he_dev -> rbpl_virt [i ].virt = cpuaddr ;
819- he_dev -> rbpl_base [i ].status = RBP_LOANED | (i << RBP_INDEX_OFF );
820- he_dev -> rbpl_base [i ].phys = dma_handle ;
835+ set_bit (i , he_dev -> rbpl_table );
836+ he_dev -> rbpl_virt [i ] = heb ;
837+ he_dev -> rbpl_hint = i + 1 ;
838+ he_dev -> rbpl_base [i ].idx = i << RBP_IDX_OFFSET ;
839+ he_dev -> rbpl_base [i ].phys = mapping + offsetof(struct he_buff , data );
821840 }
822841 he_dev -> rbpl_tail = & he_dev -> rbpl_base [CONFIG_RBPL_SIZE - 1 ];
823842
824843 he_writel (he_dev , he_dev -> rbpl_phys , G0_RBPL_S + (group * 32 ));
825844 he_writel (he_dev , RBPL_MASK (he_dev -> rbpl_tail ),
826845 G0_RBPL_T + (group * 32 ));
827- he_writel (he_dev , CONFIG_RBPL_BUFSIZE /4 ,
846+ he_writel (he_dev , ( CONFIG_RBPL_BUFSIZE - sizeof ( struct he_buff )) /4 ,
828847 G0_RBPL_BS + (group * 32 ));
829848 he_writel (he_dev ,
830849 RBP_THRESH (CONFIG_RBPL_THRESH ) |
@@ -838,7 +857,7 @@ he_init_group(struct he_dev *he_dev, int group)
838857 CONFIG_RBRQ_SIZE * sizeof (struct he_rbrq ), & he_dev -> rbrq_phys );
839858 if (he_dev -> rbrq_base == NULL ) {
840859 hprintk ("failed to allocate rbrq\n" );
841- goto out_free_rbpl_virt ;
860+ goto out_free_rbpl ;
842861 }
843862 memset (he_dev -> rbrq_base , 0 , CONFIG_RBRQ_SIZE * sizeof (struct he_rbrq ));
844863
@@ -879,19 +898,19 @@ he_init_group(struct he_dev *he_dev, int group)
879898 pci_free_consistent (he_dev -> pci_dev , CONFIG_RBRQ_SIZE *
880899 sizeof (struct he_rbrq ), he_dev -> rbrq_base ,
881900 he_dev -> rbrq_phys );
882- i = CONFIG_RBPL_SIZE ;
883- out_free_rbpl_virt :
884- while (i -- )
885- pci_pool_free (he_dev -> rbpl_pool , he_dev -> rbpl_virt [i ].virt ,
886- he_dev -> rbpl_base [i ].phys );
887- kfree (he_dev -> rbpl_virt );
901+ out_free_rbpl :
902+ list_for_each_entry_safe (heb , next , & he_dev -> rbpl_outstanding , entry )
903+ pci_pool_free (he_dev -> rbpl_pool , heb , heb -> mapping );
888904
889- out_free_rbpl_base :
890905 pci_free_consistent (he_dev -> pci_dev , CONFIG_RBPL_SIZE *
891906 sizeof (struct he_rbp ), he_dev -> rbpl_base ,
892907 he_dev -> rbpl_phys );
893908out_destroy_rbpl_pool :
894909 pci_pool_destroy (he_dev -> rbpl_pool );
910+ out_free_rbpl_virt :
911+ kfree (he_dev -> rbpl_virt );
912+ out_free_rbpl_table :
913+ kfree (he_dev -> rbpl_table );
895914
896915 return - ENOMEM ;
897916}
@@ -1522,9 +1541,10 @@ he_start(struct atm_dev *dev)
15221541static void
15231542he_stop (struct he_dev * he_dev )
15241543{
1525- u16 command ;
1526- u32 gen_cntl_0 , reg ;
1544+ struct he_buff * heb , * next ;
15271545 struct pci_dev * pci_dev ;
1546+ u32 gen_cntl_0 , reg ;
1547+ u16 command ;
15281548
15291549 pci_dev = he_dev -> pci_dev ;
15301550
@@ -1565,18 +1585,16 @@ he_stop(struct he_dev *he_dev)
15651585 he_dev -> hsp , he_dev -> hsp_phys );
15661586
15671587 if (he_dev -> rbpl_base ) {
1568- int i ;
1569-
1570- for (i = 0 ; i < CONFIG_RBPL_SIZE ; ++ i ) {
1571- void * cpuaddr = he_dev -> rbpl_virt [i ].virt ;
1572- dma_addr_t dma_handle = he_dev -> rbpl_base [i ].phys ;
1588+ list_for_each_entry_safe (heb , next , & he_dev -> rbpl_outstanding , entry )
1589+ pci_pool_free (he_dev -> rbpl_pool , heb , heb -> mapping );
15731590
1574- pci_pool_free (he_dev -> rbpl_pool , cpuaddr , dma_handle );
1575- }
15761591 pci_free_consistent (he_dev -> pci_dev , CONFIG_RBPL_SIZE
15771592 * sizeof (struct he_rbp ), he_dev -> rbpl_base , he_dev -> rbpl_phys );
15781593 }
15791594
1595+ kfree (he_dev -> rbpl_virt );
1596+ kfree (he_dev -> rbpl_table );
1597+
15801598 if (he_dev -> rbpl_pool )
15811599 pci_pool_destroy (he_dev -> rbpl_pool );
15821600
@@ -1609,13 +1627,13 @@ static struct he_tpd *
16091627__alloc_tpd (struct he_dev * he_dev )
16101628{
16111629 struct he_tpd * tpd ;
1612- dma_addr_t dma_handle ;
1630+ dma_addr_t mapping ;
16131631
1614- tpd = pci_pool_alloc (he_dev -> tpd_pool , GFP_ATOMIC |GFP_DMA , & dma_handle );
1632+ tpd = pci_pool_alloc (he_dev -> tpd_pool , GFP_ATOMIC |GFP_DMA , & mapping );
16151633 if (tpd == NULL )
16161634 return NULL ;
16171635
1618- tpd -> status = TPD_ADDR (dma_handle );
1636+ tpd -> status = TPD_ADDR (mapping );
16191637 tpd -> reserved = 0 ;
16201638 tpd -> iovec [0 ].addr = 0 ; tpd -> iovec [0 ].len = 0 ;
16211639 tpd -> iovec [1 ].addr = 0 ; tpd -> iovec [1 ].len = 0 ;
@@ -1644,13 +1662,12 @@ he_service_rbrq(struct he_dev *he_dev, int group)
16441662 struct he_rbrq * rbrq_tail = (struct he_rbrq * )
16451663 ((unsigned long )he_dev -> rbrq_base |
16461664 he_dev -> hsp -> group [group ].rbrq_tail );
1647- struct he_rbp * rbp = NULL ;
16481665 unsigned cid , lastcid = -1 ;
1649- unsigned buf_len = 0 ;
16501666 struct sk_buff * skb ;
16511667 struct atm_vcc * vcc = NULL ;
16521668 struct he_vcc * he_vcc ;
1653- struct he_iovec * iov ;
1669+ struct he_buff * heb , * next ;
1670+ int i ;
16541671 int pdus_assembled = 0 ;
16551672 int updated = 0 ;
16561673
@@ -1670,41 +1687,35 @@ he_service_rbrq(struct he_dev *he_dev, int group)
16701687 RBRQ_CON_CLOSED (he_dev -> rbrq_head ) ? " CON_CLOSED" : "" ,
16711688 RBRQ_HBUF_ERR (he_dev -> rbrq_head ) ? " HBUF_ERR" : "" );
16721689
1673- rbp = & he_dev -> rbpl_base [RBP_INDEX (RBRQ_ADDR (he_dev -> rbrq_head ))];
1674-
1675- buf_len = RBRQ_BUFLEN (he_dev -> rbrq_head ) * 4 ;
1676- cid = RBRQ_CID (he_dev -> rbrq_head );
1690+ i = RBRQ_ADDR (he_dev -> rbrq_head ) >> RBP_IDX_OFFSET ;
1691+ heb = he_dev -> rbpl_virt [i ];
16771692
1693+ cid = RBRQ_CID (he_dev -> rbrq_head );
16781694 if (cid != lastcid )
16791695 vcc = __find_vcc (he_dev , cid );
16801696 lastcid = cid ;
16811697
1682- if (vcc == NULL ) {
1683- hprintk ("vcc == NULL (cid 0x%x)\n" , cid );
1684- if (!RBRQ_HBUF_ERR (he_dev -> rbrq_head ))
1685- rbp -> status &= ~RBP_LOANED ;
1698+ if (vcc == NULL || (he_vcc = HE_VCC (vcc )) == NULL ) {
1699+ hprintk ("vcc/he_vcc == NULL (cid 0x%x)\n" , cid );
1700+ if (!RBRQ_HBUF_ERR (he_dev -> rbrq_head )) {
1701+ clear_bit (i , he_dev -> rbpl_table );
1702+ list_del (& heb -> entry );
1703+ pci_pool_free (he_dev -> rbpl_pool , heb , heb -> mapping );
1704+ }
16861705
16871706 goto next_rbrq_entry ;
16881707 }
16891708
1690- he_vcc = HE_VCC (vcc );
1691- if (he_vcc == NULL ) {
1692- hprintk ("he_vcc == NULL (cid 0x%x)\n" , cid );
1693- if (!RBRQ_HBUF_ERR (he_dev -> rbrq_head ))
1694- rbp -> status &= ~RBP_LOANED ;
1695- goto next_rbrq_entry ;
1696- }
1697-
16981709 if (RBRQ_HBUF_ERR (he_dev -> rbrq_head )) {
16991710 hprintk ("HBUF_ERR! (cid 0x%x)\n" , cid );
17001711 atomic_inc (& vcc -> stats -> rx_drop );
17011712 goto return_host_buffers ;
17021713 }
17031714
1704- he_vcc -> iov_tail -> iov_base = RBRQ_ADDR (he_dev -> rbrq_head );
1705- he_vcc -> iov_tail -> iov_len = buf_len ;
1706- he_vcc -> pdu_len += buf_len ;
1707- ++ he_vcc -> iov_tail ;
1715+ heb -> len = RBRQ_BUFLEN (he_dev -> rbrq_head ) * 4 ;
1716+ clear_bit ( i , he_dev -> rbpl_table ) ;
1717+ list_move_tail ( & heb -> entry , & he_vcc -> buffers ) ;
1718+ he_vcc -> pdu_len += heb -> len ;
17081719
17091720 if (RBRQ_CON_CLOSED (he_dev -> rbrq_head )) {
17101721 lastcid = -1 ;
@@ -1713,12 +1724,6 @@ he_service_rbrq(struct he_dev *he_dev, int group)
17131724 goto return_host_buffers ;
17141725 }
17151726
1716- #ifdef notdef
1717- if ((he_vcc -> iov_tail - he_vcc -> iov_head ) > HE_MAXIOV ) {
1718- hprintk ("iovec full! cid 0x%x\n" , cid );
1719- goto return_host_buffers ;
1720- }
1721- #endif
17221727 if (!RBRQ_END_PDU (he_dev -> rbrq_head ))
17231728 goto next_rbrq_entry ;
17241729
@@ -1746,9 +1751,8 @@ he_service_rbrq(struct he_dev *he_dev, int group)
17461751
17471752 __net_timestamp (skb );
17481753
1749- for (iov = he_vcc -> iov_head ; iov < he_vcc -> iov_tail ; ++ iov )
1750- memcpy (skb_put (skb , iov -> iov_len ),
1751- he_dev -> rbpl_virt [RBP_INDEX (iov -> iov_base )].virt , iov -> iov_len );
1754+ list_for_each_entry (heb , & he_vcc -> buffers , entry )
1755+ memcpy (skb_put (skb , heb -> len ), & heb -> data , heb -> len );
17521756
17531757 switch (vcc -> qos .aal ) {
17541758 case ATM_AAL0 :
@@ -1788,12 +1792,9 @@ he_service_rbrq(struct he_dev *he_dev, int group)
17881792return_host_buffers :
17891793 ++ pdus_assembled ;
17901794
1791- for (iov = he_vcc -> iov_head ; iov < he_vcc -> iov_tail ; ++ iov ) {
1792- rbp = & he_dev -> rbpl_base [RBP_INDEX (iov -> iov_base )];
1793- rbp -> status &= ~RBP_LOANED ;
1794- }
1795-
1796- he_vcc -> iov_tail = he_vcc -> iov_head ;
1795+ list_for_each_entry_safe (heb , next , & he_vcc -> buffers , entry )
1796+ pci_pool_free (he_dev -> rbpl_pool , heb , heb -> mapping );
1797+ INIT_LIST_HEAD (& he_vcc -> buffers );
17971798 he_vcc -> pdu_len = 0 ;
17981799
17991800next_rbrq_entry :
@@ -1897,23 +1898,43 @@ he_service_tbrq(struct he_dev *he_dev, int group)
18971898static void
18981899he_service_rbpl (struct he_dev * he_dev , int group )
18991900{
1900- struct he_rbp * newtail ;
1901+ struct he_rbp * new_tail ;
19011902 struct he_rbp * rbpl_head ;
1903+ struct he_buff * heb ;
1904+ dma_addr_t mapping ;
1905+ int i ;
19021906 int moved = 0 ;
19031907
19041908 rbpl_head = (struct he_rbp * ) ((unsigned long )he_dev -> rbpl_base |
19051909 RBPL_MASK (he_readl (he_dev , G0_RBPL_S )));
19061910
19071911 for (;;) {
1908- newtail = (struct he_rbp * ) ((unsigned long )he_dev -> rbpl_base |
1912+ new_tail = (struct he_rbp * ) ((unsigned long )he_dev -> rbpl_base |
19091913 RBPL_MASK (he_dev -> rbpl_tail + 1 ));
19101914
19111915 /* table 3.42 -- rbpl_tail should never be set to rbpl_head */
1912- if (( newtail == rbpl_head ) || ( newtail -> status & RBP_LOANED ) )
1916+ if (new_tail == rbpl_head )
19131917 break ;
19141918
1915- newtail -> status |= RBP_LOANED ;
1916- he_dev -> rbpl_tail = newtail ;
1919+ i = find_next_zero_bit (he_dev -> rbpl_table , RBPL_TABLE_SIZE , he_dev -> rbpl_hint );
1920+ if (i > (RBPL_TABLE_SIZE - 1 )) {
1921+ i = find_first_zero_bit (he_dev -> rbpl_table , RBPL_TABLE_SIZE );
1922+ if (i > (RBPL_TABLE_SIZE - 1 ))
1923+ break ;
1924+ }
1925+ he_dev -> rbpl_hint = i + 1 ;
1926+
1927+ heb = pci_pool_alloc (he_dev -> rbpl_pool , GFP_ATOMIC |GFP_DMA , & mapping );
1928+ if (!heb )
1929+ break ;
1930+ heb -> mapping = mapping ;
1931+ list_add (& heb -> entry , & he_dev -> rbpl_outstanding );
1932+ he_dev -> rbpl_virt [i ] = heb ;
1933+ set_bit (i , he_dev -> rbpl_table );
1934+ new_tail -> idx = i << RBP_IDX_OFFSET ;
1935+ new_tail -> phys = mapping + offsetof(struct he_buff , data );
1936+
1937+ he_dev -> rbpl_tail = new_tail ;
19171938 ++ moved ;
19181939 }
19191940
@@ -2137,7 +2158,7 @@ he_open(struct atm_vcc *vcc)
21372158 return - ENOMEM ;
21382159 }
21392160
2140- he_vcc -> iov_tail = he_vcc -> iov_head ;
2161+ INIT_LIST_HEAD ( & he_vcc -> buffers ) ;
21412162 he_vcc -> pdu_len = 0 ;
21422163 he_vcc -> rc_index = -1 ;
21432164
0 commit comments