Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
22 years ago

LWIP/LAN91C111 Bug!

I've just spent the best part of a day trying to get some simple socket stuff to work under LWIP/uCos.

Symptoms? Telnet-style connections locked up and dropped mysteriously...

Anyway, I checked out the comms with Ethereal, and found my PC was simply ignoring some packets from the client. Ethereal marked said packets as having bad TCP checksums - but the frame and IP checksums were OK.

To cut a long story short, the last byte of each packet was being checksummed - but not sent!

I believe it's a bug in altera_avalon_lan91c111.c's low_level_output() function, failing to handle pbuf chains where the overall length is odd, but the last pbuf length is even...

Recommended fix is to change a section of low_level_output() from...

  
    /*
    * Last buffer in the packet?
    */
    if (total_length_sent == p->tot_len) 
    {
      if (q->tot_len & 1) 
      {

... to ...

  
    /*
    * Last buffer in the packet?
    */
    if (total_length_sent == p->tot_len) 
    {
      if (p->tot_len & 1)   // check the TOTAL packet len - q->tot_len cannot be used here
      {

Hope that's of use!

- Roddy

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Roddy,

    Thank you very much!

    I'll file a report on this and advise the appropriate people. We are *very* close to the next release so I cannot guarantee a fix with the next release (we will have to verify the bug & test the fix), but this will be given a serious look.

    Again, thank you for taking the time to post this here!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    What kind of thruput do you see with LWIP/uCOS?

    I have a 30Mhz board running a modified SSS to do file transfer (LWIP,uCOS). My thruput is no better than a serial port. The same board running u-boot tftp (no stack, no OS) does transfers 10 times faster. Somewhere in the LWIP, uCOS, driver code there is a serious bottleneck.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I don't have any accurate figures, but my NIOS dev kit board is serving web pages at about 150KBytes/second. Not great, but I've done no optimization yet.

    If your receive is slow, try increasing the MAX WINDOW SIZE option in the LWIP TCP options page. It defaults to 2K, which means almost every packet will need an immediate ACK. Ethereal is a great tool for seeing what's really happening on your link.

    - Roddy
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    tns1,

    What protocol are you running? As a ball park the figures I can reproduce with a design @ 50Mhz on a full featured design are UDP 820kbytes/s Tx 610 kbytes/s Rx. TCP is a little lower and once retransmissions start the performance is obviously lousy
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I've taken the SSS example and tweaked it to handle file transfers. In my test the board receives a file in 1500 byte max data packets and immediatly sends them back to the client. There are several things I could do to streamline the code, I just didn't expect it would be so slow. The NiosII is tiny model (no cache) @ 30Mhz. The lan91C111 has a 16bit bus. Have to give ethereal a try if I run out of ideas.