2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#include <sun_sas.h>
2N/A
2N/A/*
2N/A * Retrieves the statistics for a specified port on an adapter
2N/A */
2N/AHBA_STATUS Sun_sasGetSASPhyAttributes(HBA_HANDLE handle,
2N/A HBA_UINT32 port, HBA_UINT32 phy, SMHBA_SAS_PHY *pAttributes)
2N/A{
2N/A const char ROUTINE[] = "Sun_sasGetSASPhyAttributes";
2N/A HBA_STATUS status = HBA_STATUS_OK;
2N/A struct sun_sas_hba *hba_ptr;
2N/A struct sun_sas_port *hba_port_ptr;
2N/A struct phy_info *phy_ptr;
2N/A
2N/A /* Validate the arguments */
2N/A if (pAttributes == NULL) {
2N/A log(LOG_DEBUG, ROUTINE, "NULL response buffer");
2N/A return (HBA_STATUS_ERROR_ARG);
2N/A }
2N/A lock(&all_hbas_lock);
2N/A
2N/A if ((hba_ptr = Retrieve_Sun_sasHandle(handle)) == NULL) {
2N/A log(LOG_DEBUG, ROUTINE, "Invalid handle %08lx", handle);
2N/A unlock(&all_hbas_lock);
2N/A return (HBA_STATUS_ERROR_INVALID_HANDLE);
2N/A }
2N/A
2N/A /* Check for stale data */
2N/A status = verifyAdapter(hba_ptr);
2N/A if (status != HBA_STATUS_OK) {
2N/A log(LOG_DEBUG, ROUTINE, "Verify adapter failed");
2N/A unlock(&all_hbas_lock);
2N/A return (status);
2N/A }
2N/A
2N/A for (hba_port_ptr = hba_ptr->first_port;
2N/A hba_port_ptr != NULL;
2N/A hba_port_ptr = hba_port_ptr->next) {
2N/A if (hba_port_ptr->index == port) {
2N/A break;
2N/A }
2N/A }
2N/A
2N/A if (hba_port_ptr == NULL) {
2N/A log(LOG_DEBUG, ROUTINE, "Invalid port index");
2N/A unlock(&all_hbas_lock);
2N/A return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
2N/A }
2N/A
2N/A /* match phy index. */
2N/A if (phy >= hba_port_ptr->port_attributes.PortSpecificAttribute.
2N/A SASPort->NumberofPhys) {
2N/A log(LOG_DEBUG, ROUTINE, "Invalid phy index %d", phy);
2N/A unlock(&all_hbas_lock);
2N/A return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
2N/A } else {
2N/A for (phy_ptr = hba_port_ptr->first_phy; phy_ptr != NULL;
2N/A phy_ptr = phy_ptr->next) {
2N/A if (phy == phy_ptr->index) {
2N/A (void) memset(pAttributes, 0,
2N/A sizeof (SMHBA_SAS_PHY));
2N/A (void) memcpy(pAttributes, &phy_ptr->phy,
2N/A sizeof (SMHBA_SAS_PHY));
2N/A unlock(&all_hbas_lock);
2N/A return (HBA_STATUS_OK);
2N/A }
2N/A }
2N/A }
2N/A
2N/A unlock(&all_hbas_lock);
2N/A log(LOG_DEBUG, ROUTINE, "Illegal phy index %d", phy);
2N/A return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
2N/A}