Consolidate ifqueue macros for the upcoming ALTQ work.
[dragonfly.git] / sys / net / i4b / include / i4b_global.h
1 /*
2  * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b_global.h - i4b global include file
28  *      --------------------------------------
29  *
30  * $FreeBSD: src/sys/i4b/include/i4b_global.h,v 1.6.2.2 2002/07/07 10:17:10 hm Exp $
31  * $DragonFly: src/sys/net/i4b/include/i4b_global.h,v 1.4 2005/01/23 13:47:24 joerg Exp $
32  *
33  *      last edit-date: [Sun Jul  7 12:11:35 2002]
34  *
35  *---------------------------------------------------------------------------*/
36
37 #ifndef _I4B_GLOBAL_H_
38 #define _I4B_GLOBAL_H_
39
40 /*---------------------------------------------------------------------------*
41  *      hiding OS differences in the kernel
42  *---------------------------------------------------------------------------*/ 
43
44 /*-------------------------------------------------*/
45 /* hide SMP changes in FreeBSD 5.x-current for 4.x */
46 /*-------------------------------------------------*/
47
48 #if defined(__FreeBSD__) && __FreeBSD__ >= 5
49 /*
50  * Deprecated LKM interface.
51  */
52 #include <sys/module.h>
53 #define PSEUDO_SET(sym, name) \
54         static int name ## _modevent(module_t mod, int type, void *data) \
55         { \
56                 void (*initfunc)(void *) = (void (*)(void *))data; \
57                 switch (type) { \
58                 case MOD_LOAD: \
59                         /* printf(#name " module load\n"); */ \
60                         initfunc(NULL); \
61                         break; \
62                 case MOD_UNLOAD: \
63                         printf(#name " module unload - not possible for this module type\n"); \
64                         return EINVAL; \
65                 } \
66                 return 0; \
67         } \
68         static moduledata_t name ## _mod = { \
69                 #name, \
70                 name ## _modevent, \
71                 (void *)sym \
72         }; \
73         DECLARE_MODULE(name, name ## _mod, SI_SUB_PSEUDO, SI_ORDER_ANY)
74 #endif
75
76 /*---------------*/
77 /* time handling */
78 /*---------------*/
79
80 #if defined(__DragonFly__) || defined(__FreeBSD__)
81 #include <sys/param.h>
82
83 #if defined(__FreeBSD_version) && __FreeBSD_version >= 400000 && __FreeBSD_version < 400011
84 #error "Unsupported FreeBSD-current version,"
85 #error "you need a FreeBSD-current >= 400011"
86 #endif
87
88 #if defined(__DragonFly__) || (defined(__FreeBSD_version) && __FreeBSD_version >= 300001)
89
90 #define TIMEOUT_FUNC_T  timeout_t *
91 #define SECOND          time_second
92 #define MICROTIME(x)    getmicrotime(&(x))
93
94 #else /* FreeBSD < 3 */
95
96 #define TIMEOUT_FUNC_T  timeout_func_t
97 #define SECOND          time.tv_sec
98 #define MICROTIME(x)    microtime(&(x))
99
100 #endif /* >= 3 */
101 #endif /* __FreeBSD__ */
102
103 #if defined(__NetBSD__) || defined (__OpenBSD__) || defined(__bsdi__)
104
105 #define TIMEOUT_FUNC_T  void *
106 #define SECOND          time.tv_sec
107 #define MICROTIME(x)    (x) = time
108
109 #endif /* __NetBSD__ */
110
111 /*----------------*/
112 /* timer handling */
113 /*----------------*/
114
115 #if defined(__NetBSD__)
116
117 #if __NetBSD_Version__ >= 104230000
118 #define START_TIMER(XHANDLE, XF, XSC, XTIME) callout_reset(&XHANDLE, XTIME, (TIMEOUT_FUNC_T)XF, (void*)XSC)
119 #define STOP_TIMER(XHANDLE, XF, XSC) callout_stop(&XHANDLE)
120 #else
121 #define START_TIMER(XHANDLE, XF, XSC, XTIME) timeout((TIMEOUT_FUNC_T)XF, (void*)XSC, XTIME)
122 #define STOP_TIMER(XHANDLE, XF, XSC)    untimeout((TIMEOUT_FUNC_T)XF, (void*)XSC)
123 #endif
124
125 #else
126 #define START_TIMER(XHANDLE, XF, XSC, XTIME) XHANDLE = timeout((TIMEOUT_FUNC_T)XF, (void*)XSC, XTIME)
127 #if defined(__DragonFly__) || defined(__FreeBSD__)
128 #define STOP_TIMER(XHANDLE, XF, XSC)    untimeout((TIMEOUT_FUNC_T)XF, (void*)XSC, XHANDLE)
129 #else
130 #define STOP_TIMER(XHANDLE, XF, XSC)    untimeout((TIMEOUT_FUNC_T)XF, (void*)XSC)
131 #endif
132 #endif
133
134 /*----------------------*/
135 /* poll/select handling */
136 /*----------------------*/
137
138 #if (defined(__FreeBSD__) && \
139         (!defined(__FreeBSD_version) || (__FreeBSD_version < 300001))) \
140                 || defined (__OpenBSD__) || defined(__bsdi__)
141 #define OS_USES_SELECT
142 #else
143 #define OS_USES_POLL
144 #endif
145
146 /*---------------------------------------------------------------------------*
147  *      misc globally used things in the kernel
148  *---------------------------------------------------------------------------*/ 
149
150 /* timer states */
151
152 #define TIMER_IDLE      1               /* a timer is running   */
153 #define TIMER_ACTIVE    2               /* a timer is idle      */
154
155 /* i4b's spl */
156
157 #define SPLI4B()        splimp()        /* spl for i4b          */
158
159 /* critial code region handling macros */
160
161 #define CRIT_VAR        int _svd_spl_   /* declare variable     */
162 #define CRIT_BEG        _svd_spl_ = SPLI4B()    /* save spl     */
163 #define CRIT_END        splx(_svd_spl_) /* restore spl          */
164
165 /* definitions for the STATUS indications L1 -> L2 -> L3 */
166
167 #define STI_ATTACH      0       /* attach at boot time                  */
168 #define STI_L1STAT      1       /* layer 1 status                       */
169 #define STI_L2STAT      2       /* layer 2 status                       */
170 #define STI_TEIASG      3       /* TEI assignments                      */
171 #define STI_PDEACT      4       /* Layer 1 T4 expired = persistent deactivation */
172 #define STI_NOL1ACC     5       /* no outgoing L1 access possible       */
173
174 /* definitions for the COMMAND requests L3 -> L2 -> L1 */
175
176 #define CMR_DOPEN       0       /* daemon opened /dev/i4b               */
177 #define CMR_DCLOSE      1       /* daemon closed /dev/i4b               */
178 #define CMR_SETTRACE    2       /* set D-channel and B-channel trace    */
179 #define CMR_GCST        3       /* get chipset statistics               */
180 #define CMR_CCST        4       /* clear chipset statistics             */
181
182 #endif /* _I4B_GLOBAL_H_ */