mxge: properly remove the sysctls
[dragonfly.git] / sys / net / i4b / layer2 / i4b_mbuf.c
blobe160a01338c6c34cc147188f5045133a9a107311
1 /*
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
6 * are met:
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
23 * SUCH DAMAGE.
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>
39 #include <sys/mbuf.h>
40 #include <sys/socket.h>
41 #include <sys/thread2.h>
43 #include <net/if.h>
45 #include "../include/i4b_mbuf.h"
47 #define I4B_MBUF_DEBUG
48 #undef I4B_MBUF_TYPE_DEBUG
50 #ifdef I4B_MBUF_TYPE_DEBUG
52 #define MT_DCHAN 42
53 #define MT_BCHAN 43
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 *---------------------------------------------------------------------------*/
67 struct mbuf*
68 i4b_Dgetmbuf(int len)
70 struct mbuf *m;
72 if(len > MCLBYTES) /* if length > max extension size */
75 #ifdef I4B_MBUF_DEBUG
76 kprintf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
77 len, MCLBYTES);
78 #endif
80 return(NULL);
83 MGETHDR(m, MB_DONTWAIT, MT_I4B_D); /* get mbuf with pkthdr */
85 /* did we actually get the mbuf ? */
87 if(!m)
90 #ifdef I4B_MBUF_DEBUG
91 kprintf("i4b_getbuf: error - MGETHDR failed!\n");
92 #endif
94 return(NULL);
97 if(len >= MHLEN)
99 MCLGET(m, MB_DONTWAIT);
101 if(!(m->m_flags & M_EXT))
103 m_freem(m);
105 #ifdef I4B_MBUF_DEBUG
106 kprintf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
107 #endif
109 return (NULL);
113 m->m_len = len;
115 return(m);
118 /*---------------------------------------------------------------------------*
119 * free a D-channel mbuf
120 *---------------------------------------------------------------------------*/
121 void
122 i4b_Dfreembuf(struct mbuf *m)
124 if(m)
125 m_freem(m);
128 /*---------------------------------------------------------------------------*
129 * clear a D-channel ifqueue from data
130 *---------------------------------------------------------------------------*/
131 void
132 i4b_Dcleanifq(struct ifqueue *ifq)
134 crit_enter();
136 IF_DRAIN(ifq);
138 crit_exit();
141 /*---------------------------------------------------------------------------*
142 * allocate B-channel mbuf space
143 *---------------------------------------------------------------------------*/
144 struct mbuf*
145 i4b_Bgetmbuf(int len)
147 struct mbuf *m;
149 if(len > MCLBYTES) /* if length > max extension size */
152 #ifdef I4B_MBUF_DEBUG
153 kprintf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
154 len, MCLBYTES);
155 #endif
157 return(NULL);
160 MGETHDR(m, MB_DONTWAIT, MT_I4B_B); /* get mbuf with pkthdr */
162 /* did we actually get the mbuf ? */
164 if(!m)
167 #ifdef I4B_MBUF_DEBUG
168 kprintf("i4b_getbuf: error - MGETHDR failed!\n");
169 #endif
171 return(NULL);
174 if(len >= MHLEN)
176 MCLGET(m, MB_DONTWAIT);
178 if(!(m->m_flags & M_EXT))
180 m_freem(m);
182 #ifdef I4B_MBUF_DEBUG
183 kprintf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
184 #endif
186 return (NULL);
190 m->m_len = len;
192 return(m);
195 /*---------------------------------------------------------------------------*
196 * free a B-channel mbuf
197 *---------------------------------------------------------------------------*/
198 void
199 i4b_Bfreembuf(struct mbuf *m)
201 if(m)
202 m_freem(m);
205 /*---------------------------------------------------------------------------*
206 * clear a B-channel ifqueue from data
207 *---------------------------------------------------------------------------*/
208 void
209 i4b_Bcleanifq(struct ifqueue *ifq)
211 crit_enter();
213 IF_DRAIN(ifq);
215 crit_exit();
218 /* EOF */