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/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "cfga_fp.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Function prototypes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t get_xport_devlink(const char *hba_phys,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **hba_logpp, int *l_errnop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char ctoi(char c);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t is_apid_configured(const char *xport_phys,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dyncomp, struct luninfo_list **lunlistpp, int *l_errnop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t insert_lun_to_lunlist(struct luninfo_list **lunlistpp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dyncomp, di_node_t devnode, int *l_errnop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t update_lunlist(struct luninfo_list **lunlistpp, int lun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t state, char *pathp, int *l_errnop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Globals */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Various conversions routines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecvt_lawwn_to_dyncomp(const la_wwn_t *pwwn, char **dyncomp, int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dyncomp = calloc(1, WWN_SIZE*2 + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*dyncomp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(*dyncomp, "%016llx",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (wwnConversion((uchar_t *)pwwn->raw_wwn)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecvt_dyncomp_to_lawwn(const char *dyncomp, la_wwn_t *port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char c, c1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *wwnp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnp = port_wwn->raw_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < WWN_SIZE; i++, wwnp++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = ctoi(*dyncomp++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1 = ctoi(*dyncomp++);
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 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 Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Generates the HBA logical ap_id from physical ap_id.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemake_xport_logid(const char *xport_phys, char **xport_logpp, int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*xport_logpp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A devlink for the XPORT should exist. Without the /dev/cfg link
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * driver name and instance number based based link needs to be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * constructed for the minor node type of DDI_NT_FC_ATTACHMENT_POINT.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sunddi.h defines DDI_NT_FC_ATTACHMENT_POINT for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ddi_ctl:attachment_point:fc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (get_xport_devlink(xport_phys, xport_logpp, l_errnop) == FPCFGA_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte assert(*xport_logpp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_xport_devlink(const char *xport_phys, char **xport_logpp, int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int match_minor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpcfga_ret_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte match_minor = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = physpath_to_devlink(CFGA_DEV_DIR, (char *)xport_phys,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xport_logpp, l_errnop, match_minor);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != FPCFGA_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte assert(*xport_logpp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Remove the "/dev/cfg/" prefix */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = strlen(CFGA_DEV_DIR SLASH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memmove(*xport_logpp, *xport_logpp + len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(*xport_logpp + len) + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Given a xport path and dynamic ap_id, returns the physical
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * path in pathpp. If the dynamic ap is not configured pathpp set to NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and returns FPCFGA_APID_NOCONFIGURE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedyn_apid_to_path(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *xport_phys,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dyncomp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct luninfo_list **lunlistpp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpcfga_ret_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A device MUST have a dynamic component */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dyncomp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = is_apid_configured(xport_phys, dyncomp, lunlistpp, l_errnop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte assert(ret != FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When both the transport and dynamic comp are given this function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * checks to see if the dynamic ap is configured on the dev tree.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If it is configured the devfs path will be stored in pathpp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When the dynamic comp is null this function check to see if the transport
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * node has any child.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retrun value: FPCFGA_OK if the apid is configured.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FPCFGA_APID_NOCONFIGURE if the apid is not configured.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FPCFGA_LIB_ERR for other errors.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteis_apid_configured(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *xport_phys,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dyncomp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct luninfo_list **lunlistpp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *devfs_phys, *devfs_fp_path, *client_path, *cp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pathp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char path_name[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_node_t tree_root, root, fpnode, dev_node, client_node;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_path_t path = DI_PATH_NIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_prop_t prop = DI_PROP_NIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *port_wwn_data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *lun_guid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char port_wwn[WWN_SIZE*2+1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count, *lunnump, devlen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found_fp = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t statep;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpcfga_ret_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*lunlistpp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_APID_NOCONFIGURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((devfs_phys = strdup(xport_phys)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(devfs_phys, DEVICES_DIR SLASH, strlen(DEVICES_DIR) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(SLASH)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = devfs_phys + strlen(DEVICES_DIR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memmove(devfs_phys, cp, strlen(cp) + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cp = strstr(devfs_phys, MINOR_SEP)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *cp = '\0'; /* Terminate string. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tree_root = di_init("/", DINFOCPYALL | DINFOPATH))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(devfs_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpnode = di_drv_first_node("fp", tree_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fpnode) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devfs_fp_path = di_devfs_path(fpnode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((devfs_fp_path) && !(strncmp(devfs_fp_path,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devfs_phys, strlen(devfs_phys)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found_fp = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devfs_path_free(devfs_fp_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devfs_path_free(devfs_fp_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fpnode = di_drv_next_node(fpnode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(found_fp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_LIB_ERR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte root = fpnode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when there is no child and path info node the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FPCFGA_APID_NOCONFIGURE is returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * regardless of the dynamic comp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_node = di_child_node(root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path = di_path_next_client(root, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_node == DI_NODE_NIL) && (path == DI_PATH_NIL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_APID_NOCONFIGURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when dyn comp is null the function just checks if there is any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * child under fp transport attachment point.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dyncomp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_OK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now checks the children node to find
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if dynamic ap is configured. if there are multiple luns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * store into lunlist.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_node != DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((prop = di_prop_next(dev_node, prop)) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* is property name port-wwn */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!(strcmp(PORT_WWN_PROP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_prop_name(prop)))) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (di_prop_type(prop) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DI_PROP_TYPE_BYTE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop != DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = di_prop_bytes(prop, &port_wwn_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (count != WWN_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_LIB_ERR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(port_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[0], port_wwn_data[1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[2], port_wwn_data[3],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[4], port_wwn_data[5],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[6], port_wwn_data[7]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(strncmp(port_wwn, dyncomp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WWN_SIZE*2))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = insert_lun_to_lunlist(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lunlistpp, dyncomp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_node, l_errnop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != FPCFGA_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_node = di_sibling_node(dev_node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop = DI_PROP_NIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (dev_node != DI_NODE_NIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now checks the path info node to find
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if dynamic ap is configured. if there are multiple luns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * store into lunlist.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (path != DI_PATH_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now parse the path info node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = di_path_prop_lookup_bytes(path, PORT_WWN_PROP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &port_wwn_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (count != WWN_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_LIB_ERR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(port_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x%1.2x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[0], port_wwn_data[1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[2], port_wwn_data[3],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[4], port_wwn_data[5],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_data[6], port_wwn_data[7]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if matches get the path of scsi_vhci child node. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(strncmp(port_wwn, dyncomp, WWN_SIZE*2))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte client_node = di_path_client_node(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (client_node == DI_NODE_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_LIB_ERR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = di_path_prop_lookup_ints(path,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte LUN_PROP, &lunnump);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte client_path = di_devfs_path(client_node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(path_name, client_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devfs_path_free(client_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state = di_state(client_node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte statep = di_path_state(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the node is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * state then check the devfs_path to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see if it has a complete path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For non scsi_vhci node the path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doesn't contain @w(portwwn) part
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consistently. For scsi_vhci
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this behavior may not be there.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * To be safe @g(guid) is attempted
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to be added here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((state & DI_DRIVER_DETACHED) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strstr(path_name, "@g") == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop = DI_PROP_NIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((prop = di_prop_next(client_node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop)) != DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* is property name lun-wwn */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!(strcmp(LUN_GUID_PROP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_prop_name(prop)))) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (di_prop_type(prop) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DI_PROP_TYPE_STRING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop != DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = di_prop_strings(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop, &lun_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(&path_name[
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(path_name)],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "@g%s", lun_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = FPCFGA_LIB_ERR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devlen = strlen(DEVICES_DIR) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(path_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((pathp = calloc(1, devlen))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(pathp, devlen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s%s", DEVICES_DIR, path_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = (update_lunlist(lunlistpp, *lunnump,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte statep, pathp, l_errnop))) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FPCFGA_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(pathp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path = di_path_next_client(root, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (path != DI_PATH_NIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_fini(tree_root);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(devfs_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteinsert_lun_to_lunlist(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct luninfo_list **lunlistpp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dyncomp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_node_t dev_node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char path_name[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *pathp, *dev_phys;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_prop_t prop_lun = DI_PROP_NIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count, devlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *lunp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((prop_lun = di_prop_next(dev_node, prop_lun)) != DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(strcmp(LUN_PROP, di_prop_name(prop_lun))) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (di_prop_type(prop_lun) == DI_PROP_TYPE_INT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = di_prop_ints(prop_lun, &lunp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (count <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop_lun == DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stores state info in state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This information is used to get the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * validity of path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if driver_detached don't try to get
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the devfs_path since it is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * complete. ex, /pci@1f,2000/pci@1/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SUNW,qlc@5/fp@0,0/ssd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which doesn't contain the port wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * part. The attached node looks like
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /pci@1f,2000/pci@1/SUNW,qlc@5/fp@0,0/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ssd@w2100002037006b14,0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state = di_state(dev_node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_phys = di_devfs_path(dev_node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_phys == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(path_name, dev_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devfs_path_free(dev_phys);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((state & DI_DRIVER_DETACHED) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strstr(path_name, "@w") == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(&path_name[strlen(path_name)], "@w%s,%x", dyncomp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *lunp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devlen = strlen(DEVICES_DIR) + strlen(path_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((pathp = calloc(1, devlen))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(pathp, devlen, "%s%s", DEVICES_DIR, path_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (update_lunlist(lunlistpp, *lunp, state, pathp, l_errnop));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic fpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteupdate_lunlist(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct luninfo_list **lunlistpp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int lun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t state,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *pathp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct luninfo_list *newlun, *curlun, *prevlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun = curlun = prevlun = (struct luninfo_list *)NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun = calloc(1, sizeof (struct luninfo_list));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (newlun == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun->lunnum = lun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun->node_state = state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun->path = pathp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun->next = (struct luninfo_list *)NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if lunlist is empty add the new lun info and return. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*lunlistpp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *lunlistpp = newlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if the first lun in the list is the same as the new lun return. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*lunlistpp)->lunnum == lun) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(newlun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the first lun in the list is less than the new lun add the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * new lun as the first lun and return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*lunlistpp)->lunnum < lun) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun->next = *lunlistpp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *lunlistpp = newlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the first lun in the list is greater than the new lun and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * there is a single lun add new lun after the first lun and return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*lunlistpp)->next == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*lunlistpp)->next = newlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now there is more than two luns in the list and the first lun
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is greter than the input lun.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curlun = (*lunlistpp)->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prevlun = *lunlistpp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (curlun != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (curlun->lunnum == lun) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(newlun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (curlun->lunnum < lun) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlun->next = curlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prevlun->next = newlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prevlun = curlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curlun = curlun->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* add the new lun at the end of list. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prevlun->next = newlun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemake_dyncomp_from_dinode(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const di_node_t node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **dyncompp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_prop_t prop = DI_PROP_NIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *port_wwn_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dyncompp = calloc(1, WWN_SIZE*2 + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*dyncompp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now get port-wwn for the input node. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((prop = di_prop_next(node, prop)) != DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(strcmp(PORT_WWN_PROP, di_prop_name(prop))) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (di_prop_type(prop) == DI_PROP_TYPE_BYTE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop != DI_PROP_NIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = di_prop_bytes(prop, &port_wwn_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (count != WWN_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(*dyncompp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(*dyncompp, "%016llx",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (wwnConversion(port_wwn_data)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(*dyncompp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemake_portwwn_luncomp_from_dinode(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const di_node_t node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **dyncompp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int **luncompp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *port_wwn_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pwwn_ret, lun_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dyncompp != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((pwwn_ret = di_prop_lookup_bytes(DDI_DEV_T_ANY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node, PORT_WWN_PROP, &port_wwn_data)) <= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((luncompp != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((lun_ret = di_prop_lookup_ints(DDI_DEV_T_ANY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node, LUN_PROP, luncompp)) <= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * di_prop* returns the number of entries found or 0 if not found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or -1 for othere failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((pwwn_ret <= 0) || (lun_ret <= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dyncompp = calloc(1, WWN_SIZE*2+1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*dyncompp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(*dyncompp, "%016llx", (wwnConversion(port_wwn_data)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemake_portwwn_luncomp_from_pinode(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const di_path_t pinode,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **dyncompp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int **luncompp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *port_wwn_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pwwn_ret, lun_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dyncompp != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((pwwn_ret = di_path_prop_lookup_bytes(pinode,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PORT_WWN_PROP, &port_wwn_data)) <= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((luncompp != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((lun_ret = di_path_prop_lookup_ints(pinode,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte LUN_PROP, luncompp)) <= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * di_prop* returns the number of entries found or 0 if not found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or -1 for othere failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((pwwn_ret <= 0) || (lun_ret <= 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dyncompp = calloc(1, WWN_SIZE*2+1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*dyncompp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(*dyncompp, "%016llx", (wwnConversion(port_wwn_data)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefpcfga_ret_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconstruct_nodepath_from_dinode(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const di_node_t node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **node_pathp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *l_errnop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *devfs_path, path_name[MAXPATHLEN], *lun_guid, *port_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *port_wwn_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int is_scsi_vhci_dev, di_ret, devlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devfs_path = di_devfs_path(node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(path_name, devfs_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devfs_path_free(devfs_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state = di_state(node);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_scsi_vhci_dev = (strstr(path_name, SCSI_VHCI_DRVR) != NULL) ? 1 : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the node is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * state then check the devfs_path to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see if it has a complete path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For non scsi_vhci node the path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doesn't contain @w(portwwn) part
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consistently. For scsi_vhci
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this behavior may not be there.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * To be safe @g(guid) is attempted
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to be added here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state & DI_DRIVER_DETACHED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_scsi_vhci_dev &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strstr(path_name, "@g") == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_ret = di_prop_lookup_strings(DDI_DEV_T_ANY, node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte LUN_GUID_PROP, &lun_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (di_ret == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(&path_name[strlen(path_name)],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "@g%s", lun_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (!is_scsi_vhci_dev &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strstr(path_name, "@w") == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_ret = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PORT_WWN_PROP, &port_wwn_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (di_ret == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((port_wwn = calloc(1, WWN_SIZE*2 + 1))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(port_wwn, "%016llx",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (wwnConversion(port_wwn_data)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&path_name[strlen(path_name)],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "@w%s", port_wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_FREE(port_wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devlen = strlen(DEVICES_DIR) + strlen(path_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*node_pathp = calloc(1, devlen)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *l_errnop = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_LIB_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(*node_pathp, devlen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s%s", DEVICES_DIR, path_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FPCFGA_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteu_longlong_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortewwnConversion(uchar_t *wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte u_longlong_t tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&tmp, wwn, sizeof (u_longlong_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ntohll(tmp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}