1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 28 29 /* 30 * This file implements the _init(9e), _info(9e) and _fini(9e) functions. 31 */ 32 33 #include <sys/ib/mgt/ibmf/ibmf_impl.h> 34 35 /* Module Info */ 36 static struct modlmisc ibmf_modlmisc = { 37 &mod_miscops, 38 "IB Agent Interfaces 2.0" 39 }; 40 41 /* Module linkage */ 42 static struct modlinkage ibmf_modlinkage = { 43 MODREV_1, 44 { &ibmf_modlmisc, 45 NULL } 46 }; 47 48 static ibmf_state_t ibmf_state; 49 ibmf_state_t *ibmf_statep; 50 51 extern int ibmf_init(); 52 extern int ibmf_fini(); 53 extern int ibmf_saa_impl_init(); 54 extern int ibmf_saa_impl_fini(); 55 56 #ifndef NPROBE 57 extern int tnf_mod_load(void); 58 extern int tnf_mod_unload(struct modlinkage *mlp); 59 #endif 60 61 int 62 _init() 63 { 64 int status; 65 66 /* CONSTCOND */ 67 ASSERT(NO_COMPETING_THREADS); 68 69 #ifndef NPROBE 70 (void) tnf_mod_load(); 71 #endif 72 ibmf_statep = &ibmf_state; 73 74 /* 75 * call ibmf_saa_init first so it can set up subnet list before being 76 * contacted with ibt_async events 77 */ 78 status = ibmf_saa_impl_init(); 79 if (status != IBMF_SUCCESS) { 80 TNF_PROBE_1(_init_error, IBMF_TNF_ERROR, "", tnf_string, msg, 81 "ibmf_saa_impl_init failed"); 82 83 #ifndef NPROBE 84 (void) tnf_mod_unload(&ibmf_modlinkage); 85 #endif 86 return (EACCES); 87 } 88 89 90 91 status = ibmf_init(); 92 if (status != 0) { 93 TNF_PROBE_1(_init_error, IBMF_TNF_ERROR, "", tnf_string, msg, 94 "ibmf_init failed"); 95 96 (void) ibmf_saa_impl_fini(); 97 98 #ifndef NPROBE 99 (void) tnf_mod_unload(&ibmf_modlinkage); 100 #endif 101 return (EACCES); 102 } 103 104 status = mod_install(&ibmf_modlinkage); 105 if (status != 0) { 106 TNF_PROBE_2(_init_error, IBMF_TNF_ERROR, "", tnf_string, msg, 107 "mod_install failed", tnf_uint, status, status); 108 #ifndef NPROBE 109 (void) tnf_mod_unload(&ibmf_modlinkage); 110 #endif 111 (void) ibmf_fini(); 112 ibmf_statep = (ibmf_state_t *)NULL; 113 } 114 115 return (status); 116 } 117 118 int 119 _info(struct modinfo *modinfop) 120 { 121 return (mod_info(&ibmf_modlinkage, modinfop)); 122 } 123 124 int 125 _fini() 126 { 127 int status; 128 status = mod_remove(&ibmf_modlinkage); 129 if (status != 0) { 130 TNF_PROBE_2(_fini_error, IBMF_TNF_ERROR, "", tnf_string, msg, 131 "mod_remove failed", tnf_uint, status, status); 132 return (status); 133 } 134 135 status = ibmf_saa_impl_fini(); 136 if (status != 0) { 137 138 TNF_PROBE_2(_fini_error, IBMF_TNF_ERROR, "", tnf_string, msg, 139 "ibmf_saa fini failed", tnf_uint, status, status); 140 return (status); 141 } 142 143 (void) ibmf_fini(); 144 ibmf_statep = (ibmf_state_t *)NULL; 145 #ifndef NPROBE 146 (void) tnf_mod_unload(&ibmf_modlinkage); 147 #endif 148 return (status); 149 }