Network problem on ARM

Joel Sherrill joel.sherrill at OARcorp.com
Thu Oct 2 14:06:26 UTC 2008


I think the SONIC driver in libchip has some code
that does this.  See ipalign().

--joel

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!
>
> --
> Sebastian Huber, Embedded Brains GmbH
>
> Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
> Phone   : +49 89 18 90 80 79-6
> Fax     : +49 89 18 90 80 79-9
> E-Mail  : sebastian.huber at embedded-brains.de
> PGP     : Public key available on request
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users
>   


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985





More information about the users mailing list