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_signal.c,v 1.4 1999/08/28 00:48:37 peter Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/atm_signal.c,v 1.5 2005/06/02 22:37:45 dillon Exp $
34 * General ATM signalling management
38 #include "kern_include.h"
43 static struct sigmgr *atm_sigmgr_head = NULL;
44 static struct stack_defn *atm_stack_head = NULL;
48 * Register a new Signalling Manager
50 * Each Signalling Manager must register itself here upon completing
51 * its internal initialization. This applies to both linked and loaded
55 * smp pointer to Signalling Manager description
58 * 0 registration was successful
59 * errno registration failed - reason indicated
63 atm_sigmgr_register(smp)
71 * See if we need to be initialized
77 * Make sure there's only one instance of each protocol
79 for (smp2 = atm_sigmgr_head; smp2 != NULL; smp2 = smp2->sm_next) {
80 if (smp->sm_proto == smp2->sm_proto) {
87 * Looks okay, link it in
89 LINK2TAIL(smp, struct sigmgr, atm_sigmgr_head, sm_next);
97 * De-register a Signalling Manager
99 * Each Signalling Manager must de-register (is this really a word?)
100 * itself before removing itself from the system. This really only
101 * applies to managers about to be modunload'ed. It is the signal
102 * manager's responsibility to ensure that all its protocol instances
103 * have been successfully terminated before de-registering itself.
106 * smp pointer to Signalling Manager description
109 * 0 deregistration was successful
110 * errno deregistration failed - reason indicated
114 atm_sigmgr_deregister(smp)
123 UNLINKF(smp, struct sigmgr, atm_sigmgr_head, sm_next, found);
134 * Attach a Signalling Manager to an ATM physical interface
136 * Each ATM physical interface must have a signalling manager attached to
137 * itself for the signalling protocol to be run across this interface. The
138 * interface must be registered and completely initialized before the attach,
139 * since the signalling manager may initiate virtual circuit activity as part
140 * its response to this call.
142 * Called from a critical section.
145 * pip pointer to atm physical interface control block
146 * proto requested signalling protocol
149 * 0 attach successful
150 * errno attach failed - reason indicated
154 atm_sigmgr_attach(pip, proto)
163 * Make sure interface is registered
165 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
174 * Make sure no signalling manager is already attached
176 if (pip->pif_sigmgr != NULL) {
181 * Must have at least one network interface defined
183 if (pip->pif_nif == NULL)
184 return (ETOOMANYREFS);
187 * Find requested protocol
189 for (smp = atm_sigmgr_head; smp != NULL; smp = smp->sm_next) {
190 if (smp->sm_proto == proto)
194 return (EPROTONOSUPPORT);
198 * Tell the signal manager about it
200 err = (*smp->sm_attach)(smp, pip);
203 * Tell all registered convergence modules about this
209 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
210 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
211 if ((err = (*ncp->ncm_stat)
212 (NCM_SIGATTACH, nip, 0)) != 0)
221 * Someone's unhappy, so back all this out
223 (void) atm_sigmgr_detach(pip);
232 * Detach an ATM physical interface from a Signalling Manager
234 * The ATM interface must be detached from the signalling manager
235 * before the interface can be de-registered.
237 * Called from a critical section.
240 * pip pointer to atm physical interface control block
243 * 0 detach successful
244 * errno detach failed - reason indicated
248 atm_sigmgr_detach(pip)
258 * Make sure interface is registered
260 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
269 * Make sure a signalling manager is attached
271 if (pip->pif_sigmgr == NULL) {
276 * Tell all registered convergence modules about this
278 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
279 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
280 (void) (*ncp->ncm_stat)(NCM_SIGDETACH, nip, 0);
285 * Tell the signal manager about it
288 * The only reason this should ever fail is if things are really
289 * hosed up somewhere, in which case doing a bunch of NCM_SIGATTACH's
290 * here just doesn't seem to help much.
292 err = (*pip->pif_sigmgr->sm_detach)(pip);
299 * Register an ATM Stack Service
301 * Each ATM stack service provider must register its provided service(s) here.
302 * Each service must be registered separately. Service providers include
303 * both loaded and linked kernel modules. Device driver services are NOT
304 * registered here - their service registry is performed implicitly through
305 * the device interface structure stack services list (pif_services).
308 * sdp pointer to stack service definition block
311 * 0 registration successful
312 * errno registration failed - reason indicated
316 atm_stack_register(sdp)
317 struct stack_defn *sdp;
319 struct stack_defn *tdp;
324 * See if we need to be initialized
330 * Ensure no duplicates
332 for (tdp = atm_stack_head; tdp != NULL; tdp = tdp->sd_next) {
333 if (tdp->sd_sap == sdp->sd_sap)
344 LINK2TAIL(sdp, struct stack_defn, atm_stack_head, sd_next);
352 * De-register an ATM Stack Service
354 * Each ATM stack service provider must de-register its registered service(s)
355 * before terminating the service. Specifically, loaded kernel modules
356 * must de-register their services before unloading themselves.
359 * sdp pointer to stack service definition block
362 * 0 de-registration successful
363 * errno de-registration failed - reason indicated
367 atm_stack_deregister(sdp)
368 struct stack_defn *sdp;
373 * Remove service from list
376 UNLINKF(sdp, struct stack_defn, atm_stack_head, sd_next, found);
387 * Create and Instantiate a Stack
389 * For the requested stack list, locate the stack service definitions
390 * necessary to build the stack to implement the listed services.
391 * The stack service definitions provided by the interface device-driver
392 * are always preferred, since they are (hopefully) done with
393 * hardware assistance from the interface card.
395 * After the stack has been built, the selected services are called to
396 * notify them of the new stack instantiation. Each service should then
397 * allocate all the resources it requires for this new stack instance.
398 * The service should then wait for subsequent protocol notification
399 * via its stack command handlers.
401 * Must be called from a critical section.
404 * cvp pointer to connection vcc block for the created stack
405 * tlp pointer to stack list
406 * upf top-of-stack CM upper command handler
409 * 0 stack successfully created
410 * errno failed - reason indicated
414 atm_create_stack(cvp, tlp, upf)
416 struct stack_list *tlp;
417 void (*upf)(int, void *, int, int);
419 struct stack_defn *sdp, usd;
420 struct stack_inst svs;
421 struct atm_pif *pip = cvp->cvc_attr.nif->nif_pif;
426 * Initialize stack (element 0 is for owner's services)
428 svs.si_srvc[1] = sdp = NULL;
431 * Locate service provider for each service in the
432 * stack list. We prefer interface driver providers
433 * over kernel module providers.
435 for (i = 0; i < STACK_CNT; i++) {
438 /* Stack list is 0-terminated */
439 if ((sap = tlp->sl_sap[i]) == 0)
443 * Search interface's services
445 for (sdp = pip->pif_services; sdp; sdp = sdp->sd_next)
446 if (sdp->sd_sap == sap)
451 * Search kernel services
453 for (sdp = atm_stack_head; sdp;
455 if (sdp->sd_sap == sap)
461 * Requested service id not found
467 * Save stack definition for this service
469 svs.si_srvc[i+1] = sdp;
472 * Quit loop if this service is terminal, ie. if
473 * it takes care of the rest of the stack.
475 if (sdp->sd_flag & SDF_TERM)
480 * Ensure stack instance array is located and terminated
482 if ((svs.si_srvc[1] == NULL) || !(sdp->sd_flag & SDF_TERM)) {
487 * Setup owner service definition
489 KM_ZERO((caddr_t)&usd, sizeof(struct stack_defn));
492 svs.si_srvc[0] = &usd;
495 * Instantiate the stack
497 err = (*svs.si_srvc[1]->sd_inst)(&svs.si_srvc[0], cvp);
503 * Save top 'o stack info
505 cvp->cvc_lower = svs.si_srvc[1]->sd_lower;
506 cvp->cvc_tokl = svs.si_srvc[1]->sd_toku;