Network problem on ARM

Till Straumann strauman at slac.stanford.edu
Thu Oct 2 09:53:56 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? 
I use a mbuf cluster to receive the entire 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? 
yes; you can adjust m->m_data as you wish (at the
same time reducing m->m_len)

If you want the start of the IP header to be word-aligned
then you can up-adjust m_data by 2 bytes (but note
that some ethernet chips/dma controllers do 'pre-pad'
the ethernet header).
>  Has the data start address of a fresh mbuf a defined
> alignment guarantee?
If you use a cluster and the cluster size is (std) 2048b
then the clusters should have the same alignment as
the entire cluster memory area which is IIRC aligned
to 2k (the cluster size)
(see libnetworking  sys/mbuf.h + rtems/rtems_glue.c)

>   If I modify the data start address of a mbuf do I
> have to undo this before I free this modified mbuf?
>   
no

You can look at the routines 'alloc_mbuf_rx' and
'consume_rx_mbuf'
libbsp/powerpc/mvme3100/network/tsec.c
for an example.

HTH
-- Till

> Thanks!
>
>   




More information about the users mailing list