xref: /illumos-gate/usr/src/uts/common/os/dacf_clnt.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * DACF (Device Autoconfiguration Framework) client code.
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * DACF has two clients. the first is dacf modules which implement
33*7c478bd9Sstevel@tonic-gate  * configuration operations; the second is the set of hooks in the kernel
34*7c478bd9Sstevel@tonic-gate  * which do rule matching and invoke configuration operations.
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  * This file implements the second part, the kernel hooks.
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  * Currently implemented are post-attach and pre-detach handlers, and the hook
39*7c478bd9Sstevel@tonic-gate  * for ddi_create_minor_common() which sets up post-attach and pre-detach
40*7c478bd9Sstevel@tonic-gate  * reservations.
41*7c478bd9Sstevel@tonic-gate  *
42*7c478bd9Sstevel@tonic-gate  * This code depends on the core dacf code (in dacf.c) but the converse should
43*7c478bd9Sstevel@tonic-gate  * never be true.
44*7c478bd9Sstevel@tonic-gate  *
45*7c478bd9Sstevel@tonic-gate  * This file also implements '__kernel', the kernel-supplied dacf module.
46*7c478bd9Sstevel@tonic-gate  * For now, this is pretty much empty, except under DEBUG, in which case it
47*7c478bd9Sstevel@tonic-gate  * contains some debugging code.
48*7c478bd9Sstevel@tonic-gate  */
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
56*7c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
57*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/modhash.h>
60*7c478bd9Sstevel@tonic-gate #include <sys/dacf_impl.h>
61*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
62*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /*
65*7c478bd9Sstevel@tonic-gate  * dacfc_match_create_minor()
66*7c478bd9Sstevel@tonic-gate  * 	Check to see if this minor node creation sequence matches a dacf
67*7c478bd9Sstevel@tonic-gate  * 	(device autoconfiguration framework) rule.  If so make a reservation
68*7c478bd9Sstevel@tonic-gate  * 	for the operation to be invoked at post-attach and/or pre-detach time.
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate void
71*7c478bd9Sstevel@tonic-gate dacfc_match_create_minor(char *name, char *node_type, dev_info_t *dip,
72*7c478bd9Sstevel@tonic-gate     struct ddi_minor_data *dmdp, int flag)
73*7c478bd9Sstevel@tonic-gate {
74*7c478bd9Sstevel@tonic-gate 	dacf_rule_t *r;
75*7c478bd9Sstevel@tonic-gate 	char *dev_path, *dev_pathp, *drv_mname = NULL;
76*7c478bd9Sstevel@tonic-gate 	dacf_rsrvlist_t *pa_rsrv, *pd_rsrv;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	if (flag & CLONE_DEV) {
79*7c478bd9Sstevel@tonic-gate 		return;
80*7c478bd9Sstevel@tonic-gate 	}
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 	/*
83*7c478bd9Sstevel@tonic-gate 	 * Because dacf currently only implements post-attach and pre-detach
84*7c478bd9Sstevel@tonic-gate 	 * processing, we only care about minor nodes created during attach.
85*7c478bd9Sstevel@tonic-gate 	 * However, there is no restriction on drivers about when to create
86*7c478bd9Sstevel@tonic-gate 	 * minor nodes.
87*7c478bd9Sstevel@tonic-gate 	 */
88*7c478bd9Sstevel@tonic-gate 	if (!DEVI_IS_ATTACHING(dmdp->dip)) {
89*7c478bd9Sstevel@tonic-gate 		return;
90*7c478bd9Sstevel@tonic-gate 	}
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	dev_path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
93*7c478bd9Sstevel@tonic-gate 	dev_pathp = ddi_pathname(dip, dev_path);
94*7c478bd9Sstevel@tonic-gate 	pa_rsrv = kmem_alloc(sizeof (dacf_rsrvlist_t), KM_SLEEP);
95*7c478bd9Sstevel@tonic-gate 	pd_rsrv = kmem_alloc(sizeof (dacf_rsrvlist_t), KM_SLEEP);
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	if (name) {
98*7c478bd9Sstevel@tonic-gate 		const char *drv_name = ddi_driver_name(dip);
99*7c478bd9Sstevel@tonic-gate 		if (drv_name == NULL)
100*7c478bd9Sstevel@tonic-gate 			drv_name = "???";
101*7c478bd9Sstevel@tonic-gate 		drv_mname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
102*7c478bd9Sstevel@tonic-gate 		(void) snprintf(drv_mname, MAXPATHLEN, "%s:%s", drv_name, name);
103*7c478bd9Sstevel@tonic-gate 	}
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	mutex_enter(&dacf_lock);
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	/*
108*7c478bd9Sstevel@tonic-gate 	 * Ensure that we don't wind up in a 'matching loop' against a devinfo
109*7c478bd9Sstevel@tonic-gate 	 * node, which could cause deadlock.  This could happen as follows:
110*7c478bd9Sstevel@tonic-gate 	 *
111*7c478bd9Sstevel@tonic-gate 	 * 	We match (just below)
112*7c478bd9Sstevel@tonic-gate 	 * 	We invoke a task (later, at the end of devi_attach)
113*7c478bd9Sstevel@tonic-gate 	 *	   this means we have taken the per-devinfo lock
114*7c478bd9Sstevel@tonic-gate 	 * 	The task invoke winds up causing the same driver (that has
115*7c478bd9Sstevel@tonic-gate 	 *	   just finished attaching) to create another minor node.
116*7c478bd9Sstevel@tonic-gate 	 * 	We try to re-acquire the per-devinfo list lock again in the
117*7c478bd9Sstevel@tonic-gate 	 *	   process of making another reservation
118*7c478bd9Sstevel@tonic-gate 	 */
119*7c478bd9Sstevel@tonic-gate 	mutex_enter(&(DEVI(dip)->devi_lock));
120*7c478bd9Sstevel@tonic-gate 	if (DEVI_IS_INVOKING_DACF(dip)) {
121*7c478bd9Sstevel@tonic-gate 		mutex_exit(&(DEVI(dip)->devi_lock));
122*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
123*7c478bd9Sstevel@tonic-gate 		    "!dacf detected deadlock, aborting matching procedure\n");
124*7c478bd9Sstevel@tonic-gate 		mutex_exit(&dacf_lock);
125*7c478bd9Sstevel@tonic-gate 		kmem_free(pa_rsrv, sizeof (dacf_rsrvlist_t));
126*7c478bd9Sstevel@tonic-gate 		kmem_free(pd_rsrv, sizeof (dacf_rsrvlist_t));
127*7c478bd9Sstevel@tonic-gate 		kmem_free(dev_path, MAXPATHLEN);
128*7c478bd9Sstevel@tonic-gate 		if (drv_mname) {
129*7c478bd9Sstevel@tonic-gate 			kmem_free(drv_mname, MAXPATHLEN);
130*7c478bd9Sstevel@tonic-gate 		}
131*7c478bd9Sstevel@tonic-gate 		return;
132*7c478bd9Sstevel@tonic-gate 	}
133*7c478bd9Sstevel@tonic-gate 	mutex_exit(&(DEVI(dip)->devi_lock));
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	/*
136*7c478bd9Sstevel@tonic-gate 	 * Do rule matching.  It's possible to construct two rules that would
137*7c478bd9Sstevel@tonic-gate 	 * match against the same minor node, so we match from most to least
138*7c478bd9Sstevel@tonic-gate 	 * specific:
139*7c478bd9Sstevel@tonic-gate 	 * 	device path
140*7c478bd9Sstevel@tonic-gate 	 * 	minor node name (concatenation of drv_name:name
141*7c478bd9Sstevel@tonic-gate 	 * 	node type
142*7c478bd9Sstevel@tonic-gate 	 *
143*7c478bd9Sstevel@tonic-gate 	 * Future additions to the set of device-specifiers should be
144*7c478bd9Sstevel@tonic-gate 	 * sensitive to this ordering.
145*7c478bd9Sstevel@tonic-gate 	 */
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	/*
148*7c478bd9Sstevel@tonic-gate 	 * post-attach matching
149*7c478bd9Sstevel@tonic-gate 	 */
150*7c478bd9Sstevel@tonic-gate 	r = NULL;
151*7c478bd9Sstevel@tonic-gate 	if (dev_pathp) {
152*7c478bd9Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_POSTATTACH, DACF_DS_DEV_PATH,
153*7c478bd9Sstevel@tonic-gate 		    dev_pathp);
154*7c478bd9Sstevel@tonic-gate 	}
155*7c478bd9Sstevel@tonic-gate 	if (!r && drv_mname) {
156*7c478bd9Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_POSTATTACH, DACF_DS_DRV_MNAME,
157*7c478bd9Sstevel@tonic-gate 		    drv_mname);
158*7c478bd9Sstevel@tonic-gate 	}
159*7c478bd9Sstevel@tonic-gate 	if (!r && node_type) {
160*7c478bd9Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_POSTATTACH, DACF_DS_MIN_NT, node_type);
161*7c478bd9Sstevel@tonic-gate 	}
162*7c478bd9Sstevel@tonic-gate 	if (r) {
163*7c478bd9Sstevel@tonic-gate 		dacf_rsrv_make(pa_rsrv, r, dmdp, &(DEVI(dip)->devi_dacf_tasks));
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_MSGS)
166*7c478bd9Sstevel@tonic-gate 			printf("dacf: made 'post-attach' reservation for "
167*7c478bd9Sstevel@tonic-gate 			    "%s, %s, %s\n", name, node_type, dev_pathp);
168*7c478bd9Sstevel@tonic-gate 	} else {
169*7c478bd9Sstevel@tonic-gate 		kmem_free(pa_rsrv, sizeof (dacf_rsrvlist_t));
170*7c478bd9Sstevel@tonic-gate 	}
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 	/*
173*7c478bd9Sstevel@tonic-gate 	 * pre-detach matching
174*7c478bd9Sstevel@tonic-gate 	 */
175*7c478bd9Sstevel@tonic-gate 	r = NULL;
176*7c478bd9Sstevel@tonic-gate 	if (dev_pathp) {
177*7c478bd9Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_PREDETACH, DACF_DS_DEV_PATH,
178*7c478bd9Sstevel@tonic-gate 		    dev_pathp);
179*7c478bd9Sstevel@tonic-gate 	}
180*7c478bd9Sstevel@tonic-gate 	if (!r && drv_mname) {
181*7c478bd9Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_PREDETACH, DACF_DS_DRV_MNAME,
182*7c478bd9Sstevel@tonic-gate 		    drv_mname);
183*7c478bd9Sstevel@tonic-gate 	}
184*7c478bd9Sstevel@tonic-gate 	if (!r && node_type) {
185*7c478bd9Sstevel@tonic-gate 		r = dacf_match(DACF_OPID_PREDETACH, DACF_DS_MIN_NT, node_type);
186*7c478bd9Sstevel@tonic-gate 	}
187*7c478bd9Sstevel@tonic-gate 	if (r) {
188*7c478bd9Sstevel@tonic-gate 		dacf_rsrv_make(pd_rsrv, r, dmdp, &(DEVI(dip)->devi_dacf_tasks));
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_MSGS) {
191*7c478bd9Sstevel@tonic-gate 			printf("dacf: made 'pre-detach' reservation for "
192*7c478bd9Sstevel@tonic-gate 			    "%s, %s, %s\n", name, node_type, dev_pathp);
193*7c478bd9Sstevel@tonic-gate 		}
194*7c478bd9Sstevel@tonic-gate 	} else {
195*7c478bd9Sstevel@tonic-gate 		kmem_free(pd_rsrv, sizeof (dacf_rsrvlist_t));
196*7c478bd9Sstevel@tonic-gate 	}
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 	mutex_exit(&dacf_lock);
199*7c478bd9Sstevel@tonic-gate 	kmem_free(dev_path, MAXPATHLEN);
200*7c478bd9Sstevel@tonic-gate 	if (drv_mname) {
201*7c478bd9Sstevel@tonic-gate 		kmem_free(drv_mname, MAXPATHLEN);
202*7c478bd9Sstevel@tonic-gate 	}
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate /*
206*7c478bd9Sstevel@tonic-gate  * dacfc_postattach()
207*7c478bd9Sstevel@tonic-gate  * 	autoconfiguration for post-attach events.
208*7c478bd9Sstevel@tonic-gate  *
209*7c478bd9Sstevel@tonic-gate  * 	strategy: try to configure.  If some of the configuration operations
210*7c478bd9Sstevel@tonic-gate  * 	fail, emit a warning.
211*7c478bd9Sstevel@tonic-gate  */
212*7c478bd9Sstevel@tonic-gate int
213*7c478bd9Sstevel@tonic-gate dacfc_postattach(dev_info_t *devi)
214*7c478bd9Sstevel@tonic-gate {
215*7c478bd9Sstevel@tonic-gate 	int err = DACF_SUCCESS;
216*7c478bd9Sstevel@tonic-gate 	char *path, *pathp;
217*7c478bd9Sstevel@tonic-gate 	dacf_rsrvlist_t **opsp, *op;
218*7c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&dacf_lock));
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate 	/*
221*7c478bd9Sstevel@tonic-gate 	 * Instruct dacf_process_rsrvs() to invoke each POSTATTACH op.
222*7c478bd9Sstevel@tonic-gate 	 */
223*7c478bd9Sstevel@tonic-gate 	opsp = &DEVI(devi)->devi_dacf_tasks;
224*7c478bd9Sstevel@tonic-gate 	dacf_process_rsrvs(opsp, DACF_OPID_POSTATTACH, DACF_PROC_INVOKE);
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 	/*
227*7c478bd9Sstevel@tonic-gate 	 * Check to see that all POSTATTACH's succeeded.
228*7c478bd9Sstevel@tonic-gate 	 */
229*7c478bd9Sstevel@tonic-gate 	for (op = *opsp; op != NULL; op = op->rsrv_next) {
230*7c478bd9Sstevel@tonic-gate 		if (op->rsrv_rule->r_opid != DACF_OPID_POSTATTACH)
231*7c478bd9Sstevel@tonic-gate 			continue;
232*7c478bd9Sstevel@tonic-gate 		if (op->rsrv_result == DACF_SUCCESS)
233*7c478bd9Sstevel@tonic-gate 			continue;
234*7c478bd9Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_DEVI) {
235*7c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN, "op failed, err = %d\n",
236*7c478bd9Sstevel@tonic-gate 			    op->rsrv_result);
237*7c478bd9Sstevel@tonic-gate 		}
238*7c478bd9Sstevel@tonic-gate 		err = DACF_FAILURE;
239*7c478bd9Sstevel@tonic-gate 		break;
240*7c478bd9Sstevel@tonic-gate 	}
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 	/*
243*7c478bd9Sstevel@tonic-gate 	 * If one or more postattach's failed, give up.
244*7c478bd9Sstevel@tonic-gate 	 */
245*7c478bd9Sstevel@tonic-gate 	if ((err == DACF_FAILURE) && (dacfdebug & DACF_DBG_DEVI)) {
246*7c478bd9Sstevel@tonic-gate 		path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
247*7c478bd9Sstevel@tonic-gate 		if ((pathp = ddi_pathname(devi, path)) == NULL)
248*7c478bd9Sstevel@tonic-gate 			pathp = "<unknown>";
249*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s attached, but failed to auto-configure",
250*7c478bd9Sstevel@tonic-gate 		    pathp);
251*7c478bd9Sstevel@tonic-gate 		kmem_free(path, MAXPATHLEN);
252*7c478bd9Sstevel@tonic-gate 	}
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 	return (err);
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate /*
258*7c478bd9Sstevel@tonic-gate  * dacfc_predetach()
259*7c478bd9Sstevel@tonic-gate  * 	auto-unconfiguration for pre-detach events.
260*7c478bd9Sstevel@tonic-gate  *
261*7c478bd9Sstevel@tonic-gate  * 	strategy: call the pre-detach operation for all matching reservations.
262*7c478bd9Sstevel@tonic-gate  * 	If any of these fail, make (one) attempt to reconfigure things back
263*7c478bd9Sstevel@tonic-gate  * 	into a sane state.  if that fails, our state is uncertain.
264*7c478bd9Sstevel@tonic-gate  */
265*7c478bd9Sstevel@tonic-gate int
266*7c478bd9Sstevel@tonic-gate dacfc_predetach(dev_info_t *devi)
267*7c478bd9Sstevel@tonic-gate {
268*7c478bd9Sstevel@tonic-gate 	int err = DDI_SUCCESS;
269*7c478bd9Sstevel@tonic-gate 	char *path, *pathp;
270*7c478bd9Sstevel@tonic-gate 	dacf_rsrvlist_t **opsp, *op;
271*7c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&dacf_lock));
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	/*
274*7c478bd9Sstevel@tonic-gate 	 * Instruct dacf_process_rsrvs() to invoke each PREDETACH op.
275*7c478bd9Sstevel@tonic-gate 	 */
276*7c478bd9Sstevel@tonic-gate 	opsp = &DEVI(devi)->devi_dacf_tasks;
277*7c478bd9Sstevel@tonic-gate 	dacf_process_rsrvs(opsp, DACF_OPID_PREDETACH, DACF_PROC_INVOKE);
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate 	/*
280*7c478bd9Sstevel@tonic-gate 	 * Check to see that all PREDETACH's succeeded.
281*7c478bd9Sstevel@tonic-gate 	 */
282*7c478bd9Sstevel@tonic-gate 	for (op = *opsp; op != NULL; op = op->rsrv_next) {
283*7c478bd9Sstevel@tonic-gate 		if (op->rsrv_rule->r_opid != DACF_OPID_PREDETACH)
284*7c478bd9Sstevel@tonic-gate 			continue;
285*7c478bd9Sstevel@tonic-gate 		if (op->rsrv_result == 0)
286*7c478bd9Sstevel@tonic-gate 			continue;
287*7c478bd9Sstevel@tonic-gate 		err = DDI_FAILURE;
288*7c478bd9Sstevel@tonic-gate 		break;
289*7c478bd9Sstevel@tonic-gate 	}
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 	/*
292*7c478bd9Sstevel@tonic-gate 	 * If one or more predetach's failed, make one attempt to fix things
293*7c478bd9Sstevel@tonic-gate 	 * by re-running all of the POST-ATTACH operations.  If any of those
294*7c478bd9Sstevel@tonic-gate 	 * fail, give up.
295*7c478bd9Sstevel@tonic-gate 	 */
296*7c478bd9Sstevel@tonic-gate 	if (err == DDI_FAILURE) {
297*7c478bd9Sstevel@tonic-gate 		int pa_err;
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_DEVI) {
300*7c478bd9Sstevel@tonic-gate 			path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
301*7c478bd9Sstevel@tonic-gate 			if ((pathp = ddi_pathname(devi, path)) == NULL)
302*7c478bd9Sstevel@tonic-gate 				pathp = "<unknown>";
303*7c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s failed to auto-unconfigure, "
304*7c478bd9Sstevel@tonic-gate 			    "attempting to reconfigure...", pathp);
305*7c478bd9Sstevel@tonic-gate 			kmem_free(path, MAXPATHLEN);
306*7c478bd9Sstevel@tonic-gate 		}
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 		pa_err = dacfc_postattach(devi);
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate 		if (dacfdebug & DACF_DBG_DEVI) {
311*7c478bd9Sstevel@tonic-gate 			path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
312*7c478bd9Sstevel@tonic-gate 			if ((pathp = ddi_pathname(devi, path)) == NULL)
313*7c478bd9Sstevel@tonic-gate 				pathp = "<unknown>";
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate 			if (pa_err == DDI_FAILURE) {
316*7c478bd9Sstevel@tonic-gate 				cmn_err(CE_WARN, "%s failed to "
317*7c478bd9Sstevel@tonic-gate 				    "auto-unconfigure, and could not be "
318*7c478bd9Sstevel@tonic-gate 				    "re-autoconfigured.", pathp);
319*7c478bd9Sstevel@tonic-gate 			} else {
320*7c478bd9Sstevel@tonic-gate 				cmn_err(CE_WARN, "%s failed to "
321*7c478bd9Sstevel@tonic-gate 				    "auto-unconfigure, but was successfully "
322*7c478bd9Sstevel@tonic-gate 				    "re-autoconfigured.", pathp);
323*7c478bd9Sstevel@tonic-gate 			}
324*7c478bd9Sstevel@tonic-gate 			kmem_free(path, MAXPATHLEN);
325*7c478bd9Sstevel@tonic-gate 		}
326*7c478bd9Sstevel@tonic-gate 	}
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 	return (err);
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate /*
332*7c478bd9Sstevel@tonic-gate  * kmod_dacfsw:
333*7c478bd9Sstevel@tonic-gate  * 	This is the declaration for the kernel-supplied '__kernel' dacf module.
334*7c478bd9Sstevel@tonic-gate  * 	DACF supplies a framework based around loadable modules.  However, it
335*7c478bd9Sstevel@tonic-gate  * 	may be convenient (in the future) to have a module provided by the
336*7c478bd9Sstevel@tonic-gate  * 	kernel.  This is useful in cases when a module can't be loaded (early in
337*7c478bd9Sstevel@tonic-gate  * 	boot), or for code that would never get unloaded anyway.
338*7c478bd9Sstevel@tonic-gate  */
339*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
340*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
341*7c478bd9Sstevel@tonic-gate static int
342*7c478bd9Sstevel@tonic-gate kmod_test_postattach(dacf_infohdl_t info_hdl, dacf_arghdl_t arg_hdl, int flags)
343*7c478bd9Sstevel@tonic-gate {
344*7c478bd9Sstevel@tonic-gate 	const char *verbose = dacf_get_arg(arg_hdl, "verbose");
345*7c478bd9Sstevel@tonic-gate 	if (verbose && (strcmp(verbose, "true") == 0)) {
346*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "got kmod_test_postattach\n");
347*7c478bd9Sstevel@tonic-gate 	}
348*7c478bd9Sstevel@tonic-gate 	return (0);
349*7c478bd9Sstevel@tonic-gate }
350*7c478bd9Sstevel@tonic-gate #endif
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate static dacf_op_t kmod_op_test[] = {
353*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
354*7c478bd9Sstevel@tonic-gate 	{ DACF_OPID_POSTATTACH, kmod_test_postattach },
355*7c478bd9Sstevel@tonic-gate #endif
356*7c478bd9Sstevel@tonic-gate 	{ DACF_OPID_END,	NULL },
357*7c478bd9Sstevel@tonic-gate };
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate static dacf_opset_t kmod_opsets[] = {
360*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
361*7c478bd9Sstevel@tonic-gate 	{ "kmod_test",		kmod_op_test },
362*7c478bd9Sstevel@tonic-gate #endif
363*7c478bd9Sstevel@tonic-gate 	{ NULL,			NULL },
364*7c478bd9Sstevel@tonic-gate };
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate struct dacfsw kmod_dacfsw = {
367*7c478bd9Sstevel@tonic-gate 	DACF_MODREV_1, kmod_opsets
368*7c478bd9Sstevel@tonic-gate };
369