Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Sep 1998 13:45:24 -0400 (EDT)
From:      Bill Paul <wpaul@skynet.ctr.columbia.edu>
To:        hackers@FreeBSD.ORG
Subject:   malloc()ing 64K physically contiguous buffer in kernel
Message-ID:  <199809201745.NAA21711@skynet.ctr.columbia.edu>

next in thread | raw e-mail | index | archive | help
Grrr.... this is a question which has probably been asked many times
before and I feel really silly asking it now. Unfortunately, I've been
pushed into a corner by this crappy RealTek fast ethernet card.

To make the RealTek 8129/8139 receiver work, I need to allocate a buffer
of either 8, 16, 32 or 64K to act as a receive buffer. The card DMAs 
packets into this buffer until it reaches the end, then wraps back to
the top.

I initially programmed the card to use a 64K buffer, but I noticed
that I was only able to receive about 16K worth of packets before
everything ground to a halt. The card was still generating interrupts
indicating that packets were still being received but there didn't seem 
to be any new packet data in the buffer region after the first 16K. This 
confused the heck out of me for a while, and I was convinced that I'd 
programmed the card wrong but couldn't see how.

Then it dawned on me that although malloc() was giving me 64K of
space to play with, it probably hadn't actually allocated 64K worth
of contiguous pages. In other words, the first 4 pages are mapped
contiguosly in memory, but the next 4K page after that is probably
somewhere else off in physical memory. But the card doesn't know
that, so it's probably DMAing into some unknown location in RAM and
it's only by pure coincidence that it isn't scribbling all over
the guts of the kernel and causing a panic.

Unfortunately, the stinking hardware will not allow one to specify
a buffer size smaller than 8K, and since the page size on x86 is
4K, there's no way to be sure that malloc() will return any more
than 4K of contiguously mapped space. (I'm not even sure why I can
even get 16K.)

So: is there some way to allocate 64K of contiguous memory? Or even
8/16/32K? As long as I can hit one of the allowed buffer sizes I'll
be happy, although I wanted 64K in order to reduce the likelyhood of
receiver overruns.

-Bill

-- 
=============================================================================
-Bill Paul            (212) 854-6020 | System Manager, Master of Unix-Fu
Work:         wpaul@ctr.columbia.edu | Center for Telecommunications Research
Home:  wpaul@skynet.ctr.columbia.edu | Columbia University, New York City
=============================================================================
 "It is not I who am crazy; it is I who am mad!" - Ren Hoek, "Space Madness"
=============================================================================

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809201745.NAA21711>