Update contrib.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // SCSI Protocol layer for USB Mass Storage
23 #ifndef __SCSIPROT_H__
24 #define __SCSIPROT_H__
28 #include "drivemanager.h"
31 // Define MSDC_MULTITHREADED to use Mass Storage multi-threaded (Double-buffering) disk read/writes.
32 // smassstorage_db.mmp defines this macro.
34 #if defined MSDC_MULTITHREADED
35 class CWriteDriveThread;
36 class CReadDriveThread;
40 // Display time taken to write data to disk
41 //#define MEASURE_AND_DISPLAY_WRITE_TIME
42 // Display time taken to read data from disk
43 //#define MEASURE_AND_DISPLAY_READ_TIME
46 // Maximum size for SCSI Read10 Write10 and Verify10 commands
47 // Windows requests size of 64K whereas MAC requests size of 128K
48 static const TUint32 KMaxBufSize = 128 * 1024;
50 // Write to media when data is available
51 static const TUint32 KDefaultMediaWriteSize = 4 * 1024;
53 // Use in the HS case a write size of 64KB
54 static const TUint32 KHsMediaWriteSize = 64 * 1024;
63 // Spec: SCSI Primary Commands 3 (SPC-3)
64 // Section 4.5.6 Sense key and sense code defintions
65 // Table 27 - Sense key descriptions
84 // Table 28 - ASC and ASQ assignments
88 EAscLogicalUnitNotReady = 0x04,
89 EAscLogicalUnitDoesNotRespondToSelection = 0x05,
90 EInvalidCmdCode = 0x20,
91 ELbaOutOfRange = 0x21,
92 EInvalidFieldInCdb = 0x24,
93 ELuNotSupported = 0x25,
94 EWriteProtected = 0x27,
95 ENotReadyToReadyChange = 0x28,
96 EMediaNotPresent = 0x3A,
97 EInsufficientRes = 0x55
100 enum TAdditionalSenseCodeQualifier
103 EAscqLogicalUnitIsInProcessOfBecomingReady = 0x01
109 void SetSense(TSenseCode aSenseCode);
111 void SetSense(TSenseCode aSenseCode,
112 TAdditionalCode aAdditional);
114 void SetSense(TSenseCode aSenseCode,
115 TAdditionalCode aAdditional,
116 TAdditionalSenseCodeQualifier aQualifier);
128 Returns EFalse if a sense code has been set.
129 Note that ENoSense indicates that there is no specific sense key infotmation
130 to be reported and the command was successful.
132 inline TBool TSenseInfo::SenseOk()
134 return (iSenseCode == ENoSense);
138 const TUint KModeSenseCommandLength = 4;
139 const TUint KReadCapacityCommandLength = 8;
140 const TUint KReadFormatCapacitiesCommandLength = 12;
141 const TUint KRequestSenseCommandLength = 18;
142 const TUint KInquiryCommandLength = 36;
146 The CScsiProtocol is responsible for interpreting the data received from the Transpor layer
147 and where appropriate routing specific requests through to the appropriate drive unit.
151 class CScsiProtocol : public CBase, public MProtocolBase
156 ETestUnitReady = 0x00,
157 ERequestSense = 0x03,
160 EStartStopUnit = 0x1B,
161 EPreventMediaRemoval = 0x1E,
162 EReadFormatCapacities = 0x23,
163 EReadCapacity = 0x25,
167 EUndefinedCommand = 0xFF
173 static CScsiProtocol* NewL(CDriveManager& aDriveManager);
174 void RegisterTransport(MTransportBase* aTransport);
175 void ReportHighSpeedDevice();
176 TBool DecodePacket(TPtrC8& aData, TUint aLun);
177 TInt ReadComplete(TInt aError);
178 TInt SetScsiParameters(TMassStorageConfig aConfig);
182 #ifdef MSDC_MULTITHREADED
183 void InitializeBufferPointers(TPtr8& aDes1, TPtr8& aDes2);
184 static void ProcessWriteComplete (TUint8* aAddress, TAny* aPtr); //todo const
188 CScsiProtocol(CDriveManager& aDriveManager);
190 CMassStorageDrive* GetCheckDrive(TUint aLun);
191 TBool HandleUnitReady(TUint aLun);
192 TBool HandleRequestSense(TPtrC8& aData);
193 TBool HandleInquiry(TPtrC8& aData, TUint aLun);
194 TBool HandleStartStopUnit(TPtrC8& aData, TUint aLun);
195 TBool HandlePreventMediaRemoval(TPtrC8& aData, TUint aLun);
196 TBool HandleReadCapacity(TPtrC8& aData, TUint aLun);
197 TBool HandleRead10(TPtrC8& aData, TUint aLun);
198 TBool HandleWrite10(TPtrC8& aData, TUint aLun);
199 TBool HandleVerify10(TPtrC8& aData, TUint aLun);
200 TBool HandleModeSense(TPtrC8& aData, TUint aLun);
201 TBool HandleReadFormatCapacities(TUint aLun);
204 /** Configuration data for INQUIRY command*/
205 TMassStorageConfig iConfig;
207 /** reference to the Drive Manager */
208 CDriveManager& iDriveManager;
210 /** pointer to the transport level */
211 MTransportBase* iTransport;
214 TSenseInfo iSenseInfo;
216 #ifdef MSDC_MULTITHREADED
218 TSenseInfo iDeferredSenseInfo;
221 /** Start offset (in bytes) for Write/Verify */
224 /** Last command for SetupRead (Write or Verify) */
227 /** LUN for SetupRead */
231 CArrayFixFlat<TUint8>* iSimDisk;
234 /** The number of bytes remaining to be read from the host for write operations */
235 TUint32 iBytesRemain;
237 /** Write to the media when this amount of data is available */
238 TUint32 iMediaWriteSize;
240 #ifdef MSDC_MULTITHREADED
241 /** Ptr to Write Thread instance */
242 CWriteDriveThread* iWriteDriveThread;
244 /** Ptr to Read Thread instance */
245 CReadDriveThread* iReadDriveThread;
246 #endif // MSDC_MULTITHREADED
248 #ifdef USB_TRANSFER_PUBLISHER
250 Publish and subscribe properties for tracking data transfer volume
252 CUsbWriteTransferPublisher* iWriteTransferPublisher;
253 CUsbReadTransferPublisher* iReadTransferPublisher;
256 Cumulative bytes read
258 TFixedArray<TInt64, KUsbMsMaxDrives> iBytesRead;
260 Cumulative bytes written
262 TFixedArray<TInt64, KUsbMsMaxDrives> iBytesWritten;
265 Publish and subscribe properties for tracking data transfer volume
267 CDriveWriteTransferPublisher* iWriteTransferPublisher;
268 CDriveReadTransferPublisher* iReadTransferPublisher;
272 #endif // __SCSIPROT_H__