2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
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
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
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 $
32 * $DragonFly: src/sys/netgraph7/atm/sscfu/ng_sscfu_cust.h,v 1.2 2008/06/26 23:05:39 dillon Exp $
33 * $DragonFly: src/sys/netgraph7/atm/sscfu/ng_sscfu_cust.h,v 1.2 2008/06/26 23:05:39 dillon Exp $
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/kernel.h>
39 #include <sys/queue.h>
40 #include <sys/callout.h>
41 #include <sys/systm.h>
42 #include <sys/malloc.h>
43 #include <machine/stdarg.h>
46 * Allocate zeroed or non-zeroed memory of some size and cast it.
47 * Return NULL on failure.
52 MALLOC_DECLARE(M_NG_SSCFU); \
55 #define MEMZALLOC(PTR, CAST, SIZE) \
56 ((PTR) = (CAST)kmalloc((SIZE), M_NG_SSCFU, M_WAITOK | M_NULLOK | M_ZERO))
57 #define MEMFREE(PTR) \
58 kfree(PTR, M_NG_SSCFU)
60 #define SIG_ALLOC(PTR) \
61 MEMZALLOC(PTR, struct sscfu_sig *, sizeof(struct sscfu_sig))
62 #define SIG_FREE(PTR) \
68 MALLOC_DEFINE(M_NG_SSCFU_INS, "sscfu_ins", "SSCFU instances"); \
69 MALLOC_DEFINE(M_NG_SSCFU_SIG, "sscfu_sig", "SSCFU signals"); \
72 #define MEMZALLOC(PTR, CAST, SIZE) \
73 ((PTR) = (CAST)kmalloc((SIZE), M_NG_SSCFU_INS, M_WAITOK | M_NULLOK | M_ZERO))
74 #define MEMFREE(PTR) \
75 FREE(PTR, M_NG_SSCFU_INS)
77 #define SIG_ALLOC(PTR) \
78 ((PTR) = kmalloc(sizeof(struct sscfu_sig), \
79 M_NG_SSCFU_SIG, M_WAITOK | M_NULLOK | M_ZERO))
80 #define SIG_FREE(PTR) \
81 FREE(PTR, M_NG_SSCFU_SIG)
89 typedef TAILQ_ENTRY(sscfu_sig) sscfu_sigq_link_t;
90 typedef TAILQ_HEAD(sscfu_sigq, sscfu_sig) sscfu_sigq_head_t;
91 #define SIGQ_INIT(Q) TAILQ_INIT(Q)
92 #define SIGQ_APPEND(Q, S) TAILQ_INSERT_TAIL(Q, S, link)
94 #define SIGQ_GET(Q) ng_sscfu_sigq_get((Q))
96 #define DECL_SIGQ_GET \
97 static __inline struct sscfu_sig * \
98 ng_sscfu_sigq_get(struct sscfu_sigq *q) \
100 struct sscfu_sig *s; \
102 s = TAILQ_FIRST(q); \
104 TAILQ_REMOVE(q, s, link); \
108 #define SIGQ_CLEAR(Q) \
110 struct sscfu_sig *_s1, *_s2; \
112 _s1 = TAILQ_FIRST(Q); \
113 while (_s1 != NULL) { \
114 _s2 = TAILQ_NEXT(_s1, link); \
127 #define MBUF_FREE(M) m_freem(M)
130 #define ASSERT(S) KASSERT(S, (#S))