1/* 2 * Copyright (c) 2002-2008 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 25/* The SCSI Parallel Task object wraps a SCSI Task object and adds the 26 * necessary information for the SCSI Parallel physical interconnect. 27 * All set accessors do not directly affect the original SCSI Task and any 28 * data that is added to the Parallel Task object via such accessors must 29 * be set in the original SCSI Task by the SCSI Parallel Device obejct 30 * before completing the original SCSI Task. 31 */ 32 33#ifndef __SCSI_PARALLEL_TASK_H__ 34#define __SCSI_PARALLEL_TASK_H__ 35 36#include <IOKit/IODMACommand.h> 37#include <IOKit/scsi/spi/IOSCSIParallelInterfaceController.h> 38#include <IOKit/scsi/SCSITask.h> 39 40#include <IOKit/scsi/SCSITaskDefinition.h> 41 42 43//----------------------------------------------------------------------------- 44// Class Declarations 45//----------------------------------------------------------------------------- 46 47class SCSIParallelTask: public IODMACommand 48{ 49 50 OSDeclareDefaultStructors ( SCSIParallelTask ) 51 52public: 53 54 queue_chain_t fResendTaskChain; 55 queue_chain_t fTimeoutChain; 56 57 // Counter to keep track of the number of times the IO completes 58 // with TASK SET FULL status. 59 UInt8 fTaskRetryCount; 60 61 static SCSIParallelTask * Create ( UInt32 sizeOfHBAData, UInt64 alignmentMask ); 62 63 void free ( void ); 64 bool InitWithSize ( UInt32 sizeOfHBAData, UInt64 alignmentMask ); 65 66 void ResetForNewTask ( void ); 67 68 bool SetSCSITaskIdentifier ( SCSITaskIdentifier scsiRequest ); 69 SCSITaskIdentifier GetSCSITaskIdentifier ( void ); 70 71 bool SetTargetIdentifier ( SCSITargetIdentifier theTargetID ); 72 SCSITargetIdentifier GetTargetIdentifier ( void ); 73 74 bool SetDevice ( IOSCSIParallelInterfaceDevice * device ); 75 IOSCSIParallelInterfaceDevice * GetDevice ( void ); 76 77 // ---- Methods for Accessing data in the client's SCSI Task Object ---- 78 79 SCSILogicalUnitNumber GetLogicalUnitNumber ( void ); 80 void GetLogicalUnitBytes ( SCSILogicalUnitBytes * logicalUnitBytes ); 81 SCSITaskAttribute GetTaskAttribute ( void ); 82 SCSITaggedTaskIdentifier GetTaggedTaskIdentifier ( void ); 83 UInt8 GetCommandDescriptorBlockSize ( void ); 84 bool GetCommandDescriptorBlock ( 85 SCSICommandDescriptorBlock * cdbData ); 86 87 UInt8 GetDataTransferDirection ( void ); 88 UInt64 GetRequestedDataTransferCount ( void ); 89 UInt64 GetRealizedDataTransferCount ( void ); 90 bool SetRealizedDataTransferCount ( UInt64 realizedTransferCountInBytes ); 91 void IncrementRealizedDataTransferCount ( UInt64 realizedTransferCountInBytes ); 92 93 IOMemoryDescriptor * GetDataBuffer ( void ); 94 UInt64 GetDataBufferOffset ( void ); 95 UInt32 GetTimeoutDuration ( void ); 96 bool SetAutoSenseData ( SCSI_Sense_Data * senseData, UInt8 senseDataSize ); 97 bool GetAutoSenseData ( SCSI_Sense_Data * receivingBuffer, UInt8 senseDataSize ); 98 UInt8 GetAutoSenseDataSize ( void ); 99 UInt64 GetAutosenseRealizedDataCount ( void ); 100 101 void SetSCSIParallelFeatureNegotiation ( SCSIParallelFeature requestedFeature, 102 SCSIParallelFeatureRequest newRequest ); 103 104 SCSIParallelFeatureRequest GetSCSIParallelFeatureNegotiation ( SCSIParallelFeature requestedFeature ); 105 UInt64 GetSCSIParallelFeatureNegotiationCount ( void ); 106 void SetSCSIParallelFeatureNegotiationResult ( SCSIParallelFeature requestedFeature, 107 SCSIParallelFeatureResult newResult ); 108 109 SCSIParallelFeatureResult GetSCSIParallelFeatureNegotiationResult ( SCSIParallelFeature requestedFeature ); 110 UInt64 GetSCSIParallelFeatureNegotiationResultCount ( void ); 111 112 void SetControllerTaskIdentifier ( UInt64 newIdentifier ); 113 UInt64 GetControllerTaskIdentifier ( void ); 114 115 UInt32 GetHBADataSize ( void ); 116 void * GetHBADataPointer ( void ); 117 IOMemoryDescriptor * GetHBADataDescriptor ( void ); 118 119 AbsoluteTime GetTimeoutDeadline ( void ); 120 void SetTimeoutDeadline ( AbsoluteTime time ); 121 122 inline IOReturn SetBuffer ( IOMemoryDescriptor * buffer ) 123 { 124 return setMemoryDescriptor ( buffer, false ); 125 } 126 127private: 128 129 SCSITargetIdentifier fTargetID; 130 IOSCSIParallelInterfaceDevice * fDevice; 131 132 // --> Wide, Sync and other parallel specific fields. 133 // The member variables to indicate if wide transfers should be 134 // negotiated for the target and whether the negotiation was successful. 135 // If the request is made to negotiate for wide transfers, if the HBA supports 136 // such transfers, it should honor it regardless of whether a successful negotiation 137 // was made as it is the responsiblity of the target driver to manage whether or not 138 // such a negotiation exists. 139 // The target should only ask for such a negotiation if both the target and the bus 140 // support such transfers and if there is no outstanding negotiation for such. 141 // On notification of a bus or target reset, the target device should request a new 142 // negotiation. 143 // Wide support in this object only implies Wide16, as Wide32 was obsoleted by SPI-3. 144 SCSIParallelFeatureRequest fSCSIParallelFeatureRequest[kSCSIParallelFeature_TotalFeatureCount]; 145 SCSIParallelFeatureResult fSCSIParallelFeatureResult[kSCSIParallelFeature_TotalFeatureCount]; 146 147 UInt64 fSCSIParallelFeatureRequestCount; 148 UInt64 fSCSIParallelFeatureRequestResultCount; 149 150 // This is the SCSI Task that is to be executed on behalf of the Application 151 // Layer client that controls the Target. 152 SCSITaskIdentifier fSCSITask; 153 154 // This is a value that can be used by a controller to uniquely identify a given 155 // task. 156 UInt64 fControllerTaskIdentifier; 157 158 // This is the size and space of the HBA data as requested on 159 // when the task object was created. 160 UInt32 fHBADataSize; 161 void * fHBAData; 162 IOMemoryDescriptor * fHBADataDescriptor; 163 164 // Local storage for data that needs to be copied back to the client's SCSI Task 165 UInt64 fRealizedTransferCount; 166 167 // Member variables to maintain the next element in the 168 // timeout list and the timeout deadline. 169 AbsoluteTime fTimeoutDeadline; 170 171}; 172 173 174#endif /* __SCSI_PARALLEL_TASK_H__ */