fix bug in wrong setting of the tx_write_offset
This commit is contained in:
parent
f0c0ab4bdb
commit
c73b69a2d1
1 changed files with 16 additions and 36 deletions
|
@ -216,7 +216,7 @@ static err_t rckemacif_output(struct netif* netif, struct pbuf* p)
|
|||
int sum = 0;
|
||||
|
||||
/* check for over/underflow */
|
||||
if (BUILTIN_EXPECT((p->tot_len < 20) || (p->tot_len > 1536), 0)) {
|
||||
if (BUILTIN_EXPECT((p->tot_len < 20 /* IP header size */) || (p->tot_len > 1536), 0)) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("rckemacif_output: illegal packet length %d => drop\n", p->len));
|
||||
return ERR_IF;
|
||||
}
|
||||
|
@ -231,11 +231,10 @@ static err_t rckemacif_output(struct netif* netif, struct pbuf* p)
|
|||
read_offset = read_emac(rckemacif->num_emac, EMAC_TX_CONTROL+EMAC_TX_BUFFER_READ_OFFSET, rckemacif->core);
|
||||
#if 1
|
||||
again:
|
||||
if (read_offset < rckemacif->tx_write_offset) {
|
||||
if (read_offset < rckemacif->tx_write_offset)
|
||||
sum = rckemacif->tx_buffer_max - rckemacif->tx_write_offset + read_offset - 1;
|
||||
} else if (read_offset > rckemacif->tx_write_offset) {
|
||||
else if (read_offset > rckemacif->tx_write_offset)
|
||||
sum = read_offset - rckemacif->tx_write_offset - 1;
|
||||
}
|
||||
|
||||
if (sum < packets) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Warning: not enough space available, retrying...\n"));
|
||||
|
@ -280,7 +279,7 @@ again:
|
|||
|
||||
q = p; i = 0;
|
||||
while ((q != 0) && (i < bytes_to_copy)) {
|
||||
sz = q->len > bytes_to_copy-i ? bytes_to_copy-i : q->len;
|
||||
sz = MIN(bytes_to_copy-i, q->len);
|
||||
memcpy_to_nc(((uint8_t*) addr) + 2 + i, q->payload, sz);
|
||||
bytes_left -= sz;
|
||||
i += sz;
|
||||
|
@ -296,7 +295,6 @@ again:
|
|||
i = 0;
|
||||
if (sz < q->len) {
|
||||
memcpy_to_nc((uint8_t*) addr, q->payload + sz, q->len - sz);
|
||||
bytes_left -= (q->len - sz);
|
||||
i = q->len - sz;
|
||||
}
|
||||
for(q=q->next; (q != 0); q = q->next) {
|
||||
|
@ -316,7 +314,7 @@ again:
|
|||
*((volatile int*) rckemacif->tx_buffer) = 2;
|
||||
|
||||
// flush write combining buffers
|
||||
*(int *)RCCE_fool_write_combine_buffer = 1;
|
||||
*((int*)RCCE_fool_write_combine_buffer) = 1;
|
||||
|
||||
/* set new write offset */
|
||||
//LWIP_DEBUGF(NETIF_DEBUG, ("Update tx write offset: %d (read offset %d)\n", rckemacif->tx_write_offset, read_offset));
|
||||
|
@ -350,7 +348,7 @@ static void rckemacif_input(struct netif* netif, struct pbuf* p)
|
|||
#endif /* PPPOE_SUPPORT */
|
||||
/* full packet send to tcpip_thread to process */
|
||||
if ((err = mynetif->input(p, mynetif)) != ERR_OK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("rckemacif_input: IP input error %u\n", err));
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("rckemacif_input: IP input error %d\n", (int32_t) err));
|
||||
pbuf_free(p);
|
||||
}
|
||||
break;
|
||||
|
@ -364,10 +362,8 @@ static void rckemacif_rx_handler(struct netif* netif, unsigned int write_offset)
|
|||
{
|
||||
rckemacif_t* rckemacif = netif->state;
|
||||
unsigned short read_offset = rckemacif->rx_read_offset;
|
||||
//unsigned int counter;
|
||||
volatile void *addr = NULL;
|
||||
uint16_t i, length = 0;
|
||||
uint32_t packets = 0;
|
||||
struct pbuf *p;
|
||||
struct pbuf* q;
|
||||
|
||||
|
@ -424,14 +420,13 @@ again:
|
|||
#endif
|
||||
|
||||
if (read_offset < write_offset) {
|
||||
for (q=p, i/*counter=0*/; q!=NULL; q=q->next) {
|
||||
memcpy_from_nc((uint8_t*) q->payload, (uint8_t*)addr + 2, q->len);
|
||||
//for(i=0; i<q->len; i++, counter++) {
|
||||
// ((uint8_t*) q->payload)[i] = ((uint8_t*)addr)[2 + counter];
|
||||
//}
|
||||
}
|
||||
unsigned int counter;
|
||||
|
||||
read_offset += CLINE_PACKETS(p->len + 2) - 1;
|
||||
for (q=p, counter=0; q!=NULL; q=q->next) {
|
||||
memcpy_from_nc((uint8_t*) q->payload, (uint8_t*)addr + 2 + counter, q->len);
|
||||
counter += q->len;
|
||||
}
|
||||
read_offset += CLINE_PACKETS(p->tot_len + 2) - 1;
|
||||
} else {
|
||||
int rest;
|
||||
int bytesLeft = length;
|
||||
|
@ -445,7 +440,7 @@ again:
|
|||
//LWIP_DEBUGF(NETIF_DEBUG, ("bytes to copy: %d, bytesLeft: %d\n", bytesToCopy, bytesLeft));
|
||||
|
||||
q = p;
|
||||
i = /*counter =*/ 0;
|
||||
i = 0;
|
||||
while ((q != NULL) && (counter < bytesToCopy)) {
|
||||
i = MIN(q->len, bytesToCopy - counter);
|
||||
memcpy_from_nc(q->payload, (uint8_t*) addr + 2 + counter, i);
|
||||
|
@ -454,12 +449,6 @@ again:
|
|||
goto out;
|
||||
else
|
||||
q = q->next;
|
||||
/*for(i=0; i<q->len; i++, counter++) {
|
||||
if (counter < bytesToCopy)
|
||||
((uint8_t*) q->payload)[i] = ((uint8_t*)addr)[2 + counter];
|
||||
else
|
||||
goto out;
|
||||
}*/
|
||||
}
|
||||
out:
|
||||
bytesLeft -= bytesToCopy;
|
||||
|
@ -473,19 +462,14 @@ out:
|
|||
counter = MIN(q->len - i, bytesLeft);
|
||||
memcpy_from_nc((uint8_t*)q->payload + i, (uint8_t*) addr, counter);
|
||||
}
|
||||
//for(counter=0; (i<q->len) && (counter < bytesLeft); i++, counter++)
|
||||
// ((uint8_t*) q->payload)[i] = ((uint8_t*)addr)[counter];
|
||||
for(q=q->next; (q!=NULL) && (counter < bytesLeft); q=q->next) {
|
||||
i = MIN(q->len, bytesLeft - counter);
|
||||
memcpy_from_nc((uint8_t*)q->payload, (uint8_t*)addr + counter, i);
|
||||
counter += i;
|
||||
//for(i=0; (i<q->len) && (counter < bytesLeft); i++, counter++) {
|
||||
// ((uint8_t*) q->payload)[i] = ((uint8_t*)addr)[counter];
|
||||
//}
|
||||
}
|
||||
read_offset = CLINE_PACKETS(bytesLeft);
|
||||
} else {
|
||||
read_offset += CLINE_PACKETS(p->len + 2) - 1;
|
||||
read_offset += CLINE_PACKETS(p->tot_len + 2) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -500,18 +484,14 @@ out:
|
|||
LINK_STATS_INC(link.drop);
|
||||
}
|
||||
|
||||
packets++;
|
||||
|
||||
rxDone:
|
||||
/* set new read pointer */
|
||||
//LWIP_DEBUGF(NETIF_DEBUG, ("Update rx read offset: %d\n", read_offset));
|
||||
write_emac(rckemacif->num_emac, EMAC_RX_CONTROL + EMAC_RX_BUFFER_READ_OFFSET, rckemacif->core, read_offset);
|
||||
rckemacif->rx_read_offset = read_offset;
|
||||
|
||||
if (read_offset != write_offset) {
|
||||
if (packets < 5 /*max_num*/)
|
||||
goto again;
|
||||
}
|
||||
if (read_offset != write_offset)
|
||||
goto again;
|
||||
}
|
||||
|
||||
static void rckemacif_handler(struct state* s)
|
||||
|
|
Loading…
Add table
Reference in a new issue