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.
     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".
     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 
   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;
   143 
   144 
   145 /**
   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.
   148 
   149 @internalTechnology
   150 */
   151 class CScsiProtocol : public CBase, public MProtocolBase
   152 	{
   153 public:
   154 	enum TCommand
   155 	{
   156 	ETestUnitReady			= 0x00,
   157 	ERequestSense			= 0x03,
   158 	EInquiry 				= 0x12,
   159 	EModeSense				= 0x1A,
   160 	EStartStopUnit			= 0x1B,
   161 	EPreventMediaRemoval	= 0x1E,
   162 	EReadFormatCapacities	= 0x23,
   163 	EReadCapacity			= 0x25,
   164 	ERead10 				= 0x28,
   165 	EWrite10				= 0x2A,
   166 	EVerify10				= 0x2f,
   167 	EUndefinedCommand		= 0xFF
   168 	};
   169 
   170 
   171 public:
   172 
   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);
   179 	TInt Cancel();
   180 	~CScsiProtocol();
   181 
   182 #ifdef MSDC_MULTITHREADED
   183 	void InitializeBufferPointers(TPtr8& aDes1, TPtr8& aDes2);
   184 	static void ProcessWriteComplete (TUint8* aAddress, TAny* aPtr); //todo const
   185 #endif
   186 
   187 private:
   188 	CScsiProtocol(CDriveManager& aDriveManager);
   189 	void  ConstructL();
   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);
   202 
   203 private:
   204 	/** Configuration data for INQUIRY command*/
   205 	TMassStorageConfig iConfig;
   206 
   207 	/** reference to the Drive Manager */
   208 	CDriveManager& iDriveManager;
   209 	
   210 	/** pointer to the transport level */
   211 	MTransportBase* iTransport; 
   212 
   213 	/** Sense Info */
   214 	TSenseInfo iSenseInfo;
   215 
   216 #ifdef MSDC_MULTITHREADED
   217 	/** Sense Info */
   218 	TSenseInfo iDeferredSenseInfo;
   219 #endif
   220 
   221 	/** Start offset (in bytes) for Write/Verify */
   222 	TInt64 iOffset;
   223 
   224 	/** Last command for SetupRead (Write or Verify) */
   225 	TUint8 iLastCommand;
   226 
   227 	/** LUN for SetupRead */
   228 	TUint iLastLun;
   229 
   230 #ifdef SIMDISK
   231 	CArrayFixFlat<TUint8>* iSimDisk;
   232 #endif
   233 
   234 	/** The number of bytes remaining to be read from the host for write operations */
   235 	TUint32 iBytesRemain;
   236 
   237 	/** Write to the media when this amount of data is available */
   238 	TUint32 iMediaWriteSize;
   239 
   240 #ifdef MSDC_MULTITHREADED
   241 	/** Ptr to Write Thread instance */
   242 	CWriteDriveThread* iWriteDriveThread;
   243 
   244 	/** Ptr to Read Thread instance */
   245 	CReadDriveThread* iReadDriveThread;
   246 #endif // MSDC_MULTITHREADED
   247 
   248 #ifdef USB_TRANSFER_PUBLISHER
   249 	/**
   250 	Publish and subscribe properties for tracking data transfer volume
   251 	*/
   252 	CUsbWriteTransferPublisher* iWriteTransferPublisher;
   253 	CUsbReadTransferPublisher* iReadTransferPublisher;
   254 
   255 	/**
   256 	Cumulative bytes read
   257 	*/
   258 	TFixedArray<TInt64, KUsbMsMaxDrives> iBytesRead;
   259 	/**
   260 	Cumulative bytes written
   261 	*/
   262 	TFixedArray<TInt64, KUsbMsMaxDrives> iBytesWritten;
   263 #else
   264 	/**
   265 	Publish and subscribe properties for tracking data transfer volume
   266 	*/
   267 	CDriveWriteTransferPublisher* iWriteTransferPublisher;
   268 	CDriveReadTransferPublisher* iReadTransferPublisher;
   269 #endif
   270 	};
   271 
   272 #endif // __SCSIPROT_H__