4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
31 #include "Exceptions.h"
35 #define BUSY_SLEEP 1000 /* 1/100 second */
36 #define BUSY_RETRY_TIMER 5000000000ULL /* Retry for 5 seconds */
42 * @memo Send a read capacity to a remote WWN
43 * @return HBA_STATUS_OK or other error code
44 * scsiStatus should be checked to ensure SCSI command
46 * @param handle The HBA to operate on
47 * @param portWWN Indicates the HBA port to send command through
48 * @param targetPortWWN Indicates the target to send command to
49 * @param fcLun Indicates the target unit to send command to
50 * @param responseBuffer User-allocated response buffer
51 * @param responseSize Size of User-allocated response buffer
52 * @param scsiStatus User-allocated scsi status byte
54 * @doc This routine will attempt a limited number of retries
55 * When busy or again errors are encountered.
58 Sun_fcScsiReadCapacityV2(HBA_HANDLE handle
, HBA_WWN portWWN
,
59 HBA_WWN targetPortWWN
, HBA_UINT64 fcLun
,
60 void *responseBuffer
, HBA_UINT32
*responseSize
,
61 HBA_UINT8
*scsiStatus
,
62 void *senseBuffer
, HBA_UINT32
*senseSize
) {
63 Trace
log("Sun_fcScsiReadCapacityV2");
65 hrtime_t start
= gethrtime();
66 hrtime_t end
= start
+ BUSY_RETRY_TIMER
;
67 for (hrtime_t cur
= start
; cur
< end
; cur
= gethrtime()) {
69 Handle
*myHandle
= Handle::findHandle(handle
);
70 HBA
*hba
= myHandle
->getHBA();
71 HBAPort
*port
= hba
->getPort(wwnConversion(portWWN
.wwn
));
72 port
->sendReadCapacity(wwnConversion(targetPortWWN
.wwn
),
73 fcLun
, responseBuffer
, responseSize
, scsiStatus
,
74 senseBuffer
, senseSize
);
75 return (HBA_STATUS_OK
);
76 } catch (BusyException
&e
) {
79 } catch (TryAgainException
&e
) {
82 } catch (HBAException
&e
) {
83 return (e
.getErrorCode());
86 "Uncaught exception");
87 return (HBA_STATUS_ERROR
);