1139823Simp/*- 2122219Sharti * Copyright (c) 2001-2003 3122219Sharti * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4122219Sharti * All rights reserved. 5122219Sharti * 6122219Sharti * Author: Hartmut Brandt <harti@freebsd.org> 7122219Sharti * 8122219Sharti * Redistribution and use in source and binary forms, with or without 9122219Sharti * modification, are permitted provided that the following conditions 10122219Sharti * are met: 11122219Sharti * 1. Redistributions of source code must retain the above copyright 12122219Sharti * notice, this list of conditions and the following disclaimer. 13122219Sharti * 2. Redistributions in binary form must reproduce the above copyright 14122219Sharti * notice, this list of conditions and the following disclaimer in the 15122219Sharti * documentation and/or other materials provided with the distribution. 16122219Sharti * 17122219Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18122219Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19122219Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20122219Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21122219Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22122219Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23122219Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24122219Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25122219Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26122219Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27122219Sharti * SUCH DAMAGE. 28122219Sharti * 29122219Sharti * Customisation of signalling source to the NG environment. 30122219Sharti * 31122219Sharti * $FreeBSD: releng/10.3/sys/netgraph/atm/uni/ng_uni_cust.h 281657 2015-04-17 15:39:42Z rrs $ 32122219Sharti */ 33122219Sharti 34122219Sharti#include <sys/param.h> 35122219Sharti#include <sys/systm.h> 36122219Sharti#include <sys/kernel.h> 37122219Sharti#include <sys/malloc.h> 38122219Sharti#include <sys/queue.h> 39122219Sharti#include <sys/lock.h> 40122219Sharti#include <sys/mutex.h> 41131108Sjulian#include <sys/mbuf.h> 42122219Sharti#include <netgraph/ng_message.h> 43122219Sharti#include <netgraph/netgraph.h> 44122219Sharti#include <netgraph/atm/ngatmbase.h> 45122219Sharti 46122219Sharti#define ASSERT(E, M) KASSERT(E,M) 47122219Sharti 48122219Sharti/* 49122219Sharti * Memory 50122219Sharti */ 51122219Shartienum unimem { 52122219Sharti UNIMEM_INS = 0, 53122219Sharti UNIMEM_ALL, 54122219Sharti UNIMEM_SIG, 55122219Sharti UNIMEM_CALL, 56122219Sharti UNIMEM_PARTY, 57122219Sharti}; 58122219Sharti#define UNIMEM_TYPES 5 59122219Sharti 60122219Shartivoid *ng_uni_malloc(enum unimem, const char *, u_int); 61122219Shartivoid ng_uni_free(enum unimem, void *, const char *, u_int); 62122219Sharti 63122219Sharti#define INS_ALLOC() ng_uni_malloc(UNIMEM_INS, __FILE__, __LINE__) 64122219Sharti#define INS_FREE(P) ng_uni_free(UNIMEM_INS, P, __FILE__, __LINE__) 65122219Sharti 66122219Sharti#define UNI_ALLOC() ng_uni_malloc(UNIMEM_ALL, __FILE__, __LINE__) 67122219Sharti#define UNI_FREE(P) ng_uni_free(UNIMEM_ALL, P, __FILE__, __LINE__) 68122219Sharti 69122219Sharti#define SIG_ALLOC() ng_uni_malloc(UNIMEM_SIG, __FILE__, __LINE__) 70122219Sharti#define SIG_FREE(P) ng_uni_free(UNIMEM_SIG, P, __FILE__, __LINE__) 71122219Sharti 72122219Sharti#define CALL_ALLOC() ng_uni_malloc(UNIMEM_CALL, __FILE__, __LINE__) 73122219Sharti#define CALL_FREE(P) ng_uni_free(UNIMEM_CALL, P, __FILE__, __LINE__) 74122219Sharti 75122219Sharti#define PARTY_ALLOC() ng_uni_malloc(UNIMEM_PARTY, __FILE__, __LINE__) 76122219Sharti#define PARTY_FREE(P) ng_uni_free(UNIMEM_PARTY, P, __FILE__, __LINE__) 77122219Sharti 78122219Sharti/* 79122219Sharti * Timers 80122219Sharti */ 81122219Shartistruct uni_timer { 82137199Sharti struct callout c; 83122219Sharti}; 84122219Sharti 85137199Sharti#define _TIMER_INIT(X,T) ng_callout_init(&(X)->T.c) 86122219Sharti#define _TIMER_DESTROY(UNI,FIELD) _TIMER_STOP(UNI,FIELD) 87122219Sharti#define _TIMER_STOP(UNI,FIELD) do { \ 88138268Sglebius ng_uncallout(&FIELD.c, (UNI)->arg); \ 89122219Sharti } while (0) 90281657Srrs#define TIMER_ISACT(UNI,T) (callout_active(&(UNI)->T.c) || \ 91281657Srrs callout_pending(&(UNI)->T.c)) 92122219Sharti#define _TIMER_START(UNI,ARG,FIELD,DUE,FUNC) do { \ 93122219Sharti _TIMER_STOP(UNI, FIELD); \ 94138268Sglebius ng_callout(&FIELD.c, (UNI)->arg, NULL, \ 95122219Sharti hz * (DUE) / 1000, FUNC, (ARG), 0); \ 96122219Sharti } while (0) 97122219Sharti 98122219Sharti#define TIMER_FUNC_UNI(T,F) \ 99122219Shartistatic void F(struct uni *); \ 100122219Shartistatic void \ 101122219Sharti_##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \ 102122219Sharti{ \ 103122219Sharti struct uni *uni = (struct uni *)arg1; \ 104122219Sharti \ 105122219Sharti (F)(uni); \ 106122219Sharti uni_work(uni); \ 107122219Sharti} 108122219Sharti 109122219Sharti/* 110122219Sharti * Be careful: call may be invalid after the call to F 111122219Sharti */ 112122219Sharti#define TIMER_FUNC_CALL(T,F) \ 113122219Shartistatic void F(struct call *); \ 114122219Shartistatic void \ 115122219Sharti_##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \ 116122219Sharti{ \ 117122219Sharti struct call *call = (struct call *)arg1; \ 118122219Sharti struct uni *uni = call->uni; \ 119122219Sharti \ 120122219Sharti (F)(call); \ 121122219Sharti uni_work(uni); \ 122122219Sharti} 123122219Sharti 124122219Sharti/* 125122219Sharti * Be careful: call/party may be invalid after the call to F 126122219Sharti */ 127122219Sharti#define TIMER_FUNC_PARTY(T,F) \ 128122219Shartistatic void F(struct party *); \ 129122219Shartistatic void \ 130122219Sharti_##T##_func(node_p node, hook_p hook, void *arg1, int arg2) \ 131122219Sharti{ \ 132122219Sharti struct party *party = (struct party *)arg1; \ 133122219Sharti struct uni *uni = party->call->uni; \ 134122219Sharti \ 135122219Sharti (F)(party); \ 136122219Sharti uni_work(uni); \ 137122219Sharti} 138122219Sharti 139122219Shartiextern size_t unimem_sizes[UNIMEM_TYPES]; 140122219Sharti 141122219Sharti#define UNICORE \ 142122219Shartisize_t unimem_sizes[UNIMEM_TYPES] = { \ 143159166Sdds [UNIMEM_INS] = sizeof(struct uni), \ 144159166Sdds [UNIMEM_ALL] = sizeof(struct uni_all), \ 145159166Sdds [UNIMEM_SIG] = sizeof(struct sig), \ 146159166Sdds [UNIMEM_CALL] = sizeof(struct call), \ 147159166Sdds [UNIMEM_PARTY] = sizeof(struct party) \ 148122219Sharti}; 149