2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001-2003
5 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
8 * Author: Harti Brandt <harti@freebsd.org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Customisation of the SSCFU code to ng_sscfu.
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)malloc((SIZE), M_NG_SSCFU, M_NOWAIT | M_ZERO))
57 #define MEMFREE(PTR) \
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)malloc((SIZE), M_NG_SSCFU_INS, M_NOWAIT | M_ZERO))
74 #define MEMFREE(PTR) \
75 free(PTR, M_NG_SSCFU_INS)
77 #define SIG_ALLOC(PTR) \
78 ((PTR) = malloc(sizeof(struct sscfu_sig), \
79 M_NG_SSCFU_SIG, M_NOWAIT | 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))