fetch.9: Minor fixes.
[dragonfly.git] / sys / netproto / atm / atm_sys.h
blob9e8dd7baea32d1c91125d9c16183f32677567453
1 /*
3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/netatm/atm_sys.h,v 1.3 1999/08/28 00:48:38 peter Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/atm_sys.h,v 1.4 2006/12/22 23:57:53 swildner Exp $
32 * Core ATM Services
33 * -----------------
35 * General system definitions
39 #ifndef _NETATM_ATM_SYS_H
40 #define _NETATM_ATM_SYS_H
43 * Software Version
45 #define ATM_VERSION 0x00030000 /* Version 3.0 */
46 #define ATM_VERS_MAJ(v) ((v) >> 16)
47 #define ATM_VERS_MIN(v) ((v) & 0xffff)
51 * Misc system defines
53 #define ATM_CALLQ_MAX 100 /* Maximum length of call queue */
54 #define ATM_INTRQ_MAX 1000 /* Maximum length of interrupt queue */
58 * ATM address manipulation macros
60 #define ATM_ADDR_EQUAL(a1, a2) \
61 (((a1)->address_format == (a2)->address_format) && \
62 ((a1)->address_length == (a2)->address_length) && \
63 (bcmp((caddr_t)(a1)->address, (caddr_t)(a2)->address, \
64 (a1)->address_length) == 0))
66 #define ATM_ADDR_SEL_EQUAL(a1, s1, a2) \
67 (((a1)->address_format == (a2)->address_format) && \
68 ((a1)->address_length == (a2)->address_length) && \
69 (((((a1)->address_format == T_ATM_ENDSYS_ADDR) || \
70 ((a1)->address_format == T_ATM_NSAP_ADDR)) && \
71 (bcmp((caddr_t)(a1)->address, (caddr_t)(a2)->address, \
72 (a1)->address_length - 1) == 0) && \
73 ((s1) == ((struct atm_addr_nsap *)(a2)->address)->aan_sel)) || \
74 (((a1)->address_format != T_ATM_ENDSYS_ADDR) && \
75 ((a1)->address_format != T_ATM_NSAP_ADDR) && \
76 (bcmp((caddr_t)(a1)->address, (caddr_t)(a2)->address, \
77 (a1)->address_length) == 0))))
79 #define ATM_ADDR_COPY(a1, a2) \
80 { \
81 (a2)->address_format = (a1)->address_format; \
82 (a2)->address_length = (a1)->address_length; \
83 XM_COPY((caddr_t)(a1)->address, (caddr_t)(a2)->address, \
84 (a1)->address_length); \
87 #define ATM_ADDR_SEL_COPY(a1, s1, a2) \
88 { \
89 (a2)->address_format = (a1)->address_format; \
90 (a2)->address_length = (a1)->address_length; \
91 if (((a1)->address_format == T_ATM_ENDSYS_ADDR) || \
92 ((a1)->address_format == T_ATM_NSAP_ADDR)) { \
93 XM_COPY((caddr_t)(a1)->address, (caddr_t)(a2)->address, \
94 (a1)->address_length - 1); \
95 ((struct atm_addr_nsap *)(a2)->address)->aan_sel = (s1);\
96 } else { \
97 XM_COPY((caddr_t)(a1)->address, (caddr_t)(a2)->address, \
98 (a1)->address_length); \
99 } \
104 * ATM Cell Header definitions
108 * These macros assume that the cell header (minus the HEC)
109 * is contained in the least-significant 32-bits of a word
111 #define ATM_HDR_SET_VPI(vpi) (((vpi) & 0xff) << 20)
112 #define ATM_HDR_SET_VCI(vci) (((vci) & 0xffff) << 4)
113 #define ATM_HDR_SET_PT(pt) (((pt) & 0x7) << 1)
114 #define ATM_HDR_SET_CLP(clp) ((clp) & 0x1)
115 #define ATM_HDR_SET(vpi,vci,pt,clp) (ATM_HDR_SET_VPI(vpi) | \
116 ATM_HDR_SET_VCI(vci) | \
117 ATM_HDR_SET_PT(pt) | \
118 ATM_HDR_SET_CLP(clp))
119 #define ATM_HDR_GET_VPI(hdr) (((hdr) >> 20) & 0xff)
120 #define ATM_HDR_GET_VCI(hdr) (((hdr) >> 4) & 0xffff)
121 #define ATM_HDR_GET_PT(hdr) (((hdr) >> 1) & 0x7)
122 #define ATM_HDR_GET_CLP(hdr) ((hdr) & 0x1)
125 * Payload Type Identifier (3 bits)
127 #define ATM_PT_USER_SDU0 0x0 /* User, no congestion, sdu type 0 */
128 #define ATM_PT_USER_SDU1 0x1 /* User, no congestion, sdu type 1 */
129 #define ATM_PT_USER_CONG_SDU0 0x2 /* User, congestion, sdu type 0 */
130 #define ATM_PT_USER_CONG_SDU1 0x3 /* User, congestion, sdu type 1 */
131 #define ATM_PT_NONUSER 0x4 /* User/non-user differentiator */
132 #define ATM_PT_OAMF5_SEG 0x4 /* OAM F5 segment flow */
133 #define ATM_PT_OAMF5_E2E 0x5 /* OAM F5 end-to-end flow */
137 * AAL (ATM Adaptation Layer) codes
139 typedef u_char Aal_t;
140 #define ATM_AAL0 0 /* AAL0 - Cell service */
141 #define ATM_AAL1 1 /* AAL1 */
142 #define ATM_AAL2 2 /* AAL2 */
143 #define ATM_AAL3_4 3 /* AAL3/4 */
144 #define ATM_AAL5 5 /* AAL5 */
148 * VCC Encapsulation codes
150 typedef u_char Encaps_t;
151 #define ATM_ENC_NULL 1 /* Null encapsulation */
152 #define ATM_ENC_LLC 2 /* LLC encapsulation */
155 #ifdef ATM_KERNEL
157 * ATM timer control block. Used to schedule a timeout via atm_timeout().
158 * This control block will typically be embedded in a processing-specific
159 * control block.
161 struct atm_time {
162 u_short ti_ticks; /* Delta of ticks until timeout */
163 u_char ti_flag; /* Timer flag bits (see below) */
164 void (*ti_func) /* Call at timeout expiration */
165 (struct atm_time *);
166 struct atm_time *ti_next; /* Next on queue */
170 * Timer Flags
172 #define TIF_QUEUED 0x01 /* Control block on timer queue */
174 #define ATM_HZ 2 /* Time ticks per second */
178 * To avoid heavy use of kmem_alloc, memory for protocol control blocks may
179 * be allocated from storage pools. Each control block type will have
180 * its own pool. Each storage pool will consist of individually allocated
181 * memory chunks, which will then be sub-divided into the separate control
182 * blocks. Each chunk will contain a header (sp_chunk) and 'n' blocks of the
183 * same type, plus a link field for each block. Each chunk will also contain
184 * a list of all free control blocks in the chunk.
186 * Each protocol must define an sp_info structure for each of its storage
187 * pools. This structure serves as the "root" for its particular pool.
188 * Protocols must not modify this structure after its first use.
190 struct sp_info {
191 /* Values supplied by pool owner */
192 char *si_name; /* Name of pool */
193 size_t si_blksiz; /* Size of each block */
194 int si_blkcnt; /* Blocks per chunk */
195 int si_maxallow; /* Maximum allowable chunks */
197 /* Used by allocate/free functions - do not touch */
198 struct sp_info *si_next; /* Next active storage pool */
199 struct sp_chunk *si_poolh; /* Storage pool chunk head */
200 struct sp_chunk *si_poolt; /* Storage pool chunk tail */
201 size_t si_chunksiz; /* Size of chunk */
202 int si_chunks; /* Current allocated chunks */
203 int si_total; /* Total number of blocks */
204 int si_free; /* Free blocks */
205 int si_maxused; /* Maximum allocated chunks */
206 int si_allocs; /* Total allocate calls */
207 int si_fails; /* Allocate failures */
210 struct sp_chunk {
211 struct sp_chunk *sc_next; /* Next chunk in pool */
212 struct sp_info *sc_info; /* Storage pool info */
213 u_int sc_magic; /* Chunk magic number */
214 int sc_used; /* Allocated blocks in chunk */
215 struct sp_link *sc_freeh; /* Head of free blocks in chunk */
216 struct sp_link *sc_freet; /* Tail of free blocks in chunk */
219 struct sp_link {
220 union {
221 struct sp_link *slu_next; /* Next block in free list */
222 struct sp_chunk *slu_chunk; /* Link back to our chunk */
223 } sl_u;
226 #define SPOOL_MAGIC 0x73d4b69c /* Storage pool magic number */
227 #define SPOOL_MIN_CHUNK 2 /* Minimum number of chunks */
228 #define SPOOL_ROUNDUP 16 /* Roundup for allocated chunks */
229 #define SPOOL_COMPACT (300 * ATM_HZ) /* Compaction timeout value */
232 * Debugging
234 #ifdef DIAGNOSTIC
235 #define ATM_TIME \
236 struct timeval now, delta; \
237 KT_TIME(now); \
238 delta.tv_sec = now.tv_sec - atm_debugtime.tv_sec; \
239 delta.tv_usec = now.tv_usec - atm_debugtime.tv_usec; \
240 atm_debugtime = now; \
241 if (delta.tv_usec < 0) { \
242 delta.tv_sec--; \
243 delta.tv_usec += 1000000; \
245 kprintf("%3ld.%6ld: ", delta.tv_sec, delta.tv_usec);
247 #define ATM_DEBUG0(f) if (atm_debug) {ATM_TIME; kprintf(f);}
248 #define ATM_DEBUGN0(f) if (atm_debug) {kprintf(f);}
249 #define ATM_DEBUG1(f,a1) if (atm_debug) {ATM_TIME; kprintf(f, a1);}
250 #define ATM_DEBUGN1(f,a1) if (atm_debug) {kprintf(f, a1);}
251 #define ATM_DEBUG2(f,a1,a2) if (atm_debug) {ATM_TIME; kprintf(f, a1, a2);}
252 #define ATM_DEBUGN2(f,a1,a2) if (atm_debug) {kprintf(f, a1, a2);}
253 #define ATM_DEBUG3(f,a1,a2,a3) if (atm_debug) {ATM_TIME; kprintf(f, a1, a2, a3);}
254 #define ATM_DEBUGN3(f,a1,a2,a3) if (atm_debug) {kprintf(f, a1, a2, a3);}
255 #define ATM_DEBUG4(f,a1,a2,a3,a4) if (atm_debug) {ATM_TIME; kprintf(f, a1, a2, a3, a4);}
256 #define ATM_DEBUGN4(f,a1,a2,a3,a4) if (atm_debug) {kprintf(f, a1, a2, a3, a4);}
257 #define ATM_DEBUG5(f,a1,a2,a3,a4,a5) if (atm_debug) {ATM_TIME; kprintf(f, a1, a2, a3, a4, a5);}
258 #define ATM_DEBUGN5(f,a1,a2,a3,a4,a5) if (atm_debug) {kprintf(f, a1, a2, a3, a4, a5);}
259 #else
260 #define ATM_DEBUG0(f)
261 #define ATM_DEBUGN0(f)
262 #define ATM_DEBUG1(f,a1)
263 #define ATM_DEBUGN1(f,a1)
264 #define ATM_DEBUG2(f,a1,a2)
265 #define ATM_DEBUGN2(f,a1,a2)
266 #define ATM_DEBUG3(f,a1,a2,a3)
267 #define ATM_DEBUGN3(f,a1,a2,a3)
268 #define ATM_DEBUG4(f,a1,a2,a3,a4)
269 #define ATM_DEBUGN4(f,a1,a2,a3,a4)
270 #define ATM_DEBUG5(f,a1,a2,a3,a4,a5)
271 #define ATM_DEBUGN5(f,a1,a2,a3,a4,a5)
272 #endif
274 #endif /* ATM_KERNEL */
276 #endif /* _NETATM_ATM_SYS_H */