Home | History | Annotate | Line # | Download | only in pci
twareg.h revision 1.2.4.1
      1  1.2.4.1   gdamore /*	$NetBSD: twareg.h,v 1.2.4.1 2006/07/13 17:49:29 gdamore Exp $ */
      2      1.1  wrstuden /*	$wasabi: twareg.h,v 1.11 2006/04/27 17:12:39 wrstuden Exp $	*/
      3      1.1  wrstuden 
      4      1.1  wrstuden /*-
      5      1.1  wrstuden  * Copyright (c) 2003-04 3ware, Inc.
      6      1.1  wrstuden  * All rights reserved.
      7      1.1  wrstuden  *
      8      1.1  wrstuden  * Redistribution and use in source and binary forms, with or without
      9      1.1  wrstuden  * modification, are permitted provided that the following conditions
     10      1.1  wrstuden  * are met:
     11      1.1  wrstuden  * 1. Redistributions of source code must retain the above copyright
     12      1.1  wrstuden  *    notice, this list of conditions and the following disclaimer.
     13      1.1  wrstuden  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  wrstuden  *    notice, this list of conditions and the following disclaimer in the
     15      1.1  wrstuden  *    documentation and/or other materials provided with the distribution.
     16      1.1  wrstuden  *
     17      1.1  wrstuden  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     18      1.1  wrstuden  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19      1.1  wrstuden  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20      1.1  wrstuden  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     21      1.1  wrstuden  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22      1.1  wrstuden  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23      1.1  wrstuden  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24      1.1  wrstuden  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25      1.1  wrstuden  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26      1.1  wrstuden  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27      1.1  wrstuden  * SUCH DAMAGE.
     28      1.1  wrstuden  *
     29      1.1  wrstuden  *	$FreeBSD: src/sys/dev/twa/twa_reg.h,v 1.2 2004/08/18 16:14:44 vkashyap Exp $
     30      1.1  wrstuden  */
     31      1.1  wrstuden 
     32      1.1  wrstuden /*
     33      1.1  wrstuden  * 3ware driver for 9000 series storage controllers.
     34      1.1  wrstuden  *
     35      1.1  wrstuden  * Author: Vinod Kashyap
     36      1.1  wrstuden  */
     37      1.1  wrstuden 
     38      1.1  wrstuden #ifndef _PCI_TWAREG_H_
     39      1.1  wrstuden #define	_PCI_TWAREG_H_
     40      1.1  wrstuden 
     41      1.1  wrstuden #if defined(_KERNEL)
     42      1.1  wrstuden #include <machine/bus.h>
     43      1.1  wrstuden 
     44      1.1  wrstuden /*
     45      1.1  wrstuden  * The following macro has no business being in twa_reg.h.  It should probably
     46      1.1  wrstuden  * be defined in twa_includes.h, before the #include twa_reg.h....  But that
     47      1.1  wrstuden  * causes the API to run into build errors.  Will leave it here for now...
     48      1.1  wrstuden  */
     49      1.1  wrstuden #define TWA_64BIT_ADDRESSES	((sizeof(bus_addr_t) == 8) ? 1 : 0)
     50      1.1  wrstuden 
     51      1.1  wrstuden /*
     52      1.1  wrstuden  * Define the following here since it relies on TWA_64BIT_ADDRESSES which
     53      1.1  wrstuden  * depends on sizeof(bus_addr_t), which is not exported to userland.
     54      1.1  wrstuden  * The userland API shouldn't care about the kernel's bus_addr_t.
     55      1.1  wrstuden  * For the userland API, use the array size that we would use for 32-bit
     56      1.1  wrstuden  * addresses since that's what we use in the sg structure definition.
     57      1.1  wrstuden  * The userland API does not actually appear to use the array, but it
     58      1.1  wrstuden  * does include the array in various command structures.
     59      1.1  wrstuden  */
     60      1.1  wrstuden #define TWA_MAX_SG_ELEMENTS		(TWA_64BIT_ADDRESSES ? 70 : 105)
     61      1.1  wrstuden #else
     62      1.1  wrstuden #define TWA_MAX_SG_ELEMENTS		105
     63      1.1  wrstuden #endif
     64      1.1  wrstuden 
     65      1.1  wrstuden #define TWAQ_FREE	0
     66      1.1  wrstuden #define TWAQ_BUSY	1
     67      1.1  wrstuden #define TWAQ_PENDING	2
     68      1.1  wrstuden #define TWAQ_COMPLETE	3
     69      1.1  wrstuden #define TWAQ_IO_PENDING 4
     70      1.1  wrstuden #define TWAQ_COUNT	5	/* total number of queues */
     71      1.1  wrstuden 
     72      1.1  wrstuden #define TWA_DRIVER_VERSION_STRING		"1.00.00.000"
     73      1.1  wrstuden 
     74      1.1  wrstuden #define TWA_REQUEST_TIMEOUT_PERIOD		60 /* seconds */
     75      1.1  wrstuden 
     76      1.1  wrstuden #define TWA_MESSAGE_SOURCE_CONTROLLER_ERROR	3
     77      1.1  wrstuden 
     78      1.1  wrstuden /* Register offsets from base address. */
     79      1.1  wrstuden #define	TWA_CONTROL_REGISTER_OFFSET		0x0
     80      1.1  wrstuden #define	TWA_STATUS_REGISTER_OFFSET		0x4
     81      1.1  wrstuden #define	TWA_COMMAND_QUEUE_OFFSET		0x8
     82      1.1  wrstuden #define	TWA_RESPONSE_QUEUE_OFFSET		0xC
     83      1.1  wrstuden #define	TWA_COMMAND_QUEUE_OFFSET_LOW		0x20
     84      1.1  wrstuden #define	TWA_COMMAND_QUEUE_OFFSET_HIGH		0x24
     85      1.1  wrstuden 
     86      1.1  wrstuden #if defined(_KERNEL)
     87      1.1  wrstuden #define TWA_WRITE_REGISTER(sc, offset, val)	\
     88  1.2.4.1   gdamore 	bus_space_write_4(sc->twa_bus_iot, sc->twa_bus_ioh, offset, (uint32_t)val)
     89      1.1  wrstuden 
     90      1.1  wrstuden #define TWA_WRITE_COMMAND_QUEUE(sc, val)				\
     91      1.1  wrstuden 	do {								\
     92      1.1  wrstuden 		if (TWA_64BIT_ADDRESSES) {				\
     93      1.1  wrstuden 			/* First write the low 4 bytes, then the high 4. */  \
     94      1.1  wrstuden 			TWA_WRITE_REGISTER(sc, TWA_COMMAND_QUEUE_OFFSET_LOW, \
     95  1.2.4.1   gdamore 						(uint32_t)(val));	\
     96      1.1  wrstuden 			TWA_WRITE_REGISTER(sc, TWA_COMMAND_QUEUE_OFFSET_HIGH,\
     97  1.2.4.1   gdamore 					(uint32_t)(((uint64_t)val)>>32));  \
     98      1.1  wrstuden 		} else							\
     99      1.1  wrstuden 			TWA_WRITE_REGISTER(sc, TWA_COMMAND_QUEUE_OFFSET,\
    100  1.2.4.1   gdamore 						(uint32_t)(val)); \
    101      1.1  wrstuden 	} while (0)
    102      1.1  wrstuden #endif
    103      1.1  wrstuden 
    104      1.1  wrstuden /* Control register bit definitions. */
    105      1.1  wrstuden #define TWA_CONTROL_CLEAR_SBUF_WRITE_ERROR	0x00000008
    106      1.1  wrstuden #define TWA_CONTROL_ISSUE_HOST_INTERRUPT	0x00000020
    107      1.1  wrstuden #define TWA_CONTROL_DISABLE_INTERRUPTS		0x00000040
    108      1.1  wrstuden #define TWA_CONTROL_ENABLE_INTERRUPTS		0x00000080
    109      1.1  wrstuden #define TWA_CONTROL_ISSUE_SOFT_RESET		0x00000100
    110      1.1  wrstuden #define TWA_CONTROL_UNMASK_RESPONSE_INTERRUPT	0x00004000
    111      1.1  wrstuden #define TWA_CONTROL_UNMASK_COMMAND_INTERRUPT	0x00008000
    112      1.1  wrstuden #define TWA_CONTROL_MASK_RESPONSE_INTERRUPT	0x00010000
    113      1.1  wrstuden #define TWA_CONTROL_MASK_COMMAND_INTERRUPT	0x00020000
    114      1.1  wrstuden #define TWA_CONTROL_CLEAR_ATTENTION_INTERRUPT	0x00040000
    115      1.1  wrstuden #define TWA_CONTROL_CLEAR_HOST_INTERRUPT	0x00080000
    116      1.1  wrstuden #define TWA_CONTROL_CLEAR_PCI_ABORT		0x00100000
    117      1.1  wrstuden #define TWA_CONTROL_CLEAR_QUEUE_ERROR		0x00400000
    118      1.1  wrstuden #define TWA_CONTROL_CLEAR_PARITY_ERROR		0x00800000
    119      1.1  wrstuden 
    120      1.1  wrstuden /* Status register bit definitions. */
    121      1.1  wrstuden #define TWA_STATUS_ROM_BIOS_IN_SBUF		0x00000002
    122      1.1  wrstuden #define TWA_STATUS_SBUF_WRITE_ERROR		0x00000008
    123      1.1  wrstuden #define TWA_STATUS_COMMAND_QUEUE_EMPTY		0x00001000
    124      1.1  wrstuden #define TWA_STATUS_MICROCONTROLLER_READY	0x00002000
    125      1.1  wrstuden #define TWA_STATUS_RESPONSE_QUEUE_EMPTY		0x00004000
    126      1.1  wrstuden #define TWA_STATUS_COMMAND_QUEUE_FULL		0x00008000
    127      1.1  wrstuden #define TWA_STATUS_RESPONSE_INTERRUPT		0x00010000
    128      1.1  wrstuden #define TWA_STATUS_COMMAND_INTERRUPT		0x00020000
    129      1.1  wrstuden #define TWA_STATUS_ATTENTION_INTERRUPT		0x00040000
    130      1.1  wrstuden #define TWA_STATUS_HOST_INTERRUPT		0x00080000
    131      1.1  wrstuden #define TWA_STATUS_PCI_ABORT_INTERRUPT		0x00100000
    132      1.1  wrstuden #define TWA_STATUS_MICROCONTROLLER_ERROR	0x00200000
    133      1.1  wrstuden #define TWA_STATUS_QUEUE_ERROR_INTERRUPT	0x00400000
    134      1.1  wrstuden #define TWA_STATUS_PCI_PARITY_ERROR_INTERRUPT	0x00800000
    135      1.1  wrstuden #define TWA_STATUS_MINOR_VERSION_MASK		0x0F000000
    136      1.1  wrstuden #define TWA_STATUS_MAJOR_VERSION_MASK		0xF0000000
    137      1.1  wrstuden 
    138      1.1  wrstuden #define TWA_STATUS_EXPECTED_BITS		0x00002000
    139      1.1  wrstuden #define TWA_STATUS_UNEXPECTED_BITS		0x00F00000
    140      1.1  wrstuden 
    141      1.1  wrstuden /* For use with the %b printf format. */
    142      1.1  wrstuden #define TWA_STATUS_BITS_DESCRIPTION \
    143      1.1  wrstuden 	"\20\15CMD_Q_EMPTY\16MC_RDY\17RESP_Q_EMPTY\20CMD_Q_FULL\21RESP_INTR\22CMD_INTR\23ATTN_INTR\24HOST_INTR\25PCI_ABRT\26MC_ERR\27Q_ERR\30PCI_PERR\n"
    144      1.1  wrstuden 
    145      1.1  wrstuden /* Detect inconsistencies in the status register. */
    146      1.1  wrstuden #define TWA_STATUS_ERRORS(x)			\
    147      1.1  wrstuden 	((x & TWA_STATUS_UNEXPECTED_BITS) &&	\
    148      1.1  wrstuden 	 (x & TWA_STATUS_MICROCONTROLLER_READY))
    149      1.1  wrstuden 
    150      1.1  wrstuden /* PCI related defines. */
    151      1.1  wrstuden #define TWA_IO_CONFIG_REG		0x10
    152      1.1  wrstuden #define TWA_DEVICE_NAME			"3ware 9000 series Storage Controller"
    153      1.1  wrstuden #define TWA_VENDOR_ID			0x13C1
    154      1.1  wrstuden #define TWA_DEVICE_ID_9K		0x1002
    155      1.1  wrstuden 
    156      1.1  wrstuden #define TWA_PCI_CONFIG_CLEAR_PARITY_ERROR	0xc100
    157      1.1  wrstuden #define TWA_PCI_CONFIG_CLEAR_PCI_ABORT		0x2000
    158      1.1  wrstuden 
    159      1.1  wrstuden /* Command packet opcodes. */
    160      1.1  wrstuden #define TWA_OP_NOP			0x00
    161      1.1  wrstuden #define TWA_OP_INIT_CONNECTION		0x01
    162      1.1  wrstuden #define TWA_OP_READ			0x02
    163      1.1  wrstuden #define TWA_OP_WRITE			0x03
    164      1.1  wrstuden #define TWA_OP_READVERIFY		0x04
    165      1.1  wrstuden #define TWA_OP_VERIFY			0x05
    166      1.1  wrstuden #define TWA_OP_ZEROUNIT			0x08
    167      1.1  wrstuden #define TWA_OP_REPLACEUNIT		0x09
    168      1.1  wrstuden #define TWA_OP_HOTSWAP			0x0A
    169      1.1  wrstuden #define TWA_OP_SELFTESTS		0x0B
    170      1.1  wrstuden #define TWA_OP_SYNC_PARAM		0x0C
    171      1.1  wrstuden #define TWA_OP_REORDER_UNITS		0x0D
    172      1.1  wrstuden #define TWA_OP_FLUSH			0x0E
    173      1.1  wrstuden #define TWA_OP_EXECUTE_SCSI_COMMAND	0x10
    174      1.1  wrstuden #define TWA_OP_ATA_PASSTHROUGH		0x11
    175      1.1  wrstuden #define TWA_OP_GET_PARAM		0x12
    176      1.1  wrstuden #define TWA_OP_SET_PARAM		0x13
    177      1.1  wrstuden #define TWA_OP_CREATEUNIT		0x14
    178      1.1  wrstuden #define TWA_OP_DELETEUNIT		0x15
    179      1.1  wrstuden #define TWA_OP_DOWNLOAD_FIRMWARE	0x16
    180      1.1  wrstuden #define TWA_OP_REBUILDUNIT		0x17
    181      1.1  wrstuden #define TWA_OP_POWER_MANAGEMENT		0x18
    182      1.1  wrstuden 
    183      1.1  wrstuden #define TWA_OP_REMOTE_PRINT		0x1B
    184      1.1  wrstuden #define TWA_OP_RESET_FIRMWARE		0x1C
    185      1.1  wrstuden #define TWA_OP_DEBUG			0x1D
    186      1.1  wrstuden 
    187      1.1  wrstuden #define TWA_OP_DIAGNOSTICS		0x1F
    188      1.1  wrstuden 
    189      1.1  wrstuden /* Misc defines. */
    190      1.1  wrstuden #define TWA_ALIGNMENT			0x4
    191      1.1  wrstuden #define TWA_MAX_UNITS			16
    192      1.1  wrstuden #define TWA_INIT_MESSAGE_CREDITS	0x100
    193      1.1  wrstuden #define TWA_SHUTDOWN_MESSAGE_CREDITS	0x001
    194      1.1  wrstuden #define TWA_64BIT_SG_ADDRESSES		0x00000001
    195      1.1  wrstuden #define TWA_EXTENDED_INIT_CONNECT	0x00000002
    196      1.1  wrstuden #define TWA_BASE_MODE			1
    197      1.1  wrstuden #define TWA_BASE_FW_SRL			24
    198      1.1  wrstuden #define TWA_BASE_FW_BRANCH		0
    199      1.1  wrstuden #define TWA_BASE_FW_BUILD		1
    200      1.1  wrstuden #define TWA_CURRENT_FW_SRL		28
    201      1.1  wrstuden #define TWA_CURRENT_FW_BRANCH		4
    202      1.1  wrstuden #define TWA_CURRENT_FW_BUILD		9
    203      1.1  wrstuden #define TWA_9000_ARCH_ID		0x5	/* 9000 series controllers */
    204      1.1  wrstuden #define TWA_CTLR_FW_SAME_OR_NEWER	0x00000001
    205      1.1  wrstuden #define TWA_CTLR_FW_COMPATIBLE		0x00000002
    206      1.1  wrstuden #define TWA_BUNDLED_FW_SAFE_TO_FLASH	0x00000004
    207      1.1  wrstuden #define TWA_CTLR_FW_RECOMMENDS_FLASH	0x00000008
    208      1.1  wrstuden #define NUM_FW_IMAGE_CHUNKS		5
    209      1.1  wrstuden #define TWA_MAX_IO_SIZE			0x20000	/* 128K */
    210      1.1  wrstuden /* #define TWA_MAX_SG_ELEMENTS		defined above */
    211      1.1  wrstuden #define TWA_MAX_ATA_SG_ELEMENTS		60
    212      1.1  wrstuden #define TWA_Q_LENGTH			TWA_INIT_MESSAGE_CREDITS
    213      1.1  wrstuden #define TWA_MAX_RESET_TRIES		3
    214      1.1  wrstuden #define TWA_SECTOR_SIZE			0x200	/* generic I/O bufffer */
    215      1.1  wrstuden #define TWA_SENSE_DATA_LENGTH		18
    216      1.1  wrstuden 
    217      1.1  wrstuden #define TWA_ERROR_LOGICAL_UNIT_NOT_SUPPORTED	0x010a
    218      1.1  wrstuden #define TWA_ERROR_UNIT_OFFLINE			0x0128
    219      1.1  wrstuden #define TWA_ERROR_MORE_DATA			0x0231
    220      1.1  wrstuden 
    221      1.1  wrstuden /* Scatter/Gather list entry. */
    222      1.1  wrstuden struct twa_sg {
    223      1.1  wrstuden #if defined(_KERNEL)
    224      1.1  wrstuden 	bus_addr_t	address;
    225      1.1  wrstuden #else
    226  1.2.4.1   gdamore 	uint32_t	xx_address_xx;	/* Fail if userland tries to use this */
    227      1.1  wrstuden #endif
    228  1.2.4.1   gdamore 	uint32_t	length;
    229      1.1  wrstuden } __attribute__ ((packed));
    230      1.1  wrstuden 
    231      1.1  wrstuden 
    232      1.1  wrstuden /* 7000 structures. */
    233      1.1  wrstuden struct twa_command_init_connect {
    234  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_OP_INITCONNECTION */
    235  1.2.4.1   gdamore 	uint8_t		res1:3;
    236  1.2.4.1   gdamore 	uint8_t		size;
    237  1.2.4.1   gdamore 	uint8_t		request_id;
    238  1.2.4.1   gdamore 	uint8_t		res2;
    239  1.2.4.1   gdamore 	uint8_t		status;
    240  1.2.4.1   gdamore 	uint8_t		flags;
    241  1.2.4.1   gdamore 	uint16_t	message_credits;
    242  1.2.4.1   gdamore 	uint32_t	features;
    243  1.2.4.1   gdamore 	uint16_t	fw_srl;
    244  1.2.4.1   gdamore 	uint16_t	fw_arch_id;
    245  1.2.4.1   gdamore 	uint16_t	fw_branch;
    246  1.2.4.1   gdamore 	uint16_t	fw_build;
    247  1.2.4.1   gdamore 	uint32_t	result;
    248      1.1  wrstuden }__attribute__ ((packed));
    249      1.1  wrstuden 
    250      1.1  wrstuden struct twa_command_download_firmware {
    251  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_DOWNLOAD_FIRMWARE */
    252  1.2.4.1   gdamore 	uint8_t		sgl_offset:3;
    253  1.2.4.1   gdamore 	uint8_t		size;
    254  1.2.4.1   gdamore 	uint8_t		request_id;
    255  1.2.4.1   gdamore 	uint8_t		unit;
    256  1.2.4.1   gdamore 	uint8_t		status;
    257  1.2.4.1   gdamore 	uint8_t		flags;
    258  1.2.4.1   gdamore 	uint16_t	param;
    259      1.1  wrstuden 	struct twa_sg	sgl[TWA_MAX_SG_ELEMENTS];
    260      1.1  wrstuden } __attribute__ ((packed));
    261      1.1  wrstuden 
    262      1.1  wrstuden 
    263      1.1  wrstuden struct twa_command_reset_firmware {
    264  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_OP_RESET_FIRMWARE */
    265  1.2.4.1   gdamore 	uint8_t		res1:3;
    266  1.2.4.1   gdamore 	uint8_t		size;
    267  1.2.4.1   gdamore 	uint8_t		request_id;
    268  1.2.4.1   gdamore 	uint8_t		unit;
    269  1.2.4.1   gdamore 	uint8_t		status;
    270  1.2.4.1   gdamore 	uint8_t		flags;
    271  1.2.4.1   gdamore 	uint8_t		res2;
    272  1.2.4.1   gdamore 	uint8_t		param;
    273      1.1  wrstuden } __attribute__ ((packed));
    274      1.1  wrstuden 
    275      1.1  wrstuden 
    276      1.1  wrstuden struct twa_command_io {
    277  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_OP_READ/TWA_OP_WRITE */
    278  1.2.4.1   gdamore 	uint8_t		sgl_offset:3;
    279  1.2.4.1   gdamore 	uint8_t		size;
    280  1.2.4.1   gdamore 	uint8_t		request_id;
    281  1.2.4.1   gdamore 	uint8_t		unit:4;
    282  1.2.4.1   gdamore 	uint8_t		host_id:4;
    283  1.2.4.1   gdamore 	uint8_t		status;
    284  1.2.4.1   gdamore 	uint8_t		flags;
    285  1.2.4.1   gdamore 	uint16_t	block_count;
    286  1.2.4.1   gdamore 	uint32_t	lba;
    287      1.1  wrstuden 	struct twa_sg	sgl[TWA_MAX_SG_ELEMENTS];
    288      1.1  wrstuden } __attribute__ ((packed));
    289      1.1  wrstuden 
    290      1.1  wrstuden 
    291      1.1  wrstuden struct twa_command_hotswap {
    292  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_OP_HOTSWAP */
    293  1.2.4.1   gdamore 	uint8_t		res1:3;
    294  1.2.4.1   gdamore 	uint8_t		size;
    295  1.2.4.1   gdamore 	uint8_t		request_id;
    296  1.2.4.1   gdamore 	uint8_t		unit:4;
    297  1.2.4.1   gdamore 	uint8_t		host_id:4;
    298  1.2.4.1   gdamore 	uint8_t		status;
    299  1.2.4.1   gdamore 	uint8_t		flags;
    300  1.2.4.1   gdamore 	uint8_t		action;
    301      1.1  wrstuden #define TWA_OP_HOTSWAP_REMOVE		0x00	/* remove assumed-degraded unit */
    302      1.1  wrstuden #define TWA_OP_HOTSWAP_ADD_CBOD		0x01	/* add CBOD to empty port */
    303      1.1  wrstuden #define TWA_OP_HOTSWAP_ADD_SPARE	0x02	/* add spare to empty port */
    304  1.2.4.1   gdamore 	uint8_t		aport;
    305      1.1  wrstuden } __attribute__ ((packed));
    306      1.1  wrstuden 
    307      1.1  wrstuden 
    308      1.1  wrstuden struct twa_command_param {
    309  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_OP_GETPARAM, TWA_OP_SETPARAM */
    310  1.2.4.1   gdamore 	uint8_t		sgl_offset:3;
    311  1.2.4.1   gdamore 	uint8_t		size;
    312  1.2.4.1   gdamore 	uint8_t		request_id;
    313  1.2.4.1   gdamore 	uint8_t		unit:4;
    314  1.2.4.1   gdamore 	uint8_t		host_id:4;
    315  1.2.4.1   gdamore 	uint8_t		status;
    316  1.2.4.1   gdamore 	uint8_t		flags;
    317  1.2.4.1   gdamore 	uint16_t	param_count;
    318      1.1  wrstuden 	struct twa_sg	sgl[TWA_MAX_SG_ELEMENTS];
    319      1.1  wrstuden } __attribute__ ((packed));
    320      1.1  wrstuden 
    321      1.1  wrstuden 
    322      1.1  wrstuden struct twa_command_rebuildunit {
    323  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_OP_REBUILDUNIT */
    324  1.2.4.1   gdamore 	uint8_t		res1:3;
    325  1.2.4.1   gdamore 	uint8_t		size;
    326  1.2.4.1   gdamore 	uint8_t		request_id;
    327  1.2.4.1   gdamore 	uint8_t		src_unit:4;
    328  1.2.4.1   gdamore 	uint8_t		host_id:4;
    329  1.2.4.1   gdamore 	uint8_t		status;
    330  1.2.4.1   gdamore 	uint8_t		flags;
    331  1.2.4.1   gdamore 	uint8_t		action:7;
    332      1.1  wrstuden #define TWA_OP_REBUILDUNIT_NOP		0
    333      1.1  wrstuden #define TWA_OP_REBUILDUNIT_STOP		2	/* stop all rebuilds */
    334      1.1  wrstuden #define TWA_OP_REBUILDUNIT_START	4	/* start rebuild with lowest unit */
    335      1.1  wrstuden #define TWA_OP_REBUILDUNIT_STARTUNIT	5	/* rebuild src_unit (not supported) */
    336  1.2.4.1   gdamore 	uint8_t		cs:1;			/* request state change on src_unit */
    337  1.2.4.1   gdamore 	uint8_t		logical_subunit;	/* for RAID10 rebuild of logical subunit */
    338      1.1  wrstuden } __attribute__ ((packed));
    339      1.1  wrstuden 
    340      1.1  wrstuden 
    341      1.1  wrstuden struct twa_command_ata {
    342  1.2.4.1   gdamore 	uint8_t		opcode:5;	/* TWA_OP_ATA_PASSTHROUGH */
    343  1.2.4.1   gdamore 	uint8_t		sgl_offset:3;
    344  1.2.4.1   gdamore 	uint8_t		size;
    345  1.2.4.1   gdamore 	uint8_t		request_id;
    346  1.2.4.1   gdamore 	uint8_t		unit:4;
    347  1.2.4.1   gdamore 	uint8_t		host_id:4;
    348  1.2.4.1   gdamore 	uint8_t		status;
    349  1.2.4.1   gdamore 	uint8_t		flags;
    350  1.2.4.1   gdamore 	uint16_t	param;
    351  1.2.4.1   gdamore 	uint16_t	features;
    352  1.2.4.1   gdamore 	uint16_t	sector_count;
    353  1.2.4.1   gdamore 	uint16_t	sector_num;
    354  1.2.4.1   gdamore 	uint16_t	cylinder_lo;
    355  1.2.4.1   gdamore 	uint16_t	cylinder_hi;
    356  1.2.4.1   gdamore 	uint8_t		drive_head;
    357  1.2.4.1   gdamore 	uint8_t		command;
    358      1.1  wrstuden 	struct twa_sg	sgl[TWA_MAX_ATA_SG_ELEMENTS];
    359      1.1  wrstuden } __attribute__ ((packed));
    360      1.1  wrstuden 
    361      1.1  wrstuden 
    362      1.1  wrstuden struct twa_command_generic {
    363  1.2.4.1   gdamore 	uint8_t		opcode:5;
    364  1.2.4.1   gdamore 	uint8_t		sgl_offset:3;
    365  1.2.4.1   gdamore 	uint8_t		size;
    366  1.2.4.1   gdamore 	uint8_t		request_id;
    367  1.2.4.1   gdamore 	uint8_t		unit:4;
    368  1.2.4.1   gdamore 	uint8_t		host_id:4;
    369  1.2.4.1   gdamore 	uint8_t		status;
    370  1.2.4.1   gdamore 	uint8_t		flags;
    371      1.1  wrstuden #define TWA_FLAGS_SUCCESS	0x00
    372      1.1  wrstuden #define TWA_FLAGS_INFORMATIONAL	0x01
    373      1.1  wrstuden #define TWA_FLAGS_WARNING	0x02
    374      1.1  wrstuden #define TWA_FLAGS_FATAL		0x03
    375      1.1  wrstuden #define TWA_FLAGS_PERCENTAGE	(1<<8)	/* bits 0-6 indicate completion percentage */
    376  1.2.4.1   gdamore 	uint16_t	count;		/* block count, parameter count, message credits */
    377      1.1  wrstuden } __attribute__ ((packed));
    378      1.1  wrstuden 
    379      1.1  wrstuden 
    380      1.1  wrstuden /* Command packet - must be TWA_ALIGNMENT aligned. */
    381      1.1  wrstuden union twa_command_7k {
    382      1.1  wrstuden 	struct twa_command_init_connect		init_connect;
    383      1.1  wrstuden 	struct twa_command_download_firmware	download_fw;
    384      1.1  wrstuden 	struct twa_command_reset_firmware	reset_fw;
    385      1.1  wrstuden 	struct twa_command_io			io;
    386      1.1  wrstuden 	struct twa_command_hotswap		hotswap;
    387      1.1  wrstuden 	struct twa_command_param		param;
    388      1.1  wrstuden 	struct twa_command_rebuildunit		rebuildunit;
    389      1.1  wrstuden 	struct twa_command_ata			ata;
    390      1.1  wrstuden 	struct twa_command_generic		generic;
    391      1.1  wrstuden } __attribute__ ((packed));
    392      1.1  wrstuden 
    393      1.1  wrstuden 
    394      1.1  wrstuden /* 9000 structures. */
    395      1.1  wrstuden 
    396      1.1  wrstuden /* Command Packet. */
    397      1.1  wrstuden struct twa_command_9k {
    398      1.1  wrstuden 	struct {
    399  1.2.4.1   gdamore 		uint8_t		opcode:5;
    400  1.2.4.1   gdamore 		uint8_t		reserved:3;
    401      1.1  wrstuden 	} command;
    402  1.2.4.1   gdamore 	uint8_t		unit;
    403  1.2.4.1   gdamore 	uint16_t	request_id;
    404  1.2.4.1   gdamore 	uint8_t		status;
    405  1.2.4.1   gdamore 	uint8_t		sgl_offset; /* offset (in bytes) to sg_list, from the end of sgl_entries */
    406  1.2.4.1   gdamore 	uint16_t	sgl_entries;
    407  1.2.4.1   gdamore 	uint8_t		cdb[16];
    408      1.1  wrstuden 	struct twa_sg	sg_list[TWA_MAX_SG_ELEMENTS];
    409  1.2.4.1   gdamore 	uint8_t		padding[32];
    410      1.1  wrstuden } __attribute__ ((packed));
    411      1.1  wrstuden 
    412      1.1  wrstuden 
    413      1.1  wrstuden /* Command packet header. */
    414      1.1  wrstuden struct twa_command_header {
    415  1.2.4.1   gdamore 	uint8_t		sense_data[TWA_SENSE_DATA_LENGTH];
    416      1.1  wrstuden 	struct {
    417      1.1  wrstuden 		int8_t		reserved[4];
    418  1.2.4.1   gdamore 		uint16_t	error;
    419  1.2.4.1   gdamore 		uint8_t		padding;
    420      1.1  wrstuden 		struct {
    421  1.2.4.1   gdamore 			uint8_t		severity:3;
    422  1.2.4.1   gdamore 			uint8_t		reserved:5;
    423      1.1  wrstuden 		} substatus_block;
    424      1.1  wrstuden 	} status_block;
    425  1.2.4.1   gdamore 	uint8_t		err_specific_desc[98];
    426      1.1  wrstuden 	struct {
    427  1.2.4.1   gdamore 		uint8_t		size_header;
    428  1.2.4.1   gdamore 		uint16_t	reserved;
    429  1.2.4.1   gdamore 		uint8_t		size_sense;
    430      1.1  wrstuden 	} header_desc;
    431  1.2.4.1   gdamore 	uint8_t		reserved[2];
    432      1.1  wrstuden } __attribute__ ((packed));
    433      1.1  wrstuden 
    434      1.1  wrstuden 
    435      1.1  wrstuden /* Full command packet. */
    436      1.1  wrstuden struct twa_command_packet {
    437      1.1  wrstuden 	struct twa_command_header	cmd_hdr;
    438      1.1  wrstuden 	union {
    439      1.1  wrstuden 		union twa_command_7k	cmd_pkt_7k;
    440      1.1  wrstuden 		struct twa_command_9k 	cmd_pkt_9k;
    441      1.1  wrstuden 	} command;
    442      1.1  wrstuden } __attribute__ ((packed));
    443      1.1  wrstuden 
    444      1.1  wrstuden 
    445      1.1  wrstuden /* Response queue entry. */
    446      1.1  wrstuden union twa_response_queue {
    447      1.1  wrstuden 	struct {
    448  1.2.4.1   gdamore 		uint32_t	undefined_1:4;
    449  1.2.4.1   gdamore 		uint32_t	response_id:8;
    450  1.2.4.1   gdamore 		uint32_t	undefined_2:20;
    451      1.1  wrstuden 	} u;
    452  1.2.4.1   gdamore 	uint32_t	value;
    453      1.1  wrstuden } __attribute__ ((packed));
    454      1.1  wrstuden 
    455      1.1  wrstuden 
    456      1.1  wrstuden #define TWA_AEN_QUEUE_EMPTY		0x00
    457      1.1  wrstuden #define TWA_AEN_SOFT_RESET		0x01
    458      1.1  wrstuden #define TWA_AEN_SYNC_TIME_WITH_HOST	0x31
    459      1.1  wrstuden #define TWA_AEN_SEVERITY_ERROR		0x1
    460      1.1  wrstuden #define TWA_AEN_SEVERITY_WARNING	0x1
    461      1.1  wrstuden #define TWA_AEN_SEVERITY_INFO		0x1
    462      1.1  wrstuden #define TWA_AEN_SEVERITY_DEBUG		0x4
    463      1.1  wrstuden 
    464      1.1  wrstuden #define	TWA_PARAM_DRIVESUMMARY		0x0002
    465      1.1  wrstuden #define TWA_PARAM_DRIVESTATUS		3
    466      1.1  wrstuden 
    467      1.1  wrstuden #define TWA_DRIVE_DETECTED		0x80
    468      1.1  wrstuden 
    469      1.1  wrstuden #define	TWA_PARAM_DRIVE_TABLE		0x0200
    470      1.1  wrstuden #define TWA_PARAM_DRIVESIZEINDEX	2
    471      1.1  wrstuden #define TWA_PARAM_DRIVEMODELINDEX	3
    472      1.1  wrstuden 
    473      1.1  wrstuden #define TWA_PARAM_DRIVESIZE_LENGTH	4
    474      1.1  wrstuden #define TWA_PARAM_DRIVEMODEL_LENGTH	40
    475      1.1  wrstuden 
    476      1.1  wrstuden 
    477      1.1  wrstuden #define TWA_PARAM_VERSION		0x0402
    478      1.1  wrstuden #define TWA_PARAM_VERSION_Mon		2	/* monitor version [16] */
    479      1.1  wrstuden #define TWA_PARAM_VERSION_FW		3	/* firmware version [16] */
    480      1.1  wrstuden #define TWA_PARAM_VERSION_BIOS		4	/* BIOSs version [16] */
    481      1.1  wrstuden #define TWA_PARAM_VERSION_PCBA		5	/* PCB version [8] */
    482      1.1  wrstuden #define TWA_PARAM_VERSION_ATA		6	/* A-chip version [8] */
    483      1.1  wrstuden #define TWA_PARAM_VERSION_PCI		7	/* P-chip version [8] */
    484      1.1  wrstuden 
    485      1.1  wrstuden #define TWA_PARAM_CONTROLLER		0x0403
    486      1.1  wrstuden #define TWA_PARAM_CONTROLLER_PortCount	3	/* number of ports [1] */
    487      1.1  wrstuden 
    488      1.1  wrstuden #define TWA_PARAM_TIME_TABLE		0x40A
    489      1.1  wrstuden #define TWA_PARAM_TIME_SchedulerTime	0x3
    490      1.1  wrstuden 
    491      1.1  wrstuden #define TWA_9K_PARAM_DESCRIPTOR		0x8000
    492      1.1  wrstuden 
    493      1.1  wrstuden 
    494      1.1  wrstuden struct twa_param_9k {
    495  1.2.4.1   gdamore 	uint16_t	table_id;
    496  1.2.4.1   gdamore 	uint8_t		parameter_id;
    497  1.2.4.1   gdamore 	uint8_t		reserved;
    498  1.2.4.1   gdamore 	uint16_t	parameter_size_bytes;
    499  1.2.4.1   gdamore 	uint16_t	parameter_actual_size_bytes;
    500  1.2.4.1   gdamore 	uint8_t		data[1];
    501      1.1  wrstuden } __attribute__ ((packed));
    502      1.1  wrstuden 
    503      1.1  wrstuden #endif	/* !_PCI_TWAREG_H_ */
    504