fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*LINTLIBRARY*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I18N message number ranges
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This file: 12000 - 12499
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Shared common messages: 1 - 1999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This module is part of the Fibre Channel Interface library.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* #define _POSIX_SOURCE 1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Includes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/file.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mkdev.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/param.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/scsi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <dirent.h> /* for DIR */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/vtoc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nl_types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h> /* for max */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fnmatch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <l_common.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stgcom.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <l_error.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <g_state.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <g_scsi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/ulp/fcp_util.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/impl/fc_error.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/impl/fcph.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/socalio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libdevinfo.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <devid.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Some forward declarations of static functions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * becomes extern interface for Tapestry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static int g_get_inq_dtype(char *, la_wwn_t, uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static int g_get_dev_list(char *, fc_port_dev_t **, int *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int g_issue_fcp_ioctl(int, struct fcp_ioctl *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int g_set_port_state(char *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int g_dev_log_in_out(char *, la_wwn_t, uint16_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int g_get_dev_port_state(char *, la_wwn_t, uint32_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void g_free_rls(AL_rls *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int g_scsi_inquiry_cmd80(int, uchar_t *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int get_fca_inq_dtype(char *, la_wwn_t, uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int g_find_supported_inq_page(int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int wwn_list_name_compare(const void *, const void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int devid_get_all(ddi_devid_t, di_node_t, char *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct mplist_struct **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int get_multipath(char *, struct dlist **,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int get_multipath_disk(char *, struct dlist **,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void mplist_free(struct mplist_struct *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int get_wwn_data(di_node_t, uchar_t **, uchar_t **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int get_dev_path(struct wwn_list_struct **, char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int insert_missing_pwwn(char *, struct wwn_list_struct **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int get_scsi_vhci_port_wwn(char *, uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int search_wwn_entry(struct wwn_list_found_struct *, uchar_t *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int add_wwn_entry(struct wwn_list_found_struct **, uchar_t *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int string_to_wwn(uchar_t *, uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int get_wwns(char *, uchar_t *, uchar_t *, int *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_found_struct **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* type for g_dev_map_init related routines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define S_FREE(x) (((x) != NULL) ? (free(x), (x) = NULL) : (void *)0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct impl_map_dev_prop {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char prop_name[MAXNAMELEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int prop_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int prop_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *prop_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int prop_error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct impl_map_dev_prop *next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} impl_map_dev_prop_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct impl_map_dev {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t topo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *prop_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct impl_map_dev *parent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct impl_map_dev *child;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct impl_map_dev *next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} impl_map_dev_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Defines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define VERBPRINT if (verbose) (void) printf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DIR_MATCH_ST "*[0-9+]n"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DIR_MATCH_SSD "*s2"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PROP_NOEXIST 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PROP_EXIST 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Prototypes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int create_map(char *, gfc_map_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char ctoi(char);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int lilp_map_cmp(const void*, const void*);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int devices_get_all(di_node_t, char *, char *,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *my_devfs_path(di_node_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void my_devfs_path_free(char *path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void copy_wwn_data_to_str(char *, const uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void init_drv(char *, char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* static for g_dev_map_init related routines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int update_map_dev_fc_prop(impl_map_dev_prop_t **, uint32_t,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *, uchar_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int update_map_dev_FCP_prop(impl_map_dev_prop_t **, uchar_t *, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int handle_map_dev_FCP_prop(minor_t, la_wwn_t, impl_map_dev_prop_t **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void free_prop_list(impl_map_dev_prop_t **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void free_child_list(impl_map_dev_t **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic u_longlong_t wwnConversion(uchar_t *wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuchar_t g_switch_to_alpa[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda, 0xd9, 0xd6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce, 0xcd, 0xcc, 0xcb, 0xca,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xc9, 0xc7, 0xc6, 0xc5, 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xb4, 0xb3, 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b, 0x98, 0x97,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7c, 0x7a, 0x79,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x6a, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c, 0x4b, 0x4a,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c, 0x3a, 0x39, 0x36, 0x35,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x34, 0x33, 0x32, 0x31, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x27, 0x26, 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuchar_t g_sf_alpa_to_switch[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x7d, 0x7c, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x7a, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0x78, 0x00, 0x00, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x00, 0x00, 0x77, 0x76, 0x00, 0x00, 0x75, 0x00, 0x74,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x73, 0x72, 0x00, 0x00, 0x00, 0x71, 0x00, 0x70, 0x6f, 0x6e,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x6d, 0x6c, 0x6b, 0x6a, 0x69, 0x68, 0x00, 0x00, 0x67,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x66, 0x65, 0x64, 0x63, 0x62, 0x00, 0x00, 0x61, 0x60, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x00, 0x5d,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x5c, 0x5b, 0x00, 0x5a, 0x59, 0x58, 0x57, 0x56, 0x55, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x54, 0x53, 0x52, 0x51, 0x50, 0x4f, 0x00, 0x00, 0x4e,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x4d, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4b,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x4a, 0x49, 0x48, 0x00, 0x47, 0x46, 0x45, 0x44, 0x43,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x42, 0x00, 0x00, 0x41, 0x40, 0x3f, 0x3e, 0x3d, 0x3c, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x3b, 0x3a, 0x00, 0x39, 0x00, 0x00, 0x00, 0x38, 0x37,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x36, 0x00, 0x35, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x00, 0x00, 0x33, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x31, 0x30, 0x00, 0x00, 0x2f, 0x00, 0x2e, 0x2d, 0x2c,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x00, 0x00, 0x2b, 0x00, 0x2a, 0x29, 0x28, 0x00, 0x27,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x26, 0x25, 0x24, 0x23, 0x22, 0x00, 0x00, 0x21, 0x20, 0x1f,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x1e, 0x1d, 0x1c, 0x00, 0x00, 0x1b, 0x1a, 0x00, 0x19, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x17, 0x16, 0x15,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x00, 0x00, 0x0e,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x00, 0x00, 0x08, 0x07, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x06, 0x00, 0x00, 0x00, 0x05, 0x04, 0x03, 0x00, 0x02, 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if device is in the map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PARAMS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map - loop map returned from fc port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tid - device ID for private map or 24-bit alpa for fabric map
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 if device present in the map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_device_in_map(gfc_map_t *map, int tid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gfc_port_dev_info_t *dev_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr = map->dev_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map->hba_addr.port_topology == FC_TOP_PUBLIC_LOOP) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (map->hba_addr.port_topology == FC_TOP_FABRIC)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < map->count; i++, dev_ptr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_ptr->
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell gfc_port_dev.pub_port.dev_did.port_id == tid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Does not count if WWN == 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < FC_WWN_SIZE; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_ptr->gfc_port_dev.pub_port.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_pwwn.raw_wwn[j] != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < map->count; i++, dev_ptr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_ptr->gfc_port_dev.priv_port.sf_al_pa ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (int)g_switch_to_alpa[tid]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Does not count if WWN == 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < WWN_SIZE; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_ptr->gfc_port_dev.priv_port.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_port_wwn[j] != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Inserts any missing port wwns for mpxio device paths
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which are in ONLINE or STANDBY state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteinsert_missing_pwwn(char *phys_path, struct wwn_list_struct **wwn_list_ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int i, pathcnt, match;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_struct *new_wwn, *wwn_list_s, *wwn_list_found;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char pwwn1[WWN_S_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now check each scsi_vhci device path to find any missed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port wwns and insert a new wwn list entry for the missed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(phys_path, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free memory for pathlist before return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just search for ONLINE and STANDBY paths as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * those should be the only missing wwn entries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There is a very small window for an offline
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to have occurred between the time we retrieved
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the device list and a call to this function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If that happens, we just won't add it to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the list which is probably a good thing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_ONLINE ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathlist.path_info[i].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(pwwn1, pathlist.path_info[i].path_addr,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_S_LEN - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pwwn1[WWN_S_LEN - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now search through wwn list for matching
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * device path AND pwwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If it's found, continue to next path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If it's not found, add it the wwn list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte match = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list_s = *wwn_list_ptr; wwn_list_s != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_s = wwn_list_s->wwn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(phys_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_s->physical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(phys_path)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_found = wwn_list_s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pwwn1,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_s->port_wwn_s,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_S_LEN) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte match++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (match) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * didn't find a match but the mpxio
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * device is in the list. Retrieve
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the info from the wwn_list_found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and add it to the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((new_wwn = (struct wwn_list_struct *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (struct wwn_list_struct)))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(pathlist.path_info);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((new_wwn->physical_path = (char *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(wwn_list_found->physical_path)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell + 1)) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(pathlist.path_info);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((new_wwn->logical_path = (char *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(wwn_list_found->logical_path)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell + 1)) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(pathlist.path_info);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Insert new_wwn at the beginning of the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new_wwn->wwn_next = *wwn_list_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*wwn_list_ptr)->wwn_prev = new_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set new starting ptr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_ptr = new_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(new_wwn->physical_path,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_found->physical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(wwn_list_found->physical_path));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(new_wwn->logical_path,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_found->logical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(wwn_list_found->logical_path));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copy found node wwn data to this new entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Node wwn is required for the wwn_list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * however for mpxio devices it is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * relevant as it may apply to multiple
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * target controllers, so just use what
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we already have in wwn_list_found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(new_wwn->node_wwn_s,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_found->node_wwn_s, WWN_S_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(new_wwn->w_node_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_found->w_node_wwn, WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new_wwn->device_type =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_found->device_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(new_wwn->port_wwn_s, pwwn1, WWN_S_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * gets the port wwn for a scsi_vhci device using ONLINE path priority
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_scsi_vhci_port_wwn(char *phys_path, uchar_t *port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int i, pathcnt, found;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char pwwn1[WWN_S_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(phys_path, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Look for an ONLINE path first.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If that fails, get the STANDBY path port WWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If that fails, give up
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; found == 0 && i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(pwwn1, pathlist.path_info[i].path_addr,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_S_LEN - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pwwn1[WWN_S_LEN - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; found == 0 && i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(pwwn1, pathlist.path_info[i].path_addr,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_S_LEN - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pwwn1[WWN_S_LEN - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (string_to_wwn((uchar_t *)pwwn1, port_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * searches wwn_list_found for the pwwn passed in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and sets the corresponding nwwn on return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If no match is found, -1 is returned and nwwn is not set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesearch_wwn_entry(struct wwn_list_found_struct *wwn_list_found, uchar_t *pwwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t *nwwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_found_struct *wwn_list_s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list_s = wwn_list_found; wwn_list_s != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_s = wwn_list_s->wwn_next) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (memcmp(pwwn, wwn_list_s->port_wwn, WWN_SIZE) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(nwwn, wwn_list_s->node_wwn, WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * adds a nwwn, pwwn entry to the next entry in wwn_list_found list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteadd_wwn_entry(struct wwn_list_found_struct **wwn_list_found, uchar_t *pwwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t *nwwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_found_struct *new_wwn, *temp_wwn_list_found = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Got wwns, load data in list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((new_wwn = (struct wwn_list_found_struct *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1, sizeof (struct wwn_list_found_struct))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(new_wwn->node_wwn, nwwn, WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(new_wwn->port_wwn, pwwn, WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Insert new_wwn in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*wwn_list_found != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte temp_wwn_list_found = (*wwn_list_found)->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*wwn_list_found)->wwn_next = new_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_found = new_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new_wwn->wwn_next = temp_wwn_list_found;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create a linked list of all the WWN's for all FC_AL disks and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tapes that are attached to this host.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN VALUES: 0 O.K.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_list pointer:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL: No devices found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * !NULL: Devices found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_list points to a linked list of wwn's.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_wwn_list(struct wwn_list_struct **wwn_list_ptr, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_struct *wwn_list_p = NULL, *wwn_list_tmp_p = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_found_struct *wwn_list_found = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int al_pa;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t node_wwn[WWN_SIZE], port_wwn[WWN_SIZE];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell hrtime_t start_time, end_time;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *env = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return L_NULL_WWN_LIST if wwn_list_ptr is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list_ptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NULL_WWN_LIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((env = getenv("_LUX_T_DEBUG")) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_devices_get_all(wwn_list_ptr)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * retain backward compatibility with g_get_wwn_list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and retrieve the WWN for scsi_vhci devices in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * same fashion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note that for scsi_vhci devices, the wwn fields are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not relevant but in the previous versions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we loaded the wwns so...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_p = *wwn_list_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (wwn_list_p != NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (strstr(wwn_list_p->physical_path, SCSI_VHCI) != NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* get port wwn of first ONLINE, STANDBY */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((get_scsi_vhci_port_wwn(wwn_list_p->physical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell port_wwn)) == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((search_wwn_entry(wwn_list_found, port_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell node_wwn)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell get_wwns(wwn_list_p->physical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell port_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell node_wwn, &al_pa,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &wwn_list_found)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_wwn_list_found(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &wwn_list_found);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Use g_get_wwn as a last resort */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_get_wwn(wwn_list_p->physical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell port_wwn, node_wwn, &al_pa, 0)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * this is a bad WWN.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * remove it from the wwn_list.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * After removing the bad WWN,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * wwn_list_p should point to the next
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * node in the list.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((wwn_list_p->wwn_prev == NULL) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (wwn_list_p->wwn_next == NULL)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *wwn_list_ptr = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(wwn_list_p);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_wwn_list_found(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &wwn_list_found);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_NO_DEVICES_FOUND);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else if (
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_prev == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *wwn_list_ptr =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_next;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(wwn_list_p);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p = *wwn_list_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_prev = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else if (
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_next == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_prev->wwn_next =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(wwn_list_p);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_tmp_p =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_next;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_prev->wwn_next =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_next;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_next->wwn_prev =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->wwn_prev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(wwn_list_p);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p = wwn_list_tmp_p;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell continue;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell copy_wwn_data_to_str(wwn_list_p->node_wwn_s, node_wwn);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell copy_wwn_data_to_str(wwn_list_p->port_wwn_s, port_wwn);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell memcpy(wwn_list_p->w_node_wwn, node_wwn, WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p = wwn_list_p->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list_found(&wwn_list_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now go through the list one more time to add entries for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * any missing port wwns.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This allows a search on port wwn for any paths which are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ONLINE or STANDBY. We don't care about OFFLINE as those won't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and should not show up in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list_p = *wwn_list_ptr; wwn_list_p != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_p = wwn_list_p->wwn_next) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (strstr(wwn_list_p->physical_path, SCSI_VHCI) != NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = insert_missing_pwwn(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_p->physical_path, wwn_list_ptr)) != 0)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, " g_get_wwn_list: "
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "\t\tTime = %lld millisec\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (end_time - start_time)/1000000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_devices_get_all(struct wwn_list_struct **wwn_list_ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_struct *tape_ptr = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_struct *tmp;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell di_node_t root;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell hrtime_t start_time, end_time;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *env = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((env = getenv("_LUX_T_DEBUG")) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Try to prime di_drv_first_node()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If there are no nodes bound, di_drv_first_node()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will return nothing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_drv(DEV_TAPE_DIR, DIR_MATCH_ST, SLSH_DRV_NAME_ST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_drv(DEV_RDIR, DIR_MATCH_SSD, SLSH_DRV_NAME_SSD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((root = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_DEV_SNAPSHOT_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, " di_init - /: "
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "\t\tTime = %lld millisec\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (end_time - start_time)/1000000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = devices_get_all(root, SSD_DRVR_NAME, SSD_MINOR_NAME,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != L_NO_DEVICES_FOUND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(&tape_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(wwn_list_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, " devices_get_all - ssd: "
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "\t\tTime = %lld millisec\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (end_time - start_time)/1000000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = devices_get_all(root, ST_DRVR_NAME, ST_MINOR_NAME,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &tape_ptr)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != L_NO_DEVICES_FOUND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(&tape_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(wwn_list_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if *wwn_list_ptr == NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we have disks but no tapes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*wwn_list_ptr != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No disks or tapes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(&tape_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(wwn_list_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, " devices_get_all - st: "
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "\t\tTime = %lld millisec\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (end_time - start_time)/1000000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now link the two together */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*wwn_list_ptr != NULL) { /* We have both disks and tapes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Walk to the end of it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tmp = *wwn_list_ptr; tmp->wwn_next != NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell tmp = tmp->wwn_next)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp->wwn_next = tape_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tape_ptr->wwn_prev = tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* else we have no disks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_ptr = tape_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_free_wwn_list_found(struct wwn_list_found_struct **wwn_list_found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WWN_list_found *next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return if wwn_list_found is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list_found == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; *wwn_list_found != NULL; *wwn_list_found = next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next = (*wwn_list_found)->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_destroy_data(*wwn_list_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_found = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_free_wwn_list(struct wwn_list_struct **wwn_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_list *next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return if wwn_list is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; *wwn_list != NULL; *wwn_list = next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next = (*wwn_list)->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*wwn_list)->physical_path != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data((*wwn_list)->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*wwn_list)->logical_path != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data((*wwn_list)->logical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data(*wwn_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_sort_wwn_list(struct wwn_list_struct **wwn_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct **wwn_list_array;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct *wwn_list_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct **wwn_list_array_ptr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct **wwn_list_array_ptr2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Count the number of wwn_list in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (n = 0, wwn_list_ptr = *wwn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_ptr != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_ptr = wwn_list_ptr->wwn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n <= 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate a simple wwn_list array and fill it in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_array = (struct wwn_list_struct **)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_zalloc((n+1) * sizeof (struct wwn_list_struct *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_array_ptr1 = wwn_list_array;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list_ptr = *wwn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_ptr != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_ptr = wwn_list_ptr->wwn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_array_ptr1++ = wwn_list_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_array_ptr1 = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Sort the wwn_list array
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qsort((void *) wwn_list_array, n,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct wwn_list_struct *), wwn_list_name_compare);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Rebuild the linked list wwn_list structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_array_ptr1 = wwn_list_array;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list = *wwn_list_array_ptr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_array_ptr2 = wwn_list_array_ptr1 + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*wwn_list_array_ptr1)->wwn_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n - 1; i++) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (*wwn_list_array_ptr2)->wwn_prev = *wwn_list_array_ptr1;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (*wwn_list_array_ptr1++)->wwn_next = *wwn_list_array_ptr2++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*wwn_list_array_ptr1)->wwn_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clean up
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data((void *)wwn_list_array);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewwn_list_name_compare(const void *arg1, const void *arg2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *s1, *s2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n1, n2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p1, *p2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s1 = (*((struct wwn_list_struct **)arg1))->logical_path;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s2 = (*((struct wwn_list_struct **)arg2))->logical_path;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*s1 == 0 || *s2 == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((isdigit(*s1) && isdigit(*s2))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n1 = strtol(s1, &p1, 10);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n2 = strtol(s2, &p2, 10);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n1 != n2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (n1 - n2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s1 = p1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s2 = p2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (*s1 != *s2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s1++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s2++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*s1 - *s2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the limited map for FC4 devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is specific to FC4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devices and doesn't work for FC (leadville) devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN VALUES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 O.K.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lilpmap *map_ptr:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL: No devices found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * !NULL: if devices found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_limited_map(char *path, struct lilpmap *map_ptr, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, i;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char drvr_path[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat stbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize map */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset(map_ptr, 0, sizeof (struct lilpmap));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the path to the :devctl driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This assumes the path looks something like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0:1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a 1 level PCI type driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(drvr_path, &stbuf) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append a port. Just try 0 since they did not give us one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, ":0");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_limited_map: Geting drive map from:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " %s\n", drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(drvr_path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_GETMAP, map_ptr) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GETMAP ioctl failed\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCIO_GETMAP_IOCTL_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check for reasonableness.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map_ptr->lilp_length > 126) || (map_ptr->lilp_magic != 0x1107)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_LOOP_MAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < (uint_t)map_ptr->lilp_length; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_ptr->lilp_list[i] > 0xef) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_LOOP_MAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For leadville specific HBA's ONLY.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the host specific parameters,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * al_pa, hard address, node/port WWN etc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OUTPUT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fc_port_dev_t structure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if OK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero in case of error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_host_params(char *host_path, fc_port_dev_t *host_val, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int dev_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if host_path is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host_path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if host_val is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host_val == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_type = g_get_path_type(host_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type == 0) || !(dev_type & FC_GEN_XPORT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(host_path, O_NDELAY | O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize structure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset(host_val, 0, sizeof (struct fc_port_dev));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_HOST_PARAMS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)host_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (fc_port_dev_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_issue_fcio_ioctl(fd, &fcio, verbose) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GET_HOST_PARAMS ioctl failed.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCIO_GET_HOST_PARAMS_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the inquiry information for the leadville HBA. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = get_fca_inq_dtype(host_path, host_val->dev_pwwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &host_val->dev_dtype)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue FCIO ioctls to the port(fp) driver.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO ioctl needs to be retried when it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is returned with an EINVAL error, wait
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * time between retries should be atleast
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * WAIT_FCIO_IOCTL (too much of a time to wait!!)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OUTPUT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fcio_t structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if O.K.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_issue_fcio_ioctl(int fd, fcio_t *fcio, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int ntries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ntries = 0; ntries < RETRY_FCIO_IOCTL; ntries++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_CMD, fcio) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((errno == EAGAIN) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (ntries+1 < RETRY_FCIO_IOCTL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait WAIT_FCIO_IOCTL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) usleep(WAIT_FCIO_IOCTL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF("FCIO ioctl failed.\n"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "Error: %s. fc_error = %d (0x%x)\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strerror(errno), fcio->fcio_errno,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio->fcio_errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno == EINVAL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fcio->fcio_errno == FC_TOOMANY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_DEVICE_COUNT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When port is offlined, qlc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns the FC_OFFLINE error and errno
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is set to EIO.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We do want to ignore this error,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * especially when an enclosure is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * removed from the loop.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fcio->fcio_errno == FC_OFFLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function issues the FCP_TGT_INQUIRY ioctl to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the fcp module
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OUTPUT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fcp_ioctl structure in fcp_data is filled in by fcp
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN VALUES :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on Success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Non-zero otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_issue_fcp_ioctl(int fd, struct fcp_ioctl *fcp_data, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct device_data *dev_data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue the ioctl to FCP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The retries are required because the driver may
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need some time to respond at times.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (num_tries++ < RETRY_FCP_IOCTL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if ioctl fails it is an error from Solaris operation. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCP_TGT_INQUIRY, fcp_data) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno == EAGAIN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) usleep(WAIT_FCP_IOCTL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_data = (struct device_data *)((void *)(fcp_data->list));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_data->dev_status == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_data->dev_status == EAGAIN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) usleep(WAIT_FCP_IOCTL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_data->dev0_type = DTYPE_UNKNOWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCP_TGT_INQUIRY_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the number of devices and also
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a list of devices accessible through
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the device's port as specified by path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The calling function * is responsible for freeing the dev_list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Acquires inq_dtype from g_get_inq_dtype() and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stores into dev_dtype field of fc_port_dev.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For fabric devices call FCIO_DEV_LOGIN (if necessary) to execute port login
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and get inq dtype.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dev_list:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL: No devices found, in case of an error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Non-NULL: Devices found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ndevs:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set to the number of devices
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * accessible through the port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if O.K.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_dev_list(char *path, fc_port_dev_t **dev_list, int *ndevs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int num_devices = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int i, err, ulp_failure = 0, new_count = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int dev_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char fcapath[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *char_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat stbuf;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio_t fcio;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint32_t port_top;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_port_dev_t *dlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dev_list = dlist = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(fcapath, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the path to the :devctl driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This assumes the path looks something like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0/ses@e,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a 1 level PCI type driver but still :devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(fcapath, DRV_NAME_SSD) || strstr(fcapath, SES_NAME)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strrchr(fcapath, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *char_ptr = '\0'; /* Terminate sting */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(fcapath, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(fcapath, &stbuf) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(fcapath, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_type = g_get_path_type(fcapath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type == 0) || !(dev_type & FC_GEN_XPORT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(fcapath, O_NDELAY | O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the device list from port driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_NUM_DEVS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (num_devices);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&num_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_issue_fcio_ioctl(fd, &fcio, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GET_NUM_DEVS ioctl failed.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCIO_GET_NUM_DEVS_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_devices == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ndevs = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dlist = (fc_port_dev_t *)calloc(num_devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero((caddr_t)&fcio, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the device list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_DEV_LIST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Information read operation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = num_devices * sizeof (fc_port_dev_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)dlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* new device count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_alen = sizeof (new_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_abuf = (caddr_t)&new_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_issue_fcio_ioctl(fd, &fcio, 0)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (err == L_INVALID_DEVICE_COUNT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * original buffer was small so allocate buffer
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * with a new count and retry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(dlist);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell num_devices = new_count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell new_count = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((dlist = (fc_port_dev_t *)calloc(num_devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd = FCIO_GET_DEV_LIST;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Information read operation */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_xfer = FCIO_XFER_READ;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = (caddr_t)dlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_olen = num_devices * sizeof (fc_port_dev_t);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* new device count */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_alen = sizeof (new_count);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_abuf = (caddr_t)&new_count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_issue_fcio_ioctl(fd, &fcio, 0)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (err == L_INVALID_DEVICE_COUNT) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * No more retry. There may be severe
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * hardware problem so return error
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * here.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" Device count was %d"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " should have been %d\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell num_devices, new_count);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " FCIO_GET_DEV_LIST ioctl failed.");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell err = L_FCIO_GET_DEV_LIST_FAIL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(dlist);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GET_DEV_LIST ioctl failed.");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(dlist);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_FCIO_GET_DEV_LIST_FAIL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if new count is smaller than the original number from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO_GET_NUM_DEVS, adjust new count and buffer size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and continue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (new_count < num_devices) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (new_count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ndevs = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(dlist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_devices = new_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dlist = (fc_port_dev_t *)realloc(dlist,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (new_count * sizeof (fc_port_dev_t))))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(dlist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dev_list = dlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ndevs = num_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* close here since fcapath will be passed to other routines. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_fca_port_topology(fcapath, &port_top, 0)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(*dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dev_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the inq_dtype for each device on dev list. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < num_devices; i++, dlist++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the inq_dtype for each device. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_inq_dtype(fcapath, dlist->dev_pwwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &dlist->dev_dtype)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if g_get_inq_dtype failed on g_dev_login
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or g_issue_fcp_ioctl, continue to the next
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dev on dlist.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_GET_DEV_LIST_ULP_FAILURE is returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * after processing the whole dlist.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err == L_FCIO_DEV_LOGIN_FAIL) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (err == L_FCP_TGT_INQUIRY_FAIL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ulp_failure = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlist->dev_dtype = GFC_ERR_INQ_DTYPE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(*dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dev_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ulp_failure) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_GET_DEV_LIST_ULP_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Constant used by g_get_inq_dtype() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FCP_PATH "/devices/pseudo/fcp@0:fcp"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Gets the inq_dtype for devices on the fabric FC driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * through an ioctl to the FCP module.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OUTPUT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inq_dtype is set to the dtype on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN VALUES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on Success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Non-zero on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_inq_dtype(char *fcapath, la_wwn_t pwwn, uchar_t *inq_dtype)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dev_type, fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err, fcp_fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t port_top = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct fcp_ioctl fcp_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct device_data inq_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat sbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_type = g_get_path_type(fcapath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type == 0) || !(dev_type & FC_GEN_XPORT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_fca_port_topology(fcapath, &port_top, 0)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((port_top == FC_TOP_FABRIC) || (port_top == FC_TOP_PUBLIC_LOOP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if there is an error on getting port state we will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue to login.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * state can be either of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PORT_DEVICE_INVALID, PORT_DEVICE_VALID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PORT_DEVICE_LOGGED_IN. Trying port login
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unless already logged in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It will be examined if there is an adverse
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * effect on invalid state device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((err = g_get_dev_port_state(fcapath, pwwn, &state))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell != 0) || (state != PORT_DEVICE_LOGGED_IN)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* do port login to fabric device. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_dev_login(fcapath, pwwn)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(fcapath, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fstat(fd, &sbuf) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fcp_fd = g_object_open(FCP_PATH, O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the minor number for an fp instance */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.fp_minor = minor(sbuf.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.listlen = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq_data.dev_pwwn = pwwn; /* The port WWN as passed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.list = (caddr_t)&inq_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err = g_issue_fcp_ioctl(fcp_fd, &fcp_data, 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fcp_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *inq_dtype = inq_data.dev0_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fcp_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Gets the inq_dtype for devices on the fabric FC driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * through an ioctl to the FCP module.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is exactly same as g_get_inq_dtype except that it does not do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_dev_login(). That is for the case when the FCA tries to get its own
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inq_dtype and in such a case, it cannot PLOGI into itself.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OUTPUT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inq_dtype is set to the dtype on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN VALUES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on Success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Non-zero on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_fca_inq_dtype(char *fcapath, la_wwn_t pwwn, uchar_t *inq_dtype)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dev_type, fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err, fcp_fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct fcp_ioctl fcp_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct device_data inq_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat sbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_type = g_get_path_type(fcapath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type == 0) || !(dev_type & FC_GEN_XPORT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(fcapath, O_NDELAY | O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fstat(fd, &sbuf) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fcp_fd = g_object_open(FCP_PATH, O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the minor number for an fp instance */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.fp_minor = minor(sbuf.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.listlen = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq_data.dev_pwwn = pwwn; /* The port WWN as passed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.list = (caddr_t)&inq_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err = g_issue_fcp_ioctl(fcp_fd, &fcp_data, 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fcp_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *inq_dtype = inq_data.dev0_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fcp_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the traditional g_get_dev_map. Device list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and local hba seperate.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_dev_map(char *path, gfc_map_t *map_ptr, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (create_map(path, map_ptr, verbose, MAP_FORMAT_STANDARD));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the device map with local hba in physical
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * order. Note: Physical order is only returned properly for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * private loop. local hba is also included seperate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_lilp_map(char *path, gfc_map_t *map_ptr, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (create_map(path, map_ptr, verbose, MAP_FORMAT_LILP));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Gets device map from nexus driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PARAMS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * path - must be the physical path to a device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map - loop map returned from fc port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * verbose - options.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LOGIC:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1. check the validity of path via g_get_path_type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2. If FC path, get the topology of the path via
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_fca_port_topology.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3. If FC type(Leadville statck)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_dev_list to get the device node list of fc_port_dev_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_host_params to get the fca port node of fc_port_dev_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Case of fabric or public loop topology
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if the port id > 0xffff.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Move device node and fca port node to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * gfc_map structure via gfc_port_dev_info_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pub_port union.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue g_get_inq_dtype to get FCP inquiry data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and store it into gfc_port_dev_info_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Case of private loop topology
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if the port id < 0xff.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Move device node and fca port node to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * gfc_map structure via gfc_port_dev_info_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * priv_port union.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue g_get_inq_dtype to get FCP inquiry data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and store it into gfc_port_dev_info_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * else FC4 type(socal/sf or ifp stack)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SFIOCGMAP ioctl to get the device and hba nodes of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sf_addr_pair_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 : if OK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero: otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecreate_map(char *path, gfc_map_t *map_ptr, int verbose, int map_type)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, i, j, num_devices = 0, err, pathcnt = 1;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char drvr_path[MAXPATHLEN], drvr_path0[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *char_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat stbuf;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_port_dev_t *dev_list, *dlistptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint32_t hba_port_top = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint_t dev_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_al_map_t sf_map;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell gfc_port_dev_info_t *dev_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_port_dev_t fp_hba_port;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int p_on = 0, p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if path is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if map_ptr is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_ptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the path to the :devctl driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This assumes the path looks something like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0/ses@e,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a 1 level PCI type driver but still :devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(path, SCSI_VHCI)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path0, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(drvr_path0, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state < MAXPATHSTATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_st = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[p_on].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on_line path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_on].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* standby or path0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_st].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(drvr_path, DRV_NAME_SSD) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strstr(drvr_path, SES_NAME) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strstr(drvr_path, DRV_NAME_ST)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strrchr(drvr_path, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *char_ptr = '\0'; /* Terminate sting */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(drvr_path, &stbuf) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_dev_map: Geting drive map from:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " %s\n", drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_type = g_get_path_type(drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type == 0) || !(dev_type & XPORT_MASK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get fiber topology */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_fca_port_topology(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &hba_port_top, verbose)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* for FC devices. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_type & FC_FCA_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if g_get_dev_list fails with L_NO_DEVICES_FOUND
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we still want to call g_get_host_params to try to find the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * HBA. If we do not see any HBAs on the loop, the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_host_params will fail when it trys to issue the target
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inquiry ioctl. In this case, we would still like to return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_NO_DEVICES_FOUND.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If g_get_dev_list fails with L_NO_DEVICES_FOUND and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_host_params fails, the function returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_NO_DEVICES_FOUND
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_dev_list(drvr_path, &dev_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &num_devices)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_dev_map doesn't allow ulp failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to continue thus we need to free dev_list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == L_GET_DEV_LIST_ULP_FAILURE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != L_NO_DEVICES_FOUND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get local HBA information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_host_params(drvr_path, &fp_hba_port,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell verbose)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_devices == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If devices, other than local HBA are found */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate space for them in the gfc_map. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_devices > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If map type is on MAP_FORMAT_LILP we need */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* to add space for the local HBA */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_type == MAP_FORMAT_LILP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->count = ++num_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->count = num_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map_ptr->dev_addr = (gfc_port_dev_info_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte calloc(map_ptr->count,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (gfc_port_dev_info_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If we want the lilp map then we need to do a little */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* work here. The lilp map contains the local hba in */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the dev_addr. Once this has been added qsort the */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* dev_addr array so it's in physical order. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The lilp map will contain the local hba in the */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* dev_addr array only when num_devices > 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_type == MAP_FORMAT_LILP && num_devices > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* First we need to allocate one additional */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* device to the dev_addr structure, for the */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* local hba */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_list = (fc_port_dev_t *)realloc(dev_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (num_devices * sizeof (fc_port_dev_t))))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Next, copy the local hba into this new loc. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcpy(dev_list+(num_devices-1), &fp_hba_port,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MEMCPY_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now sort by physical location */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qsort((void*)dev_list, num_devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t), lilp_map_cmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlistptr = dev_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr = map_ptr->dev_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (hba_port_top) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TOP_FABRIC:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TOP_PUBLIC_LOOP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fp_hba_port.dev_did.port_id <= 0xffff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dlistptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_FABRIC_ADDRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.port_topology = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.gfc_port_dev.pub_port =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fp_hba_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < num_devices; i++, dev_ptr++,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_list++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_list->dev_did.port_id <= 0xffff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dlistptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_FABRIC_ADDRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr->port_topology = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr->gfc_port_dev.pub_port =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *dev_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TOP_PRIVATE_LOOP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Map the (new->old) structures here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Checking (i < SF_NUM_ENTRIES_IN_MAP) just to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * make sure that we don't overrun the map structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * since it can hold data for upto 126 devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fp_hba_port.dev_did.port_id > 0xff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dlistptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PRIVATE_LOOP_ADDRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.port_topology = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.gfc_port_dev.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell priv_port.sf_al_pa =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (uchar_t)fp_hba_port.dev_did.port_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.gfc_port_dev.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell priv_port.sf_hard_address = (uchar_t)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fp_hba_port.dev_hard_addr.hard_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < FC_WWN_SIZE; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.gfc_port_dev.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell priv_port.sf_node_wwn[j] =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fp_hba_port.dev_nwwn.raw_wwn[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.gfc_port_dev.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell priv_port.sf_port_wwn[j] =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fp_hba_port.dev_pwwn.raw_wwn[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.gfc_port_dev.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell priv_port.sf_inq_dtype =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fp_hba_port.dev_dtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; (i < num_devices &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell i < SF_NUM_ENTRIES_IN_MAP);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell i++, dev_ptr++, dev_list++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Out of 24 bits of port_id, copy only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 8 bits to al_pa. This works okay for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devices that're on a private loop.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_list->dev_did.port_id > 0xff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dlistptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PRIVATE_LOOP_ADDRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr->port_topology = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr->gfc_port_dev.priv_port.sf_al_pa
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell = (uchar_t)dev_list->dev_did.port_id;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Code refactorization is needed for C style */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_ptr->gfc_port_dev.priv_port.sf_hard_address
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell = (uchar_t)dev_list->dev_hard_addr.hard_addr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < FC_WWN_SIZE; j++) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_ptr->gfc_port_dev.priv_port.sf_node_wwn[j] =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_list->dev_nwwn.raw_wwn[j];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_ptr->gfc_port_dev.priv_port.sf_port_wwn[j] =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_list->dev_pwwn.raw_wwn[j];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr->gfc_port_dev.priv_port.sf_inq_dtype =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_list->dev_dtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TOP_PT_PT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dlistptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_PT_PT_FC_TOP_NOT_SUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dlistptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_UNEXPECTED_FC_TOPOLOGY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* End of switch on port_topology */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dlistptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* sf and fc4/pci devices */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(drvr_path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize map */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset(&sf_map, 0, sizeof (struct sf_al_map));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, SFIOCGMAP, &sf_map) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" SFIOCGMAP ioctl failed.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_SFIOCGMAP_IOCTL_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for reasonableness. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sf_map.sf_count > 126) || (sf_map.sf_count < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_LOOP_MAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sf_map.sf_count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->count = sf_map.sf_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map_ptr->dev_addr =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (gfc_port_dev_info_t *)calloc(map_ptr->count,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (gfc_port_dev_info_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr = map_ptr->dev_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sf_map.sf_count; i++, dev_ptr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sf_map.sf_addr_pair[i].sf_al_pa > 0xef) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(map_ptr->dev_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->dev_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_LOOP_MAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr->port_topology = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_ptr->gfc_port_dev.priv_port =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_map.sf_addr_pair[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.port_topology = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map_ptr->hba_addr.gfc_port_dev.priv_port =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_map.sf_hba_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function consturct FC proerty list using map_dev_fc_prop_list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port WWN, node WWN, port addr and hard addr properties is constructed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise returns error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellupdate_map_dev_fc_prop(impl_map_dev_prop_t **prop_list, uint32_t map_topo,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t *port_wwn, uchar_t *node_wwn, int port_addr, int hard_addr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *prop_ptr, *pl_start = NULL, *pl_end = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *port_wwn_data, *node_wwn_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *port_addr_data, *hard_addr_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consrtruct port addr property. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((map_topo == FC_TOP_FABRIC) || (map_topo == FC_TOP_PUBLIC_LOOP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port_addr <= 0xffff) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_INVALID_FABRIC_ADDRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (map_topo == FC_TOP_PRIVATE_LOOP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port_addr > 0xff) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_INVALID_PRIVATE_LOOP_ADDRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_ptr = (impl_map_dev_prop_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_prop_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(prop_ptr->prop_name, PORT_ADDR_PROP,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(PORT_ADDR_PROP));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_type = GFC_PROP_TYPE_INT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((port_addr_data = (int *)calloc(1, sizeof (int))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(prop_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *port_addr_data = port_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_data = port_addr_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_start = pl_end = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consrtruct port WWN property. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_ptr = (impl_map_dev_prop_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_prop_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_prop_list(&pl_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(prop_ptr->prop_name, PORT_WWN_PROP,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(PORT_WWN_PROP));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_type = GFC_PROP_TYPE_BYTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((port_wwn_data = (uchar_t *)calloc(1, FC_WWN_SIZE)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_prop_list(&pl_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(port_wwn_data, port_wwn, FC_WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_data = port_wwn_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_size = FC_WWN_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_end->next = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_end = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consrtruct node WWN property. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_ptr = (impl_map_dev_prop_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_prop_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_prop_list(&pl_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(prop_ptr->prop_name, NODE_WWN_PROP,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(NODE_WWN_PROP));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_type = GFC_PROP_TYPE_BYTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((node_wwn_data = (uchar_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, FC_WWN_SIZE)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_prop_list(&pl_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(node_wwn_data, node_wwn, FC_WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_data = node_wwn_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_size = FC_WWN_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_end->next = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_end = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consrtruct hard addr property. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_ptr = (impl_map_dev_prop_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_prop_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_prop_list(&pl_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(prop_ptr->prop_name, HARD_ADDR_PROP,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(HARD_ADDR_PROP));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_type = GFC_PROP_TYPE_INT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((hard_addr_data = (int *)calloc(1, sizeof (int))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_prop_list(&pl_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *hard_addr_data = hard_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_data = hard_addr_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_end->next = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_end = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*prop_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *prop_list = pl_start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pl_end->next = (*prop_list)->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *prop_list = pl_start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function consturct FCP inq dtype propery.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if inq_dtype is null the property is constrcted with err info.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_MALLOC_FAILED is the only possible error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellupdate_map_dev_FCP_prop(impl_map_dev_prop_t **prop_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t *inq_dtype, int err, int exist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *prop_ptr, *old_prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *inq_dtype_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_ptr = (impl_map_dev_prop_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_prop_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(prop_ptr->prop_name, INQ_DTYPE_PROP,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(INQ_DTYPE_PROP));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (inq_dtype == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_error = err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((inq_dtype_data = (uchar_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (uchar_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(prop_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(inq_dtype_data, inq_dtype, sizeof (uchar_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_data = inq_dtype_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_type = GFC_PROP_TYPE_BYTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->prop_size = sizeof (uchar_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*prop_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *prop_list = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (exist == PROP_EXIST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->next = (*prop_list)->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_prop_ptr = *prop_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *prop_list = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free((uchar_t *)(old_prop_ptr->prop_data));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_prop_ptr->prop_data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(old_prop_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_ptr->next = *prop_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *prop_list = prop_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function calls FCP_TGT_INQUIRY via g_issue_fcp_ioctl()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to get the inq_dtype of input device and calls update_map_dev_FCP_prop().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inq_dtype is set to NULL and pass error code if inq_dtype data is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * requried.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error from update_map_dev_FCP_prop().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellhandle_map_dev_FCP_prop(minor_t fp_xport_minor, la_wwn_t port_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map_dev_prop_t **prop_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct device_data inq_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fcp_fd, err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct fcp_ioctl fcp_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t inq_dtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fcp_fd = g_object_open(FCP_PATH, O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update_map_dev_FCP_prop(prop_list, NULL,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell L_OPEN_PATH_FAIL, PROP_NOEXIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the minor number for an fp instance */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.fp_minor = fp_xport_minor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get FCP prop for the hba first. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.listlen = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq_data.dev_pwwn = port_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcp_data.list = (caddr_t)&inq_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err = g_issue_fcp_ioctl(fcp_fd, &fcp_data, 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if ioctl error then set the prop_error. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_FCP_prop(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell prop_list, NULL, err, PROP_NOEXIST)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell inq_dtype = inq_data.dev0_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_FCP_prop(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell prop_list, &inq_dtype, 0, PROP_NOEXIST)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Construct device map tree from nexus driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PARAMS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * path - must be the physical path to a device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err - ptr to an error code. Set when NULL is returned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - device map fomat and property type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LOGIC:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1. check the validity of path via g_get_path_type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2. If FC path, get the topology of the path via
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_fca_port_topology.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3. If FC type(Leadville statck)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO_GET_DEV_LIST to get the device node list of fc_port_dev_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO_GET_HOST_PARAMS to get the fca port node of fc_port_dev_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * root of tree is set with host_params info
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FC propery is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCP property is set if reqyested through flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue g_issue_fcp_ioctl to get FCP inquiry data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consruruct list of children via dev_list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FC property is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCP property is set if reqyested through flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue FCIO_DEV_LOGIN if it is fabric device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue g_issue_fcp_ioctl to get FCP inquiry data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * else FC4 type(socal/sf or ifp stack)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SFIOCGMAP ioctl to get the device and hba nodes of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sf_addr_pair_t.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO_GETMAP ioctl to get hba port info.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consturct map and child tree list and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set the properties as private loop devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ptr to map is returned if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL and l_err is set otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegfc_dev_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_dev_map_init(char *path, int *l_err, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, i, num_devices = 0, err, pathcnt = 1, new_count = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char drvr_path[MAXPATHLEN], drvr_path0[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *char_ptr, *nexus_path;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat stbuf;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_port_dev_t *dev_list = NULL, *dlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint32_t hba_port_top, state;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint_t path_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_al_map_t sf_map;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_port_dev_t fp_hba_port;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int p_on = 0, p_st = 0, hba_alpa_found = 0, nexus_fd;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio_t fcio;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct lilpmap limited_map;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map_dev_t *impl_map, *impl_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map_dev_t *mdl_start = NULL, *mdl_end = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat sbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_err == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_PATH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the path to the :devctl driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This assumes the path looks something like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0/ses@e,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a 1 level PCI type driver but still :devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(path, SCSI_VHCI)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path0, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(drvr_path0, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_PATH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state < MAXPATHSTATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_st = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[p_on].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on_line path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_on].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* standby or path0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_st].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(drvr_path, DRV_NAME_SSD) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strstr(drvr_path, SES_NAME) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strstr(drvr_path, DRV_NAME_ST)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strrchr(drvr_path, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_PATH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *char_ptr = '\0'; /* Terminate sting */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(drvr_path, &stbuf) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_LSTAT_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_dev_map_init: Geting drive map from:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " %s\n", drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path_type = g_get_path_type(drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((path_type == 0) || !(path_type & XPORT_MASK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_PATH_TYPE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get fiber topology */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_fca_port_topology(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &hba_port_top, 0)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(drvr_path, O_NDELAY | O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* for FC devices. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_type & FC_FCA_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the number of device first. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd = FCIO_GET_NUM_DEVS;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_olen = sizeof (num_devices);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = (caddr_t)&num_devices;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (g_issue_fcio_ioctl(fd, &fcio, 0) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" FCIO_GET_NUM_DEVS ioctl failed.\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_FCIO_GET_NUM_DEVS_FAIL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (num_devices != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_list = (fc_port_dev_t *)calloc(num_devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell bzero((caddr_t)&fcio, sizeof (fcio));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Get the device list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_DEV_LIST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Information read operation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = num_devices * sizeof (fc_port_dev_t);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = (caddr_t)dev_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* new device count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_alen = sizeof (new_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_abuf = (caddr_t)&new_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_issue_fcio_ioctl(fd, &fcio, 0)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (err == L_INVALID_DEVICE_COUNT) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * original buffer was small so allocate
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * buffer with a new count and retry.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell num_devices = new_count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell new_count = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((dev_list = (fc_port_dev_t *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(num_devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd = FCIO_GET_DEV_LIST;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Information read operation */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_xfer = FCIO_XFER_READ;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = (caddr_t)dev_list;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_olen = num_devices *
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* new device count */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_alen = sizeof (new_count);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_abuf = (caddr_t)&new_count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_issue_fcio_ioctl(fd, &fcio,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 0)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (err ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell L_INVALID_DEVICE_COUNT) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * No more retry. There
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * may be severe
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * hardware problem so
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * return error here.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" Device"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " count was %d"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " should have been"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " %d\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell num_devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell new_count);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_INVALID_DEVICE_COUNT;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Code refactorization is needed for C style */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GET_DEV_LIST ioctl failed.");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_FCIO_GET_DEV_LIST_FAIL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if new count is smaller than the original number from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO_GET_NUM_DEVS, adjust new count and buffer size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and continue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (new_count < num_devices) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell num_devices = new_count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (new_count > 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((dev_list = (fc_port_dev_t *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell realloc(dev_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (new_count * sizeof (fc_port_dev_t))))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the host param info */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) memset(&fp_hba_port, 0, sizeof (struct fc_port_dev));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd = FCIO_GET_HOST_PARAMS;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_xfer = FCIO_XFER_READ;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = (caddr_t)&fp_hba_port;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_olen = sizeof (fc_port_dev_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (g_issue_fcio_ioctl(fd, &fcio, 0) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" FCIO_GET_HOST_PARAMS ioctl failed.\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (num_devices == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_NO_DEVICES_FOUND;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_FCIO_GET_HOST_PARAMS_FAIL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If we want the lilp map then we need to do a little */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* work here. The lilp map contains the local hba in */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the dev_addr. Once this has been added qsort the */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* dev_addr array so it's in physical order. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((flag & MAP_FORMAT_LILP) == MAP_FORMAT_LILP) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* First we need to allocate one additional */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* device to the dev_addr structure, for the */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* local hba */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (num_devices > 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((dev_list = (fc_port_dev_t *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell realloc(dev_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (++num_devices *
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t)))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * In case dev_list is not null free
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * it.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Next, copy the local hba into this new
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * loc.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (memcpy(dev_list+(num_devices-1),
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &fp_hba_port,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t)) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MEMCPY_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Now sort by physical location */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell qsort((void*)dev_list, num_devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fc_port_dev_t), lilp_map_cmp);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We have dev list info and host param info. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now constructs map tree with these info. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* First consturct the root of the map tree */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* with host param. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((impl_map = (impl_map_dev_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map->flag = flag;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map->topo = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consturct hba property list. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_fc_prop(&impl_map->prop_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hba_port_top, fp_hba_port.dev_pwwn.raw_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_hba_port.dev_nwwn.raw_wwn, fp_hba_port.dev_did.port_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_hba_port.dev_hard_addr.hard_addr)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flag & MAP_XPORT_PROP_ONLY) != MAP_XPORT_PROP_ONLY) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (fstat(fd, &sbuf) == -1) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_FSTAT_ERROR;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = handle_map_dev_FCP_prop(minor(sbuf.st_rdev),
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fp_hba_port.dev_pwwn, &impl_map->prop_list)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(impl_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* consturct child for each device and */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* set device property list. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dlist = dev_list;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell for (i = 0; i < num_devices; i++, dlist++) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((impl_dev = (impl_map_dev_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* set the map as parent */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_dev->parent = impl_map;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_fc_prop(&impl_dev->prop_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell hba_port_top, dlist->dev_pwwn.raw_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dlist->dev_nwwn.raw_wwn, dlist->dev_did.port_id,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dlist->dev_hard_addr.hard_addr)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (i == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mdl_start = mdl_end = impl_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mdl_end->next = impl_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mdl_end = impl_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((flag & MAP_XPORT_PROP_ONLY) !=
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MAP_XPORT_PROP_ONLY) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (((hba_port_top == FC_TOP_PUBLIC_LOOP) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (hba_port_top == FC_TOP_FABRIC)) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (memcmp(fp_hba_port.dev_pwwn.raw_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dlist->dev_pwwn.raw_wwn, FC_WWN_SIZE) != 0)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) memset(&fcio, 0, sizeof (fcio_t));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd = FCIO_GET_STATE;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_ilen = sizeof (dlist->dev_pwwn);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_ibuf = (caddr_t)&dlist->dev_pwwn;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_xfer = FCIO_XFER_READ |
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell FCIO_XFER_WRITE;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_olen = sizeof (uint32_t);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = (caddr_t)&state;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_alen = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_abuf = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (g_issue_fcio_ioctl(fd, &fcio, 0) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " FCIO_GET_STATE ioctl failed.\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_FCP_prop(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &impl_dev->prop_list, NULL,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell L_FCIO_GET_STATE_FAIL,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell PROP_NOEXIST)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (state != PORT_DEVICE_LOGGED_IN) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((fd = g_object_open(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell O_NDELAY | O_RDONLY | O_EXCL)) ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell -1) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_OPEN_PATH_FAIL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) memset(&fcio, 0,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (fcio_t));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd = FCIO_DEV_LOGIN;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_ilen =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (dlist->dev_pwwn);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_ibuf =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (caddr_t)&dlist->dev_pwwn;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_xfer = FCIO_XFER_WRITE;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_olen = fcio.fcio_alen = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = fcio.fcio_abuf = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (g_issue_fcio_ioctl(fd, &fcio, 0) !=
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Code refactorization is needed for C style */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_DEV_LOGIN ioctl failed.\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = update_map_dev_FCP_prop(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &impl_dev->prop_list, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte L_FCIO_DEV_LOGIN_FAIL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PROP_NOEXIST)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * plogi failed continue
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * to next dev
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell continue;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* sbuf should be set from hba_port handling. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = handle_map_dev_FCP_prop(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell minor(sbuf.st_rdev),
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dlist->dev_pwwn, &impl_dev->prop_list)) !=
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) free(dev_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* connect the children to to map. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map->child = mdl_start;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(dev_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* sf and fc4/pci devices */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* initialize map */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) memset(&sf_map, 0, sizeof (struct sf_al_map));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (ioctl(fd, SFIOCGMAP, &sf_map) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" SFIOCGMAP ioctl failed.\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_SFIOCGMAP_IOCTL_FAIL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for reasonableness. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((sf_map.sf_count > 126) || (sf_map.sf_count < 0)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_INVALID_LOOP_MAP;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (sf_map.sf_count == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_NO_DEVICES_FOUND;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_get_nexus_path(drvr_path, &nexus_path)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((nexus_fd =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_object_open(nexus_path, O_NDELAY | O_RDONLY)) == -1) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(nexus_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = errno;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get limited map to get hba param info */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (ioctl(nexus_fd, FCIO_GETMAP, &limited_map) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" FCIO_GETMAP ioctl failed\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(nexus_fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(nexus_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_FCIO_GETMAP_IOCTL_FAIL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(nexus_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(nexus_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell for (i = 0; i < sf_map.sf_count; i++) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (sf_map.sf_addr_pair[i].sf_al_pa ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell limited_map.lilp_myalpa) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_map.sf_hba_addr = sf_map.sf_addr_pair[i];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell hba_alpa_found = 1;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (!(hba_alpa_found)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_INVALID_LOOP_MAP;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We have dev list info and host param info. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now constructs map tree with these info. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* First consturct the root of the map tree */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* with host param. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((impl_map = (impl_map_dev_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map->flag = flag;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map->topo = hba_port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consturct hba property list. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_fc_prop(&impl_map->prop_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hba_port_top, sf_map.sf_hba_addr.sf_port_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sf_map.sf_hba_addr.sf_node_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (int)sf_map.sf_hba_addr.sf_al_pa,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (int)sf_map.sf_hba_addr.sf_hard_address)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(impl_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((flag & MAP_XPORT_PROP_ONLY) != MAP_XPORT_PROP_ONLY) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_FCP_prop(&impl_map->prop_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &sf_map.sf_hba_addr.sf_inq_dtype, 0,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell PROP_NOEXIST)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell for (i = 0; i < sf_map.sf_count; i++) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((impl_dev = (impl_map_dev_t *)calloc(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 1, sizeof (impl_map_dev_t))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = L_MALLOC_FAILED;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* set the map as parent */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_dev->parent = impl_map;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_fc_prop(&impl_dev->prop_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell hba_port_top, sf_map.sf_addr_pair[i].sf_port_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_map.sf_addr_pair[i].sf_node_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (int)(sf_map.sf_addr_pair[i].sf_al_pa),
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (int)(sf_map.sf_addr_pair[i].sf_hard_address))) !=
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (i == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mdl_start = mdl_end = impl_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mdl_end->next = impl_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mdl_end = impl_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((flag & MAP_XPORT_PROP_ONLY) !=
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MAP_XPORT_PROP_ONLY) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = update_map_dev_FCP_prop(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &impl_dev->prop_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &sf_map.sf_addr_pair[i].sf_inq_dtype, 0,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell PROP_NOEXIST)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(impl_map);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *l_err = err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (NULL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } /* end of for loop */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_map->child = mdl_start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* end of else */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((gfc_dev_t)(impl_map));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function deallocates memory for propery list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefree_prop_list(impl_map_dev_prop_t **prop_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *lp, *olp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lp = *prop_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (lp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (lp->prop_type) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case GFC_PROP_TYPE_BYTES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free((uchar_t *)(lp->prop_data));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case GFC_PROP_TYPE_INT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free((int *)(lp->prop_data));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case GFC_PROP_TYPE_STRING:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free((char *)(lp->prop_data));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lp->prop_data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte olp = lp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lp = olp->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(olp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *prop_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function deallocates memory for children list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefree_child_list(impl_map_dev_t **dev_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *lp, *olp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lp = *dev_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (lp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_prop_list(&lp->prop_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte olp = lp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lp = olp->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(olp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dev_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function deallocates memory for the whole map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_dev_map_fini(gfc_dev_t map)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map = (impl_map_dev_t *)map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_map != NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free_prop_list(&impl_map->prop_list);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free_child_list(&impl_map->child);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(impl_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function passes back topology of the input map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * input should be a handle form g_dev_map_init().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_map_topology(gfc_dev_t map, uint_t *topology)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_MAP_DEV_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (topology == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map = (impl_map_dev_t *)map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *topology = impl_map->topo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the first device handle of the input map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map input should be a handle form g_dev_map_init().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegfc_dev_t
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_first_dev(gfc_dev_t map, int *l_err)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_err == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_MAP_DEV_ADDR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map = (impl_map_dev_t *)map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_map->child == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_NO_SUCH_DEV_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((gfc_dev_t)(impl_map->child));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the next device handle of the input map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_dev input should be a handle for device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegfc_dev_t
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_next_dev(gfc_dev_t map_dev, int *l_err)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_err == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_dev == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_MAP_DEV_ADDR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_dev = (impl_map_dev_t *)map_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_dev->next == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_NO_SUCH_DEV_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((gfc_dev_t)(impl_dev->next));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function passes back uchar_t type property and its count.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_dev input should be a handle for device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_dev_prop_lookup_bytes(gfc_dev_t map_dev, const char *prop_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int *prop_data_count, uchar_t **prop_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_dev == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_MAP_DEV_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_name == NULL) || (prop_data == NULL) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (prop_data_count == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_dev = (impl_map_dev_t *)map_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = impl_dev->prop_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = L_INVALID_MAP_DEV_PROP_NAME;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (impl_prop) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (strncmp(impl_prop->prop_name, prop_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(prop_name)) == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (impl_prop->prop_type != GFC_PROP_TYPE_BYTES) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell err = L_INVALID_MAP_DEV_PROP_TYPE;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell break;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (impl_prop->prop_data) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data = (uchar_t *)(impl_prop->prop_data);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data_count = impl_prop->prop_size;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (0);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell err = impl_prop->prop_error;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_prop = impl_prop->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function passes back int type property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_dev input should be a handle for device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_dev_prop_lookup_ints(gfc_dev_t map_dev, const char *prop_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int **prop_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_dev == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_MAP_DEV_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_name == NULL) || (prop_data == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_dev = (impl_map_dev_t *)map_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = impl_dev->prop_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = L_INVALID_MAP_DEV_PROP_NAME;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (impl_prop) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (strncmp(impl_prop->prop_name, prop_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(prop_name)) == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (impl_prop->prop_type != GFC_PROP_TYPE_INT) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell err = L_INVALID_MAP_DEV_PROP_TYPE;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell break;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (impl_prop->prop_data) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data = (int *)(impl_prop->prop_data);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (0);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell err = impl_prop->prop_error;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_prop = impl_prop->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function passes back int type property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_dev input should be a handle for device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_dev_prop_lookup_strings(gfc_dev_t map_dev, const char *prop_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char **prop_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_dev == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_MAP_DEV_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_name == NULL) || (prop_data == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_dev = (impl_map_dev_t *)map_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = impl_dev->prop_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = L_INVALID_MAP_DEV_PROP_NAME;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (impl_prop) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (strncmp(impl_prop->prop_name, prop_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(prop_name)) == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (impl_prop->prop_type != GFC_PROP_TYPE_STRING) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell err = L_INVALID_MAP_DEV_PROP_TYPE;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell break;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (impl_prop->prop_data) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data = (char *)(impl_prop->prop_data);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (0);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell err = impl_prop->prop_error;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell impl_prop = impl_prop->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the handle for the first property of the input device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_dev input should be a handle form a device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegfc_prop_t
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_first_dev_prop(gfc_dev_t map_dev, int *l_err)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_t *impl_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_err == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_dev == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_MAP_DEV_ADDR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_dev = (impl_map_dev_t *)map_dev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_dev->prop_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_NO_SUCH_PROP_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((gfc_prop_t)(impl_dev->prop_list));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the handle for next property handle of the input prop.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_prop input should be a handle for property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * l_err set to error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegfc_prop_t
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_next_dev_prop(gfc_prop_t map_prop, int *l_err)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_err == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_prop == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_MAP_DEV_PROP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = (impl_map_dev_prop_t *)map_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_prop->next == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_NO_SUCH_PROP_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((gfc_prop_t)(impl_prop->next));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the name of the property of the input prop.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_prop input should be a handle for property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return name string if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns NULL and l_err set to error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_dev_prop_name(gfc_prop_t map_prop, int *l_err)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_err == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_prop == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_MAP_DEV_PROP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = (impl_map_dev_prop_t *)map_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (impl_prop->prop_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function returns the type of the property of the input prop.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_prop input should be a handle for property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return type if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns GFC_PROP_TYPE_UNKNOWN and l_err set to error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_dev_prop_type(gfc_prop_t map_prop, int *l_err)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_err != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_prop == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_err = L_INVALID_MAP_DEV_PROP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (GFC_PROP_TYPE_UNKNOWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = (impl_map_dev_prop_t *)map_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (impl_prop->prop_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function passes back uchar_t type property and its count.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_prop input should be a handle for property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_dev_prop_bytes(gfc_prop_t map_prop, int *prop_data_count,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t **prop_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_prop == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_MAP_DEV_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prop_data == NULL) || (prop_data_count == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = (impl_map_dev_prop_t *)map_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_prop->prop_type != GFC_PROP_TYPE_BYTES) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_INVALID_MAP_DEV_PROP_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_prop->prop_data) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data = (uchar_t *)(impl_prop->prop_data);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data_count = impl_prop->prop_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (impl_prop->prop_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function passes back int type property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_prop input should be a handle for property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_dev_prop_ints(gfc_prop_t map_prop, int **prop_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_prop == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_MAP_DEV_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop_data == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = (impl_map_dev_prop_t *)map_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_prop->prop_type != GFC_PROP_TYPE_INT) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_INVALID_MAP_DEV_PROP_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_prop->prop_data) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data = (int *)(impl_prop->prop_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (impl_prop->prop_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function passes back string type property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map_prop input should be a handle for property.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return error code otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrellg_get_dev_prop_strings(gfc_prop_t map_prop, char **prop_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_map_dev_prop_t *impl_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map_prop == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_MAP_DEV_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop_data == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte impl_prop = (impl_map_dev_prop_t *)map_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_prop->prop_type != GFC_PROP_TYPE_STRING) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_INVALID_MAP_DEV_PROP_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (impl_prop->prop_data) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *prop_data = (char *)(impl_prop->prop_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (impl_prop->prop_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free the linked list allocated by g_rdls()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_free_rls(AL_rls *rlsptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AL_rls *trlsptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rlsptr != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trlsptr = rlsptr->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(rlsptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rlsptr = trlsptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Read the extended link error status block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from the specified device and Host Adapter.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PARAMS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * path_phys - physical path to an FC device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rls_ptr - pointer to read link state structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 : if OK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero: otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_rdls(char *path_phys, struct al_rls **rls_ptr, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char nexus_path[MAXPATHLEN], *nexus_path_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, fp_fd, err, length, exp_map_flag = 0, *port_addr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct lilpmap map;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell AL_rls *rls, *c1 = NULL, *c2 = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t i, *port_wwn_byte;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell la_wwn_t port_wwn;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sf_al_map_t exp_map;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *charPtr, fp_path[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint_t dev_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat stbuf;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio_t fcio;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_portid_t rls_req;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_rls_acc_t rls_payload;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell gfc_dev_t map_root, map_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint32_t hba_port_top, state;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int pathcnt = 1, count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int p_on = 0, p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if path_phys is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_phys == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if rls_ptr is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rls_ptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rls_ptr = rls = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(path_phys, SCSI_VHCI) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(fp_path, path_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(fp_path, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state < MAXPATHSTATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_st = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[p_on].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on_line path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(fp_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_on].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* standby or path0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(fp_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_st].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(fp_path, path_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get map of devices on this loop. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type = g_get_path_type(fp_path)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_type & FC_FCA_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(path_phys, SCSI_VHCI) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(fp_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strstr(fp_path, DRV_NAME_SSD) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strstr(fp_path, DRV_NAME_ST) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strstr(fp_path, SES_NAME)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((charPtr = strrchr(fp_path, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *charPtr = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append devctl to the path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(fp_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(fp_path, &stbuf) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append devctl to the path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(fp_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map_root = g_dev_map_init(fp_path, &err,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MAP_XPORT_PROP_ONLY)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* FC4_FCA_MASK type path */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) memset(&map, 0, sizeof (struct lilpmap));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_get_nexus_path(path_phys,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &nexus_path_ptr)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) strcpy(nexus_path, nexus_path_ptr);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_destroy_data(nexus_path_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open driver */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((fd = g_object_open(nexus_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell O_NDELAY | O_RDONLY)) == -1)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First try using the socal version of the map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If that fails get the expanded vesion.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (ioctl(fd, FCIO_GETMAP, &map) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" FCIO_GETMAP ioctl failed.\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (ioctl(fd, SFIOCGMAP, &exp_map) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" SFIOCGMAP ioctl failed.\n");
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_SFIOCGMAP_IOCTL_FAIL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Check for reasonableness. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((exp_map.sf_count > 126) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (exp_map.sf_count < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_LOOP_MAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell for (i = 0; i < exp_map.sf_count; i++) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (exp_map.sf_addr_pair[i].sf_al_pa > 0xef) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_INVALID_LOOP_MAP);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell length = exp_map.sf_count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell exp_map_flag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" g_rdls:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " FCIO_GETMAP ioctl returned %d entries.\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell map.lilp_length);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Check for reasonableness. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (map.lilp_length > sizeof (map.lilp_list)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_FCIOGETMAP_INVLD_LEN);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell length = map.lilp_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell for (i = 0; i < length; i++) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((c2 = (struct al_rls *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_zalloc(sizeof (struct al_rls))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (rls == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1 = rls = c2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell for (c1 = rls; c1->next; c1 = c1->next) {};
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1 = c1->next = c2;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) strcpy(c1->driver_path, nexus_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (exp_map_flag) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_portno = c1->al_ha =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell exp_map.sf_addr_pair[i].sf_al_pa;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_portno = c1->al_ha =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell map.lilp_list[i];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_linkfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (uint_t)0xff000000; /* get LESB for this port */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" g_rdls:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " al_pa 0x%x\n", c1->payload.rls_portno);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (ioctl(fd, FCIO_LINKSTATUS, &c1->payload) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * The ifp driver will return ENXIO when rls
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * is issued for same initiator on loop when
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * there is more than one on the loop.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Rather than completely fail, continue on.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Set values in the payload struct to -1 as
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * this is what socal is currently doing for
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * the case of same initiator rls.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((dev_type & FC4_PCI_FCA) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (errno == ENXIO)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_linkfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_syncfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_sigfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_primitiverr =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidword =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidcrc =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (uint_t)0xffffffff;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" FCIO_LINKSTATUS ioctl"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " failed with errno %d.\n", errno);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_rls(rls);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_FCIO_LINKSTATUS_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell I_DPRINTF(" g_rdls: al_pa returned by ioctl 0x%x\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_portno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *rls_ptr = rls; /* Pass back pointer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now we need to take care of FC_FCA_MASK case. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we have map created already via g_dev_map_init. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_map_topology(map_root, &hba_port_top)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map_dev = g_get_first_dev(map_root, &err)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != L_NO_SUCH_DEV_FOUND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (map_dev) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_dev_prop_lookup_ints(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell map_dev, PORT_ADDR_PROP, &port_addr)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(map_root);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_rls(rls);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((c2 = (struct al_rls *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_zalloc(sizeof (struct al_rls))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(map_root);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_rls(rls);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell close(fd);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (rls == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1 = rls = c2;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell for (c1 = rls; c1->next; c1 = c1->next) {};
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1 = c1->next = c2;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Set the al_ha here */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->al_ha = rls_req.port_id = *port_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fp uses different input/output structures for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rls. Load the values returned for the fp ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * into the structure passed back to the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: There is no reason for the path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to be loaded into AL_rls as is done for socal/ifp
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((hba_port_top == FC_TOP_FABRIC) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (hba_port_top == FC_TOP_PUBLIC_LOOP)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_dev_prop_lookup_bytes(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell map_dev, PORT_WWN_PROP, &count,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &port_wwn_byte)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(map_root);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_rls(rls);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell memcpy(port_wwn.raw_wwn, port_wwn_byte, FC_WWN_SIZE);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_get_dev_port_state(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fp_path, port_wwn, &state)) == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (state != PORT_DEVICE_LOGGED_IN) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = g_dev_login(fp_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell port_wwn)) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_linkfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_syncfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_sigfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_primitiverr =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidword =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidcrc =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (uint_t)0xffffffff;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (((map_dev =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_get_next_dev(map_dev,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &err))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell == NULL) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (err !=
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell L_NO_SUCH_DEV_FOUND)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell map_root);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_rls(rls);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell continue;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } /* if g_get_dev_port_state fails proceed. */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd_flags = FCIO_CFLAGS_RLS_DEST_NPORT;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((fp_fd = g_object_open(fp_path, O_RDONLY | O_EXCL)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_rls(rls);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_OPEN_PATH_FAIL);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_cmd = FCIO_LINK_STATUS;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_ibuf = (caddr_t)&rls_req;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_ilen = sizeof (rls_req);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_xfer = FCIO_XFER_RW;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_flags = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_obuf = (caddr_t)&rls_payload;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio.fcio_olen = sizeof (rls_payload);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (g_issue_fcio_ioctl(fp_fd, &fcio, verbose) != 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_linkfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_syncfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_sigfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_primitiverr =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidword =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidcrc = (uint_t)0xffffffff;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Load the values into the struct passed
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * back to the caller
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_linkfail = rls_payload.rls_link_fail;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_syncfail = rls_payload.rls_sync_loss;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_sigfail = rls_payload.rls_sig_loss;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_primitiverr =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell rls_payload.rls_prim_seq_err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidword =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell rls_payload.rls_invalid_word;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidcrc =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell rls_payload.rls_invalid_crc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (void) close(fp_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (((map_dev = g_get_next_dev(map_dev, &err)) == NULL) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (err != L_NO_SUCH_DEV_FOUND)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_dev_map_fini(map_root);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_free_rls(rls);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* for Leadville issue a final call for the initiator */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_dev_prop_lookup_ints(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell map_root, PORT_ADDR_PROP, &port_addr)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_rls(rls);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((c2 = (struct al_rls *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_zalloc(sizeof (struct al_rls))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_rls(rls);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rls == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1 = rls = c2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (c1 = rls; c1->next; c1 = c1->next) {};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1 = c1->next = c2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->al_ha = rls_req.port_id = *port_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fp_fd = g_object_open(fp_path, O_RDONLY | O_EXCL)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_rls(rls);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_LINK_STATUS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&rls_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (rls_req);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_RW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd_flags = FCIO_CFLAGS_RLS_DEST_NPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&rls_payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (rls_payload);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_issue_fcio_ioctl(fp_fd, &fcio, verbose) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->payload.rls_linkfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_syncfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_sigfail =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_primitiverr =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidword =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell c1->payload.rls_invalidcrc = (uint_t)0xffffffff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Load the values into the struct passed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * back to the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->payload.rls_linkfail = rls_payload.rls_link_fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->payload.rls_syncfail = rls_payload.rls_sync_loss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->payload.rls_sigfail = rls_payload.rls_sig_loss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->payload.rls_primitiverr = rls_payload.rls_prim_seq_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->payload.rls_invalidword = rls_payload.rls_invalid_word;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1->payload.rls_invalidcrc = rls_payload.rls_invalid_crc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fp_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fp_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rls_ptr = rls; /* Pass back pointer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic u_longlong_t wwnConversion(uchar_t *wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte u_longlong_t tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&tmp, wwn, sizeof (u_longlong_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get device World Wide Name (port and node) for device at path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and add all WWNs to the wwn_list_found list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN: 0 O.K.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INPUTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - path_phys must be of a device, either an IB or disk.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_wwns(char *path_phys, uchar_t port_wwn[], uchar_t node_wwn[], int *al_pa,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_found_struct **wwn_list_found)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint32_t hba_port_top;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int i, err, count;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *char_ptr, *ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int found = 0, pathcnt, *port_addr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell unsigned long long pwwn;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t *port_wwn_byte, *node_wwn_byte;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char drvr_path[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int p_on = 0, p_st = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char pwwn1[WWN_S_LEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell gfc_dev_t map_root, map_dev;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell hrtime_t start_time, end_time;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *env = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_wwn: Getting device WWN"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " and al_pa for device: %s\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell path_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((env = getenv("_LUX_T_DEBUG")) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the loop identifier (switch setting) from the path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This assumes the path looks something like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/.../SUNW,socal@3,0/SUNW,sf@0,0/SUNW,ssd@x,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/.../SUNW,qlc@5/SUNW,fp@0,0/SUNW,ssd@x,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strrchr(path_phys, '@')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVLD_PATH_NO_ATSIGN_FND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char_ptr++; /* point to the loop identifier or WWN */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This function allocs mem for map.dev_addr on success */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(drvr_path, SCSI_VHCI)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(drvr_path, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state < MAXPATHSTATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_st = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p_on == i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on_line path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_on].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(pwwn1,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_on].path_addr,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_S_LEN - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pwwn1[WWN_S_LEN - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* standby or path0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_st].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(pwwn1,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_st].path_addr,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_S_LEN - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pwwn1[WWN_S_LEN - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map_root = g_dev_map_init(drvr_path, &err,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MAP_XPORT_PROP_ONLY)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_map_topology(map_root, &hba_port_top)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(path_phys, SCSI_VHCI)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char_ptr = pwwn1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Format of WWN is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ssd@w2200002037000f96,0:a,raw
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*char_ptr != 'w') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVLD_WWN_FORMAT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char_ptr++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pwwn = strtoull(char_ptr, &ptr, 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ptr == char_ptr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_WWN_FOUND_IN_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_wwn: Looking for WWN "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "0x%llx\n", pwwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((map_dev = g_get_first_dev(map_root, &err)) == NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (err != L_NO_SUCH_DEV_FOUND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (map_dev) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_dev_prop_lookup_bytes(map_dev,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell PORT_WWN_PROP, &count, &port_wwn_byte)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_dev_prop_lookup_bytes(map_dev,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell NODE_WWN_PROP, &count, &node_wwn_byte)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pwwn == wwnConversion(port_wwn_byte) && found != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(port_wwn, port_wwn_byte, FC_WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(node_wwn, node_wwn_byte, FC_WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_dev_prop_lookup_ints(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell map_dev, PORT_ADDR_PROP, &port_addr)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *al_pa = *port_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte add_wwn_entry(wwn_list_found, port_wwn_byte,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_wwn_byte);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((map_dev = g_get_next_dev(map_dev, &err)) == NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (err != L_NO_SUCH_DEV_FOUND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_LOOP_ADDRS_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, " get_wwns: "
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "\t\tTime = %lld millisec\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (end_time - start_time)/1000000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get device World Wide Name and AL_PA for device at path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN: 0 O.K.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INPUTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - path_phys must be of a device, either an IB or disk.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_wwn(char *path_phys, uchar_t port_wwn[], uchar_t node_wwn[],
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int *al_pa, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_found_struct *wwn_list_found = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if the argument is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_phys == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if the argument is NULL */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((port_wwn == NULL) || (node_wwn == NULL) || (al_pa == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = get_wwns(path_phys, port_wwn, node_wwn, al_pa, &wwn_list_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list_found(&wwn_list_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_serial_number(char *path, uchar_t *serial_number,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t *serial_number_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, status = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell L_inquiry80 inq80;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if path is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if serial_number is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (serial_number == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_serial_number: path: %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(path, O_NDELAY | O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Call the inquiry cmd on page 0x80 only if the vendor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * supports page 0x80.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((g_find_supported_inq_page(fd, 0x80))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Let's retrieve the serial number from page 0x80
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and store it in the inquiry structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = g_scsi_inquiry_cmd80(fd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)&inq80,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct l_inquiry80_struct));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*serial_number_len > inq80.inq_page_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *serial_number_len = inq80.inq_page_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy((char *)serial_number, (char *)inq80.inq_serial,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *serial_number_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char unavail[] = "Unavailable";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*serial_number_len > strlen(unavail))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *serial_number_len = strlen(unavail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy((char *)serial_number, unavail,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *serial_number_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * page 0x80 is not supported, so print the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * appropriate message.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char unsupp[] = "Unsupported";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*serial_number_len > strlen(unsupp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *serial_number_len = strlen(unsupp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy((char *)serial_number, unsupp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *serial_number_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_inquiry(char *path, L_inquiry *l_inquiry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if path is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if l_inquiry is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (l_inquiry == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_inquiry: path: %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = g_scsi_inquiry_cmd(fd,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (uchar_t *)l_inquiry, sizeof (struct l_inquiry_struct));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Function to retrieve inquiry page 0x80 from the device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_scsi_inquiry_cmd80(int fd, uchar_t *buf_ptr, int buf_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct uscsi_cmd ucmd;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_cdb_g0 cdb = {SCMD_INQUIRY, 0x1, 0x80, 0, 0x10, 0};
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct scsi_extended_sense sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset(buf_ptr, 0, buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&ucmd, 0, sizeof (ucmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb.count = (uchar_t)buf_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (caddr_t)&cdb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = buf_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqbuf = (caddr_t)&sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = 60;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cmd(fd, &ucmd, USCSI_READ | USCSI_SILENT));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Function to determine if the given page is supported by vendor.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_find_supported_inq_page(int fd, int page_num)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct uscsi_cmd ucmd;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_cdb_g0 cdb = {SCMD_INQUIRY, 0x1, 0, 0, 0xff, 0};
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct scsi_extended_sense sense;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell L_inquiry00 inq00;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t *data;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int status = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&ucmd, 0, sizeof (ucmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb.count = (uchar_t)(sizeof (L_inquiry00));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (caddr_t)&cdb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = (caddr_t)&inq00;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = sizeof (inq00);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqbuf = (caddr_t)&sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = 60;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = cmd(fd, &ucmd, USCSI_READ | USCSI_SILENT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = (uchar_t *)&inq00;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 4; (index <= inq00.len+3)&&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (data[index] <= page_num); index ++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (data[index] == page_num) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_perf_statistics(char *path, uchar_t *perf_ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_perf_statistics: Get Performance Statistics:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "\n Path:%s\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize tables */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset(perf_ptr, 0, sizeof (int));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update parameters in the performance table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the period in seconds */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_start(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int status;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_start: Start: Path %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = g_scsi_start_cmd(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_stop(char *path, int immediate_flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int status, fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_stop: Stop: Path %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = g_scsi_stop_cmd(fd, immediate_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_reserve(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_reserve: Reserve: Path %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = g_scsi_reserve_cmd(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_release(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_release: Release: Path %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = g_scsi_release_cmd(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortectoi(char c)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((c >= '0') && (c <= '9'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c -= '0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((c >= 'A') && (c <= 'F'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = c - 'A' + 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((c >= 'a') && (c <= 'f'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = c - 'a' + 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (c);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_string_to_wwn(uchar_t *wwn, uchar_t *wwnp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char c, c1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwnp++ = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwnp++ = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < WWN_SIZE - 2; i++, wwnp++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = ctoi(*wwn++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1 = ctoi(*wwn++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (c == -1 || c1 == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwnp = ((c << 4) + c1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Converts a string of WWN ASCII characters to a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * binary representation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input: string - pointer to uchar_t array
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * WWN in ASCII
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * length: 16 bytes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Output: wwn - pointer to uchar_t array
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * containing WWN result
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * length: 8 bytes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * zero on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestring_to_wwn(uchar_t *string, uchar_t *wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char c, c1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *wwnp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnp = wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < WWN_SIZE; i++, wwnp++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = ctoi(*string++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1 = ctoi(*string++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (c == -1 || c1 == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwnp = ((c << 4) + c1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get multiple paths to a given device port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INPUTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port WWN string.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_port_multipath(char *port_wwn_s, struct dlist **dlh, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_list *wwn_list, *wwn_list_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct dlist *dlt, *dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialize list structures. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl = *dlh = dlt = (struct dlist *)NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = wwn_list_ptr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte H_DPRINTF(" g_get_port_multipath: Looking for multiple paths for"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " device with\n port WWW:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "%s\n", port_wwn_s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err = g_get_wwn_list(&wwn_list, verbose)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list_ptr = wwn_list; wwn_list_ptr != NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr = wwn_list_ptr->wwn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(port_wwn_s, wwn_list_ptr->port_wwn_s) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dl = (struct dlist *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_zalloc(sizeof (struct dlist))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*dlh != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl = (*dlh)->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data(*dlh);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dlh = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_free_wwn_list(&wwn_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte H_DPRINTF(" g_get_port_multipath:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " Found multipath:\n %s\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl->dev_path = strdup(wwn_list_ptr->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl->logical_path = strdup(wwn_list_ptr->logical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*dlh == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dlh = dlt = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlt->next = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl->prev = dlt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlt = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_free_wwn_list(&wwn_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get multiple paths to a given disk/tape device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The arg: devpath should be the physical path to device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OUTPUT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multipath_list points to a list of multiple paths to the device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: The caller must free the allocated list (dlist).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if O.K.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_multipath(char *devpath, struct dlist **multipath_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_struct *wwn_list, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte H_DPRINTF(" g_get_multipath: Looking for multiple paths for"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " device at path: %s\n", devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if devpath is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devpath == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if argument is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((multipath_list == NULL) || (wwn_list == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(devpath, DRV_NAME_SSD) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = get_multipath_disk(devpath, multipath_list, wwn_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = get_multipath(devpath, multipath_list, wwn_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns multipath information for a ssd device.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Inputs:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devpath: device path to for requested multipath info
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_list: returned from g_get_wwn_list or devices_get_all
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Output:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multipath_list: dlist list of paths
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_multipath_disk(char *devpath, struct dlist **multipath_list,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_struct *wwn_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_list *wwn_list_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct dlist *dl = NULL, *dlt = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell ddi_devid_t devid = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell di_node_t root;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct mplist_struct *mplistp = NULL, *mplisth = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list == NULL || multipath_list == NULL || devpath == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NULL_WWN_LIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((root = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_DEV_SNAPSHOT_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_devid_get(devpath, &devid, root, SSD_DRVR_NAME)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *multipath_list = (struct dlist *)NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = devid_get_all(devid, root, SSD_DRVR_NAME, &mplisth)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mplisth == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NULL_WWN_LIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list_ptr = wwn_list; wwn_list_ptr != NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr = wwn_list_ptr->wwn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When a path is found from the list, load the logical
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and physical dev path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (mplistp = mplisth; mplistp != NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mplistp = mplistp->next) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (strncmp(mplistp->devpath,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr->physical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(mplistp->devpath)) == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Load multipath list */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((dl = (struct dlist *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1, sizeof (struct dlist))) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell while (*multipath_list != NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dl = dlt->next;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_destroy_data(dlt);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dlt = dl;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell di_fini(root);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell H_DPRINTF(
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " g_get_multipath: Found multipath=%s\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr->physical_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dl->logical_path =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strdup(wwn_list_ptr->logical_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dl->dev_path =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strdup(wwn_list_ptr->physical_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (*multipath_list == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *multipath_list = dlt = dl;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dlt->next = dl;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dl->prev = dlt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlt = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mplist_free(mplisth);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_multipath(char *devpath, struct dlist **multipath_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct wwn_list_struct *wwn_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_list *wwn_list_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct dlist *dl, *dlt;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char path[MAXPATHLEN], m_phys_path[MAXPATHLEN], *ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int len;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int lun_a = -1;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char node_wwn_s[WWN_S_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devpath == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Strip partition information. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ptr = strrchr(devpath, ':')) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = strlen(devpath) - strlen(ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(path, devpath, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path[len] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(path, devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *multipath_list = dl = dlt = (struct dlist *)NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NULL_WWN_LIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (*node_wwn_s = NULL, wwn_list_ptr = wwn_list;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr != NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr = wwn_list_ptr->wwn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ptr = strrchr(wwn_list_ptr->physical_path, ':')) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = strlen(wwn_list_ptr->physical_path) - strlen(ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(m_phys_path, wwn_list_ptr->physical_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte m_phys_path[len] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(m_phys_path, wwn_list_ptr->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcasecmp(m_phys_path, path) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(node_wwn_s, wwn_list_ptr->node_wwn_s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*node_wwn_s == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte H_DPRINTF("node_wwn_s is NULL!\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_NODE_WWN_IN_WWNLIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_a = g_get_lun_number(wwn_list_ptr->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list_ptr = wwn_list; wwn_list_ptr != NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr = wwn_list_ptr->wwn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(node_wwn_s, wwn_list_ptr->node_wwn_s) == 0) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell ((lun_a < 0) || (lun_a ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_get_lun_number(wwn_list_ptr->physical_path)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dl = (struct dlist *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell g_zalloc(sizeof (struct dlist))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*multipath_list != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl = dlt->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data(dlt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlt = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte H_DPRINTF(" g_get_multipath: Found multipath=%s\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl->dev_path = strdup(wwn_list_ptr->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl->logical_path = strdup(wwn_list_ptr->logical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*multipath_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *multipath_list = dlt = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlt->next = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl->prev = dlt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlt = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free a multipath list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_free_multipath(struct dlist *dlh)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct dlist *dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (dlh != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dl = dlh->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dlh->dev_path != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data(dlh->dev_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dlh->logical_path != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data(dlh->logical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) g_destroy_data(dlh);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlh = dl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the path to the nexus (HBA) driver.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This assumes the path looks something like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0/ses@e,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or maybe this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@1,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0:1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (or "qlc" instead of "socal" and "fp" for "sf")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Which should resolve to a path like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0:1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@6,2000/pci@2/SUNW,qlc@5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@4,2000/scsi@1/ses@w50800200000000d2,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which should resolve to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@4,2000/scsi@1:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_nexus_path(char *path_phys, char **nexus_path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t port = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int port_flag = 0, i = 0, pathcnt = 1;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *char_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char drvr_path[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char buf[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char temp_buf[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat stbuf;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint_t path_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int p_on = 0, p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if the path_phys is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_phys == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nexus_path = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(path_phys, SCSI_VHCI)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(drvr_path, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state < MAXPATHSTATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_st = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[p_on].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on_line path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_on].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* standby or path0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_st].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(drvr_path, DRV_NAME_SSD) || strstr(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell DRV_NAME_ST) || strstr(drvr_path, SES_NAME)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strrchr(drvr_path, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *char_ptr = '\0'; /* Terminate string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path_type = g_get_path_type(drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_type & FC4_SF_XPORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* sf driver in path so capture the port # */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strstr(drvr_path, "sf@")) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port = atoi(char_ptr + 3);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVLD_PORT_IN_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strrchr(drvr_path, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *char_ptr = '\0'; /* Terminate string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_flag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte L_DPRINTF(" g_get_nexus_path:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " sf driver in path so use port #%d.\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (path_type & FC_GEN_XPORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check to see if it 3rd party vendor FCA.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it is return error for this operation since
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we don't know how they creates FCA port related minor node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * As of now there is no supported operation on FCA node so
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this should be okay.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((path_type & FC_FCA_MASK) == FC_FCA_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For current Sun FCA driver, appending
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port # doesn't work. Just remove transport layer from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * input path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strstr(drvr_path, "/fp@")) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *char_ptr = '\0'; /* Terminate string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(drvr_path, &stbuf) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Found a directory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now append a port number or devctl to the path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port_flag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(buf, ":%d", port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Try adding port 0 and see if node exists. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(temp_buf, "%s:0", drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(temp_buf, &stbuf) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Path we guessed at does not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * exist so it may be a driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that ends in :devctl.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(buf, ":devctl");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The path that was entered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * did not include a port number
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so the port was set to zero, and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then checked. The default path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * did exist.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF("Since a complete path"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " was not supplied "
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "a default path is being"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " used:\n %s\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell temp_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(buf, ":0");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nexus_path = g_alloc_string(drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte L_DPRINTF(" g_get_nexus_path: Nexus path = %s\n", drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the FC topology for the input device or nexus(HBA) path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The routine calls g_get_path_type to determine the stack of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the input path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If it a socal path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it returns FC_TOP_PRIVATE_LOOP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * calls fc_get_topology ioctl to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the fp topolgy from the driver.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INPUTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * path - a string of device path, transport path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: "path" SHOULD NOT BE OPEN BEFORE CALLING
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * THIS FUNCTION BECAUSE THIS FUNCTION DOES
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * AN "O_EXCL" OPEN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_top - a pointer to the toplogy type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if there is no error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The input path is expected to be something like below:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0/ses@e,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0/ssd@..
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@1,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0:1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (or "qlc" instead of "socal" and "fp" for "sf")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Which should resolve to a path like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0:1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@6,2000/pci@2/SUNW,qlc@5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@4,2000/scsi@1/ses@w50800200000000d2,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which should resolve to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@4,2000/scsi@1:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3) The nexus(hba or nexus) path will get an error only for qlc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * since the routine need to open fp :devctl node for fcio ioctl.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0:1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@6,2000/pci@2/SUNW,qlc@5 => error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_fca_port_topology(char *path, uint32_t *port_top, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio_t fcio;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, i = 0, pathcnt = 1;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char drvr_path[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *char_ptr;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct stat stbuf;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint_t dev_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mp_pathlist_t pathlist;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int p_on = 0, p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if the path is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if the argument is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port_top == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(path, SCSI_VHCI)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_pathlist(drvr_path, &pathlist)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathcnt = pathlist.path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = p_st = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pathcnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state < MAXPATHSTATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_on = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (pathlist.path_info[i].path_state ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MDI_PATHINFO_STATE_STANDBY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_st = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathlist.path_info[p_on].path_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MDI_PATHINFO_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* on_line path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_on].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* standby or path0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(drvr_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pathlist.path_info[p_st].path_hba);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(pathlist.path_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the path to the :devctl driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This assumes the path looks something like this:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0/ses@e,0:0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@1f,0/SUNW,socal@1,0/SUNW,sf@0,0:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a 1 level PCI type driver but still :devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (or "qlc" in the place of "socal" and "fp" for "sf")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The dir below doesn't have corresponding :devctl node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@6,2000/pci@2/SUNW,qlc@5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/sbus@2,0/SUNW,socal@1,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strstr(drvr_path, DRV_NAME_SSD) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strstr(drvr_path, SES_NAME)) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strstr(drvr_path, DRV_NAME_ST)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((char_ptr = strrchr(drvr_path, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *char_ptr = '\0'; /* Terminate sting */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(drvr_path, &stbuf) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LSTAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* append controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(drvr_path, FC_CTLR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type = g_get_path_type(drvr_path)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type & FC4_XPORT_MASK) || (dev_type & FC4_FCA_MASK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *port_top = FC_TOP_PRIVATE_LOOP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* To contiue the path type should be fp :devctl node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(dev_type & FC_XPORT_MASK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(drvr_path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" g_get_fca_port_topology: Geting topology from:"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " %s\n", drvr_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_TOPOLOGY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)port_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_issue_fcio_ioctl(fd, &fcio, verbose) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GET_TOPOLOGY ioctl failed.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCIO_GET_TOPOLOGY_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This functions enables or disables a FCA port depending on the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argument, cmd, passed to it. If cmd is PORT_OFFLINE, the function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tries to disable the port specified by the argument 'phys_path'. If
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmd is PORT_ONLINE, the function tries to enable the port specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by the argument 'phys_path'.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INPUTS :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nexus_port_ptr - Pointer to the nexus path of the FCA port to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * operate on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmd - PORT_OFFLINE or PORT_ONLINE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success and non-zero otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_set_port_state(char *nexus_port_ptr, int cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int path_type, fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((path_type = g_get_path_type(nexus_port_ptr)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(nexus_port_ptr, O_NDELAY|O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case PORT_OFFLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_type & FC4_SOCAL_FCA) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Socal/sf drivers -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The socal driver currently returns EFAULT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * even if the ioctl has completed successfully.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_LOOPBACK_INTERNAL,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell NULL) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_PORT_OFFLINE_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * QLogic card -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Can't do much here since the driver currently
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doesn't support this feature. We'll just fail
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for now. Support can be added when the driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is enabled with the feature at a later date.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_PORT_OFFLINE_UNSUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case PORT_ONLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_type & FC4_SOCAL_FCA) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Socal/sf drivers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The socal driver currently returns EFAULT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * even if the ioctl has completed successfully.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_NO_LOOPBACK, NULL) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_PORT_ONLINE_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * QLogic card -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Can't do much here since the driver currently
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doesn't support this feature. We'll just fail
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for now. Support can be added when the driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is enabled with the feature at a later date.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_PORT_ONLINE_UNSUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The interfaces defined below (g_port_offline() and g_port_online())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * are what will be exposed to applications. We will hide g_set_port_state().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * They have to be functions (as against macros) because making them
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * macros will mean exposing g_set_port_state() and we dont want to do that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_port_offline(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (g_set_port_state(path, PORT_OFFLINE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_port_online(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (g_set_port_state(path, PORT_ONLINE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function sets the loopback mode for a port on a HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INPUTS :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portpath - Pointer to the path of the FCA port on which to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set the loopback mode
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmd - EXT_LPBACK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INT_LPBACK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NO_LPBACK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURNS :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success and non-zero otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_loopback_mode(char *portpath, int cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int path_type, fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((path_type = g_get_path_type(portpath)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(portpath, O_NDELAY|O_RDONLY|O_EXCL)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The loopback calls are currently not fully supported
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * via fp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A fp based general solution is required to support Leadville FCAs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * including Qlgc and 3rd party FCA. As of now qlgc provides
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * some diag functions like echo through qlc private ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which is not supproted by luxadm and libraries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EXT_LPBACK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_type & FC4_SOCAL_FCA) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_LOOPBACK_MANUAL,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell NULL) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for previous mode set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno != EALREADY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOOPBACK_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Well, it wasn't one of the above cards so..
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOOPBACK_UNSUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NO_LPBACK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_type & FC4_SOCAL_FCA) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_NO_LOOPBACK, NULL) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOOPBACK_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Well, it wasn't one of the above cards so..
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOOPBACK_UNSUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case INT_LPBACK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path_type & FC4_SOCAL_FCA) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_LOOPBACK_INTERNAL,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell NULL) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for previous mode set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno != EALREADY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOOPBACK_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Well, it wasn't one of the above cards so..
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOOPBACK_UNSUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_LOOPBACK_UNSUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_port_state(char *portpath, int port_state)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Get port state for a path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input: portpath
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set to path of port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Output: port_state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set to one of the following:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PORT_CONNECTED
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PORT_NOTCONNECTED
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_port_state(char *portpath, int *portstate, int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd, err, num_devices = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct lilpmap map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t dev_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gfc_dev_t map_root;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset(&map, 0, sizeof (struct lilpmap));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid path if portpath is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (portpath == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return invalid arg if argument is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((portpath == NULL) || (portstate == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type = g_get_path_type(portpath)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO_GETMAP returns error when there are * no devices attached.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ENOMEM is returned when no devices are attached.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_first_dev returns NULL without error when there is no
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devices are attached.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_type & FC_FCA_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map_root = g_dev_map_init(portpath, &err,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell MAP_XPORT_PROP_ONLY)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_get_first_dev(map_root, &err) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no device is found if err == 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == L_NO_SUCH_DEV_FOUND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *portstate = PORT_NOTCONNECTED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Device found okay */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *portstate = PORT_CONNECTED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_dev_map_fini(map_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(portpath, O_NDELAY | O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: There is only one error returned by this ioctl. ENOMEM.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Hence the lack of return on error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_GETMAP, &map) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map.lilp_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_devices = map.lilp_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Non-Leadville stacks report the FCA in the count */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *portstate = (num_devices > 1) ? PORT_CONNECTED :
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell PORT_NOTCONNECTED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_dev_login(char *port_path, la_wwn_t port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: port login via g_dev_log_in_out()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input: port_path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fc transport port with fabric/public loop topology
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port wwn of device node to login
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: return code from g_dev_log_in_out()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_dev_login(char *port_path, la_wwn_t port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (g_dev_log_in_out(port_path, port_wwn, FCIO_DEV_LOGIN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_dev_logout(char *port_path, la_wwn_t port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: port login via g_dev_log_in_out()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input: port_path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fc transport port with fabric/public loop topology
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port wwn of device node to logout
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: return code from g_dev_log_in_out()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_dev_logout(char *port_path, la_wwn_t port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (g_dev_log_in_out(port_path, port_wwn, FCIO_DEV_LOGOUT));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_dev_log_in_out(char *port_path, la_wwn_t port_wwn, uint16_t cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: port login via FCIO_DEV_LOGOUT and port logout via FCIO_DEV_LOGOUT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IOCTL requires EXCLUSIVE open.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input: port_path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fc transport port with fabric/public loop topology
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port wwn of device node to logout
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO_DEV_LOGON or FCIO_DEV_LOGOUT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_dev_log_in_out(char *port_path, la_wwn_t port_wwn, uint16_t cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd, err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint32_t hba_port_top;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio_t fcio;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int verbose = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = g_get_fca_port_topology(port_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell &hba_port_top, verbose)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!((hba_port_top == FC_TOP_PUBLIC_LOOP) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (hba_port_top == FC_TOP_FABRIC))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPNOSUPP_ON_TOPOLOGY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(port_path, O_NDELAY | O_RDONLY | O_EXCL)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stores port_wwn to la_wwn_t raw_wwn field
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and construct fcio structures for FCIO_DEV_LOGIN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = cmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (port_wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&port_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_WRITE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = fcio.fcio_alen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = fcio.fcio_abuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_issue_fcio_ioctl(fd, &fcio, verbose) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF((cmd == FCIO_DEV_LOGIN) ?
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " FCIO_DEV_LOGIN ioctl failed.\n"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell : " FCIO_DEV_LOGOUT ioctl failed.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((cmd == FCIO_DEV_LOGIN) ?
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell L_FCIO_DEV_LOGIN_FAIL
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell : L_FCIO_DEV_LOGOUT_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will verify if a FC device (represented by input WWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is connected on a FCA port by searching the device list from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_dev_list() for a WWN match.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * input:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fca_path: pointer to the physical path string, path to a fp node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * possible forms are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@1f,2000/pci@1/SUNW,qlc@5/fp@0,0:devctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dev_wwn: WWN string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag: indicate that the input WWN is node or port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returned values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0: if a match is found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_WWN_NOT_FOUND_IN_DEV_LIST: if no match found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_UNEXPECTED_FC_TOPOLOGY: existing error code for an error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from the topology checking of the input fca path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_MALLOC_FAILED: existing error code for allocation eror from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_dev_list().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * L_FCIO_GETMAP_IOCTL_FAIL: existing error code for an error from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FCIO ioctl called by the g_get_dev_list()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1: other failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_wwn_in_dev_list(char *fca_path, la_wwn_t dev_wwn, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uint_t dev_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int i, err;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_port_dev_t *dev_list;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fc_port_dev_t *dev_list_save;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int num_devices = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type = g_get_path_type(fca_path)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(dev_type & FC_XPORT_MASK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((err = g_get_dev_list(fca_path, &dev_list, &num_devices))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell != 0) && (err != L_GET_DEV_LIST_ULP_FAILURE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_list_save = dev_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (flag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case MATCH_NODE_WWN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < num_devices; i++, dev_list++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp(dev_list->dev_nwwn.raw_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_wwn.raw_wwn, FC_WWN_SIZE) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list_save);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list_save);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consider a new error code for not found. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_WWN_NOT_FOUND_IN_DEV_LIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case MATCH_PORT_WWN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < num_devices; i++, dev_list++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp(dev_list->dev_pwwn.raw_wwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dev_wwn.raw_wwn, FC_WWN_SIZE) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list_save);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list_save);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* consider a new error code for not found. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_WWN_NOT_FOUND_IN_DEV_LIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(dev_list_save);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_get_dev_port_state(char *fca_path, la_wwn_t port_wwn, uint32_t *state)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: get the state of device port login via FCIO_GET_STATE ioctl.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input: fca_path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fc transport port with fabric/public loop topology
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port wwn of device node to logout
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port login or not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteg_get_dev_port_state(char *fca_path, la_wwn_t port_wwn, uint32_t *state)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int dev_type;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell fcio_t fcio;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int verbose = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type = g_get_path_type(fca_path)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(dev_type & FC_XPORT_MASK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(fca_path, O_NDELAY | O_RDONLY)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stores port_wwn to la_wwn_t raw_wwn field
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and construct fcio structures for FCIO_DEV_LOGIN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_STATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (port_wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&port_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ | FCIO_XFER_WRITE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_alen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_abuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g_issue_fcio_ioctl(fd, &fcio, verbose) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GET_STATE ioctl failed.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCIO_GET_STATE_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Name: lilp_map_cmp
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description: This function is used to compare the physical location
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of to fc devices in a gfc_map_t.dev_addr arrary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Params:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First device to compare
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Second device to compare
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 = Devices at equal phyiscal location, How did this happen?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * >0 = First device have a higher physical location than second
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * <0 = Second device have a higher physical location than first
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int lilp_map_cmp(const void* dev1, const void* dev2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i_dev1 = ((fc_port_dev_t *)dev1)->dev_did.priv_lilp_posit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i_dev2 = ((fc_port_dev_t *)dev2)->dev_did.priv_lilp_posit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i_dev1 > i_dev2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i_dev1 < i_dev2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retrieves multiple paths to a device based on devid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Caller must use mplist_free to free mplist structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This currently only supports ssd devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The st driver does not register a device id.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input Values:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid: ptr to valid ddi_devid_t struct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * root: root handle to device tree snapshot
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * drvr_name: driver name to start the node tree search
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return Value:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedevid_get_all(ddi_devid_t devid, di_node_t root, char *drvr_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct mplist_struct **mplistp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell ddi_devid_t mydevid;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell di_node_t node;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *devfs_path = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct mplist_struct *mpl, *mpln;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devid == NULL || root == NULL || drvr_name == NULL ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mplistp == NULL ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (strncmp(drvr_name, SSD_DRVR_NAME, strlen(SSD_DRVR_NAME))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *mplistp = mpl = mpln = (struct mplist_struct *)NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* point to first node which matches portdrvr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node = di_drv_first_node(drvr_name, root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node == DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DRIVER_NODES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (node != DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mydevid = di_devid(node)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((devid_compare(mydevid, devid)) == 0)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Load multipath list */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((mpl = (struct mplist_struct *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1, sizeof (struct mplist_struct)))
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mplist_free(*mplistp);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((devfs_path = my_devfs_path(node)) ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell node = di_drv_next_node(node);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(mpl);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell continue;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mpl->devpath = (char *)calloc(1,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(devfs_path) +
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strlen(SSD_MINOR_NAME) + 1);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (mpl->devpath == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell S_FREE(mpl);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mplist_free(*mplistp);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_devfs_path_free(devfs_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sprintf(mpl->devpath, "%s%s", devfs_path,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell SSD_MINOR_NAME);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (*mplistp == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell *mplistp = mpln = mpl;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mpln->next = mpl;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell mpln = mpl;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte my_devfs_path_free(devfs_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node = di_drv_next_node(node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Frees a previously allocated mplist_struct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemplist_free(struct mplist_struct *mplistp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct mplist_struct *mplistn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (mplistp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mplistn = mplistp->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mplistp->devpath != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(mplistp->devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mplistp->devpath = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(mplistp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mplistp = mplistn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retrieves all device nodes based on drvr_name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Currently supports SSD_DRVR_NAME, ST_DRVR_NAME
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There will be a device node in the libdevinfo
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * snapshot only if there is at least one node bound.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input values:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * root valid snapshot handle from di_init(3DEVINFO)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * drvr_name name of driver to start node search
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_list_ptr ptr to ptr to WWN_list struct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedevices_get_all(di_node_t root, char *drvr_name, char *minor_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct wwn_list_struct **wwn_list_ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell di_node_t node;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *devfs_path;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char devicepath[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t *nwwn = NULL, *pwwn = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell uchar_t node_wwn[WWN_SIZE], port_wwn[WWN_SIZE];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_list *wwn_list, *l1, *l2;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int scsi_vhci = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int err, devtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (root == DI_NODE_NIL || drvr_name == NULL ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list_ptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = *wwn_list_ptr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(port_wwn, 0, sizeof (port_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(node_wwn, 0, sizeof (node_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(drvr_name, SSD_DRVR_NAME) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devtype = DTYPE_DIRECT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcmp(drvr_name, ST_DRVR_NAME) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devtype = DTYPE_SEQUENTIAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * An unsupported driver name was passed in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_DRIVER_NOTSUPP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* point to first node which matches portdrvr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node = di_drv_first_node(drvr_name, root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node == DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (node != DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((devfs_path = my_devfs_path(node)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Check for offline state
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((di_state(node) &
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell DI_DEVICE_OFFLINE) == DI_DEVICE_OFFLINE) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_devfs_path_free(devfs_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell node = di_drv_next_node(node);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell continue;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Only support st, ssd nodes
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (!strstr(devfs_path, SLSH_DRV_NAME_SSD) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell !strstr(devfs_path, SLSH_DRV_NAME_ST)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_devfs_path_free(devfs_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell node = di_drv_next_node(node);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell continue;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell devicepath[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * form device path
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sprintf(devicepath, "%s%s", devfs_path, minor_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((strstr(devicepath, SCSI_VHCI) == NULL)) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((err = get_wwn_data(node, &nwwn, &pwwn)) !=
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_devfs_path_free(devfs_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (err);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell memcpy(node_wwn, nwwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (node_wwn));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell memcpy(port_wwn, pwwn,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell sizeof (port_wwn));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Clear values for SCSI VHCI devices.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * node wwn, port wwn are irrevelant at
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * the SCSI VHCI level
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell scsi_vhci++;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell memset(port_wwn, 0, sizeof (port_wwn));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell memset(node_wwn, 0, sizeof (node_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Got wwns, load data in list */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((l2 = (struct wwn_list_struct *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1, sizeof (struct wwn_list_struct))) ==
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_devfs_path_free(devfs_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((l2->physical_path = (char *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1, strlen(devicepath) +1)) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_devfs_path_free(devfs_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell memcpy(l2->w_node_wwn, node_wwn, WWN_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (scsi_vhci) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strcpy(l2->node_wwn_s, MSGSTR(12000, "N/A"));
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell copy_wwn_data_to_str(l2->node_wwn_s, node_wwn);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell copy_wwn_data_to_str(l2->port_wwn_s, port_wwn);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strcpy(l2->physical_path, devicepath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell l2->device_type = devtype;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (wwn_list == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell l1 = wwn_list = l2;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell } else {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell l2->wwn_prev = l1;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell l1 = l1->wwn_next = l2;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell my_devfs_path_free(devfs_path);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell scsi_vhci = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell node = di_drv_next_node(node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_ptr = wwn_list; /* pass back ptr to list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*wwn_list_ptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now load the /dev/ paths
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(drvr_name, SSD_DRVR_NAME) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = get_dev_path(wwn_list_ptr, DEV_RDIR,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell DIR_MATCH_SSD)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(wwn_list_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcmp(drvr_name, ST_DRVR_NAME) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = get_dev_path(wwn_list_ptr, DEV_TAPE_DIR,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell DIR_MATCH_ST)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte g_free_wwn_list(wwn_list_ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Access the properties for the node to get the node-wwn, port-wwn property
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On error, contents of nwwn, pwwn are unspecified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On successful return nwwn and pwwn are WWN_SIZE bytes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_wwn_data(di_node_t node, uchar_t **nwwn, uchar_t **pwwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (di_prop_lookup_bytes(DDI_DEV_T_ANY, node, NODE_WWN_PROP,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell nwwn) != WWN_SIZE) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* If we didn't get back the right count, return error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_WWN_PROP_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (di_prop_lookup_bytes(DDI_DEV_T_ANY, node, PORT_WWN_PROP,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell pwwn) != WWN_SIZE) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* If we didn't get back the right count, return error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_WWN_PROP_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * retrieves the /dev logical path for a WWN_list of devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_list_ptr ptr to list returned by devices_get_all
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dir_name /dev/ directory to search
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_dev_path(struct wwn_list_struct **wwn_list_ptr, char *dir_name,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *pattern_match)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell DIR *dirp;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct dirent *entp;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char namebuf[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *result = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell WWN_list *wwn_list, *wwn_list_save;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *env;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell hrtime_t start_time, end_time;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list_ptr == NULL || *wwn_list_ptr == NULL ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dir_name == NULL || pattern_match == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((env = getenv("_LUX_T_DEBUG")) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = *wwn_list_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dirp = opendir(dir_name)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" get_dev_path: No devices found\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((entp = readdir(dirp)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Ignore current directory and parent directory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * entries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(entp->d_name, ".") == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(entp->d_name, "..") == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (fnmatch(pattern_match, entp->d_name, 0) != 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(namebuf, 0, sizeof (namebuf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(namebuf, "%s/%s", dir_name, entp->d_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((result = g_get_physical_name_from_link(namebuf)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF(" Warning: Get physical name from"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " link failed. Link=%s\n", namebuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (wwn_list = *wwn_list_ptr; wwn_list != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = wwn_list->wwn_next) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if (strcmp(wwn_list->physical_path, result) == 0) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /*
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Add information to the list.
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((wwn_list->logical_path = (char *)
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell calloc(1, strlen(namebuf) + 1)) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell free(result);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell return (L_MALLOC_FAILED);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell }
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell strcpy(wwn_list->logical_path, namebuf);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte closedir(dirp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Did we load all of the paths?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: if there is a missing entry in /dev then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the user probably did a cleanup of /dev.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Whatever the case, remove the entry as it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is invalid.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = *wwn_list_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (wwn_list != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list->logical_path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(wwn_list->physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list_save = wwn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list->wwn_prev != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list->wwn_prev->wwn_next =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No previous entries
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwn_list_ptr = wwn_list->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn_list->wwn_next != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list->wwn_next->wwn_prev =
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell wwn_list->wwn_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = wwn_list->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(wwn_list_save);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_list = wwn_list->wwn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (env != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end_time = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " get_dev_path %s: "
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "\t\tTime = %lld millisec\n",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell dir_name, (end_time - start_time)/1000000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*wwn_list_ptr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_NO_DEVICES_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This functions calls di_devfs_path and gets the path associated with a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * given devinfo node. If the path returned does not have a '@' in it, it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * checks if the driver is detached and creates a path after looking at the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * driver properties.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * di_devfs_path_free is called internally.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The argument 'path' points to the final value upon return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Caller must use my_devfs_path_free on returned char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: Only support FC/SCSI_VHCI devices,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * for FC check for initiator-interconnect-type prop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemy_devfs_path(di_node_t node)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *pwwn = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *interconnect = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char pwwns[WWN_SIZE*2+1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *mypath;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int scsi_vhci = 0;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *tptr = NULL, *lun_guid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *lunnump = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell di_node_t parentnode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* sanity check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node == DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now go get the path for this node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tptr = di_devfs_path(node)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell parentnode = di_parent_node(node);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mypath = (char *)calloc(1, MAXPATHLEN + 1)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devfs_path_free(tptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Prepend "/devices" to libdevinfo-returned paths */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(mypath, "%s%s", DEVICES_DIR, tptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devfs_path_free(tptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Is this a FC device?
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell * Check initiator-interconnect-type property
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(mypath, SCSI_VHCI) == NULL) {
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell rval = di_prop_lookup_strings(DDI_DEV_T_ANY, parentnode,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell "initiator-interconnect-type", &interconnect);
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell /* Check for INTERCONNECT_FABRIC_STR & INTERCONNECT_FIBRE_STR */
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell if ((rval <= 0) ||
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell ((strcmp(interconnect, "FABRIC") != 0) &&
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell (strcmp(interconnect, "FIBRE") != 0))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Not a FC device. Free path and return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(mypath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_vhci++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tptr = strrchr(mypath, '/')) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(mypath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strchr(tptr, '@') != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (mypath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No '@' in path. This can happen when driver is detached.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We'll check if the state is detached and if it is, we'll construct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the path by looking at the properties.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((di_state(node) & DI_DRIVER_DETACHED) != DI_DRIVER_DETACHED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Driver is not detached and no '@' in path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Can't handle it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(mypath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!scsi_vhci) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte copy_wwn_data_to_str(pwwns, pwwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_prop_lookup_ints(DDI_DEV_T_ANY, node, LUN_PROP, &lunnump);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(&mypath[strlen(mypath)], "@w%s,%x", pwwn, *lunnump);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_prop_lookup_strings(DDI_DEV_T_ANY, node,
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell LUN_GUID_PROP, &lun_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(&mypath[strlen(mypath)], "@g%s", lun_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (mypath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemy_devfs_path_free(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from_ptr: ptr to uchar_t array of size WWN_SIZE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to_ptr: char ptr to string of size WWN_SIZE*2+1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecopy_wwn_data_to_str(char *to_ptr, const uchar_t *from_ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((to_ptr == NULL) || (from_ptr == NULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(to_ptr, "%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x",
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell from_ptr[0], from_ptr[1], from_ptr[2], from_ptr[3],
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell from_ptr[4], from_ptr[5], from_ptr[6], from_ptr[7]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open the requested directory and get one valid open.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If a device is busy, return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only need to open one device since
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that implies there will be a node returned from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * di_drv_first_node()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dir_name: logical device name directory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (DEV_TAPE_DIR, DEV_RDIR)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pattern_match: used by fnmatch on directory entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (DIR_MATCH_SSD, DIR_MATCH_ST)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * drvr_path: path type to verify ("/ssd@", "/st@")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (SLSH_DRV_NAME_ST, SLSH_DRV_NAME_SSD)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: None
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteinit_drv(char *dir_name, char *pattern_match, char *drvr_path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell DIR *dirp;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell struct dirent *entp;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char namebuf[MAXPATHLEN];
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell char *result = NULL;
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dirp = opendir(dir_name)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((entp = readdir(dirp)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Ignore current directory and parent directory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * entries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(entp->d_name, ".") == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(entp->d_name, "..") == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (fnmatch(pattern_match, entp->d_name, 0) != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(namebuf, 0, sizeof (namebuf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(namebuf, "%s/%s", dir_name, entp->d_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((result = g_get_physical_name_from_link(namebuf)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF(" Warning: Get physical name from"
063d642a188d1daeae23f68feedcc14a72d5276dBill Gumbrell " link failed. Link=%s\n", namebuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(result, drvr_path) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte result = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = g_object_open(result, O_NDELAY | O_RDONLY)) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (errno != EBUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte result = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte closedir(dirp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}