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