Network problem on ARM

Gene Smith gds at chartertn.net
Fri Oct 3 17:47:12 UTC 2008


Sebastian Huber wrote:
> Hi,
> I currently write a driver for the Ethernet interface on a LPC2478 with
> a ARM7TMDI-S core.  For this core word (= 4 bytes) load and store
> operations must be word aligned.  The DMA controller of the Ethernet
> interface has no alignment restrictions.
> 
> I encountered now a nasty problem in the receiver path.  At first I took
> a mbuf and instructed the DMA to copy a new Ethernet packet directly to
> the data start address of the mbuf.  The size of the Ethernet header is
> 14 bytes (2 * 6 bytes for the MAC addresses and 2 bytes for the type
> field).  The mbuf data start address was always word aligned so the
> succeeding IP header was now only halfword aligned.
> 
> The IP header structure is declared as:
> 
> struct ip {
>   u_char  ip_vhl;
>   u_char  ip_tos;
>   u_short ip_len;
>   u_short ip_id;
>   u_short ip_off;
>   u_char  ip_ttl;
>   u_char  ip_p;
>   u_short ip_sum;
>   struct  in_addr ip_src, ip_dst;
> } __packed __aligned(4);
> 
> Thus the IP source and destination addresses are word aligned within
> this structure and the GCC generates word load and store operations.
> This lead to wrong address values since the structure was only half word
> aligned within the Ethernet packet.
> 
> What is the standard way to receive a Ethernet packet?  Do I have to use
> two mbufs, one for the Ethernet header and one for the IP packet? Is it
> possible to modify the start address of the mbuf such that the IP header
> is proper aligned?  Has the data start address of a fresh mbuf a defined
> alignment guarantee?  If I modify the data start address of a mbuf do I
> have to undo this before I free this modified mbuf?
> 
> Thanks!
> 

Would like to know how you ultimately fix this. I may have the same 
problem if I ever optimize my driver to have the DMA drop the received 
packets directly in the mbufs.




More information about the users mailing list