Newer
Older
AMI-Aptio-BIOS-Reversed / IScsiDxe / IScsiDxe.h
@Ajax Dong Ajax Dong 2 days ago 9 KB Init
/**
 * IScsiDxe.h - UEFI iSCSI Driver definitions
 *
 * AMI iSCSI initiator driver for UEFI.
 * Built from AmiNetworkPkg/IScsiDxe (source path: e:\hs\AmiNetworkPkg\IScsiDxe\)
 * Compiler: VS2015 DEBUG, target X64, build HR6N0XMLK
 *
 * Source files:
 *   IScsiDriver.c       - Driver entry, Driver Binding, Start/Stop
 *   IScsiMisc.c         - Utility functions: NIC list, config, MAC/IP string conversions
 *   ComponentName.c     - Component Name and Controller Name
 *   IScsiConfig.c       - HII configuration (IFR), keyword handler, form callback
 *   IScsiProto.c        - iSCSI protocol: login, session, PDU I/O, SCSI command processing
 *   IScsiIbft.c         - iSCSI Boot Firmware Table (iBFT) ACPI table installation
 *   IScsiExtScsiPassThru.c - EFI_EXT_SCSI_PASS_THRU protocol implementation
 *   IScsiCHAP.c         - CHAP authentication
 */

#ifndef __ISCSI_DXE_H__
#define __ISCSI_DXE_H__

#include <Uefi.h>
#include <Protocol/DriverBinding.h>
#include <Protocol/ComponentName2.h>
#include <Protocol/ComponentName.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/HiiDatabase.h>
#include <Protocol/HiiString.h>
#include <Protocol/ExtendedScsiPassThru.h>
#include <Protocol/Ip4Config2.h>
#include <Protocol/Ip6Config.h>
#include <Protocol/Tcp4.h>
#include <Protocol/Tcp6.h>
#include <Protocol/Dhcp4.h>
#include <Protocol/Dhcp6.h>
#include <Protocol/Dns4.h>
#include <Protocol/Dns6.h>
#include <Protocol/AdapterInformation.h>
#include <Protocol/DevicePath.h>
#include <Protocol/Iscsi4.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/DxeNetLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/HiiLib.h>
#include <Library/DevicePathLib.h>
#include <Guid/Acpi.h>
#include <IndustryStandard/Acpi60.h>

/* ====================================================================
 * GUID definitions
 * ==================================================================== */

/* iSCSI private protocol GUID: 59324945-EC44-4C0D-b1cd-9db139df070c */
#define ISCSI_PRIVATE_PROTOCOL_GUID \
  { 0x59324945, 0xEC44, 0x4C0D, { 0xb1, 0xcd, 0x9d, 0xb1, 0x39, 0xdf, 0x07, 0x0c } }

/* iSCSI4 protocol GUID: 7671D9D0-53DB-4173-aa69-2327f21f0bc7 */
#define ISCSI4_PROTOCOL_GUID \
  { 0x7671D9D0, 0x53DB, 0x4173, { 0xaa, 0x69, 0x23, 0x27, 0xf2, 0x1f, 0x0b, 0xc7 } }

/* gEfiAdapterInfoProtocolGuid: E5DD1403-D622-C24E-8488-c71b17f5e802 */
#define ADAPTER_INFO_PROTOCOL_GUID \
  { 0xE5DD1403, 0xD622, 0xC24E, { 0x84, 0x88, 0xc7, 0x1b, 0x17, 0xf5, 0xe8, 0x02 } }

/* ====================================================================
 * Private context signature: 0x414D4953 = "AMIS"
 * ==================================================================== */
#define ISCSI_DRIVER_SIGNATURE   SIGNATURE_32 ('A', 'M', 'I', 'S')
#define ISCSI_ATTEMPT_SIGNATURE  SIGNATURE_32 ('A', 'T', 'T', 'P')

#define MAX_ATTEMPT_COUNT     8
#define MAX_NIC_COUNT         16

/* ====================================================================
 * iSCSI attempt configuration structure (1049 bytes)
 * ==================================================================== */
typedef struct {
  UINT8     AttemptConfigIndex;     /* +0x00: 1..8 */
  UINT16    Reserved;               /* +0x02 */
  UINT16    PortString[112];        /* +0x1a: port string */
  UINT8     NicIndex;               /* +0xfa: NIC index */
  UINT8     NicValid;               /* +0xfb: NIC valid */
  UINT8     BddPolicy;             /* +0xfc: Boot Device Selection Policy */
  UINT8     IpMode;                 /* +0xfd: 0=None, 1=DHCP, 2=Static */
  UINT8     NicSpecific;            /* +0xfe: NIC-specific config */
  UINT8     Reserved2;             /* +0xff: */
  /* --- iSCSI connection parameters --- */
  UINT8     ConnectetRetryCount;      /* +0x100 */
  UINT8     ConnectTimeout;         /* +0x101 */
  UINT8     Reserved3[8];          /* +0x102..0x109 */
  /* ISID */
  UINT8     Isid[6];                /* +0x10a */
  /* --- Initiator Name --- */
  UINT16    InitiatorName[128];     /* +0x110..0x22f */
  UINT16    InitiatorSecret[128];   /* +0x230..0x34f */
  UINT16    InitiatorSecretConfirm[128]; /* +0x350..0x46f */
  /* --- Target --- */
  UInt16    TargetName[128];        /* +0x470..0x58f */
  UINT16    TargetAddress[64];      /* +0x590..0x62f */
  UINT8     TargetPort;            /* +0x630 */
  UINT16     TargetTcpPort;          /* +0x631 */
  UINT8     TargetIpOrigin;         /* +0x633 */
  UINT8     TargetIpType;           /* +0x634 */
  /* LUN */
  UINT8     Lun[8];                /* +0x635.. */
  /* --- Authentication --- */
  UInt8     AuthMethod;             /* 0=None, 1=CHAP, 2=Reverse CHAP, 3=CHAP+Reverse */
  UINT8     ChapType;              /* CHAP type: 0=One-way, 1=Bidirectional */
  UINT16    ChapUserName[128];      /* CHAP user name */
  UINT16    ChapSecret[128];        /* CHAP secret */
  UINT16    ChapReverseName[128];   /* Reverse CHAP name */
  UINT16    ChapReverseSecret[128]; /* Reverse CHAP secret */
} ISCSI_ATTEMPT_CONFIG;

/* ====================================================================
 * ISCSI_DRIVER private context structure
 * ==================================================================== */
typedef struct _ISCSI_DRIVER_DATA {
  UINT32            Signature;           /* +0x00: "AMIS" */
  EFI_HANDLE        DriverHandle;        /* +0x08 */
  EFI_HANDLE        ControllerHandle;    /* +0x10 */
  UINT8             AttemptConfigIndex;  /* +0x17 */
  VOID              *AttemptConfig;      /* +0x18: ptr to ISCSI_NIC_DATA */
  /* NIC list */
  LIST_ENTRY        NicList;             /* +0x28 */
  UINT8             NicCount;
  UINT8             EnabledNicCount;
  /* Session state */
  UINT8             SessionCount;
  UINT8             SessionValid;
  /* Current NIC info */
  UINT16            MacString[96];
  CHAR16            PortString[96];
  /* Timer */
  EFI_EVENT         TimerEvent;
  /* HII */
  EFI_HII_HANDLE    HiiHandle;
  EFI_HII_CONIG_ACCESS_PROTOCOL  ConfigAccess;
  /* iSCSI4 protocol */
  EFI_ISCSI4_PROTOCOL *Iii4;
} ISCSI_DRIVER_DATA;

/* ====================================================================
 * iSCSI NIC entry (linked-list)
 * ==================================================================== */
typedef struct _ISCSI_NIC_DATA {
  LIST_ENTRY        Link;              /* +0x00 */
  UINT32            HwAddressSize;     /* MAC addr size */
  UINT8             MacAddr[32];       /* / * +0x?? * /
  UINT16            VlanId;            /* / +0x?? * /
  UINT8             NicIndex;          /* / +0x?? */
  UInt8             Enabled;           /* 1 = enabled */
  UInt8             Ipv6Available;     /* IPv6 support available */
} ISCSI_NIC_DATA;

/* ====================================================================
 * iSCSI session / connection state (per attempt)
 * ==================================================================== /
typedef struct _ISCSI_SESSION {
  LIST_ENTRY        Link;              /* session list link */
  UINT32            SessionId;         /* session ID */
  UINT16            Cid;               /* connection ID */
  UINT8             State;             /* 0=idle, 1=logged-in */
  UINT8             AuthType;          /* authentication type */
  UINT8             TargetIpType;      /* 0=IPv4, 1=IPv6 */
  UINT8             IpAddress[16];     /* target IP */
  UINT8             Lun[8];            /* target LUN */
  /* operational parameters as negotiated */
  UINT16            TargetTcpPort;     /* TCP port */
  UINT32            DataSeqInOrder;
  UINT32            DataPduInOrder;
  UINT32            InitialR2T;
  UINT32            ImmediateData;
  UINT32            MaxRecvDataSegLen;
  UINT32            MaxBurstLength;
  UINT32            FirstBurstLength;
  UINT32            MaxConnections;
  UINT32            DefaultTime2Wait;
  UINT32            DefaultTime2Retain;
  UINT32            MaxOutstandingR2T;
  UINT32            ErrorRecoveryLevel;
  UINT8             HeaderDigest;      /* 0=None, 1=CRC32 */
  UINT8             DataDigest;
} ISCSI_SESSION;

/* ====================================================================
 * iSCSI PDU opcodes
 * ====================================================================*/
#define ISCSI_OPCODE_NOP_OUT       0x00
#define ISCSI_OPCODE_SCSI_CMD      0x01
#define ISCSI_OPCODE_DATA_OUT      0x05
#define ISCSI_OPCODE_LOGIN_CMD     0x03
#define ISCSI_OPCODE_TEXT_CMD      0x04
#define ISCSI_OPCODE_NOP_IN        0x20
#define ISCSI_OPCODE_SCSI_RSP     0x21
#define ISCSI_OPCODE_LOGIN_RSP    0x23
#define ISCSI_OPCODE_TEXT_RSP     0x24
#define ISCSI_OPCODE_DATA_IN       0x25
#define ISCSI_OPCODE_R2T           0x31
#define ISCSI_OPCODE_ASYNC_MSG    0x22
#define ISCSI_OPCODE_REJECT        0x3F

/* ====================================================================
 * iSCSI IFR NVDATA (HII config)
 * ====================================================================*/
#define ISCSI_CONIG_VARSTORE_ID    0x1234

typedef struct {
  UINT8   InitialAttemptOrder[MAX_ATTEMPT_COUNT+1];
  UINT8   AttemptConfigOrder[MAX_ATTEMPT_COUNT+1];
  UINT8   NicCount;
  UINT8   SinglePathCount;
  UINT8   MpioCount;
  UINT8   Reserved;
} ISCSI_CONIG_IFR_NVDATA;

/* ====================================================================
 * GRobbal data declarations
 * =====================================================================*/

#define ISCSI_PRIVATE_DATA_FROM_PROTOCOL(p) \
  CR (p, ISCSI_DRIVER_DATA, ConfigAccess, ISCSI_DRIVER_SIGNATURE)

#define ISCSI_NIC_FROM_LINK(l) \
  CR (l, ISCSI_NIC_DATA, Link, ISCSI_ATTEMPT_SIGNATURE)

#endif /* __ISCSI_DXE_H__ */