xref: /onnv-gate/usr/src/uts/sun4u/ngdr/io/dr_io.c (revision 11651:b0aa8d9f0afd)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51772Sjl139090  * Common Development and Distribution License (the "License").
61772Sjl139090  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
2111311SSurya.Prakki@Sun.COM 
220Sstevel@tonic-gate /*
23*11651SVijay.Balakrishna@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * I/O support routines for DR
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/debug.h>
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/errno.h>
340Sstevel@tonic-gate #include <sys/cred.h>
350Sstevel@tonic-gate #include <sys/dditypes.h>
360Sstevel@tonic-gate #include <sys/devops.h>
370Sstevel@tonic-gate #include <sys/modctl.h>
380Sstevel@tonic-gate #include <sys/poll.h>
390Sstevel@tonic-gate #include <sys/conf.h>
400Sstevel@tonic-gate #include <sys/ddi.h>
410Sstevel@tonic-gate #include <sys/sunddi.h>
420Sstevel@tonic-gate #include <sys/sunndi.h>
430Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
440Sstevel@tonic-gate #include <sys/stat.h>
450Sstevel@tonic-gate #include <sys/kmem.h>
460Sstevel@tonic-gate #include <sys/processor.h>
470Sstevel@tonic-gate #include <sys/cpuvar.h>
480Sstevel@tonic-gate #include <sys/mem_config.h>
490Sstevel@tonic-gate #include <sys/promif.h>
500Sstevel@tonic-gate #include <sys/x_call.h>
510Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
520Sstevel@tonic-gate #include <sys/membar.h>
530Sstevel@tonic-gate #include <sys/stack.h>
540Sstevel@tonic-gate #include <sys/sysmacros.h>
550Sstevel@tonic-gate #include <sys/machsystm.h>
560Sstevel@tonic-gate #include <sys/spitregs.h>
570Sstevel@tonic-gate #include <sys/cpupart.h>
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #include <sys/archsystm.h>
600Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
610Sstevel@tonic-gate #include <sys/pte.h>
620Sstevel@tonic-gate #include <sys/mmu.h>
630Sstevel@tonic-gate #include <sys/x_call.h>
640Sstevel@tonic-gate #include <sys/cpu_module.h>
650Sstevel@tonic-gate 
660Sstevel@tonic-gate #include <sys/cmn_err.h>
670Sstevel@tonic-gate 
680Sstevel@tonic-gate #include <sys/dr.h>
690Sstevel@tonic-gate #include <sys/dr_util.h>
700Sstevel@tonic-gate #include <sys/drmach.h>
710Sstevel@tonic-gate 
720Sstevel@tonic-gate void
dr_init_io_unit(dr_io_unit_t * ip)730Sstevel@tonic-gate dr_init_io_unit(dr_io_unit_t *ip)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate 	dr_state_t	new_state;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	if (DR_DEV_IS_ATTACHED(&ip->sbi_cm)) {
780Sstevel@tonic-gate 		new_state = DR_STATE_CONFIGURED;
790Sstevel@tonic-gate 		ip->sbi_cm.sbdev_cond = SBD_COND_OK;
800Sstevel@tonic-gate 	} else if (DR_DEV_IS_PRESENT(&ip->sbi_cm)) {
810Sstevel@tonic-gate 		new_state = DR_STATE_CONNECTED;
820Sstevel@tonic-gate 		ip->sbi_cm.sbdev_cond = SBD_COND_OK;
830Sstevel@tonic-gate 	} else {
840Sstevel@tonic-gate 		new_state = DR_STATE_EMPTY;
850Sstevel@tonic-gate 	}
860Sstevel@tonic-gate 	dr_device_transition(&ip->sbi_cm, new_state);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*ARGSUSED*/
900Sstevel@tonic-gate void
dr_attach_io(dr_handle_t * hp,dr_common_unit_t * cp)910Sstevel@tonic-gate dr_attach_io(dr_handle_t *hp, dr_common_unit_t *cp)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate 	sbd_error_t *err;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	dr_lock_status(hp->h_bd);
960Sstevel@tonic-gate 	err = drmach_configure(cp->sbdev_id, 0);
970Sstevel@tonic-gate 	dr_unlock_status(hp->h_bd);
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	if (!err)
1000Sstevel@tonic-gate 		err = drmach_io_post_attach(cp->sbdev_id);
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	if (err)
1030Sstevel@tonic-gate 		DRERR_SET_C(&cp->sbdev_error, &err);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate /*
1070Sstevel@tonic-gate  * remove device nodes for the branch indicated by cp
1080Sstevel@tonic-gate  */
1090Sstevel@tonic-gate /*ARGSUSED*/
1100Sstevel@tonic-gate void
dr_detach_io(dr_handle_t * hp,dr_common_unit_t * cp)1110Sstevel@tonic-gate dr_detach_io(dr_handle_t *hp, dr_common_unit_t *cp)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate 	sbd_error_t *err;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	err = drmach_unconfigure(cp->sbdev_id, 0);
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	if (!err)
1181772Sjl139090 		err = drmach_unconfigure(cp->sbdev_id, DEVI_BRANCH_DESTROY);
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	if (!err)
1210Sstevel@tonic-gate 		err = drmach_io_post_release(cp->sbdev_id);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	if (err) {
1240Sstevel@tonic-gate 		dr_device_transition(cp, DR_STATE_CONFIGURED);
1250Sstevel@tonic-gate 		DRERR_SET_C(&cp->sbdev_error, &err);
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate /*ARGSUSED*/
1300Sstevel@tonic-gate int
dr_disconnect_io(dr_io_unit_t * ip)1310Sstevel@tonic-gate dr_disconnect_io(dr_io_unit_t *ip)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate 	return (0);
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*ARGSUSED*/
1370Sstevel@tonic-gate int
dr_pre_attach_io(dr_handle_t * hp,dr_common_unit_t ** devlist,int devnum)1380Sstevel@tonic-gate dr_pre_attach_io(dr_handle_t *hp,
1390Sstevel@tonic-gate 	dr_common_unit_t **devlist, int devnum)
1400Sstevel@tonic-gate {
1410Sstevel@tonic-gate 	int		d;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	for (d = 0; d < devnum; d++) {
1440Sstevel@tonic-gate 		dr_common_unit_t *cp = devlist[d];
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 		cmn_err(CE_CONT, "OS configure %s", cp->sbdev_path);
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	return (0);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /*ARGSUSED*/
1530Sstevel@tonic-gate int
dr_post_attach_io(dr_handle_t * hp,dr_common_unit_t ** devlist,int devnum)1540Sstevel@tonic-gate dr_post_attach_io(dr_handle_t *hp,
1550Sstevel@tonic-gate 	dr_common_unit_t **devlist, int devnum)
1560Sstevel@tonic-gate {
1570Sstevel@tonic-gate 	return (0);
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate static int
dr_check_io_refs(dr_handle_t * hp,dr_common_unit_t ** devlist,int devnum)1610Sstevel@tonic-gate dr_check_io_refs(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate 	register int	i, reftotal = 0;
1640Sstevel@tonic-gate 	static fn_t	f = "dr_check_io_refs";
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	for (i = 0; i < devnum; i++) {
1670Sstevel@tonic-gate 		dr_io_unit_t	*ip = (dr_io_unit_t *)devlist[i];
1680Sstevel@tonic-gate 		dev_info_t	*dip;
1690Sstevel@tonic-gate 		int		ref;
170*11651SVijay.Balakrishna@Sun.COM 		int		refcount_non_gldv3;
1710Sstevel@tonic-gate 		sbd_error_t	*err;
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 		err = drmach_get_dip(ip->sbi_cm.sbdev_id, &dip);
1740Sstevel@tonic-gate 		if (err)
1750Sstevel@tonic-gate 			DRERR_SET_C(&ip->sbi_cm.sbdev_error, &err);
1760Sstevel@tonic-gate 		else if (dip != NULL) {
1770Sstevel@tonic-gate 			ref = 0;
178*11651SVijay.Balakrishna@Sun.COM 			refcount_non_gldv3 = 0;
1790Sstevel@tonic-gate 			ASSERT(e_ddi_branch_held(dip));
180*11651SVijay.Balakrishna@Sun.COM 			dr_check_devices(dip, &ref, hp, NULL, NULL,
181*11651SVijay.Balakrishna@Sun.COM 			    0, &refcount_non_gldv3);
182*11651SVijay.Balakrishna@Sun.COM 			ASSERT(refcount_non_gldv3 >= 0);
183*11651SVijay.Balakrishna@Sun.COM 			ASSERT(ref >= refcount_non_gldv3);
184*11651SVijay.Balakrishna@Sun.COM 			/*
185*11651SVijay.Balakrishna@Sun.COM 			 * Ignore reference counts of non-gldv3 network devices
186*11651SVijay.Balakrishna@Sun.COM 			 * as Crossbow creates reference counts for non-active
187*11651SVijay.Balakrishna@Sun.COM 			 * (unplumbed) instances.  Reference count check in
188*11651SVijay.Balakrishna@Sun.COM 			 * detach() known to prevent device from detaching
189*11651SVijay.Balakrishna@Sun.COM 			 * as necessary.
190*11651SVijay.Balakrishna@Sun.COM 			 */
191*11651SVijay.Balakrishna@Sun.COM 			ref -= refcount_non_gldv3;
1920Sstevel@tonic-gate 			hp->h_err = NULL;
1930Sstevel@tonic-gate 			if (ref) {
1940Sstevel@tonic-gate 				dr_dev_err(CE_WARN, &ip->sbi_cm, ESBD_BUSY);
1950Sstevel@tonic-gate 			}
1960Sstevel@tonic-gate 			PR_IO("%s: dip(%s) ref = %d\n",
19711311SSurya.Prakki@Sun.COM 			    f, ddi_get_name(dip), ref);
1980Sstevel@tonic-gate 			reftotal += ref;
1990Sstevel@tonic-gate 		} else {
2000Sstevel@tonic-gate 			PR_IO("%s: NO dip for id (0x%x)\n",
20111311SSurya.Prakki@Sun.COM 			    f, (uint_t)(uintptr_t)ip->sbi_cm.sbdev_id);
2020Sstevel@tonic-gate 		}
2030Sstevel@tonic-gate 	}
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	return (reftotal);
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate int
dr_pre_release_io(dr_handle_t * hp,dr_common_unit_t ** devlist,int devnum)2090Sstevel@tonic-gate dr_pre_release_io(dr_handle_t *hp,
2100Sstevel@tonic-gate 	dr_common_unit_t **devlist, int devnum)
2110Sstevel@tonic-gate {
2120Sstevel@tonic-gate 	static fn_t	f = "dr_pre_release_io";
2130Sstevel@tonic-gate 	int	d;
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 	ASSERT(devnum > 0);
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	/* fail if any I/O device pre-release fails */
2180Sstevel@tonic-gate 	for (d = 0; d < devnum; d++) {
2190Sstevel@tonic-gate 		dr_io_unit_t *ip = (dr_io_unit_t *)devlist[d];
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 		if ((hp->h_err = drmach_io_pre_release(
22211311SSurya.Prakki@Sun.COM 		    ip->sbi_cm.sbdev_id)) != 0) {
2230Sstevel@tonic-gate 			return (-1);
2240Sstevel@tonic-gate 		}
2250Sstevel@tonic-gate 	}
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 	for (d = 0; d < devnum; d++) {
2280Sstevel@tonic-gate 		dr_io_unit_t *ip = (dr_io_unit_t *)devlist[d];
2290Sstevel@tonic-gate 		sbd_error_t *err;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 		err = drmach_release(ip->sbi_cm.sbdev_id);
2320Sstevel@tonic-gate 		if (err) {
2330Sstevel@tonic-gate 			DRERR_SET_C(&ip->sbi_cm.sbdev_error,
23411311SSurya.Prakki@Sun.COM 			    &err);
2350Sstevel@tonic-gate 			return (-1);
2360Sstevel@tonic-gate 		}
2370Sstevel@tonic-gate 	}
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 	/* fail if any I/O devices are still referenced */
2400Sstevel@tonic-gate 	if (dr_check_io_refs(hp, devlist, devnum) > 0) {
2410Sstevel@tonic-gate 		PR_IO("%s: failed - I/O devices ref'd\n", f);
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 		/* recover before return error */
2440Sstevel@tonic-gate 		for (d = 0; d < devnum; d++) {
2450Sstevel@tonic-gate 			dr_io_unit_t *ip = (dr_io_unit_t *)devlist[d];
2460Sstevel@tonic-gate 			sbd_error_t *err;
2470Sstevel@tonic-gate 			err = drmach_io_unrelease(ip->sbi_cm.sbdev_id);
2480Sstevel@tonic-gate 			if (err) {
2490Sstevel@tonic-gate 				DRERR_SET_C(&ip->sbi_cm.sbdev_error, &err);
2500Sstevel@tonic-gate 				return (-1);
2510Sstevel@tonic-gate 			}
2520Sstevel@tonic-gate 		}
2530Sstevel@tonic-gate 		return (-1);
2540Sstevel@tonic-gate 	}
2550Sstevel@tonic-gate 	return (0);
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*ARGSUSED*/
2590Sstevel@tonic-gate int
dr_pre_detach_io(dr_handle_t * hp,dr_common_unit_t ** devlist,int devnum)2600Sstevel@tonic-gate dr_pre_detach_io(dr_handle_t *hp,
2610Sstevel@tonic-gate 	dr_common_unit_t **devlist, int devnum)
2620Sstevel@tonic-gate {
2630Sstevel@tonic-gate 	int		d;
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	ASSERT(devnum > 0);
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	for (d = 0; d < devnum; d++) {
2680Sstevel@tonic-gate 		dr_common_unit_t *cp = devlist[d];
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 		cmn_err(CE_CONT, "OS unconfigure %s", cp->sbdev_path);
2710Sstevel@tonic-gate 	}
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	return (0);
2740Sstevel@tonic-gate }
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate /*ARGSUSED*/
2770Sstevel@tonic-gate int
dr_post_detach_io(dr_handle_t * hp,dr_common_unit_t ** devlist,int devnum)2780Sstevel@tonic-gate dr_post_detach_io(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
2790Sstevel@tonic-gate {
2800Sstevel@tonic-gate 	register int	i;
2810Sstevel@tonic-gate 	int		rv = 0;
2820Sstevel@tonic-gate 	static fn_t	f = "dr_post_detach_io";
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate 	ASSERT(devnum > 0);
2850Sstevel@tonic-gate 	for (i = 0; i < devnum; i++) {
2860Sstevel@tonic-gate 		dr_common_unit_t	*cp = devlist[i];
2870Sstevel@tonic-gate 		if (cp->sbdev_error != NULL) {
2880Sstevel@tonic-gate 			PR_IO("%s: Failed\n", f);
2890Sstevel@tonic-gate 			rv = -1;
2900Sstevel@tonic-gate 			break;
2910Sstevel@tonic-gate 		}
2920Sstevel@tonic-gate 	}
2930Sstevel@tonic-gate 	return (rv);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate 
2964845Svikram static void
dr_get_comp_cond(dr_io_unit_t * ip,dev_info_t * dip)2974845Svikram dr_get_comp_cond(dr_io_unit_t *ip, dev_info_t *dip)
2984845Svikram {
2994845Svikram 	if (dip == NULL) {
3004845Svikram 		ip->sbi_cm.sbdev_cond = SBD_COND_UNKNOWN;
3014845Svikram 		return;
3024845Svikram 	}
3034845Svikram 
3044845Svikram 	if (DEVI(dip)->devi_flags & DEVI_RETIRED) {
3054845Svikram 		ip->sbi_cm.sbdev_cond = SBD_COND_FAILED;
3064845Svikram 		return;
3074845Svikram 	}
3084845Svikram 
3094845Svikram 	if (DR_DEV_IS_ATTACHED(&ip->sbi_cm)) {
3104845Svikram 		ip->sbi_cm.sbdev_cond = SBD_COND_OK;
3114845Svikram 	} else if (DR_DEV_IS_PRESENT(&ip->sbi_cm)) {
3124845Svikram 		ip->sbi_cm.sbdev_cond = SBD_COND_OK;
3134845Svikram 	}
3144845Svikram }
3154845Svikram 
3160Sstevel@tonic-gate int
dr_io_status(dr_handle_t * hp,dr_devset_t devset,sbd_dev_stat_t * dsp)3170Sstevel@tonic-gate dr_io_status(dr_handle_t *hp, dr_devset_t devset, sbd_dev_stat_t *dsp)
3180Sstevel@tonic-gate {
3190Sstevel@tonic-gate 	int		i, ix;
3200Sstevel@tonic-gate 	dr_board_t	*bp;
3210Sstevel@tonic-gate 	sbd_io_stat_t	*isp;
3220Sstevel@tonic-gate 	dr_io_unit_t	*ip;
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 	bp = hp->h_bd;
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	/*
3270Sstevel@tonic-gate 	 * Only look for requested devices that are actually present.
3280Sstevel@tonic-gate 	 */
3290Sstevel@tonic-gate 	devset &= DR_DEVS_PRESENT(bp);
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 	for (i = ix = 0; i < MAX_IO_UNITS_PER_BOARD; i++) {
3320Sstevel@tonic-gate 		drmachid_t	 id;
3330Sstevel@tonic-gate 		dev_info_t	*dip;
3340Sstevel@tonic-gate 		sbd_error_t	*err;
3350Sstevel@tonic-gate 		drmach_status_t	 pstat;
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate 		if (DEVSET_IN_SET(devset, SBD_COMP_IO, i) == 0)
3380Sstevel@tonic-gate 			continue;
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 		ip = dr_get_io_unit(bp, i);
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate 		if (ip->sbi_cm.sbdev_state == DR_STATE_EMPTY) {
3430Sstevel@tonic-gate 			/* present, but not fully initialized */
3440Sstevel@tonic-gate 			continue;
3450Sstevel@tonic-gate 		}
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 		id = ip->sbi_cm.sbdev_id;
3480Sstevel@tonic-gate 		if (id == (drmachid_t)0)
3490Sstevel@tonic-gate 			continue;
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 		err = drmach_status(ip->sbi_cm.sbdev_id, &pstat);
3520Sstevel@tonic-gate 		if (err) {
3530Sstevel@tonic-gate 			DRERR_SET_C(&ip->sbi_cm.sbdev_error, &err);
3540Sstevel@tonic-gate 			return (-1);
3550Sstevel@tonic-gate 		}
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 		dip = NULL;
3580Sstevel@tonic-gate 		err = drmach_get_dip(id, &dip);
3590Sstevel@tonic-gate 		if (err) {
3600Sstevel@tonic-gate 			/* catch this in debug kernels */
3610Sstevel@tonic-gate 			ASSERT(0);
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 			sbd_err_clear(&err);
3640Sstevel@tonic-gate 			continue;
3654845Svikram 		}
3664845Svikram 
3674845Svikram 		isp = &dsp->d_io;
3684845Svikram 		bzero((caddr_t)isp, sizeof (*isp));
3694845Svikram 
3704845Svikram 		isp->is_cm.c_id.c_type = ip->sbi_cm.sbdev_type;
3714845Svikram 		isp->is_cm.c_id.c_unit = ip->sbi_cm.sbdev_unum;
37211311SSurya.Prakki@Sun.COM 		(void) strncpy(isp->is_cm.c_id.c_name, pstat.type,
37311311SSurya.Prakki@Sun.COM 		    sizeof (isp->is_cm.c_id.c_name));
3744845Svikram 
3754845Svikram 		dr_get_comp_cond(ip, dip);
3764845Svikram 		isp->is_cm.c_cond = ip->sbi_cm.sbdev_cond;
3774845Svikram 		isp->is_cm.c_busy = ip->sbi_cm.sbdev_busy | pstat.busy;
3784845Svikram 		isp->is_cm.c_time = ip->sbi_cm.sbdev_time;
3794845Svikram 		isp->is_cm.c_ostate = ip->sbi_cm.sbdev_ostate;
3804845Svikram 		isp->is_cm.c_sflags = 0;
3814845Svikram 
3824845Svikram 		if (dip == NULL) {
3830Sstevel@tonic-gate 			isp->is_pathname[0] = '\0';
3840Sstevel@tonic-gate 			isp->is_referenced = 0;
3850Sstevel@tonic-gate 			isp->is_unsafe_count = 0;
3860Sstevel@tonic-gate 		} else {
3870Sstevel@tonic-gate 			int		refcount = 0, idx = 0;
3880Sstevel@tonic-gate 			uint64_t	unsafe_devs[SBD_MAX_UNSAFE];
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 			ASSERT(e_ddi_branch_held(dip));
3910Sstevel@tonic-gate 			(void) ddi_pathname(dip, isp->is_pathname);
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 			/* check reference and unsafe counts on devices */
3940Sstevel@tonic-gate 			isp->is_unsafe_count = 0;
3950Sstevel@tonic-gate 			dr_check_devices(dip, &refcount, hp, unsafe_devs,
396*11651SVijay.Balakrishna@Sun.COM 			    &idx, SBD_MAX_UNSAFE, NULL);
3970Sstevel@tonic-gate 			while (idx > 0) {
3980Sstevel@tonic-gate 				isp->is_unsafe_list[idx-1] = unsafe_devs[idx-1];
3990Sstevel@tonic-gate 				--idx;
4000Sstevel@tonic-gate 			}
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 			isp->is_referenced = (refcount == 0) ? 0 : 1;
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate 			hp->h_err = NULL;
4050Sstevel@tonic-gate 		}
4060Sstevel@tonic-gate 		ix++;
4070Sstevel@tonic-gate 		dsp++;
4080Sstevel@tonic-gate 	}
4090Sstevel@tonic-gate 
4100Sstevel@tonic-gate 	return (ix);
4110Sstevel@tonic-gate }
412