cosmetic changes

This commit is contained in:
Stefan Lankes 2011-10-03 23:59:52 -07:00
parent fbb0b9237b
commit f2a3930046
2 changed files with 77 additions and 199 deletions

View file

@ -51,7 +51,7 @@
#define TRUE 1
#define FALSE 0
#define DEBUGPRINTF(x,...) kprintf(x,##__VA_ARGS__)
#define DEBUGPRINTF(x,...) LWIP_DEBUGF(NETIF_DEBUG, (x, ##__VA_ARGS__))
#define DEBUG_MMNIF
//#define DEBUG_MMNIF_PACKET
@ -71,7 +71,7 @@
#define MMNIF_AUTO_SOCKET_TIMEOUT 500
#define MMNIF_FAST_SOCKET_BLOCK 0
#define MMNIF_FAST_SOCKET_BLOCK 1
#ifdef DEBUG_MMNIF
#include "util.h" /* hex dump */
@ -112,14 +112,6 @@
static int npseudosocket = MMNIF_PSEUDO_SOCKET_START;
static spinlock_t pseudolock;
/* decide whether it's polling mode or not
*/
static int reduce_irq = 0;
/* this will be set by open() and close() and shows wether the driver is running or not
*/
static int active = 0;
/* IP address of the local core and the router core to get packets forwarded
*/
static unsigned int own_ip_address = 0xC0A80000; /* 192.168.0.0 */
@ -140,13 +132,9 @@ static unsigned int heap_size = 0;
*/
static struct netif* mmnif_dev = NULL;
/* thread variables */
static tid_t polling_thread;
/* accept struct
*/
typedef struct acceptor {
/* stat: status of the acceptor
* src_ip: where did the connect request came from
* port: port on which the acceptor is listening
@ -165,7 +153,6 @@ typedef struct acceptor {
/* bypass descriptor struct
*/
typedef struct bypass_rxdesc {
/* socket : hashtarget
* remote_socket: socket on the remote end
* cnt : atomic counter for the recv function
@ -182,7 +169,6 @@ typedef struct bypass_rxdesc {
*/
static bypass_rxdesc_t mmnif_hashtable[MMNIF_HASHTABLE_SIZE];
typedef struct mmnif_device_stats {
/* device stats (granularity in packets):
* - recieve errors
* - recieve successes
@ -201,18 +187,13 @@ typedef struct mmnif_device_stats {
/* Heuristics :
* - how many times an budget overflow occured
* - how many times the polling thread polled without recieving a new message
* - how many messages are recieved via interrupt
* - how many messages are recieved via the polling thread
*/
unsigned int bdg_overflow;
unsigned int pll_empty;
unsigned int rx_intr;
unsigned int rx_poll;
} mmnif_device_stats_t;
/* receive descror structure */
typedef struct rx_desc {
/* stat : status of the descriptor
* len : length of the packet
* addr : memory address of the packet
@ -227,13 +208,6 @@ typedef struct rx_desc {
/* receive ring buffer structure */
typedef struct mm_rx_buffer {
/* iv_intr: inform via interrupt
* states whether the interface wants to recieve an interrupt for
* incoming packet
*/
uint16_t iv_intr;
/* memory "pseudo-ring/heap"
* packets are always in one single chunk of memory
* head : head of allocated memory region
@ -273,6 +247,9 @@ typedef struct mmnif {
struct eth_addr *ethaddr;
uint32_t ipaddr;
// checks the TCPIP thread already the rx buffers?
uint8_t check_in_progress;
/* memory interaction variables:
* - transmit queue
* - pointer to transmit buffer
@ -296,16 +273,6 @@ typedef struct mmnif {
* memory maped interface helper functions
*/
/* mmnif_device_schedule() :
* if there is no interupt used to indicate new packets
* this creates a polling thread which looks for data
* itself
*/
inline static int mmnif_device_schedule(void)
{
return create_kernel_task(&polling_thread, mmnif_poll, NULL, NORMAL_PRIO);
}
/* trigger an interrupt on the remote processor
* so he knows there is a packet to read
*/
@ -350,18 +317,18 @@ static mmnif_device_stats_t mmnif_get_device_stats(void)
static void mmnif_print_stats(void)
{
mmnif_t *mmnif;
if (!mmnif_dev)
{
DEBUGPRINTF
("mmnif_print_stats(): the device is not initialized yet.\n");
return;
}
mmnif = (mmnif_t *) mmnif_dev->state;
DEBUGPRINTF("/dev/mmnif - stats:\n");
DEBUGPRINTF("Received: %d packets successfull\n", mmnif->stats.rx);
DEBUGPRINTF("Received: %d bytes\n", mmnif->stats.rx_bytes);
DEBUGPRINTF("interrupts: %d\n", mmnif->stats.rx_intr);
DEBUGPRINTF("polling: %d\n", mmnif->stats.rx_poll);
DEBUGPRINTF("Received: %d packets containuing errors\n", mmnif->stats.rx_err);
DEBUGPRINTF("Transmitted: %d packests successfull\n", mmnif->stats.tx);
DEBUGPRINTF("Transmitted: %d bytes\n", mmnif->stats.tx_bytes);
@ -375,17 +342,20 @@ void mmnif_print_driver_status(void)
{
mmnif_t *mmnif;
int i;
if (!mmnif_dev)
{
DEBUGPRINTF("mmnif_print_driver_status(): the device is not initialized yet.\n");
return;
}
mmnif = (mmnif_t *) mmnif_dev->state;
DEBUGPRINTF("/dev/mmnif driver status: \n\n");
DEBUGPRINTF("rx_buf: 0xp\n", mmnif->rx_buff);
DEBUGPRINTF("free descriptors : %d\n\n", mmnif->rx_buff->dcount);
DEBUGPRINTF("descriptor table: (only print descriptors in use)\n");
DEBUGPRINTF("status\taddr\tsize\n");
for (i = 0; i < MMNIF_MAX_DESCRIPTORS; i++)
{
if (mmnif->rx_buff->desc_table[i].stat != 0)
@ -394,7 +364,7 @@ void mmnif_print_driver_status(void)
mmnif->rx_buff->desc_table[i].addr,
mmnif->rx_buff->desc_table[i].len);
}
DEBUGPRINTF("\n\nretrive via interrupt : %d\n", mmnif->rx_buff->iv_intr);
DEBUGPRINTF("ring heap start addr: %p\n", mmnif->rx_buff + sizeof(mm_rx_buffer_t));
DEBUGPRINTF("head: 0x%X\ttail: 0x%X\n", mmnif->rx_buff->head, mmnif->rx_buff->tail);
mmnif_print_stats();
@ -633,7 +603,7 @@ static err_t mmnif_tx(struct netif *netif, struct pbuf *p)
uint8_t build_buff = TRUE;
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);
//mm_rx_buffer_t *rb = (mm_rx_buffer_t *) ((char *)header_start_address + (dest_ip - 1) * header_size);
spinlock_lock(&mmnif->lock);
mmnif->tx_queue++;
@ -651,7 +621,7 @@ static err_t mmnif_tx(struct netif *netif, struct pbuf *p)
if (p->tot_len > MMNIF_TX_BUFFERLEN)
{
DEBUGPRINTF("mmnif_tx(): packet is longer than %d bytes\n",MMNIF_TX_BUFFERLEN);
DEBUGPRINTF("mmnif_tx(): packet is longer than %d bytes\n", MMNIF_TX_BUFFERLEN);
goto drop_packet;
}
@ -713,15 +683,12 @@ realloc:
memcpy_put(write_address, mmnif->tx_buff[slot], CLINE_ALIGN(p->tot_len));
#else
memcpy((void*)write_address, mmnif->tx_buff[slot], CLINE_ALIGN(p->tot_len));
#endif
else
#if MMNIF_USE_MPB
memcpy_put(write_address, p->payload, CLINE_ALIGN(p->tot_len));
#else
memcpy((void*)write_address, p->payload, CLINE_ALIGN(p->tot_len));
#endif
*((int *)RCCE_fool_write_combine_buffer) = 1;
@ -734,6 +701,7 @@ realloc:
{
DEBUGPRINTF("mmnif_tx(): packet somehow lost during commit\n");
}
#ifdef DEBUG_MMNIF_PACKET
// DEBUGPRINTF("\n SEND %p with length: %d\n",(char*)heap_start_address + (dest_ip -1)*mpb_size + pos * 1792,p->tot_len +2);
// hex_dump(p->tot_len, p->payload);
@ -748,8 +716,7 @@ realloc:
LINK_STATS_INC(link.xmit);
mmnif->stats.tx++;
mmnif->stats.tx_bytes += p->tot_len;
if (rb->iv_intr)
mmnif_trigger_irq(dest_ip);
mmnif_trigger_irq(dest_ip);
return ERR_OK;
@ -758,8 +725,8 @@ drop_packet:
*/
#ifdef DEBUG_MMNIF
DEBUGPRINTF("mmnif_tx(): packet dropped");
#endif
#endif /* */
spinlock_lock(&mmnif->lock);
mmnif->tx_queue--;
spinlock_unlock(&mmnif->lock);
@ -783,6 +750,7 @@ static bypass_rxdesc_t *mmnif_hashlookup(int s)
return p;
p = &mmnif_hashtable[(s + i + 1) % MMNIF_HASHTABLE_SIZE];
}
return 0;
}
@ -793,9 +761,11 @@ static int mmnif_hashadd(int sock, int rsock, uint8_t dest_ip)
{
bypass_rxdesc_t *p;
int i;
p = mmnif_hashlookup(sock);
if (p != 0)
return -1;
for (i = 0; i < MMNIF_HASHTABLE_SIZE; i++)
{
p = &mmnif_hashtable[(sock + i) % MMNIF_HASHTABLE_SIZE];
@ -807,6 +777,7 @@ static int mmnif_hashadd(int sock, int rsock, uint8_t dest_ip)
return 0;
}
}
return -1;
}
@ -833,6 +804,7 @@ static int mmnif_hashdelete(int sock)
return 0;
}
}
return -1;
}
@ -845,7 +817,7 @@ static err_t mmnif_tx_bypass(struct netif * netif, void *pbuff, uint16_t size, i
uint32_t write_address;
bypass_rxdesc_t *dest = mmnif_hashlookup(s);
//uint32_t exp_delay = 2;
mm_rx_buffer_t *rb = (mm_rx_buffer_t *) ((char *)header_start_address + (dest->dest_ip - 1) * header_size);
//mm_rx_buffer_t *rb = (mm_rx_buffer_t *) ((char *)header_start_address + (dest->dest_ip - 1) * header_size);
/* Perform serveral sanity checks on the packet and the buffers:
* - is the output packet to big?
@ -912,10 +884,10 @@ realloc:
LINK_STATS_INC(link.xmit);
mmnif->stats.tx++;
mmnif->stats.tx_bytes += size;
if (rb->iv_intr)
mmnif_trigger_irq(dest->dest_ip);
mmnif_trigger_irq(dest->dest_ip);
return ERR_OK;
//drop_packet:
drop_packet:
/* drop packet for one or another reason
*/
LINK_STATS_INC(link.drop);
@ -976,11 +948,10 @@ err_t mmnif_init(struct netif *netif)
mmnif_t *mmnif;
uint32_t i;
int num = 0;
int tmp1, tmp2, n;
//int tmp1, tmp2, n;
#ifdef DEBUG_MMNIF
DEBUGPRINTF("mmnif init attempt\n");
#endif
mmnif_dev = netif;
@ -994,7 +965,7 @@ err_t mmnif_init(struct netif *netif)
DEBUGPRINTF("mmnif init():out of memory\n");
return ERR_MEM;
}
memset(mmnif, 0, sizeof(mmnif_t));
memset(mmnif, 0x00, sizeof(mmnif_t));
/* Alloc and clear shared memory for rx_buff
*/
@ -1032,7 +1003,6 @@ err_t mmnif_init(struct netif *netif)
#else
heap_start_address = (void*) RCCE_shmalloc(heap_size * MMNIF_CORES);
n = (int) heap_start_address;
DEBUGPRINTF("RCCE_shmalloc : %p\n", header_start_address);
// map physical address in the virtual address space
@ -1048,8 +1018,7 @@ err_t mmnif_init(struct netif *netif)
#if MMNIF_USE_MPB
mmnif->rx_heap = heap_start_address;
heap_start_address =
heap_start_address - (own_ip_address - router_ip_address) * 0x2000;
heap_start_address = heap_start_address - (own_ip_address - router_ip_address) * 0x2000;
DEBUGPRINTF("heap_start_address : %p\n", heap_start_address);
// heap_start_address = 0xC0000000;
@ -1063,14 +1032,15 @@ err_t mmnif_init(struct netif *netif)
DEBUGPRINTF("mmnif init(): allocating shared memory failed\n");
return ERR_MEM;
}
memset(mmnif->rx_buff, 0, header_size);
memset(mmnif->rx_heap, 0, heap_size);
memset(mmnif->rx_buff, 0x00, header_size);
memset(mmnif->rx_heap, 0x00, heap_size);
*((int *)RCCE_fool_write_combine_buffer) = 1;
#if USE_CACHE
asm volatile (".byte 0x0f; .byte 0x0a;\n");
#endif
#if 0
if (own_ip_address == router_ip_address)
{
kprintf("Test0: MEMCPY 2048B");
@ -1087,6 +1057,7 @@ err_t mmnif_init(struct netif *netif)
} tmp2 = get_clock_tick();
kprintf("memcpy'd' %d bytes in %d ticks\n", n * 2048, (tmp2 - tmp1));
}
#endif
/* set initial values
*/
@ -1103,11 +1074,6 @@ err_t mmnif_init(struct netif *netif)
*/
sem_init(&mmnif->com_poll, 0);
/* inform via interrupt should be the dafault
*/
if (!reduce_irq)
mmnif->rx_buff->iv_intr = TRUE;
/* Alloc and clear internal memory for tx_buff
*/
mmnif->tx_buff[0] = kmalloc(MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN);
@ -1117,7 +1083,7 @@ err_t mmnif_init(struct netif *netif)
return ERR_MEM;
}
mmnif->tx_queue = 0;
memset(mmnif->tx_buff[0], 0, MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN);
memset(mmnif->tx_buff[0], 0x00, MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN);
for (i=0; i<MMNIF_TX_QUEUELEN-1; i++)
mmnif->tx_buff[i + 1] = mmnif->tx_buff[i] + MMNIF_TX_BUFFERLEN;
@ -1171,15 +1137,6 @@ err_t mmnif_init(struct netif *netif)
/* hardware address length */
netif->hwaddr_len = 0;
/* indicate that the driver is active now */
active = TRUE;
/* If interrupts are not used we immediately add the polling function
* to the queue which would otherwise be done through the IRQ handler.
*/
if (reduce_irq)
mmnif_device_schedule();
#ifdef DEBUG_MMNIF
DEBUGPRINTF("mmnif init complete\n");
#endif
@ -1195,15 +1152,16 @@ static void mmnif_rx(struct netif *netif)
mmnif_t *mmnif = netif->state;
mm_rx_buffer_t *b = mmnif->rx_buff;
uint16_t length = 0;
struct pbuf *p = NULL;
struct pbuf *p;
struct pbuf *q;
char *packet = NULL;
uint32_t i, j;
uint8_t rdesc = 0xFF;
uint8_t rdesc;
err_t err = ERR_OK;
bypass_rxdesc_t *bp;
anotherpacket:
rdesc = 0xFF;
spinlock_lock(&b->rlock);
/* check if this call to mmnif_rx makes any sense
@ -1211,53 +1169,46 @@ anotherpacket:
if (b->desc_table[b->dread].stat == MMNIF_STATUS_FREE)
{
spinlock_unlock(&b->rlock);
return;
goto out;
}
/* search the packet whose transmission is finished
*/
for (i = 0, j = b->dread; i < MMNIF_MAX_DESCRIPTORS; i++)
{
if (b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].stat ==
MMNIF_STATUS_RDY)
if (b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].stat == MMNIF_STATUS_RDY)
{
rdesc = (j + i) % MMNIF_MAX_DESCRIPTORS;
if (b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].
fast_sock == -1)
if (b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].fast_sock == -1)
{
b->desc_table[rdesc].stat = MMNIF_STATUS_INPROC;
packet = (char *)b->desc_table[rdesc].addr;
length = b->desc_table[rdesc].len;
break;
} else {
bp = mmnif_hashlookup(b->desc_table[rdesc].
fast_sock);
bp = mmnif_hashlookup(b->desc_table[rdesc].fast_sock);
if (!bp)
{
DEBUGPRINTF
("mmnif_rx(): no fast socket associated with %d",
b->desc_table[rdesc].fast_sock);
DEBUGPRINTF("mmnif_rx(): no fast socket associated with %d", b->desc_table[rdesc].fast_sock);
mmnif->rx_buff->desc_table[rdesc].stat = MMNIF_STATUS_PROC;
mmnif_rxbuff_free();
} else {
b->desc_table[rdesc].stat = MMNIF_STATUS_INPROC;
#if MMNIF_FAST_SOCKET_BLOCK
sem_post(&bp->sem);
#else
atomic_int32_inc(&bp->cnt);
#endif
}
spinlock_unlock(&b->rlock);
return;
goto out;
}
}
if (b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].stat == MMNIF_STATUS_FREE)
{
spinlock_unlock(&b->rlock);
return;
goto out;
}
}
spinlock_unlock(&b->rlock);
@ -1265,15 +1216,16 @@ anotherpacket:
/* if there is no packet finished we encountered a random error
*/
if (rdesc == 0xFF)
return;
goto out;
/* If length is zero return silently
*/
if (length == 0)
{
DEBUGPRINTF("mmnif_rx(): empty packet error\n");
return;
goto out;
}
if (length < sizeof(struct ip_hdr) || length > netif->mtu)
{
DEBUGPRINTF("mmnif_rx(): illegal packet length %d => drop the packet\n", length);
@ -1283,11 +1235,9 @@ anotherpacket:
/* From now on there is a real packet and it
* has to be worked on
*/
#ifdef DEBUG_MMNIF_PACKET
DEBUGPRINTF("\n RECIEVED - %p with legth: %d\n", packet, length);
hex_dump(length, packet);
#endif
/* Build the pbuf for the packet so the lwip
@ -1299,6 +1249,7 @@ anotherpacket:
DEBUGPRINTF("mmnif_rx(): low on mem - packet dropped\n");
goto drop_packet;
}
#if USE_CACHE
asm volatile (".byte 0x0f; .byte 0x0a;\n");
#endif
@ -1306,7 +1257,6 @@ anotherpacket:
/* copy packet to pbuf structure going through linked list */
for (q = p, i = 0; q != NULL; q = q->next)
{
#if MMNIF_USE_MPB
memcpy_get((uint8_t *) q->payload, &packet[i], q->len);
#else
@ -1325,8 +1275,11 @@ anotherpacket:
*/
mmnif_rxbuff_free();
/* full packet send to tcpip_thread to process */
if ((err = mmnif_dev->input(p, mmnif_dev)) != ERR_OK)
/*
* This function is called in the context of the tcpip thread.
* Therefore, we are able to call directly the input functions.
*/
if ((err = ip_input(p, mmnif_dev)) != ERR_OK)
{
DEBUGPRINTF("mmnif_rx: IP input error\n");
pbuf_free(p);
@ -1336,13 +1289,7 @@ anotherpacket:
LINK_STATS_INC(link.xmit);
mmnif->stats.rx++;
mmnif->stats.rx_bytes += p->tot_len;
if (mmnif->rx_buff->iv_intr)
mmnif->stats.rx_intr++;
else
mmnif->stats.rx_poll++;
goto anotherpacket;
return;
drop_packet:
spinlock_lock(&mmnif->rx_buff->rlock);
@ -1352,6 +1299,8 @@ drop_packet:
LINK_STATS_INC(link.drop);
mmnif->stats.rx_err++;
out:
mmnif->check_in_progress = 0;
return;
}
@ -1382,10 +1331,8 @@ static int mmnif_rx_bypass(struct netif *netif, int s, void *data, uint32_t len)
*/
for (i = 0, j = b->dread; i < MMNIF_MAX_DESCRIPTORS; i++)
{
if (b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].stat ==
MMNIF_STATUS_INPROC
&& b->desc_table[(j + i) %
MMNIF_MAX_DESCRIPTORS].fast_sock != -1)
if (b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].stat == MMNIF_STATUS_INPROC
&& b->desc_table[(j + i) % MMNIF_MAX_DESCRIPTORS].fast_sock != -1)
{
rdesc = (j + i) % MMNIF_MAX_DESCRIPTORS;
packet = (char *)b->desc_table[rdesc].addr;
@ -1441,11 +1388,7 @@ static int mmnif_rx_bypass(struct netif *netif, int s, void *data, uint32_t len)
LINK_STATS_INC(link.xmit);
mmnif->stats.rx++;
mmnif->stats.rx_bytes += length;
if (mmnif->rx_buff->iv_intr)
mmnif->stats.rx_intr++;
else
mmnif->stats.rx_poll++;
return length;
drop_packet:
@ -1466,12 +1409,12 @@ int mmnif_recv(int s, void *data, uint32_t len, int flags)
{
bypass_rxdesc_t *p = mmnif_hashlookup(s);
int ret;
if (p == 0)
return lwip_recv(s, data, len, flags);
#if MMNIF_FAST_SOCKET_BLOCK
sem_wait(&p->sem, 0);
#else
while (!atomic_int32_read(&p->cnt))
{
@ -1480,7 +1423,8 @@ int mmnif_recv(int s, void *data, uint32_t len, int flags)
NOP8;
}
#endif /* */
#endif
ret = mmnif_rx_bypass(mmnif_dev, s, data, len);
atomic_int32_dec(&p->cnt);
@ -1521,8 +1465,7 @@ int mmnif_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
{
for (i = 0; i < MMNIF_MAX_ACCEPTORS; i++)
{
if (b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].
stat == MMNIF_ACC_STAT_CLOSED)
if (b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].stat == MMNIF_ACC_STAT_CLOSED)
{
spinlock_lock(&b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].alock);
b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].port = port;
@ -1532,8 +1475,10 @@ int mmnif_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].nsock = npseudosocket++;
spinlock_unlock(&pseudolock);
spinlock_unlock(&b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].alock);
while (b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].stat != MMNIF_ACC_STAT_ACCEPT_ME)
NOP8;
p = mmnif_hashlookup(b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].nsock);
p->dest_ip = b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].src_ip;
p->remote_socket = b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].rsock;
@ -1541,6 +1486,7 @@ int mmnif_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].stat = MMNIF_ACC_STAT_ACCEPTED;
i = b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].nsock;
spinlock_unlock(&b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].alock);
return i;
}
}
@ -1561,6 +1507,7 @@ int mmnif_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].nsock = npseudosocket++;
spinlock_unlock(&pseudolock);
spinlock_unlock(&b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].alock);
while (b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].stat != MMNIF_ACC_STAT_ACCEPT_ME)
{
tmp2 = get_clock_tick();
@ -1583,6 +1530,7 @@ int mmnif_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
}
NOP8;
}
p = mmnif_hashlookup(b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].nsock);
p->dest_ip = b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].src_ip;
p->remote_socket = b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].rsock;
@ -1590,6 +1538,7 @@ int mmnif_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].stat = MMNIF_ACC_STAT_ACCEPTED;
i = b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].nsock;
spinlock_unlock(&b->acceptors[(i + port) % MMNIF_MAX_ACCEPTORS].alock);
return i;
}
}
@ -1701,18 +1650,20 @@ int mmnif_closesocket(int s)
if (p == 0)
return -1;
mmnif_hashdelete(s);
if ((unsigned int)s < MMNIF_PSEUDO_SOCKET_START)
return lwip_close(s);
return 0;
}
/* mmnif_irqhandler():
* handles the incomint interrupts
*/
void mmnif_irqhandler()
void mmnif_irqhandler(void)
{
//mmnif_t *mmnif;
mmnif_t *mmnif;
/* return if mmnif_dev is not yet initialized */
if (!mmnif_dev)
@ -1720,84 +1671,16 @@ void mmnif_irqhandler()
DEBUGPRINTF("mmnif_irqhandler(): the driver is not initialized yet\n");
return;
}
//mmnif = (mmnif_t *) mmnif_dev->state;
mmnif_rx(mmnif_dev);
// while (mmnif->rx_buff->dcount < MMNIF_MAX_DESCRIPTORS)
// {
// mmnif_rx(mmnif_dev);
// if (mmnif->rx_buff->dcount < MMNIF_MAX_DESCRIPTORS/2)
// {
// budget_overflow_count++;
// if (budget_overflow_count >= MMNIF_INTR_BUDGET)
// {
// mmnif->rx_buff->iv_intr = FALSE;
// budget_overflow_count = 0;
// sem_post(&mmnif->com_poll);
// break;
// }
// }
// else
// budget_overflow_count = 0;
// }
}
/*
* the poll function wich is used if no interrupt wake up our mmnif_rx functions
*/
int mmnif_poll(void *e)
{
mmnif_t *mmnif;
if (!mmnif_dev)
{
DEBUGPRINTF("mmnif_poll(): the driver is not initialized yet\n");
return -1;
}
mmnif = (mmnif_t *) mmnif_dev->state;
if (!reduce_irq)
{
sem_wait(&mmnif->com_poll, 0);
}
#ifdef DEBUG_MMNIF
DEBUGPRINTF("mmnif_poll(): polling thread launched", mmnif->rx_buff);
#endif /* */
/*run while driver is up */
while (active)
{
while (mmnif->rx_buff->desc_table[mmnif->rx_buff->dread].stat !=
MMNIF_STATUS_RDY)
{
mmnif->stats.pll_empty++;
if (mmnif->stats.pll_empty >= MMNIF_POLL_BUDGET)
{
/* enable interrupts and suspend polling
*
*/
mmnif->rx_buff->iv_intr = TRUE;
mmnif->stats.pll_empty = 0;
#ifdef DEBUG_MMNIF
DEBUGPRINTF
("mmnif_poll(): heuristical interrupts enabled\n");
#endif /* */
sem_wait(&mmnif->com_poll, 0);
}
/* uncomment this to test only polling
*/
// mmnif->stats.pll_empty = 0;
if (!mmnif->check_in_progress) {
if (tcpip_callback_with_block(mmnif_rx, (void*) mmnif_dev, 0) == ERR_OK) {
mmnif->check_in_progress = 1;
} else {
DEBUGPRINTF("rckemacif_handler: unable to send a poll request to the tcpip thread\n");
}
mmnif->stats.pll_empty = 0;
mmnif_rx(mmnif_dev);
}
return 0;
}
/*
@ -1817,13 +1700,9 @@ err_t mmnif_shutdown(void)
err = netifapi_netif_set_down(mmnif_dev);
/* indicate that the driver is not active anymore
* - this will stop the polling thread i.e.
*/
active = FALSE;
kfree(mmnif->tx_buff[0], MMNIF_TX_QUEUELEN * MMNIF_TX_BUFFERLEN);
//RCCE_shfree(mpb_start_address);
mmnif_dev = NULL;
return err;
}

View file

@ -42,7 +42,6 @@
err_t mmnif_init(struct netif*);
err_t mmnif_shutdown(void);
int mmnif_poll(void *e);
int mmnif_worker(void *e);
void mmnif_irqhandler(void);
void mmnif_print_driver_status();