diff --git a/drivers/net/mmnif.c b/drivers/net/mmnif.c index eaddd2d2..4993266d 100644 --- a/drivers/net/mmnif.c +++ b/drivers/net/mmnif.c @@ -49,6 +49,11 @@ extern HANDLE hProc; #include +#include +#include +#include + + #endif #define MMNIF_TX_QUEUELEN 4 @@ -380,7 +385,7 @@ __inline int mmnif_write_rx_pending(uint32_t dest_ip,uint8_t pending) return nr_of_bytes_written; #else - memcpy((char*)mpb_start_address + ( dest_ip -1 ) * mpb_size ,&pending,1); + memcpy((char*)mpb_start_address + ( dest_ip -1 ) * mpb_size ,&queue,1); return 1; #endif @@ -408,7 +413,7 @@ __inline int mmnif_trigger_irq(dest_ip) /**/ value = inportl((void*)irq_address); - if ((!pulse_irq) && (value & RCK_INTR_MASK)) + if (!pulse_irq) && (value & RCK_INTR_MASK)) { value &= (~(RCK_INTR_MASK|RCK_NMI_MASK)); outportl((void*)irq_address,value); @@ -420,7 +425,7 @@ __inline int mmnif_trigger_irq(dest_ip) /**/ if (pulse_irq) { - value &= (~(RCK_INTR_MASK|RCK_NMI_MASK)); + value &= (~(RCK_INTR_MASK|NMI_MASK)); outportl((void*)irq_address,value); } @@ -435,12 +440,9 @@ __inline int mmnif_trigger_irq(dest_ip) __inline int mmnif_device_schedule() { #ifdef WIN32 - bthread_t polling_thread; bthread_create(&polling_thread,NULL,mmnif_poll,NULL); - return NULL; #else - tid_t polling_thread; create_kernel_task(&polling_thread,mmnif_poll,NULL); return NULL; #endif @@ -477,7 +479,7 @@ __inline void* mmnif_shmalloc() mpb_size = sizeof(mm_rx_buffer_t) + MMNIF_RX_QUEUELEN* MMNIF_RX_BUFFERLEN; mpb_start_address = VirtualAlloc((char*)0x41000000 /*+ (mpb_size) * (own_ip_address - router_ip_address)*/, - mpb_size *2,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE); + mpb_size *MMNIF_CORES,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE); return (char*)0x41000000 + (mpb_size) * (own_ip_address - router_ip_address); #else @@ -485,35 +487,48 @@ __inline void* mmnif_shmalloc() /* We choose a arbitrary address first * until i know how to properly allocate shared memory */ - mpb_start_address = 0x8000000+ mpb_size * (own_ip_address - router_ip_address); - return mpb_start_address; + mpb_start_address = RCCE_shmalloc(mpb_size*MMNIF_CORES); + //mpb_start_address = 0x8000000+ mpb_size * (own_ip_address - router_ip_address); + return mpb_start_address + (mpb_size) * (own_ip_address - router_ip_address); #endif } +/* mmnif_lock_rx_hdr(): lock the header of mm_rx_buffer + * so there is no race condition on the variables + */ __inline void mmnif_lock_rx_hdr(int dest_ip) { #ifdef WIN32 mm_rx_buffer_t hdr; + if(disable_locking) return; while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); sem_wait(&hdr.lock); #else + if(disable_locking) return; mm_rx_buffer_t* hdr = (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size; sem_wait(&hdr->lock); #endif } - +/* mmnif_unlock_rx_hdr(): unlock the header + * again + */ __inline void mmnif_unlock_rx_hdr(int dest_ip) { #ifdef WIN32 mm_rx_buffer_t hdr; + if(disable_locking) return; while(!ReadProcessMemory(hProc,(char*)mpb_start_address + ( dest_ip -1 ) * mpb_size,&hdr,sizeof(hdr),NULL)); sem_post(&hdr.lock); #else + if(disable_locking) return; mm_rx_buffer_t* hdr = (char*)mpb_start_address + ( dest_ip -1 ) * mpb_size; sem_post(&hdr->lock); #endif } +/* mmnif_timestamp(): genereate a timestamp for the + * packets + */ __inline int mmnif_timestamp() { #ifdef WIN32 @@ -882,10 +897,11 @@ err_t mmnif_init(struct netif* netif) num++; /* downward functions */ netif->output = mmnif_link_layer; + /* there is no special link layer just the ip layer */ netif->linkoutput = mmnif_tx; /* maximum transfer unit */ netif->mtu = 1500; - /* broadcast capability */ + /* broadcast capability, keep all default flags*/ netif->flags |= NETIF_FLAG_BROADCAST /*| NETIF_FLAG_ETHARP*/ | NETIF_FLAG_LINK_UP; /* hardware address length */ netif->hwaddr_len = 6; @@ -987,10 +1003,10 @@ static void mmnif_rx(struct netif* netif) mmnif->stats.rx_bytes += p->tot_len; - if (no_irq) - mmnif->stats.rx_poll++; - else + if (mmnif->rx_buff->iv_intr) mmnif->stats.rx_intr++; + else + mmnif->stats.rx_poll++; return;