1139825Simp/*- 2117624Sharti * Copyright (c) 2003 3117624Sharti * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4117624Sharti * All rights reserved. 5117624Sharti * 6117624Sharti * Redistribution and use in source and binary forms, with or without 7117624Sharti * modification, are permitted provided that the following conditions 8117624Sharti * are met: 9117624Sharti * 1. Redistributions of source code must retain the above copyright 10117624Sharti * notice, this list of conditions and the following disclaimer. 11117624Sharti * 2. Redistributions in binary form must reproduce the above copyright 12117624Sharti * notice, this list of conditions and the following disclaimer in the 13117624Sharti * documentation and/or other materials provided with the distribution. 14117624Sharti * 15117624Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16117624Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17117624Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18117624Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19117624Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20117624Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21117624Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22117624Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23117624Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24117624Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25117624Sharti * SUCH DAMAGE. 26117624Sharti * 27117624Sharti * Author: Hartmut Brandt <harti@freebsd.org> 28139825Simp */ 29139825Simp 30139825Simp/* 31117624Sharti * This implements pools of DMA-able buffers that conserve DMA address space 32117624Sharti * by putting several buffers into one page and that allow to map between 33117624Sharti * 32-bit handles for the buffer and buffer addresses (to use 32-bit network 34117624Sharti * interfaces on 64bit machines). This assists network interfaces that may need 35117624Sharti * huge numbers of mbufs. 36117624Sharti * 37117624Sharti * $FreeBSD$ 38117624Sharti */ 39117624Sharti#ifndef _SYS_MBPOOL_H_ 40117624Sharti#define _SYS_MBPOOL_H_ 41117624Sharti 42117624Sharti#ifdef _KERNEL 43117624Sharti 44117624Sharti#include <sys/queue.h> 45117624Sharti 46117624Sharti/* opaque */ 47117624Shartistruct mbpool; 48117624Sharti 49117624Sharti/* size of reserved area at end of each chunk */ 50117624Sharti#define MBPOOL_TRAILER_SIZE 4 51117624Sharti 52117624Sharti/* maximum value of max_pages */ 53117624Sharti#define MBPOOL_MAX_MAXPAGES ((1 << 14) - 1) 54117624Sharti 55117624Sharti/* maximum number of chunks per page */ 56117624Sharti#define MBPOOL_MAX_CHUNKS (1 << 9) 57117624Sharti 58117624Sharti/* initialize a pool */ 59117624Shartiint mbp_create(struct mbpool **, const char *, bus_dma_tag_t, u_int, 60117624Sharti size_t, size_t); 61117624Sharti 62117624Sharti/* destroy a pool */ 63117624Shartivoid mbp_destroy(struct mbpool *); 64117624Sharti 65117624Sharti/* allocate a chunk and set used and on card */ 66117624Shartivoid *mbp_alloc(struct mbpool *, bus_addr_t *, uint32_t *); 67117624Sharti 68117624Sharti/* free a chunk */ 69117624Shartivoid mbp_free(struct mbpool *, void *); 70117624Sharti 71117624Sharti/* free a chunk that is an external mbuf */ 72254842Sandreint mbp_ext_free(struct mbuf *, void *, void *); 73117624Sharti 74117624Sharti/* free all buffers that are marked to be on the card */ 75117624Shartivoid mbp_card_free(struct mbpool *); 76117624Sharti 77117624Sharti/* count used buffers and buffers on card */ 78117624Shartivoid mbp_count(struct mbpool *, u_int *, u_int *, u_int *); 79117624Sharti 80117624Sharti/* get the buffer from a handle and clear card bit */ 81117624Shartivoid *mbp_get(struct mbpool *, uint32_t); 82117624Sharti 83117624Sharti/* get the buffer from a handle and don't clear card bit */ 84117624Shartivoid *mbp_get_keep(struct mbpool *, uint32_t); 85117624Sharti 86117624Sharti/* sync the chunk */ 87117624Shartivoid mbp_sync(struct mbpool *, uint32_t, bus_addr_t, bus_size_t, u_int); 88117624Sharti 89117624Sharti#endif /* _KERNEL */ 90117624Sharti#endif /* _SYS_MBPOOL_H_ */ 91