author | hgs |
Tue, 02 Nov 2010 15:29:23 +0000 | |
changeset 300 | 1d28c8722707 |
parent 286 | 48e57fb1237e |
permissions | -rw-r--r-- |
90
947f0dc9f7a8
Revision: 201015
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 |
|
286 | 15 |
// |
0 | 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" |
|
286 | 29 |
|
0 | 30 |
|
31 |
// Define MSDC_MULTITHREADED to use Mass Storage multi-threaded (Double-buffering) disk read/writes. |
|
32 |
// smassstorage_db.mmp defines this macro. |
|
33 |
||
286 | 34 |
#if defined MSDC_MULTITHREADED |
0 | 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 |
|
286 | 61 |
{ |
0 | 62 |
public: |
286 | 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 |
}; |
|
0 | 83 |
|
286 | 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 |
}; |
|
0 | 99 |
|
286 | 100 |
enum TAdditionalSenseCodeQualifier |
101 |
{ |
|
102 |
EAscqNull = 0x00, |
|
103 |
EAscqLogicalUnitIsInProcessOfBecomingReady = 0x01 |
|
104 |
}; |
|
0 | 105 |
|
106 |
public: |
|
286 | 107 |
TSenseInfo(); |
0 | 108 |
|
286 | 109 |
void SetSense(TSenseCode aSenseCode); |
0 | 110 |
|
286 | 111 |
void SetSense(TSenseCode aSenseCode, |
112 |
TAdditionalCode aAdditional); |
|
0 | 113 |
|
286 | 114 |
void SetSense(TSenseCode aSenseCode, |
115 |
TAdditionalCode aAdditional, |
|
116 |
TAdditionalSenseCodeQualifier aQualifier); |
|
0 | 117 |
|
286 | 118 |
TBool SenseOk(); |
0 | 119 |
|
120 |
public: |
|
286 | 121 |
TUint8 iSenseCode; |
122 |
TUint8 iAdditional; |
|
123 |
TUint8 iQualifier; |
|
124 |
}; |
|
0 | 125 |
|
126 |
||
127 |
/** |
|
286 | 128 |
Returns EFalse if a sense code has been set. |
0 | 129 |
Note that ENoSense indicates that there is no specific sense key infotmation |
286 | 130 |
to be reported and the command was successful. |
0 | 131 |
*/ |
132 |
inline TBool TSenseInfo::SenseOk() |
|
286 | 133 |
{ |
134 |
return (iSenseCode == ENoSense); |
|
135 |
} |
|
0 | 136 |
|
137 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
const TUint KModeSense6CommandLength = 4; |
947f0dc9f7a8
Revision: 201015
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 |
|
286 | 153 |
{ |
0 | 154 |
public: |
286 | 155 |
enum TCommand |
156 |
{ |
|
157 |
ETestUnitReady = 0x00, |
|
158 |
ERequestSense = 0x03, |
|
159 |
EInquiry = 0x12, |
|
160 |
EModeSense6 = 0x1A, |
|
161 |
EStartStopUnit = 0x1B, |
|
162 |
EPreventMediaRemoval = 0x1E, |
|
163 |
EReadFormatCapacities = 0x23, |
|
164 |
EReadCapacity = 0x25, |
|
165 |
ERead10 = 0x28, |
|
166 |
EWrite10 = 0x2A, |
|
167 |
EVerify10 = 0x2f, |
|
168 |
EModeSense10 = 0x5A, |
|
169 |
EUndefinedCommand = 0xFF |
|
170 |
}; |
|
0 | 171 |
|
172 |
||
173 |
public: |
|
174 |
||
286 | 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(); |
|
0 | 183 |
|
184 |
#ifdef MSDC_MULTITHREADED |
|
286 | 185 |
void InitializeBufferPointers(TPtr8& aDes1, TPtr8& aDes2); |
186 |
static void ProcessWriteComplete (TUint8* aAddress, TAny* aPtr); //todo const |
|
0 | 187 |
#endif |
188 |
||
189 |
private: |
|
286 | 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); |
|
202 |
TBool HandleModeSense6(TPtrC8& aData, TUint aLun); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
TBool HandleModeSense10(TPtrC8& aData, TUint aLun); |
286 | 204 |
TBool HandleReadFormatCapacities(TUint aLun); |
0 | 205 |
|
206 |
private: |
|
286 | 207 |
/** Configuration data for INQUIRY command*/ |
208 |
TMassStorageConfig iConfig; |
|
209 |
||
210 |
/** reference to the Drive Manager */ |
|
211 |
CDriveManager& iDriveManager; |
|
0 | 212 |
|
286 | 213 |
/** pointer to the transport level */ |
214 |
MTransportBase* iTransport; |
|
0 | 215 |
|
286 | 216 |
/** Sense Info */ |
217 |
TSenseInfo iSenseInfo; |
|
0 | 218 |
|
219 |
#ifdef MSDC_MULTITHREADED |
|
286 | 220 |
/** Sense Info */ |
221 |
TSenseInfo iDeferredSenseInfo; |
|
0 | 222 |
#endif |
223 |
||
286 | 224 |
/** Start offset (in bytes) for Write/Verify */ |
225 |
TInt64 iOffset; |
|
0 | 226 |
|
286 | 227 |
/** Last command for SetupRead (Write or Verify) */ |
228 |
TUint8 iLastCommand; |
|
0 | 229 |
|
286 | 230 |
/** LUN for SetupRead */ |
231 |
TUint iLastLun; |
|
0 | 232 |
|
233 |
#ifdef SIMDISK |
|
286 | 234 |
CArrayFixFlat<TUint8>* iSimDisk; |
0 | 235 |
#endif |
236 |
||
286 | 237 |
/** The number of bytes remaining to be read from the host for write operations */ |
238 |
TUint32 iBytesRemain; |
|
0 | 239 |
|
286 | 240 |
/** Write to the media when this amount of data is available */ |
241 |
TUint32 iMediaWriteSize; |
|
0 | 242 |
|
243 |
#ifdef MSDC_MULTITHREADED |
|
286 | 244 |
/** Ptr to Write Thread instance */ |
245 |
CWriteDriveThread* iWriteDriveThread; |
|
0 | 246 |
|
286 | 247 |
/** Ptr to Read Thread instance */ |
248 |
CReadDriveThread* iReadDriveThread; |
|
0 | 249 |
#endif // MSDC_MULTITHREADED |
250 |
||
251 |
#ifdef USB_TRANSFER_PUBLISHER |
|
286 | 252 |
/** |
253 |
Publish and subscribe properties for tracking data transfer volume |
|
254 |
*/ |
|
255 |
CUsbWriteTransferPublisher* iWriteTransferPublisher; |
|
256 |
CUsbReadTransferPublisher* iReadTransferPublisher; |
|
0 | 257 |
|
286 | 258 |
/** |
259 |
Cumulative bytes read |
|
260 |
*/ |
|
261 |
TFixedArray<TInt64, KUsbMsMaxDrives> iBytesRead; |
|
262 |
/** |
|
263 |
Cumulative bytes written |
|
264 |
*/ |
|
265 |
TFixedArray<TInt64, KUsbMsMaxDrives> iBytesWritten; |
|
0 | 266 |
#else |
286 | 267 |
/** |
268 |
Publish and subscribe properties for tracking data transfer volume |
|
269 |
*/ |
|
270 |
CDriveWriteTransferPublisher* iWriteTransferPublisher; |
|
271 |
CDriveReadTransferPublisher* iReadTransferPublisher; |
|
0 | 272 |
#endif |
286 | 273 |
}; |
0 | 274 |
|
275 |
#endif // __SCSIPROT_H__ |