Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / netproto / atm / atm_stack.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_stack.h,v 1.2 1999/08/28 00:48:38 peter Exp $
27  *
28  */
29
30 /*
31  * Core ATM Services
32  * -----------------
33  *
34  * ATM Stack definitions
35  *
36  */
37
38 #ifndef _NETATM_ATM_STACK_H
39 #define _NETATM_ATM_STACK_H
40
41 #ifdef ATM_KERNEL
42 /*
43  * Structure used to define a kernel-provided ATM stack service and its
44  * associated entry points.  Each stack service provider must register
45  * themselves before they will be used.  ATM stack service providers include 
46  * kernel modules (both linked and loaded) and device drivers, which must list
47  * (via its atm_pif) any of its available hardware-supplied stack services 
48  * (such as on-card AAL processing).
49  */
50 struct stack_defn {
51         struct stack_defn *sd_next;     /* Next in registry list */
52         Sap_t           sd_sap;         /* Stack instance SAP */
53         u_char          sd_flag;        /* Flags (see below) */
54 /* Exported functions */
55         int             (*sd_inst)      /* Stack instantiation */
56                                 __P((struct stack_defn **, Atm_connvc *));
57         void            (*sd_lower)     /* Lower (from above) command handler */
58                                 __P((int, void *, int, int));
59         void            (*sd_upper)     /* Upper (from below) command handler */
60                                 __P((int, void *, int, int));
61 /* Variables used during stack instantiation */
62         void            *sd_toku;       /* Stack service instance token */
63 };
64
65 /*
66  * Stack Service Flags
67  */
68 #define SDF_TERM        0x01            /* Terminal (to lowest layer) service */
69
70
71 /*
72  * Stack Specification List  
73  *
74  * The list names the stack services and their layering relationships in
75  * order to construct a stack to provide the protocol services defined
76  * by the list.  The list is ordered starting from the stack service 
77  * interfacing with the user "down" to the ATM cell service.
78  */
79 #define STACK_CNT       8               /* Max services in a stack list */
80 struct stack_list {
81         Sap_t           sl_sap[STACK_CNT];      /* Stack service SAP list */
82 };
83
84
85 /*
86  * Structure used during the construction and instantiation of a stack 
87  * instance from a supplied stack list.  It contains pointers to the stack 
88  * service definitions which will be used to implement the stack.  The first 
89  * element in the array is reserved for the user's "stack service".
90  */
91 struct stack_inst {
92         struct stack_defn *si_srvc[STACK_CNT+1];        /* Assigned services */
93 };
94
95
96 /*
97  * Macros to update buffer headroom values during stack instantiation.
98  *
99  * These values are advisory, i.e. every service must verify the amount
100  * of available space in input/output messages and allocate new buffers
101  * if needed.
102  *
103  * The 'maximum' and 'minimum' values used below may be chosen by a 
104  * service to reflect the typical, expected message traffic pattern 
105  * for a specific connection.
106  * 
107  * The macro arguments are:
108  *      cvp = pointer to connection vcc;
109  *      hi = maximum amount of buffer headroom required by the current
110  *           service during input message processing;
111  *      si = minimum amount of buffer data stripped off the front 
112  *           of an input message by the current service;
113  *      ho = maximum amount of buffer headroom required by the current
114  *           service during output message processing;
115  *      ao = maximum amount of buffer data added to the front 
116  *           of an output message by the current service;
117  */
118 #define HEADIN(cvp, hi, si)                                     \
119 {                                                               \
120         short   t = (cvp)->cvc_attr.headin - (si);              \
121         t = (t >= (hi)) ? t : (hi);                             \
122         (cvp)->cvc_attr.headin = roundup(t, sizeof(long));      \
123 }
124
125 #define HEADOUT(cvp, ho, ao)                                    \
126 {                                                               \
127         short   t = (cvp)->cvc_attr.headout + (ao);             \
128         t = (t >= (ho)) ? t : (ho);                             \
129         (cvp)->cvc_attr.headout = roundup(t, sizeof(long));     \
130 }
131
132
133 /*
134  * Stack command codes - All stack command codes are specific to the 
135  * defined stack SAP across which the command is used.  Command values 0-15 
136  * are reserved for any common codes, which all stack SAPs must support.
137  */
138 #define STKCMD(s, d, v) (((s) << 16) | (d) | (v))
139 #define STKCMD_DOWN     0
140 #define STKCMD_UP       0x00008000
141 #define STKCMD_SAP_MASK 0xffff0000
142 #define STKCMD_VAL_MASK 0x00007fff
143
144 /* Common command values (0-15) */
145 #define CCV_INIT        1               /* DOWN */
146 #define CCV_TERM        2               /* DOWN */
147
148 /* SAP_ATM */
149 #define ATM_INIT                STKCMD(SAP_ATM, STKCMD_DOWN, CCV_INIT)
150 #define ATM_TERM                STKCMD(SAP_ATM, STKCMD_DOWN, CCV_TERM)
151 #define ATM_DATA_REQ            STKCMD(SAP_ATM, STKCMD_DOWN, 16)
152 #define ATM_DATA_IND            STKCMD(SAP_ATM, STKCMD_UP, 17)
153
154 /* SAP_SAR */
155 #define SAR_INIT                STKCMD(SAP_SAR, STKCMD_DOWN, CCV_INIT)
156 #define SAR_TERM                STKCMD(SAP_SAR, STKCMD_DOWN, CCV_TERM)
157 #define SAR_UNITDATA_INV        STKCMD(SAP_SAR, STKCMD_DOWN, 16)
158 #define SAR_UNITDATA_SIG        STKCMD(SAP_SAR, STKCMD_UP, 17)
159 #define SAR_UABORT_INV          STKCMD(SAP_SAR, STKCMD_DOWN, 18)
160 #define SAR_UABORT_SIG          STKCMD(SAP_SAR, STKCMD_UP, 19)
161 #define SAR_PABORT_SIG          STKCMD(SAP_SAR, STKCMD_UP, 20)
162
163 /* SAP_CPCS */
164 #define CPCS_INIT               STKCMD(SAP_CPCS, STKCMD_DOWN, CCV_INIT)
165 #define CPCS_TERM               STKCMD(SAP_CPCS, STKCMD_DOWN, CCV_TERM)
166 #define CPCS_UNITDATA_INV       STKCMD(SAP_CPCS, STKCMD_DOWN, 16)
167 #define CPCS_UNITDATA_SIG       STKCMD(SAP_CPCS, STKCMD_UP, 17)
168 #define CPCS_UABORT_INV         STKCMD(SAP_CPCS, STKCMD_DOWN, 18)
169 #define CPCS_UABORT_SIG         STKCMD(SAP_CPCS, STKCMD_UP, 19)
170 #define CPCS_PABORT_SIG         STKCMD(SAP_CPCS, STKCMD_UP, 20)
171
172 /* SAP_SSCOP */
173 #define SSCOP_INIT              STKCMD(SAP_SSCOP, STKCMD_DOWN, CCV_INIT)
174 #define SSCOP_TERM              STKCMD(SAP_SSCOP, STKCMD_DOWN, CCV_TERM)
175 #define SSCOP_ESTABLISH_REQ     STKCMD(SAP_SSCOP, STKCMD_DOWN, 16)
176 #define SSCOP_ESTABLISH_IND     STKCMD(SAP_SSCOP, STKCMD_UP, 17)
177 #define SSCOP_ESTABLISH_RSP     STKCMD(SAP_SSCOP, STKCMD_DOWN, 18)
178 #define SSCOP_ESTABLISH_CNF     STKCMD(SAP_SSCOP, STKCMD_UP, 19)
179 #define SSCOP_RELEASE_REQ       STKCMD(SAP_SSCOP, STKCMD_DOWN, 20)
180 #define SSCOP_RELEASE_IND       STKCMD(SAP_SSCOP, STKCMD_UP, 21)
181 #define SSCOP_RELEASE_CNF       STKCMD(SAP_SSCOP, STKCMD_UP, 22)
182 #define SSCOP_DATA_REQ          STKCMD(SAP_SSCOP, STKCMD_DOWN, 23)
183 #define SSCOP_DATA_IND          STKCMD(SAP_SSCOP, STKCMD_UP, 24)
184 #define SSCOP_RESYNC_REQ        STKCMD(SAP_SSCOP, STKCMD_DOWN, 25)
185 #define SSCOP_RESYNC_IND        STKCMD(SAP_SSCOP, STKCMD_UP, 26)
186 #define SSCOP_RESYNC_RSP        STKCMD(SAP_SSCOP, STKCMD_DOWN, 27)
187 #define SSCOP_RESYNC_CNF        STKCMD(SAP_SSCOP, STKCMD_UP, 28)
188 #define SSCOP_RECOVER_IND       STKCMD(SAP_SSCOP, STKCMD_UP, 29)
189 #define SSCOP_RECOVER_RSP       STKCMD(SAP_SSCOP, STKCMD_DOWN, 30)
190 #define SSCOP_UNITDATA_REQ      STKCMD(SAP_SSCOP, STKCMD_DOWN, 31)
191 #define SSCOP_UNITDATA_IND      STKCMD(SAP_SSCOP, STKCMD_UP, 32)
192 #define SSCOP_RETRIEVE_REQ      STKCMD(SAP_SSCOP, STKCMD_DOWN, 33)
193 #define SSCOP_RETRIEVE_IND      STKCMD(SAP_SSCOP, STKCMD_UP, 34)
194 #define SSCOP_RETRIEVECMP_IND   STKCMD(SAP_SSCOP, STKCMD_UP, 35)
195
196 /* SAP_SSCF_UNI */
197 #define SSCF_UNI_INIT           STKCMD(SAP_SSCF_UNI, STKCMD_DOWN, CCV_INIT)
198 #define SSCF_UNI_TERM           STKCMD(SAP_SSCF_UNI, STKCMD_DOWN, CCV_TERM)
199 #define SSCF_UNI_ESTABLISH_REQ  STKCMD(SAP_SSCF_UNI, STKCMD_DOWN, 16)
200 #define SSCF_UNI_ESTABLISH_IND  STKCMD(SAP_SSCF_UNI, STKCMD_UP, 17)
201 #define SSCF_UNI_ESTABLISH_CNF  STKCMD(SAP_SSCF_UNI, STKCMD_UP, 18)
202 #define SSCF_UNI_RELEASE_REQ    STKCMD(SAP_SSCF_UNI, STKCMD_DOWN, 19)
203 #define SSCF_UNI_RELEASE_IND    STKCMD(SAP_SSCF_UNI, STKCMD_UP, 20)
204 #define SSCF_UNI_RELEASE_CNF    STKCMD(SAP_SSCF_UNI, STKCMD_UP, 21)
205 #define SSCF_UNI_DATA_REQ       STKCMD(SAP_SSCF_UNI, STKCMD_DOWN, 22)
206 #define SSCF_UNI_DATA_IND       STKCMD(SAP_SSCF_UNI, STKCMD_UP, 23)
207 #define SSCF_UNI_UNITDATA_REQ   STKCMD(SAP_SSCF_UNI, STKCMD_DOWN, 24)
208 #define SSCF_UNI_UNITDATA_IND   STKCMD(SAP_SSCF_UNI, STKCMD_UP, 25)
209
210
211 /*
212  * The STACK_CALL macro must be used for all stack calls between adjacent
213  * entities.  In order to avoid the problem with recursive stack calls 
214  * modifying protocol state, this macro will only allow calls to proceed if 
215  * they are not "against the flow" of any currently pending calls for a
216  * stack instance.  If the requested call can't be processed now, it will 
217  * be deferred and queued until a later, safe time (but before control is 
218  * returned back to the kernel scheduler) when it will be dispatched.
219  *
220  * The STACK_CALL macro arguments are:
221  *      cmd = command code;
222  *      fn  = Destination entity processing function
223  *      tok = Destination layer's session token;
224  *      cvp = Connection VCC address;
225  *      a1  = command specific argument;
226  *      a2  = command specific argument;
227  *      ret = call result value (0 => success)
228  *
229  * The receiving entity command processing function prototype is:
230  *
231  *      void (fn)(int cmd, int tok, int arg1, int arg2)
232  *
233  */
234 #define STACK_CALL(cmd, fn, tok, cvp, a1, a2, ret)                      \
235 {                                                                       \
236         if ((cmd) & STKCMD_UP) {                                        \
237                 if ((cvp)->cvc_downcnt) {                               \
238                         (ret) = atm_stack_enq((cmd), (fn), (tok),       \
239                                                 (cvp), (a1), (a2));     \
240                 } else {                                                \
241                         (cvp)->cvc_upcnt++;                             \
242                         (*fn)(cmd, tok, a1, a2);                        \
243                         (cvp)->cvc_upcnt--;                             \
244                         (ret) = 0;                                      \
245                 }                                                       \
246         } else {                                                        \
247                 if ((cvp)->cvc_upcnt) {                                 \
248                         (ret) = atm_stack_enq((cmd), (fn), (tok),       \
249                                                 (cvp), (a1), (a2));     \
250                 } else {                                                \
251                         (cvp)->cvc_downcnt++;                           \
252                         (*fn)(cmd, tok, a1, a2);                        \
253                         (cvp)->cvc_downcnt--;                           \
254                         (ret) = 0;                                      \
255                 }                                                       \
256         }                                                               \
257 }
258
259
260 /*
261  * Stack queue entry - The stack queue will contain stack calls which have 
262  * been deferred in order to avoid recursive calls to a single protocol 
263  * control block.  The queue entries are allocated from its own storage pool.
264  */
265 struct stackq_entry {
266         struct stackq_entry *sq_next;   /* Next entry in queue */
267         int             sq_cmd;         /* Stack command */
268         void            (*sq_func)      /* Destination function */
269                                 __P((int, void *, int, int));
270         void            *sq_token;      /* Destination token */
271         int             sq_arg1;        /* Command-specific argument */
272         int             sq_arg2;        /* Command-specific argument */
273         Atm_connvc      *sq_connvc;     /* Connection VCC */
274 };
275
276
277 /*
278  * Macro to avoid unnecessary function call when draining the stack queue.
279  */
280 #define STACK_DRAIN()                                                   \
281 {                                                                       \
282         if (atm_stackq_head)                                            \
283                 atm_stack_drain();                                      \
284 }
285 #endif  /* ATM_KERNEL */
286
287 #endif  /* _NETATM_ATM_STACK_H */