2003-07-15 10:59:38 +02:00
|
|
|
.\" Copyright (c) 2003
|
|
|
|
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
2004-07-07 09:56:58 +02:00
|
|
|
.\" Author: Hartmut Brandt <harti@FreeBSD.org>
|
2003-07-15 10:59:38 +02:00
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
2004-07-07 09:56:58 +02:00
|
|
|
.\"
|
2003-07-15 10:59:38 +02:00
|
|
|
.Dd July 15, 2003
|
|
|
|
.Dt MBPOOL 9
|
2004-07-06 09:02:31 +02:00
|
|
|
.Os
|
2003-07-15 10:59:38 +02:00
|
|
|
.Sh NAME
|
|
|
|
.Nm mbpool
|
2004-07-07 09:56:58 +02:00
|
|
|
.Nd "buffer pools for network interfaces"
|
2003-07-15 10:59:38 +02:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/types.h
|
|
|
|
.In machine/bus.h
|
|
|
|
.In sys/mbpool.h
|
2004-07-07 09:56:58 +02:00
|
|
|
.Vt struct mbpool ;
|
2003-07-15 10:59:38 +02:00
|
|
|
.Ft int
|
2004-07-07 09:56:58 +02:00
|
|
|
.Fo mbp_create
|
|
|
|
.Fa "struct mbpool **mbp" "const char *name" "bus_dma_tag_t dmat"
|
|
|
|
.Fa "u_int max_pages" "size_t page_size" "size_t chunk_size"
|
|
|
|
.Fc
|
2003-07-15 10:59:38 +02:00
|
|
|
.Ft void
|
|
|
|
.Fn mbp_destroy "struct mbpool *mbp"
|
2004-07-07 09:56:58 +02:00
|
|
|
.Ft "void *"
|
2003-07-15 10:59:38 +02:00
|
|
|
.Fn mbp_alloc "struct mbpool *mbp" "bus_addr_t *pa" "uint32_t *hp"
|
|
|
|
.Ft void
|
|
|
|
.Fn mbp_free "struct mbpool *mbp" "void *p"
|
|
|
|
.Ft void
|
|
|
|
.Fn mbp_ext_free "void *" "void *"
|
|
|
|
.Ft void
|
|
|
|
.Fn mbp_card_free "struct mbpool *mbp"
|
|
|
|
.Ft void
|
|
|
|
.Fn mbp_count "struct mbpool *mbp" "u_int *used" "u_int *card" "u_int *free"
|
2004-07-07 09:56:58 +02:00
|
|
|
.Ft "void *"
|
2003-07-15 10:59:38 +02:00
|
|
|
.Fn mbp_get "struct mbpool *mbp" "uint32_t h"
|
2004-07-07 09:56:58 +02:00
|
|
|
.Ft "void *"
|
2003-07-15 10:59:38 +02:00
|
|
|
.Fn mbp_get_keep "struct mbpool *mbp" "uint32_t h"
|
|
|
|
.Ft void
|
2004-07-07 09:56:58 +02:00
|
|
|
.Fo mbp_sync
|
|
|
|
.Fa "struct mbpool *mbp" "uint32_t h" "bus_addr_t off" "bus_size_t len"
|
|
|
|
.Fa "u_int op"
|
|
|
|
.Fc
|
2003-07-15 10:59:38 +02:00
|
|
|
.Pp
|
|
|
|
.Fn MODULE_DEPEND "your_module" "libmbpool" 1 1 1
|
|
|
|
.Pp
|
2004-07-07 09:56:58 +02:00
|
|
|
.Cd "options LIBMBPOOL"
|
2003-07-15 10:59:38 +02:00
|
|
|
.Sh DESCRIPTION
|
2004-06-21 16:11:45 +02:00
|
|
|
Mbuf pools are intended to help drivers for interface cards that need huge
|
2004-07-07 09:56:58 +02:00
|
|
|
amounts of receive buffers, and additionally provides a mapping between these
|
2003-07-15 10:59:38 +02:00
|
|
|
buffers and 32-bit handles.
|
|
|
|
.Pp
|
2004-07-03 20:29:24 +02:00
|
|
|
An example of these cards are the Fore/Marconi ForeRunnerHE cards.
|
|
|
|
These
|
2003-07-15 10:59:38 +02:00
|
|
|
employ up to 8 receive groups, each with two buffer pools, each of which
|
2004-07-03 20:29:24 +02:00
|
|
|
can contain up to 8192.
|
|
|
|
This gives a total maximum number of more than
|
|
|
|
100000 buffers.
|
|
|
|
Even with a more moderate configuration the card eats several
|
|
|
|
thousand buffers.
|
|
|
|
Each of these buffers must be mapped for DMA.
|
|
|
|
While for
|
2003-07-15 10:59:38 +02:00
|
|
|
machines without an IOMMU and with lesser than 4GByte memory this is not
|
|
|
|
a problem, for other machines this may quickly eat up all available IOMMU
|
2004-07-03 20:29:24 +02:00
|
|
|
address space and/or bounce buffers.
|
2004-07-07 09:56:58 +02:00
|
|
|
On sparc64, the default I/O page size
|
2003-07-15 10:59:38 +02:00
|
|
|
is 16k, so mapping a simple mbuf wastes 31/32 of the address space.
|
|
|
|
.Pp
|
|
|
|
Another problem with most of these cards is that they support putting a 32-bit
|
|
|
|
handle into the buffer descriptor together with the physical address.
|
2004-07-07 09:56:58 +02:00
|
|
|
This handle is reflected back to the driver when the buffer is filled, and
|
2004-07-03 20:29:24 +02:00
|
|
|
assists the driver in finding the buffer in host memory.
|
2004-07-07 09:56:58 +02:00
|
|
|
For 32-bit machines,
|
|
|
|
the virtual address of the buffer is usually used as the handle.
|
2004-07-03 20:29:24 +02:00
|
|
|
This does not
|
2004-07-07 09:56:58 +02:00
|
|
|
work for 64-bit machines for obvious reasons, so a mapping is needed between
|
2004-07-03 20:29:24 +02:00
|
|
|
these handles and the buffers.
|
|
|
|
This mapping should be possible without
|
2003-07-15 10:59:38 +02:00
|
|
|
searching lists and the like.
|
|
|
|
.Pp
|
|
|
|
An mbuf pool overcomes both problems by allocating DMA-able memory page wise
|
2004-07-03 20:29:24 +02:00
|
|
|
with a per-pool configurable page size.
|
2004-07-07 09:56:58 +02:00
|
|
|
Each page is divided into a number of
|
|
|
|
equally-sized chunks, the last
|
2003-07-15 10:59:38 +02:00
|
|
|
.Dv MBPOOL_TRAILER_SIZE
|
2004-07-03 20:29:24 +02:00
|
|
|
of which are used by the pool code (4 bytes).
|
|
|
|
The rest of each chunk is
|
2004-07-07 09:56:58 +02:00
|
|
|
usable as a buffer.
|
2003-07-15 10:59:38 +02:00
|
|
|
There is a per-pool limit on pages that will be allocated.
|
|
|
|
.Pp
|
2004-07-07 09:56:58 +02:00
|
|
|
Additionally, the code manages two flags for each buffer:
|
|
|
|
.Dq on-card
|
|
|
|
and
|
|
|
|
.Dq used .
|
2003-07-15 10:59:38 +02:00
|
|
|
A buffer may be in one of three states:
|
2004-07-07 09:56:58 +02:00
|
|
|
.Bl -tag -width "on-card"
|
2003-07-15 10:59:38 +02:00
|
|
|
.It free
|
2004-07-07 09:56:58 +02:00
|
|
|
None of the flags is set.
|
2003-07-15 10:59:38 +02:00
|
|
|
.It on-card
|
2004-07-07 09:56:58 +02:00
|
|
|
Both flags are set.
|
2004-07-03 20:29:24 +02:00
|
|
|
The buffer is assumed to be handed over to the card and
|
2003-07-15 10:59:38 +02:00
|
|
|
waiting to be filled.
|
|
|
|
.It used
|
|
|
|
The buffer was returned by the card and is now travelling through the system.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
A pool is created with
|
|
|
|
.Fn mbp_create .
|
|
|
|
This call specifies a DMA tag
|
|
|
|
.Fa dmat
|
|
|
|
to be used to create and map the memory pages via
|
2004-07-07 09:56:58 +02:00
|
|
|
.Xr bus_dmamem_alloc 9 .
|
2003-07-15 10:59:38 +02:00
|
|
|
The
|
|
|
|
.Fa chunk_size
|
2004-07-03 20:29:24 +02:00
|
|
|
includes the pool overhead.
|
2004-07-07 09:56:58 +02:00
|
|
|
It means that to get buffers for 5 ATM cells
|
|
|
|
(240 bytes), a chunk size of 256 should be specified.
|
2004-07-03 20:29:24 +02:00
|
|
|
This results in 12 unused
|
2004-07-07 09:56:58 +02:00
|
|
|
bytes between the buffer, and the pool overhead of four byte.
|
2004-07-03 20:29:24 +02:00
|
|
|
The total
|
2003-07-15 10:59:38 +02:00
|
|
|
maximum number of buffers in a pool is
|
2004-07-07 09:56:58 +02:00
|
|
|
.Fa max_pages
|
|
|
|
*
|
|
|
|
.Fa ( page_size
|
|
|
|
/
|
2004-07-03 20:29:24 +02:00
|
|
|
.Fa chunk_size ) .
|
2003-07-15 10:59:38 +02:00
|
|
|
The maximum value for
|
|
|
|
.Fa max_pages
|
|
|
|
is 2^14-1 (16383) and the maximum of
|
2004-07-07 09:56:58 +02:00
|
|
|
.Fa page_size
|
|
|
|
/
|
2003-07-15 10:59:38 +02:00
|
|
|
.Fa chunk_size
|
|
|
|
is 2^9 (512).
|
2004-07-07 09:56:58 +02:00
|
|
|
If the call is successful, a pointer to a newly allocated
|
2003-07-15 10:59:38 +02:00
|
|
|
.Vt "struct mbpool"
|
|
|
|
is set into the variable pointed to by
|
|
|
|
.Fa mpb .
|
|
|
|
.Pp
|
|
|
|
A pool is destroyed with
|
|
|
|
.Fn mbp_destroy .
|
2004-07-03 20:29:24 +02:00
|
|
|
This frees all pages and the pool structure itself.
|
|
|
|
If compiled with
|
2004-07-07 09:56:58 +02:00
|
|
|
.Dv DIAGNOSTICS ,
|
2004-07-03 20:29:24 +02:00
|
|
|
the code checks that all buffers are free.
|
2004-07-07 09:56:58 +02:00
|
|
|
If not, a warning message is issued
|
2003-07-15 10:59:38 +02:00
|
|
|
to the console.
|
|
|
|
.Pp
|
2004-07-07 09:56:58 +02:00
|
|
|
A buffer is allocated with
|
2003-07-15 10:59:38 +02:00
|
|
|
.Fn mbp_alloc .
|
|
|
|
This returns the virtual address of the buffer and stores the physical
|
|
|
|
address into the variable pointed to by
|
|
|
|
.Fa pa .
|
|
|
|
The handle is stored into the variable pointed to by
|
|
|
|
.Fa hp .
|
|
|
|
The two most significant bits and the 7 least significant bits of the handle
|
2004-07-03 20:29:24 +02:00
|
|
|
are unused by the pool code and may be used by the caller.
|
|
|
|
These are
|
2003-07-15 10:59:38 +02:00
|
|
|
automatically stripped when passing a handle to one of the other functions.
|
|
|
|
If a buffer cannot be allocated (either because the maximum number of pages
|
2004-07-07 09:56:58 +02:00
|
|
|
is reached, no memory is available or the memory cannot be mapped),
|
|
|
|
.Dv NULL
|
|
|
|
is returned.
|
|
|
|
If a buffer could be allocated, it is in the
|
|
|
|
.Dq on-card
|
|
|
|
state.
|
2003-07-15 10:59:38 +02:00
|
|
|
.Pp
|
2004-07-07 09:56:58 +02:00
|
|
|
When the buffer is returned by the card, the driver calls
|
2003-07-15 10:59:38 +02:00
|
|
|
.Fn mbp_get
|
2004-07-03 20:29:24 +02:00
|
|
|
with the handle.
|
|
|
|
This function returns the virtual address of the buffer
|
2004-07-07 09:56:58 +02:00
|
|
|
and clears the
|
|
|
|
.Dq on-card
|
|
|
|
bit.
|
|
|
|
The buffer is now in the
|
|
|
|
.Dq used
|
|
|
|
state.
|
2003-07-15 10:59:38 +02:00
|
|
|
The function
|
|
|
|
.Fn mbp_get_keep
|
|
|
|
differs from
|
|
|
|
.Fn mbp_get
|
2004-07-07 09:56:58 +02:00
|
|
|
in that it does not clear the
|
|
|
|
.Dq on-card
|
|
|
|
bit.
|
2004-07-03 20:29:24 +02:00
|
|
|
This can be used for buffers
|
2003-07-15 10:59:38 +02:00
|
|
|
that are returned
|
2004-07-07 09:56:58 +02:00
|
|
|
.Dq partially
|
2003-07-15 10:59:38 +02:00
|
|
|
by the card.
|
|
|
|
.Pp
|
|
|
|
A buffer is freed by calling
|
|
|
|
.Fn mbp_free
|
2004-07-03 20:29:24 +02:00
|
|
|
with the virtual address of the buffer.
|
2004-07-07 09:56:58 +02:00
|
|
|
This clears the
|
|
|
|
.Dq used
|
|
|
|
bit, and
|
2004-07-03 20:29:24 +02:00
|
|
|
puts the buffer on the free list of the pool.
|
2004-07-07 09:56:58 +02:00
|
|
|
Note that free buffers
|
2003-07-15 10:59:38 +02:00
|
|
|
are NOT returned to the system.
|
|
|
|
The function
|
2004-07-07 09:56:58 +02:00
|
|
|
.Fn mbp_ext_free
|
|
|
|
can be given to
|
2003-07-15 10:59:38 +02:00
|
|
|
.Fn m_extadd
|
2004-07-03 20:29:24 +02:00
|
|
|
as the free function.
|
|
|
|
The user argument must be the pointer to
|
2003-07-15 10:59:38 +02:00
|
|
|
the pool.
|
|
|
|
.Pp
|
2004-07-07 09:56:58 +02:00
|
|
|
Before using the contents of a buffer returned by the card, the driver
|
2003-07-15 10:59:38 +02:00
|
|
|
must call
|
|
|
|
.Fn mbp_sync
|
2004-07-03 20:29:24 +02:00
|
|
|
with the appropriate parameters.
|
|
|
|
This results in a call to
|
2004-07-07 09:56:58 +02:00
|
|
|
.Xr bus_dmamap_sync 9
|
2003-07-15 10:59:38 +02:00
|
|
|
for the buffer.
|
|
|
|
.Pp
|
2004-07-07 09:56:58 +02:00
|
|
|
All buffers in the pool that are currently in the
|
|
|
|
.Dq on-card
|
|
|
|
state can be freed
|
2003-07-15 10:59:38 +02:00
|
|
|
with a call to
|
|
|
|
.Fn mbp_card_free .
|
2004-07-03 20:29:24 +02:00
|
|
|
This may be called by the driver when it stops the interface.
|
2004-07-07 09:56:58 +02:00
|
|
|
Buffers in the
|
|
|
|
.Dq used
|
|
|
|
state are not freed by this call.
|
2003-07-15 10:59:38 +02:00
|
|
|
.Pp
|
|
|
|
For debugging it is possible to call
|
|
|
|
.Fn mbp_count .
|
2004-07-07 09:56:58 +02:00
|
|
|
This returns the number of buffers in the
|
|
|
|
.Dq used
|
|
|
|
and
|
|
|
|
.Dq on-card
|
|
|
|
states and
|
2003-07-15 10:59:38 +02:00
|
|
|
the number of buffers on the free list.
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr mbuf 9
|
2010-05-13 14:07:55 +02:00
|
|
|
.Sh AUTHORS
|
2014-06-26 23:44:30 +02:00
|
|
|
.An Harti Brandt Aq Mt harti@FreeBSD.org
|
2003-07-15 10:59:38 +02:00
|
|
|
.Sh CAVEATS
|
|
|
|
The function
|
|
|
|
.Fn mbp_sync
|
2004-07-07 09:56:58 +02:00
|
|
|
is currently a no-op because
|
|
|
|
.Xr bus_dmamap_sync 9
|
2003-07-15 10:59:38 +02:00
|
|
|
is missing the offset and length parameters.
|