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 */
9a70fc3be3b1e966bf78825cdb8d509963a6f0a1Mark J. Nelson
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Use is subject to license terms.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Implementation of "scsi_vhci_f_tape" tape failover_ops.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * This file was historically meant for only tape implementation. It has
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * been extended to manage SUN "supported" tape controllers. The supported
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * VID/PID shall be listed in the tape_dev_table.
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
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* Supported device table entries. */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic char *tape_dev_table[] = {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* " 111111" */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* "012345670123456789012345" */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* "|-VID--||-----PID------|" */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "IBM ULTRIUM-TD3",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "IBM ULTRIUM-TD4",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs NULL
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs};
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* Failover module plumbing. */
9a70fc3be3b1e966bf78825cdb8d509963a6f0a1Mark J. NelsonSCSI_FAILOVER_OP("f_tape", tape);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstape_device_probe(struct scsi_device *sd, struct scsi_inquiry *inquiry,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs void **ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int i;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int rval = SFO_DEVICE_PROBE_PHCI;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL, "!tape_device_probe: inquiry string %s\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs inquiry->inq_vid));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * See if this a device type that we want to care about.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs switch (inquiry->inq_dtype & DTYPE_MASK) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs case DTYPE_SEQUENTIAL:
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs break;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs case DTYPE_CHANGER:
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rval = SFO_DEVICE_PROBE_VHCI;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs goto done;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs default:
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Not interested.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (rval);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * If it reports that it supports tpgs and it got here it may have
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * failed the tpgs commands. It might or might not support dual port
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * but we'll go with it.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (inquiry->inq_tpgs) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL, "!has tpgs bits: %s\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs inquiry->inq_vid));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rval = SFO_DEVICE_PROBE_VHCI;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if (inquiry->inq_dualp) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Looks like it claims to have more then one port.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL, "!has dual port bits: %s\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs inquiry->inq_vid));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rval = SFO_DEVICE_PROBE_VHCI;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * See if this device is on the list.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs for (i = 0; tape_dev_table[i]; i++) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (strncmp(inquiry->inq_vid, tape_dev_table[i],
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs strlen(tape_dev_table[i])) == 0) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "!was on the list: %s\n",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs inquiry->inq_vid));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs rval = SFO_DEVICE_PROBE_VHCI;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs break;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsdone:
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (rval == SFO_DEVICE_PROBE_VHCI) {
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs /*
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs * Policy only applies to 'client' probe, not
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs * vhci_is_dev_supported() pHCI probe. Detect difference
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs * based on ctpriv.
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs */
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs if (ctpriv &&
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs (mdi_set_lb_policy(sd->sd_dev, LOAD_BALANCE_NONE) !=
55e592a20765db6f52a590785ae2390c3b12fda9Randall Ralphs MDI_SUCCESS)) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs VHCI_DEBUG(6, (CE_NOTE, NULL, "!fail load balance none"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ": %s\n", inquiry->inq_vid));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (SFO_DEVICE_PROBE_PHCI);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (rval);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic void
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstape_device_unprobe(struct scsi_device *sd, void *ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * NO OP for tape.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstape_path_activate(struct scsi_device *sd, char *pathclass, void *ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstape_path_deactivate(struct scsi_device *sd, char *pathclass, void *ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstape_path_get_opinfo(struct scsi_device *sd, struct scsi_path_opinfo *opinfo,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs void *ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs opinfo->opinfo_rev = OPINFO_REV;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs (void) strcpy(opinfo->opinfo_path_attr, PCLASS_PRIMARY);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs opinfo->opinfo_path_state = SCSI_PATH_ACTIVE;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs opinfo->opinfo_pswtch_best = 0; /* N/A */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs opinfo->opinfo_pswtch_worst = 0; /* N/A */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs opinfo->opinfo_xlf_capable = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs opinfo->opinfo_mode = SCSI_NO_FAILOVER;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs opinfo->opinfo_preferred = 1;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstape_path_ping(struct scsi_device *sd, void *ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (1);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0c45178b5714d692c44817c2235320c3f2b030abwltape_analyze_sense(struct scsi_device *sd, uint8_t *sense,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs void *ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0c45178b5714d692c44817c2235320c3f2b030abwl uint8_t skey, asc, ascq;
0c45178b5714d692c44817c2235320c3f2b030abwl
0c45178b5714d692c44817c2235320c3f2b030abwl skey = scsi_sense_key(sense);
0c45178b5714d692c44817c2235320c3f2b030abwl asc = scsi_sense_asc(sense);
0c45178b5714d692c44817c2235320c3f2b030abwl ascq = scsi_sense_ascq(sense);
0c45178b5714d692c44817c2235320c3f2b030abwl
0c45178b5714d692c44817c2235320c3f2b030abwl if (skey == KEY_ABORTED_COMMAND &&
0c45178b5714d692c44817c2235320c3f2b030abwl asc == 0x4b &&
0c45178b5714d692c44817c2235320c3f2b030abwl ascq == 0x83) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (SCSI_SENSE_INACTIVE);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0c45178b5714d692c44817c2235320c3f2b030abwl if (skey == KEY_NOT_READY &&
0c45178b5714d692c44817c2235320c3f2b030abwl asc == 0x4 &&
0c45178b5714d692c44817c2235320c3f2b030abwl ascq == 0x1) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (SCSI_SENSE_NOT_READY);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (SCSI_SENSE_NOFAILOVER);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/* ARGSUSED */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic int
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphstape_pathclass_next(char *cur, char **nxt, void *ctpriv)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (cur == NULL) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *nxt = PCLASS_PRIMARY;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (0);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else if (strcmp(cur, PCLASS_PRIMARY) == 0) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (ENOENT);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return (EINVAL);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}