753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER START
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * The contents of this file are subject to the terms of the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Common Development and Distribution License (the "License").
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You may not use this file except in compliance with the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or http://www.opensolaris.org/os/licensing.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * See the License for the specific language governing permissions
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * and limitations under the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If applicable, add the following below this CDDL HEADER, with the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fields enclosed by brackets "[]" replaced with your own identifying
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * information: Portions Copyright [yyyy] [name of copyright owner]
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER END
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Use is subject to license terms.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*LINTLIBRARY*/
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This module is part of the photon library
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * I18N message number ranges
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This file: 8000 - 8499
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Shared common messages: 1 - 1999
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/* Includes */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <stdlib.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <stdio.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/file.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/types.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/param.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <fcntl.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <unistd.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <errno.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <string.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/scsi/scsi.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <nl_types.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <strings.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/ddi.h> /* for max */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <l_common.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <stgcom.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <l_error.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <a_state.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <a5k.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/* Defines */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define VERBPRINT if (verbose) (void) printf
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * take all paths supplied by dl offline.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * RETURNS:
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * 0 = No error.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * *bsy_res_flag_p: 1 = The device is "busy".
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * In pre-2.6 we just return success
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorestatic int
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moored_offline_drive(struct dlist *dl, int *bsy_res_flag_p, int verbose)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorechar dev_path1[MAXPATHLEN];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooredevctl_hdl_t devhdl;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* for each path attempt to take it offline */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (; dl != NULL; dl = dl->next) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* save a copy of the pathname */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) strcpy(dev_path1, dl->dev_path);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* attempt to acquire the device */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((devhdl = devctl_device_acquire(dev_path1,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore DC_EXCL)) == NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (errno != EBUSY) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (L_ACQUIRE_FAIL);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* attempt to offline the drive */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (devctl_device_offline(devhdl) != 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *bsy_res_flag_p = 1;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) devctl_release(devhdl);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (0);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore E_DPRINTF(" d_offline_drive: Offline succeeded:/n "
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore "%s\n", dev_path1);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* offline succeeded -- release handle acquired above */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) devctl_release(devhdl);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (0);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore}
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Check to see if any of the disks that are attached
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * to the selected port on this backplane are reserved or busy.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * INPUTS:
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * RETURNS:
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * 0 = No error.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * *bsy_res_flag_p: 1 = The device is "busy".
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorel_check_busy_reserv_bp(char *ses_path, int front_flag,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int port_a_flag, int *bsy_res_flag_p, int verbose)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint err, i;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry MooreL_state *l_state = NULL;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorestruct dlist *p_list;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((l_state = (L_state *)calloc(1, sizeof (L_state))) == NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (L_MALLOC_FAILED);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (err = l_get_status(ses_path, l_state, verbose)) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < (int)l_state->total_num_drv/2; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((front_flag &&
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (l_state->drv_front[i].g_disk_state.d_state_flags[port_a_flag] &
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore L_RESERVED)) || (!front_flag &&
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (l_state->drv_rear[i].g_disk_state.d_state_flags[port_a_flag] &
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore L_RESERVED))) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *bsy_res_flag_p = 1;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (0);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < (int)l_state->total_num_drv/2; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* Get list of all paths to the requested port. */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (front_flag) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (port_a_flag) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((err = g_get_port_multipath(
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore l_state->drv_front[i].g_disk_state.port_a_wwn_s,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore &p_list, verbose)) != 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore } else {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((err = g_get_port_multipath(
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore l_state->drv_front[i].g_disk_state.port_b_wwn_s,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore &p_list, verbose)) != 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore } else {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (port_a_flag) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((err = g_get_port_multipath(
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore l_state->drv_rear[i].g_disk_state.port_a_wwn_s,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore &p_list, verbose)) != 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore } else {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((err = g_get_port_multipath(
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore l_state->drv_rear[i].g_disk_state.port_b_wwn_s,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore &p_list, verbose)) != 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (err = d_offline_drive(p_list,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bsy_res_flag_p, verbose)) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) g_free_multipath(p_list);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) g_free_multipath(p_list);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) l_free_lstate(&l_state);
fda6624021ffe01adf1af44f72ae4fb3ba65c1e8Konstantin Ananyev return (0);
fda6624021ffe01adf1af44f72ae4fb3ba65c1e8Konstantin Ananyev}
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Request the enclosure services controller (IB)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * to set the LRC (Loop Redundancy Circuit) to the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * bypassed/enabled state for the backplane specified by
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * the a and f flag and the enclosure or pathname.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorel_bp_bypass_enable(char *ses_path, int bypass_flag, int port_a_flag,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int front_flag, int force_flag, int verbose)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint fd, i;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint nobj = 0;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreses_objarg obj;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreses_object *all_objp = NULL, *all_objp_save = NULL;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint found = 0;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry MooreBp_elem_st *bp;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorechar msg[MAXPATHLEN];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint bsy_res_flag = 0;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint err;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (ses_path == NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (L_NO_SES_PATH);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Check for reservation and busy for all disks on this
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * backplane.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (!force_flag && bypass_flag) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (err = l_check_busy_reserv_bp(ses_path,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore front_flag, port_a_flag, &bsy_res_flag, verbose)) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (bsy_res_flag) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (L_BP_BUSY_RESERVED);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((fd = g_object_open(ses_path, O_NDELAY | O_RDWR)) == -1) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (errno);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t)&nobj) < 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (errno);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (nobj == 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (L_IB_NO_ELEM_FOUND);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore E_DPRINTF(" l_ib_bypass_bp: Number of SES objects: 0x%x\n",
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore nobj);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* alloc some memory for the objmap */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((all_objp = g_zalloc((nobj + 1) * sizeof (ses_object))) == NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (errno);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore all_objp_save = all_objp;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (ioctl(fd, SESIOC_GETOBJMAP, (caddr_t)all_objp) < 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) g_destroy_data(all_objp_save);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (errno);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < nobj; i++, all_objp++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore E_DPRINTF(" ID 0x%x\t Element type 0x%x\n",
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore all_objp->obj_id, all_objp->elem_type);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (all_objp->elem_type == ELM_TYP_BP) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore found++;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore break;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (found == 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) g_destroy_data(all_objp_save);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (L_NO_BP_ELEM_FOUND);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * We found the backplane element.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (verbose) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* Get the status for backplane #0 */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore obj.obj_id = all_objp->obj_id;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t)&obj) < 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) g_destroy_data(all_objp_save);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (errno);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, MSGSTR(8000,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore " Front backplane status: "));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bp = (struct bp_element_status *)&obj.cstat[0];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore l_element_msg_string(bp->code, msg);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, "%s\n", msg);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (bp->byp_a_enabled || bp->en_bypass_a) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, " ");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MSGSTR(130, "Bypass A enabled"));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, ".\n");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (bp->byp_b_enabled || bp->en_bypass_b) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, " ");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MSGSTR(129, "Bypass B enabled"));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, ".\n");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore all_objp++;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore obj.obj_id = all_objp->obj_id;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore all_objp--;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t)&obj) < 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) g_destroy_data(all_objp_save);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (errno);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, MSGSTR(8001,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore " Rear backplane status: "));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bp = (struct bp_element_status *)&obj.cstat[0];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore l_element_msg_string(bp->code, msg);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, "%s\n", msg);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (bp->byp_a_enabled || bp->en_bypass_a) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, " ");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MSGSTR(130, "Bypass A enabled"));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, ".\n");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (bp->byp_b_enabled || bp->en_bypass_b) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, " ");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MSGSTR(129, "Bypass B enabled"));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) fprintf(stdout, ".\n");
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* Get the current status */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (!front_flag) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore all_objp++;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore obj.obj_id = all_objp->obj_id;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t)&obj) < 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) close(fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) g_destroy_data(all_objp_save);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (errno);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* Do the requested action. */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bp = (struct bp_element_status *)&obj.cstat[0];
bp->select = 1;
bp->code = 0;
if (port_a_flag) {
bp->en_bypass_a = bypass_flag;
} else {
bp->en_bypass_b = bypass_flag;
}
if (getenv("_LUX_E_DEBUG") != NULL) {
(void) printf(" Sending this structure to ID 0x%x"
" of type 0x%x\n",
obj.obj_id, all_objp->elem_type);
for (i = 0; i < 4; i++) {
(void) printf(" Byte %d 0x%x\n", i,
obj.cstat[i]);
}
}
if (ioctl(fd, SESIOC_SETOBJSTAT, (caddr_t)&obj) < 0) {
(void) close(fd);
(void) g_destroy_data(all_objp_save);
return (errno);
}
(void) g_destroy_data(all_objp_save);
(void) close(fd);
return (0);
}
/*
* This function will request the enclosure services
* controller (IB) to set the LRC (Loop Redundancy Circuit) to the
* bypassed/enabled state for the device specified by the
* enclosure,dev or pathname and the port specified by the a
* flag.
*/
int
l_dev_bypass_enable(struct path_struct *path_struct, int bypass_flag,
int force_flag, int port_a_flag, int verbose)
{
gfc_map_t map;
char ses_path[MAXPATHLEN];
uchar_t *page_buf;
int err, fd, front_index, rear_index, offset;
int pathcnt = 1;
unsigned short page_len;
struct device_element *elem;
L_state *l_state = NULL;
struct device_element status;
int bsy_flag = 0, i, f_flag;
struct dlist *p_list;
char temppath[MAXPATHLEN];
mp_pathlist_t pathlist;
int p_pw = 0, p_on = 0, p_st = 0;
L_inquiry inq;
if (path_struct == NULL) {
return (L_INVALID_PATH_FORMAT);
}
if ((l_state = (L_state *)calloc(1, sizeof (L_state))) == NULL) {
return (L_MALLOC_FAILED);
}
map.dev_addr = (gfc_port_dev_info_t *)NULL;
(void) strcpy(temppath, path_struct->p_physical_path);
if ((strstr(path_struct->p_physical_path, SCSI_VHCI) != NULL) &&
(!g_get_pathlist(temppath, &pathlist))) {
pathcnt = pathlist.path_count;
p_pw = p_on = p_st = 0;
for (i = 0; i < pathcnt; i++) {
if (pathlist.path_info[i].path_state <
MAXPATHSTATE) {
if (strstr(pathlist.path_info[i].
path_addr,
path_struct->argv) != NULL) {
p_pw = i;
break;
}
if (pathlist.path_info[i].path_state ==
MDI_PATHINFO_STATE_ONLINE) {
p_on = i;
}
if (pathlist.path_info[i].path_state ==
MDI_PATHINFO_STATE_STANDBY) {
p_st = i;
}
}
}
if (strstr(pathlist.path_info[p_pw].path_addr,
path_struct->argv) != NULL) {
/* matching input pwwn */
(void) strcpy(temppath,
pathlist.path_info[p_pw].path_hba);
} else if (pathlist.path_info[p_on].path_state ==
MDI_PATHINFO_STATE_ONLINE) {
/* on_line path */
(void) strcpy(temppath,
pathlist.path_info[p_on].path_hba);
} else {
/* standby or path0 */
(void) strcpy(temppath,
pathlist.path_info[p_st].path_hba);
}
free(pathlist.path_info);
(void) strcat(temppath, FC_CTLR);
}
/*
* Need to get a valid location, front/rear & slot.
*
* The path_struct will return a valid slot
* and the IB path or a disk path.
*/
if (!path_struct->ib_path_flag) {
if (err = g_get_dev_map(temppath, &map, verbose)) {
(void) l_free_lstate(&l_state);
return (err);
}
if (err = l_get_ses_path(path_struct->p_physical_path,
ses_path, &map, verbose)) {
(void) l_free_lstate(&l_state);
free((void *)map.dev_addr);
return (err);
}
} else {
(void) strcpy(ses_path, path_struct->p_physical_path);
}
if (!path_struct->slot_valid) {
if ((map.dev_addr == (gfc_port_dev_info_t *)NULL) &&
((err = g_get_dev_map(temppath,
&map, verbose)) != 0)) {
(void) l_free_lstate(&l_state);
return (err);
}
if ((err = l_get_ses_path(path_struct->p_physical_path,
ses_path, &map, verbose)) != 0) {
(void) l_free_lstate(&l_state);
free((void *)map.dev_addr);
return (err);
}
if ((err = l_get_status(ses_path, l_state, verbose)) != 0) {
(void) l_free_lstate(&l_state);
free((void *)map.dev_addr);
return (err);
}
/* We are passing the disks path */
if ((err = l_get_slot(path_struct, l_state, verbose)) != 0) {
(void) l_free_lstate(&l_state);
free((void *)map.dev_addr);
return (err);
}
}
if (map.dev_addr != (gfc_port_dev_info_t *)NULL) {
free((void *)map.dev_addr);
}
if ((page_buf = (uchar_t *)malloc(MAX_REC_DIAG_LENGTH)) == NULL) {
(void) l_free_lstate(&l_state);
return (errno);
}
if ((fd = g_object_open(ses_path, O_NDELAY | O_RDWR)) == -1) {
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (errno);
}
if (err = l_get_envsen_page(fd, page_buf, MAX_REC_DIAG_LENGTH,
L_PAGE_2, verbose)) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
page_len = (page_buf[2] << 8 | page_buf[3]) + HEADER_LEN;
/* Get index to the disk we are interested in */
if (err = l_get_status(ses_path, l_state, verbose)) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
/*
* Now that we have the status check to see if
* busy or reserved, if bypassing.
*/
if ((!(force_flag | path_struct->ib_path_flag)) &&
bypass_flag) {
i = path_struct->slot;
f_flag = path_struct->f_flag;
/*
* Check for reservation and busy
*/
if ((f_flag &&
(l_state->drv_front[i].g_disk_state.d_state_flags[port_a_flag] &
L_RESERVED)) || (!f_flag &&
(l_state->drv_rear[i].g_disk_state.d_state_flags[port_a_flag] &
L_RESERVED))) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (L_BP_RESERVED);
}
if (f_flag) {
if (port_a_flag) {
if ((err = g_get_port_multipath(
l_state->drv_front[i].g_disk_state.port_a_wwn_s,
&p_list, verbose)) != 0) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
} else {
if ((err = g_get_port_multipath(
l_state->drv_front[i].g_disk_state.port_b_wwn_s,
&p_list, verbose)) != 0) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
}
} else {
if (port_a_flag) {
if ((err = g_get_port_multipath(
l_state->drv_rear[i].g_disk_state.port_a_wwn_s,
&p_list, verbose)) != 0) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
} else {
if ((err = g_get_port_multipath(
l_state->drv_rear[i].g_disk_state.port_b_wwn_s,
&p_list, verbose)) != 0) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
}
}
if (err = d_offline_drive(p_list,
&bsy_flag, verbose)) {
(void) g_free_multipath(p_list);
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
(void) g_free_multipath(p_list);
if (bsy_flag) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (L_BP_BUSY);
}
}
if (err = l_get_disk_element_index(l_state, &front_index,
&rear_index)) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
if (g_get_inquiry(ses_path, &inq)) {
return (L_SCSI_ERROR);
}
/* Skip global element */
front_index++;
if ((strncmp((char *)&inq.inq_pid[0], DAK_OFF_NAME,
strlen(DAK_OFF_NAME)) == 0) ||
(strncmp((char *)&inq.inq_pid[0], DAK_PROD_STR,
strlen(DAK_PROD_STR)) == 0)) {
rear_index += (MAX_DRIVES_DAK/2) + 1;
} else {
rear_index++;
}
if (path_struct->f_flag) {
offset = (8 + (front_index + path_struct->slot)*4);
} else {
offset = (8 + (rear_index + path_struct->slot)*4);
}
elem = (struct device_element *)(page_buf + offset);
/*
* now do requested action.
*/
bcopy((const void *)elem, (void *)&status,
sizeof (struct device_element)); /* save status */
bzero(elem, sizeof (struct device_element));
elem->select = 1;
elem->dev_off = status.dev_off;
elem->en_bypass_a = status.en_bypass_a;
elem->en_bypass_b = status.en_bypass_b;
/* Do requested action */
if (port_a_flag) {
elem->en_bypass_a = bypass_flag;
} else {
elem->en_bypass_b = bypass_flag;
}
if (getenv("_LUX_E_DEBUG") != NULL) {
g_dump(" l_dev_bypass_enable: Updating LRC circuit state:\n"
" Device Status Element ",
(uchar_t *)elem, sizeof (struct device_element),
HEX_ONLY);
(void) fprintf(stdout, " for device at location:"
" enclosure:%s slot:%d %s\n",
l_state->ib_tbl.enclosure_name,
path_struct->slot,
path_struct->f_flag ? "front" : "rear");
}
if (err = g_scsi_send_diag_cmd(fd,
(uchar_t *)page_buf, page_len)) {
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (err);
}
(void) close(fd);
(void) g_destroy_data(page_buf);
(void) l_free_lstate(&l_state);
return (0);
}
/*
* Issue a Loop Port enable Primitive sequence
* to the device specified by the pathname.
*/
int
d_p_enable(char *path, int verbose)
/*ARGSUSED*/
{
return (0);
}
/*
* Issue a Loop Port Bypass Primitive sequence
* to the device specified by the pathname. This requests the
* device to set its L_Port into the bypass mode.
*/
int
d_p_bypass(char *path, int verbose)
/*ARGSUSED*/
{
return (0);
}