2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A
2N/A
2N/A#include "Trace.h"
2N/A#include "Handle.h"
2N/A#include "HBA.h"
2N/A#include "HBAPort.h"
2N/A#include "Exceptions.h"
2N/A#include "sun_fc.h"
2N/A#include <unistd.h>
2N/A
2N/A#define BUSY_SLEEP 1000000 /* 1/100 second */
2N/A#define BUSY_RETRY_TIMER 5000000000ULL /* Retry for 5 seconds */
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A/**
2N/A * @memo Send a SCSI inquiry to a remote WWN
2N/A * @return HBA_STATUS_OK or other error code
2N/A * scsiStatus should be checked to ensure SCSI command
2N/A * was a success.
2N/A * @param handle The HBA to operate on
2N/A * @param portWWN Indicates the HBA port to send command through
2N/A * @param targetPortWWN Indicates the target to send command to
2N/A * @param fcLun Indicates the target unit to send command to
2N/A * @param cdb1 The first CDB byte
2N/A * @param cdb2 The second CDB byte
2N/A * @param responseBuffer User-allocated response buffer
2N/A * @param responseSize Size of User-allocated response buffer
2N/A * @param scsiStatus User-allocated scsi status byte
2N/A *
2N/A * @doc This routine will attempt a limited number of retries
2N/A * When busy or again errors are encountered.
2N/A */
2N/AHBA_STATUS
2N/ASun_fcScsiInquiryV2(HBA_HANDLE handle, HBA_WWN portWWN, HBA_WWN targetPortWWN,
2N/A HBA_UINT64 fcLun, HBA_UINT8 cdb1, HBA_UINT8 cdb2,
2N/A void *responseBuffer, HBA_UINT32 *responseSize,
2N/A HBA_UINT8 *scsiStatus,
2N/A void *senseBuffer, HBA_UINT32 *senseSize) {
2N/A Trace log("Sun_fcScsiInquiryV2");
2N/A
2N/A hrtime_t start = gethrtime();
2N/A hrtime_t end = start + BUSY_RETRY_TIMER;
2N/A for (hrtime_t cur = start; cur < end; cur = gethrtime()) {
2N/A try {
2N/A Handle *myHandle = Handle::findHandle(handle);
2N/A HBA *hba = myHandle->getHBA();
2N/A HBAPort *port = hba->getPort(wwnConversion(portWWN.wwn));
2N/A
2N/A port->sendScsiInquiry(wwnConversion(targetPortWWN.wwn), fcLun,
2N/A cdb1, cdb2, responseBuffer, responseSize,
2N/A scsiStatus, senseBuffer, senseSize);
2N/A return (HBA_STATUS_OK);
2N/A } catch (BusyException &e) {
2N/A usleep(BUSY_SLEEP);
2N/A continue;
2N/A } catch (TryAgainException &e) {
2N/A usleep(BUSY_SLEEP);
2N/A continue;
2N/A } catch (HBAException &e) {
2N/A return (e.getErrorCode());
2N/A } catch (...) {
2N/A log.internalError(
2N/A "Uncaught exception");
2N/A return (HBA_STATUS_ERROR);
2N/A }
2N/A }
2N/A}
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif