author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:28:22 +0300 | |
branch | RCL_3 |
changeset 26 | c734af59ce98 |
parent 20 | 597aaf25e343 |
permissions | -rw-r--r-- |
20
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// SCSI Protocol layer for USB Mass Storage |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
#ifndef __SCSIPROT_H__ |
|
24 |
#define __SCSIPROT_H__ |
|
25 |
||
26 |
||
27 |
// Header files |
|
28 |
#include "drivemanager.h" |
|
29 |
#include "protocol.h" |
|
30 |
||
31 |
// Define MSDC_MULTITHREADED to use Mass Storage multi-threaded (Double-buffering) disk read/writes. |
|
32 |
// smassstorage_db.mmp defines this macro. |
|
33 |
||
34 |
#if defined MSDC_MULTITHREADED |
|
35 |
class CWriteDriveThread; |
|
36 |
class CReadDriveThread; |
|
37 |
#endif |
|
38 |
||
39 |
||
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 |
|
44 |
||
45 |
||
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; |
|
49 |
||
50 |
// Write to media when data is available |
|
51 |
static const TUint32 KDefaultMediaWriteSize = 4 * 1024; |
|
52 |
||
53 |
// Use in the HS case a write size of 64KB |
|
54 |
static const TUint32 KHsMediaWriteSize = 64 * 1024; |
|
55 |
||
56 |
||
57 |
/** |
|
58 |
Sense Info |
|
59 |
*/ |
|
60 |
class TSenseInfo |
|
61 |
{ |
|
62 |
public: |
|
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 |
|
66 |
enum TSenseCode |
|
67 |
{ |
|
68 |
ENoSense = 0, |
|
69 |
ERecoveredError = 1, |
|
70 |
ENotReady = 2, |
|
71 |
EMediumError = 3, |
|
72 |
EHardwareError = 4, |
|
73 |
EIllegalRequest = 5, |
|
74 |
EUnitAttention = 6, |
|
75 |
EDataProtection = 7, |
|
76 |
EBlankCheck = 8, |
|
77 |
EVendorSpecific = 9, |
|
78 |
ECopyAborted = 10, |
|
79 |
EAbortedCommand = 11, |
|
80 |
EDataOverflow = 13, |
|
81 |
EMisCompare = 14 |
|
82 |
}; |
|
83 |
||
84 |
// Table 28 - ASC and ASQ assignments |
|
85 |
enum TAdditionalCode |
|
86 |
{ |
|
87 |
EAscNull = 0x00, |
|
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 |
|
98 |
}; |
|
99 |
||
100 |
enum TAdditionalSenseCodeQualifier |
|
101 |
{ |
|
102 |
EAscqNull = 0x00, |
|
103 |
EAscqLogicalUnitIsInProcessOfBecomingReady = 0x01 |
|
104 |
}; |
|
105 |
||
106 |
public: |
|
107 |
TSenseInfo(); |
|
108 |
||
109 |
void SetSense(TSenseCode aSenseCode); |
|
110 |
||
111 |
void SetSense(TSenseCode aSenseCode, |
|
112 |
TAdditionalCode aAdditional); |
|
113 |
||
114 |
void SetSense(TSenseCode aSenseCode, |
|
115 |
TAdditionalCode aAdditional, |
|
116 |
TAdditionalSenseCodeQualifier aQualifier); |
|
117 |
||
118 |
TBool SenseOk(); |
|
119 |
||
120 |
public: |
|
121 |
TUint8 iSenseCode; |
|
122 |
TUint8 iAdditional; |
|
123 |
TUint8 iQualifier; |
|
124 |
}; |
|
125 |
||
126 |
||
127 |
/** |
|
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. |
|
131 |
*/ |
|
132 |
inline TBool TSenseInfo::SenseOk() |
|
133 |
{ |
|
134 |
return (iSenseCode == ENoSense); |
|
135 |
} |
|
136 |
||
137 |
||
20
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
const TUint KModeSense6CommandLength = 4; |
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
const TUint KModeSense10CommandLength = 8; |
0 | 140 |
const TUint KReadCapacityCommandLength = 8; |
141 |
const TUint KReadFormatCapacitiesCommandLength = 12; |
|
142 |
const TUint KRequestSenseCommandLength = 18; |
|
143 |
const TUint KInquiryCommandLength = 36; |
|
144 |
||
145 |
||
146 |
/** |
|
147 |
The CScsiProtocol is responsible for interpreting the data received from the Transpor layer |
|
148 |
and where appropriate routing specific requests through to the appropriate drive unit. |
|
149 |
||
150 |
@internalTechnology |
|
151 |
*/ |
|
152 |
class CScsiProtocol : public CBase, public MProtocolBase |
|
153 |
{ |
|
154 |
public: |
|
155 |
enum TCommand |
|
156 |
{ |
|
157 |
ETestUnitReady = 0x00, |
|
158 |
ERequestSense = 0x03, |
|
159 |
EInquiry = 0x12, |
|
20
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
EModeSense6 = 0x1A, |
0 | 161 |
EStartStopUnit = 0x1B, |
162 |
EPreventMediaRemoval = 0x1E, |
|
163 |
EReadFormatCapacities = 0x23, |
|
164 |
EReadCapacity = 0x25, |
|
165 |
ERead10 = 0x28, |
|
166 |
EWrite10 = 0x2A, |
|
167 |
EVerify10 = 0x2f, |
|
20
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
EModeSense10 = 0x5A, |
0 | 169 |
EUndefinedCommand = 0xFF |
170 |
}; |
|
171 |
||
172 |
||
173 |
public: |
|
174 |
||
175 |
static CScsiProtocol* NewL(CDriveManager& aDriveManager); |
|
176 |
void RegisterTransport(MTransportBase* aTransport); |
|
177 |
void ReportHighSpeedDevice(); |
|
178 |
TBool DecodePacket(TPtrC8& aData, TUint aLun); |
|
179 |
TInt ReadComplete(TInt aError); |
|
180 |
TInt SetScsiParameters(TMassStorageConfig aConfig); |
|
181 |
TInt Cancel(); |
|
182 |
~CScsiProtocol(); |
|
183 |
||
184 |
#ifdef MSDC_MULTITHREADED |
|
185 |
void InitializeBufferPointers(TPtr8& aDes1, TPtr8& aDes2); |
|
186 |
static void ProcessWriteComplete (TUint8* aAddress, TAny* aPtr); //todo const |
|
187 |
#endif |
|
188 |
||
189 |
private: |
|
190 |
CScsiProtocol(CDriveManager& aDriveManager); |
|
191 |
void ConstructL(); |
|
192 |
CMassStorageDrive* GetCheckDrive(TUint aLun); |
|
193 |
TBool HandleUnitReady(TUint aLun); |
|
194 |
TBool HandleRequestSense(TPtrC8& aData); |
|
195 |
TBool HandleInquiry(TPtrC8& aData, TUint aLun); |
|
196 |
TBool HandleStartStopUnit(TPtrC8& aData, TUint aLun); |
|
197 |
TBool HandlePreventMediaRemoval(TPtrC8& aData, TUint aLun); |
|
198 |
TBool HandleReadCapacity(TPtrC8& aData, TUint aLun); |
|
199 |
TBool HandleRead10(TPtrC8& aData, TUint aLun); |
|
200 |
TBool HandleWrite10(TPtrC8& aData, TUint aLun); |
|
201 |
TBool HandleVerify10(TPtrC8& aData, TUint aLun); |
|
20
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
TBool HandleModeSense6(TPtrC8& aData, TUint aLun); |
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
TBool HandleModeSense10(TPtrC8& aData, TUint aLun); |
0 | 204 |
TBool HandleReadFormatCapacities(TUint aLun); |
205 |
||
206 |
private: |
|
207 |
/** Configuration data for INQUIRY command*/ |
|
208 |
TMassStorageConfig iConfig; |
|
209 |
||
210 |
/** reference to the Drive Manager */ |
|
211 |
CDriveManager& iDriveManager; |
|
212 |
||
213 |
/** pointer to the transport level */ |
|
214 |
MTransportBase* iTransport; |
|
215 |
||
216 |
/** Sense Info */ |
|
217 |
TSenseInfo iSenseInfo; |
|
218 |
||
219 |
#ifdef MSDC_MULTITHREADED |
|
220 |
/** Sense Info */ |
|
221 |
TSenseInfo iDeferredSenseInfo; |
|
222 |
#endif |
|
223 |
||
224 |
/** Start offset (in bytes) for Write/Verify */ |
|
225 |
TInt64 iOffset; |
|
226 |
||
227 |
/** Last command for SetupRead (Write or Verify) */ |
|
228 |
TUint8 iLastCommand; |
|
229 |
||
230 |
/** LUN for SetupRead */ |
|
231 |
TUint iLastLun; |
|
232 |
||
233 |
#ifdef SIMDISK |
|
234 |
CArrayFixFlat<TUint8>* iSimDisk; |
|
235 |
#endif |
|
236 |
||
237 |
/** The number of bytes remaining to be read from the host for write operations */ |
|
238 |
TUint32 iBytesRemain; |
|
239 |
||
240 |
/** Write to the media when this amount of data is available */ |
|
241 |
TUint32 iMediaWriteSize; |
|
242 |
||
243 |
#ifdef MSDC_MULTITHREADED |
|
244 |
/** Ptr to Write Thread instance */ |
|
245 |
CWriteDriveThread* iWriteDriveThread; |
|
246 |
||
247 |
/** Ptr to Read Thread instance */ |
|
248 |
CReadDriveThread* iReadDriveThread; |
|
249 |
#endif // MSDC_MULTITHREADED |
|
250 |
||
251 |
#ifdef USB_TRANSFER_PUBLISHER |
|
252 |
/** |
|
253 |
Publish and subscribe properties for tracking data transfer volume |
|
254 |
*/ |
|
255 |
CUsbWriteTransferPublisher* iWriteTransferPublisher; |
|
256 |
CUsbReadTransferPublisher* iReadTransferPublisher; |
|
257 |
||
258 |
/** |
|
259 |
Cumulative bytes read |
|
260 |
*/ |
|
261 |
TFixedArray<TInt64, KUsbMsMaxDrives> iBytesRead; |
|
262 |
/** |
|
263 |
Cumulative bytes written |
|
264 |
*/ |
|
265 |
TFixedArray<TInt64, KUsbMsMaxDrives> iBytesWritten; |
|
266 |
#else |
|
267 |
/** |
|
268 |
Publish and subscribe properties for tracking data transfer volume |
|
269 |
*/ |
|
270 |
CDriveWriteTransferPublisher* iWriteTransferPublisher; |
|
271 |
CDriveReadTransferPublisher* iReadTransferPublisher; |
|
272 |
#endif |
|
273 |
}; |
|
274 |
||
275 |
#endif // __SCSIPROT_H__ |