Annotation of nono/vm/scsi.h, revision 1.1.1.7

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.