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.
31 * System Configuration
32 * --------------------
38 #ifndef _NETATM_PORT_H
39 #define _NETATM_PORT_H
42 * Try to ensure that this system is supported
44 #if (defined(BSD) && (BSD >= 199103))
46 /* 4.3 BSD Net2 based */
55 #error "Undefined/unsupported system type"
61 * Kernel memory management
63 * KM_ALLOC(size, type, flags)
64 * Returns an allocated kernel memory chunk of size bytes.
65 * KM_FREE(addr, size, type)
66 * Free a kernel memory chunk of size bytes.
68 * Compares len bytes of data from b1 against b2.
69 * KM_COPY(from, to, len)
70 * Copies len bytes of data from from to to.
72 * Zeros len bytes of data from addr.
76 #if (defined(BSD) && (BSD >= 199103))
77 #include <sys/malloc.h>
78 #define KM_ALLOC(size, type, flags) malloc((size), (type), (flags))
79 #define KM_FREE(addr, size, type) free((addr), (type))
81 #include <sys/kmem_alloc.h>
82 #define KM_ALLOC(size, type, flags) kmem_alloc(size)
83 #define KM_FREE(addr, size, type) kmem_free((addr), (size))
87 #define KM_CMP(b1, b2, len) bcmp((void *)(b1), (void *)(b2),\
89 #define KM_COPY(from, to, len) bcopy((void *)(from), (void *)(to),\
91 #define KM_ZERO(addr, len) bzero((void *)(addr), (len))
93 #define XM_COPY(f, t, l) KM_COPY((f), (t), (l))
98 * User-space memory management
100 * UM_ALLOC(size) Returns an allocated kernel memory chunk of size bytes.
101 * UM_FREE(addr) Free a kernel memory chunk of size bytes.
102 * UM_COPY(from, to, len)
103 * Copies len bytes of data from from to to.
104 * UM_ZERO(addr, len) Zeros len bytes of data from addr.
107 #if (defined(BSD) && (BSD >= 199103))
108 #define UM_ALLOC(size) malloc((size_t)(size))
109 #define UM_FREE(addr) free((void *)(addr))
110 #define UM_COPY(from, to, len) bcopy((void *)(from), (void *)(to),\
112 #define UM_ZERO(addr, len) bzero((void *)(addr), (size_t)(len))
114 #define UM_ALLOC(size) malloc(size)
115 #define UM_FREE(addr) free((char *)(addr))
116 #define UM_COPY(from, to, len) bcopy((char *)(from), (char *)(to), (len))
117 #define UM_ZERO(addr, len) bzero((char *)(addr), (len))
120 #define XM_COPY(f, t, l) UM_COPY((f), (t), (l))
122 #endif /* ATM_KERNEL */
129 * KBuffer Typedef for a kernel buffer.
131 * KB_NEXT(bfr) Access next buffer in chain (r/w).
132 * KB_LEN(bfr) Access length of data in this buffer (r/w).
133 * KB_QNEXT(bfr) Access next buffer in queue (r/w).
135 * KB_ALLOC(bfr, size, flags, type)
136 * Allocates a new kernel buffer of at least size bytes.
137 * KB_ALLOCPKT(bfr, size, flags, type)
138 * Allocates a new kernel packet header buffer of at
140 * KB_ALLOCEXT(bfr, size, flags, type)
141 * Allocates a new kernel buffer with external storage
142 * of at least size bytes.
143 * KB_FREEONE(bfr, nxt) Free buffer bfr and set next buffer in chain in nxt.
144 * KB_FREEALL(bfr) Free bfr's entire buffer chain.
145 * KB_COPY(bfr, off, len, new, flags)
146 * Copy len bytes of user data from buffer bfr starting at
147 * byte offset off and return new buffer chain in new.
148 * If len is KB_COPYALL, copy until end of chain.
149 * KB_COPYDATA(bfr, off, len, datap)
150 * Copy data from buffer bfr starting at byte offset off
151 * for len bytes into the data area pointed to by datap.
152 * Returns the number of bytes not copied to datap.
153 * KB_PULLUP(bfr, n, new)
154 * Get at least the first n bytes of data in the buffer
155 * chain headed by bfr contiguous in the first buffer.
156 * Returns the (potentially new) head of the chain in new.
157 * On failure the chain is freed and NULL is returned.
158 * KB_LINKHEAD(new, head)
159 * Link the kernel buffer new at the head of the buffer
160 * chain headed by head. If both new and head are
161 * packet header buffers, new will become the packet
162 * header for the chain.
164 * Link the kernel buffer new into the buffer chain
165 * after the buffer prev.
166 * KB_UNLINKHEAD(head, next)
167 * Unlink the kernel buffer from the head of the buffer
168 * chain headed by head. The buffer head will be freed
169 * and the new chain head will be placed in next.
170 * KB_UNLINK(old, prev, next)
171 * Unlink the kernel buffer old with previous buffer prev
172 * from its buffer chain. The following buffer in the
173 * chain will be placed in next and the buffer old will
175 * KB_ISPKT(bfr) Tests whether bfr is a packet header buffer.
176 * KB_ISEXT(bfr) Tests whether bfr has external storage.
177 * KB_BFRSTART(bfr, x, t)
178 * Sets x (cast to type t) to point to the start of the
179 * buffer space in bfr.
180 * KB_BFREND(bfr, x, t)
181 * Sets x (cast to type t) to point one byte past the end
182 * of the buffer space in bfr.
183 * KB_BFRLEN(bfr) Returns length of buffer space in bfr.
184 * KB_DATASTART(bfr, x, t)
185 * Sets x (cast to type t) to point to the start of the
186 * buffer data contained in bfr.
187 * KB_DATAEND(bfr, x, t)
188 * Sets x (cast to type t) to point one byte past the end
189 * of the buffer data contained in bfr.
190 * KB_HEADSET(bfr, n) Sets the start address for buffer data in buffer bfr to
191 * n bytes from the beginning of the buffer space.
192 * KB_HEADMOVE(bfr, n) Adjust buffer data controls to move data down (n > 0)
193 * or up (n < 0) n bytes in the buffer bfr.
194 * KB_HEADADJ(bfr, n) Adjust buffer data controls to add (n > 0) or subtract
195 * (n < 0) n bytes of data to/from the beginning of bfr.
196 * KB_TAILADJ(bfr, n) Adjust buffer data controls to add (n > 0) or subtract
197 * (n < 0) n bytes of data to/from the end of bfr.
198 * KB_TAILALIGN(bfr, n) Set buffer data controls to place an object of size n
199 * at the end of bfr, longword aligned.
200 * KB_HEADROOM(bfr, n) Set n to the amount of buffer space available before
201 * the start of data in bfr.
202 * KB_TAILROOM(bfr, n) Set n to the amount of buffer space available after
203 * the end of data in bfr.
204 * KB_PLENGET(bfr, n) Set n to bfr's packet length.
205 * KB_PLENSET(bfr, n) Set bfr's packet length to n.
206 * KB_PLENADJ(bfr, n) Adjust total packet length by n bytes.
210 #include <sys/mbuf.h>
211 typedef struct mbuf KBuffer;
213 #define KB_F_WAIT M_WAIT
214 #define KB_F_NOWAIT M_DONTWAIT
216 #define KB_T_HEADER MT_HEADER
217 #define KB_T_DATA MT_DATA
219 #define KB_COPYALL M_COPYALL
223 #define KB_NEXT(bfr) (bfr)->m_next
224 #define KB_LEN(bfr) (bfr)->m_len
225 #define KB_QNEXT(bfr) (bfr)->m_nextpkt
226 #define KB_ALLOC(bfr, size, flags, type) { \
227 if ((size) <= MLEN) { \
228 MGET((bfr), (flags), (type)); \
232 #define KB_ALLOCPKT(bfr, size, flags, type) { \
233 if ((size) <= MHLEN) { \
234 MGETHDR((bfr), (flags), (type)); \
238 #define KB_ALLOCEXT(bfr, size, flags, type) { \
239 if ((size) <= MCLBYTES) { \
240 MGET((bfr), (flags), (type)); \
241 if ((bfr) != NULL) { \
242 MCLGET((bfr), (flags)); \
243 if (((bfr)->m_flags & M_EXT) == 0) { \
251 #define KB_FREEONE(bfr, nxt) { \
252 (nxt) = m_free(bfr); \
254 #define KB_FREEALL(bfr) { \
257 #define KB_COPY(bfr, off, len, new, flags) { \
258 (new) = m_copym((bfr), (off), (len), (flags)); \
260 #define KB_COPYDATA(bfr, off, len, datap) \
261 (m_copydata((bfr), (off), (len), (datap)), 0)
262 #define KB_PULLUP(bfr, n, new) { \
263 (new) = m_pullup((bfr), (n)); \
265 #define KB_LINKHEAD(new, head) { \
266 if ((head) && KB_ISPKT(new) && KB_ISPKT(head)) {\
267 M_COPY_PKTHDR((new), (head)); \
268 (head)->m_flags &= ~M_PKTHDR; \
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 MFREE((head), (next)); \
279 #define KB_UNLINK(old, prev, next) { \
280 MFREE((old), (next)); \
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 MFREE((head), (next)); \
412 #define KB_UNLINK(old, prev, next) { \
413 MFREE((old), (next)); \
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 */