0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * CDDL HEADER START
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * The contents of this file are subject to the terms of the
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Common Development and Distribution License (the "License").
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * You may not use this file except in compliance with the License.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * or http://www.opensolaris.org/os/licensing.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * See the License for the specific language governing permissions
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * and limitations under the License.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * When distributing Covered Code, include this CDDL HEADER in each
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * If applicable, add the following below this CDDL HEADER, with the
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * fields enclosed by brackets "[]" replaced with your own identifying
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * information: Portions Copyright [yyyy] [name of copyright owner]
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * CDDL HEADER END
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
0c45178b5714d692c44817c2235320c3f2b030abwl * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Use is subject to license terms.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/conf.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/file.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/ddi.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/sunddi.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/scsi/scsi.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/scsi/adapters/scsi_vhci.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/scsi/adapters/scsi_vhci_tpgs.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * External function definitions
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
b1a03ab1e63a57c5b968c229e2f36c79d2fdd222Victor Liextern void vhci_mpapi_update_tpg_data(struct scsi_address *, char *, int);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int vhci_tpgs_inquiry(struct scsi_address *ap, struct buf *bp,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int *mode);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int vhci_tpgs_page83(struct scsi_address *ap, struct buf *bp,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int *rel_tgt_port, int *tgt_port, int *lu);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic void print_buf(char *buf, int buf_size);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int vhci_tpgs_report_target_groups(struct scsi_address *ap,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct buf *bp, int rel_tgt_port, int tgt_port, int *pstate,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int *preferred);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsint
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsvhci_tpgs_set_target_groups(struct scsi_address *ap, int set_state,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int tpg_id)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct scsi_pkt *pkt;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct buf *bp;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int len, rval, ss = SCSI_SENSE_UNKNOWN;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs char *bufp;
0c45178b5714d692c44817c2235320c3f2b030abwl uint8_t *sns, skey, asc, ascq;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs len = 8;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp = getrbuf(KM_NOSLEEP);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (bp == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_tpgs_set_target_groups: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " failed getrbuf"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bufp = kmem_zalloc(len, KM_NOSLEEP);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (bufp == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_tpgs_set_target_groups: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "request packet allocation for %d failed....", len));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs freerbuf(bp);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_un.b_addr = bufp;
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu bp->b_flags = B_WRITE;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_bcount = len;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_resid = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bufp[4] = (0x0f & set_state);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bufp[6] = (0xff00 & tpg_id) >> 8;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bufp[7] = (0x00ff & tpg_id);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt = scsi_init_pkt(ap, NULL, bp, CDB_GROUP5,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs sizeof (struct scsi_arq_status), 0, 0, NULL, NULL);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (pkt == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_set_target_groups: scsi_init_pkt error\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs freerbuf(bp);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Sends 1 TPG descriptor only. Hence Parameter list length pkt_cdbp[9]
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * is set to 8 bytes - Refer SPC3 for details.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[0] = SCMD_MAINTENANCE_OUT;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[1] = SSVC_ACTION_SET_TARGET_PORT_GROUPS;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[9] = 8;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_time = 90;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_set_target_groups: sending set target port group:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " cdb[0/1/6/7/8/9]: %x/%x/%x/%x/%x/%x\n", pkt->pkt_cdbp[0],
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[1], pkt->pkt_cdbp[6], pkt->pkt_cdbp[7],
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[8], pkt->pkt_cdbp[9]));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#ifdef DEBUG
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs print_buf(bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#endif
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rval = vhci_do_scsi_cmd(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (rval == 0) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_tpgs_set_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " vhci_do_scsi_cmd failed\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs freerbuf(bp);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (-1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if ((pkt->pkt_reason == CMD_CMPLT) &&
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs (SCBP_C(pkt) == STATUS_CHECK) &&
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs (pkt->pkt_state & STATE_ARQ_DONE)) {
0c45178b5714d692c44817c2235320c3f2b030abwl sns = (uint8_t *)
0c45178b5714d692c44817c2235320c3f2b030abwl &(((struct scsi_arq_status *)(uintptr_t)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs (pkt->pkt_scbp))->sts_sensedata);
0c45178b5714d692c44817c2235320c3f2b030abwl skey = scsi_sense_key(sns);
0c45178b5714d692c44817c2235320c3f2b030abwl asc = scsi_sense_asc(sns);
0c45178b5714d692c44817c2235320c3f2b030abwl ascq = scsi_sense_ascq(sns);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0c45178b5714d692c44817c2235320c3f2b030abwl if ((skey == KEY_UNIT_ATTENTION) &&
0c45178b5714d692c44817c2235320c3f2b030abwl (asc == STD_SCSI_ASC_STATE_CHG) &&
0c45178b5714d692c44817c2235320c3f2b030abwl (ascq == STD_SCSI_ASCQ_STATE_CHG_SUCC)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ss = SCSI_SENSE_STATE_CHANGED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_set_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " sense:%x, add_code: %x, qual_code:%x"
0c45178b5714d692c44817c2235320c3f2b030abwl " sense:%x\n", skey, asc, ascq, ss));
0c45178b5714d692c44817c2235320c3f2b030abwl } else if ((skey == KEY_ILLEGAL_REQUEST) &&
0c45178b5714d692c44817c2235320c3f2b030abwl (asc == STD_SCSI_ASC_INVAL_PARAM_LIST)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ss = SCSI_SENSE_NOFAILOVER;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_set_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " sense:%x, add_code: %x, qual_code:%x"
0c45178b5714d692c44817c2235320c3f2b030abwl " sense:%x\n", skey, asc, ascq, ss));
0c45178b5714d692c44817c2235320c3f2b030abwl } else if ((skey == KEY_ILLEGAL_REQUEST) &&
0c45178b5714d692c44817c2235320c3f2b030abwl (asc == STD_SCSI_ASC_INVAL_CMD_OPCODE)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ss = SCSI_SENSE_NOFAILOVER;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_set_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " sense_key:%x, add_code: %x, qual_code:%x"
0c45178b5714d692c44817c2235320c3f2b030abwl " sense:%x\n", skey, asc, ascq, rval));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * At this point sns data may be for power-on-reset
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * UNIT ATTN hardware errors, vendor unqiue sense etc.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * For all these cases, sense is unknown.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ss = SCSI_SENSE_NOFAILOVER;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_set_target_groups: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " sense UNKNOWN: sense key:%x, ASC:%x, ASCQ:%x\n",
0c45178b5714d692c44817c2235320c3f2b030abwl skey, asc, ascq));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (ss == SCSI_SENSE_STATE_CHANGED) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs freerbuf(bp);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu } else if ((pkt->pkt_reason == CMD_CMPLT) &&
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu (SCBP_C(pkt) == STATUS_GOOD)) {
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu freerbuf(bp);
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu kmem_free((void *)bufp, len);
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu scsi_destroy_pkt(pkt);
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs freerbuf(bp);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * get the failover mode, ownership and if it has extended failover
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * capability. The mode(bits5-4/byte5) is defined as implicit, explicit, or
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * both. The state is defined as online-optimized(0h),
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * online-nonoptimized(1h), standby(2h), offline(3h),
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * and transitioning(fh). Currently, there is online,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * standby, and offline(defined in sunmdi.h).
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Online-nonoptimized will be a mode of secondary
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * and an ownership of online. Thought about using a different mode but
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * it appears the states are really for the states for secondary mode.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * We currently have IS_ONLINING, IS_OFFLINING - should we have TRANSITIONING
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * to mean from online-optimized to online-nonoptimized or does onlining
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * cover this?
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsint
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsvhci_tpgs_get_target_fo_mode(struct scsi_device *sd, int *mode,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int *state, int *xlf_capable, int *preferred)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int retval = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct buf *bp;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct scsi_address *ap;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int lu = 0, rel_tgt_port = 0, tgt_port = 0x0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_get_target_fo_mode: enter\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *mode = *state = *xlf_capable = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp = getrbuf(KM_NOSLEEP);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (bp == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_tpgs_get_target_fo_mode: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " failed getrbuf\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ap = &sd->sd_address;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (vhci_tpgs_inquiry(ap, bp, mode)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_tpgs_get_target_fo_mode: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " failed vhci_tpgs_inquiry\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs retval = 1;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if (vhci_tpgs_page83(ap, bp, &rel_tgt_port, &tgt_port, &lu)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_tpgs_get_target_fo_mode: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " failed vhci_tpgs_page83\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs retval = 1;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if (vhci_tpgs_report_target_groups(ap, bp, rel_tgt_port,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tgt_port, state, preferred)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_tpgs_get_target_fo_mode: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " failed vhci_tpgs_report_target_groups\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs retval = 1;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs freerbuf(bp);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (retval == 0) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL, "!vhci_tpgs_get_target_fo_mode: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "SUCCESS\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (retval);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsvhci_tpgs_inquiry(struct scsi_address *ap, struct buf *bp, int *mode)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct scsi_pkt *pkt;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct scsi_inquiry inq;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int retval;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *mode = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_un.b_addr = (caddr_t)&inq;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_flags = B_READ;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_bcount = sizeof (inq);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_resid = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt = scsi_init_pkt(ap, NULL, bp, CDB_GROUP0,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs sizeof (struct scsi_arq_status), 0, 0, SLEEP_FUNC, NULL);
d35e9352c203d3c67ed57186e0e8a6de000384abChris Liu if (pkt == NULL) {
d35e9352c203d3c67ed57186e0e8a6de000384abChris Liu VHCI_DEBUG(1, (CE_WARN, NULL,
d35e9352c203d3c67ed57186e0e8a6de000384abChris Liu "!vhci_tpgs_inquiry: Failure returned from scsi_init_pkt"));
d35e9352c203d3c67ed57186e0e8a6de000384abChris Liu return (1);
d35e9352c203d3c67ed57186e0e8a6de000384abChris Liu }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[0] = SCMD_INQUIRY;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[4] = sizeof (inq);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_time = 60;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs retval = vhci_do_scsi_cmd(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (retval == 0) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_tpgs_inquiry: Failure"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " returned from vhci_do_scsi_cmd"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
d91393a8e4d666dd6b6588c980c59cec667835f4Chris Horne if (inq.inq_tpgs == TPGS_FAILOVER_NONE) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_inquiry: zero tpgs_bits"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs retval = 0;
d91393a8e4d666dd6b6588c980c59cec667835f4Chris Horne if (inq.inq_tpgs == TPGS_FAILOVER_IMPLICIT) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *mode = SCSI_IMPLICIT_FAILOVER;
d91393a8e4d666dd6b6588c980c59cec667835f4Chris Horne } else if (inq.inq_tpgs == TPGS_FAILOVER_EXPLICIT) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *mode = SCSI_EXPLICIT_FAILOVER;
d91393a8e4d666dd6b6588c980c59cec667835f4Chris Horne } else if (inq.inq_tpgs == TPGS_FAILOVER_BOTH) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *mode = SCSI_BOTH_FAILOVER;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_inquiry: Illegal mode returned: %x mode: %x",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs inq.inq_tpgs, *mode));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs retval = 1;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (retval);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsvhci_tpgs_page83(struct scsi_address *ap, struct buf *bp,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int *rel_tgt_port, int *tgt_port, int *lu)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs char *ptr, *end;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct scsi_pkt *pkt;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs char *bufp;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs unsigned int buf_len, rx_bsize;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * lets start the buf size with 512 bytes. If this
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * if found to be insufficient, we can allocate
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * appropriate size in the next iteration.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs buf_len = 512;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsonce_again:
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bufp = kmem_zalloc(buf_len, KM_NOSLEEP);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (bufp == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_tpgs_page83: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "request packet allocation for %d failed....",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs buf_len));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_un.b_addr = bufp;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_flags = B_READ;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_bcount = buf_len;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_resid = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt = scsi_init_pkt(ap, NULL, bp, CDB_GROUP0,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs sizeof (struct scsi_arq_status), 0, 0, NULL, NULL);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (pkt == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_page83: Failure returned from scsi_init_pkt"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, buf_len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[0] = SCMD_INQUIRY;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[1] = 0x1;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[2] = 0x83;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[3] = (unsigned char)((buf_len >> 8) & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[4] = (unsigned char)(buf_len & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_time = 90;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (vhci_do_scsi_cmd(pkt) == 0) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_page83: vhci_do_scsi_cmd failed\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, buf_len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Now lets check if the size that was provided was
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * sufficient. If not, allocate the appropriate size
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * and retry the command again.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rx_bsize = (((bufp[2] & 0xff) << 8) | (bufp[3] & 0xff));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rx_bsize += 4;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (rx_bsize > buf_len) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Need to allocate more buf and retry again
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_tpgs_page83: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "bufsize: %d greater than allocated buf: %d\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rx_bsize, buf_len));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "Retrying for size %d\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rx_bsize));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, buf_len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs buf_len = (unsigned int)(rx_bsize);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs goto once_again;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr = bufp;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr += 4; /* identification descriptor 0 */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs end = bufp + rx_bsize;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs while (ptr < end) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "vhci_tpgs_page83: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "desc[1/4/5/6/7]:%x %x %x %x %x\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr[1], ptr[4], ptr[5], ptr[6], ptr[7]));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if ((ptr[1] & 0x0f) == 0x04) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *rel_tgt_port = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *rel_tgt_port |= ((ptr[6] & 0xff) << 8);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *rel_tgt_port |= (ptr[7] & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_page83: relative target port: %x\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *rel_tgt_port));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if ((ptr[1] & 0x0f) == 0x05) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *tgt_port = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *tgt_port = ((ptr[6] & 0xff) << 8);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *tgt_port |= (ptr[7] & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_page83: target port: %x\n", *tgt_port));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if ((ptr[1] & 0x0f) == 0x06) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *lu = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *lu |= ((ptr[6] & 0xff)<< 8);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *lu |= (ptr[7] & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_page83: logical unit: %x\n", *lu));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr += ptr[3] + 4; /* next identification descriptor */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, buf_len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#ifdef DEBUG
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic void
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsprint_buf(char *buf, int buf_size)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int i = 0, j;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int loop, left;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs loop = buf_size / 8;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs left = buf_size % 8;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL, "!buf_size: %x loop: %x left: %x",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs buf_size, loop, left));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs for (j = 0; j < loop; j++) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!buf[%d-%d]: %x %x %x %x %x %x %x %x",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs i, i + 7, buf[i], buf[i+1], buf[i+2], buf[i+3],
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs buf[i+4], buf[i+5], buf[i+6], buf[i+7]));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs i += 8;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (left) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_CONT, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "NOTICE: buf[%d-%d]:", i, i + left));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs for (j = 0; j < left; j++) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_CONT, NULL, " %x", buf[i + j]));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_CONT, NULL, "\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#endif
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsvhci_tpgs_report_target_groups(struct scsi_address *ap, struct buf *bp,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int rel_tgt_port, int tgt_port, int *pstate, int *preferred)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs struct scsi_pkt *pkt;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs char *ptr, *end, *bufp, *mpapi_ptr;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs unsigned int rtpg_len = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs unsigned int l_tgt_port = 0, tpgs_state = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs unsigned int tgt_port_cnt = 0, lr_tgt_port = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int i, len;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Start with buffer size of 512.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * If this is found to be insufficient, required size
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * will be allocated and the command will be retried.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs len = 512;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstry_again:
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bufp = kmem_zalloc(len, KM_NOSLEEP);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (bufp == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_WARN, NULL, "!vhci_tpgs_report_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " request packet allocation for %d failed....", len));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_un.b_addr = bufp;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_flags = B_READ;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_bcount = len;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs bp->b_resid = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt = scsi_init_pkt(ap, NULL, bp, CDB_GROUP5,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs sizeof (struct scsi_arq_status), 0, 0, NULL, NULL);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (pkt == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_report_target_groups: scsi_init_pkt error\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[0] = SCMD_MAINTENANCE_IN;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[1] = SSVC_ACTION_GET_TARGET_PORT_GROUPS;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[6] = ((len >> 24) & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[7] = ((len >> 16) & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[8] = ((len >> 8) & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[9] = len & 0xff;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_time = 90;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_report_target_groups: sending target port group:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " cdb[6/7/8/9]: %x/%x/%x/%x\n", pkt->pkt_cdbp[6],
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pkt->pkt_cdbp[7], pkt->pkt_cdbp[8], pkt->pkt_cdbp[9]));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (vhci_do_scsi_cmd(pkt) == 0) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL, "!vhci_tpgs_report_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " vhci_do_scsi_cmd failed\n"));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr = bufp;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL, "!vhci_tpgs_report_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " returned from target"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " port group: buf[0/1/2/3]: %x/%x/%x/%x\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr[0], ptr[1], ptr[2], ptr[3]));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rtpg_len = (unsigned int)((0xff & ptr[0]) << 24);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rtpg_len |= (unsigned int)((0xff & ptr[1]) << 16);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rtpg_len |= (unsigned int)((0xff & ptr[2]) << 8);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rtpg_len |= (unsigned int)(0xff & ptr[3]);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rtpg_len += 4;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (rtpg_len > len) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL, "!vhci_tpgs_report_target_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " bufsize: %d greater than allocated buf: %d\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rtpg_len, len));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL, "Retrying for size %d\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rtpg_len));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs len = (unsigned int)(rtpg_len + 1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs goto try_again;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#ifdef DEBUG
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs print_buf(bufp, rtpg_len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#endif
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs end = ptr + rtpg_len;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr += 4;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs while (ptr < end) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs mpapi_ptr = ptr;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs l_tgt_port = ((ptr[2] & 0xff) << 8) + (ptr[3] & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tpgs_state = ptr[0] & 0x0f;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tgt_port_cnt = (ptr[7] & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL, "!vhci_tpgs_report_tgt_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " tpgs state: %x"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " tgt_group: %x count: %x\n", tpgs_state,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs l_tgt_port, tgt_port_cnt));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr += 8;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs for (i = 0; i < tgt_port_cnt; i++) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs lr_tgt_port = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs lr_tgt_port |= ((ptr[2] & 0Xff) << 8);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs lr_tgt_port |= (ptr[3] & 0xff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if ((lr_tgt_port == rel_tgt_port) &&
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs (l_tgt_port == tgt_port)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_report_tgt_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " found tgt_port: %x rel_tgt_port:%x"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " tpgs_state: %x\n", tgt_port, rel_tgt_port,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tpgs_state));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * once we have the preferred flag
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * and a non-optimized state flag
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * we will get preferred flag from the
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * report target groups
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (tpgs_state == STD_ACTIVE_OPTIMIZED) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *pstate = STD_ACTIVE_OPTIMIZED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *preferred = PCLASS_PREFERRED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if (tpgs_state ==
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs STD_ACTIVE_NONOPTIMIZED) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *pstate = STD_ACTIVE_NONOPTIMIZED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *preferred = PCLASS_NONPREFERRED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if (tpgs_state == STD_STANDBY) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *pstate = STD_STANDBY;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *preferred = PCLASS_NONPREFERRED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *pstate = STD_UNAVAILABLE;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *preferred = PCLASS_NONPREFERRED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
b1a03ab1e63a57c5b968c229e2f36c79d2fdd222Victor Li vhci_mpapi_update_tpg_data(ap, mpapi_ptr,
b1a03ab1e63a57c5b968c229e2f36c79d2fdd222Victor Li rel_tgt_port);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(4, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!vhci_tpgs_report_tgt_groups:"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs " tgt_port: %x rel_tgt_port:%x\n", tgt_port,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rel_tgt_port));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ptr += 4;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *pstate = SCSI_PATH_INACTIVE;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *preferred = PCLASS_NONPREFERRED;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(1, (CE_NOTE, NULL, "!vhci_tpgs_report_tgt_groups: "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "NO rel_TGTPRT MATCH!!! Assigning Default: state: %x "
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "preferred: %d\n", *pstate, *preferred));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs kmem_free((void *)bufp, len);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs scsi_destroy_pkt(pkt);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}