Subject: Data Alignment in mbufs
To: None <tech-net@NetBSD.ORG>
From: Curt Sampson <cjs@portal.ca>
List: tech-net
Date: 05/24/1997 00:10:35
While tweaking the (ISA) ed driver to run on the Alpha port, I've
run into a little problem that I'm not finding terribly tractable.

As most of you probably know, the Alpha has alignment restrictions
on reads; it's not possible to read a word (16 bits) from anything
but a word-aligned address, for example.

It appears that some Ethernet cards that use shared memory have a
similar restriction; you cannot write anything but 16-bit quanities
to the shared memory. (I presume from my inspection of the code
that these writes do not actually have to be aligned on 16-bit
boundaries, however; if they do, there's a bug in the Ehernet
driver.)

Unfortunately, the TCP layer is handing me mbufs that have data
start addresses that are not word-aligned. (It's always the address
in the second mbuf of a pair.) Currently the ed driver cannot handle
copying these from system RAM into the Ethernet card's RAM without
doing unaligned 16-bit reads from system RAM.

So what's the best way to solve this problem? I can tweak the driver
so that it will do a bit of buffering between the reads and the
writes (though possibly at a small loss of efficiency--on the other
hand, the shared memory on the ISA bus is probably slow enough that
it would make no difference). However, I'm wondering if other
drivers are affected by similar problems, and if perhaps we don't
want to consider adding alignment guarantees to some of the mbuf
operations.

cjs

Curt Sampson    cjs@portal.ca		Info at http://www.portal.ca/
Internet Portal Services, Inc.		`And malt does more than Milton can
Vancouver, BC   (604) 257-9400		 To justify God's ways to man.'