os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/inc/scsiprot.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// SCSI Protocol layer for USB Mass Storage
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
#ifndef __SCSIPROT_H__
sl@0
    24
#define __SCSIPROT_H__
sl@0
    25
sl@0
    26
sl@0
    27
// Header files
sl@0
    28
#include "drivemanager.h"
sl@0
    29
#include "protocol.h"
sl@0
    30
sl@0
    31
// Define MSDC_MULTITHREADED to use Mass Storage multi-threaded (Double-buffering) disk read/writes.
sl@0
    32
// smassstorage_db.mmp defines this macro.
sl@0
    33
sl@0
    34
#if defined MSDC_MULTITHREADED 
sl@0
    35
class CWriteDriveThread;
sl@0
    36
class CReadDriveThread;
sl@0
    37
#endif
sl@0
    38
sl@0
    39
sl@0
    40
// Display time taken to write data to disk
sl@0
    41
//#define MEASURE_AND_DISPLAY_WRITE_TIME
sl@0
    42
// Display time taken to read data from disk
sl@0
    43
//#define MEASURE_AND_DISPLAY_READ_TIME
sl@0
    44
sl@0
    45
sl@0
    46
// Maximum size for SCSI Read10 Write10 and Verify10 commands
sl@0
    47
// Windows requests size of 64K whereas MAC requests size of 128K
sl@0
    48
static const TUint32 KMaxBufSize = 128 * 1024;
sl@0
    49
sl@0
    50
// Write to media when data is available
sl@0
    51
static const TUint32 KDefaultMediaWriteSize = 4 * 1024;
sl@0
    52
sl@0
    53
// Use in the HS case a write size of 64KB
sl@0
    54
static const TUint32 KHsMediaWriteSize = 64 * 1024;
sl@0
    55
sl@0
    56
sl@0
    57
/**
sl@0
    58
Sense Info
sl@0
    59
*/
sl@0
    60
class TSenseInfo
sl@0
    61
	{
sl@0
    62
public:
sl@0
    63
	// Spec: SCSI Primary Commands 3 (SPC-3)
sl@0
    64
	// Section 4.5.6 Sense key and sense code defintions
sl@0
    65
	// Table 27 - Sense key descriptions
sl@0
    66
	enum TSenseCode
sl@0
    67
		{
sl@0
    68
		ENoSense        = 0,
sl@0
    69
		ERecoveredError = 1,
sl@0
    70
		ENotReady       = 2,
sl@0
    71
		EMediumError    = 3,
sl@0
    72
		EHardwareError  = 4,
sl@0
    73
		EIllegalRequest = 5,
sl@0
    74
		EUnitAttention  = 6,
sl@0
    75
		EDataProtection = 7,
sl@0
    76
		EBlankCheck     = 8,
sl@0
    77
		EVendorSpecific = 9,
sl@0
    78
		ECopyAborted    = 10,
sl@0
    79
		EAbortedCommand = 11,
sl@0
    80
		EDataOverflow   = 13,
sl@0
    81
		EMisCompare     = 14
sl@0
    82
		};
sl@0
    83
sl@0
    84
	// Table 28 - ASC and ASQ assignments
sl@0
    85
	enum TAdditionalCode
sl@0
    86
		{
sl@0
    87
		EAscNull								 = 0x00,
sl@0
    88
		EAscLogicalUnitNotReady					 = 0x04,
sl@0
    89
		EAscLogicalUnitDoesNotRespondToSelection = 0x05,
sl@0
    90
		EInvalidCmdCode							 = 0x20,
sl@0
    91
		ELbaOutOfRange							 = 0x21,
sl@0
    92
		EInvalidFieldInCdb						 = 0x24,
sl@0
    93
		ELuNotSupported							 = 0x25,
sl@0
    94
		EWriteProtected							 = 0x27,
sl@0
    95
		ENotReadyToReadyChange					 = 0x28,
sl@0
    96
		EMediaNotPresent						 = 0x3A,
sl@0
    97
		EInsufficientRes						 = 0x55
sl@0
    98
		};
sl@0
    99
sl@0
   100
	enum TAdditionalSenseCodeQualifier
sl@0
   101
		{
sl@0
   102
		EAscqNull								   = 0x00,
sl@0
   103
		EAscqLogicalUnitIsInProcessOfBecomingReady = 0x01
sl@0
   104
		};
sl@0
   105
sl@0
   106
public:
sl@0
   107
	TSenseInfo();
sl@0
   108
sl@0
   109
	void SetSense(TSenseCode aSenseCode);
sl@0
   110
sl@0
   111
	void SetSense(TSenseCode aSenseCode,
sl@0
   112
				  TAdditionalCode aAdditional);
sl@0
   113
sl@0
   114
	void SetSense(TSenseCode aSenseCode,
sl@0
   115
				  TAdditionalCode aAdditional,
sl@0
   116
				  TAdditionalSenseCodeQualifier aQualifier);
sl@0
   117
sl@0
   118
	TBool SenseOk();
sl@0
   119
sl@0
   120
public:
sl@0
   121
	TUint8 iSenseCode;
sl@0
   122
	TUint8 iAdditional;
sl@0
   123
	TUint8 iQualifier;
sl@0
   124
	};
sl@0
   125
sl@0
   126
sl@0
   127
/**
sl@0
   128
Returns EFalse if a sense code has been set. 
sl@0
   129
Note that ENoSense indicates that there is no specific sense key infotmation
sl@0
   130
to be reported and the command was successful. 
sl@0
   131
*/
sl@0
   132
inline TBool TSenseInfo::SenseOk()
sl@0
   133
	{
sl@0
   134
	return (iSenseCode == ENoSense);
sl@0
   135
	}
sl@0
   136
sl@0
   137
sl@0
   138
const TUint KModeSenseCommandLength = 4;
sl@0
   139
const TUint KReadCapacityCommandLength = 8;
sl@0
   140
const TUint KReadFormatCapacitiesCommandLength = 12;
sl@0
   141
const TUint KRequestSenseCommandLength = 18;
sl@0
   142
const TUint KInquiryCommandLength = 36;
sl@0
   143
sl@0
   144
sl@0
   145
/**
sl@0
   146
The CScsiProtocol is responsible for interpreting the data received from the Transpor layer
sl@0
   147
and where appropriate routing specific requests through to the appropriate drive unit.
sl@0
   148
sl@0
   149
@internalTechnology
sl@0
   150
*/
sl@0
   151
class CScsiProtocol : public CBase, public MProtocolBase
sl@0
   152
	{
sl@0
   153
public:
sl@0
   154
	enum TCommand
sl@0
   155
	{
sl@0
   156
	ETestUnitReady			= 0x00,
sl@0
   157
	ERequestSense			= 0x03,
sl@0
   158
	EInquiry 				= 0x12,
sl@0
   159
	EModeSense				= 0x1A,
sl@0
   160
	EStartStopUnit			= 0x1B,
sl@0
   161
	EPreventMediaRemoval	= 0x1E,
sl@0
   162
	EReadFormatCapacities	= 0x23,
sl@0
   163
	EReadCapacity			= 0x25,
sl@0
   164
	ERead10 				= 0x28,
sl@0
   165
	EWrite10				= 0x2A,
sl@0
   166
	EVerify10				= 0x2f,
sl@0
   167
	EUndefinedCommand		= 0xFF
sl@0
   168
	};
sl@0
   169
sl@0
   170
sl@0
   171
public:
sl@0
   172
sl@0
   173
	static CScsiProtocol* NewL(CDriveManager& aDriveManager);
sl@0
   174
	void RegisterTransport(MTransportBase* aTransport);
sl@0
   175
	void ReportHighSpeedDevice();
sl@0
   176
	TBool DecodePacket(TPtrC8& aData, TUint aLun);
sl@0
   177
	TInt ReadComplete(TInt aError);
sl@0
   178
	TInt SetScsiParameters(TMassStorageConfig aConfig);
sl@0
   179
	TInt Cancel();
sl@0
   180
	~CScsiProtocol();
sl@0
   181
sl@0
   182
#ifdef MSDC_MULTITHREADED
sl@0
   183
	void InitializeBufferPointers(TPtr8& aDes1, TPtr8& aDes2);
sl@0
   184
	static void ProcessWriteComplete (TUint8* aAddress, TAny* aPtr); //todo const
sl@0
   185
#endif
sl@0
   186
sl@0
   187
private:
sl@0
   188
	CScsiProtocol(CDriveManager& aDriveManager);
sl@0
   189
	void  ConstructL();
sl@0
   190
	CMassStorageDrive* GetCheckDrive(TUint aLun);
sl@0
   191
	TBool HandleUnitReady(TUint aLun);
sl@0
   192
	TBool HandleRequestSense(TPtrC8& aData);
sl@0
   193
	TBool HandleInquiry(TPtrC8& aData, TUint aLun);
sl@0
   194
	TBool HandleStartStopUnit(TPtrC8& aData, TUint aLun);
sl@0
   195
	TBool HandlePreventMediaRemoval(TPtrC8& aData, TUint aLun);
sl@0
   196
	TBool HandleReadCapacity(TPtrC8& aData, TUint aLun);
sl@0
   197
	TBool HandleRead10(TPtrC8& aData, TUint aLun);
sl@0
   198
	TBool HandleWrite10(TPtrC8& aData, TUint aLun);
sl@0
   199
	TBool HandleVerify10(TPtrC8& aData, TUint aLun);
sl@0
   200
	TBool HandleModeSense(TPtrC8& aData, TUint aLun);
sl@0
   201
	TBool HandleReadFormatCapacities(TUint aLun);
sl@0
   202
sl@0
   203
private:
sl@0
   204
	/** Configuration data for INQUIRY command*/
sl@0
   205
	TMassStorageConfig iConfig;
sl@0
   206
sl@0
   207
	/** reference to the Drive Manager */
sl@0
   208
	CDriveManager& iDriveManager;
sl@0
   209
	
sl@0
   210
	/** pointer to the transport level */
sl@0
   211
	MTransportBase* iTransport; 
sl@0
   212
sl@0
   213
	/** Sense Info */
sl@0
   214
	TSenseInfo iSenseInfo;
sl@0
   215
sl@0
   216
#ifdef MSDC_MULTITHREADED
sl@0
   217
	/** Sense Info */
sl@0
   218
	TSenseInfo iDeferredSenseInfo;
sl@0
   219
#endif
sl@0
   220
sl@0
   221
	/** Start offset (in bytes) for Write/Verify */
sl@0
   222
	TInt64 iOffset;
sl@0
   223
sl@0
   224
	/** Last command for SetupRead (Write or Verify) */
sl@0
   225
	TUint8 iLastCommand;
sl@0
   226
sl@0
   227
	/** LUN for SetupRead */
sl@0
   228
	TUint iLastLun;
sl@0
   229
sl@0
   230
#ifdef SIMDISK
sl@0
   231
	CArrayFixFlat<TUint8>* iSimDisk;
sl@0
   232
#endif
sl@0
   233
sl@0
   234
	/** The number of bytes remaining to be read from the host for write operations */
sl@0
   235
	TUint32 iBytesRemain;
sl@0
   236
sl@0
   237
	/** Write to the media when this amount of data is available */
sl@0
   238
	TUint32 iMediaWriteSize;
sl@0
   239
sl@0
   240
#ifdef MSDC_MULTITHREADED
sl@0
   241
	/** Ptr to Write Thread instance */
sl@0
   242
	CWriteDriveThread* iWriteDriveThread;
sl@0
   243
sl@0
   244
	/** Ptr to Read Thread instance */
sl@0
   245
	CReadDriveThread* iReadDriveThread;
sl@0
   246
#endif // MSDC_MULTITHREADED
sl@0
   247
sl@0
   248
#ifdef USB_TRANSFER_PUBLISHER
sl@0
   249
	/**
sl@0
   250
	Publish and subscribe properties for tracking data transfer volume
sl@0
   251
	*/
sl@0
   252
	CUsbWriteTransferPublisher* iWriteTransferPublisher;
sl@0
   253
	CUsbReadTransferPublisher* iReadTransferPublisher;
sl@0
   254
sl@0
   255
	/**
sl@0
   256
	Cumulative bytes read
sl@0
   257
	*/
sl@0
   258
	TFixedArray<TInt64, KUsbMsMaxDrives> iBytesRead;
sl@0
   259
	/**
sl@0
   260
	Cumulative bytes written
sl@0
   261
	*/
sl@0
   262
	TFixedArray<TInt64, KUsbMsMaxDrives> iBytesWritten;
sl@0
   263
#else
sl@0
   264
	/**
sl@0
   265
	Publish and subscribe properties for tracking data transfer volume
sl@0
   266
	*/
sl@0
   267
	CDriveWriteTransferPublisher* iWriteTransferPublisher;
sl@0
   268
	CDriveReadTransferPublisher* iReadTransferPublisher;
sl@0
   269
#endif
sl@0
   270
	};
sl@0
   271
sl@0
   272
#endif // __SCSIPROT_H__