diff --git a/drivers/net/mmnif.c b/drivers/net/mmnif.c index 1abb68fb..de6b1e48 100644 --- a/drivers/net/mmnif.c +++ b/drivers/net/mmnif.c @@ -85,17 +85,11 @@ * regarding the driver & its configuration */ -//#define MMNIF_TX_BUFFERLEN 2048 -//#define MMNIF_TX_QUEUELEN 4 - -#define MMNIF_RX_BUFFERLEN 7*1024 +#define MMNIF_RX_BUFFERLEN 32*1024 #define MMNIF_MAX_DESCRIPTORS 64 #define MMNIF_CORES 2 -#define MMNIF_POLL_BUDGET 0x100000 -#define MMNIF_INTR_BUDGET 0x10 - #define MMNIF_STATUS_FREE 0x00 #define MMNIF_STATUS_PENDING 0x01 #define MMNIF_STATUS_RDY 0x02 @@ -255,12 +249,8 @@ typedef struct mmnif { uint8_t check_in_progress; /* memory interaction variables: - * - transmit queue - * - pointer to transmit buffer * - pointer to recive buffer */ - //uint8_t tx_queue; - //uint8_t *tx_buff[MMNIF_TX_QUEUELEN]; mm_rx_buffer_t *rx_buff; uint8_t *rx_heap; @@ -324,8 +314,7 @@ static void mmnif_print_stats(void) if (!mmnif_dev) { - DEBUGPRINTF - ("mmnif_print_stats(): the device is not initialized yet.\n"); + DEBUGPRINTF("mmnif_print_stats(): the device is not initialized yet.\n"); return; } @@ -600,52 +589,31 @@ static void mmnif_rxbuff_free(void) static err_t mmnif_tx(struct netif *netif, struct pbuf *p) { mmnif_t *mmnif = netif->state; - //uint8_t slot = mmnif->tx_queue; size_t write_address; uint32_t i; struct pbuf *q; /* interator */ uint32_t dest_ip = mmnif_get_destination(netif, p); - //uint8_t chances = 20; - //mm_rx_buffer_t *rb = (mm_rx_buffer_t *) ((char *)header_start_address + (dest_ip - 1) * header_size); + int8_t chances = 20; - //spinlock_lock(&mmnif->lock); - //mmnif->tx_queue++; - //spinlock_unlock(&mmnif->lock); - - /* Perform serveral sanity checks on the packet and the buffers: - * - is the queue full? - * - is the output packet to big? - */ - /*if (mmnif->tx_queue > MMNIF_TX_QUEUELEN) - { - DEBUGPRINTF("mmnif_tx(): too many packets at once for tx_queue\n"); + /* check for over/underflow */ + if (BUILTIN_EXPECT((p->tot_len < 20 /* IP header size */) || (p->tot_len > 1536), 0)) { + DEBUGPRINTF("mmnif_tx: illegal packet length %d => drop\n", p->tot_len); goto drop_packet; - }*/ - - /*if (p->tot_len > MMNIF_TX_BUFFERLEN) - { - DEBUGPRINTF("mmnif_tx(): packet is longer than %d bytes\n", MMNIF_TX_BUFFERLEN); - goto drop_packet; - }*/ + } /* allocate memory for the packet in the remote buffer */ realloc: - write_address = mmnif_rxbuff_alloc(dest_ip, CLINE_ALIGN(p->tot_len)); + write_address = mmnif_rxbuff_alloc(dest_ip, p->tot_len); if (!write_address) { + //DEBUGPRINTF("mmnif_tx(): concurrency"); -// DEBUGPRINTF("mmnif_tx(): concurrency"); + if (chances <= 0) + goto drop_packet; -// if (!chances) -// goto drop_packet; - -// chances--; -// // udelay(exp_delay); -// // exp_delay << 1; -// // reschedule(); -// // NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8; -// udelay(20000); -// mmnif_trigger_irq(dest_ip); + chances--; + //mmnif_trigger_irq(dest_ip); + NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8; goto realloc; } @@ -659,7 +627,6 @@ realloc: #if MMNIF_USE_MPB asm volatile (".byte 0x0f; .byte 0x0a;\n"); - #endif for (q = p, i = 0; q != 0; q = q->next) @@ -673,10 +640,8 @@ realloc: } *((int *)RCCE_fool_write_combine_buffer) = 1; -#if USE_CACHE -#if MMNIF_USE_MPB +#if USE_CACHE || MMNIF_USE_MPB asm volatile (".byte 0x0f; .byte 0x0a;\n"); -#endif #endif if (mmnif_commit_packet(dest_ip, write_address)) { @@ -688,11 +653,6 @@ realloc: // hex_dump(p->tot_len, p->payload); #endif - /* release the tx_queue because it's finished */ - //spinlock_lock(&mmnif->lock); - //mmnif->tx_queue--; - //spinlock_unlock(&mmnif->lock); - /* just gather some stats */ LINK_STATS_INC(link.xmit); mmnif->stats.tx++; @@ -704,13 +664,8 @@ realloc: drop_packet: /* drop packet for one or another reason */ -#ifdef DEBUG_MMNIF DEBUGPRINTF("mmnif_tx(): packet dropped"); -#endif - //spinlock_lock(&mmnif->lock); - //mmnif->tx_queue--; - //spinlock_unlock(&mmnif->lock); LINK_STATS_INC(link.drop); mmnif->stats.tx_err++; @@ -931,9 +886,7 @@ err_t mmnif_init(struct netif *netif) int num = 0; //int tmp1, tmp2, n; -#ifdef DEBUG_MMNIF DEBUGPRINTF("mmnif init attempt\n"); -#endif mmnif_dev = netif; own_ip_address += RCCE_ue() + 1; @@ -1055,20 +1008,6 @@ err_t mmnif_init(struct netif *netif) */ sem_init(&mmnif->com_poll, 0); - /* Alloc and clear internal memory for tx_buff - */ - /*mmnif->tx_buff[0] = kmalloc(MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN); - if (!(mmnif->tx_buff[0])) - { - DEBUGPRINTF("mmnif init: out of memory tx\n"); - return ERR_MEM; - }*/ - //mmnif->tx_queue = 0; - //memset(mmnif->tx_buff[0], 0x00, MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN); - - //for (i=0; itx_buff[i + 1] = mmnif->tx_buff[i] + MMNIF_TX_BUFFERLEN; - for (i=0; ilinkoutput = mmnif_tx; /* maximum transfer unit */ - netif->mtu = 1500; //MMNIF_TX_BUFFERLEN; + netif->mtu = 1500; /* broadcast capability, keep all default flags */ netif->flags |= NETIF_FLAG_BROADCAST; @@ -1118,9 +1057,7 @@ err_t mmnif_init(struct netif *netif) /* hardware address length */ netif->hwaddr_len = 0; -#ifdef DEBUG_MMNIF DEBUGPRINTF("mmnif init complete\n"); -#endif return ERR_OK; } @@ -1201,13 +1138,14 @@ anotherpacket: /* If length is zero return silently */ - if (length == 0) + if (BUILTIN_EXPECT(length == 0, 0)) { DEBUGPRINTF("mmnif_rx(): empty packet error\n"); goto out; } - if (length < sizeof(struct ip_hdr) || length > netif->mtu) + /* check for over/underflow */ + if (BUILTIN_EXPECT((length < 20 /* IP header size */) || (length > 1536), 0)) { DEBUGPRINTF("mmnif_rx(): illegal packet length %d => drop the packet\n", length); goto drop_packet; @@ -1231,7 +1169,7 @@ anotherpacket: goto drop_packet; } -#if USE_CACHE +#if USE_CACHE || MMNIF_USE_MPB asm volatile (".byte 0x0f; .byte 0x0a;\n"); #endif @@ -1273,10 +1211,7 @@ anotherpacket: goto anotherpacket; drop_packet: - spinlock_lock(&mmnif->rx_buff->rlock); - - /*error handling */ - spinlock_unlock(&mmnif->rx_buff->rlock); + /* TODO: error handling */ LINK_STATS_INC(link.drop); mmnif->stats.rx_err++; @@ -1500,10 +1435,8 @@ int mmnif_accept(int s, struct sockaddr *addr, socklen_t * addrlen) spinlock_unlock(&b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].alock); break; } -#ifdef DEBUG_MMNIF DEBUGPRINTF("mmnif_accept(): Timout occoured, switching to normal accept()"); -#endif mmnif_hashdelete(b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].nsock); b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].stat = MMNIF_ACC_STAT_CLOSED; spinlock_unlock(&b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].alock); @@ -1600,11 +1533,8 @@ int mmnif_connect(int s, const struct sockaddr *name, socklen_t namelen) } } -#ifdef DEBUG_MMNIF DEBUGPRINTF("mmnif_connect(): no acceptor found"); -#endif - return -1; } @@ -1681,7 +1611,6 @@ err_t mmnif_shutdown(void) err = netifapi_netif_set_down(mmnif_dev); - //kfree(mmnif->tx_buff[0], MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN); //RCCE_shfree(mpb_start_address); mmnif_dev = NULL;