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 
29*10652SHyon.Kim@Sun.COM /*
30*10652SHyon.Kim@Sun.COM  * Retrieves the statistics for a specified port on an adapter
31*10652SHyon.Kim@Sun.COM  */
Sun_sasGetSASPhyAttributes(HBA_HANDLE handle,HBA_UINT32 port,HBA_UINT32 phy,SMHBA_SAS_PHY * pAttributes)32*10652SHyon.Kim@Sun.COM HBA_STATUS Sun_sasGetSASPhyAttributes(HBA_HANDLE handle,
33*10652SHyon.Kim@Sun.COM     HBA_UINT32 port, HBA_UINT32 phy, SMHBA_SAS_PHY *pAttributes)
34*10652SHyon.Kim@Sun.COM {
35*10652SHyon.Kim@Sun.COM 	const char	ROUTINE[] = "Sun_sasGetSASPhyAttributes";
36*10652SHyon.Kim@Sun.COM 	HBA_STATUS		status = HBA_STATUS_OK;
37*10652SHyon.Kim@Sun.COM 	struct sun_sas_hba	*hba_ptr;
38*10652SHyon.Kim@Sun.COM 	struct sun_sas_port	*hba_port_ptr;
39*10652SHyon.Kim@Sun.COM 	struct phy_info		*phy_ptr;
40*10652SHyon.Kim@Sun.COM 
41*10652SHyon.Kim@Sun.COM 	/* Validate the arguments */
42*10652SHyon.Kim@Sun.COM 	if (pAttributes == NULL) {
43*10652SHyon.Kim@Sun.COM 		log(LOG_DEBUG, ROUTINE, "NULL response buffer");
44*10652SHyon.Kim@Sun.COM 		return (HBA_STATUS_ERROR_ARG);
45*10652SHyon.Kim@Sun.COM 	}
46*10652SHyon.Kim@Sun.COM 	lock(&all_hbas_lock);
47*10652SHyon.Kim@Sun.COM 
48*10652SHyon.Kim@Sun.COM 	if ((hba_ptr = Retrieve_Sun_sasHandle(handle)) == NULL) {
49*10652SHyon.Kim@Sun.COM 		log(LOG_DEBUG, ROUTINE, "Invalid handle %08lx", handle);
50*10652SHyon.Kim@Sun.COM 		unlock(&all_hbas_lock);
51*10652SHyon.Kim@Sun.COM 		return (HBA_STATUS_ERROR_INVALID_HANDLE);
52*10652SHyon.Kim@Sun.COM 	}
53*10652SHyon.Kim@Sun.COM 
54*10652SHyon.Kim@Sun.COM 	/* Check for stale data */
55*10652SHyon.Kim@Sun.COM 	status = verifyAdapter(hba_ptr);
56*10652SHyon.Kim@Sun.COM 	if (status != HBA_STATUS_OK) {
57*10652SHyon.Kim@Sun.COM 		log(LOG_DEBUG, ROUTINE, "Verify adapter failed");
58*10652SHyon.Kim@Sun.COM 		unlock(&all_hbas_lock);
59*10652SHyon.Kim@Sun.COM 		return (status);
60*10652SHyon.Kim@Sun.COM 	}
61*10652SHyon.Kim@Sun.COM 
62*10652SHyon.Kim@Sun.COM 	for (hba_port_ptr = hba_ptr->first_port;
63*10652SHyon.Kim@Sun.COM 	    hba_port_ptr != NULL;
64*10652SHyon.Kim@Sun.COM 	    hba_port_ptr = hba_port_ptr->next) {
65*10652SHyon.Kim@Sun.COM 		if (hba_port_ptr->index == port) {
66*10652SHyon.Kim@Sun.COM 			break;
67*10652SHyon.Kim@Sun.COM 		}
68*10652SHyon.Kim@Sun.COM 	}
69*10652SHyon.Kim@Sun.COM 
70*10652SHyon.Kim@Sun.COM 	if (hba_port_ptr == NULL) {
71*10652SHyon.Kim@Sun.COM 		log(LOG_DEBUG, ROUTINE, "Invalid port index");
72*10652SHyon.Kim@Sun.COM 		unlock(&all_hbas_lock);
73*10652SHyon.Kim@Sun.COM 		return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
74*10652SHyon.Kim@Sun.COM 	}
75*10652SHyon.Kim@Sun.COM 
76*10652SHyon.Kim@Sun.COM 	/* match phy index. */
77*10652SHyon.Kim@Sun.COM 	if (phy >= hba_port_ptr->port_attributes.PortSpecificAttribute.
78*10652SHyon.Kim@Sun.COM 	    SASPort->NumberofPhys) {
79*10652SHyon.Kim@Sun.COM 		log(LOG_DEBUG, ROUTINE, "Invalid phy index %d", phy);
80*10652SHyon.Kim@Sun.COM 		unlock(&all_hbas_lock);
81*10652SHyon.Kim@Sun.COM 		return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
82*10652SHyon.Kim@Sun.COM 	} else {
83*10652SHyon.Kim@Sun.COM 		for (phy_ptr = hba_port_ptr->first_phy; phy_ptr != NULL;
84*10652SHyon.Kim@Sun.COM 		    phy_ptr = phy_ptr->next) {
85*10652SHyon.Kim@Sun.COM 			if (phy == phy_ptr->index) {
86*10652SHyon.Kim@Sun.COM 				(void) memset(pAttributes, 0,
87*10652SHyon.Kim@Sun.COM 				    sizeof (SMHBA_SAS_PHY));
88*10652SHyon.Kim@Sun.COM 				(void) memcpy(pAttributes, &phy_ptr->phy,
89*10652SHyon.Kim@Sun.COM 				    sizeof (SMHBA_SAS_PHY));
90*10652SHyon.Kim@Sun.COM 				unlock(&all_hbas_lock);
91*10652SHyon.Kim@Sun.COM 				return (HBA_STATUS_OK);
92*10652SHyon.Kim@Sun.COM 			}
93*10652SHyon.Kim@Sun.COM 		}
94*10652SHyon.Kim@Sun.COM 	}
95*10652SHyon.Kim@Sun.COM 
96*10652SHyon.Kim@Sun.COM 	unlock(&all_hbas_lock);
97*10652SHyon.Kim@Sun.COM 	log(LOG_DEBUG, ROUTINE, "Illegal phy index %d", phy);
98*10652SHyon.Kim@Sun.COM 	return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
99*10652SHyon.Kim@Sun.COM }
100