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.2 2003/06/17 04:28:49 dillon Exp $
32 * System Configuration
33 * --------------------
39 #ifndef _NETATM_PORT_H
40 #define _NETATM_PORT_H
43 * Try to ensure that this system is supported
45 #if (defined(BSD) && (BSD >= 199103))
47 /* 4.3 BSD Net2 based */
56 #error "Undefined/unsupported system type"
62 * Kernel memory management
64 * KM_ALLOC(size, type, flags)
65 * Returns an allocated kernel memory chunk of size bytes.
66 * KM_FREE(addr, size, type)
67 * Free a kernel memory chunk of size bytes.
69 * Compares len bytes of data from b1 against b2.
70 * KM_COPY(from, to, len)
71 * Copies len bytes of data from from to to.
73 * Zeros len bytes of data from addr.
77 #if (defined(BSD) && (BSD >= 199103))
78 #include <sys/malloc.h>
79 #define KM_ALLOC(size, type, flags) malloc((size), (type), (flags))
80 #define KM_FREE(addr, size, type) free((addr), (type))
82 #include <sys/kmem_alloc.h>
83 #define KM_ALLOC(size, type, flags) kmem_alloc(size)
84 #define KM_FREE(addr, size, type) kmem_free((addr), (size))
88 #define KM_CMP(b1, b2, len) bcmp((void *)(b1), (void *)(b2),\
90 #define KM_COPY(from, to, len) bcopy((void *)(from), (void *)(to),\
92 #define KM_ZERO(addr, len) bzero((void *)(addr), (len))
94 #define XM_COPY(f, t, l) KM_COPY((f), (t), (l))
99 * User-space memory management
101 * UM_ALLOC(size) Returns an allocated kernel memory chunk of size bytes.
102 * UM_FREE(addr) Free a kernel memory chunk of size bytes.
103 * UM_COPY(from, to, len)
104 * Copies len bytes of data from from to to.
105 * UM_ZERO(addr, len) Zeros len bytes of data from addr.
108 #if (defined(BSD) && (BSD >= 199103))
109 #define UM_ALLOC(size) malloc((size_t)(size))
110 #define UM_FREE(addr) free((void *)(addr))
111 #define UM_COPY(from, to, len) bcopy((void *)(from), (void *)(to),\
113 #define UM_ZERO(addr, len) bzero((void *)(addr), (size_t)(len))
115 #define UM_ALLOC(size) malloc(size)
116 #define UM_FREE(addr) free((char *)(addr))
117 #define UM_COPY(from, to, len) bcopy((char *)(from), (char *)(to), (len))
118 #define UM_ZERO(addr, len) bzero((char *)(addr), (len))
121 #define XM_COPY(f, t, l) UM_COPY((f), (t), (l))
123 #endif /* ATM_KERNEL */
130 * KBuffer Typedef for a kernel buffer.
132 * KB_NEXT(bfr) Access next buffer in chain (r/w).
133 * KB_LEN(bfr) Access length of data in this buffer (r/w).
134 * KB_QNEXT(bfr) Access next buffer in queue (r/w).
136 * KB_ALLOC(bfr, size, flags, type)
137 * Allocates a new kernel buffer of at least size bytes.
138 * KB_ALLOCPKT(bfr, size, flags, type)
139 * Allocates a new kernel packet header buffer of at
141 * KB_ALLOCEXT(bfr, size, flags, type)
142 * Allocates a new kernel buffer with external storage
143 * of at least size bytes.
144 * KB_FREEONE(bfr, nxt) Free buffer bfr and set next buffer in chain in nxt.
145 * KB_FREEALL(bfr) Free bfr's entire buffer chain.
146 * KB_COPY(bfr, off, len, new, flags)
147 * Copy len bytes of user data from buffer bfr starting at
148 * byte offset off and return new buffer chain in new.
149 * If len is KB_COPYALL, copy until end of chain.
150 * KB_COPYDATA(bfr, off, len, datap)
151 * Copy data from buffer bfr starting at byte offset off
152 * for len bytes into the data area pointed to by datap.
153 * Returns the number of bytes not copied to datap.
154 * KB_PULLUP(bfr, n, new)
155 * Get at least the first n bytes of data in the buffer
156 * chain headed by bfr contiguous in the first buffer.
157 * Returns the (potentially new) head of the chain in new.
158 * On failure the chain is freed and NULL is returned.
159 * KB_LINKHEAD(new, head)
160 * Link the kernel buffer new at the head of the buffer
161 * chain headed by head. If both new and head are
162 * packet header buffers, new will become the packet
163 * header for the chain.
165 * Link the kernel buffer new into the buffer chain
166 * after the buffer prev.
167 * KB_UNLINKHEAD(head, next)
168 * Unlink the kernel buffer from the head of the buffer
169 * chain headed by head. The buffer head will be freed
170 * and the new chain head will be placed in next.
171 * KB_UNLINK(old, prev, next)
172 * Unlink the kernel buffer old with previous buffer prev
173 * from its buffer chain. The following buffer in the
174 * chain will be placed in next and the buffer old will
176 * KB_ISPKT(bfr) Tests whether bfr is a packet header buffer.
177 * KB_ISEXT(bfr) Tests whether bfr has external storage.
178 * KB_BFRSTART(bfr, x, t)
179 * Sets x (cast to type t) to point to the start of the
180 * buffer space in bfr.
181 * KB_BFREND(bfr, x, t)
182 * Sets x (cast to type t) to point one byte past the end
183 * of the buffer space in bfr.
184 * KB_BFRLEN(bfr) Returns length of buffer space in bfr.
185 * KB_DATASTART(bfr, x, t)
186 * Sets x (cast to type t) to point to the start of the
187 * buffer data contained in bfr.
188 * KB_DATAEND(bfr, x, t)
189 * Sets x (cast to type t) to point one byte past the end
190 * of the buffer data contained in bfr.
191 * KB_HEADSET(bfr, n) Sets the start address for buffer data in buffer bfr to
192 * n bytes from the beginning of the buffer space.
193 * KB_HEADMOVE(bfr, n) Adjust buffer data controls to move data down (n > 0)
194 * or up (n < 0) n bytes in the buffer bfr.
195 * KB_HEADADJ(bfr, n) Adjust buffer data controls to add (n > 0) or subtract
196 * (n < 0) n bytes of data to/from the beginning of bfr.
197 * KB_TAILADJ(bfr, n) Adjust buffer data controls to add (n > 0) or subtract
198 * (n < 0) n bytes of data to/from the end of bfr.
199 * KB_TAILALIGN(bfr, n) Set buffer data controls to place an object of size n
200 * at the end of bfr, longword aligned.
201 * KB_HEADROOM(bfr, n) Set n to the amount of buffer space available before
202 * the start of data in bfr.
203 * KB_TAILROOM(bfr, n) Set n to the amount of buffer space available after
204 * the end of data in bfr.
205 * KB_PLENGET(bfr, n) Set n to bfr's packet length.
206 * KB_PLENSET(bfr, n) Set bfr's packet length to n.
207 * KB_PLENADJ(bfr, n) Adjust total packet length by n bytes.
211 #include <sys/mbuf.h>
212 typedef struct mbuf KBuffer;
214 #define KB_F_WAIT M_WAIT
215 #define KB_F_NOWAIT M_DONTWAIT
217 #define KB_T_HEADER MT_HEADER
218 #define KB_T_DATA MT_DATA
220 #define KB_COPYALL M_COPYALL
224 #define KB_NEXT(bfr) (bfr)->m_next
225 #define KB_LEN(bfr) (bfr)->m_len
226 #define KB_QNEXT(bfr) (bfr)->m_nextpkt
227 #define KB_ALLOC(bfr, size, flags, type) { \
228 if ((size) <= MLEN) { \
229 MGET((bfr), (flags), (type)); \
233 #define KB_ALLOCPKT(bfr, size, flags, type) { \
234 if ((size) <= MHLEN) { \
235 MGETHDR((bfr), (flags), (type)); \
239 #define KB_ALLOCEXT(bfr, size, flags, type) { \
240 if ((size) <= MCLBYTES) { \
241 MGET((bfr), (flags), (type)); \
242 if ((bfr) != NULL) { \
243 MCLGET((bfr), (flags)); \
244 if (((bfr)->m_flags & M_EXT) == 0) { \
252 #define KB_FREEONE(bfr, nxt) { \
253 (nxt) = m_free(bfr); \
255 #define KB_FREEALL(bfr) { \
258 #define KB_COPY(bfr, off, len, new, flags) { \
259 (new) = m_copym((bfr), (off), (len), (flags)); \
261 #define KB_COPYDATA(bfr, off, len, datap) \
262 (m_copydata((bfr), (off), (len), (datap)), 0)
263 #define KB_PULLUP(bfr, n, new) { \
264 (new) = m_pullup((bfr), (n)); \
266 #define KB_LINKHEAD(new, head) { \
267 if ((head) && KB_ISPKT(new) && KB_ISPKT(head)) {\
268 M_MOVE_PKTHDR((new), (head)); \
270 (new)->m_next = (head); \
272 #define KB_LINK(new, prev) { \
273 (new)->m_next = (prev)->m_next; \
274 (prev)->m_next = (new); \
276 #define KB_UNLINKHEAD(head, next) { \
277 next = m_free((head)); \
279 #define KB_UNLINK(old, prev, next) { \
280 next = m_free((old)); \
281 (prev)->m_next = (next); \
283 #define KB_ISPKT(bfr) (((bfr)->m_flags & M_PKTHDR) != 0)
284 #define KB_ISEXT(bfr) (((bfr)->m_flags & M_EXT) != 0)
285 #define KB_BFRSTART(bfr, x, t) { \
286 if ((bfr)->m_flags & M_EXT) \
287 (x) = (t)((bfr)->m_ext.ext_buf); \
288 else if ((bfr)->m_flags & M_PKTHDR) \
289 (x) = (t)(&(bfr)->m_pktdat); \
291 (x) = (t)((bfr)->m_dat); \
293 #define KB_BFREND(bfr, x, t) { \
294 if ((bfr)->m_flags & M_EXT) \
295 (x) = (t)((bfr)->m_ext.ext_buf + (bfr)->m_ext.ext_size);\
296 else if ((bfr)->m_flags & M_PKTHDR) \
297 (x) = (t)(&(bfr)->m_pktdat + MHLEN); \
299 (x) = (t)((bfr)->m_dat + MLEN); \
301 #define KB_BFRLEN(bfr) \
302 (((bfr)->m_flags & M_EXT) ? (bfr)->m_ext.ext_size : \
303 (((bfr)->m_flags & M_PKTHDR) ? MHLEN : MLEN))
304 #define KB_DATASTART(bfr, x, t) { \
305 (x) = mtod((bfr), t); \
307 #define KB_DATAEND(bfr, x, t) { \
308 (x) = (t)(mtod((bfr), caddr_t) + (bfr)->m_len); \
310 #define KB_HEADSET(bfr, n) { \
311 if ((bfr)->m_flags & M_EXT) \
312 (bfr)->m_data = (bfr)->m_ext.ext_buf + (n); \
313 else if ((bfr)->m_flags & M_PKTHDR) \
314 (bfr)->m_data = (bfr)->m_pktdat + (n); \
316 (bfr)->m_data = (bfr)->m_dat + (n); \
318 #define KB_HEADMOVE(bfr, n) { \
319 (bfr)->m_data += (n); \
321 #define KB_HEADADJ(bfr, n) { \
322 (bfr)->m_len += (n); \
323 (bfr)->m_data -= (n); \
325 #define KB_TAILADJ(bfr, n) { \
326 (bfr)->m_len += (n); \
328 #define KB_TAILALIGN(bfr, n) { \
329 (bfr)->m_len = (n); \
330 if ((bfr)->m_flags & M_EXT) \
331 (bfr)->m_data = (caddr_t)(((u_int)(bfr)->m_ext.ext_buf \
332 + (bfr)->m_ext.ext_size - (n)) & ~(sizeof(long) - 1));\
334 (bfr)->m_data = (caddr_t)(((u_int)(bfr)->m_dat + MLEN - (n)) \
335 & ~(sizeof(long) - 1)); \
337 #define KB_HEADROOM(bfr, n) { \
338 /* n = M_LEADINGSPACE(bfr) XXX */ \
339 (n) = ((bfr)->m_flags & M_EXT ? (bfr)->m_data - (bfr)->m_ext.ext_buf : \
340 (bfr)->m_flags & M_PKTHDR ? (bfr)->m_data - (bfr)->m_pktdat : \
341 (bfr)->m_data - (bfr)->m_dat); \
343 #define KB_TAILROOM(bfr, n) { \
344 (n) = M_TRAILINGSPACE(bfr); \
346 #define KB_PLENGET(bfr, n) { \
347 (n) = (bfr)->m_pkthdr.len; \
349 #define KB_PLENSET(bfr, n) { \
350 (bfr)->m_pkthdr.len = (n); \
352 #define KB_PLENADJ(bfr, n) { \
353 (bfr)->m_pkthdr.len += (n); \
357 #else /* ! BSD >= 199103 */
360 #define KB_NEXT(bfr) (bfr)->m_next
361 #define KB_LEN(bfr) (bfr)->m_len
362 #define KB_QNEXT(bfr) (bfr)->m_act
363 #define KB_ALLOC(bfr, size, flags, type) { \
364 if ((size) <= MLEN) { \
365 MGET((bfr), (flags), (type)); \
369 #define KB_ALLOCPKT(bfr, size, flags, type) { \
370 if ((size) <= MLEN) { \
371 MGET((bfr), (flags), (type)); \
375 #define KB_ALLOCEXT(bfr, size, flags, type) { \
376 if ((size) <= MCLBYTES) { \
377 MGET((bfr), (flags), (type)); \
378 if ((bfr) != NULL) { \
380 if ((bfr)->m_len != MCLBYTES) { \
388 #define KB_FREEONE(bfr, nxt) { \
389 (nxt) = m_free(bfr); \
391 #define KB_FREEALL(bfr) { \
394 #define KB_COPY(bfr, off, len, new, flags) { \
395 (new) = m_copy((bfr), (off), (len)); \
397 #define KB_COPYDATA(bfr, off, len, datap) \
398 m_cpytoc((bfr), (off), (len), (datap))
399 #define KB_PULLUP(bfr, n, new) { \
400 (new) = m_pullup((bfr), (n)); \
402 #define KB_LINKHEAD(new, head) { \
403 (new)->m_next = (head); \
405 #define KB_LINK(new, prev) { \
406 (new)->m_next = (prev)->m_next; \
407 (prev)->m_next = (new); \
409 #define KB_UNLINKHEAD(head, next) { \
410 next = m_free((head)); \
412 #define KB_UNLINK(old, prev, next) { \
413 next = m_free((old)); \
414 (prev)->m_next = (next); \
416 #define KB_ISPKT(bfr) (0)
417 #define KB_ISEXT(bfr) M_HASCL(bfr)
418 #define KB_BFRSTART(bfr, x, t) { \
419 if (M_HASCL(bfr)) { \
420 if ((bfr)->m_cltype == MCL_STATIC) \
421 (x) = (t)(mtod((bfr), int) & ~(MCLBYTES - 1)); \
425 (x) = (t)((bfr)->m_dat); \
427 #define KB_BFREND(bfr, x, t) { \
428 if (M_HASCL(bfr)) { \
429 if ((bfr)->m_cltype == MCL_STATIC) \
430 (x) = (t)((mtod((bfr), int) & ~(MCLBYTES - 1)) \
435 (x) = (t)((bfr)->m_dat + MLEN); \
437 #define KB_BFRLEN(bfr) \
438 (M_HASCL(bfr) ? (((bfr)->m_cltype == MCL_STATIC) ? MCLBYTES : 0) : MLEN)
439 #define KB_DATASTART(bfr, x, t) { \
440 (x) = mtod((bfr), t); \
442 #define KB_DATAEND(bfr, x, t) { \
443 (x) = (t)(mtod((bfr), caddr_t) + (bfr)->m_len); \
445 #define KB_HEADSET(bfr, n) { \
446 if (M_HASCL(bfr)) { \
447 /* Assume cluster buffer is empty XXX */\
448 (bfr)->m_off += (n); \
450 (bfr)->m_off = MMINOFF + (n); \
452 #define KB_HEADMOVE(bfr, n) { \
453 (bfr)->m_off += (n); \
455 #define KB_HEADADJ(bfr, n) { \
456 (bfr)->m_len += (n); \
457 (bfr)->m_off -= (n); \
459 #define KB_TAILADJ(bfr, n) { \
460 (bfr)->m_len += (n); \
462 #define KB_TAILALIGN(bfr, n) { \
463 (bfr)->m_len = (n); \
464 if (M_HASCL(bfr)) { \
465 if ((bfr)->m_cltype == MCL_STATIC) \
466 (bfr)->m_off = (int)(((mtod((bfr), int) \
467 & ~(MCLBYTES - 1)) + MCLBYTES - (n)) \
468 & ~(sizeof(long) - 1)) - (int)(bfr); \
469 /* Out of luck for loaned buffers */ \
471 (bfr)->m_off = (MMAXOFF - (n)) & ~(sizeof(long) - 1); \
473 #define KB_HEADROOM(bfr, n) { \
474 if (M_HASCL(bfr)) { \
475 if ((bfr)->m_cltype == MCL_STATIC) \
476 (n) = mtod((bfr), int) & (MCLBYTES - 1); \
480 (n) = (bfr)->m_off - MMINOFF; \
482 #define KB_TAILROOM(bfr, n) { \
483 if (M_HASCL(bfr)) { \
484 if ((bfr)->m_cltype == MCL_STATIC) \
485 (n) = MCLBYTES - ((mtod((bfr), int) + (bfr)->m_len) \
490 (n) = MMAXOFF - ((bfr)->m_off + (bfr)->m_len); \
492 #define KB_PLENGET(bfr, n) { \
494 for ((n) = 0, zz = (bfr); zz; zz = zz->m_next) \
497 #define KB_PLENSET(bfr, n) { \
499 #define KB_PLENADJ(bfr, n) { \
503 #endif /* ! BSD >= 199103 */
505 #endif /* defined(BSD) */
511 * KTimeout_ret Typedef for timeout() function return
513 * KT_TIME(t) Sets t to the current time.
516 #if (defined(BSD) && (BSD >= 199306))
517 typedef void KTimeout_ret;
519 typedef int KTimeout_ret;
521 #if (defined(BSD) && (BSD >= 199103))
522 #define KT_TIME(t) microtime(&t)
524 #define KT_TIME(t) uniqtime(&t)
526 #define KT_TIME(t) ((t) = time)
529 #endif /* ATM_KERNEL */
532 #if BYTE_ORDER == BIG_ENDIAN
538 #define NTOHL(x) (x) = ntohl((u_long)(x))
539 #define NTOHS(x) (x) = ntohs((u_short)(x))
540 #define HTONL(x) (x) = htonl((u_long)(x))
541 #define HTONS(x) (x) = htons((u_short)(x))
546 #define MAX(a,b) max((a),(b))
549 #define MIN(a,b) min((a),(b))
552 #if (!(defined(BSD) && (BSD >= 199306)))
553 #ifndef __BIT_TYPES_DEFINED__
554 #define __BIT_TYPES_DEFINED__
556 typedef unsigned char u_int8_t;
557 typedef short int16_t;
558 typedef unsigned short u_int16_t;
560 typedef unsigned int u_int32_t;
564 #endif /* _NETATM_PORT_H */