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 $
34 * General ATM signalling management
38 #include <netatm/kern_include.h>
41 __RCSID("@(#) $FreeBSD: src/sys/netatm/atm_signal.c,v 1.4 1999/08/28 00:48:37 peter Exp $");
48 static struct sigmgr *atm_sigmgr_head = NULL;
49 static struct stack_defn *atm_stack_head = NULL;
53 * Register a new Signalling Manager
55 * Each Signalling Manager must register itself here upon completing
56 * its internal initialization. This applies to both linked and loaded
60 * smp pointer to Signalling Manager description
63 * 0 registration was successful
64 * errno registration failed - reason indicated
68 atm_sigmgr_register(smp)
75 * See if we need to be initialized
81 * Make sure there's only one instance of each protocol
83 for (smp2 = atm_sigmgr_head; smp2 != NULL; smp2 = smp2->sm_next) {
84 if (smp->sm_proto == smp2->sm_proto) {
91 * Looks okay, link it in
93 LINK2TAIL(smp, struct sigmgr, atm_sigmgr_head, sm_next);
101 * De-register a Signalling Manager
103 * Each Signalling Manager must de-register (is this really a word?)
104 * itself before removing itself from the system. This really only
105 * applies to managers about to be modunload'ed. It is the signal
106 * manager's responsibility to ensure that all its protocol instances
107 * have been successfully terminated before de-registering itself.
110 * smp pointer to Signalling Manager description
113 * 0 deregistration was successful
114 * errno deregistration failed - reason indicated
118 atm_sigmgr_deregister(smp)
121 int found, s = splnet();
126 UNLINKF(smp, struct sigmgr, atm_sigmgr_head, sm_next, found);
138 * Attach a Signalling Manager to an ATM physical interface
140 * Each ATM physical interface must have a signalling manager attached to
141 * itself for the signalling protocol to be run across this interface. The
142 * interface must be registered and completely initialized before the attach,
143 * since the signalling manager may initiate virtual circuit activity as part
144 * its response to this call.
149 * pip pointer to atm physical interface control block
150 * proto requested signalling protocol
153 * 0 attach successful
154 * errno attach failed - reason indicated
158 atm_sigmgr_attach(pip, proto)
167 * Make sure interface is registered
169 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
178 * Make sure no signalling manager is already attached
180 if (pip->pif_sigmgr != NULL) {
185 * Must have at least one network interface defined
187 if (pip->pif_nif == NULL)
188 return (ETOOMANYREFS);
191 * Find requested protocol
193 for (smp = atm_sigmgr_head; smp != NULL; smp = smp->sm_next) {
194 if (smp->sm_proto == proto)
198 return (EPROTONOSUPPORT);
202 * Tell the signal manager about it
204 err = (*smp->sm_attach)(smp, pip);
207 * Tell all registered convergence modules about this
213 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
214 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
215 if ((err = (*ncp->ncm_stat)
216 (NCM_SIGATTACH, nip, 0)) != 0)
225 * Someone's unhappy, so back all this out
227 (void) atm_sigmgr_detach(pip);
236 * Detach an ATM physical interface from a Signalling Manager
238 * The ATM interface must be detached from the signalling manager
239 * before the interface can be de-registered.
244 * pip pointer to atm physical interface control block
247 * 0 detach successful
248 * errno detach failed - reason indicated
252 atm_sigmgr_detach(pip)
262 * Make sure interface is registered
264 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
273 * Make sure a signalling manager is attached
275 if (pip->pif_sigmgr == NULL) {
280 * Tell all registered convergence modules about this
282 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
283 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
284 (void) (*ncp->ncm_stat)(NCM_SIGDETACH, nip, 0);
289 * Tell the signal manager about it
292 * The only reason this should ever fail is if things are really
293 * hosed up somewhere, in which case doing a bunch of NCM_SIGATTACH's
294 * here just doesn't seem to help much.
296 err = (*pip->pif_sigmgr->sm_detach)(pip);
303 * Register an ATM Stack Service
305 * Each ATM stack service provider must register its provided service(s) here.
306 * Each service must be registered separately. Service providers include
307 * both loaded and linked kernel modules. Device driver services are NOT
308 * registered here - their service registry is performed implicitly through
309 * the device interface structure stack services list (pif_services).
312 * sdp pointer to stack service definition block
315 * 0 registration successful
316 * errno registration failed - reason indicated
320 atm_stack_register(sdp)
321 struct stack_defn *sdp;
323 struct stack_defn *tdp;
327 * See if we need to be initialized
333 * Ensure no duplicates
335 for (tdp = atm_stack_head; tdp != NULL; tdp = tdp->sd_next) {
336 if (tdp->sd_sap == sdp->sd_sap)
347 LINK2TAIL(sdp, struct stack_defn, atm_stack_head, sd_next);
355 * De-register an ATM Stack Service
357 * Each ATM stack service provider must de-register its registered service(s)
358 * before terminating the service. Specifically, loaded kernel modules
359 * must de-register their services before unloading themselves.
362 * sdp pointer to stack service definition block
365 * 0 de-registration successful
366 * errno de-registration failed - reason indicated
370 atm_stack_deregister(sdp)
371 struct stack_defn *sdp;
373 int found, s = splnet();
376 * Remove service from list
378 UNLINKF(sdp, struct stack_defn, atm_stack_head, sd_next, found);
389 * Create and Instantiate a Stack
391 * For the requested stack list, locate the stack service definitions
392 * necessary to build the stack to implement the listed services.
393 * The stack service definitions provided by the interface device-driver
394 * are always preferred, since they are (hopefully) done with
395 * hardware assistance from the interface card.
397 * After the stack has been built, the selected services are called to
398 * notify them of the new stack instantiation. Each service should then
399 * allocate all the resources it requires for this new stack instance.
400 * The service should then wait for subsequent protocol notification
401 * via its stack command handlers.
403 * Must be called at splnet.
406 * cvp pointer to connection vcc block for the created stack
407 * tlp pointer to stack list
408 * upf top-of-stack CM upper command handler
411 * 0 stack successfully created
412 * errno failed - reason indicated
416 atm_create_stack(cvp, tlp, upf)
418 struct stack_list *tlp;
419 void (*upf)__P((int, void *, int, int));
421 struct stack_defn *sdp, usd;
422 struct stack_inst svs;
423 struct atm_pif *pip = cvp->cvc_attr.nif->nif_pif;
428 * Initialize stack (element 0 is for owner's services)
430 svs.si_srvc[1] = sdp = NULL;
433 * Locate service provider for each service in the
434 * stack list. We prefer interface driver providers
435 * over kernel module providers.
437 for (i = 0; i < STACK_CNT; i++) {
440 /* Stack list is 0-terminated */
441 if ((sap = tlp->sl_sap[i]) == 0)
445 * Search interface's services
447 for (sdp = pip->pif_services; sdp; sdp = sdp->sd_next)
448 if (sdp->sd_sap == sap)
453 * Search kernel services
455 for (sdp = atm_stack_head; sdp;
457 if (sdp->sd_sap == sap)
463 * Requested service id not found
469 * Save stack definition for this service
471 svs.si_srvc[i+1] = sdp;
474 * Quit loop if this service is terminal, ie. if
475 * it takes care of the rest of the stack.
477 if (sdp->sd_flag & SDF_TERM)
482 * Ensure stack instance array is located and terminated
484 if ((svs.si_srvc[1] == NULL) || !(sdp->sd_flag & SDF_TERM)) {
489 * Setup owner service definition
491 KM_ZERO((caddr_t)&usd, sizeof(struct stack_defn));
494 svs.si_srvc[0] = &usd;
497 * Instantiate the stack
499 err = (*svs.si_srvc[1]->sd_inst)(&svs.si_srvc[0], cvp);
505 * Save top 'o stack info
507 cvp->cvc_lower = svs.si_srvc[1]->sd_lower;
508 cvp->cvc_tokl = svs.si_srvc[1]->sd_toku;