xref: /titanic_52/usr/src/lib/sun_sas/common/verify.c (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
1*9e86db79SHyon Kim /*
2*9e86db79SHyon Kim  * CDDL HEADER START
3*9e86db79SHyon Kim  *
4*9e86db79SHyon Kim  * The contents of this file are subject to the terms of the
5*9e86db79SHyon Kim  * Common Development and Distribution License (the "License").
6*9e86db79SHyon Kim  * You may not use this file except in compliance with the License.
7*9e86db79SHyon Kim  *
8*9e86db79SHyon Kim  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9e86db79SHyon Kim  * or http://www.opensolaris.org/os/licensing.
10*9e86db79SHyon Kim  * See the License for the specific language governing permissions
11*9e86db79SHyon Kim  * and limitations under the License.
12*9e86db79SHyon Kim  *
13*9e86db79SHyon Kim  * When distributing Covered Code, include this CDDL HEADER in each
14*9e86db79SHyon Kim  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9e86db79SHyon Kim  * If applicable, add the following below this CDDL HEADER, with the
16*9e86db79SHyon Kim  * fields enclosed by brackets "[]" replaced with your own identifying
17*9e86db79SHyon Kim  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9e86db79SHyon Kim  *
19*9e86db79SHyon Kim  * CDDL HEADER END
20*9e86db79SHyon Kim  */
21*9e86db79SHyon Kim 
22*9e86db79SHyon Kim /*
23*9e86db79SHyon Kim  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*9e86db79SHyon Kim  * Use is subject to license terms.
25*9e86db79SHyon Kim  */
26*9e86db79SHyon Kim 
27*9e86db79SHyon Kim #include <sun_sas.h>
28*9e86db79SHyon Kim #include <signal.h>
29*9e86db79SHyon Kim 
30*9e86db79SHyon Kim /*
31*9e86db79SHyon Kim  * Verify that a given adapter is present on the system.
32*9e86db79SHyon Kim  * No checks will be performed on the targets, and it is assumed
33*9e86db79SHyon Kim  * that an adapter can't change the number of ports it has.
34*9e86db79SHyon Kim  */
35*9e86db79SHyon Kim HBA_STATUS
36*9e86db79SHyon Kim verifyAdapter(struct sun_sas_hba *hba_ptr) {
37*9e86db79SHyon Kim 	const char	    ROUTINE[] = "verifyAdapter";
38*9e86db79SHyon Kim 	char		    *charptr, path[MAXPATHLEN+1];
39*9e86db79SHyon Kim 	di_node_t	    node;
40*9e86db79SHyon Kim 	uint_t		    state;
41*9e86db79SHyon Kim 
42*9e86db79SHyon Kim 	/*
43*9e86db79SHyon Kim 	 * valid test for a removed HBA.
44*9e86db79SHyon Kim 	 */
45*9e86db79SHyon Kim 	if (hba_ptr == NULL) {
46*9e86db79SHyon Kim 	    log(LOG_DEBUG, ROUTINE, "Null hba_ptr argument");
47*9e86db79SHyon Kim 	    return (HBA_STATUS_ERROR);
48*9e86db79SHyon Kim 	}
49*9e86db79SHyon Kim 	(void) strlcpy(path, hba_ptr->device_path, sizeof (path));
50*9e86db79SHyon Kim 
51*9e86db79SHyon Kim 	charptr = strrchr(path, ':');
52*9e86db79SHyon Kim 	if (charptr) {
53*9e86db79SHyon Kim 	    *charptr = '\0';
54*9e86db79SHyon Kim 	}
55*9e86db79SHyon Kim 
56*9e86db79SHyon Kim 	errno = 0;
57*9e86db79SHyon Kim 
58*9e86db79SHyon Kim 	node = di_init(path, DINFOCPYALL);
59*9e86db79SHyon Kim 	if (node == DI_NODE_NIL) {
60*9e86db79SHyon Kim 		log(LOG_DEBUG, ROUTINE,
61*9e86db79SHyon Kim 		    "Unable to take devinfo snapshot on HBA \"%s\" due to %s",
62*9e86db79SHyon Kim 		    path, strerror(errno));
63*9e86db79SHyon Kim 		return (HBA_STATUS_ERROR);
64*9e86db79SHyon Kim 	} else {
65*9e86db79SHyon Kim 		state = di_state(node);
66*9e86db79SHyon Kim 		if (((state & DI_DRIVER_DETACHED) == DI_DRIVER_DETACHED) ||
67*9e86db79SHyon Kim 		    ((state & DI_BUS_DOWN) == DI_BUS_DOWN) ||
68*9e86db79SHyon Kim 		    ((state & DI_BUS_QUIESCED) == DI_BUS_QUIESCED)) {
69*9e86db79SHyon Kim 			di_fini(node);
70*9e86db79SHyon Kim 			log(LOG_DEBUG, ROUTINE,
71*9e86db79SHyon Kim 			    "devinfo node is not online state: %d", state);
72*9e86db79SHyon Kim 			return (HBA_STATUS_ERROR);
73*9e86db79SHyon Kim 		}
74*9e86db79SHyon Kim 	}
75*9e86db79SHyon Kim 
76*9e86db79SHyon Kim 	di_fini(node);
77*9e86db79SHyon Kim 
78*9e86db79SHyon Kim 	return (HBA_STATUS_OK);
79*9e86db79SHyon Kim }
80