2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 @header IOSCSICommand_Reference.h
27 This header defines the IOSCSICommand class.
29 This class encapsulates a SCSI Command. The client driver allocates a
30 command using IOSCSIDevice::allocCommand() and initializes it using
31 functions of this class. The client can then submit the command to
32 the SCSI stack by invoking the execute() function.
38 Defines values for the cdbFlags field in the SCSICDBInfo structure.
39 @constant kCDBFNoDisconnect
40 Set by the IOSCSIDevice client to indicate the target may not disconnect
41 during the execution of this IOSCSICommand.
42 @constant kCDBFlagsDisableParity
43 Set by the IOSCSIController class to tell the host adapter driver to disable
44 parity checking during the execution of this CDB.
45 @constant kCDBFlagsNoDisconnect
46 Set by the IOSCSIController class to tell the host adapter driver that the
47 target may not disconnect during the execution of this IOSCSICommand.
48 @constant kCDBFlagsNegotiateSDTR
49 Set by the IOSCSIController class to tell the host adapter driver that it
50 should initiate synchronous data transfer negotiation during this IOSCSICommand.
51 @constant kCDBFlagsNegotiateWDTR
52 Set by the IOSCSIController class to tell the host adapter driver that it
53 should initiate wide data transfer negotiation during this IOSCSICommand.
56 kCDBFNoDisconnect
= 0x00000001,
59 * Note: These flags are for IOSCSIController subclasses only
61 kCDBFlagsDisableParity
= 0x08000000,
62 kCDBFlagsNoDisconnect
= 0x10000000,
63 kCDBFlagsNegotiateSDTR
= 0x20000000,
64 kCDBFlagsNegotiateWDTR
= 0x40000000,
69 @enum SCSIAdapterStatus
70 Defines the values of the adapterStatus field of the SCSIResults structure.
71 @constant kSCSIAdapterStatusSuccess
72 Request completed with no adapter reported errors.
73 @constant kSCSIAdapterStatusProtocolError
74 Violation of SCSI protocol detected by host adapter.
75 @constant kSCSIAdapterStatusSelectionTimeout
76 Target device did not respond to selection.
77 @constant kSCSIAdapterStatusMsgReject
78 Adapter received a msg reject from the target device.
79 @constant kSCSIAdapterStatusParityError
80 Adapter detected, or target reported a parity error during the
82 @constant kSCSIAdapterStatusOverrun
83 Target device requested more data than supplied by host.
85 enum SCSIAdapterStatus
{
86 kSCSIAdapterStatusSuccess
= 0,
87 kSCSIAdapterStatusProtocolError
,
88 kSCSIAdapterStatusSelectionTimeout
,
89 kSCSIAdapterStatusMsgReject
,
90 kSCSIAdapterStatusParityError
,
91 kSCSIAdapterStatusOverrun
,
98 Fields specified here are set by IOSCSIDevice client, while others
99 are set by the IOSCSIController class for use by the host adapter
100 driver. The client should zero all fields of the structure prior
103 See enum SCSICDBFlags for flag definitions.
105 This field should be set to zero by the IOSCSIDevice client. If the
106 SCSI device supports tag queuing then the IOSCSIController class
107 will set this field to select simple (unordered) tags.
109 This field is set by the IOSCSIController class to tell the host
110 adapter driver the SCSI tag value to assign to this IOSCSICommand.
112 Set by the IOSCSIDevice client to the length of the Command Descriptor
115 Set by the IOSCSIDevice client to command descriptor block the client
116 wishes the target to execute.
118 typedef struct SCSICDBInfo
{
137 The overall return code for the command. See iokit/iokit/IOReturn.h.
138 This value is also returned as the getResults() return value.
140 Note: The SCSI Family will automatically generate standard return codes
141 based on the values in the adapterStatus and scsiStatus fields. Unless
142 the IOSCSIController subclass needs set a specific return code, it should
143 leave this field set to zero.
144 @field bytesTransferred
145 The total number of bytes transferred to/from the target device.
147 The IOSCSIController subclass must fill-in this field as appropriate.
148 See enum SCSIAdapterStatus.
150 The SCSI Status byte returned from the target device.
151 @field requestSenseDone
152 A boolean indicating whether sense data was obtained from the target
154 @field requestSenseLength
155 The number of sense data bytes returned from the target device.
157 typedef struct SCSIResults
{
160 UInt32 bytesTransferred
;
162 enum SCSIAdapterStatus adapterStatus
;
165 bool requestSenseDone
;
166 UInt32 requestSenseLength
;
172 Each IOSCSIDevice has two queues, a normal Q and a bypass Q. The treatment of the
173 queues is essentially identical except that the bypass Q is given preference whenever
174 it has commands available.
176 Usually, the client will use the normal Q for regular I/O commands and the bypass Q
177 to send error recovery commands to the device.
178 @constant kQTypeNormalQ
179 Indicates command applies to the normal IOSCSIDevice queue.
180 @constant kQTypeBypassQ
181 Indicates command applies to the bypass IOSCSIDevice queue.
190 @enum SCSIQueuePosition
191 Indicates whether a IOSCSICommand should be added to the head or tail
192 of the queue selected.
193 @constant kQPositionTail
194 Queue request at the tail (end) of the selected queue.
195 @constant kQPositionHead
196 Queue request at the head (front) of the selected queue.
198 enum SCSIQueuePosition
{
205 @struct SCSITargetLun
207 The SCSI Id for the SCSI device being selected.
209 The SCSI Lun for the SCSI device being selected.
211 typedef struct SCSITargetLun
{
218 @class IOSCSICommand : public IOCDBCommand
220 Class that describes a SCSI device (target/lun pair).
222 This class encapsulates a SCSI Command. The client driver allocates a
223 command using IOSCSIDevice::allocCommand() and initializes it using
224 functions of this class. The client can then submit the command to
225 the SCSI stack by invoking the execute() function.
227 class IOSCSICommand
: public IOCDBCommand
233 @function setPointers
235 Sets the data buffer component of a SCSI Command.
237 The client provides an IOMemoryDescriptor object to corresponding
238 to the client's data or request sense buffer, the maximum data transfer count
239 and data transfer direction.
241 Pointer to a IOMemoryDescriptor describing the client's I/O buffer.
243 Maximum data transfer count in bytes.
245 Data transfer direction. (Defined with respect to the device, i.e. isWrite = true
246 indicates the host is writing to the device.
248 If isSense is set to false, the IOSCSICommand's data buffer information is set. Otherwise,
249 the IOSCSICommand's request sense buffer information is set
251 void setPointers( IOMemoryDescriptor
*desc
, UInt32 transferCount
, bool isWrite
, bool isSense
=false );
255 @function getPointers
257 Gets the data buffer component of a SCSI Command.
259 The client provides a set of pointers to fields to receive the IOSCSICommand's
260 data/request sense buffer pointers.
262 Pointer to a field (IOMemoryDescriptor *) to receive the IOSCSICommand's IOMemoryDescriptor pointer.
264 Pointer to a field (UInt32) to receive the IOSCSICommand's maximum transfer count.
266 Pointer to a field (bool) to receive the IOSCSICommand's transfer direction.
268 If isSense is set to true, the IOSCSICommand's data buffer information is returned. Otherwise,
269 the IOSCSICommand's request sense buffer information is returned.
271 void getPointers( IOMemoryDescriptor
**desc
, UInt32
*transferCount
, bool *isWrite
, bool isSense
= false );
276 Sets the timeout for the command in milliseconds.
278 The IOSCSIController class will abort a command which does not
279 complete with in the time interval specified. The client should
280 set the timeout parameter to zero if they want to suppress
283 Command timeout in milliseconds.
285 void setTimeout( UInt32 timeoutmS
);
290 Gets the timeout for the command in milliseconds.
292 This function returns the command timeout previously set by setTimeout().
294 Command timeout in milliseconds.
300 @function setCallback
302 Sets the callback routine to be invoked when the SCSI Command completes.
304 Pointer to the object to be passed to the callback routine. This would usually
305 be the client's (this) pointer.
307 Pointer to the client's function to process the completed command
309 Pointer to the information required by the client's callback routine to process
310 the completed command.
312 void setCallback( void *target
= 0, CallbackFn callback
= 0, void *refcon
= 0 );
316 @function getClientData
318 Returns a pointer to the SCSI Command's client data area.
320 The client may allocate storage in the SCSI Command for its own use.
321 See IOSCSIDevice::allocateCmd().
323 void *getClientData();
326 @function getCommandData
328 Returns a pointer to the SCSI Command's controller data area
330 This area is allocated for use by the IOSCSIController subclass (host adapter
331 driver). The client should not normally access this area.
333 void *getCommandData();
339 Sets the CDB component of a SCSI Command.
341 Pointer to a SCSICDBInfo structure.
343 void setCDB( SCSICDBInfo
*scsiCmd
);
349 Gets the CDB component of a SCSI Command.
351 Pointer to a SCSICDBInfo structure to receive the SCSI Command's cdb information.
353 void getCDB( SCSICDBInfo
*scsiCmd
);
359 Gets results from a completed SCSI Command.
361 The getResults() function returns the value of the returnCode field of the command results. If
362 the client is only interested in a pass/fail indication for the command, the client
363 can pass (SCSIResult *)0 as a parameter.
365 Pointer to a SCSIResults structure to receive the SCSI Commands completion information.
367 IOReturn
getResults( SCSIResults
*results
);
372 Sets the results component of a SCSI Command.
374 The setResults() function is used by the IOSCSIController subclass (host
375 adapter driver) return results for a SCSI Command about to be completed.
376 @param scsiResults Pointer to a SCSIResults structure containing
377 completion information for the SCSI Command.
379 Completion information is copied into the command, so the caller may
380 release the SCSIResults structure provided when this function returns.
382 void setResults( SCSIResults
*results
);
388 Returns the IOSCSIDevice this command is targeted to.
390 The caller should use value kIOSCSIDeviceType.
392 In some cases a IOSCSICommand is not associated with a specific target/lun. This
393 would be the case for a SCSI Bus Reset. In this case getDevice() returns 0.
395 IOSCSIDevice
*getDevice( IOSCSIDevice
*deviceType
);
399 @function getTargetLun
401 Returns the target/lun for the IOSCSIDevice this command is associated with.
403 Pointer to a SCSITargetLun structure to receive the target/lun information.
405 void getTargetLun( SCSITargetLun
*targetLun
);
411 Submits a SCSI command to be executed.
413 Once the execute() function is called, the client should not
414 invoke any further functions on the SCSI Command with the
415 exception of abort().
417 The execute() function optionally returns sets a unique sequence
418 number token for the command. If the client intends to use the abort()
419 method they must retain this sequence number token.
420 @param sequenceNumber
421 Pointer to field (UInt32) to receive the sequence number assigned to the SCSI
424 bool execute( UInt32
*sequenceNumber
= 0 );
429 Aborts an executing SCSI Command.
431 The client may invoke the abort() method to force the completion of an
432 executing SCSI Command. The client must pass the sequence number
433 provided when the execute() function was invoked.
435 Note: The abort function provides no status on whether or not a
436 command has been successfully aborted. The client should wait for the
437 command to actually complete to determine whether the abort completed
439 @param sequenceNumber
440 The client must pass the sequence number assigned to the command when
441 the client called the execute() function.
443 void abort( UInt32 sequenceNumber
);
448 Indicates the IOSCSIController subclass (host adapter driver) has completed a SCSI command.
450 Once the complete() function is called, the controller
451 subclass should make no further accesses to the IOSCSICommand
454 A IOSCSIDevice client would not normally call this function.
460 @function getSequenceNumber
462 Returns the sequence number assigned to an executing command.
464 The caller should check the sequence number for 0. This indicates that
465 the command has completed or has not been processed to the point where
466 a sequence number has been assigned.
468 UInt32
getSequenceNumber();
472 @function setQueueInfo
474 Sets queuing information for the SCSI Command.
476 Each IOSCSIDevice has two queues, a normal Q and a bypass Q. The treatment of the
477 queues is esentially identical except that the bypass Q is given preference whenever
478 it has commands available.
480 Usually, the client will use the normal Q for regular I/O commands and the bypass Q
481 to send error recovery commands to the device.
483 Set to kQTypeNormalQ or kQTypeBypassQ to indicate which IOSCSIDevice queue the
484 SCSI Command should be routed to.
486 Set to kQPositionTail or kQPositionHead to indicate whether the SCSI Command should
487 be added to the head to tail for the selected IOSCSIDevice queue.
489 void setQueueInfo( UInt32 queueType
= kQTypeNormalQ
, UInt32 queuePosition
= kQPositionTail
);
493 @function getQueueInfo
495 Gets queuing information for the SCSI Command.
497 Pointer to a field (UInt32) to receive the queue type previously set for this SCSI Command.
499 Pointer to a field (UInt32) to receive the queue position previously set for this SCSI Command.
501 void getQueueInfo( UInt32
*queueType
, UInt32
*queuePosition
= 0 );
507 Obtains the underlying 'intent' of a SCSI Command.
509 This function provides information on the intent of a SCSI
510 Command. For example, since Aborts, Request Sense and normal Execute commands are
511 all sent to the executeCommand() function, invoking getCmdType()
512 will indicate whether a Request Sense, Abort or Normal I/O request is
515 It this information is not normally meaningful to IOSCSIDevice clients.
521 @function getOriginalCmd
523 Obtains a 'related' SCSI Command.
525 In cases where a SCSI command is related to a previous command, this
526 function will return the original command. For example, if a
527 Request Sense command (CmdType = kSCSICommandReqSense)is processed,
528 then this function can be used to obtain the original command that
529 caused the check condition. If an Abort command (CmdType =
530 kSCSICommandAbort) then this function can be used to obtain the original
531 command the abort was issued against.
534 It this information is not normally meaningful to IOSCSIDevice clients.
536 IOSCSICommand
*getOriginalCmd();