Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / sys / netgraph7 / atm / uni / ng_uni_cust.h
1 /*-
2  * Copyright (c) 2001-2003
3  *      Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4  *      All rights reserved.
5  *
6  * Author: Hartmut Brandt <harti@freebsd.org>
7  *
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.
16  *
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.
28  *
29  * Customisation of signalling source to the NG environment.
30  *
31  * $FreeBSD: src/sys/netgraph/atm/uni/ng_uni_cust.h,v 1.6 2006/06/02 09:08:51 dds Exp $
32  * $DragonFly: src/sys/netgraph7/atm/uni/ng_uni_cust.h,v 1.2 2008/06/26 23:05:39 dillon Exp $
33  * $DragonFly: src/sys/netgraph7/atm/uni/ng_uni_cust.h,v 1.2 2008/06/26 23:05:39 dillon Exp $
34  */
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/queue.h>
41 #include <sys/lock.h>
42 #include <sys/mutex.h>
43 #include <sys/mbuf.h>
44 #include "ng_message.h"
45 #include "netgraph.h"
46 #include "atm/ngatmbase.h"
47
48 #define ASSERT(E, M) KASSERT(E,M)
49
50 /*
51  * Memory
52  */
53 enum unimem {
54         UNIMEM_INS = 0,
55         UNIMEM_ALL,
56         UNIMEM_SIG,
57         UNIMEM_CALL,
58         UNIMEM_PARTY,
59 };
60 #define UNIMEM_TYPES    5
61
62 void *ng_uni_malloc(enum unimem, const char *, u_int);
63 void ng_uni_free(enum unimem, void *, const char *, u_int);
64
65 #define INS_ALLOC()     ng_uni_malloc(UNIMEM_INS, __FILE__, __LINE__)
66 #define INS_FREE(P)     ng_uni_free(UNIMEM_INS, P, __FILE__, __LINE__)
67
68 #define UNI_ALLOC()     ng_uni_malloc(UNIMEM_ALL, __FILE__, __LINE__)
69 #define UNI_FREE(P)     ng_uni_free(UNIMEM_ALL, P, __FILE__, __LINE__)
70
71 #define SIG_ALLOC()     ng_uni_malloc(UNIMEM_SIG, __FILE__, __LINE__)
72 #define SIG_FREE(P)     ng_uni_free(UNIMEM_SIG, P, __FILE__, __LINE__)
73
74 #define CALL_ALLOC()    ng_uni_malloc(UNIMEM_CALL, __FILE__, __LINE__)
75 #define CALL_FREE(P)    ng_uni_free(UNIMEM_CALL, P, __FILE__, __LINE__)
76
77 #define PARTY_ALLOC()   ng_uni_malloc(UNIMEM_PARTY, __FILE__, __LINE__)
78 #define PARTY_FREE(P)   ng_uni_free(UNIMEM_PARTY, P, __FILE__, __LINE__)
79
80 /*
81  * Timers
82  */
83 struct uni_timer {
84         struct callout c;
85 };
86
87 #define _TIMER_INIT(X,T)        ng_callout_init(&(X)->T.c)
88 #define _TIMER_DESTROY(UNI,FIELD) _TIMER_STOP(UNI,FIELD)
89 #define _TIMER_STOP(UNI,FIELD) do {                                             \
90         ng_uncallout(&FIELD.c, (UNI)->arg);                                     \
91     } while (0)
92 #define TIMER_ISACT(UNI,T)      ((UNI)->T.c.c_flags & (CALLOUT_ACTIVE | \
93                                                         CALLOUT_PENDING))
94 #define _TIMER_START(UNI,ARG,FIELD,DUE,FUNC) do {                       \
95         _TIMER_STOP(UNI, FIELD);                                        \
96         ng_callout(&FIELD.c, (UNI)->arg, NULL,                          \
97             hz * (DUE) / 1000, FUNC, (ARG), 0);                         \
98     } while (0)
99
100 #define TIMER_FUNC_UNI(T,F)                                             \
101 static void F(struct uni *);                                            \
102 static void                                                             \
103 _##T##_func(node_p node, hook_p hook, void *arg1, int arg2)             \
104 {                                                                       \
105         struct uni *uni = (struct uni *)arg1;                           \
106                                                                         \
107         (F)(uni);                                                       \
108         uni_work(uni);                                                  \
109 }
110
111 /*
112  * Be careful: call may be invalid after the call to F
113  */
114 #define TIMER_FUNC_CALL(T,F)                                            \
115 static void F(struct call *);                                           \
116 static void                                                             \
117 _##T##_func(node_p node, hook_p hook, void *arg1, int arg2)             \
118 {                                                                       \
119         struct call *call = (struct call *)arg1;                        \
120         struct uni *uni = call->uni;                                    \
121                                                                         \
122         (F)(call);                                                      \
123         uni_work(uni);                                                  \
124 }
125
126 /*
127  * Be careful: call/party may be invalid after the call to F
128  */
129 #define TIMER_FUNC_PARTY(T,F)                                           \
130 static void F(struct party *);                                          \
131 static void                                                             \
132 _##T##_func(node_p node, hook_p hook, void *arg1, int arg2)             \
133 {                                                                       \
134         struct party *party = (struct party *)arg1;                     \
135         struct uni *uni = party->call->uni;                             \
136                                                                         \
137         (F)(party);                                                     \
138         uni_work(uni);                                                  \
139 }
140
141 extern size_t unimem_sizes[UNIMEM_TYPES];
142
143 #define UNICORE                                                         \
144 size_t unimem_sizes[UNIMEM_TYPES] = {                                   \
145         [UNIMEM_INS]    = sizeof(struct uni),                           \
146         [UNIMEM_ALL]    = sizeof(struct uni_all),                       \
147         [UNIMEM_SIG]    = sizeof(struct sig),                           \
148         [UNIMEM_CALL]   = sizeof(struct call),                          \
149         [UNIMEM_PARTY]  = sizeof(struct party)                          \
150 };
151
152 #define memmove(T, F, L) bcopy((F), (T), (L))