|
|
1.1 root 1: //
2: // nono
1.1.1.4 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
1.1.1.8 ! root 7: //
! 8: // SCSI (定数等)
! 9: //
! 10:
1.1 root 11: #pragma once
12:
13: #include "device.h"
14:
1.1.1.2 root 15: // このクラスは SCSI プロトコル上の定数などだけを持つ。
1.1 root 16: class SCSI
17: {
18: public:
1.1.1.2 root 19: static const uint IO = 0x01;
20: static const uint CD = 0x02;
21: static const uint MSG = 0x04;
22: static const uint BSY = 0x08;
23: static const uint SEL = 0x10;
24:
25: // SCSI のフェーズを表す。
26: // フェーズは概ね BSY と SEL の状態遷移によって決まる。
27: // 情報転送フェーズの内訳は XferPhase 側で区別する。
28: enum Phase {
29: BusFree = 0,
30: Arbitration = 1,
31: Selection = 2,
32: Reselection = 3,
33: Transfer = 4,
1.1 root 34: };
35:
1.1.1.2 root 36: // 情報転送フェーズを表す。
37: // この値は MSG,CD,IO で表現できる値をそのまま流用して表現する。
38: enum XferPhase { // MSG CD IO
39: DataOut = 0, // 0 0 0
40: DataIn = 1, // 0 0 1
41: Command = 2, // 0 1 0
42: Status = 3, // 0 1 1
43: MsgOut = 6, // 1 1 0
44: MsgIn = 7, // 1 1 1
1.1 root 45:
1.1.1.2 root 46: End = -1, // SCSICmd 内でフェーズ遷移を表現するために使う
47: };
48:
49: // フェーズ文字列を返す
1.1.1.7 root 50: static const char *GetPhaseName(Phase phase);
51: static const char *GetPhaseName(int phase) {
1.1.1.2 root 52: return GetPhaseName((Phase)phase);
53: }
54:
55: // 情報転送フェーズ文字列を返す
1.1.1.7 root 56: static const char *GetXferPhaseName(XferPhase xfer);
57: static const char *GetXferPhaseName(int xfer) {
1.1.1.2 root 58: return GetXferPhaseName((XferPhase)xfer);
59: }
60:
61: // デバイス種別
1.1.1.5 root 62: enum class DevType {
1.1.1.2 root 63: None = 0,
1.1.1.6 root 64: Initiator,
1.1.1.2 root 65: HD,
1.1.1.7 root 66: CD,
67: MO,
1.1 root 68: };
69:
1.1.1.7 root 70: // デバイス種別文字列を返す
71: static const char *GetDevTypeName(DevType type);
72:
1.1 root 73: // コマンド。
74: // ダイレクトアクセスデバイスのコマンドを元にしている。
75: // シーケンシャルアクセスデバイスでは 0x01 が Rewind だったり
76: // 同じコードで違うコマンドのようだが、とりあえずそれは放置。
77: struct Command {
78: // Group0
79: static const uint TestUnitReady = 0x00; // 共通
80: static const uint RezeroUnit = 0x01;
81: static const uint RequestSense = 0x03; // 共通
82: static const uint FormatUnit = 0x04;
83: static const uint ReassignBlocks = 0x07;
84: static const uint Read6 = 0x08;
85: static const uint Write6 = 0x0a;
86: static const uint Seek6 = 0x0b;
87: static const uint Inquiry = 0x12; // 共通
88: static const uint ModeSelect6 = 0x15; // 共通
89: static const uint Reserve = 0x16;
90: static const uint Release = 0x17;
91: static const uint Copy = 0x18; // 共通
92: static const uint ModeSense6 = 0x1a;
93: static const uint StartStopUnit = 0x1b;
94: static const uint ReceiveDiagnosticResults = 0x1c; // 共通
95: static const uint SendDiagnostic = 0x1d; // 共通
96: static const uint PreventAllowMediumRemoval = 0x1e;
97: // Group1
1.1.1.7 root 98: static const uint ReadFormatCapacities = 0x23;
99: static const uint ReadCapacity = 0x25; // Direct Access
100: static const uint ReadCDROMCapacity = 0x25; // CD-ROM
1.1 root 101: static const uint Read10 = 0x28;
102: static const uint Write10 = 0x2a;
103: static const uint Seek10 = 0x2b;
104: // Group1
105: static const uint WriteAndVerify10 = 0x2e;
106: static const uint Verify10 = 0x2f;
107: static const uint SearchDataHigh10 = 0x30;
108: static const uint SearchDataEqual10 = 0x31;
109: static const uint SearchDataLow10 = 0x32;
110: static const uint SetLimits = 0x33;
111: static const uint PreFetch = 0x34;
112: static const uint SynchronizeCache = 0x35;
113: static const uint LockUnlockCache = 0x36;
114: static const uint ReadDefectData10 = 0x37;
115: static const uint Compare = 0x39; // 共通
116: static const uint CopyAndVerify = 0x3a; // 共通
117: static const uint WriteBuffer = 0x3b; // 共通
118: static const uint ReadBuffer = 0x3c; // 共通
119: static const uint ReadLong = 0x3e;
120: static const uint WriteLong = 0x3f;
121: // Group2
122: static const uint ChangeDefinition = 0x40;
123: static const uint WriteSame = 0x41;
1.1.1.7 root 124: static const uint ReadTOC = 0x43; // CD-ROM
125: static const uint ReadHeader = 0x44; // CD-ROM
1.1 root 126: static const uint LogSelect = 0x4c; // 共通
127: static const uint LogSense = 0x4d; // 共通
1.1.1.7 root 128: static const uint ReadDiscInformation = 0x51; // ?
1.1 root 129: static const uint ModeSelect10 = 0x55; // 共通
130: static const uint ModeSense10 = 0x5a; // 共通
131: };
1.1.1.7 root 132: // SCSI コマンド名を返す
133: static const char *GetCommandName(uint8 cmd);
1.1 root 134:
135: // ステータスバイト
136: struct StatusByte {
137: static const uint8 Good = (0x00 << 1);
138: static const uint8 CheckCondition = (0x01 << 1);
139: static const uint8 ConditionMet = (0x02 << 1);
140: static const uint8 Busy = (0x04 << 1);
141: static const uint8 Intermediate = (0x08 << 1);
142: static const uint8 IntermediateCondMet = (0x0a << 1);
143: static const uint8 ReservationConflict = (0x0c << 1);
144: static const uint8 CommandTerminated = (0x11 << 1);
145: static const uint8 QueueFull = (0x14 << 1);
146: };
147:
148: // メッセージバイト
149: struct MsgByte {
150: static const uint8 CommandComplete = 0x00;
151: static const uint8 ExtendMessage = 0x01;
152: static const uint8 SaveDataPointer = 0x02;
153: static const uint8 RestorePointers = 0x03;
154: static const uint8 Disconnect = 0x04;
155: static const uint8 InitiatorDetectedError = 0x05;
156: static const uint8 Abort = 0x06;
157: static const uint8 MessageReject = 0x07;
158: static const uint8 NoOperation = 0x08;
159: static const uint8 MessageParityError = 0x09;
160: static const uint8 LinkedCommandComplete = 0x0a;
161: static const uint8 LinkedCommandCompleteWithFlag = 0x0b;
162: static const uint8 BusDeviceReset = 0x0c;
163: static const uint8 AbortTag = 0x0d;
164: static const uint8 ClearQueue = 0x0e;
165: static const uint8 InitiateRecovery = 0x0f;
166: static const uint8 ReleaseRecovery = 0x10;
167: static const uint8 TerminateIOProcess = 0x11;
168: static const uint8 SimpleQueueTag = 0x20;
169: static const uint8 HeadOfQueueTag = 0x21;
170: static const uint8 OrderedQueueTag = 0x22;
171: static const uint8 IgnoreWideResidue = 0x23;
172: static const uint8 Identify = 0x80; // 0x80..0xff
173: };
174:
1.1.1.7 root 175: // Inquiry コマンドの Peripheral Qualifier フィールド
176: struct InquiryQualifier {
177: static const uint8 LU_Present = 0x00;
178: static const uint8 LU_NotPreseted = 0x20;
179: static const uint8 Reserved = 0x40;
180: static const uint8 LU_NotSupported = 0x60;
181: static const uint8 Mask = 0xe0;
182: };
183: // Inquiry コマンドの Peripheral Device Type フィールド
184: struct InquiryDeviceType {
185: static const uint8 DirectAccess = 0x00;
186: static const uint8 SequentialAccess = 0x01;
187: static const uint8 Printer = 0x02;
188: static const uint8 Processor = 0x03;
189: static const uint8 WriteOnce = 0x04;
190: static const uint8 CDROM = 0x05;
191: static const uint8 Scanner = 0x06;
192: static const uint8 MO = 0x07;
193: static const uint8 MediaChanger = 0x08;
194: static const uint8 Communication = 0x09;
195: static const uint8 Unknown = 0x1f;
196: };
197:
1.1.1.5 root 198: // センスキー
199: struct SenseKey {
200: static const uint8 NoSense = 0x0;
201: static const uint8 RecoveredError = 0x1;
202: static const uint8 NotReady = 0x2;
203: static const uint8 MediumError = 0x3;
204: static const uint8 HardwareError = 0x4;
205: static const uint8 IllegalRequest = 0x5;
206: static const uint8 UnitAttention = 0x6;
207: static const uint8 DataProtect = 0x7;
208: static const uint8 BlankCheck = 0x8;
209: static const uint8 VendorSpecific = 0x9;
210: static const uint8 CopyAborted = 0xa;
211: static const uint8 AbortedCommand = 0xb;
212: static const uint8 Equal = 0xc;
213: static const uint8 VolumeOverflow = 0xd;
214: static const uint8 Miscompare = 0xe;
215: static const uint8 Reserved = 0xf;
216: };
1.1.1.7 root 217: // センスキーコードとキー名を表示用に整形したものを返す
218: static std::string GetSenseKeyDisp(uint8 key);
1.1.1.5 root 219:
220: // ASC/ASCQ
221: // 上位バイトが ASC、下位バイトが ASCQ を示す。
222: struct ASC {
223: static const uint16 NoAdditionalSenseInformation = 0x0000;
1.1.1.7 root 224: static const uint16 PeripheralDeviceWriteFault = 0x0300;
1.1.1.5 root 225: static const uint16 InvalidCommandOperationCode = 0x2000;
226: static const uint16 InvalidFieldInCDB = 0x2400;
1.1.1.7 root 227: static const uint16 LogicalUnitNotSupported = 0x2500;
228: static const uint16 MediumNotPresent = 0x3a00;
1.1.1.5 root 229: };
230:
1.1.1.7 root 231: // Mode Select/Sense のページ
232: // - 詳細解説本の日本語訳が微妙に遠い…。
233: // Rigid Disk Geometry Page は「ドライブ・パラメータ」、
234: // Flexible Disk Page は「フロッピ・ディスク・パラメータ」、
235: // Caching Page は「キャッシュ・コントロール・パラメータ」としてある。
236: // ページコード(番号)を軸に読み替えること。
237: // - ReadWriteErrorRecovery は CD-ROM クラスではページ番号同じで
238: // ReadErrorRecovery だがそれはもう区別しない。
239: // - 名前の後ろの Page は基本省略しているが、Caching Page は省略すると
240: // 訳分からんことになるので。
241: enum ModePage : uint8 {
242: VendorSpecific = 0x00,
243: ReadWriteErrorRecovery = 0x01,
244: DisconnectReconnect = 0x02,
245: FormatDevice = 0x03,
246: RigidDiskGeometry = 0x04,
247: FlexibleDisk = 0x05,
248: OpticalMemory = 0x06,
249: VerifyErrorRecovery = 0x07,
250: CachingPage = 0x08,
251: PeripheralDevice = 0x09,
252: ControlMode = 0x0a,
253: MediumTypeSupported = 0x0b,
254: NotchAndPartition = 0x0c,
255: CDROM = 0x0d,
256: CDROMAudioControl = 0x0e,
1.1 root 257:
1.1.1.7 root 258: AllPages = 0x3f,
259: };
260: // ページ番号とページ名を表示用に整形したものを返す
261: static std::string GetModePageDisp(uint8 page);
1.1 root 262:
263: private:
1.1.1.7 root 264: static const std::vector<const char *> commandname;
265: static const std::vector<const char *> sensekeyname;
266: static const std::vector<const char *> modepagename;
1.1 root 267: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.