Confusing sequence in libchip/network/smc91111.c

Peter Dufault dufault at hda.com
Sun Feb 9 09:58:55 UTC 2014


I decided to look at adding DMA support for the Phytec MPC5554 for the SMC91111 to speed up network performance.  It's a twisty piece of work.  So far I've only looked at where the info in the receive FIFO is copied into the mbuf.

Here's the critical loop (around line 215).  LAN91CXX_32BIT_RX is defined, meaning "sizeof(rxdt)" and "sizeof(*data)" are 2:

    while (mlen >= sizeof(*data)) {
#ifdef LAN91CXX_32BIT_RX
        rxd_t val = get_data(cpd);
        *(unsigned short *)data = (val >> 16) & 0xffff;
        data = (rxd_t *)((unsigned short *)data + 1); 
        *(unsigned short *)data = (val & 0xffff);
        data = (rxd_t *)((unsigned short *)data + 1); 
#else
        *data++ = get_data(cpd);
#endif
        mlen -= sizeof(*data);
        plen -= sizeof(*data);
    }

Let's simplify this for the case of sizeof(rxd_t) == 4:

    while (mlen >= sizeof(rxd_t)) {
        rxd_t val = get_data(cpd);
        ((uint16_t *)data)[0] = val >> 16;
        ((uint16_t *)data)[1] = val;
        data++;
        mlen -= sizeof(rxd_t);
        plen -= sizeof(rxd_t);
    }

What is this trying to do?  I think on a big endian system it's (almost, other than the extra work) a NOP and on a little endian system it's swapping the two 16 bit halves of the word, but it's not swapping the bytes. I don't understand.

Maybe this is only in use on big endian systems?  I'm using it on PowerPC and I know it's also used on the SPARC.

Peter
-----------------
Peter Dufault
HD Associates, Inc.      Software and System Engineering





More information about the devel mailing list