/* * File: fecbd.c * Purpose: Provide a simple buffer management driver * * Notes: */ #include #include #include #include #include #include #include #include #define ASSERT(x) if (!(x)) hang(); /* * This implements a simple static buffer descriptor * ring for each channel and each direction * * FEC Buffer Descriptors need to be aligned to a 4-byte boundary. * In order to accomplish this, data is over-allocated and manually * aligned at runtime * * Enough space is allocated for each of the two FEC channels to have * NRXBD Rx BDs and NTXBD Tx BDs * */ FECBD unaligned_bds[(2 * NRXBD) + (2 * NTXBD) + 1]; /* * These pointers are used to reference into the chunck of data set * aside for buffer descriptors */ FECBD *RxBD; FECBD *TxBD; /* * Macros to easier access to the BD ring */ #define RxBD(ch,i) RxBD[(ch * NRXBD) + i] #define TxBD(ch,i) TxBD[(ch * NTXBD) + i] /* * Buffer descriptor indexes */ static int iTxbd_new; static int iTxbd_old; static int iRxbd; /* * Initialize the FEC Buffer Descriptor ring * Buffer Descriptor format is defined by the MCDAPI * * Parameters: * ch FEC channel */ void fecbd_init(uint8_t ch) { NBUF *nbuf; int i; /* * Align Buffer Descriptors to 4-byte boundary */ RxBD = (FECBD *)(((int)unaligned_bds + 3) & 0xFFFFFFFC); TxBD = (FECBD *)((int)RxBD + (sizeof(FECBD) * 2 * NRXBD)); /* * Initialize the Rx Buffer Descriptor ring */ for (i = 0; i < NRXBD; ++i) { /* Grab a network buffer from the free list */ nbuf = nbuf_alloc(); ASSERT(nbuf); /* Initialize the BD */ RxBD(ch,i).status = RX_BD_E | RX_BD_INTERRUPT; RxBD(ch,i).length = RX_BUF_SZ; RxBD(ch,i).data = nbuf->data; /* Add the network buffer to the Rx queue */ nbuf_add(NBUF_RX_RING, nbuf); } /* * Set the WRAP bit on the last one */ RxBD(ch,i-1).status |= RX_BD_W; /* * Initialize the Tx Buffer Descriptor ring */ for (i = 0; i < NTXBD; ++i) { TxBD(ch,i).status = TX_BD_INTERRUPT; TxBD(ch,i).length = 0; TxBD(ch,i).data = NULL; } /* * Set the WRAP bit on the last one */ TxBD(ch,i-1).status |= TX_BD_W; /* * Initialize the buffer descriptor indexes */ iTxbd_new = iTxbd_old = iRxbd = 0; } void fecbd_dump(uint8_t ch) { #ifdef CONFIG_DRIVER_NET_MCF54XX_DEBUG int i; printf("\n------------ FEC%d BDs -----------\n",ch); printf("RxBD Ring\n"); for (i=0; i