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