3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/netatm/port.h,v 1.2.2.2 2003/01/23 21:06:44 sam Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/port.h,v 1.9 2006/09/05 17:41:18 dillon Exp $
32 * System Configuration
33 * --------------------
39 #ifndef _NETATM_PORT_H
40 #define _NETATM_PORT_H
43 * Kernel memory management
45 * KM_ALLOC(size, type, flags)
46 * Returns an allocated kernel memory chunk of size bytes.
47 * KM_FREE(addr, size, type)
48 * Free a kernel memory chunk of size bytes.
50 * Compares len bytes of data from b1 against b2.
51 * KM_COPY(from, to, len)
52 * Copies len bytes of data from from to to.
54 * Zeros len bytes of data from addr.
58 #include <sys/malloc.h>
59 #define KM_ALLOC(size, type, flags) kmalloc((size), (type), (flags))
60 #define KM_FREE(addr, size, type) kfree((addr), (type))
62 #define KM_CMP(b1, b2, len) bcmp((b1), (b2), (len))
63 #define KM_COPY(from, to, len) bcopy((from), (to), (len))
64 #define KM_ZERO(addr, len) bzero((addr), (len))
65 #define XM_COPY(f, t, l) KM_COPY((f), (t), (l))
70 * User-space memory management
72 * UM_ALLOC(size) Returns an allocated kernel memory chunk of size bytes.
73 * UM_FREE(addr) Free a kernel memory chunk of size bytes.
74 * UM_COPY(from, to, len)
75 * Copies len bytes of data from from to to.
76 * UM_ZERO(addr, len) Zeros len bytes of data from addr.
79 #define UM_ALLOC(size) malloc((size_t)(size))
80 #define UM_FREE(addr) free((void *)(addr))
81 #define UM_COPY(from, to, len) bcopy((void *)(from), (void *)(to),\
83 #define UM_ZERO(addr, len) bzero((void *)(addr), (size_t)(len))
84 #define XM_COPY(f, t, l) UM_COPY((f), (t), (l))
86 #endif /* ATM_KERNEL */
93 * KBuffer Typedef for a kernel buffer.
95 * KB_NEXT(bfr) Access next buffer in chain (r/w).
96 * KB_LEN(bfr) Access length of data in this buffer (r/w).
97 * KB_QNEXT(bfr) Access next buffer in queue (r/w).
99 * KB_ALLOC(bfr, size, flags, type)
100 * Allocates a new kernel buffer of at least size bytes.
101 * KB_ALLOCPKT(bfr, size, flags, type)
102 * Allocates a new kernel packet header buffer of at
104 * KB_ALLOCEXT(bfr, size, flags, type)
105 * Allocates a new kernel buffer with external storage
106 * of at least size bytes.
107 * KB_FREEONE(bfr, nxt) Free buffer bfr and set next buffer in chain in nxt.
108 * KB_FREEALL(bfr) Free bfr's entire buffer chain.
109 * KB_COPY(bfr, off, len, new, flags)
110 * Copy len bytes of user data from buffer bfr starting at
111 * byte offset off and return new buffer chain in new.
112 * If len is KB_COPYALL, copy until end of chain.
113 * KB_COPYDATA(bfr, off, len, datap)
114 * Copy data from buffer bfr starting at byte offset off
115 * for len bytes into the data area pointed to by datap.
116 * Returns the number of bytes not copied to datap.
117 * KB_PULLUP(bfr, n, new)
118 * Get at least the first n bytes of data in the buffer
119 * chain headed by bfr contiguous in the first buffer.
120 * Returns the (potentially new) head of the chain in new.
121 * On failure the chain is freed and NULL is returned.
122 * KB_LINKHEAD(new, head)
123 * Link the kernel buffer new at the head of the buffer
124 * chain headed by head. If both new and head are
125 * packet header buffers, new will become the packet
126 * header for the chain.
128 * Link the kernel buffer new into the buffer chain
129 * after the buffer prev.
130 * KB_UNLINKHEAD(head, next)
131 * Unlink the kernel buffer from the head of the buffer
132 * chain headed by head. The buffer head will be freed
133 * and the new chain head will be placed in next.
134 * KB_UNLINK(old, prev, next)
135 * Unlink the kernel buffer old with previous buffer prev
136 * from its buffer chain. The following buffer in the
137 * chain will be placed in next and the buffer old will
139 * KB_ISPKT(bfr) Tests whether bfr is a packet header buffer.
140 * KB_ISEXT(bfr) Tests whether bfr has external storage.
141 * KB_BFRSTART(bfr, x, t)
142 * Sets x (cast to type t) to point to the start of the
143 * buffer space in bfr.
144 * KB_BFREND(bfr, x, t)
145 * Sets x (cast to type t) to point one byte past the end
146 * of the buffer space in bfr.
147 * KB_BFRLEN(bfr) Returns length of buffer space in bfr.
148 * KB_DATASTART(bfr, x, t)
149 * Sets x (cast to type t) to point to the start of the
150 * buffer data contained in bfr.
151 * KB_DATAEND(bfr, x, t)
152 * Sets x (cast to type t) to point one byte past the end
153 * of the buffer data contained in bfr.
154 * KB_HEADSET(bfr, n) Sets the start address for buffer data in buffer bfr to
155 * n bytes from the beginning of the buffer space.
156 * KB_HEADMOVE(bfr, n) Adjust buffer data controls to move data down (n > 0)
157 * or up (n < 0) n bytes in the buffer bfr.
158 * KB_HEADADJ(bfr, n) Adjust buffer data controls to add (n > 0) or subtract
159 * (n < 0) n bytes of data to/from the beginning of bfr.
160 * KB_TAILADJ(bfr, n) Adjust buffer data controls to add (n > 0) or subtract
161 * (n < 0) n bytes of data to/from the end of bfr.
162 * KB_TAILALIGN(bfr, n) Set buffer data controls to place an object of size n
163 * at the end of bfr, longword aligned.
164 * KB_HEADROOM(bfr, n) Set n to the amount of buffer space available before
165 * the start of data in bfr.
166 * KB_TAILROOM(bfr, n) Set n to the amount of buffer space available after
167 * the end of data in bfr.
168 * KB_PLENGET(bfr, n) Set n to bfr's packet length.
169 * KB_PLENSET(bfr, n) Set bfr's packet length to n.
170 * KB_PLENADJ(bfr, n) Adjust total packet length by n bytes.
173 #include <sys/mbuf.h>
174 typedef struct mbuf KBuffer
;
176 #define KB_F_WAIT MB_WAIT
177 #define KB_F_NOWAIT MB_DONTWAIT
179 #define KB_T_HEADER MT_HEADER
180 #define KB_T_DATA MT_DATA
182 #define KB_COPYALL M_COPYALL
184 #define KB_NEXT(bfr) (bfr)->m_next
185 #define KB_LEN(bfr) (bfr)->m_len
186 #define KB_QNEXT(bfr) (bfr)->m_nextpkt
187 #define KB_ALLOC(bfr, size, flags, type) { \
188 if ((size) <= MLEN) { \
189 MGET((bfr), (flags), (type)); \
193 #define KB_ALLOCPKT(bfr, size, flags, type) { \
194 if ((size) <= MHLEN) { \
195 MGETHDR((bfr), (flags), (type)); \
199 #define KB_ALLOCEXT(bfr, size, flags, type) { \
200 if ((size) <= MCLBYTES) { \
201 MGET((bfr), (flags), (type)); \
202 if ((bfr) != NULL) { \
203 MCLGET((bfr), (flags)); \
204 if (((bfr)->m_flags & M_EXT) == 0) { \
212 #define KB_FREEONE(bfr, nxt) { \
213 (nxt) = m_free(bfr); \
215 #define KB_FREEALL(bfr) { \
218 #define KB_COPY(bfr, off, len, new, flags) { \
219 (new) = m_copym((bfr), (off), (len), (flags)); \
221 #define KB_COPYDATA(bfr, off, len, datap) \
222 (m_copydata((bfr), (off), (len), (datap)), 0)
223 #define KB_PULLUP(bfr, n, new) { \
224 (new) = m_pullup((bfr), (n)); \
226 #define KB_LINKHEAD(new, head) { \
227 if ((head) && KB_ISPKT(new) && KB_ISPKT(head)) {\
228 M_MOVE_PKTHDR((new), (head)); \
230 (new)->m_next = (head); \
232 #define KB_LINK(new, prev) { \
233 (new)->m_next = (prev)->m_next; \
234 (prev)->m_next = (new); \
236 #define KB_UNLINKHEAD(head, next) { \
237 next = m_free((head)); \
239 #define KB_UNLINK(old, prev, next) { \
240 next = m_free((old)); \
241 (prev)->m_next = (next); \
243 #define KB_ISPKT(bfr) (((bfr)->m_flags & M_PKTHDR) != 0)
244 #define KB_ISEXT(bfr) (((bfr)->m_flags & M_EXT) != 0)
245 #define KB_BFRSTART(bfr, x, t) { \
246 if ((bfr)->m_flags & M_EXT) \
247 (x) = (t)((bfr)->m_ext.ext_buf); \
248 else if ((bfr)->m_flags & M_PKTHDR) \
249 (x) = (t)(&(bfr)->m_pktdat); \
251 (x) = (t)((bfr)->m_dat); \
253 #define KB_BFREND(bfr, x, t) { \
254 if ((bfr)->m_flags & M_EXT) \
255 (x) = (t)((bfr)->m_ext.ext_buf + (bfr)->m_ext.ext_size);\
256 else if ((bfr)->m_flags & M_PKTHDR) \
257 (x) = (t)(&(bfr)->m_pktdat + MHLEN); \
259 (x) = (t)((bfr)->m_dat + MLEN); \
261 #define KB_BFRLEN(bfr) \
262 (((bfr)->m_flags & M_EXT) ? (bfr)->m_ext.ext_size : \
263 (((bfr)->m_flags & M_PKTHDR) ? MHLEN : MLEN))
264 #define KB_DATASTART(bfr, x, t) { \
265 (x) = mtod((bfr), t); \
267 #define KB_DATAEND(bfr, x, t) { \
268 (x) = (t)(mtod((bfr), caddr_t) + (bfr)->m_len); \
270 #define KB_HEADSET(bfr, n) { \
271 if ((bfr)->m_flags & M_EXT) \
272 (bfr)->m_data = (bfr)->m_ext.ext_buf + (n); \
273 else if ((bfr)->m_flags & M_PKTHDR) \
274 (bfr)->m_data = (bfr)->m_pktdat + (n); \
276 (bfr)->m_data = (bfr)->m_dat + (n); \
278 #define KB_HEADMOVE(bfr, n) { \
279 (bfr)->m_data += (n); \
281 #define KB_HEADADJ(bfr, n) { \
282 (bfr)->m_len += (n); \
283 (bfr)->m_data -= (n); \
285 #define KB_TAILADJ(bfr, n) { \
286 (bfr)->m_len += (n); \
288 #define KB_TAILALIGN(bfr, n) { \
289 (bfr)->m_len = (n); \
290 if ((bfr)->m_flags & M_EXT) \
291 (bfr)->m_data = (caddr_t)(((u_int)(bfr)->m_ext.ext_buf \
292 + (bfr)->m_ext.ext_size - (n)) & ~(sizeof(long) - 1));\
294 (bfr)->m_data = (caddr_t)(((u_int)(bfr)->m_dat + MLEN - (n)) \
295 & ~(sizeof(long) - 1)); \
297 #define KB_HEADROOM(bfr, n) { \
298 /* n = M_LEADINGSPACE(bfr) XXX */ \
299 (n) = ((bfr)->m_flags & M_EXT ? (bfr)->m_data - (bfr)->m_ext.ext_buf : \
300 (bfr)->m_flags & M_PKTHDR ? (bfr)->m_data - (bfr)->m_pktdat : \
301 (bfr)->m_data - (bfr)->m_dat); \
303 #define KB_TAILROOM(bfr, n) { \
304 (n) = M_TRAILINGSPACE(bfr); \
306 #define KB_PLENGET(bfr, n) { \
307 (n) = (bfr)->m_pkthdr.len; \
309 #define KB_PLENSET(bfr, n) { \
310 (bfr)->m_pkthdr.len = (n); \
312 #define KB_PLENADJ(bfr, n) { \
313 (bfr)->m_pkthdr.len += (n); \
319 * KTimeout_ret Typedef for timeout() function return
321 * KT_TIME(t) Sets t to the current time.
324 typedef void KTimeout_ret
;
325 #define KT_TIME(t) microtime(&t)
327 #endif /* ATM_KERNEL */
330 #define MAX(a,b) max((a),(b))
333 #define MIN(a,b) min((a),(b))
336 #endif /* _NETATM_PORT_H */