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

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #pragma once
                      7: 
                      8: #include "device.h"
                      9: 
1.1.1.2 ! root       10: // このクラスは SCSI プロトコル上の定数などだけを持つ。
1.1       root       11: class SCSI
                     12: {
                     13:  public:
1.1.1.2 ! root       14:        static const uint IO            = 0x01;
        !            15:        static const uint CD            = 0x02;
        !            16:        static const uint MSG           = 0x04;
        !            17:        static const uint BSY           = 0x08;
        !            18:        static const uint SEL           = 0x10;
        !            19: 
        !            20:        // SCSI のフェーズを表す。
        !            21:        // フェーズは概ね BSY と SEL の状態遷移によって決まる。
        !            22:        // 情報転送フェーズの内訳は XferPhase 側で区別する。
        !            23:        enum Phase {
        !            24:                BusFree         = 0,
        !            25:                Arbitration     = 1,
        !            26:                Selection       = 2,
        !            27:                Reselection     = 3,
        !            28:                Transfer        = 4,
1.1       root       29:        };
                     30: 
1.1.1.2 ! root       31:        // 情報転送フェーズを表す。
        !            32:        // この値は MSG,CD,IO で表現できる値をそのまま流用して表現する。
        !            33:        enum XferPhase {        // MSG CD IO
        !            34:                DataOut         = 0,    //   0  0  0
        !            35:                DataIn          = 1,    //   0  0  1
        !            36:                Command         = 2,    //   0  1  0
        !            37:                Status          = 3,    //   0  1  1
        !            38:                MsgOut          = 6,    //   1  1  0
        !            39:                MsgIn           = 7,    //   1  1  1
1.1       root       40: 
1.1.1.2 ! root       41:                End                     = -1,   // SCSICmd 内でフェーズ遷移を表現するために使う
        !            42:        };
        !            43: 
        !            44:        // フェーズ文字列を返す
        !            45:        static const char * const GetPhaseName(int phase) {
        !            46:                return GetPhaseName((Phase)phase);
        !            47:        }
        !            48:        static const char * const GetPhaseName(Phase phase) {
        !            49:                switch (phase) {
        !            50:                 case BusFree:          return "BusFree";
        !            51:                 case Arbitration:      return "Arbitration";
        !            52:                 case Selection:        return "Selection";
        !            53:                 case Reselection:      return "Reselection";
        !            54:                 case Transfer:         return "Transfer";
        !            55:                }
        !            56:                return "Phase?";
        !            57:        }
        !            58: 
        !            59:        // 情報転送フェーズ文字列を返す
        !            60:        static const char * const GetXferPhaseName(int xfer) {
        !            61:                return GetXferPhaseName((XferPhase)xfer);
        !            62:        }
        !            63:        static const char * const GetXferPhaseName(XferPhase xfer) {
        !            64:                switch (xfer) {
        !            65:                 case DataOut:  return "DataOut";
        !            66:                 case DataIn:   return "DataIn";
        !            67:                 case Command:  return "Command";
        !            68:                 case Status:   return "Status";
        !            69:                 case MsgOut:   return "MsgOut";
        !            70:                 case MsgIn:    return "MsgIn";
        !            71:                 case End:              return "End";
        !            72:                }
        !            73:                return "XferPhase?";
        !            74:        }
        !            75: 
        !            76:        // デバイス種別
        !            77:        enum DevType {
        !            78:                None = 0,
        !            79:                HD,
1.1       root       80:        };
                     81: 
                     82:        // コマンド。
                     83:        // ダイレクトアクセスデバイスのコマンドを元にしている。
                     84:        // シーケンシャルアクセスデバイスでは 0x01 が Rewind だったり
                     85:        // 同じコードで違うコマンドのようだが、とりあえずそれは放置。
                     86:        struct Command {
                     87:                // Group0
                     88:                static const uint TestUnitReady         = 0x00;         // 共通
                     89:                static const uint RezeroUnit            = 0x01;
                     90:                static const uint RequestSense          = 0x03;         // 共通
                     91:                static const uint FormatUnit            = 0x04;
                     92:                static const uint ReassignBlocks        = 0x07;
                     93:                static const uint Read6                         = 0x08;
                     94:                static const uint Write6                        = 0x0a;
                     95:                static const uint Seek6                         = 0x0b;
                     96:                static const uint Inquiry                       = 0x12;         // 共通
                     97:                static const uint ModeSelect6           = 0x15;         // 共通
                     98:                static const uint Reserve                       = 0x16;
                     99:                static const uint Release                       = 0x17;
                    100:                static const uint Copy                          = 0x18;         // 共通
                    101:                static const uint ModeSense6            = 0x1a;
                    102:                static const uint StartStopUnit         = 0x1b;
                    103:                static const uint ReceiveDiagnosticResults      = 0x1c; // 共通
                    104:                static const uint SendDiagnostic        = 0x1d;         // 共通
                    105:                static const uint PreventAllowMediumRemoval     = 0x1e;
                    106:                // Group1
                    107:                static const uint ReadCapacity          = 0x25;
                    108:                static const uint Read10                        = 0x28;
                    109:                static const uint Write10                       = 0x2a;
                    110:                static const uint Seek10                        = 0x2b;
                    111:                // Group1
                    112:                static const uint WriteAndVerify10      = 0x2e;
                    113:                static const uint Verify10                      = 0x2f;
                    114:                static const uint SearchDataHigh10      = 0x30;
                    115:                static const uint SearchDataEqual10     = 0x31;
                    116:                static const uint SearchDataLow10       = 0x32;
                    117:                static const uint SetLimits                     = 0x33;
                    118:                static const uint PreFetch                      = 0x34;
                    119:                static const uint SynchronizeCache      = 0x35;
                    120:                static const uint LockUnlockCache       = 0x36;
                    121:                static const uint ReadDefectData10      = 0x37;
                    122:                static const uint Compare                       = 0x39;         // 共通
                    123:                static const uint CopyAndVerify         = 0x3a;         // 共通
                    124:                static const uint WriteBuffer           = 0x3b;         // 共通
                    125:                static const uint ReadBuffer            = 0x3c;         // 共通
                    126:                static const uint ReadLong                      = 0x3e;
                    127:                static const uint WriteLong                     = 0x3f;
                    128:                // Group2
                    129:                static const uint ChangeDefinition      = 0x40;
                    130:                static const uint WriteSame                     = 0x41;
                    131:                static const uint LogSelect                     = 0x4c;         // 共通
                    132:                static const uint LogSense                      = 0x4d;         // 共通
                    133:                static const uint ModeSelect10          = 0x55;         // 共通
                    134:                static const uint ModeSense10           = 0x5a;         // 共通
                    135:                static const uint MAX                           = 0x5b; // 最大値+1にすること
                    136:        };
                    137: 
                    138:        // ステータスバイト
                    139:        struct StatusByte {
                    140:                static const uint8 Good                                 = (0x00 << 1);
                    141:                static const uint8 CheckCondition               = (0x01 << 1);
                    142:                static const uint8 ConditionMet                 = (0x02 << 1);
                    143:                static const uint8 Busy                                 = (0x04 << 1);
                    144:                static const uint8 Intermediate                 = (0x08 << 1);
                    145:                static const uint8 IntermediateCondMet  = (0x0a << 1);
                    146:                static const uint8 ReservationConflict  = (0x0c << 1);
                    147:                static const uint8 CommandTerminated    = (0x11 << 1);
                    148:                static const uint8 QueueFull                    = (0x14 << 1);
                    149:        };
                    150: 
                    151:        // メッセージバイト
                    152:        struct MsgByte {
                    153:                static const uint8 CommandComplete                      = 0x00;
                    154:                static const uint8 ExtendMessage                        = 0x01;
                    155:                static const uint8 SaveDataPointer                      = 0x02;
                    156:                static const uint8 RestorePointers                      = 0x03;
                    157:                static const uint8 Disconnect                           = 0x04;
                    158:                static const uint8 InitiatorDetectedError       = 0x05;
                    159:                static const uint8 Abort                                        = 0x06;
                    160:                static const uint8 MessageReject                        = 0x07;
                    161:                static const uint8 NoOperation                          = 0x08;
                    162:                static const uint8 MessageParityError           = 0x09;
                    163:                static const uint8 LinkedCommandComplete        = 0x0a;
                    164:                static const uint8 LinkedCommandCompleteWithFlag = 0x0b;
                    165:                static const uint8 BusDeviceReset                       = 0x0c;
                    166:                static const uint8 AbortTag                                     = 0x0d;
                    167:                static const uint8 ClearQueue                           = 0x0e;
                    168:                static const uint8 InitiateRecovery                     = 0x0f;
                    169:                static const uint8 ReleaseRecovery                      = 0x10;
                    170:                static const uint8 TerminateIOProcess           = 0x11;
                    171:                static const uint8 SimpleQueueTag                       = 0x20;
                    172:                static const uint8 HeadOfQueueTag                       = 0x21;
                    173:                static const uint8 OrderedQueueTag                      = 0x22;
                    174:                static const uint8 IgnoreWideResidue            = 0x23;
                    175:                static const uint8 Identify                                     = 0x80; // 0x80..0xff
                    176:        };
                    177: 
                    178:        // Mode Select(6) ヘッダ
                    179:        struct ModeParamHdr {
                    180:                uint8 mode_param_len;           // ヘッダ以降のバイト数
                    181:                uint8 media_type;
                    182:                uint8 device_specific_param;
                    183:                uint8 block_desc_len;           // 0 か 8の倍数
                    184:        } __packed;
                    185: 
                    186:        // Mode Select(6) ブロックディスクリプタ
                    187:        struct BlockDesc {
                    188:                uint8 density_code;
                    189:                uint8 block_cnt[3];                     // ブロック数
                    190:                uint8 reserved;
                    191:                uint8 block_size[3];            // 論理ブロック長 (バイト)
                    192:        } __packed;
                    193: 
1.1.1.2 ! root      194:        // SCSI コマンド名を返す
        !           195:        static const char *GetCommandName(uint8 cmd);
1.1       root      196: 
                    197:  private:
                    198:        static const char * const commandname[Command::MAX];
                    199: };

unix.superglobalmegacorp.com

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