avoid races
This commit is contained in:
parent
907eb10e28
commit
264ab41457
1 changed files with 23 additions and 12 deletions
|
@ -85,7 +85,12 @@
|
||||||
* regarding the driver & its configuration
|
* regarding the driver & its configuration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MMNIF_RX_BUFFERLEN 32*1024
|
#if MMNIF_USE_MPB
|
||||||
|
#define MMNIF_RX_BUFFERLEN 7*1024
|
||||||
|
#else
|
||||||
|
#define MMNIF_RX_BUFFERLEN 8*1024
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MMNIF_MAX_DESCRIPTORS 64
|
#define MMNIF_MAX_DESCRIPTORS 64
|
||||||
|
|
||||||
#define MMNIF_CORES 2
|
#define MMNIF_CORES 2
|
||||||
|
@ -429,6 +434,7 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
|
||||||
// if ((rb->head - rb->tail < len)&&(rb->tail != rb->head))
|
// if ((rb->head - rb->tail < len)&&(rb->tail != rb->head))
|
||||||
// return NULL;
|
// return NULL;
|
||||||
|
|
||||||
|
RCCE_acquire_lock(dest-1);
|
||||||
spinlock_lock(&rb->dlock);
|
spinlock_lock(&rb->dlock);
|
||||||
if (rb->dcount)
|
if (rb->dcount)
|
||||||
{
|
{
|
||||||
|
@ -444,6 +450,7 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
|
||||||
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
||||||
rb->tail = (rb->tail + len);
|
rb->tail = (rb->tail + len);
|
||||||
spinlock_unlock(&rb->dlock);
|
spinlock_unlock(&rb->dlock);
|
||||||
|
RCCE_release_lock(dest-1);
|
||||||
return ret;
|
return ret;
|
||||||
} else if (rb->head > len) {
|
} else if (rb->head > len) {
|
||||||
rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING;
|
rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING;
|
||||||
|
@ -454,9 +461,11 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
|
||||||
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
||||||
rb->tail = len;
|
rb->tail = len;
|
||||||
spinlock_unlock(&rb->dlock);
|
spinlock_unlock(&rb->dlock);
|
||||||
|
RCCE_release_lock(dest-1);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
spinlock_unlock(&rb->dlock);
|
spinlock_unlock(&rb->dlock);
|
||||||
|
RCCE_release_lock(dest-1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -470,6 +479,7 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
|
||||||
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
||||||
rb->tail = (rb->tail + len);
|
rb->tail = (rb->tail + len);
|
||||||
spinlock_unlock(&rb->dlock);
|
spinlock_unlock(&rb->dlock);
|
||||||
|
RCCE_release_lock(dest-1);
|
||||||
return ret;
|
return ret;
|
||||||
} else if (rb->tail == rb->head) {
|
} else if (rb->tail == rb->head) {
|
||||||
if (MMNIF_RX_BUFFERLEN - rb->tail < len)
|
if (MMNIF_RX_BUFFERLEN - rb->tail < len)
|
||||||
|
@ -486,14 +496,17 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
|
||||||
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
|
||||||
rb->tail = (rb->tail + len);
|
rb->tail = (rb->tail + len);
|
||||||
spinlock_unlock(&rb->dlock);
|
spinlock_unlock(&rb->dlock);
|
||||||
|
RCCE_release_lock(dest-1);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
spinlock_unlock(&rb->dlock);
|
spinlock_unlock(&rb->dlock);
|
||||||
|
RCCE_release_lock(dest-1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
spinlock_unlock(&rb->dlock);
|
spinlock_unlock(&rb->dlock);
|
||||||
|
RCCE_release_lock(dest-1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,6 +567,7 @@ static void mmnif_rxbuff_free(void)
|
||||||
uint32_t i, j;
|
uint32_t i, j;
|
||||||
uint32_t rpos;
|
uint32_t rpos;
|
||||||
|
|
||||||
|
RCCE_acquire_lock(RCCE_ue());
|
||||||
spinlock_lock(&b->dlock);
|
spinlock_lock(&b->dlock);
|
||||||
rpos = b->dread;
|
rpos = b->dread;
|
||||||
|
|
||||||
|
@ -580,7 +594,9 @@ static void mmnif_rxbuff_free(void)
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_unlock(&b->dlock);
|
spinlock_unlock(&b->dlock);
|
||||||
|
RCCE_release_lock(RCCE_ue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -593,7 +609,7 @@ static err_t mmnif_tx(struct netif *netif, struct pbuf *p)
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
struct pbuf *q; /* interator */
|
struct pbuf *q; /* interator */
|
||||||
uint32_t dest_ip = mmnif_get_destination(netif, p);
|
uint32_t dest_ip = mmnif_get_destination(netif, p);
|
||||||
int8_t chances = 20;
|
int8_t chances = 40;
|
||||||
|
|
||||||
/* check for over/underflow */
|
/* check for over/underflow */
|
||||||
if (BUILTIN_EXPECT((p->tot_len < 20 /* IP header size */) || (p->tot_len > 1536), 0)) {
|
if (BUILTIN_EXPECT((p->tot_len < 20 /* IP header size */) || (p->tot_len > 1536), 0)) {
|
||||||
|
@ -608,23 +624,18 @@ realloc:
|
||||||
{
|
{
|
||||||
//DEBUGPRINTF("mmnif_tx(): concurrency");
|
//DEBUGPRINTF("mmnif_tx(): concurrency");
|
||||||
|
|
||||||
if (chances <= 0)
|
//if (chances <= 0)
|
||||||
goto drop_packet;
|
// goto drop_packet;
|
||||||
|
|
||||||
chances--;
|
//chances--;
|
||||||
//mmnif_trigger_irq(dest_ip);
|
//mmnif_trigger_irq(dest_ip);
|
||||||
NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;
|
//NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;
|
||||||
goto realloc;
|
goto realloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!write_address)
|
if (!write_address)
|
||||||
goto drop_packet;
|
goto drop_packet;
|
||||||
|
|
||||||
/* write buffer to buffer & increment the queued packet count
|
|
||||||
* this can be safely done without locking because this place is
|
|
||||||
* reserved for us because it has the status "pending"
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if MMNIF_USE_MPB
|
#if MMNIF_USE_MPB
|
||||||
asm volatile (".byte 0x0f; .byte 0x0a;\n");
|
asm volatile (".byte 0x0f; .byte 0x0a;\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -634,7 +645,7 @@ realloc:
|
||||||
#if MMNIF_USE_MPB
|
#if MMNIF_USE_MPB
|
||||||
memcpy_put((char*) write_address + i, q->payload, q->len);
|
memcpy_put((char*) write_address + i, q->payload, q->len);
|
||||||
#else
|
#else
|
||||||
memcpy((char*)write_address+ i, q->payload, q->len);
|
memcpy((char*) write_address+ i, q->payload, q->len);
|
||||||
#endif
|
#endif
|
||||||
i += q->len;
|
i += q->len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue