xref: /titanic_52/usr/src/lib/sun_sas/common/Sun_sasGetSASPhyAttributes.c (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include    <sun_sas.h>
28 
29 /*
30  * Retrieves the statistics for a specified port on an adapter
31  */
32 HBA_STATUS Sun_sasGetSASPhyAttributes(HBA_HANDLE handle,
33     HBA_UINT32 port, HBA_UINT32 phy, SMHBA_SAS_PHY *pAttributes)
34 {
35 	const char	ROUTINE[] = "Sun_sasGetSASPhyAttributes";
36 	HBA_STATUS		status = HBA_STATUS_OK;
37 	struct sun_sas_hba	*hba_ptr;
38 	struct sun_sas_port	*hba_port_ptr;
39 	struct phy_info		*phy_ptr;
40 
41 	/* Validate the arguments */
42 	if (pAttributes == NULL) {
43 		log(LOG_DEBUG, ROUTINE, "NULL response buffer");
44 		return (HBA_STATUS_ERROR_ARG);
45 	}
46 	lock(&all_hbas_lock);
47 
48 	if ((hba_ptr = Retrieve_Sun_sasHandle(handle)) == NULL) {
49 		log(LOG_DEBUG, ROUTINE, "Invalid handle %08lx", handle);
50 		unlock(&all_hbas_lock);
51 		return (HBA_STATUS_ERROR_INVALID_HANDLE);
52 	}
53 
54 	/* Check for stale data */
55 	status = verifyAdapter(hba_ptr);
56 	if (status != HBA_STATUS_OK) {
57 		log(LOG_DEBUG, ROUTINE, "Verify adapter failed");
58 		unlock(&all_hbas_lock);
59 		return (status);
60 	}
61 
62 	for (hba_port_ptr = hba_ptr->first_port;
63 	    hba_port_ptr != NULL;
64 	    hba_port_ptr = hba_port_ptr->next) {
65 		if (hba_port_ptr->index == port) {
66 			break;
67 		}
68 	}
69 
70 	if (hba_port_ptr == NULL) {
71 		log(LOG_DEBUG, ROUTINE, "Invalid port index");
72 		unlock(&all_hbas_lock);
73 		return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
74 	}
75 
76 	/* match phy index. */
77 	if (phy >= hba_port_ptr->port_attributes.PortSpecificAttribute.
78 	    SASPort->NumberofPhys) {
79 		log(LOG_DEBUG, ROUTINE, "Invalid phy index %d", phy);
80 		unlock(&all_hbas_lock);
81 		return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
82 	} else {
83 		for (phy_ptr = hba_port_ptr->first_phy; phy_ptr != NULL;
84 		    phy_ptr = phy_ptr->next) {
85 			if (phy == phy_ptr->index) {
86 				(void) memset(pAttributes, 0,
87 				    sizeof (SMHBA_SAS_PHY));
88 				(void) memcpy(pAttributes, &phy_ptr->phy,
89 				    sizeof (SMHBA_SAS_PHY));
90 				unlock(&all_hbas_lock);
91 				return (HBA_STATUS_OK);
92 			}
93 		}
94 	}
95 
96 	unlock(&all_hbas_lock);
97 	log(LOG_DEBUG, ROUTINE, "Illegal phy index %d", phy);
98 	return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
99 }
100