home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / twindv21.zip / GRACILIS.C next >
C/C++ Source or Header  |  1992-09-07  |  4KB  |  190 lines

  1. /****************************************************************************
  2. *
  3. *            COPYRIGHT 1990,91,92 BY GRACILIS INC.
  4. *
  5. *             623 Palace St.
  6. *             Aurora, Il. 60506
  7. *
  8. *             (708)-801-8800        Office
  9. *             (708)-844-0183        (FAX - Support BBS)
  10. *
  11. * GRACILIS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS 
  12. * SOFTWARE FOR ANY PURPOSE.  
  13. *
  14. * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
  15. * Permission is granted for non-commercial use/distribution only, as long as
  16. * this copyright header is included intact and unaltered.
  17. *
  18. ******************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <dos.h>
  22. #include "global.h"
  23. #include "mbuf.h"
  24. #include "iface.h"
  25. #include "gracilis.h"
  26.  
  27.  
  28. /*
  29.  * Dequeue of Available Buffers - Used with a head pointer and
  30.  * a Counter to dequeue a pre-allocated receive buffer of type "struct mbuf".
  31.  *
  32.  * Use only for LIFO queues!  (i.e. don't need a tail pointer)
  33.  */
  34. struct mbuf *
  35. f_dequeavail(headp, availcount)
  36. struct mbuf **headp;
  37. int16 *availcount;
  38. {
  39.     char    i_state;
  40.     struct mbuf *rx_mbufp;
  41.     
  42.     rx_mbufp = NULLBUF;
  43.  
  44.     i_state = dirps();
  45.  
  46.     rx_mbufp = *headp;
  47.  
  48.     if ( *headp != NULLBUF )
  49.     {
  50.         *headp = rx_mbufp->anext;
  51.         (*availcount)--;
  52.         rx_mbufp->anext = NULLBUF;
  53.     }
  54.  
  55.     restore(i_state);
  56.  
  57.         /* return the mbuf used to receive data */
  58.     return(rx_mbufp);    
  59. }
  60.  
  61.  
  62.  
  63.  
  64. /*
  65.  * Fill a preallocated mbuf queue with a specified number of buffers.
  66.  * Used with a head pointer and a Counter.
  67.  * THIS IS USED by PackeTen and PackeTwin
  68.  * drivers to maintain their receive frame queues.
  69.  *
  70.  */
  71. void
  72. f_getavail(headp, getcount, bufsize, rxavailcount, ifacep, dma_flg)
  73. struct mbuf **headp;            /* address of headq */
  74. int16 getcount;                    /* number of mbufs to get */
  75. int16 bufsize;                    /* size of data buffer */
  76. int16 *rxavailcount;            /* headq's avail counter */
  77. struct iface *ifacep;            /* device's iface control structure's */
  78.                     /* address */
  79. bool    dma_flg;
  80. {
  81.     char    i_state;
  82.     struct mbuf *rx_mbufp;
  83.     int16    gotcount = 0;    
  84.     struct mbuf *badlist,*srchptr;    /* discard list */
  85.     ulong realaddr;
  86.     unsigned page,alloc_size;
  87.  
  88. #ifdef OLD_KA9Q
  89.     struct phdr *hdr;
  90. #endif
  91.  
  92.  
  93.     badlist = NULLBUF;    /* init list to null */
  94.  
  95.     while ( (getcount > 0) )
  96.     {
  97. #ifdef OLD_KA9Q
  98.         alloc_size = bufsize + sizeof(struct phdr);
  99. #else
  100.         alloc_size = bufsize;
  101. #endif
  102.         rx_mbufp = alloc_mbuf(alloc_size);
  103.  
  104.         /* If we are being asked for dma-able buffers, then check */
  105.         if( dma_flg == TRUE )
  106.         {
  107.             /* A rendition of an absolute address for the ptr */
  108.             realaddr = ((ulong)FP_SEG(rx_mbufp) << 4) + 
  109.                         (ulong)FP_OFF(rx_mbufp);
  110.  
  111.             /* DMA page reg for 8237 */
  112.             page = realaddr >> 16;
  113.             if(((realaddr + alloc_size) >> 16) != page)
  114.             {
  115.                 rx_mbufp->next = NULL;
  116.  
  117.                 /* put this buffer on a list to be free'd */
  118.  
  119.                 if(badlist == NULLBUF)badlist = rx_mbufp;
  120.                 else 
  121.                 {
  122.                     /* find the end of the list */
  123.                     srchptr = badlist;
  124.                     while(srchptr->next != NULLBUF)
  125.                             srchptr = srchptr->next;
  126.                     /* put this one on the end */
  127.                     srchptr->next = rx_mbufp;
  128.                 }
  129.  
  130.                 /* cause the loop to try again */
  131.                 rx_mbufp = NULLBUF;
  132.  
  133.                 pwait(NULL);     /* be nice to others... */
  134.             }
  135.  
  136.         }
  137.  
  138.         if(rx_mbufp != NULLBUF )
  139.         {
  140.             /* setup the packet header for the DRIVER */
  141.             /* calling this routine */
  142.  
  143. #ifdef OLD_KA9Q
  144.             /* init to packet header's byte count */
  145.             rx_mbufp->cnt = sizeof(struct phdr);
  146.             hdr = (struct phdr *)rx_mbufp->data;
  147.             hdr->type = ifacep->type;
  148.             hdr->iface = ifacep;
  149.  
  150.  
  151.             /* Rx data goes in after packet header  */
  152.             /* works because data is a char pointer */
  153.             rx_mbufp->data += sizeof(struct phdr);
  154. #endif
  155.  
  156.             i_state = dirps();
  157.  
  158.             if ( *headp != NULLBUF )
  159.             {
  160.                 rx_mbufp->anext = *headp;
  161.                 *headp = rx_mbufp;
  162.             }
  163.             else
  164.             {
  165.                 *headp = rx_mbufp;
  166.  
  167.                 /* done in alloc_mbuf() */
  168.                 /* rx_mbufp->anext = NULLBUF; */
  169.             }
  170.             (*rxavailcount)++;
  171.             restore(i_state);
  172.         
  173.             getcount--;
  174.  
  175.             gotcount++;
  176.         }
  177.  
  178.     }
  179.     /* All done... now free any accumulated non-dma_able buffers */
  180.     if(badlist != NULLBUF)free_p(badlist);
  181.  
  182.     return;
  183. }
  184.  
  185.  
  186.  
  187.  
  188.  
  189.