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