summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/atm/uni/ng_uni_cust.h
blob: 84e63e89e87ed607c39ed0b9890d6de223c3ed53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Customisation of signalling source to the NG environment.
 *
 * $FreeBSD$
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/atm/ngatmbase.h>

#define	ASSERT(E, M) KASSERT(E,M)

/*
 * Memory
 */
enum unimem {
	UNIMEM_INS = 0,
	UNIMEM_ALL,
	UNIMEM_SIG,
	UNIMEM_CALL,
	UNIMEM_PARTY,
};
#define	UNIMEM_TYPES	5

void *ng_uni_malloc(enum unimem, const char *, u_int);
void ng_uni_free(enum unimem, void *, const char *, u_int);

#define	INS_ALLOC()	ng_uni_malloc(UNIMEM_INS, __FILE__, __LINE__)
#define	INS_FREE(P)	ng_uni_free(UNIMEM_INS, P, __FILE__, __LINE__)

#define	UNI_ALLOC()	ng_uni_malloc(UNIMEM_ALL, __FILE__, __LINE__)
#define	UNI_FREE(P)	ng_uni_free(UNIMEM_ALL, P, __FILE__, __LINE__)

#define	SIG_ALLOC()	ng_uni_malloc(UNIMEM_SIG, __FILE__, __LINE__)
#define	SIG_FREE(P)	ng_uni_free(UNIMEM_SIG, P, __FILE__, __LINE__)

#define	CALL_ALLOC()	ng_uni_malloc(UNIMEM_CALL, __FILE__, __LINE__)
#define	CALL_FREE(P)	ng_uni_free(UNIMEM_CALL, P, __FILE__, __LINE__)

#define	PARTY_ALLOC()	ng_uni_malloc(UNIMEM_PARTY, __FILE__, __LINE__)
#define	PARTY_FREE(P)	ng_uni_free(UNIMEM_PARTY, P, __FILE__, __LINE__)

/*
 * Timers
 */
struct uni_timer {
	struct callout_handle c;
};

#define	_TIMER_INIT(X,T)	callout_handle_init(&(X)->T.c)
#define	_TIMER_DESTROY(UNI,FIELD) _TIMER_STOP(UNI,FIELD)
#define	_TIMER_STOP(UNI,FIELD) do {						\
	ng_untimeout(FIELD.c, (UNI)->arg);					\
	callout_handle_init(&FIELD.c);					\
    } while (0)
#define	TIMER_ISACT(UNI,T)	((UNI)->T.c.callout != NULL)
#define	_TIMER_START(UNI,ARG,FIELD,DUE,FUNC) do {			\
	_TIMER_STOP(UNI, FIELD);					\
	FIELD.c = ng_timeout((UNI)->arg, NULL,				\
	    hz * (DUE) / 1000, FUNC, (ARG), 0);				\
    } while (0)

#define	TIMER_FUNC_UNI(T,F)						\
static void F(struct uni *);						\
static void								\
_##T##_func(node_p node, hook_p hook, void *arg1, int arg2)		\
{									\
	struct uni *uni = (struct uni *)arg1;				\
									\
	callout_handle_init(&uni->T.c);					\
	(F)(uni);							\
	uni_work(uni);							\
}

/*
 * Be careful: call may be invalid after the call to F
 */
#define	TIMER_FUNC_CALL(T,F)						\
static void F(struct call *);						\
static void								\
_##T##_func(node_p node, hook_p hook, void *arg1, int arg2)		\
{									\
	struct call *call = (struct call *)arg1;			\
	struct uni *uni = call->uni;					\
									\
	callout_handle_init(&call->T.c);				\
	(F)(call);							\
	uni_work(uni);							\
}

/*
 * Be careful: call/party may be invalid after the call to F
 */
#define	TIMER_FUNC_PARTY(T,F)						\
static void F(struct party *);						\
static void								\
_##T##_func(node_p node, hook_p hook, void *arg1, int arg2)		\
{									\
	struct party *party = (struct party *)arg1;			\
	struct uni *uni = party->call->uni;				\
									\
	callout_handle_init(&party->T.c);					\
	(F)(party);							\
	uni_work(uni);							\
}

extern size_t unimem_sizes[UNIMEM_TYPES];

#define	UNICORE								\
size_t unimem_sizes[UNIMEM_TYPES] = {					\
	[UNIMEM_INS]	sizeof(struct uni),				\
	[UNIMEM_ALL]	sizeof(struct uni_all),				\
	[UNIMEM_SIG]	sizeof(struct sig),				\
	[UNIMEM_CALL]	sizeof(struct call),				\
	[UNIMEM_PARTY]	sizeof(struct party)				\
};

#define	memmove(T, F, L) bcopy((F), (T), (L))
OpenPOWER on IntegriCloud