9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * See the License for the specific language governing permissions
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and limitations under the License.
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 * CDDL HEADER END
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Use is subject to license terms.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Remote port tree node structure.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Report LUN data structure.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The following flag is used for printing HBA header on-demand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The following structure is for sorted output of HBA and HBA Port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The following two functions are for generating hierachy of expander
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_rp_tree_insert(rp_tree_t **rproot, rp_tree_t *rpnode);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_rp_tree_print(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_rp_tree_print_desc(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimtypedef int (*processPortFunc)(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_ADAPTERATTRIBUTES *attrs, inputArg_t *input);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int isPortWWNInArgv(inputArg_t *input, PHBA_WWN pWWN);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int isStringInArgv(inputArg_t *input, const char *adapterName);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic boolean_t compareLUName(char *cmdArg, char *osName);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* processes for hanlding local HBA info */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleHBA(SMHBA_ADAPTERATTRIBUTES *attrs, inputArg_t *input,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleHBAPort(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_ADAPTERATTRIBUTES *attrs, inputArg_t *input);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int processHBAPortPhyInfo(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int processHBAPortPhyStat(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* process for handling expander info */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleExpander(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_ADAPTERATTRIBUTES *attrs, inputArg_t *input);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* process for handling target port info */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleTargetPort(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_ADAPTERATTRIBUTES *attrs, inputArg_t *input);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* process for handling logical unit info */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleLogicalUnit(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_ADAPTERATTRIBUTES *attrs, inputArg_t *input);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* process for target port SCSI processing */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimsearchTargetPortMappingData(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_PORTATTRIBUTES *port, SMHBA_SAS_PORT *sasattr,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* process for target port config processing */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int searchTargetPort(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_PORTATTRIBUTES *port, SMHBA_PORTATTRIBUTES *targetattr,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* process for logical-unit config processing */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimsearchDevice(PSMHBA_SCSIENTRY entryP, HBA_HANDLE handle, HBA_WWN hbaPortWWN,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* get domain port out of hba-port phy attr. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_name_comp(const char *name1, const char *name2);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * function for hba subcommand
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwnCount - count of the number of WWNs in wwn_argv
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount > 0, then we will only print information for
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the hba ports listed in wwn_argv
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount == 0, then we will print information on all hba ports
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwn_argv - argument array of hba port WWNs
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * options - any options specified by the caller
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 if successful
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 otherwise
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_util_list_hba(int hbaCount, char **hba_argv, cmdOptions_t *options)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* process each of the options */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* utilize wwnCount and wwn_argv for hbaCount and hba_argv */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Process and filter for every local hba,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * when the hba is not specificed, print all hba(s).
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * function for hba-port subcommand
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwnCount - count of the number of WWNs in wwn_argv
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount > 0, then we will only print information for
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the hba ports listed in wwn_argv
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount == 0, then we will print information on all hba ports
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwn_argv - argument array of hba port WWNs
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * options - any options specified by the caller
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 if successful
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 otherwise
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_util_list_hbaport(int wwnCount, char **wwn_argv, cmdOptions_t *options)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* process each of the options */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Process and filter for every local hba-port,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * when the hba-port is not specificed, print all hba-port(s).
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * function for expander subcommand
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwnCount - the number of Remote Port SAS Address in wwn_argv
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount == 0, then print information on all
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * expander devices.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount > 0, then print information for the exapnders
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * given in wwn_argv.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwn_argv - array of WWNs
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * options - options specified by the caller
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 if successful
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 otherwise
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_util_list_expander(int wwnCount, char **wwn_argv, cmdOptions_t *options)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* process each of the options */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Process and filter for every hba-port,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * when the hba-port is not specificed, print all hba-port(s).
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * function for target-port subcommand
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwnCount - the number of Remote Port SAS Address in wwn_argv
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount == 0, then print information on all
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * target ports.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if wwnCount > 0, then print information for the target ports
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * given in wwn_argv.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwn_argv - array of WWNs
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * options - options specified by the caller
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 if successful
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 otherwise
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_util_list_targetport(int tpCount, char **tpArgv, cmdOptions_t *options)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* process each of the options */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Process and filter for every hba-port,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * when the hba-port is not specificed, print all hba-port(s).
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* list all target port */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (tpListWalk = gTargetPortList; tpListWalk != NULL;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim err_cnt += printTargetPortInfo(tpListWalk, input.pflag);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When operands provided, we should set the error code
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * only if there are issues related with the operands.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * list any paths not found first
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * this gives the user cleaner output
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (tpListWalk = gTargetPortList, tpFound = B_FALSE;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Error: Target Port %s Not Found \n",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* list all paths requested in order requested */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (tpListWalk = gTargetPortList, tpFound = B_FALSE;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * This function will enumerate all the hba and hba ports,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * call the callback function to proceed with futher process.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * processPort - a callback function when handling each port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimprocessHBA(inputArg_t *input, processPortFunc processPort)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * To deal with mismatching HBA/HBA Port/Expander Port, we need an
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * array of flags for each operands.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (input->wwnCount && (processPort != handleTargetPort) &&
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim input->wwn_flag = calloc(input->wwnCount, sizeof (int));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim adpt_array = calloc(numAdapters, sizeof (sas_elem_t));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (i = 0; i < numAdapters; i++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If we get SAS incompatible library warning here,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * just skip the following steps.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = HBA_GetAdapterName(i, adpt_array[i].name);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim " HBA index"),
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Sort the HBA Name in place. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (i = 0; i < numAdapters; i++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We need to support an adapter without hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * So get attributes anyway.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = SMHBA_GetAdapterAttributes(handle, &attrs);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = SMHBA_GetNumberOfPorts(handle, &numberOfPorts);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Deal with each subcommand for hba filter here,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * processPort is NULL for hba subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * In order to have a sorted output for HBA Port, we should
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * do the sorting before moving on.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim port_array = calloc(numberOfPorts, sizeof (sas_elem_t));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (portIndex = 0; portIndex < numberOfPorts; portIndex++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* skip any non-sas hba port */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Not able to get port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * print out error message and
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * move on to the next port
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Sort the HBA Port Name here. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Sum up the local hba ports available.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Clear g_printHBA flag for expander subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* process each port on the given adapter */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We only handle the port which is valid.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We have different things to do for the three
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sub-commands here.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * For hba-port, we will check whether the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * specified hba port exist first.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * But if no hba port specified, we should
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * by pass this check(just let hbaPortExist
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "HBA Name:",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "HBA Name:",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * For expander device, input->hbaName is
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the hba port name specified on the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * command line(with -p option).
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * For target port, we don't need to check the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * hba port address, so let it go here.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * For lu, we don't need to check the hba
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port address, so let it go here.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We should reset the hbaPortExist flag
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * here for next round of check and count
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * for the machedHBAPorts.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When we are here, we have traversed all the hba and hba ports.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * processPort == NULL signifies hba subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If enter here, it means we have at least one matching
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * hba, we need to check if there are mismatching ones.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "not found."));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim } else if (local_avail == 0) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If enter here, we have at least one HBA port
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * matched. For hba-port subcommand, we shall check
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * whether there are operands mismatching.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * For expander subcommand, we need to check if the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * specified sas address(ese) exist (none/partial/all).
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If sum is zero, it means that for all the given
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * operands matching count is zero. So none of the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * specified SAS address exist actually.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (sum == 0) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Matching SAS Address not found.\n"));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If we get here, it means that some of the specified
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sas address exist, we will know through looping the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * wwn_flag array.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* even if no remote port is found it is not an error. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * This function will handle the phy stuff for hba-port subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - the index of hba port currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - pointer to hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * pflag - options user specified.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimprocessHBAPortPhyInfo(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim numphys = port->PortSpecificAttribute.SASPort->NumberofPhys;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((pflag & PRINT_PHY) || (pflag & PRINT_PHY_LINKSTAT))
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) fprintf(stdout, "%s\n", " Phy Information:");
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (phyIndex = 0; phyIndex < numphys; phyIndex++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * This function will handle the phy stuff for hba-port subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - the index of hba port currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - pointer to hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * pflag - options user specified.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimprocessHBAPortPhyStat(HBA_HANDLE handle, HBA_UINT32 portIndex, int phyIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) memset(&sasphystat, 0, sizeof (sasphystat));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = SMHBA_GetPhyStatistics(handle, portIndex, phyIndex, &phystat);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim " Link Error Statistics:");
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Error Statistics!"));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (1);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim printHBAPortPhyStatistics(phystat.SASPhyStatistics);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Check whether the pWWN exist in the WWNs list which specified by user.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * pWWN - pointer to the hba port sas address.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 1 true, the pWWN exist in the sas address list specified.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* list only ports given in wwn_argv */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim hbaWWN = strtoull(input->wwn_argv[port_wwn_counter], NULL,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Check whether the string value exists in the input list,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * which specified by user.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * stringName - could be hba adapter name
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * hba-port name.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 1 true, the HBA exists in the list specified.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimisStringInArgv(inputArg_t *input, const char *stringName)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* list only hba(s) given in wwn_argv */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Callback function for hba subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * attrs - pointer to adapter attributes currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * numberOfPorts - number of ports of this HBA.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * matching number
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleHBA(SMHBA_ADAPTERATTRIBUTES *attrs, inputArg_t *input,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim printHBAInfo(attrs, input->pflag, numberOfPorts, adapterName);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Callback function for hba-port subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - the index of hba port currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - pointer to hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * attrs - pointer to adapter attributes currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*ARGSUSED*/
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleHBAPort(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim ret = processHBAPortPhyInfo(handle, portIndex, port, input->pflag);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Callback function for expander subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - the index of hba port currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - pointer to hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * attrs - pointer to adapter attributes currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*ARGSUSED*/
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleExpander(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Retrive all expander device from this hba port first.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((numberOfRP = port->PortSpecificAttribute.SASPort->
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* no remote port. just return 0. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (i = 0; i < numberOfRP; i++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (rpnode->portattr.PortType == HBA_PORTTYPE_SASEXPANDER) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We will try to insert this expander device and target
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * ports into the topology tree. If we failed, we can chain
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * them together and try again when we have all the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * discovered port information in hands.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim PortSpecificAttribute.SASPort->LocalSASAddress.wwn,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sizeof (HBA_WWN)) == 0) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The root node of tree should
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * be set up first.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If we can not set up the root node of
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the tree or we failed to insert
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the disocvered port node, queue it up then.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* no expander found. No need further processing. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When we're here, we should already have all information,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * now we try again to insert them into the topology tree.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * unsolved_head is the pointer which point to the head of
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * unsolved rpnode linked list.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * unsolved_tail is the pointer which point to the tail of
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * unsolved rpnode linked list.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * unsolved_sentinel is for insertion failure detection.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When we're trying to insert the rpnodes from unsolved
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * linked list, it may happen that some of the rpnodes can
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * not be inserted no matter how many times we loop through
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * this linked list. So we use unsolved_sentinel to identify
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the tail of last round of scanning, and unsolved_inserted
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * which is a counter will be used to count how many rpnodes
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * have been inserted from last round, if it is zero, which
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * means that we can not insert rpnodes into rptree any more,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and we should stop and deallocate the memory they occupied.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We just scanned one round for the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * unsolved list. Check to see whether we
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * have nodes inserted, if none, we should
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * break in case of an indefinite loop.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Indicate there is unhandled node.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Chain free the whole unsolved
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * list here.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We just inserted one rpnode, increment the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * unsolved_inserted counter. We will utilize this
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * counter to detect an indefinite insertion loop.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* check if there is left out discovered ports. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim gettext("Error: Failed to establish expander topology on"),
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (firstPrinted == B_FALSE) firstPrinted = B_TRUE;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* still print what we have */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim ret += sas_rp_tree_print(handle, adapterName, portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim ret += sas_rp_tree_print(handle, adapterName, portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Callback function for target-port subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - the index of hba port currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - pointer to hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * attrs - pointer to adapter attributes currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*ARGSUSED*/
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleTargetPort(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim targetattr.PortSpecificAttribute.SASPort = &sasattr;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (i = 0; i < port->PortSpecificAttribute.SASPort->
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* skip expander device */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (targetattr.PortType != HBA_PORTTYPE_SASEXPANDER) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * ****************************************************************************
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * compareLUName -
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * compare names directly and also check if disk namees match with
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * different slice number or /devices path are speicified and matches.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * cmdArg - first string to compare
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * osName - os name from attributes
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * returns B_TRUE if the strings match either directly or via devid
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * B_FALSE otherwise
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * ****************************************************************************
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* user input didn't match, try to match the core of args. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* is this /devices path */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* is this a /dev link */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* if it is disk link */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* other dev links */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim } /* compare */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Process logical-unit(lu) subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * luCount - number of OS device name(s) specified by user.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * luArgv - array of OS device name(s) specified by user.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * options - all the options specified by user.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_util_list_logicalunit(int luCount, char **luArgv, cmdOptions_t *options)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* HBA_LoadLibrary() */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim verbose = (input.pflag & PRINT_VERBOSE) ? B_TRUE : B_FALSE;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* list all paths */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim err_cnt += printOSDeviceNameInfo(LUListWalk, verbose);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When operands provided, we should set the error code
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * only if there are issues related with the operands.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * list any paths not found first
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * this gives the user cleaner output
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Error: Logical Unit %s Not Found \n",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* list all paths requested in order requested */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Callback function for logical-unit(lu) subcommand.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - the index of hba port currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - pointer to hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * attrs - pointer to adapter attributes currently being processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - contains all the input parameters.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*ARGSUSED*/
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimstatic int handleLogicalUnit(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim hbaPortWWN = port->PortSpecificAttribute.SASPort->LocalSASAddress;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = get_domainPort(handle, portIndex, port, &domainPortWWN);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* don't increase error flag for no phy configuration */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * First, we need to get the target mapping data from this hba
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim gettext("Error: Failed to get SCSI mapping data for "
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * By iterating each entry of the targetmapping data, we will
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * construct a global list of logical unit.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (count = 0; count < map->NumberOfEntries; count++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim &(map->entry[count]), handle, hbaPortWWN, domainPortWWN,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Search the matching targetmapping data for given target port and SAM LUN
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and return target mapping data if found.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - hba port index
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * targetportWWN - target port SAS address.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * domainportWWN - domain port SAS address.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * domainportttr - target port SAS attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * samLUN - samLUN from report LUNs data.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * data - matching target mapping data.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimsearchTargetPortMappingData(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_PORTATTRIBUTES *port, SMHBA_SAS_PORT *sasattr,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = get_domainPort(handle, portIndex, port, &domainPortWWN);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = SMHBA_GetTargetMapping(handle, hbaPortWWN,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* continue to build mapping data based SCSI info */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Get report lun data.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if HBA_STATUS_ERROR_NOT_A_TARGET is return, we can assume this is
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * a remote HBA and move on
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Let's search mapping data and indicate that Report
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * LUNs failed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (count = 0; count < map->NumberOfEntries; count++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sizeof (HBA_WWN)) == 0) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* allocate mapping data for each LUN */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "memory."));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memcpy(&numberOfLun, &lunlength, sizeof (numberOfLun));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (lunCount = 0; lunCount < (numberOfLun / 8); lunCount++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* allocate mapping data for each LUN */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * now issue standard inquiry to get Vendor
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and product information
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memset(&inq, 0, sizeof (struct scsi_inquiry));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sasLUN = ntohll(wwnConversion(lun_resp->lun[lunCount].val));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memcpy(&smhbaLUN, &sasLUN, sizeof (SMHBA_SCSILUN));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* indicate that inquiry for this lun is failed */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (count = 0; count < map->NumberOfEntries; count++) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sizeof (HBA_WWN)) == 0) &&
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Not able to get any target mapping information */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Search the discovered LUs and construct the global LU list.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - hba port index
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - hba port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * targetattr - target port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sasattr - target port SAS attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * pflag - options the user specified.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimsearchTargetPort(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim SMHBA_PORTATTRIBUTES *port, SMHBA_PORTATTRIBUTES *targetattr,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim targetPortConfig_t *TPConfig, *newConfig, *prevConfig;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = get_domainPort(handle, portIndex, port, &domainPortWWN);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* don't increase error flag for no phy configuration */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * First, we will iterate the already constructed target port
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * list to see whether there is a target port already exist with
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * matching target port SAS address.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (discoveredTP = gTargetPortList; discoveredTP != NULL;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sizeof (HBA_WWN)) == 0) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if the target port exist and
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * verbose is not set, just return
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If there is a target port already exist, we should
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * add more information on the target port to construct the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * whole topology.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Here we will check whether the current hba port name
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * has already been added.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* first get the expander SAS address compare */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (memcmp((void *)port->PortSpecificAttribute.SASPort->
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* NO expander */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* expander exist. We should verify it. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sizeof (HBA_WWN)) == 0)) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If we get here, it means that it is a new hba port/exapnder
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sas address for this discovered target port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memcpy((void *)newConfig->expanderSASAddr.wwn,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Should be inserted in the head. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* if scsi option is not set return */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Here we got a new target port which has not ever exist
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * in our global target port list. So add it to the list.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memcpy((void *)&newTP->targetattr, (void *)targetattr,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memcpy((void *)&newTP->sasattr, (void *)sasattr,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) strlcpy(newConfig->hbaPortName, port->OSDeviceName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (memcmp((void *)port->PortSpecificAttribute.SASPort->
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* NO expander */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memset((void *)newConfig->expanderSASAddr.wwn,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim 0, sizeof (HBA_WWN));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* expander exist. We should verify it. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) memcpy((void *)newConfig->expanderSASAddr.wwn,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) memset(&tgtsasport, 0, sizeof (tgtsasport));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim tgtattr.PortSpecificAttribute.SASPort = &tgtsasport;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim newTP->next = gTargetPortList; /* insert at head */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* if scsi option is not set return */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Search the discovered LUs and construct the global LU list.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Arguments:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * entryP - one of the target mapping data.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to hba port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * hbaPortWWN - hba port sas address.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * domainPortWWN - domain port WWN for this sas domain.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portName - HBA port OS Device Name.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * pflag - options the user specified.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return Value:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 sucessfully processed handle
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 error has occured
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim HBA_HANDLE handle, HBA_WWN hbaPortWWN, HBA_WWN domainPortWWN,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* if OSDeviceName is not set, we don't need to search */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * First, we will iterate the already constructed discovered LU
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * list to see whether there is a LU already exist with the same OS
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * device name as current target mapping data entry.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if there is existing OS Device Name and
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * verbose is not set, just return
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If there is a discovered LU already exist, we should
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * add more information on this LU to construct the whole
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * topology.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Here we will check whether the current hba port has
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * already been added.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If we get here, it means that it is a new hba port name
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * for this discovered LU.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim newPort = (portList *)calloc(1, sizeof (portList));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sas_name_comp(newPort->portName, portElem->portName)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Insert in the head of list. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* add Target Port */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) memcpy((void *)&(newPort->tgtPortWWN->portWWN),
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Set LUN data */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Otherwise, we just need to add the target port
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sas address information.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sizeof (HBA_WWN)) == 0)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* add it to existing */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* insert at head */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Set LUN data */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Here we got a new discovered LU which has not ever exist
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * in our global LU list. So add it into our global LU
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* copy device name */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* if verbose is not set return */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* copy WWN data */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim portName, sizeof (newDevice->HBAPortList->portName));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (tgtPortWWNList *)calloc(1, sizeof (tgtPortWWNList));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (++ret);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) memcpy((void *)&(newDevice->HBAPortList->\
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) memset(&inq, 0, sizeof (struct scsi_inquiry));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) memcpy(&smhbaLUN, &entryP->PortLun.TargetLun,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Retrieve the VPD data for the newly found discovered LU.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* init VID/PID/dType as '\0' */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* initialize inq status */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* initialize inq status */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Function we use to insert a newly discovered port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 - success
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 - failed
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (1);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (1);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If the attched sas address is equal to the local sas address,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * then this should be a child node of current root node.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) sas_rp_tree_insert(&(*rproot)->child, rpnode);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim } else if (memcmp(wwn2, wwn3, sizeof (HBA_WWN)) == 0) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If the attached sas address is equal to the attached sas
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * address of current root node, then this should be a
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sibling node.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Insert the SAS/SATA Device at the head of sibling list.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (rpnode->portattr.PortType != HBA_PORTTYPE_SASEXPANDER) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Insert the SAS Expander at the tail of sibling
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If enter here, we should first try to insert the discovered
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port node into the child sub-tree, then try to insert to the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sibling sub-trees. If we failed to insert the discovered
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port node, return 1. The caller will queue this node
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * up and retry insertion later.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim ret = sas_rp_tree_insert(&(*rproot)->child, rpnode);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Function which will print out the whole disocvered port topology.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Here we use the Preorder Traversal algorithm.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The indentation rules are:
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 1 * TABLEN - for attributes
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 2 * TABLEN - for next tier target port/expander
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_rp_tree_print(HBA_HANDLE handle, char *adapterName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We assume that all the nodes are disocvered ports(sas device or
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * expander).
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* Adjust local indentation if a discovered port specified. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Check whether current node match one of the specified
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * SAS addresses.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((rpnode->portattr.PortType != HBA_PORTTYPE_SASEXPANDER) ||
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Step down to child tree first.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Then check the sibling tree.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if ((rpnode->portattr.PortType == HBA_PORTTYPE_SASEXPANDER) ||
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * We should print the header(HBA Name + HBA Port Name)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * on-demand. It means that, if we have expander device
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * address specified on the command line, we should print
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the header once we find a matching one. Or we will
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * print the header from the beginning of the output.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim ret += sas_print_rpnode(input, rpnode, lident, gident);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If operands provided with "-t" option specified, we will print
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * the immediate child nodes information under the expander.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* no operand. ignore the option. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Here we use DFS(Depth First Search) algorithm to traverse the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * whole tree.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Function which will destroy the whole discovered port tree.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Here we use the Postorder Traversal algorithm.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Free child tree first.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Free sibling trees then.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Free root node at last.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Function used to print out all the descendant nodes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to HBA.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - port attributes of current HBA port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * desc - the root node of a subtree which will be processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * input - input argument.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * lident - local indentation for shifting indentation.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * gident - global indentation, can also be used to obtain Tier number.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*ARGSUSED*/
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_rp_tree_print_desc(HBA_HANDLE handle, HBA_UINT32 portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Walk through the subtree of desc by Pre-Order Traversal Algo.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim for (rp_node = desc; rp_node != NULL; rp_node = rp_node->sibling) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim ret += sas_print_rpnode(input, rp_node, lident, gident);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Function used to print the information of specified SAS address.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to a HBA.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - port attributes of a HBA port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * rpnode - discovered port which will be processed.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * lident - local indentation used for shifting indentation.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * gident - global indentation used for calculating "Tier" number.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (rpnode->portattr.PortType == HBA_PORTTYPE_SASEXPANDER) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) fprintf(stdout, "%s%s(Tier %d): %016llx\n",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Expander SAS Address",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim wwnConversion(rpnode->sasattr.LocalSASAddress.wwn));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Target Port SAS Address:",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim wwnConversion(rpnode->sasattr.LocalSASAddress.wwn));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (rpnode->portattr.PortType != HBA_PORTTYPE_SASEXPANDER) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "OS Device Name:",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Function used to get the correct domainPortWWN as needed by some of the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * SMHBA APIs.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * handle - handle to a HBA.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * portIndex - index to locate the port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * port - pointer to the structure holding port attributes.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * pdomainPort - pointer to the buffer holding domainPortWWN.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Since iport can exist without any phys,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * sasinfo hba-port -v has indicated numberOfPhys;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if there is no phys within the hba, just return OK.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim status = SMHBA_GetSASPhyAttributes(handle, portIndex,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void *) memcpy(pdomainPort, &phyattr.domainPortWWN,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* return not supported for no phy configured */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Comparison function for comparing names possibly ending with digits.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * <0 - name1 is less than name2.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 - name1 is equal with name2.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 - name1 is more than name2.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim return (0);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim while ((name1[i] == name2[i]) && (name1[i] != '\0'))
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* If neither of name1[i] and name2[i] is '\0'. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* One of name1[i] and name2[i] is not digit. */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Comparison function for sorting HBA/HBA Port.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * arg1 - first argument of type sas_elem_t.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * arg2 - second argument of type sas_elem_t.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * <0 - arg1 is less than arg2.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * 0 - arg1 is equal with arg2.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * >0 - arg1 is more than arg2.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimsas_elem_compare(const void *arg1, const void *arg2)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Sorting function for HBA/HBA Port output.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * array - elements array of type sas_elem_t.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * nelem - number of elements in array of type sas_elem_t.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim qsort((void *)array, nelem, sizeof (sas_elem_t), sas_elem_compare);