2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b - mbuf handling support routines
28 * ------------------------------------
30 * $FreeBSD: src/sys/i4b/layer2/i4b_mbuf.c,v 1.6.2.1 2001/08/10 14:08:41 obrien Exp $
31 * $DragonFly: src/sys/net/i4b/layer2/i4b_mbuf.c,v 1.8 2006/12/22 23:44:56 swildner Exp $
33 * last edit-date: [Sat Jan 13 13:15:45 2001]
35 *---------------------------------------------------------------------------*/
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/socket.h>
41 #include <sys/thread2.h>
45 #include "../include/i4b_mbuf.h"
47 #define I4B_MBUF_DEBUG
48 #undef I4B_MBUF_TYPE_DEBUG
50 #ifdef I4B_MBUF_TYPE_DEBUG
54 #define MT_I4B_D MT_DCHAN
55 #define MT_I4B_B MT_BCHAN
57 #else /* ! I4B_MBUF_TYPE_DEBUG */
59 #define MT_I4B_D MT_DATA
60 #define MT_I4B_B MT_DATA
62 #endif /* I4B_MBUF_TYPE_DEBUG */
64 /*---------------------------------------------------------------------------*
65 * allocate D-channel mbuf space
66 *---------------------------------------------------------------------------*/
72 if(len
> MCLBYTES
) /* if length > max extension size */
76 kprintf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
83 MGETHDR(m
, MB_DONTWAIT
, MT_I4B_D
); /* get mbuf with pkthdr */
85 /* did we actually get the mbuf ? */
91 kprintf("i4b_getbuf: error - MGETHDR failed!\n");
99 MCLGET(m
, MB_DONTWAIT
);
101 if(!(m
->m_flags
& M_EXT
))
105 #ifdef I4B_MBUF_DEBUG
106 kprintf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len
);
118 /*---------------------------------------------------------------------------*
119 * free a D-channel mbuf
120 *---------------------------------------------------------------------------*/
122 i4b_Dfreembuf(struct mbuf
*m
)
128 /*---------------------------------------------------------------------------*
129 * clear a D-channel ifqueue from data
130 *---------------------------------------------------------------------------*/
132 i4b_Dcleanifq(struct ifqueue
*ifq
)
141 /*---------------------------------------------------------------------------*
142 * allocate B-channel mbuf space
143 *---------------------------------------------------------------------------*/
145 i4b_Bgetmbuf(int len
)
149 if(len
> MCLBYTES
) /* if length > max extension size */
152 #ifdef I4B_MBUF_DEBUG
153 kprintf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
160 MGETHDR(m
, MB_DONTWAIT
, MT_I4B_B
); /* get mbuf with pkthdr */
162 /* did we actually get the mbuf ? */
167 #ifdef I4B_MBUF_DEBUG
168 kprintf("i4b_getbuf: error - MGETHDR failed!\n");
176 MCLGET(m
, MB_DONTWAIT
);
178 if(!(m
->m_flags
& M_EXT
))
182 #ifdef I4B_MBUF_DEBUG
183 kprintf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len
);
195 /*---------------------------------------------------------------------------*
196 * free a B-channel mbuf
197 *---------------------------------------------------------------------------*/
199 i4b_Bfreembuf(struct mbuf
*m
)
205 /*---------------------------------------------------------------------------*
206 * clear a B-channel ifqueue from data
207 *---------------------------------------------------------------------------*/
209 i4b_Bcleanifq(struct ifqueue
*ifq
)