/* * File: nbuf.c * Purpose: Implementation of network buffer scheme. * * Notes: */ #include "src/include/dbug.h" #include "src/uif/net/queue.h" #include "src/uif/net/net.h" #ifdef DBUG_NETWORK /********************************************************************/ /* * Queues used for network buffer storage */ QUEUE nbuf_queue[NBUF_MAXQ]; /* * Some devices require line-aligned buffers. In order to accomplish * this, the nbuf data is over-allocated and adjusted. The following * array keeps track of the original data pointer returned by malloc */ ADDRESS unaligned_buffers[NBUF_MAX]; /********************************************************************/ /* * Initialize all the network buffer queues * * Return Value: * 0 success * 1 failure */ int nbuf_init(void) { int i; NBUF *nbuf; for (i=0; idata = (uint8 *)((uint32)(unaligned_buffers[i] + 15) & 0xFFFFFFF0); if (!nbuf->data) { ASSERT(nbuf->data); return 1; } /* Initialize the network buffer */ nbuf->offset = 0; nbuf->length = 0; /* Add the network buffer to the free list */ queue_add(&nbuf_queue[NBUF_FREE], (QNODE *)nbuf); } #ifdef DEBUG_PRINT printf("NBUF allocation complete\n"); nbuf_debug_dump(); #endif return 0; } /********************************************************************/ /* * Return all the allocated memory to the heap */ void nbuf_flush(void) { NBUF *nbuf; int i, level = asm_set_ipl(7); int n = 0; for (i=0; ioffset = 0; nbuf->length = NBUF_SZ; queue_add(&nbuf_queue[NBUF_FREE],(QNODE *)nbuf); asm_set_ipl(level); } /********************************************************************/ /* * Remove a network buffer from the specified queue * * Parameters: * q The index that identifies the queue to pull the buffer from */ NBUF * nbuf_remove(int q) { NBUF *nbuf; int level = asm_set_ipl(7); nbuf = (NBUF *)queue_remove(&nbuf_queue[q]); asm_set_ipl(level); return nbuf; } /********************************************************************/ /* * Add a network buffer to the specified queue * * Parameters: * q The index that identifies the queue to add the buffer to */ void nbuf_add(int q, NBUF *nbuf) { int level = asm_set_ipl(7); queue_add(&nbuf_queue[q],(QNODE *)nbuf); asm_set_ipl(level); } /********************************************************************/ /* * Put all the network buffers back into the free list */ void nbuf_reset(void) { NBUF *nbuf; int i, level = asm_set_ipl(7); for (i=1; idata, nbuf->offset, nbuf->length); nbuf = (NBUF *)nbuf->node.next; } } asm_set_ipl(level); #endif } /********************************************************************/ #endif /* #ifdef DBUG_NETWORK */