9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * CDDL HEADER START
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The contents of this file are subject to the terms of the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Common Development and Distribution License (the "License").
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * You may not use this file except in compliance with the License.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * or http://www.opensolaris.org/os/licensing.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * See the License for the specific language governing permissions
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and limitations under the License.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When distributing Covered Code, include this CDDL HEADER in each
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If applicable, add the following below this CDDL HEADER, with the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * fields enclosed by brackets "[]" replaced with your own identifying
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * information: Portions Copyright [yyyy] [name of copyright owner]
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * CDDL HEADER END
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Use is subject to license terms.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#include "sun_sas.h"
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Returns the text string which describes this adapter and which is used to
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * open the adapter with the library.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * index the index to which adapter to retrive the name
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * name buffer to which the adapter name will be placed
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimHBA_STATUS Sun_sasGetAdapterName(HBA_UINT32 index, char *name) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim const char ROUTINE[] = "Sun_sasGetAdapterName";
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim struct sun_sas_hba *hba_ptr;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (name == NULL) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim log(LOG_DEBUG, ROUTINE, "NULL adapter name");
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (HBA_STATUS_ERROR_ARG);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim }
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim lock(&all_hbas_lock);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (hba_ptr = global_hba_head; hba_ptr != NULL;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim hba_ptr = hba_ptr->next) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (hba_ptr->index == index) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (hba_ptr->handle_name == NULL) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim hba_ptr = NULL;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim break;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim }
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Flaw in the spec! How do we know the size of name? */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) strlcpy(name, hba_ptr->handle_name,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim strlen(hba_ptr->handle_name)+1);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim break;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim }
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim }
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim unlock(&all_hbas_lock);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (hba_ptr == NULL) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim log(LOG_DEBUG, ROUTINE,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Unable to find adapter index %d.", index);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim }
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (HBA_STATUS_OK);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim}