if_xname support Part 2/2: Convert remaining netif devices and implement full
[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  *      @(#) $DragonFly: src/sys/netproto/atm/atm_sys.h,v 1.3 2003/08/23 10:06:21 rob Exp $
28  *
29  */
30
31 /*
32  * Core ATM Services
33  * -----------------
34  *
35  * General system definitions
36  *
37  */
38
39 #ifndef _NETATM_ATM_SYS_H
40 #define _NETATM_ATM_SYS_H
41
42 /*
43  * Software Version
44  */
45 #define ATM_VERSION     0x00030000      /* Version 3.0 */
46 #define ATM_VERS_MAJ(v) ((v) >> 16)
47 #define ATM_VERS_MIN(v) ((v) & 0xffff)
48
49
50 /*
51  * Misc system defines
52  */
53 #define ATM_CALLQ_MAX   100             /* Maximum length of call queue */
54 #define ATM_INTRQ_MAX   1000            /* Maximum length of interrupt queue */
55
56
57 /*
58  * ATM address manipulation macros
59  */
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))
65
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))))
78
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);                                  \
85 }
86
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         }                                                               \
100 }
101
102
103 /*
104  * ATM Cell Header definitions
105  */
106
107 /*
108  * These macros assume that the cell header (minus the HEC)
109  * is contained in the least-significant 32-bits of a word
110  */
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)
123
124 /*
125  * Payload Type Identifier (3 bits)
126  */
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 */
134
135
136 /*
137  * AAL (ATM Adaptation Layer) codes
138  */
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 */
145
146
147 /*
148  * VCC Encapsulation codes
149  */
150 typedef u_char  Encaps_t;
151 #define ATM_ENC_NULL    1               /* Null encapsulation */
152 #define ATM_ENC_LLC     2               /* LLC encapsulation */
153
154
155 #ifdef ATM_KERNEL
156 /*
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.
160  */
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 */
167 };
168
169 /*
170  * Timer Flags
171  */
172 #define TIF_QUEUED      0x01            /* Control block on timer queue */
173
174 #define ATM_HZ          2               /* Time ticks per second */
175
176
177 /*
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. 
185  *
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.
189  */
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 */
196
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 */
208 };
209
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 */
217 };
218
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;
224 };
225
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 */
230
231 /*
232  * Debugging
233  */
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;                               \
244         }                                                               \
245         printf("%3ld.%6ld: ", delta.tv_sec, delta.tv_usec);
246
247 #define ATM_DEBUG0(f)           if (atm_debug) {ATM_TIME; printf(f);}
248 #define ATM_DEBUGN0(f)          if (atm_debug) {printf(f);}
249 #define ATM_DEBUG1(f,a1)        if (atm_debug) {ATM_TIME; printf(f, a1);}
250 #define ATM_DEBUGN1(f,a1)       if (atm_debug) {printf(f, a1);}
251 #define ATM_DEBUG2(f,a1,a2)     if (atm_debug) {ATM_TIME; printf(f, a1, a2);}
252 #define ATM_DEBUGN2(f,a1,a2)    if (atm_debug) {printf(f, a1, a2);}
253 #define ATM_DEBUG3(f,a1,a2,a3)  if (atm_debug) {ATM_TIME; printf(f, a1, a2, a3);}
254 #define ATM_DEBUGN3(f,a1,a2,a3) if (atm_debug) {printf(f, a1, a2, a3);}
255 #define ATM_DEBUG4(f,a1,a2,a3,a4)       if (atm_debug) {ATM_TIME; printf(f, a1, a2, a3, a4);}
256 #define ATM_DEBUGN4(f,a1,a2,a3,a4)      if (atm_debug) {printf(f, a1, a2, a3, a4);}
257 #define ATM_DEBUG5(f,a1,a2,a3,a4,a5)    if (atm_debug) {ATM_TIME; printf(f, a1, a2, a3, a4, a5);}
258 #define ATM_DEBUGN5(f,a1,a2,a3,a4,a5)   if (atm_debug) {printf(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
273
274 #endif  /* ATM_KERNEL */
275
276 #endif  /* _NETATM_ATM_SYS_H */