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 IOSCSIController_Reference.h
27 This header defines the IOSCSIController class.
29 IOSCSIController provides the superclass for SCSI host
32 Drivers are instantiated based on their 'personality' entry matching
33 their adapter's OpenFirmware device tree entry. When a match occurs,
34 the driver's class is instantiated. Since the driver is written as a
35 subclass of IOSCSIController, an instance of the SCSI Family is automatically
41 @typedef SCSIControllerInfo
42 Parameter structure passed for configure() function.
44 The SCSI address of your host adapter. Usually 7 (decimal).
45 @field maxTargetsSupported
46 The number of targets you controller supports. Typically 8 or 16.
47 @field maxLunsSupported
48 The number of logical units per target your controller supports.
50 @field minTransferPeriodpS
51 The minimum synchronous data transfer period in picoseconds your
53 @field maxTransferOffset
54 The maximum synchronous data offset your controller supports in bytes.
55 @field maxTransferWidth
56 The maximum data SCSI bus width your controller supports in bytes. Must
58 @field maxCommandsPerController
59 The maximum number of outstanding commands your controller supports
60 across all targets and luns. Set to 0 if there is no controller limit in
62 @field maxCommandsPerTarget
63 The maximum number of outstanding commands your controller supports on a
64 given target. Set to 0 if there is no controller limit in this category.
65 @field maxCommandsPerLun
66 The maximum number of outstanding commands your controller supports on a
67 given lun. Set to 0 if there is no controller limit in this category.
68 @field tagAllocationMethod
69 Controls whether tags are allocated on a per Lun, per Target or per
70 Controller basis. See enum SCSITagAllocation.
72 The maximum number of tags allocated to each Lun, Target or Controller
73 depending on the tagAllocationMethod setting.
74 @field targetPrivateDataSize
75 IOSCSIController will optionally allocate per-target storage for your
76 driver based on the setting of this field. The amount of storage needed
77 is specified in bytes.
78 @field lunPrivateDataSize
79 IOSCSIController will optionally allocate per-lun storage for your
80 driver based on the setting of this field. The amount of storage needed
81 is specified in bytes.
82 @field commandPrivateDataSize
83 IOSCSIController will optionally allocate per-command storage for your
84 driver based on the setting of this field. The amount of storage needed
85 is specified in bytes.
87 Note: The amount of per-command storage allowed is under review. We
88 anticipate that typical SCSI controllers will need not more than 1024
90 @field disableCancelCommands
91 Subclasses of IOSCSIController which do their own management of
92 aborts/resets can set this field to true to avoid receiving
93 cancelCommand() requests.
95 typedef struct SCSIControllerInfo
{
98 UInt32 maxTargetsSupported
;
99 UInt32 maxLunsSupported
;
101 UInt32 minTransferPeriodpS
;
102 UInt32 maxTransferOffset
;
103 UInt32 maxTransferWidth
;
105 UInt32 maxCommandsPerController
;
106 UInt32 maxCommandsPerTarget
;
107 UInt32 maxCommandsPerLun
;
109 UInt32 tagAllocationMethod
;
112 UInt32 targetPrivateDataSize
;
113 UInt32 lunPrivateDataSize
;
114 UInt32 commandPrivateDataSize
;
116 bool disableCancelCommands
;
120 } SCSIControllerInfo
;
124 @enum SCSITagAllocation
126 This enum defines how SCSI tags are allocated.
127 @constant kTagAllocationNone
128 This controller does not support tag queuing.
129 @constant kTagAllocationPerLun
130 Each SCSI Lun has its own private tag pool containing
132 @constant kTagAllocationPerTarget
133 Each SCSI Target has its own private tag pool contain
134 (maxTags) SCSI tags. Luns connected to this target
135 allocate tags from this pool.
136 @constant kTagAllocationPerController
137 The controller has a global tag pool containing (maxTags)
138 SCSI tags. This pool is shared by all Luns connected to
142 kTagAllocationNone
= 0,
143 kTagAllocationPerLun
,
144 kTagAllocationPerTarget
,
145 kTagAllocationPerController
,
150 @class IOSCSIController : public IOService
152 Superclass for SCSI host adapter drivers
154 The IOSCSIController class provides a number of services to simplify
155 writing a driver for your host adapter.
157 Specifically, the class provides the following features:
159 1. Complete request scheduling semantics.
161 The IOSCSIController class manages request queues on behalf of its
162 subclasses. It tracks all requests submitted to its subclasses,
163 including managing timeouts, aborts and request cancellations.
165 2. Request Sense scheduling
167 Subclasses of IOSCSIController do not need to implement
168 auto-request-sense functionality. Your driver can use the default
169 handling in the super class.
171 3. Storage management.
173 The IOSCSIController subclass provides per-request private storage areas
176 4. Resource management.
178 The IOSCSIController subclass will manage the number of outstanding
179 commands submitted to your subclass on a per-controller and per-lun
182 @
class IOSCSIController
: public IOService
190 Driver configuration/initialization request.
192 The configure() member function is the first call your subclass will
193 receive. You should provide the information requested in the
194 SCSIControllerInfo structure and enable your hardware for operation.
195 If your driver initialized successfully, you should return true, otherwise,
196 your driver should return false.
198 Pointer to an object (usually IOPCIDevice) which represents the bus of
199 your device is attached to . Typically your driver will use functions
200 supplied by this object to access PCI space on your hardware. See
201 IOPCIDevice for a description of PCI services.
202 @param controllerInfo
203 Pointer to a SCSIControllerInfo structure. Your driver should provide
204 the information requested in this structure prior to returning from
205 the configure() call.
207 bool configure( IOService
*provider
, SCSIControllerInfo
*controllerInfo
);
211 @function executeCommand
213 Execute a IOSCSICommand.
215 The executeCommand() function is called for all 'routine' I/O requests
216 including abort requests. The driver is passed a pointer to an
217 IOSCSICommand object. The driver obtains information about the I/O
218 request by using function calls provided by the IOSCSICommand
221 Pointer to a IOSCSICommand. See IOSCSICommand for more information.
223 void executeCommand( IOSCSICommand
*scsiCommand
);
227 @function cancelCommand
229 Cancels a IOSCSICommand previously submitted to the driver.
231 The cancelCommand() function is called to inform your subclass to force
232 completion of a SCSI command.
234 Your subclass should call the getOriginalCmd() to determine the command
237 After calling complete() on the original command, you should complete
238 the IOSCSICommand passed to the cancelCommand() function
240 Note: When a cancelCommand is issued, your subclass may presume that any
241 activity to remove an active command from the SCSI Target, i.e. (abort
242 tag/abort) has already occurred.
244 Pointer to a IOSCSICommand. See IOSCSICommand for more information.
246 void cancelCommand( IOSCSICommand
*scsiCommand
);
250 @function resetCommand
252 Request the driver issue a SCSI Bus reset.
254 The resetCommand() function indicates you should do a SCSI Bus Reset.
255 After issuing the reset you should complete to IOSCSICommand passed.
257 Note: After you report the IOSCSICommand Reset complete, you will
258 receive cancelCommand() requests for all outstanding commands.
260 Pointer to a IOSCSICommand. See IOSCSICommand for more information.
262 void resetCommand( IOSCSICommand
*scsiCommand
);
266 @function resetOccurred
268 Inform the IOSCSIController class of an unsolicited SCSI Bus reset.
270 Your subclass should call this function if
271 you detect a target initiated bus reset, or need to do an unplanned SCSI
272 Bus Reset as part of adapter error recovery.
274 Note: After you call the resetOccurred() function, you will receive
275 cancelCommand() requests for all outstanding IOSCSICommand(s).
277 void resetOccurred();
280 @function rescheduleCommand
282 Return a IOSCSICommand for rescheduling.
284 If your subclass function cannot start processing an otherwise
285 acceptable IOSCSICommand due to resource constraints, i.e. MailBox full,
286 lost SCSI Bus arbitration, you may have the IOSCSICommand rescheduled by
287 calling rescheduleCommand(). A IOSCSICommand passed to this function
288 should be treated as 'complete', i.e. you should make no further
291 Note: If you cannot process further commands, you should call the
292 disableCommands() function to prevent receiving additional commands
293 until you are ready to accept them.
295 Pointer to IOSCSICommand your driver needs to reschedule.
297 void rescheduleCommand( IOSCSICommand
*scsiCommand
);
301 @function disableCommands
303 Suspend sending I/O commands to your driver.
305 In cases where your executeCommand() member function cannot accept
306 commands, you may disable further calls by invoking disableCommands().
307 Use enableCommands() to resume receiving commands.
309 Note: The resetCommand() and cancelCommands() entry points are not
310 affected by the use of this function.
312 Note: The default timeout for disableCommands() is 5s. If this timeout
313 is exceeded the IOSCSIController class will call your driver's
314 disableTimeoutOccurred() function. The default action of this function
315 is to issue a SCSI Bus Reset by calling your driver's resetCommand()
318 Your driver may override the default timeout
319 by specifying a timeout value in milliseconds.
321 void disableCommands( UInt32 timeoutmS
);
325 @function enableCommands
327 Resume sending I/O commands to your driver.
329 Resumes sending I/O commands to your driver that were previously suspended
330 by calling disableCommands().
332 void enableCommands();
335 @function disableTimeoutOccurred
337 Indicates your driver has suspended commands too long.
339 The IOSCSIController superclass will timeout disableCommand() requests
340 to preclude the possibility of a hung SCSI bus. If a timeout occurs,
341 then disableTimeoutOccurred() will be called. The default action of this
342 routine is to do a SCSI Bus Reset by calling resetCommand(). Your
343 subclass may choose to modify the default behavior of this routine to do
344 additional adapter specific error recovery.
346 void disableTimeoutOccurred();
350 @function findCommandWithNexus
352 Locate an active IOSCSICommand using target/lun/tag values.
354 Your subclass can use this function to search for an active
355 IOSCSICommand by providing the target/lun/tag values for the command. In
356 the case of a non-tagged command the second parameter must either be
357 omitted or set to -1.
359 An unsuccessful search will return 0.
361 Structure of type SCSITargetLun, initialized to the target/lun value you
364 Optional tag value you wish to search for.
366 IOSCSICommand
*findCommandWithNexus( SCSITargetLun targetLun
, UInt32 tagValue
= (UInt32
) -1 );
369 @function allocateTarget
371 Notifies driver of allocation of per-Target resources.
373 Your driver will be called at its allocateTarget() function when a target is about
374 to be probed. The your driver should initialize its per-target data at this time.
375 If the subclass wishes to prevent probing of this target, it should return false
376 as the result of this function call.
378 This is an optional function. Your driver is not required to implement it.
380 SCSITargetLun structure containing the SCSI Id of the target that is about to be
383 bool allocateTarget( SCSITargetLun targetLun
);
387 @function deallocateTarget
389 Notifies driver that target resources will be deallocated.
391 Your driver will be called at its deallocateTarget() function when a target is about
392 deallocated. The your driver must insure that there will be no further access to
393 the per-target data allocated to this target.
395 This is an optional function. Your driver is not required to implement it.
397 SCSITargetLun structure containing the SCSI Id of the target that is about to be
400 bool deallocateTarget( SCSITargetLun targetLun
);
404 @function allocateLun
406 Notifies driver of allocation of per-Lun resources.
408 Your driver will be called at its allocateLun() function when a Lun is about
409 to be probed. The your driver should initialize its per-lun data at this time.
410 If the subclass wishes to prevent probing of this lun, it should return false
411 as the result of this function call.
413 This is an optional function. Your driver is not required to implement it.
415 SCSITargetLun structure containing the SCSI Id of the target/lun that is about to be
418 bool allocateLun( SCSITargetLun targetLun
);
422 @function deallocateLun
424 Notifies driver of deallocation of per-Lun resources.
426 Your driver will be called at its deallocateLun() function when a Lun is about
427 deallocated. The your driver must insure that there will be no further access to
428 the per-lun data allocated to this lun.
430 This is an optional function. Your driver is not required to implement it.
432 SCSITargetLun structure containing the SCSI Id of the target/lun that is about to be
435 bool allocateLun( SCSITargetLun targetLun
);
439 @function getTargetData
441 Obtains a pointer to per-Target data allocated by IOSCSIController.
443 This function returns a pointer to per-Target workarea allocated for
444 your driver's use. The size of this area must be specified in the
445 during the configure() function. See struct SCSIControllerInfo,
446 field targetDataSize.
448 SCSITargetLun structure containing the SCSI Id of the target who's
449 workarea you are requesting a pointer to.
451 void *getTargetData( SCSITargetLun targetLun
);
457 Obtains a pointer to per-Lun data allocated by IOSCSIController.
459 This function returns a pointer to per-Lun workarea allocated for
460 your driver's use. The size of this area must be specified
461 during the configure() function. See struct SCSIControllerInfo,
464 void *getLunData( SCSITargetLun targetLun
);
468 @function getWorkLoop
470 Returns the IOWorkLoop object that services your driver.
472 IOWorkloop
*getWorkLoop();