17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate/*
307c478bdstevel@tonic-gate * This file implements the _init(9e), _info(9e) and _fini(9e) functions.
317c478bdstevel@tonic-gate */
327c478bdstevel@tonic-gate
337c478bdstevel@tonic-gate#include <sys/ib/mgt/ibmf/ibmf_impl.h>
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate/* Module Info */
367c478bdstevel@tonic-gatestatic struct modlmisc ibmf_modlmisc = {
377c478bdstevel@tonic-gate	&mod_miscops,
387c478bdstevel@tonic-gate	"IB Agent Interfaces 2.0"
397c478bdstevel@tonic-gate};
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate/* Module linkage */
427c478bdstevel@tonic-gatestatic struct modlinkage ibmf_modlinkage = {
437c478bdstevel@tonic-gate	MODREV_1,
447c478bdstevel@tonic-gate	&ibmf_modlmisc,
457c478bdstevel@tonic-gate	NULL
467c478bdstevel@tonic-gate};
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gatestatic ibmf_state_t		ibmf_state;
497c478bdstevel@tonic-gateibmf_state_t			*ibmf_statep;
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gateextern int ibmf_init();
527c478bdstevel@tonic-gateextern int ibmf_fini();
537c478bdstevel@tonic-gateextern int ibmf_saa_impl_init();
547c478bdstevel@tonic-gateextern int ibmf_saa_impl_fini();
557c478bdstevel@tonic-gate
567c478bdstevel@tonic-gate#ifndef	NPROBE
577c478bdstevel@tonic-gateextern int tnf_mod_load(void);
587c478bdstevel@tonic-gateextern int tnf_mod_unload(struct modlinkage *mlp);
597c478bdstevel@tonic-gate#endif
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gateint
627c478bdstevel@tonic-gate_init()
637c478bdstevel@tonic-gate{
647c478bdstevel@tonic-gate	int status;
657c478bdstevel@tonic-gate
667c478bdstevel@tonic-gate	/* CONSTCOND */
677c478bdstevel@tonic-gate	ASSERT(NO_COMPETING_THREADS);
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate#ifndef	NPROBE
707c478bdstevel@tonic-gate	(void) tnf_mod_load();
717c478bdstevel@tonic-gate#endif
727c478bdstevel@tonic-gate	ibmf_statep = &ibmf_state;
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gate	/*
757c478bdstevel@tonic-gate	 * call ibmf_saa_init first so it can set up subnet list before being
767c478bdstevel@tonic-gate	 * contacted with ibt_async events
777c478bdstevel@tonic-gate	 */
787c478bdstevel@tonic-gate	status = ibmf_saa_impl_init();
797c478bdstevel@tonic-gate	if (status != IBMF_SUCCESS) {
807c478bdstevel@tonic-gate		TNF_PROBE_1(_init_error, IBMF_TNF_ERROR, "", tnf_string, msg,
817c478bdstevel@tonic-gate		    "ibmf_saa_impl_init failed");
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gate#ifndef	NPROBE
847c478bdstevel@tonic-gate		(void) tnf_mod_unload(&ibmf_modlinkage);
857c478bdstevel@tonic-gate#endif
867c478bdstevel@tonic-gate		return (EACCES);
877c478bdstevel@tonic-gate	}
887c478bdstevel@tonic-gate
897c478bdstevel@tonic-gate
907c478bdstevel@tonic-gate
917c478bdstevel@tonic-gate	status = ibmf_init();
927c478bdstevel@tonic-gate	if (status != 0) {
937c478bdstevel@tonic-gate		TNF_PROBE_1(_init_error, IBMF_TNF_ERROR, "", tnf_string, msg,
947c478bdstevel@tonic-gate		    "ibmf_init failed");
957c478bdstevel@tonic-gate
967c478bdstevel@tonic-gate		(void) ibmf_saa_impl_fini();
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gate#ifndef	NPROBE
997c478bdstevel@tonic-gate		(void) tnf_mod_unload(&ibmf_modlinkage);
1007c478bdstevel@tonic-gate#endif
1017c478bdstevel@tonic-gate		return (EACCES);
1027c478bdstevel@tonic-gate	}
1037c478bdstevel@tonic-gate
1047c478bdstevel@tonic-gate	status = mod_install(&ibmf_modlinkage);
1057c478bdstevel@tonic-gate	if (status != 0) {
1067c478bdstevel@tonic-gate		TNF_PROBE_2(_init_error, IBMF_TNF_ERROR, "", tnf_string, msg,
1077c478bdstevel@tonic-gate		    "mod_install failed", tnf_uint, status, status);
1087c478bdstevel@tonic-gate#ifndef NPROBE
1097c478bdstevel@tonic-gate		(void) tnf_mod_unload(&ibmf_modlinkage);
1107c478bdstevel@tonic-gate#endif
1117c478bdstevel@tonic-gate		(void) ibmf_fini();
1127c478bdstevel@tonic-gate		ibmf_statep = (ibmf_state_t *)NULL;
1137c478bdstevel@tonic-gate	}
1147c478bdstevel@tonic-gate
1157c478bdstevel@tonic-gate	return (status);
1167c478bdstevel@tonic-gate}
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gateint
1197c478bdstevel@tonic-gate_info(struct modinfo *modinfop)
1207c478bdstevel@tonic-gate{
1217c478bdstevel@tonic-gate	return (mod_info(&ibmf_modlinkage, modinfop));
1227c478bdstevel@tonic-gate}
1237c478bdstevel@tonic-gate
1247c478bdstevel@tonic-gateint
1257c478bdstevel@tonic-gate_fini()
1267c478bdstevel@tonic-gate{
1277c478bdstevel@tonic-gate	int status;
1287c478bdstevel@tonic-gate	status = mod_remove(&ibmf_modlinkage);
1297c478bdstevel@tonic-gate	if (status != 0) {
1307c478bdstevel@tonic-gate		TNF_PROBE_2(_fini_error, IBMF_TNF_ERROR, "", tnf_string, msg,
1317c478bdstevel@tonic-gate		    "mod_remove failed", tnf_uint, status, status);
1327c478bdstevel@tonic-gate		return (status);
1337c478bdstevel@tonic-gate	}
1347c478bdstevel@tonic-gate
1357c478bdstevel@tonic-gate	status = ibmf_saa_impl_fini();
1367c478bdstevel@tonic-gate	if (status != 0) {
1377c478bdstevel@tonic-gate
1387c478bdstevel@tonic-gate		TNF_PROBE_2(_fini_error, IBMF_TNF_ERROR, "", tnf_string, msg,
1397c478bdstevel@tonic-gate		    "ibmf_saa fini failed", tnf_uint, status, status);
1407c478bdstevel@tonic-gate		return (status);
1417c478bdstevel@tonic-gate	}
1427c478bdstevel@tonic-gate
1437c478bdstevel@tonic-gate	(void) ibmf_fini();
1447c478bdstevel@tonic-gate	ibmf_statep = (ibmf_state_t *)NULL;
1457c478bdstevel@tonic-gate#ifndef	NPROBE
1467c478bdstevel@tonic-gate	(void) tnf_mod_unload(&ibmf_modlinkage);
1477c478bdstevel@tonic-gate#endif
1487c478bdstevel@tonic-gate	return (status);
1497c478bdstevel@tonic-gate}
150