Vendor import of netgraph from FreeBSD-current 20080626
[dragonfly.git] / sys / netgraph7 / atm / uni / ng_uni_cust.h
blob603c419bf74809b082d9198ac82e963f4a2dacc2
1 /*-
2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 * All rights reserved.
6 * Author: Hartmut 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 signalling source to the NG environment.
31 * $FreeBSD: src/sys/netgraph/atm/uni/ng_uni_cust.h,v 1.6 2006/06/02 09:08:51 dds Exp $
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/queue.h>
39 #include <sys/lock.h>
40 #include <sys/mutex.h>
41 #include <sys/mbuf.h>
42 #include <netgraph/ng_message.h>
43 #include <netgraph/netgraph.h>
44 #include <netgraph/atm/ngatmbase.h>
46 #define ASSERT(E, M) KASSERT(E,M)
49 * Memory
51 enum unimem {
52 UNIMEM_INS = 0,
53 UNIMEM_ALL,
54 UNIMEM_SIG,
55 UNIMEM_CALL,
56 UNIMEM_PARTY,
58 #define UNIMEM_TYPES 5
60 void *ng_uni_malloc(enum unimem, const char *, u_int);
61 void ng_uni_free(enum unimem, void *, const char *, u_int);
63 #define INS_ALLOC() ng_uni_malloc(UNIMEM_INS, __FILE__, __LINE__)
64 #define INS_FREE(P) ng_uni_free(UNIMEM_INS, P, __FILE__, __LINE__)
66 #define UNI_ALLOC() ng_uni_malloc(UNIMEM_ALL, __FILE__, __LINE__)
67 #define UNI_FREE(P) ng_uni_free(UNIMEM_ALL, P, __FILE__, __LINE__)
69 #define SIG_ALLOC() ng_uni_malloc(UNIMEM_SIG, __FILE__, __LINE__)
70 #define SIG_FREE(P) ng_uni_free(UNIMEM_SIG, P, __FILE__, __LINE__)
72 #define CALL_ALLOC() ng_uni_malloc(UNIMEM_CALL, __FILE__, __LINE__)
73 #define CALL_FREE(P) ng_uni_free(UNIMEM_CALL, P, __FILE__, __LINE__)
75 #define PARTY_ALLOC() ng_uni_malloc(UNIMEM_PARTY, __FILE__, __LINE__)
76 #define PARTY_FREE(P) ng_uni_free(UNIMEM_PARTY, P, __FILE__, __LINE__)
79 * Timers
81 struct uni_timer {
82 struct callout c;
85 #define _TIMER_INIT(X,T) ng_callout_init(&(X)->T.c)
86 #define _TIMER_DESTROY(UNI,FIELD) _TIMER_STOP(UNI,FIELD)
87 #define _TIMER_STOP(UNI,FIELD) do { \
88 ng_uncallout(&FIELD.c, (UNI)->arg); \
89 } while (0)
90 #define TIMER_ISACT(UNI,T) ((UNI)->T.c.c_flags & (CALLOUT_ACTIVE | \
91 CALLOUT_PENDING))
92 #define _TIMER_START(UNI,ARG,FIELD,DUE,FUNC) do { \
93 _TIMER_STOP(UNI, FIELD); \
94 ng_callout(&FIELD.c, (UNI)->arg, NULL, \
95 hz * (DUE) / 1000, FUNC, (ARG), 0); \
96 } while (0)
98 #define TIMER_FUNC_UNI(T,F) \
99 static void F(struct uni *); \
100 static void \
101 _##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \
103 struct uni *uni = (struct uni *)arg1; \
105 (F)(uni); \
106 uni_work(uni); \
110 * Be careful: call may be invalid after the call to F
112 #define TIMER_FUNC_CALL(T,F) \
113 static void F(struct call *); \
114 static void \
115 _##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \
117 struct call *call = (struct call *)arg1; \
118 struct uni *uni = call->uni; \
120 (F)(call); \
121 uni_work(uni); \
125 * Be careful: call/party may be invalid after the call to F
127 #define TIMER_FUNC_PARTY(T,F) \
128 static void F(struct party *); \
129 static void \
130 _##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \
132 struct party *party = (struct party *)arg1; \
133 struct uni *uni = party->call->uni; \
135 (F)(party); \
136 uni_work(uni); \
139 extern size_t unimem_sizes[UNIMEM_TYPES];
141 #define UNICORE \
142 size_t unimem_sizes[UNIMEM_TYPES] = { \
143 [UNIMEM_INS] = sizeof(struct uni), \
144 [UNIMEM_ALL] = sizeof(struct uni_all), \
145 [UNIMEM_SIG] = sizeof(struct sig), \
146 [UNIMEM_CALL] = sizeof(struct call), \
147 [UNIMEM_PARTY] = sizeof(struct party) \
150 #define memmove(T, F, L) bcopy((F), (T), (L))