Nuke compatiblity parts.
[dragonfly.git] / sys / net / i4b / layer2 / i4b_mbuf.c
1 /*
2  * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
3  *
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.
12  *
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.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b - mbuf handling support routines
28  *      ------------------------------------
29  *
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.6 2005/06/14 21:19:19 joerg Exp $
32  *
33  *      last edit-date: [Sat Jan 13 13:15:45 2001]
34  *
35  *---------------------------------------------------------------------------*/
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42
43 #include "../include/i4b_mbuf.h"
44
45 #define I4B_MBUF_DEBUG
46 #undef I4B_MBUF_TYPE_DEBUG
47
48 #ifdef I4B_MBUF_TYPE_DEBUG
49
50 #define MT_DCHAN        42
51 #define MT_BCHAN        43
52 #define MT_I4B_D        MT_DCHAN
53 #define MT_I4B_B        MT_BCHAN
54
55 #else /* ! I4B_MBUF_TYPE_DEBUG */
56
57 #define MT_I4B_D        MT_DATA
58 #define MT_I4B_B        MT_DATA
59
60 #endif /* I4B_MBUF_TYPE_DEBUG */
61
62 /*---------------------------------------------------------------------------*
63  *      allocate D-channel mbuf space
64  *---------------------------------------------------------------------------*/
65 struct mbuf*
66 i4b_Dgetmbuf(int len)
67 {
68         struct mbuf *m;
69
70         if(len > MCLBYTES)      /* if length > max extension size */
71         {
72
73 #ifdef I4B_MBUF_DEBUG
74                 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
75                                         len, MCLBYTES);
76 #endif
77                 
78                 return(NULL);
79         }
80
81         MGETHDR(m, MB_DONTWAIT, MT_I4B_D);      /* get mbuf with pkthdr */
82
83         /* did we actually get the mbuf ? */
84
85         if(!m)  
86         {
87
88 #ifdef I4B_MBUF_DEBUG
89                 printf("i4b_getbuf: error - MGETHDR failed!\n");
90 #endif
91
92                 return(NULL);
93         }
94
95         if(len >= MHLEN)
96         {
97                 MCLGET(m, MB_DONTWAIT);
98
99                 if(!(m->m_flags & M_EXT))
100                 {
101                         m_freem(m);
102
103 #ifdef I4B_MBUF_DEBUG
104                         printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
105 #endif
106                         
107                         return (NULL);
108                 }
109         }
110
111         m->m_len = len;
112
113         return(m);
114 }
115
116 /*---------------------------------------------------------------------------*
117  *      free a D-channel mbuf
118  *---------------------------------------------------------------------------*/
119 void
120 i4b_Dfreembuf(struct mbuf *m)
121 {
122         if(m)
123                 m_freem(m);
124 }
125
126 /*---------------------------------------------------------------------------*
127  *      clear a D-channel ifqueue from data
128  *---------------------------------------------------------------------------*/
129 void
130 i4b_Dcleanifq(struct ifqueue *ifq)
131 {
132         int x = splimp();
133
134         IF_DRAIN(ifq);
135         splx(x);
136 }
137
138 /*---------------------------------------------------------------------------*
139  *      allocate B-channel mbuf space
140  *---------------------------------------------------------------------------*/
141 struct mbuf*
142 i4b_Bgetmbuf(int len)
143 {
144         struct mbuf *m;
145
146         if(len > MCLBYTES)      /* if length > max extension size */
147         {
148
149 #ifdef I4B_MBUF_DEBUG
150                 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
151                                         len, MCLBYTES);
152 #endif
153                 
154                 return(NULL);
155         }
156
157         MGETHDR(m, MB_DONTWAIT, MT_I4B_B);      /* get mbuf with pkthdr */
158
159         /* did we actually get the mbuf ? */
160
161         if(!m)  
162         {
163
164 #ifdef I4B_MBUF_DEBUG
165                 printf("i4b_getbuf: error - MGETHDR failed!\n");
166 #endif
167
168                 return(NULL);
169         }
170
171         if(len >= MHLEN)
172         {
173                 MCLGET(m, MB_DONTWAIT);
174
175                 if(!(m->m_flags & M_EXT))
176                 {
177                         m_freem(m);
178
179 #ifdef I4B_MBUF_DEBUG
180                         printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
181 #endif
182                         
183                         return (NULL);
184                 }
185         }
186
187         m->m_len = len;
188
189         return(m);
190 }
191
192 /*---------------------------------------------------------------------------*
193  *      free a B-channel mbuf
194  *---------------------------------------------------------------------------*/
195 void
196 i4b_Bfreembuf(struct mbuf *m)
197 {
198         if(m)
199                 m_freem(m);
200 }
201
202 /*---------------------------------------------------------------------------*
203  *      clear a B-channel ifqueue from data
204  *---------------------------------------------------------------------------*/
205 void
206 i4b_Bcleanifq(struct ifqueue *ifq)
207 {
208         int x = splimp();
209         
210         IF_DRAIN(ifq);
211         splx(x);
212 }
213
214 /* EOF */