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: releng/10.3/sys/netgraph/atm/uni/ng_uni_cust.h 281657 2015-04-17 15:39:42Z rrs $ 32 */ 33 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> 45 46#define ASSERT(E, M) KASSERT(E,M) 47 48/* 49 * Memory 50 */ 51enum unimem { 52 UNIMEM_INS = 0, 53 UNIMEM_ALL, 54 UNIMEM_SIG, 55 UNIMEM_CALL, 56 UNIMEM_PARTY, 57}; 58#define UNIMEM_TYPES 5 59 60void *ng_uni_malloc(enum unimem, const char *, u_int); 61void ng_uni_free(enum unimem, void *, const char *, u_int); 62 63#define INS_ALLOC() ng_uni_malloc(UNIMEM_INS, __FILE__, __LINE__) 64#define INS_FREE(P) ng_uni_free(UNIMEM_INS, P, __FILE__, __LINE__) 65 66#define UNI_ALLOC() ng_uni_malloc(UNIMEM_ALL, __FILE__, __LINE__) 67#define UNI_FREE(P) ng_uni_free(UNIMEM_ALL, P, __FILE__, __LINE__) 68 69#define SIG_ALLOC() ng_uni_malloc(UNIMEM_SIG, __FILE__, __LINE__) 70#define SIG_FREE(P) ng_uni_free(UNIMEM_SIG, P, __FILE__, __LINE__) 71 72#define CALL_ALLOC() ng_uni_malloc(UNIMEM_CALL, __FILE__, __LINE__) 73#define CALL_FREE(P) ng_uni_free(UNIMEM_CALL, P, __FILE__, __LINE__) 74 75#define PARTY_ALLOC() ng_uni_malloc(UNIMEM_PARTY, __FILE__, __LINE__) 76#define PARTY_FREE(P) ng_uni_free(UNIMEM_PARTY, P, __FILE__, __LINE__) 77 78/* 79 * Timers 80 */ 81struct uni_timer { 82 struct callout c; 83}; 84 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) (callout_active(&(UNI)->T.c) || \ 91 callout_pending(&(UNI)->T.c)) 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) 97 98#define TIMER_FUNC_UNI(T,F) \ 99static void F(struct uni *); \ 100static void \ 101_##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \ 102{ \ 103 struct uni *uni = (struct uni *)arg1; \ 104 \ 105 (F)(uni); \ 106 uni_work(uni); \ 107} 108 109/* 110 * Be careful: call may be invalid after the call to F 111 */ 112#define TIMER_FUNC_CALL(T,F) \ 113static void F(struct call *); \ 114static void \ 115_##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \ 116{ \ 117 struct call *call = (struct call *)arg1; \ 118 struct uni *uni = call->uni; \ 119 \ 120 (F)(call); \ 121 uni_work(uni); \ 122} 123 124/* 125 * Be careful: call/party may be invalid after the call to F 126 */ 127#define TIMER_FUNC_PARTY(T,F) \ 128static void F(struct party *); \ 129static void \ 130_##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \ 131{ \ 132 struct party *party = (struct party *)arg1; \ 133 struct uni *uni = party->call->uni; \ 134 \ 135 (F)(party); \ 136 uni_work(uni); \ 137} 138 139extern size_t unimem_sizes[UNIMEM_TYPES]; 140 141#define UNICORE \ 142size_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) \ 148}; 149