|
|
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:
7: #pragma once
8:
9: #include "device.h"
10:
1.1.1.2 root 11: // このクラスは SCSI プロトコル上の定数などだけを持つ。
1.1 root 12: class SCSI
13: {
14: public:
1.1.1.2 root 15: static const uint IO = 0x01;
16: static const uint CD = 0x02;
17: static const uint MSG = 0x04;
18: static const uint BSY = 0x08;
19: static const uint SEL = 0x10;
20:
21: // SCSI のフェーズを表す。
22: // フェーズは概ね BSY と SEL の状態遷移によって決まる。
23: // 情報転送フェーズの内訳は XferPhase 側で区別する。
24: enum Phase {
25: BusFree = 0,
26: Arbitration = 1,
27: Selection = 2,
28: Reselection = 3,
29: Transfer = 4,
1.1 root 30: };
31:
1.1.1.2 root 32: // 情報転送フェーズを表す。
33: // この値は MSG,CD,IO で表現できる値をそのまま流用して表現する。
34: enum XferPhase { // MSG CD IO
35: DataOut = 0, // 0 0 0
36: DataIn = 1, // 0 0 1
37: Command = 2, // 0 1 0
38: Status = 3, // 0 1 1
39: MsgOut = 6, // 1 1 0
40: MsgIn = 7, // 1 1 1
1.1 root 41:
1.1.1.2 root 42: End = -1, // SCSICmd 内でフェーズ遷移を表現するために使う
43: };
44:
45: // フェーズ文字列を返す
1.1.1.4 root 46: static const char * GetPhaseName(int phase) {
1.1.1.2 root 47: return GetPhaseName((Phase)phase);
48: }
1.1.1.4 root 49: static const char * GetPhaseName(Phase phase) {
1.1.1.2 root 50: switch (phase) {
51: case BusFree: return "BusFree";
52: case Arbitration: return "Arbitration";
53: case Selection: return "Selection";
54: case Reselection: return "Reselection";
55: case Transfer: return "Transfer";
56: }
57: return "Phase?";
58: }
59:
60: // 情報転送フェーズ文字列を返す
1.1.1.4 root 61: static const char * GetXferPhaseName(int xfer) {
1.1.1.2 root 62: return GetXferPhaseName((XferPhase)xfer);
63: }
1.1.1.4 root 64: static const char * GetXferPhaseName(XferPhase xfer) {
1.1.1.2 root 65: switch (xfer) {
66: case DataOut: return "DataOut";
67: case DataIn: return "DataIn";
68: case Command: return "Command";
69: case Status: return "Status";
70: case MsgOut: return "MsgOut";
71: case MsgIn: return "MsgIn";
72: case End: return "End";
73: }
74: return "XferPhase?";
75: }
76:
77: // デバイス種別
1.1.1.5 root 78: enum class DevType {
1.1.1.2 root 79: None = 0,
1.1.1.6 ! root 80: Initiator,
1.1.1.2 root 81: HD,
1.1 root 82: };
83:
84: // コマンド。
85: // ダイレクトアクセスデバイスのコマンドを元にしている。
86: // シーケンシャルアクセスデバイスでは 0x01 が Rewind だったり
87: // 同じコードで違うコマンドのようだが、とりあえずそれは放置。
88: struct Command {
89: // Group0
90: static const uint TestUnitReady = 0x00; // 共通
91: static const uint RezeroUnit = 0x01;
92: static const uint RequestSense = 0x03; // 共通
93: static const uint FormatUnit = 0x04;
94: static const uint ReassignBlocks = 0x07;
95: static const uint Read6 = 0x08;
96: static const uint Write6 = 0x0a;
97: static const uint Seek6 = 0x0b;
98: static const uint Inquiry = 0x12; // 共通
99: static const uint ModeSelect6 = 0x15; // 共通
100: static const uint Reserve = 0x16;
101: static const uint Release = 0x17;
102: static const uint Copy = 0x18; // 共通
103: static const uint ModeSense6 = 0x1a;
104: static const uint StartStopUnit = 0x1b;
105: static const uint ReceiveDiagnosticResults = 0x1c; // 共通
106: static const uint SendDiagnostic = 0x1d; // 共通
107: static const uint PreventAllowMediumRemoval = 0x1e;
108: // Group1
109: static const uint ReadCapacity = 0x25;
110: static const uint Read10 = 0x28;
111: static const uint Write10 = 0x2a;
112: static const uint Seek10 = 0x2b;
113: // Group1
114: static const uint WriteAndVerify10 = 0x2e;
115: static const uint Verify10 = 0x2f;
116: static const uint SearchDataHigh10 = 0x30;
117: static const uint SearchDataEqual10 = 0x31;
118: static const uint SearchDataLow10 = 0x32;
119: static const uint SetLimits = 0x33;
120: static const uint PreFetch = 0x34;
121: static const uint SynchronizeCache = 0x35;
122: static const uint LockUnlockCache = 0x36;
123: static const uint ReadDefectData10 = 0x37;
124: static const uint Compare = 0x39; // 共通
125: static const uint CopyAndVerify = 0x3a; // 共通
126: static const uint WriteBuffer = 0x3b; // 共通
127: static const uint ReadBuffer = 0x3c; // 共通
128: static const uint ReadLong = 0x3e;
129: static const uint WriteLong = 0x3f;
130: // Group2
131: static const uint ChangeDefinition = 0x40;
132: static const uint WriteSame = 0x41;
133: static const uint LogSelect = 0x4c; // 共通
134: static const uint LogSense = 0x4d; // 共通
135: static const uint ModeSelect10 = 0x55; // 共通
136: static const uint ModeSense10 = 0x5a; // 共通
137: static const uint MAX = 0x5b; // 最大値+1にすること
138: };
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.5 root 180: // センスキー
181: struct SenseKey {
182: static const uint8 NoSense = 0x0;
183: static const uint8 RecoveredError = 0x1;
184: static const uint8 NotReady = 0x2;
185: static const uint8 MediumError = 0x3;
186: static const uint8 HardwareError = 0x4;
187: static const uint8 IllegalRequest = 0x5;
188: static const uint8 UnitAttention = 0x6;
189: static const uint8 DataProtect = 0x7;
190: static const uint8 BlankCheck = 0x8;
191: static const uint8 VendorSpecific = 0x9;
192: static const uint8 CopyAborted = 0xa;
193: static const uint8 AbortedCommand = 0xb;
194: static const uint8 Equal = 0xc;
195: static const uint8 VolumeOverflow = 0xd;
196: static const uint8 Miscompare = 0xe;
197: static const uint8 Reserved = 0xf;
198: };
199:
200: // ASC/ASCQ
201: // 上位バイトが ASC、下位バイトが ASCQ を示す。
202: struct ASC {
203: static const uint16 NoAdditionalSenseInformation = 0x0000;
204: static const uint16 InvalidCommandOperationCode = 0x2000;
205: static const uint16 InvalidFieldInCDB = 0x2400;
206: };
207:
1.1 root 208: // Mode Select(6) ヘッダ
209: struct ModeParamHdr {
1.1.1.3 root 210: uint8 mode_param_len; // バイト長 (このバイトを含まずこれ以降)
1.1 root 211: uint8 media_type;
212: uint8 device_specific_param;
1.1.1.3 root 213: uint8 block_desc_len; // ブロックディスクリプタ長
1.1 root 214: } __packed;
215:
216: // Mode Select(6) ブロックディスクリプタ
217: struct BlockDesc {
218: uint8 density_code;
219: uint8 block_cnt[3]; // ブロック数
220: uint8 reserved;
221: uint8 block_size[3]; // 論理ブロック長 (バイト)
222: } __packed;
223:
1.1.1.2 root 224: // SCSI コマンド名を返す
225: static const char *GetCommandName(uint8 cmd);
1.1 root 226:
227: private:
228: static const char * const commandname[Command::MAX];
229: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.