![]() |
![]() |
| ||
|
If scsi_transport(9F) returns TRAN_ACCEPT, the packet is the responsibility of the host bus adapter driver and should not be accessed by the target driver until the command completion routine is called. Synchronous scsi_transport() FunctionIf FLAG_NOINTR is set in the packet, then scsi_transport(9F) will not return until the command is complete, and no callback will be performed. Note - Do not use FLAG_NOINTR in interrupt context. Command CompletionOnce the host bus adapter driver has done all it can with the command, it invokes the packet's completion callback routine, passing a pointer to the scsi_pkt(9S) structure as a parameter. The completion routine decodes the packet and takes the appropriate action. Example 14-5 presents a simple completion callback routine. This code checks for transport failures and gives up rather than retrying the command. If the target is busy, extra code is required to resubmit the command at a later time. If the command results in a check condition, the target driver needs to send a request sense command unless auto request sense has been enabled. Otherwise, the command succeeded. If this is the end of processing for the command, it destroys the packet and calls biodone(9F). In the event of a transport error (such as a bus reset or parity problem), the target driver can resubmit the packet using scsi_transport(9F). There is no need to change any values in the packet prior to resubmitting. Example 14-5 does not attempt to retry incomplete commands. Note - Normally, the target driver's callback function is called in interrupt context. Consequently, the callback function should never sleep. Example 14-5 SCSI Driver Completion Routine
Reuse of PacketsA target driver can reuse packets in the following ways:
Auto-Request Sense ModeAuto-request sense mode is most desirable if tagged or untagged queuing is used. A contingent allegiance condition is cleared by any subsequent command and, consequently, the sense data is lost. Most HBA drivers will start the next command before performing the target driver callback. Other HBA drivers can use a separate and lower-priority thread to perform the callbacks, which might increase the time needed to notify the target driver that the packet completed with a check condition. In this case, the target driver might not be able to submit a request sense command in time to retrieve the sense data. To avoid this loss of sense data, the HBA driver, or controller, should issue a request sense command as soon as a check condition has been detected; this mode is known as auto-request sense mode. Note that not all HBA drivers are capable of auto-request sense mode, and some can only operate with auto-request sense mode enabled. A target driver enables auto-request-sense mode by using scsi_ifsetcap(9F). Example 14-6 shows enabling auto request sense. Example 14-6 Enabling Auto Request Sense
When a packet is allocated using scsi_init_pkt(9F) and auto request sense is desired on this packet, then the target driver must request additional space for the status block to hold the auto request sense structure. The sense length used in the request sense command is sizeof (struct scsi_extended_sense). Auto request sense can be disabled per individual packet by just allocating sizeof (struct scsi_status) for the status block. The packet is submitted using scsi_transport(9F) as usual. When a check condition occurs on this packet, the host adapter driver takes the following steps:
| ||
| ||