#ifndef _PCI_TWEREG_H_
#define _PCI_TWEREG_H_
#define TWE_REG_CTL 0x00
#define TWE_REG_STS 0x04
#define TWE_REG_CMD_QUEUE 0x08
#define TWE_REG_RESP_QUEUE 0x0c
#define TWE_CTL_CLEAR_HOST_INTR 0x00080000
#define TWE_CTL_CLEAR_ATTN_INTR 0x00040000
#define TWE_CTL_MASK_CMD_INTR 0x00020000
#define TWE_CTL_MASK_RESP_INTR 0x00010000
#define TWE_CTL_UNMASK_CMD_INTR 0x00008000
#define TWE_CTL_UNMASK_RESP_INTR 0x00004000
#define TWE_CTL_CLEAR_ERROR_STS 0x00000200
#define TWE_CTL_ISSUE_SOFT_RESET 0x00000100
#define TWE_CTL_ENABLE_INTRS 0x00000080
#define TWE_CTL_DISABLE_INTRS 0x00000040
#define TWE_CTL_ISSUE_HOST_INTR 0x00000020
#define TWE_CTL_CLEAR_PARITY_ERROR 0x00800000
#define TWE_CTL_CLEAR_PCI_ABORT 0x00100000
#define TWE_STS_MAJOR_VERSION_MASK 0xf0000000
#define TWE_STS_MINOR_VERSION_MASK 0x0f000000
#define TWE_STS_PCI_PARITY_ERROR 0x00800000
#define TWE_STS_QUEUE_ERROR 0x00400000
#define TWE_STS_MICROCONTROLLER_ERROR 0x00200000
#define TWE_STS_PCI_ABORT 0x00100000
#define TWE_STS_HOST_INTR 0x00080000
#define TWE_STS_ATTN_INTR 0x00040000
#define TWE_STS_CMD_INTR 0x00020000
#define TWE_STS_RESP_INTR 0x00010000
#define TWE_STS_CMD_QUEUE_FULL 0x00008000
#define TWE_STS_RESP_QUEUE_EMPTY 0x00004000
#define TWE_STS_MICROCONTROLLER_READY 0x00002000
#define TWE_STS_CMD_QUEUE_EMPTY 0x00001000
#define TWE_STS_ALL_INTRS 0x000f0000
#define TWE_STS_CLEARABLE_BITS 0x00d00000
#define TWE_STS_EXPECTED_BITS 0x00002000
#define TWE_STS_UNEXPECTED_BITS 0x00f80000
#define TWE_OP_NOP 0x00
#define TWE_OP_INIT_CONNECTION 0x01
#define TWE_OP_READ 0x02
#define TWE_OP_WRITE 0x03
#define TWE_OP_READVERIFY 0x04
#define TWE_OP_VERIFY 0x05
#define TWE_OP_PROBE 0x06
#define TWE_OP_PROBEUNIT 0x07
#define TWE_OP_ZEROUNIT 0x08
#define TWE_OP_REPLACEUNIT 0x09
#define TWE_OP_HOTSWAP 0x0a
#define TWE_OP_SETATAFEATURE 0x0c
#define TWE_OP_FLUSH 0x0e
#define TWE_OP_ABORT 0x0f
#define TWE_OP_CHECKSTATUS 0x10
#define TWE_OP_ATA_PASSTHROUGH 0x11
#define TWE_OP_GET_PARAM 0x12
#define TWE_OP_SET_PARAM 0x13
#define TWE_OP_CREATEUNIT 0x14
#define TWE_OP_DELETEUNIT 0x15
#define TWE_OP_REBUILDUNIT 0x17
#define TWE_OP_SECTOR_INFO 0x1a
#define TWE_OP_AEN_LISTEN 0x1c
#define TWE_OP_CMD_PACKET 0x1d
#define TWE_OP_CMD_WITH_DATA 0x1f
#define TWE_RESP_MASK 0x00000ff0
#define TWE_RESP_SHIFT 4
#define TWE_ALIGNMENT 512
#define TWE_MAX_UNITS 16
#define TWE_INIT_CMD_PACKET_SIZE 0x3
#define TWE_SG_SIZE 62
#define TWE_MAX_CMDS 255
#define TWE_Q_START 0
#define TWE_UNIT_INFORMATION_TABLE_BASE 0x300
#define TWE_IOCTL 0x80
#define TWE_SECTOR_SIZE 512
struct twe_sgb {
u_int32_t tsg_address;
u_int32_t tsg_length;
} __packed;
struct twe_cmd {
u_int8_t tc_opcode;
u_int8_t tc_size;
u_int8_t tc_cmdid;
u_int8_t tc_unit;
u_int8_t tc_status;
u_int8_t tc_flags;
u_int16_t tc_count;
union {
struct {
u_int32_t lba;
struct twe_sgb sgl[TWE_SG_SIZE];
} io __packed;
struct {
struct twe_sgb sgl[TWE_SG_SIZE];
} param;
struct {
u_int32_t response_queue_pointer;
} init_connection __packed;
} tc_args;
int32_t tc_pad;
} __packed;
struct twe_param {
u_int16_t tp_table_id;
u_int8_t tp_param_id;
u_int8_t tp_param_size;
u_int8_t tp_data[1];
} __packed;
#define TWE_PARAM_PARAM_ALL 0
#define TWE_PARAM_PARAM_SIZE 1
#define TWE_PARAM_DIRECTORY 0xffff
#define TWE_PARAM_DIRECTORY_TABLES 2
#define TWE_PARAM_DIRECTORY_SIZES 3
#define TWE_PARAM_DRIVESUMMARY 0x0002
#define TWE_PARAM_DRIVESUMMARY_Num 2
#define TWE_PARAM_DRIVESUMMARY_Status 3
#define TWE_PARAM_DRIVESTATUS_Missing 0x00
#define TWE_PARAM_DRIVESTATUS_NotSupp 0xfe
#define TWE_PARAM_DRIVESTATUS_Present 0xff
#define TWE_PARAM_UNITSUMMARY 0x0003
#define TWE_PARAM_UNITSUMMARY_Num 2
#define TWE_PARAM_UNITSUMMARY_Status 3
#define TWE_PARAM_UNITSTATUS_Online (1<<0)
#define TWE_PARAM_UNITSTATUS_Complete (1<<1)
#define TWE_PARAM_UNITSTATUS_MASK 0xfc
#define TWE_PARAM_UNITSTATUS_Normal 0xfc
#define TWE_PARAM_UNITSTATUS_Initialising 0xf4
#define TWE_PARAM_UNITSTATUS_Degraded 0xec
#define TWE_PARAM_UNITSTATUS_Rebuilding 0xdc
#define TWE_PARAM_UNITSTATUS_Verifying 0xcc
#define TWE_PARAM_UNITSTATUS_Corrupt 0xbc
#define TWE_PARAM_UNITSTATUS_Missing 0x00
#define TWE_PARAM_DRIVEINFO 0x0200
#define TWE_PARAM_DRIVEINFO_Size 2
#define TWE_PARAM_DRIVEINFO_Model 3
#define TWE_PARAM_DRIVEINFO_Serial 4
#define TWE_PARAM_DRIVEINFO_PhysCylNum 5
#define TWE_PARAM_DRIVEINFO_PhysHeadNum 6
#define TWE_PARAM_DRIVEINFO_PhysSectorNum 7
#define TWE_PARAM_DRIVEINFO_LogCylNum 8
#define TWE_PARAM_DRIVEINFO_LogHeadNum 9
#define TWE_PARAM_DRIVEINFO_LogSectorNum 10
#define TWE_PARAM_DRIVEINFO_UnitNum 11
#define TWE_PARAM_DRIVEINFO_DriveFlags 12
#define TWE_PARAM_APORTTIMEOUT 0x02c0
#define TWE_PARAM_APORTTIMEOUT_READ 2
#define TWE_PARAM_APORTTIMEOUT_WRITE 3
#define TWE_PARAM_APORTTIMEOUT_DEGRADE 4
#define TWE_PARAM_UNITINFO 0x0300
#define TWE_PARAM_UNITINFO_Number 2
#define TWE_PARAM_UNITINFO_Status 3
#define TWE_PARAM_UNITINFO_Capacity 4
#define TWE_PARAM_UNITINFO_DescriptorSize 5
#define TWE_PARAM_UNITINFO_Descriptor 6
#define TWE_PARAM_UNITINFO_Flags 7
#define TWE_PARAM_UNITFLAGS_WCE (1<<0)
#define TWE_PARAM_AEN 0x0401
#define TWE_PARAM_AEN_UnitCode 2
#define TWE_AEN_QUEUE_EMPTY 0x00
#define TWE_AEN_SOFT_RESET 0x01
#define TWE_AEN_DEGRADED_MIRROR 0x02
#define TWE_AEN_CONTROLLER_ERROR 0x03
#define TWE_AEN_REBUILD_FAIL 0x04
#define TWE_AEN_REBUILD_DONE 0x05
#define TWE_AEN_INCOMP_UNIT 0x06
#define TWE_AEN_INIT_DONE 0x07
#define TWE_AEN_UNCLEAN_SHUTDOWN 0x08
#define TWE_AEN_APORT_TIMEOUT 0x09
#define TWE_AEN_DRIVE_ERROR 0x0a
#define TWE_AEN_REBUILD_STARTED 0x0b
#define TWE_AEN_QUEUE_FULL 0xff
#define TWE_AEN_TABLE_UNDEFINED 0x15
#define TWE_AEN_CODE(x) ((x) & 0xff)
#define TWE_AEN_UNIT(x) ((x) >> 8)
#define TWE_PARAM_VERSION 0x0402
#define TWE_PARAM_VERSION_Mon 2
#define TWE_PARAM_VERSION_FW 3
#define TWE_PARAM_VERSION_BIOS 4
#define TWE_PARAM_VERSION_PCB 5
#define TWE_PARAM_VERSION_ATA 6
#define TWE_PARAM_VERSION_PCI 7
#define TWE_PARAM_VERSION_CtrlModel 8
#define TWE_PARAM_VERSION_CtrlSerial 9
#define TWE_PARAM_VERSION_SBufSize 10
#define TWE_PARAM_VERSION_CompCode 11
#define TWE_PARAM_CONTROLLER 0x0403
#define TWE_PARAM_CONTROLLER_DCBSectors 2
#define TWE_PARAM_CONTROLLER_PortCount 3
#define TWE_PARAM_FEATURES 0x404
#define TWE_PARAM_FEATURES_DriverShutdown 2
#define TWE_PARAM_PROC 0x406
#define TWE_PARAM_PROC_PERCENT 2
struct twe_unit_descriptor {
u_int8_t num_subunits;
u_int8_t configuration;
#define TWE_UD_CONFIG_CBOD 0x0c
#define TWE_UD_CONFIG_SPARE 0x0d
#define TWE_UD_CONFIG_SUBUNIT 0x0e
#define TWE_UD_CONFIG_JBOD 0x0f
u_int8_t phys_drv_num;
u_int8_t log_drv_num;
u_int32_t start_lba;
u_int32_t block_count;
} __packed;
struct twe_mirror_descriptor {
u_int8_t flag;
u_int8_t res1;
u_int8_t mirunit_status[4];
u_int8_t res2[6];
} __packed;
struct twe_array_descriptor {
u_int8_t num_subunits;
u_int8_t configuration;
#define TWE_AD_CONFIG_RAID0 0x00
#define TWE_AD_CONFIG_RAID1 0x01
#define TWE_AD_CONFIG_TwinStor 0x02
#define TWE_AD_CONFIG_RAID5 0x05
#define TWE_AD_CONFIG_RAID10 0x06
u_int8_t stripe_size;
#define TWE_AD_STRIPE_4k 0x03
#define TWE_AD_STRIPE_8k 0x04
#define TWE_AD_STRIPE_16k 0x05
#define TWE_AD_STRIPE_32k 0x06
#define TWE_AD_STRIPE_64k 0x07
#define TWE_AD_STRIPE_128k 0x08
#define TWE_AD_STRIPE_256k 0x09
#define TWE_AD_STRIPE_512k 0x0a
#define TWE_AD_STRIPE_1024k 0x0b
u_int8_t log_drv_status;
u_int32_t start_lba;
u_int32_t block_count;
struct twe_unit_descriptor subunit[1];
} __packed;
#endif