1 /* Intel PRO/1000 Family Driver
2 * Copyright (C) 2004 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
4 * Permission to use, copy, modify and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies, and that both the
7 * copyright notice and this permission notice appear in supporting documentation.
9 * Marcus Overhagen makes no representations about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
12 * MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
13 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
14 * OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
15 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <KernelExport.h>
22 #include "if_compat.h"
26 spinlock mbuf_pool_lock
= 0;
27 spinlock chunk_pool_lock
= 0;
36 mempool_init(int count
)
38 int chunk_size
= 2048;
39 int mbuf_size
= ROUNDUP(sizeof(struct mbuf
), 16);
41 int chunk_alloc_size
= chunk_size
* (count
+ 1);
42 int mbuf_alloc_size
= mbuf_size
* (count
+ 1);
49 INIT_DEBUGOUT2("chunk_size %d, mbuf_size %d", chunk_size
, mbuf_size
);
50 INIT_DEBUGOUT2("chunk_alloc_size %d, mbuf_alloc_size %d", chunk_alloc_size
, mbuf_alloc_size
);
52 chunk_pool
= area_malloc(chunk_alloc_size
);
54 ERROROUT1("failed to allocate chunk storage of %d bytes\n", chunk_alloc_size
);
57 mbuf_pool
= area_malloc(mbuf_alloc_size
);
59 ERROROUT1("failed to allocate mbuf storage of %d bytes\n", mbuf_alloc_size
);
60 area_free(chunk_pool
);
64 chunk_base
= (char *)ROUNDUP((unsigned long)chunk_pool
, 2048);
65 mbuf_base
= (char *)ROUNDUP((unsigned long)mbuf_pool
, 16);
67 for (i
= 0; i
< count
; i
++) {
68 chunk_pool_put(chunk_base
+ i
* chunk_size
);
69 mbuf_pool_put(mbuf_base
+ i
* mbuf_size
);
72 INIT_DEBUGOUT("mempool init success");
79 area_free(chunk_pool
);
88 s
= disable_interrupts();
89 acquire_spinlock(&mbuf_pool_lock
);
93 mbuf_head
= *(void **)p
;
95 release_spinlock(&mbuf_pool_lock
);
96 restore_interrupts(s
);
101 mbuf_pool_put(void *p
)
104 s
= disable_interrupts();
105 acquire_spinlock(&mbuf_pool_lock
);
107 *(void **)p
= mbuf_head
;
110 release_spinlock(&mbuf_pool_lock
);
111 restore_interrupts(s
);
119 s
= disable_interrupts();
120 acquire_spinlock(&chunk_pool_lock
);
124 chunk_head
= *(void **)p
;
126 release_spinlock(&chunk_pool_lock
);
127 restore_interrupts(s
);
132 chunk_pool_put(void *p
)
135 s
= disable_interrupts();
136 acquire_spinlock(&chunk_pool_lock
);
138 *(void **)p
= chunk_head
;
141 release_spinlock(&chunk_pool_lock
);
142 restore_interrupts(s
);