tpgs.c revision f218e94ba20e9f27fa304f7daae68e9129427398
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Implementation of "scsi_vhci_f_tpgs" T10 standard based failover_ops.
*
* NOTE: for non-sequential devices only.
*/
/* Supported device table entries. */
char *std_dev_table[] = { NULL };
/* Failover module plumbing. */
#define STD_SCSI_CMD_LEN 0xff
/*
* max time for failover to complete is 3 minutes. Compute
* number of retries accordingly, to ensure we wait for at least
* 3 minutes
*/
/*
* max number of retries for std failover to complete where the ping
* command is failing due to transport errors or commands being rejected by
* std.
* STD_FO_MAX_RETRIES takes into account the case where CMD_CMPLTs but
* std takes time to complete the failover.
*/
#define STD_FO_MAX_CMD_RETRIES 3
#define STD_ACTIVE_OPTIMIZED 0x0
#define STD_ACTIVE_NONOPTIMIZED 0x1
#define STD_STANDBY 0x2
#define STD_UNAVAILABLE 0x3
#define STD_TRANSITIONING 0xf
#define STD_SCSI_ASC_STATE_TRANS 0x04
#define STD_SCSI_ASCQ_STATE_TRANS_FAIL 0x0A
#define STD_SCSI_ASC_STATE_CHG 0x2A
#define STD_SCSI_ASCQ_STATE_CHG_SUCC 0x06
#define STD_SCSI_ASCQ_STATE_CHG_FAILED 0x07
#define STD_SCSI_ASC_INVAL_PARAM_LIST 0x26
#define STD_SCSI_ASC_INVAL_CMD_OPCODE 0x20
#define STD_LOGICAL_UNIT_NOT_ACCESSIBLE 0x04
#define STD_TGT_PORT_UNAVAILABLE 0x0C
/* Special exported for direct use by MP-API */
int std_set_target_groups(struct scsi_address *, int, int);
/*
* External function definitions
*/
extern void vhci_mpapi_update_tpg_data(struct scsi_address *, char *);
static int std_get_fo_mode(struct scsi_device *,
int *, int *, int *, int *);
int, int, int *, int *);
/* ARGSUSED */
static int
void **ctpriv)
{
unsigned int tpgs_bits;
if (tpgs_bits == 0) {
"!std_device_probe: not a standard tpgs device"));
return (SFO_DEVICE_PROBE_PHCI);
}
if (dtype == DTYPE_SEQUENTIAL) {
"!std_device_probe: Detected a "
"Standard Asymmetric device "
"not yet supported\n"));
return (SFO_DEVICE_PROBE_PHCI);
}
"mode: sd(%p)", (void *) sd));
return (SFO_DEVICE_PROBE_PHCI);
}
if (tpgs_bits == SCSI_IMPLICIT_FAILOVER) {
"!std_device_probe: Detected a "
"Standard Asymmetric device "
"with implicit failover\n"));
return (SFO_DEVICE_PROBE_VHCI);
}
if (tpgs_bits == SCSI_EXPLICIT_FAILOVER) {
"!std_device_probe: Detected a "
"Standard Asymmetric device "
"with explicit failover\n"));
return (SFO_DEVICE_PROBE_VHCI);
}
if (tpgs_bits == SCSI_BOTH_FAILOVER) {
"!std_device_probe: Detected a "
"Standard Asymmetric device "
"which supports both implicit and explicit failover\n"));
return (SFO_DEVICE_PROBE_VHCI);
}
"!std_device_probe: "
"Unknown tpgs_bits: %x", tpgs_bits));
return (SFO_DEVICE_PROBE_PHCI);
}
/* ARGSUSED */
static void
{
/*
* For future use
*/
}
static int
{
char buf[STD_SCSI_CMD_LEN];
unsigned int tpgs_bits;
int retval;
*mode = 0;
if (retval == 0) {
"!std_inquiry: Failure returned from vhci_do_scsi_cmd"));
return (1);
}
if (tpgs_bits == 0) {
"!std_inquiry: zero tpgs_bits"));
return (1);
}
retval = 0;
if (tpgs_bits == SCSI_IMPLICIT_FAILOVER) {
} else if (tpgs_bits == SCSI_EXPLICIT_FAILOVER) {
} else if (tpgs_bits == SCSI_BOTH_FAILOVER) {
} else {
"!std_inquiry: Illegal mode returned: %x mode: %x",
retval = 1;
}
return (retval);
}
static int
{
char *bufp;
/*
* lets start the buf size with 512 bytes. If this
* if found to be insufficient, we can allocate
* appropriate size in the next iteration.
*/
buf_len = 512;
"request packet allocation for %d failed....",
buf_len));
return (1);
}
"!std_page83: Failure returned from scsi_init_pkt"));
return (1);
}
if (vhci_do_scsi_cmd(pkt) == 0) {
"!std_page83: vhci_do_scsi_cmd failed\n"));
return (1);
}
/*
* Now lets check if the size that was provided was
* sufficient. If not, allocate the appropriate size
* and retry the command again.
*/
rx_bsize += 4;
/*
* Need to allocate more buf and retry again
*/
"bufsize: %d greater than allocated buf: %d\n",
rx_bsize));
goto once_again;
}
"%x %x %x %x %x\n",
*rel_tgt_port = 0;
"!std_page83: relative target port: %x\n",
*rel_tgt_port));
*tgt_port = 0;
"!std_page83: target port: %x\n", *tgt_port));
*lu = 0;
"!std_page83: logical unit: %x\n", *lu));
}
}
return (0);
}
#ifdef DEBUG
static void
{
int i = 0, j;
for (j = 0; j < loop; j++) {
"!buf[%d-%d]: %x %x %x %x %x %x %x %x",
i += 8;
}
if (left) {
"NOTICE: buf[%d-%d]:", i, i + left));
for (j = 0; j < left; j++) {
}
}
}
#endif
static int
{
unsigned int rtpg_len = 0;
unsigned int l_tgt_port = 0, tpgs_state = 0;
unsigned int tgt_port_cnt = 0, lr_tgt_port = 0;
int i, len;
/*
* Start with buffer size of 512.
* If this is found to be insufficient, required size
* will be allocated and the command will be retried.
*/
len = 512;
"request packet allocation for %d failed....",
len));
return (1);
}
"!std_report_target_groups: scsi_init_pkt error\n"));
return (1);
}
"!std_report_target_groups: sending target port group:"
if (vhci_do_scsi_cmd(pkt) == 0) {
" vhci_do_scsi_cmd failed\n"));
return (1);
}
" returned from target"
" port group: buf[0/1/2/3]: %x/%x/%x/%x\n",
rtpg_len += 4;
"bufsize: %d greater than allocated buf: %d\n",
rtpg_len));
goto try_again;
}
#ifdef DEBUG
#endif
ptr += 4;
" tpgs state: %x"
" tgt_group: %x count: %x\n", tpgs_state,
ptr += 8;
for (i = 0; i < tgt_port_cnt; i++) {
lr_tgt_port = 0;
if ((lr_tgt_port == rel_tgt_port) &&
(l_tgt_port == tgt_port)) {
"!std_report_tgt_groups:"
" found tgt_port: %x rel_tgt_port:%x"
tpgs_state));
/*
* once we have the preferred flag
* and a non-optimized state flag
* we will get preferred flag from the
* report target groups
*/
if (tpgs_state == STD_ACTIVE_OPTIMIZED) {
} else if (tpgs_state ==
} else if (tpgs_state == STD_STANDBY) {
*pstate = STD_STANDBY;
} else {
}
return (0);
}
" tgt_port: %x rel_tgt_port:%x\n", tgt_port,
rel_tgt_port));
ptr += 4;
}
}
"NO rel_TGTPRT MATCH!!! Assigning Default: state: %x "
return (1);
}
/*
* get the failover mode, ownership and if it has extended failover
* both. The state is defined as online-optimized(0h),
* online-nonoptimized(1h), standby(2h), offline(3h),
* and transitioning(fh). Currently, there is online,
* standby, and offline(defined in sunmdi.h).
* Online-nonoptimized will be a mode of secondary
* and an ownership of online. Thought about using a different mode but
* it appears the states are really for the states for secondary mode.
* We currently have IS_ONLINING, IS_OFFLINING - should we have TRANSITIONING
* to mean from online-optimized to online-nonoptimized or does onlining
* cover this?
*/
/* ARGSUSED */
static int
{
int retval = 0;
struct scsi_address *ap;
" failed getrbuf\n"));
return (1);
}
" failed std_inquiry\n"));
retval = 1;
" failed std_page83\n"));
retval = 1;
" failed std_report_target_groups\n"));
retval = 1;
}
if (retval == 0) {
"SUCCESS\n"));
}
return (retval);
}
/* ARGSUSED */
static int
{
"std_set_target_groups() call from MPAPI");
return (1);
}
/*
* Process the packet reason of CMD_PKT_CMPLT - return 0 if no
* retry and 1 if a retry should be done
*/
static int
int *retry_cnt)
{
struct scsi_extended_sense *sns;
/*
* Re-initialize retry_cmd_cnt. Allow transport and
* cmd errors to go through a full retry count when
* retry count is not exhausted due to CMD_CMPLTs
* delay. This allows the system
* to brave a hick-up on the link at any given time,
* while waiting for the fo to complete.
*/
/*
* tpgs access state changed
*/
/* XXX: update path info? */
" state change");
}
return (1);
if ((*retry_cnt)++ >=
" failed: timed out waiting "
"for path to become active");
return (0);
}
"!(sd:%p)lun "
"becoming active...\n", (void *)sd));
return (1);
}
" sense key:%x, ASC: %x, "
return (0);
}
case STATUS_GOOD:
break;
case STATUS_CHECK:
"!(sd:%p):"
" status returned CHECK during std"
" path activation", (void *)sd));
return (0);
case STATUS_QFULL:
"status returned QFULL during std "
"path activation for %p\n", (void *)sd));
drv_usecwait(5000);
return (1);
case STATUS_BUSY:
"status returned BUSY during std "
"path activation for %p\n", (void *)sd));
drv_usecwait(5000);
return (1);
default:
"!(sd:%p) Bad status returned during std "
"activation (pkt %p, status %x)",
return (0);
}
return (0);
}
/*
* There is no standby path returned by the dsp and we may have
* to do something different for other devices that use standby
*/
/* ARGSUSED */
static int
void *ctpriv)
{
struct scsi_address *ap;
" failed std_get_fo_mode\n"));
return (1);
}
if ((state == STD_ACTIVE_OPTIMIZED) ||
(state == STD_ACTIVE_NONOPTIMIZED)) {
(void *)sd));
return (0);
}
if (mode != SCSI_IMPLICIT_FAILOVER) {
"!mode is EXPLICIT for %p xlf %x\n",
if (retval != 0) {
"!(sd:%p)std_path_activate failed(1)\n",
(void *)sd));
return (1);
}
} else {
(void *)sd));
}
if (!bp) {
"!(sd:%p)std_path_activate failed to alloc buffer",
(void *)sd));
return (1);
}
if (!pkt) {
"!(sd:%p)std_path_activate failed to initialize packet",
(void *)sd));
return (1);
}
retry_cnt = 0;
retry_cmd_cnt = 0;
if (err != TRAN_ACCEPT) {
/*
* Retry TRAN_BUSY till STD_FO_MAX_RETRIES is exhausted.
* All other errors are fatal and should not be retried.
*/
(retry_cnt++ < STD_FO_MAX_RETRIES)) {
goto retry;
}
"couldn't transport packet");
return (1);
}
switch (pkt->pkt_reason) {
case CMD_CMPLT:
retry_cmd_cnt = 0;
if (retval != 0) {
goto retry;
}
break;
case CMD_TIMEOUT:
retval = 1;
break;
case CMD_INCOMPLETE:
case CMD_RESET:
case CMD_ABORTED:
case CMD_TRAN_ERR:
/*
* Increased the number of retries when these error
* cases are encountered. Also added a 1 sec wait
* before retrying.
*/
if (retry_cmd_cnt++ < STD_FO_MAX_CMD_RETRIES) {
"!Retrying path activation due to "
"pkt reason:%x, retry cnt:%d",
goto retry;
}
/* FALLTHROUGH */
default:
"complete successfully,"
retval = 1;
break;
}
return (retval);
}
/* ARGSUSED */
void *ctpriv)
{
return (0);
}
/* ARGSUSED */
static int
{
" failed std_get_fo_mode\n"));
return (1);
}
if (state == STD_ACTIVE_OPTIMIZED) {
} else if (state == STD_ACTIVE_NONOPTIMIZED) {
} else if (state == STD_STANDBY) {
} else if (state == STD_UNAVAILABLE) {
}
if (preferred) {
} else {
}
"ACTIVE" : "INACTIVE"));
opinfo->opinfo_xlf_capable = 0;
return (0);
}
/* ARGSUSED */
{
/*
* For future use
*/
return (1);
}
/*
* Analyze the sense code to determine whether failover process
*/
/* ARGSUSED */
static int
{
int rval = SCSI_SENSE_UNKNOWN;
" sense_key:%x, add_code: %x, qual_code:%x"
" sense_key:%x, add_code: %x, qual_code:%x"
" sense_key:%x, add_code: %x, qual_code:%x"
" sense_key:%x, add_code: %x, qual_code:%x"
} else {
/*
* At this point sense data may be for power-on-reset
* UNIT ATTN hardware errors, vendor unqiue sense data etc.
* For all these cases, return SCSI_SENSE_UNKNOWN.
*/
}
return (rval);
}
/* ARGSUSED */
static int
{
/*
* The first phase does not have a standby path so
* there will be no explicit failover - when standard tpgs.
* standard defines preferred flag then we should start
* using this as the selection mechanism - there can be
* preferred primary standby that we should fail to first and then
* nonpreferred secondary standby.
*/
*nxt = PCLASS_PRIMARY;
return (0);
*nxt = PCLASS_SECONDARY;
return (0);
return (ENOENT);
} else {
return (EINVAL);
}
}
int
{
char *bufp;
struct scsi_extended_sense *sns;
len = 8;
" failed getrbuf"));
return (1);
}
"request packet allocation for %d failed....", len));
return (1);
}
"!std_set_target_groups: scsi_init_pkt error\n"));
return (1);
}
/*
* Sends 1 TPG descriptor only. Hence Parameter list length pkt_cdbp[9]
* is set to 8 bytes - Refer SPC3 for details.
*/
"!std_set_target_groups: sending set target port group:"
#ifdef DEBUG
#endif
if (rval == 0) {
" vhci_do_scsi_cmd failed\n"));
return (-1);
" sense:%x, add_code: %x, qual_code:%x"
" sense:%x, add_code: %x, qual_code:%x"
" sense_key:%x, add_code: %x, qual_code:%x"
} else {
/*
* At this point sns data may be for power-on-reset
* UNIT ATTN hardware errors, vendor unqiue sense etc.
* For all these cases, sense is unknown.
*/
" sense UNKNOWN: sense key:%x, ASC:%x, ASCQ:%x\n",
}
if (ss == SCSI_SENSE_STATE_CHANGED) {
return (0);
}
}
return (1);
}