Vendor import of netgraph from FreeBSD-current 20080626
[dragonfly.git] / sys / netgraph7 / atm / sscfu / ng_sscfu_cust.h
blob4605ad53f36ae823851e7a6a169f6689e37da5e8
1 /*-
2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 * All rights reserved.
6 * Author: Harti Brandt <harti@freebsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * Customisation of the SSCFU code to ng_sscfu.
31 * $FreeBSD: src/sys/netgraph/atm/sscfu/ng_sscfu_cust.h,v 1.2 2005/01/07 01:45:41 imp Exp $
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/kernel.h>
36 #include <sys/mbuf.h>
37 #include <sys/queue.h>
38 #include <sys/callout.h>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <machine/stdarg.h>
44 * Allocate zeroed or non-zeroed memory of some size and cast it.
45 * Return NULL on failure.
47 #ifndef SSCFU_DEBUG
49 #define MEMINIT() \
50 MALLOC_DECLARE(M_NG_SSCFU); \
51 DECL_SIGQ_GET
53 #define MEMZALLOC(PTR, CAST, SIZE) \
54 ((PTR) = (CAST)malloc((SIZE), M_NG_SSCFU, M_NOWAIT | M_ZERO))
55 #define MEMFREE(PTR) \
56 free(PTR, M_NG_SSCFU)
58 #define SIG_ALLOC(PTR) \
59 MEMZALLOC(PTR, struct sscfu_sig *, sizeof(struct sscfu_sig))
60 #define SIG_FREE(PTR) \
61 MEMFREE(PTR)
63 #else
65 #define MEMINIT() \
66 MALLOC_DEFINE(M_NG_SSCFU_INS, "sscfu_ins", "SSCFU instances"); \
67 MALLOC_DEFINE(M_NG_SSCFU_SIG, "sscfu_sig", "SSCFU signals"); \
68 DECL_SIGQ_GET
70 #define MEMZALLOC(PTR, CAST, SIZE) \
71 ((PTR) = (CAST)malloc((SIZE), M_NG_SSCFU_INS, M_NOWAIT | M_ZERO))
72 #define MEMFREE(PTR) \
73 FREE(PTR, M_NG_SSCFU_INS)
75 #define SIG_ALLOC(PTR) \
76 ((PTR) = malloc(sizeof(struct sscfu_sig), \
77 M_NG_SSCFU_SIG, M_NOWAIT | M_ZERO))
78 #define SIG_FREE(PTR) \
79 FREE(PTR, M_NG_SSCFU_SIG)
81 #endif
85 * Signal queues
87 typedef TAILQ_ENTRY(sscfu_sig) sscfu_sigq_link_t;
88 typedef TAILQ_HEAD(sscfu_sigq, sscfu_sig) sscfu_sigq_head_t;
89 #define SIGQ_INIT(Q) TAILQ_INIT(Q)
90 #define SIGQ_APPEND(Q, S) TAILQ_INSERT_TAIL(Q, S, link)
92 #define SIGQ_GET(Q) ng_sscfu_sigq_get((Q))
94 #define DECL_SIGQ_GET \
95 static __inline struct sscfu_sig * \
96 ng_sscfu_sigq_get(struct sscfu_sigq *q) \
97 { \
98 struct sscfu_sig *s; \
100 s = TAILQ_FIRST(q); \
101 if (s != NULL) \
102 TAILQ_REMOVE(q, s, link); \
103 return (s); \
106 #define SIGQ_CLEAR(Q) \
107 do { \
108 struct sscfu_sig *_s1, *_s2; \
110 _s1 = TAILQ_FIRST(Q); \
111 while (_s1 != NULL) { \
112 _s2 = TAILQ_NEXT(_s1, link); \
113 if (_s1->m) \
114 MBUF_FREE(_s1->m); \
115 SIG_FREE(_s1); \
116 _s1 = _s2; \
118 TAILQ_INIT(Q); \
119 } while (0)
123 * Message buffers
125 #define MBUF_FREE(M) m_freem(M)
127 #ifdef SSCFU_DEBUG
128 #define ASSERT(S) KASSERT(S, (#S))
129 #else
130 #define ASSERT(S)
131 #endif