home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / GRACILIS.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  5KB  |  184 lines

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