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.2 2003/06/17 04:28:49 dillon Exp $
34 * General ATM signalling management
38 #include <netatm/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)
70 * See if we need to be initialized
76 * Make sure there's only one instance of each protocol
78 for (smp2 = atm_sigmgr_head; smp2 != NULL; smp2 = smp2->sm_next) {
79 if (smp->sm_proto == smp2->sm_proto) {
86 * Looks okay, link it in
88 LINK2TAIL(smp, struct sigmgr, atm_sigmgr_head, sm_next);
96 * De-register a Signalling Manager
98 * Each Signalling Manager must de-register (is this really a word?)
99 * itself before removing itself from the system. This really only
100 * applies to managers about to be modunload'ed. It is the signal
101 * manager's responsibility to ensure that all its protocol instances
102 * have been successfully terminated before de-registering itself.
105 * smp pointer to Signalling Manager description
108 * 0 deregistration was successful
109 * errno deregistration failed - reason indicated
113 atm_sigmgr_deregister(smp)
116 int found, s = splnet();
121 UNLINKF(smp, struct sigmgr, atm_sigmgr_head, sm_next, found);
133 * Attach a Signalling Manager to an ATM physical interface
135 * Each ATM physical interface must have a signalling manager attached to
136 * itself for the signalling protocol to be run across this interface. The
137 * interface must be registered and completely initialized before the attach,
138 * since the signalling manager may initiate virtual circuit activity as part
139 * its response to this call.
144 * pip pointer to atm physical interface control block
145 * proto requested signalling protocol
148 * 0 attach successful
149 * errno attach failed - reason indicated
153 atm_sigmgr_attach(pip, proto)
162 * Make sure interface is registered
164 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
173 * Make sure no signalling manager is already attached
175 if (pip->pif_sigmgr != NULL) {
180 * Must have at least one network interface defined
182 if (pip->pif_nif == NULL)
183 return (ETOOMANYREFS);
186 * Find requested protocol
188 for (smp = atm_sigmgr_head; smp != NULL; smp = smp->sm_next) {
189 if (smp->sm_proto == proto)
193 return (EPROTONOSUPPORT);
197 * Tell the signal manager about it
199 err = (*smp->sm_attach)(smp, pip);
202 * Tell all registered convergence modules about this
208 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
209 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
210 if ((err = (*ncp->ncm_stat)
211 (NCM_SIGATTACH, nip, 0)) != 0)
220 * Someone's unhappy, so back all this out
222 (void) atm_sigmgr_detach(pip);
231 * Detach an ATM physical interface from a Signalling Manager
233 * The ATM interface must be detached from the signalling manager
234 * before the interface can be de-registered.
239 * pip pointer to atm physical interface control block
242 * 0 detach successful
243 * errno detach failed - reason indicated
247 atm_sigmgr_detach(pip)
257 * Make sure interface is registered
259 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
268 * Make sure a signalling manager is attached
270 if (pip->pif_sigmgr == NULL) {
275 * Tell all registered convergence modules about this
277 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
278 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
279 (void) (*ncp->ncm_stat)(NCM_SIGDETACH, nip, 0);
284 * Tell the signal manager about it
287 * The only reason this should ever fail is if things are really
288 * hosed up somewhere, in which case doing a bunch of NCM_SIGATTACH's
289 * here just doesn't seem to help much.
291 err = (*pip->pif_sigmgr->sm_detach)(pip);
298 * Register an ATM Stack Service
300 * Each ATM stack service provider must register its provided service(s) here.
301 * Each service must be registered separately. Service providers include
302 * both loaded and linked kernel modules. Device driver services are NOT
303 * registered here - their service registry is performed implicitly through
304 * the device interface structure stack services list (pif_services).
307 * sdp pointer to stack service definition block
310 * 0 registration successful
311 * errno registration failed - reason indicated
315 atm_stack_register(sdp)
316 struct stack_defn *sdp;
318 struct stack_defn *tdp;
322 * See if we need to be initialized
328 * Ensure no duplicates
330 for (tdp = atm_stack_head; tdp != NULL; tdp = tdp->sd_next) {
331 if (tdp->sd_sap == sdp->sd_sap)
342 LINK2TAIL(sdp, struct stack_defn, atm_stack_head, sd_next);
350 * De-register an ATM Stack Service
352 * Each ATM stack service provider must de-register its registered service(s)
353 * before terminating the service. Specifically, loaded kernel modules
354 * must de-register their services before unloading themselves.
357 * sdp pointer to stack service definition block
360 * 0 de-registration successful
361 * errno de-registration failed - reason indicated
365 atm_stack_deregister(sdp)
366 struct stack_defn *sdp;
368 int found, s = splnet();
371 * Remove service from list
373 UNLINKF(sdp, struct stack_defn, atm_stack_head, sd_next, found);
384 * Create and Instantiate a Stack
386 * For the requested stack list, locate the stack service definitions
387 * necessary to build the stack to implement the listed services.
388 * The stack service definitions provided by the interface device-driver
389 * are always preferred, since they are (hopefully) done with
390 * hardware assistance from the interface card.
392 * After the stack has been built, the selected services are called to
393 * notify them of the new stack instantiation. Each service should then
394 * allocate all the resources it requires for this new stack instance.
395 * The service should then wait for subsequent protocol notification
396 * via its stack command handlers.
398 * Must be called at splnet.
401 * cvp pointer to connection vcc block for the created stack
402 * tlp pointer to stack list
403 * upf top-of-stack CM upper command handler
406 * 0 stack successfully created
407 * errno failed - reason indicated
411 atm_create_stack(cvp, tlp, upf)
413 struct stack_list *tlp;
414 void (*upf)__P((int, void *, int, int));
416 struct stack_defn *sdp, usd;
417 struct stack_inst svs;
418 struct atm_pif *pip = cvp->cvc_attr.nif->nif_pif;
423 * Initialize stack (element 0 is for owner's services)
425 svs.si_srvc[1] = sdp = NULL;
428 * Locate service provider for each service in the
429 * stack list. We prefer interface driver providers
430 * over kernel module providers.
432 for (i = 0; i < STACK_CNT; i++) {
435 /* Stack list is 0-terminated */
436 if ((sap = tlp->sl_sap[i]) == 0)
440 * Search interface's services
442 for (sdp = pip->pif_services; sdp; sdp = sdp->sd_next)
443 if (sdp->sd_sap == sap)
448 * Search kernel services
450 for (sdp = atm_stack_head; sdp;
452 if (sdp->sd_sap == sap)
458 * Requested service id not found
464 * Save stack definition for this service
466 svs.si_srvc[i+1] = sdp;
469 * Quit loop if this service is terminal, ie. if
470 * it takes care of the rest of the stack.
472 if (sdp->sd_flag & SDF_TERM)
477 * Ensure stack instance array is located and terminated
479 if ((svs.si_srvc[1] == NULL) || !(sdp->sd_flag & SDF_TERM)) {
484 * Setup owner service definition
486 KM_ZERO((caddr_t)&usd, sizeof(struct stack_defn));
489 svs.si_srvc[0] = &usd;
492 * Instantiate the stack
494 err = (*svs.si_srvc[1]->sd_inst)(&svs.si_srvc[0], cvp);
500 * Save top 'o stack info
502 cvp->cvc_lower = svs.si_srvc[1]->sd_lower;
503 cvp->cvc_tokl = svs.si_srvc[1]->sd_toku;