]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/scsi/IOSCSICommand_Reference.h
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / IOKit / scsi / IOSCSICommand_Reference.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23
24/*!
25@header IOSCSICommand_Reference.h
26
27This header defines the IOSCSICommand class.
28
29This class encapsulates a SCSI Command. The client driver allocates a
30command using IOSCSIDevice::allocCommand() and initializes it using
31functions of this class. The client can then submit the command to
32the SCSI stack by invoking the execute() function.
33*/
34
35
36/*!
37@enum SCSICDBFlags
38Defines values for the cdbFlags field in the SCSICDBInfo structure.
39@constant kCDBFNoDisconnect
40Set by the IOSCSIDevice client to indicate the target may not disconnect
41during the execution of this IOSCSICommand.
42@constant kCDBFlagsDisableParity
43Set by the IOSCSIController class to tell the host adapter driver to disable
44parity checking during the execution of this CDB.
45@constant kCDBFlagsNoDisconnect
46Set by the IOSCSIController class to tell the host adapter driver that the
47target may not disconnect during the execution of this IOSCSICommand.
48@constant kCDBFlagsNegotiateSDTR
49Set by the IOSCSIController class to tell the host adapter driver that it
50should initiate synchronous data transfer negotiation during this IOSCSICommand.
51@constant kCDBFlagsNegotiateWDTR
52Set by the IOSCSIController class to tell the host adapter driver that it
53should initiate wide data transfer negotiation during this IOSCSICommand.
54*/
55enum SCSICDBFlags {
56 kCDBFNoDisconnect = 0x00000001,
57
58/*
59 * Note: These flags are for IOSCSIController subclasses only
60 */
61 kCDBFlagsDisableParity = 0x08000000,
62 kCDBFlagsNoDisconnect = 0x10000000,
63 kCDBFlagsNegotiateSDTR = 0x20000000,
64 kCDBFlagsNegotiateWDTR = 0x40000000,
65};
66
67
68/*!
69@enum SCSIAdapterStatus
70Defines the values of the adapterStatus field of the SCSIResults structure.
71@constant kSCSIAdapterStatusSuccess
72Request completed with no adapter reported errors.
73@constant kSCSIAdapterStatusProtocolError
74Violation of SCSI protocol detected by host adapter.
75@constant kSCSIAdapterStatusSelectionTimeout
76Target device did not respond to selection.
77@constant kSCSIAdapterStatusMsgReject
78Adapter received a msg reject from the target device.
79@constant kSCSIAdapterStatusParityError
80Adapter detected, or target reported a parity error during the
81IOSCSICommand.
82@constant kSCSIAdapterStatusOverrun
83Target device requested more data than supplied by host.
84*/
85enum SCSIAdapterStatus {
86 kSCSIAdapterStatusSuccess = 0,
87 kSCSIAdapterStatusProtocolError,
88 kSCSIAdapterStatusSelectionTimeout,
89 kSCSIAdapterStatusMsgReject,
90 kSCSIAdapterStatusParityError,
91 kSCSIAdapterStatusOverrun,
92};
93
94
95/*!
96@typedef SCSICDBInfo
97@discussion
98Fields specified here are set by IOSCSIDevice client, while others
99are set by the IOSCSIController class for use by the host adapter
100driver. The client should zero all fields of the structure prior
101to use.
102@field cdbFlags
103See enum SCSICDBFlags for flag definitions.
104@field cdbTagMsg
105This field should be set to zero by the IOSCSIDevice client. If the
106SCSI device supports tag queuing then the IOSCSIController class
107will set this field to select simple (unordered) tags.
108@field cdbTag
109This field is set by the IOSCSIController class to tell the host
110adapter driver the SCSI tag value to assign to this IOSCSICommand.
111@field cdbLength
112Set by the IOSCSIDevice client to the length of the Command Descriptor
113Block (CDB).
114@field cdb
115Set by the IOSCSIDevice client to command descriptor block the client
116wishes the target to execute.
117*/
118typedef struct SCSICDBInfo {
119
120 UInt32 cdbFlags;
121
122 UInt32 cdbTagMsg;
123 UInt32 cdbTag;
124
125 UInt32 cdbAbortMsg;
126
127 UInt32 cdbLength;
128 UInt8 cdb[16];
129
130 UInt32 reserved[16];
131} SCSICDBInfo;
132
133
134/*!
135@typedef SCSIResults
136@field returnCode
137The overall return code for the command. See iokit/iokit/IOReturn.h.
138This value is also returned as the getResults() return value.
139
140Note: The SCSI Family will automatically generate standard return codes
141based on the values in the adapterStatus and scsiStatus fields. Unless
142the IOSCSIController subclass needs set a specific return code, it should
143leave this field set to zero.
144@field bytesTransferred
145The total number of bytes transferred to/from the target device.
146@field adapterStatus
147The IOSCSIController subclass must fill-in this field as appropriate.
148See enum SCSIAdapterStatus.
149@field scsiStatus
150The SCSI Status byte returned from the target device.
151@field requestSenseDone
152A boolean indicating whether sense data was obtained from the target
153device.
154@field requestSenseLength
155The number of sense data bytes returned from the target device.
156*/
157typedef struct SCSIResults {
158 IOReturn returnCode;
159
160 UInt32 bytesTransferred;
161
162 enum SCSIAdapterStatus adapterStatus;
163 UInt8 scsiStatus;
164
165 bool requestSenseDone;
166 UInt32 requestSenseLength;
167} SCSIResults;
168
169
170/*!
171@enum SCSIQueueType
172Each IOSCSIDevice has two queues, a normal Q and a bypass Q. The treatment of the
173queues is essentially identical except that the bypass Q is given preference whenever
174it has commands available.
175
176Usually, the client will use the normal Q for regular I/O commands and the bypass Q
177to send error recovery commands to the device.
178@constant kQTypeNormalQ
179Indicates command applies to the normal IOSCSIDevice queue.
180@constant kQTypeBypassQ
181Indicates command applies to the bypass IOSCSIDevice queue.
182*/
183enum SCSIQueueType {
184 kQTypeNormalQ = 0,
185 kQTypeBypassQ = 1,
186};
187
188
189/*!
190@enum SCSIQueuePosition
191Indicates whether a IOSCSICommand should be added to the head or tail
192of the queue selected.
193@constant kQPositionTail
194Queue request at the tail (end) of the selected queue.
195@constant kQPositionHead
196Queue request at the head (front) of the selected queue.
197*/
198enum SCSIQueuePosition {
199 kQPositionTail = 0,
200 kQPositionHead = 1,
201};
202
203
204/*!
205@struct SCSITargetLun
206@field target
207The SCSI Id for the SCSI device being selected.
208@field lun
209The SCSI Lun for the SCSI device being selected.
210*/
211typedef struct SCSITargetLun {
212 UInt8 target;
213 UInt8 lun;
214 UInt8 reserved[2];
215} SCSITargetLun;
216
217/*!
218@class IOSCSICommand : public IOCDBCommand
219@abstract
220Class that describes a SCSI device (target/lun pair).
221@discussion
222This class encapsulates a SCSI Command. The client driver allocates a
223command using IOSCSIDevice::allocCommand() and initializes it using
224functions of this class. The client can then submit the command to
225the SCSI stack by invoking the execute() function.
226*/
227class IOSCSICommand : public IOCDBCommand
228{
229public:
230
231
232/*!
233@function setPointers
234@abstract
235Sets the data buffer component of a SCSI Command.
236@discussion
237The client provides an IOMemoryDescriptor object to corresponding
238to the client's data or request sense buffer, the maximum data transfer count
239and data transfer direction.
240@param desc
241Pointer to a IOMemoryDescriptor describing the client's I/O buffer.
242@param transferCount
243Maximum data transfer count in bytes.
244@param isWrite
245Data transfer direction. (Defined with respect to the device, i.e. isWrite = true
246indicates the host is writing to the device.
247@param isSense
248If isSense is set to false, the IOSCSICommand's data buffer information is set. Otherwise,
249the IOSCSICommand's request sense buffer information is set
250*/
251void setPointers( IOMemoryDescriptor *desc, UInt32 transferCount, bool isWrite, bool isSense=false );
252
253
254/*!
255@function getPointers
256@abstract
257Gets the data buffer component of a SCSI Command.
258@discussion
259The client provides a set of pointers to fields to receive the IOSCSICommand's
260data/request sense buffer pointers.
261@param desc
262Pointer to a field (IOMemoryDescriptor *) to receive the IOSCSICommand's IOMemoryDescriptor pointer.
263@param transferCount
264Pointer to a field (UInt32) to receive the IOSCSICommand's maximum transfer count.
265@param isWrite
266Pointer to a field (bool) to receive the IOSCSICommand's transfer direction.
267@param isSense
268If isSense is set to true, the IOSCSICommand's data buffer information is returned. Otherwise,
269the IOSCSICommand's request sense buffer information is returned.
270*/
271void getPointers( IOMemoryDescriptor **desc, UInt32 *transferCount, bool *isWrite, bool isSense = false );
272
273/*!
274@function setTimeout
275@abstract
276Sets the timeout for the command in milliseconds.
277@discussion
278The IOSCSIController class will abort a command which does not
279complete with in the time interval specified. The client should
280set the timeout parameter to zero if they want to suppress
281timing.
282@param timeout
283Command timeout in milliseconds.
284*/
285void setTimeout( UInt32 timeoutmS );
286
287/*!
288@function getTimeout
289@abstract
290Gets the timeout for the command in milliseconds.
291@discussion
292This function returns the command timeout previously set by setTimeout().
293@param timeout
294Command timeout in milliseconds.
295*/
296UInt32 getTimeout();
297
298
299/*!
300@function setCallback
301@abstract
302Sets the callback routine to be invoked when the SCSI Command completes.
303@param target
304Pointer to the object to be passed to the callback routine. This would usually
305be the client's (this) pointer.
306@param callback
307Pointer to the client's function to process the completed command
308@param refcon
309Pointer to the information required by the client's callback routine to process
310the completed command.
311*/
312void setCallback( void *target = 0, CallbackFn callback = 0, void *refcon = 0 );
313
314
315/*!
316@function getClientData
317@abstract
318Returns a pointer to the SCSI Command's client data area.
319@discussion
320The client may allocate storage in the SCSI Command for its own use.
321See IOSCSIDevice::allocateCmd().
322*/
323void *getClientData();
324
325/*
326@function getCommandData
327@abstract
328Returns a pointer to the SCSI Command's controller data area
329@discussion
330This area is allocated for use by the IOSCSIController subclass (host adapter
331driver). The client should not normally access this area.
332*/
333void *getCommandData();
334
335
336/*!
337@function setCDB
338@abstract
339Sets the CDB component of a SCSI Command.
340@param scsiCDB
341Pointer to a SCSICDBInfo structure.
342*/
343void setCDB( SCSICDBInfo *scsiCmd );
344
345
346/*!
347@function getCDB
348@abstract
349Gets the CDB component of a SCSI Command.
350@param scsiCDB
351Pointer to a SCSICDBInfo structure to receive the SCSI Command's cdb information.
352*/
353void getCDB( SCSICDBInfo *scsiCmd );
354
355
356/*!
357@function getResults
358@abstract
359Gets results from a completed SCSI Command.
360@discussion
361The getResults() function returns the value of the returnCode field of the command results. If
362the client is only interested in a pass/fail indication for the command, the client
363can pass (SCSIResult *)0 as a parameter.
364@param results
365Pointer to a SCSIResults structure to receive the SCSI Commands completion information.
366*/
367IOReturn getResults( SCSIResults *results );
368
369/*!
370@function setResults
371@abstract
372Sets the results component of a SCSI Command.
373@discussion
374The setResults() function is used by the IOSCSIController subclass (host
375adapter driver) return results for a SCSI Command about to be completed.
376@param scsiResults Pointer to a SCSIResults structure containing
377completion information for the SCSI Command.
378
379Completion information is copied into the command, so the caller may
380release the SCSIResults structure provided when this function returns.
381*/
382void setResults( SCSIResults *results );
383
384
385/*!
386@function getDevice
387@abstract
388Returns the IOSCSIDevice this command is targeted to.
389@param deviceType
390The caller should use value kIOSCSIDeviceType.
391@discussion
392In some cases a IOSCSICommand is not associated with a specific target/lun. This
393would be the case for a SCSI Bus Reset. In this case getDevice() returns 0.
394*/
395IOSCSIDevice *getDevice( IOSCSIDevice *deviceType );
396
397
398/*!
399@function getTargetLun
400@abstract
401Returns the target/lun for the IOSCSIDevice this command is associated with.
402@param targetLun
403Pointer to a SCSITargetLun structure to receive the target/lun information.
404*/
405void getTargetLun( SCSITargetLun *targetLun );
406
407
408/*!
409@function execute
410@abstract
411Submits a SCSI command to be executed.
412@discussion
413Once the execute() function is called, the client should not
414invoke any further functions on the SCSI Command with the
415exception of abort().
416
417The execute() function optionally returns sets a unique sequence
418number token for the command. If the client intends to use the abort()
419method they must retain this sequence number token.
420@param sequenceNumber
421Pointer to field (UInt32) to receive the sequence number assigned to the SCSI
422Command.
423*/
424bool execute( UInt32 *sequenceNumber = 0 );
425
426/*!
427@function abort
428@abstract
429Aborts an executing SCSI Command.
430@discussion
431The client may invoke the abort() method to force the completion of an
432executing SCSI Command. The client must pass the sequence number
433provided when the execute() function was invoked.
434
435Note: The abort function provides no status on whether or not a
436command has been successfully aborted. The client should wait for the
437command to actually complete to determine whether the abort completed
438successfully.
439@param sequenceNumber
440The client must pass the sequence number assigned to the command when
441the client called the execute() function.
442*/
443void abort( UInt32 sequenceNumber );
444
445/*!
446@function complete
447@abstract
448Indicates the IOSCSIController subclass (host adapter driver) has completed a SCSI command.
449@discussion
450Once the complete() function is called, the controller
451subclass should make no further accesses to the IOSCSICommand
452being completed.
453
454A IOSCSIDevice client would not normally call this function.
455*/
456void complete();
457
458
459/*!
460@function getSequenceNumber
461@abstract
462Returns the sequence number assigned to an executing command.
463@discussion
464The caller should check the sequence number for 0. This indicates that
465the command has completed or has not been processed to the point where
466a sequence number has been assigned.
467*/
468UInt32 getSequenceNumber();
469
470
471/*!
472@function setQueueInfo
473@abstract
474Sets queuing information for the SCSI Command.
475@discussion
476Each IOSCSIDevice has two queues, a normal Q and a bypass Q. The treatment of the
477queues is esentially identical except that the bypass Q is given preference whenever
478it has commands available.
479
480Usually, the client will use the normal Q for regular I/O commands and the bypass Q
481to send error recovery commands to the device.
482@param queueType
483Set to kQTypeNormalQ or kQTypeBypassQ to indicate which IOSCSIDevice queue the
484SCSI Command should be routed to.
485@param queuePosition
486Set to kQPositionTail or kQPositionHead to indicate whether the SCSI Command should
487be added to the head to tail for the selected IOSCSIDevice queue.
488*/
489void setQueueInfo( UInt32 queueType = kQTypeNormalQ, UInt32 queuePosition = kQPositionTail );
490
491
492/*!
493@function getQueueInfo
494@abstract
495Gets queuing information for the SCSI Command.
496@param queueType
497Pointer to a field (UInt32) to receive the queue type previously set for this SCSI Command.
498@param queuePosition
499Pointer to a field (UInt32) to receive the queue position previously set for this SCSI Command.
500*/
501void getQueueInfo( UInt32 *queueType, UInt32 *queuePosition = 0 );
502
503
504/*!
505@function getCmdType
506@abstract
507Obtains the underlying 'intent' of a SCSI Command.
508@discussion
509This function provides information on the intent of a SCSI
510Command. For example, since Aborts, Request Sense and normal Execute commands are
511all sent to the executeCommand() function, invoking getCmdType()
512will indicate whether a Request Sense, Abort or Normal I/O request is
513being processed.
514
515It this information is not normally meaningful to IOSCSIDevice clients.
516*/
517UInt32 getCmdType();
518
519
520/*!
521@function getOriginalCmd
522@abstract
523Obtains a 'related' SCSI Command.
524@discussion
525In cases where a SCSI command is related to a previous command, this
526function will return the original command. For example, if a
527Request Sense command (CmdType = kSCSICommandReqSense)is processed,
528then this function can be used to obtain the original command that
529caused the check condition. If an Abort command (CmdType =
530kSCSICommandAbort) then this function can be used to obtain the original
531command the abort was issued against.
532
533
534It this information is not normally meaningful to IOSCSIDevice clients.
535*/
536IOSCSICommand *getOriginalCmd();
537
538};