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
29*9e86db79SHyon Kim /*
30*9e86db79SHyon Kim * Closes an adapter
31*9e86db79SHyon Kim *
32*9e86db79SHyon Kim * the handle is removed from the open_handles list
33*9e86db79SHyon Kim */
34*9e86db79SHyon Kim void
Sun_sasCloseAdapter(HBA_HANDLE handle)35*9e86db79SHyon Kim Sun_sasCloseAdapter(HBA_HANDLE handle)
36*9e86db79SHyon Kim {
37*9e86db79SHyon Kim const char ROUTINE[] = "Sun_sasCloseAdapter";
38*9e86db79SHyon Kim struct open_handle *open_handle_ptr, *open_handle_prev_ptr;
39*9e86db79SHyon Kim int found = 0;
40*9e86db79SHyon Kim
41*9e86db79SHyon Kim if (global_hba_head == NULL) {
42*9e86db79SHyon Kim log(LOG_DEBUG, ROUTINE,
43*9e86db79SHyon Kim "Attempted to close an invalid handle %08lx. "
44*9e86db79SHyon Kim "There are no hba handles loaded in the VSL.",
45*9e86db79SHyon Kim handle);
46*9e86db79SHyon Kim return;
47*9e86db79SHyon Kim }
48*9e86db79SHyon Kim
49*9e86db79SHyon Kim /* Removing handle from open_handles; */
50*9e86db79SHyon Kim lock(&open_handles_lock);
51*9e86db79SHyon Kim if (global_hba_head->open_handles == NULL) {
52*9e86db79SHyon Kim /* check to see if there are any open global_hba_head */
53*9e86db79SHyon Kim log(LOG_DEBUG, ROUTINE,
54*9e86db79SHyon Kim "Attempted to close an invalid handle %08lx. "
55*9e86db79SHyon Kim "There are no open handles in the VSL.",
56*9e86db79SHyon Kim handle);
57*9e86db79SHyon Kim } else if (global_hba_head->open_handles->next == NULL) {
58*9e86db79SHyon Kim /* there is only one handle open */
59*9e86db79SHyon Kim if (global_hba_head->open_handles->handle == handle) {
60*9e86db79SHyon Kim free(global_hba_head->open_handles);
61*9e86db79SHyon Kim global_hba_head->open_handles = NULL;
62*9e86db79SHyon Kim } else {
63*9e86db79SHyon Kim log(LOG_DEBUG, ROUTINE,
64*9e86db79SHyon Kim "Attempted to close an invalid handle %08lx. "
65*9e86db79SHyon Kim "Unable to find handle to close.", handle);
66*9e86db79SHyon Kim }
67*9e86db79SHyon Kim } else { /* there is more than one handle open */
68*9e86db79SHyon Kim open_handle_ptr = global_hba_head->open_handles;
69*9e86db79SHyon Kim if (open_handle_ptr->handle == handle) {
70*9e86db79SHyon Kim global_hba_head->open_handles = open_handle_ptr->next;
71*9e86db79SHyon Kim free(open_handle_ptr);
72*9e86db79SHyon Kim } else {
73*9e86db79SHyon Kim for (open_handle_ptr = open_handle_ptr->next,
74*9e86db79SHyon Kim open_handle_prev_ptr =
75*9e86db79SHyon Kim global_hba_head->open_handles;
76*9e86db79SHyon Kim open_handle_ptr != NULL;
77*9e86db79SHyon Kim open_handle_ptr = open_handle_ptr->next) {
78*9e86db79SHyon Kim if (open_handle_ptr->handle == handle) {
79*9e86db79SHyon Kim open_handle_prev_ptr->next =
80*9e86db79SHyon Kim open_handle_ptr->next;
81*9e86db79SHyon Kim free(open_handle_ptr);
82*9e86db79SHyon Kim found = 1;
83*9e86db79SHyon Kim break;
84*9e86db79SHyon Kim } else {
85*9e86db79SHyon Kim open_handle_prev_ptr =
86*9e86db79SHyon Kim open_handle_prev_ptr->next;
87*9e86db79SHyon Kim }
88*9e86db79SHyon Kim }
89*9e86db79SHyon Kim if (found == 0) {
90*9e86db79SHyon Kim log(LOG_DEBUG, ROUTINE,
91*9e86db79SHyon Kim "Attempted to close an invalid handle "
92*9e86db79SHyon Kim "%08lx. Unable to find handle to close.",
93*9e86db79SHyon Kim handle);
94*9e86db79SHyon Kim }
95*9e86db79SHyon Kim }
96*9e86db79SHyon Kim }
97*9e86db79SHyon Kim
98*9e86db79SHyon Kim unlock(&open_handles_lock);
99*9e86db79SHyon Kim }
100