187011Smsmith/*-
287011Smsmith * Copyright (c) 2001 Michael Smith
387011Smsmith * All rights reserved.
487011Smsmith *
587011Smsmith * Redistribution and use in source and binary forms, with or without
687011Smsmith * modification, are permitted provided that the following conditions
787011Smsmith * are met:
887011Smsmith * 1. Redistributions of source code must retain the above copyright
987011Smsmith *    notice, this list of conditions and the following disclaimer.
1087011Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1187011Smsmith *    notice, this list of conditions and the following disclaimer in the
1287011Smsmith *    documentation and/or other materials provided with the distribution.
1387011Smsmith *
1487011Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1587011Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1687011Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1787011Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1887011Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1987011Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2087011Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2187011Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2287011Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2387011Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2487011Smsmith * SUCH DAMAGE.
2587011Smsmith *
2687011Smsmith *	$FreeBSD$
2787011Smsmith */
2887011Smsmith
2987011Smsmith/*
3087011Smsmith * Structure and I/O definitions for the Command Interface for SCSI-3 Support.
3187011Smsmith *
3287011Smsmith * Data in command CDBs are in big-endian format.  All other data is little-endian.
3387011Smsmith * This header only supports little-endian hosts at this time.
3487011Smsmith */
3587011Smsmith
36128334Spsunion ciss_device_address
3787011Smsmith{
3887011Smsmith    struct 				/* MODE_PERIPHERAL and MODE_MASK_PERIPHERAL */
3987011Smsmith    {
4087011Smsmith	u_int32_t	target:24;	/* SCSI target */
4187011Smsmith	u_int32_t	bus:6;		/* SCSI bus */
4287011Smsmith	u_int32_t	mode:2;		/* CISS_HDR_ADDRESS_MODE_* */
4387011Smsmith	u_int32_t	extra_address;	/* SCSI-3 level-2 and level-3 address bytes */
4487011Smsmith    } physical;
4587011Smsmith    struct 				/* MODE_LOGICAL */
4687011Smsmith    {
4787011Smsmith	u_int32_t	lun:30;		/* logical device ID */
4887011Smsmith	u_int32_t	mode:2;		/* CISS_HDR_ADDRESS_MODE_LOGICAL */
4987011Smsmith	u_int32_t	:32;		/* reserved */
5087011Smsmith    } logical;
5187011Smsmith    struct
5287011Smsmith    {
5387011Smsmith	u_int32_t	:30;
5487011Smsmith	u_int32_t	mode:2;
5587011Smsmith	u_int32_t	:32;
5687011Smsmith    } mode;
5787011Smsmith};
5887011Smsmith#define CISS_HDR_ADDRESS_MODE_PERIPHERAL	0x0
5987011Smsmith#define CISS_HDR_ADDRESS_MODE_LOGICAL		0x1
6087011Smsmith#define CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL	0x3
61128334Sps
62130874Sscottl#define CISS_EXTRA_MODE2(extra)		((extra & 0xc0000000) >> 30)
63130874Sscottl#define CISS_EXTRA_BUS2(extra)		((extra & 0x3f000000) >> 24)
64130874Sscottl#define CISS_EXTRA_TARGET2(extra)	((extra & 0x00ff0000) >> 16)
65130874Sscottl#define CISS_EXTRA_MODE3(extra)		((extra & 0x0000c000) >> 14)
66130874Sscottl#define CISS_EXTRA_BUS3(extra)		((extra & 0x00003f00) >> 8)
67130874Sscottl#define CISS_EXTRA_TARGET3(extra)	((extra & 0x000000ff))
68130874Sscottl
69128334Spsstruct ciss_header
7087011Smsmith{
7187011Smsmith    u_int8_t	:8;			/* reserved */
7287011Smsmith    u_int8_t	sg_in_list;		/* SG's in the command structure */
7387011Smsmith    u_int16_t	sg_total;		/* total count of SGs for this command */
7487011Smsmith    u_int32_t	host_tag;		/* host identifier, bits 0&1 must be clear */
7587011Smsmith#define CISS_HDR_HOST_TAG_ERROR	(1<<1)
7687011Smsmith    u_int32_t	host_tag_zeroes;	/* tag is 64 bits, but interface only supports 32 */
7787011Smsmith    union ciss_device_address address;
78103870Salfred} __packed;
7987011Smsmith
8087011Smsmithstruct ciss_cdb
8187011Smsmith{
8287011Smsmith    u_int8_t	cdb_length;		/* valid CDB bytes */
8387011Smsmith    u_int8_t	type:3;
8487011Smsmith#define CISS_CDB_TYPE_COMMAND			0
8587011Smsmith#define CISS_CDB_TYPE_MESSAGE			1
8687011Smsmith    u_int8_t	attribute:3;
8787011Smsmith#define CISS_CDB_ATTRIBUTE_UNTAGGED		0
8887011Smsmith#define CISS_CDB_ATTRIBUTE_SIMPLE		4
8987011Smsmith#define CISS_CDB_ATTRIBUTE_HEAD_OF_QUEUE	5
9087011Smsmith#define CISS_CDB_ATTRIBUTE_ORDERED		6
9187011Smsmith#define CISS_CDB_ATTRIBUTE_AUTO_CONTINGENT	7
9287011Smsmith    u_int8_t	direction:2;
9387011Smsmith#define CISS_CDB_DIRECTION_NONE			0
94123307Sps#define CISS_CDB_DIRECTION_WRITE		1
95123307Sps#define CISS_CDB_DIRECTION_READ			2
9687011Smsmith    u_int16_t	timeout;		/* seconds */
9787011Smsmith#define CISS_CDB_BUFFER_SIZE	16
9887011Smsmith    u_int8_t	cdb[CISS_CDB_BUFFER_SIZE];
99103870Salfred} __packed;
10087011Smsmith
10187011Smsmithstruct ciss_error_info_pointer
10287011Smsmith{
10387011Smsmith    u_int64_t	error_info_address;	/* points to ciss_error_info structure */
10487011Smsmith    u_int32_t	error_info_length;
105103870Salfred} __packed;
10687011Smsmith
10787011Smsmithstruct ciss_error_info
10887011Smsmith{
10987011Smsmith    u_int8_t	scsi_status;
11087011Smsmith#define CISS_SCSI_STATUS_GOOD			0x00	/* these are scsi-standard values */
11187011Smsmith#define CISS_SCSI_STATUS_CHECK_CONDITION	0x02
11287011Smsmith#define CISS_SCSI_STATUS_CONDITION_MET		0x04
11387011Smsmith#define CISS_SCSI_STATUS_BUSY			0x08
11487011Smsmith#define CISS_SCSI_STATUS_INDETERMINATE		0x10
11587011Smsmith#define CISS_SCSI_STATUS_INDETERMINATE_CM	0x14
11687011Smsmith#define CISS_SCSI_STATUS_RESERVATION_CONFLICT	0x18
11787011Smsmith#define CISS_SCSI_STATUS_COMMAND_TERMINATED	0x22
11887011Smsmith#define CISS_SCSI_STATUS_QUEUE_FULL		0x28
11987011Smsmith#define CISS_SCSI_STATUS_ACA_ACTIVE		0x30
12087011Smsmith    u_int8_t	sense_length;
12187011Smsmith    u_int16_t	command_status;
12287011Smsmith#define CISS_CMD_STATUS_SUCCESS			0
12387011Smsmith#define CISS_CMD_STATUS_TARGET_STATUS		1
12487011Smsmith#define CISS_CMD_STATUS_DATA_UNDERRUN		2
12587011Smsmith#define CISS_CMD_STATUS_DATA_OVERRUN		3
12687011Smsmith#define CISS_CMD_STATUS_INVALID_COMMAND		4
12787011Smsmith#define CISS_CMD_STATUS_PROTOCOL_ERROR		5
12887011Smsmith#define CISS_CMD_STATUS_HARDWARE_ERROR		6
12987011Smsmith#define CISS_CMD_STATUS_CONNECTION_LOST		7
13087011Smsmith#define CISS_CMD_STATUS_ABORTED			8
13187011Smsmith#define CISS_CMD_STATUS_ABORT_FAILED		9
13287011Smsmith#define CISS_CMD_STATUS_UNSOLICITED_ABORT	10
13387011Smsmith#define CISS_CMD_STATUS_TIMEOUT			11
13487011Smsmith#define CISS_CMD_STATUS_UNABORTABLE		12
13587011Smsmith    u_int32_t	residual_count;
13687011Smsmith    union {
13787011Smsmith	struct {
13887011Smsmith	    u_int8_t	res1[3];
13987011Smsmith	    u_int8_t	type;
14087011Smsmith	    u_int32_t	error_info;
141132829Sps	} __packed common_info;
14287011Smsmith	struct {
14387011Smsmith	    u_int8_t	res1[2];
14487011Smsmith	    u_int8_t	offense_size;
14587011Smsmith	    u_int8_t	offense_offset;
14687011Smsmith	    u_int32_t	offense_value;
147132829Sps	} __packed invalid_command;
14887011Smsmith    } additional_error_info;
14987011Smsmith    u_int8_t	sense_info[0];
150103870Salfred} __packed;
15187011Smsmith
15287011Smsmithstruct ciss_sg_entry
15387011Smsmith{
15487011Smsmith    u_int64_t	address;
15587011Smsmith#define CISS_SG_ADDRESS_BITBUCKET	(~(u_int64_t)0)
15687011Smsmith    u_int32_t	length;
15787011Smsmith    u_int32_t	:31;
15887011Smsmith    u_int32_t	extension:1;		/* address points to another s/g chain */
159103870Salfred} __packed;
16087011Smsmith
16187011Smsmithstruct ciss_command
16287011Smsmith{
16387011Smsmith    struct ciss_header			header;
16487011Smsmith    struct ciss_cdb			cdb;
16587011Smsmith    struct ciss_error_info_pointer	error_info;
16687011Smsmith    struct ciss_sg_entry		sg[0];
167103870Salfred} __packed;
16887011Smsmith
16987011Smsmith#define CISS_OPCODE_REPORT_LOGICAL_LUNS		0xc2
17087011Smsmith#define CISS_OPCODE_REPORT_PHYSICAL_LUNS	0xc3
17187011Smsmith
172128334Spsstruct ciss_lun_report
17387011Smsmith{
17487011Smsmith    u_int32_t	list_size;		/* big-endian */
17587011Smsmith    u_int32_t	:32;
17687011Smsmith    union ciss_device_address lun[0];
177103870Salfred} __packed;
17887011Smsmith
179110366Sps#define	CISS_VPD_LOGICAL_DRIVE_GEOMETRY		0xc1
180110366Spsstruct ciss_ldrive_geometry
181110366Sps{
182110366Sps    u_int8_t	periph_qualifier:3;
183110366Sps    u_int8_t	periph_devtype:5;
184110366Sps    u_int8_t	page_code;
185110366Sps    u_int8_t	res1;
186110366Sps    u_int8_t	page_length;
187110366Sps    u_int16_t	cylinders;		/* big-endian */
188110366Sps    u_int8_t	heads;
189110366Sps    u_int8_t	sectors;
190110366Sps    u_int8_t	fault_tolerance;
191110366Sps    u_int8_t	res2[3];
192110366Sps} __attribute__ ((packed));
193110366Sps
194128334Spsstruct ciss_report_cdb
19587011Smsmith{
19687011Smsmith    u_int8_t	opcode;
19787011Smsmith    u_int8_t	reserved[5];
19887011Smsmith    u_int32_t	length;			/* big-endian */
19987011Smsmith    u_int8_t	:8;
20087011Smsmith    u_int8_t	control;
201103870Salfred} __packed;
20287011Smsmith
20387011Smsmith/*
20487011Smsmith * Note that it's not clear whether we have to set the detail field to
20587011Smsmith * the tag of the command to be aborted, or the tag field in the command itself;
20687011Smsmith * documentation conflicts on this.
20787011Smsmith */
20887011Smsmith#define CISS_OPCODE_MESSAGE_ABORT		0x00
20987011Smsmith#define CISS_MESSAGE_ABORT_TASK			0x00
210128334Sps#define CISS_MESSAGE_ABORT_TASK_SET		0x01
21187011Smsmith#define CISS_MESSAGE_ABORT_CLEAR_ACA		0x02
21287011Smsmith#define CISS_MESSAGE_ABORT_CLEAR_TASK_SET	0x03
21387011Smsmith
21487011Smsmith#define CISS_OPCODE_MESSAGE_RESET		0x01
21587011Smsmith#define CISS_MESSAGE_RESET_CONTROLLER		0x00
21687011Smsmith#define CISS_MESSAGE_RESET_BUS			0x01
21787011Smsmith#define CISS_MESSAGE_RESET_TARGET		0x03
21887011Smsmith#define CISS_MESSAGE_RESET_LOGICAL_UNIT		0x04
21987011Smsmith
22087011Smsmith#define CISS_OPCODE_MESSAGE_SCAN		0x02
22187011Smsmith#define CISS_MESSAGE_SCAN_CONTROLLER		0x00
22287011Smsmith#define CISS_MESSAGE_SCAN_BUS			0x01
22387011Smsmith#define CISS_MESSAGE_SCAN_TARGET		0x03
22487011Smsmith#define CISS_MESSAGE_SCAN_LOGICAL_UNIT		0x04
22587011Smsmith
22687011Smsmith#define CISS_OPCODE_MESSAGE_NOP			0x03
22787011Smsmith
228128334Spsstruct ciss_message_cdb
22987011Smsmith{
23087011Smsmith    u_int8_t	opcode;
23187011Smsmith    u_int8_t	type;
23287011Smsmith    u_int16_t	:16;
23387011Smsmith    u_int32_t	abort_tag;					/* XXX endianness? */
23487011Smsmith    u_int8_t	reserved[8];
235103870Salfred} __packed;
23687011Smsmith
23787011Smsmith/*
23887011Smsmith * CISS vendor-specific commands/messages.
23987011Smsmith *
24087011Smsmith * Note that while messages and vendor-specific commands are
24187011Smsmith * differentiated, they are handled in basically the same way and can
24287011Smsmith * be considered to be basically the same thing, as long as the cdb
24387011Smsmith * type field is set correctly.
24487011Smsmith */
24587011Smsmith#define CISS_OPCODE_READ		0xc0
24687011Smsmith#define CISS_OPCODE_WRITE		0xc1
24787011Smsmith#define CISS_COMMAND_NOTIFY_ON_EVENT	0xd0
24887011Smsmith#define CISS_COMMAND_ABORT_NOTIFY	0xd1
24987011Smsmith
250128334Spsstruct ciss_notify_cdb
25187011Smsmith{
25287011Smsmith    u_int8_t	opcode;
25387011Smsmith    u_int8_t	command;
25487011Smsmith    u_int8_t	res1[2];
25587011Smsmith    u_int16_t	timeout;		/* seconds, little-endian */
25687011Smsmith    u_int8_t	res2;			/* reserved */
25787011Smsmith    u_int8_t	synchronous:1;		/* return immediately */
25887011Smsmith    u_int8_t	ordered:1;		/* return events in recorded order */
25987011Smsmith    u_int8_t	seek_to_oldest:1;	/* reset read counter to oldest event */
26087011Smsmith    u_int8_t	new_only:1;		/* ignore any queued events */
26187011Smsmith    u_int8_t	:4;
26287011Smsmith    u_int32_t	length;			/* must be 512, little-endian */
26387011Smsmith#define CISS_NOTIFY_DATA_SIZE	512
26487011Smsmith    u_int8_t	control;
265103870Salfred} __packed;
26687011Smsmith
26787011Smsmith#define CISS_NOTIFY_NOTIFIER		0
26887011Smsmith#define CISS_NOTIFY_NOTIFIER_STATUS		0
26987011Smsmith#define CISS_NOTIFY_NOTIFIER_PROTOCOL		1
27087011Smsmith
27187011Smsmith#define CISS_NOTIFY_HOTPLUG		1
27287011Smsmith#define CISS_NOTIFY_HOTPLUG_PHYSICAL		0
27387011Smsmith#define CISS_NOTIFY_HOTPLUG_POWERSUPPLY		1
27487011Smsmith#define CISS_NOTIFY_HOTPLUG_FAN			2
27587011Smsmith#define CISS_NOTIFY_HOTPLUG_POWER		3
27687011Smsmith#define CISS_NOTIFY_HOTPLUG_REDUNDANT		4
277129796Sps#define CISS_NOTIFY_HOTPLUG_NONDISK		5
27887011Smsmith
27987011Smsmith#define CISS_NOTIFY_HARDWARE		2
28087011Smsmith#define CISS_NOTIFY_HARDWARE_CABLES		0
28187011Smsmith#define CISS_NOTIFY_HARDWARE_MEMORY		1
28287011Smsmith#define CISS_NOTIFY_HARDWARE_FAN		2
28387011Smsmith#define CISS_NOTIFY_HARDWARE_VRM		3
28487011Smsmith
28587011Smsmith#define CISS_NOTIFY_ENVIRONMENT		3
28687011Smsmith#define CISS_NOTIFY_ENVIRONMENT_TEMPERATURE	0
28787011Smsmith#define CISS_NOTIFY_ENVIRONMENT_POWERSUPPLY	1
28887011Smsmith#define CISS_NOTIFY_ENVIRONMENT_CHASSIS		2
28987011Smsmith#define CISS_NOTIFY_ENVIRONMENT_POWER		3
29087011Smsmith
29187011Smsmith#define CISS_NOTIFY_PHYSICAL		4
29287011Smsmith#define CISS_NOTIFY_PHYSICAL_STATE		0
29387011Smsmith
29487011Smsmith#define CISS_NOTIFY_LOGICAL		5
29587011Smsmith#define CISS_NOTIFY_LOGICAL_STATUS		0
29687011Smsmith#define CISS_NOTIFY_LOGICAL_ERROR		1
29787011Smsmith#define CISS_NOTIFY_LOGICAL_SURFACE		2
29887011Smsmith
29987011Smsmith#define CISS_NOTIFY_REDUNDANT		6
30087011Smsmith#define CISS_NOTIFY_REDUNDANT_STATUS		0
30187011Smsmith
30287011Smsmith#define CISS_NOTIFY_CISS		8
30387011Smsmith#define CISS_NOTIFY_CISS_REDUNDANT_CHANGE	0
30487011Smsmith#define CISS_NOTIFY_CISS_PATH_STATUS		1
30587011Smsmith#define CISS_NOTIFY_CISS_HARDWARE_ERROR		2
30687011Smsmith#define CISS_NOTIFY_CISS_LOGICAL		3
30787011Smsmith
30887011Smsmithstruct ciss_notify_drive
30987011Smsmith{
31087011Smsmith    u_int16_t	physical_drive_number;
31187011Smsmith    u_int8_t	configured_drive_flag;
31287011Smsmith    u_int8_t	spare_drive_flag;
31387011Smsmith    u_int8_t	big_physical_drive_number;
31487011Smsmith    u_int8_t	enclosure_bay_number;
315103870Salfred} __packed;
31687011Smsmith
31787011Smsmithstruct ciss_notify_locator
31887011Smsmith{
31987011Smsmith    u_int16_t	port;
32087011Smsmith    u_int16_t	id;
32187011Smsmith    u_int16_t	box;
322103870Salfred} __packed;
32387011Smsmith
32487011Smsmithstruct ciss_notify_redundant_controller
32587011Smsmith{
32687011Smsmith    u_int16_t	slot;
327103870Salfred} __packed;
32887011Smsmith
32987011Smsmithstruct ciss_notify_logical_status
33087011Smsmith{
33187011Smsmith    u_int16_t	logical_drive;
33287011Smsmith    u_int8_t	previous_state;
33387011Smsmith    u_int8_t	new_state;
33487011Smsmith    u_int8_t	spare_state;
335103870Salfred} __packed;
336128334Sps
33787011Smsmithstruct ciss_notify_rebuild_aborted
33887011Smsmith{
33987011Smsmith    u_int16_t	logical_drive;
34087011Smsmith    u_int8_t	replacement_drive;
34187011Smsmith    u_int8_t	error_drive;
34287011Smsmith    u_int8_t	big_replacement_drive;
34387011Smsmith    u_int8_t	big_error_drive;
344103870Salfred} __packed;
34587011Smsmith
346128334Spsstruct ciss_notify_io_error
34787011Smsmith{
34887011Smsmith    u_int16_t	logical_drive;
34987011Smsmith    u_int32_t	lba;
35087011Smsmith    u_int16_t	block_count;
35187011Smsmith    u_int8_t	command;
35287011Smsmith    u_int8_t	failure_bus;
35387011Smsmith    u_int8_t	failure_drive;
35487011Smsmith    u_int64_t	big_lba;
355103870Salfred} __packed;
35687011Smsmith
35787011Smsmithstruct ciss_notify_consistency_completed
35887011Smsmith{
35987011Smsmith    u_int16_t	logical_drive;
360103870Salfred} __packed;
36187011Smsmith
362128334Spsstruct ciss_notify
36387011Smsmith{
36487011Smsmith    u_int32_t	timestamp;		/* seconds since controller power-on */
36587011Smsmith    u_int16_t	class;
36687011Smsmith    u_int16_t	subclass;
36787011Smsmith    u_int16_t	detail;
368128334Sps    union
36987011Smsmith    {
37087011Smsmith	struct ciss_notify_drive		drive;
37187011Smsmith	struct ciss_notify_locator		location;
37287011Smsmith	struct ciss_notify_redundant_controller	redundant_controller;
37387011Smsmith	struct ciss_notify_logical_status	logical_status;
37487011Smsmith	struct ciss_notify_rebuild_aborted	rebuild_aborted;
37587011Smsmith	struct ciss_notify_io_error		io_error;
37687011Smsmith	struct ciss_notify_consistency_completed consistency_completed;
37787011Smsmith	u_int8_t	data[64];
37887011Smsmith    } data;
37987011Smsmith    char	message[80];
38087011Smsmith    u_int32_t	tag;
38187011Smsmith    u_int16_t	date;
38287011Smsmith    u_int16_t	year;
38387011Smsmith    u_int32_t	time;
38487011Smsmith    u_int16_t	pre_power_up_time;
38587011Smsmith    union ciss_device_address	device;
38687011Smsmith    /* XXX pads to 512 bytes */
387103870Salfred} __packed;
38887011Smsmith
38987011Smsmith/*
390128334Sps * CISS config table, which describes the controller's
39187011Smsmith * supported interface(s) and capabilities.
39287011Smsmith *
39387011Smsmith * This is mapped directly via PCI.
39487011Smsmith */
395128334Spsstruct ciss_config_table
39687011Smsmith{
39787011Smsmith    char	signature[4];		/* "CISS" */
39887011Smsmith    u_int32_t	valence;
39987011Smsmith    u_int32_t	supported_methods;
40087011Smsmith#define CISS_TRANSPORT_METHOD_READY	(1<<0)
401128334Sps#define CISS_TRANSPORT_METHOD_SIMPLE	(1<<1)
402180454Sscottl#define CISS_TRANSPORT_METHOD_PERF	(1<<2)
40387011Smsmith    u_int32_t	active_method;
40487011Smsmith    u_int32_t	requested_method;
40587011Smsmith    u_int32_t	command_physlimit;
40687011Smsmith    u_int32_t	interrupt_coalesce_delay;
40787011Smsmith    u_int32_t	interrupt_coalesce_count;
40887011Smsmith    u_int32_t	max_outstanding_commands;
40987011Smsmith    u_int32_t	bus_types;
41087011Smsmith#define CISS_TRANSPORT_BUS_TYPE_ULTRA2	(1<<0)
41187011Smsmith#define CISS_TRANSPORT_BUS_TYPE_ULTRA3	(1<<1)
41287011Smsmith#define CISS_TRANSPORT_BUS_TYPE_FIBRE1	(1<<8)
41387011Smsmith#define CISS_TRANSPORT_BUS_TYPE_FIBRE2	(1<<9)
414129345Sps    u_int32_t	transport_offset;
415129345Sps    char	server_name[16];
416129345Sps    u_int32_t	heartbeat;
41787011Smsmith    u_int32_t	host_driver;
41887011Smsmith#define CISS_DRIVER_SUPPORT_UNIT_ATTENTION	(1<<0)
41987011Smsmith#define CISS_DRIVER_QUICK_INIT			(1<<1)
42087011Smsmith#define CISS_DRIVER_INTERRUPT_ON_LOCKUP		(1<<2)
42187011Smsmith#define CISS_DRIVER_SUPPORT_MIXED_Q_TAGS	(1<<3)
42287011Smsmith#define CISS_DRIVER_HOST_IS_ALPHA		(1<<4)
423129345Sps#define CISS_DRIVER_MULTI_LUN_SUPPORT		(1<<5)
424129345Sps#define CISS_DRIVER_MESSAGE_REQUESTS_SUPPORTED	(1<<7)
425129345Sps#define CISS_DRIVER_DAUGHTER_ATTACHED		(1<<8)
426129345Sps#define CISS_DRIVER_SCSI_PREFETCH		(1<<9)
427129345Sps    u_int32_t	max_sg_length;		/* 31 in older firmware */
428245459Ssbruno/*
429245459Ssbruno * these fields appear in OpenCISS Spec 1.06
430245459Ssbruno * http://cciss.sourceforge.net/#docs
431245459Ssbruno */
432245459Ssbruno    u_int32_t	max_logical_supported;
433245459Ssbruno    u_int32_t	max_physical_supported;
434245459Ssbruno    u_int32_t	max_physical_per_logical;
435245459Ssbruno    u_int32_t	max_perfomant_mode_cmds;
436245459Ssbruno    u_int32_t	max_block_fetch_count;
437103870Salfred} __packed;
43887011Smsmith
43987011Smsmith/*
440180454Sscottl * Configuration table for the Performant transport.  Only 4 request queues
441180454Sscottl * are mentioned in this table, though apparently up to 256 can exist.
442180454Sscottl */
443180454Sscottlstruct ciss_perf_config {
444180454Sscottl    uint32_t	fetch_count[8];
445180454Sscottl#define CISS_SG_FETCH_MAX	0
446180454Sscottl#define CISS_SG_FETCH_1		1
447180454Sscottl#define CISS_SG_FETCH_2		2
448180454Sscottl#define CISS_SG_FETCH_4		3
449180454Sscottl#define CISS_SG_FETCH_8		4
450180454Sscottl#define CISS_SG_FETCH_16	5
451180454Sscottl#define CISS_SG_FETCH_32	6
452180454Sscottl#define CISS_SG_FETCH_NONE	7
453180454Sscottl    uint32_t	rq_size;
454180454Sscottl    uint32_t	rq_count;
455180454Sscottl    uint32_t	rq_bank_lo;
456180454Sscottl    uint32_t	rq_bank_hi;
457180454Sscottl    struct {
458180454Sscottl	uint32_t	rq_addr_lo;
459180454Sscottl	uint32_t	rq_addr_hi;
460180454Sscottl    } __packed rq[4];
461180454Sscottl} __packed;
462180454Sscottl
463180454Sscottl/*
46487011Smsmith * In a flagrant violation of what CISS seems to be meant to be about,
46587011Smsmith * Compaq recycle a goodly portion of their previous generation's
46687011Smsmith * command set (and all the legacy baggage related to a design
46787011Smsmith * originally aimed at narrow SCSI) through the Array Controller Read
46887011Smsmith * and Array Controller Write interface.
46987011Smsmith *
47087011Smsmith * Command ID values here can be looked up for in the
47187011Smsmith * publically-available documentation for the older controllers; note
47287011Smsmith * that the command layout is necessarily different to fit within the
47387011Smsmith * CDB.
47487011Smsmith */
47587011Smsmith#define CISS_ARRAY_CONTROLLER_READ	0x26
47687011Smsmith#define CISS_ARRAY_CONTROLLER_WRITE	0x27
47787011Smsmith
47887011Smsmith#define CISS_BMIC_ID_LDRIVE		0x10
47987011Smsmith#define CISS_BMIC_ID_CTLR		0x11
48087011Smsmith#define CISS_BMIC_ID_LSTATUS		0x12
48187011Smsmith#define CISS_BMIC_ID_PDRIVE		0x15
48287011Smsmith#define CISS_BMIC_BLINK_PDRIVE		0x16
48387011Smsmith#define CISS_BMIC_SENSE_BLINK_PDRIVE	0x17
484145258Sps#define CISS_BMIC_SOFT_RESET		0x40
48587011Smsmith#define CISS_BMIC_FLUSH_CACHE		0xc2
48687011Smsmith#define CISS_BMIC_ACCEPT_MEDIA		0xe0
48787011Smsmith
48887011Smsmith/*
48987011Smsmith * When numbering drives, the original design assumed that
49087011Smsmith * drives 0-7 are on the first SCSI bus, 8-15 on the second,
49187011Smsmith * and so forth.  In order to handle modern SCSI configurations,
49287011Smsmith * the MSB is set in the drive ID field, in which case the
49387011Smsmith * modulus changes from 8 to the number of supported drives
49487011Smsmith * per SCSI bus (as obtained from the ID_CTLR command).
49587011Smsmith * This feature is referred to as BIG_MAP support, and we assume
49687011Smsmith * that all CISS controllers support it.
49787011Smsmith */
49887011Smsmith
49987011Smsmith#define CISS_BIG_MAP_ID(sc, bus, target)		\
50087011Smsmith	(0x80 | 					\
50187011Smsmith	 ((sc)->ciss_id->drives_per_scsi_bus * (bus)) |	\
50287011Smsmith	 (target))
50387011Smsmith
50487011Smsmith#define CISS_BIG_MAP_BUS(sc, id)			\
50587011Smsmith	(((id) & 0x80) ? (((id) & ~0x80) / (sc)->ciss_id->drives_per_scsi_bus) : -1)
50687011Smsmith
50787011Smsmith#define CISS_BIG_MAP_TARGET(sc, id)			\
50887011Smsmith	(((id) & 0x80) ? (((id) & ~0x80) % (sc)->ciss_id->drives_per_scsi_bus) : -1)
50987011Smsmith
51087011Smsmith#define CISS_BIG_MAP_ENTRIES	128	/* number of entries in a BIG_MAP */
51187011Smsmith
51287011Smsmith/*
513128337Sps * In the device address of a logical volume, the bus number
514128337Sps * is encoded into the logical lun volume number starting
515128337Sps * at the second byte, with the first byte defining the
516128337Sps * logical drive number.
517128337Sps */
518128337Sps#define CISS_LUN_TO_BUS(x)    (((x) >> 16) & 0xFF)
519128337Sps#define CISS_LUN_TO_TARGET(x) ((x) & 0xFF)
520128337Sps
521128337Sps/*
52287011Smsmith * BMIC CDB
52387011Smsmith *
52487011Smsmith * Note that the phys_drive/res1 field is nominally the 32-bit
52587011Smsmith * "block number" field, but the only BMIC command(s) of interest
526128334Sps * implemented overload the MSB (note big-endian format here)
52787011Smsmith * to be the physical drive ID, so we define accordingly.
52887011Smsmith */
52987011Smsmithstruct ciss_bmic_cdb {
53087011Smsmith    u_int8_t	opcode;
53187011Smsmith    u_int8_t	log_drive;
53287011Smsmith    u_int8_t	phys_drive;
53387011Smsmith    u_int8_t	res1[3];
53487011Smsmith    u_int8_t	bmic_opcode;
53587011Smsmith    u_int16_t	size;			/* big-endian */
53687011Smsmith    u_int8_t	res2;
537103870Salfred} __packed;
53887011Smsmith
53987011Smsmith/*
54087011Smsmith * BMIC command command/return structures.
54187011Smsmith */
54287011Smsmith
54387011Smsmith/* CISS_BMIC_ID_LDRIVE */
54487011Smsmithstruct ciss_bmic_id_ldrive {
54587011Smsmith    u_int16_t	block_size;
54687011Smsmith    u_int32_t	blocks_available;
54787011Smsmith    u_int8_t	drive_parameter_table[16];	/* XXX define */
54887011Smsmith    u_int8_t	fault_tolerance;
54987011Smsmith#define CISS_LDRIVE_RAID0	0
55087011Smsmith#define CISS_LDRIVE_RAID4	1
55187011Smsmith#define CISS_LDRIVE_RAID1	2
55287011Smsmith#define CISS_LDRIVE_RAID5	3
553123298Sps#define CISS_LDRIVE_RAID51	4
554123298Sps#define CISS_LDRIVE_RAIDADG	5
555130081Sps    u_int8_t	res1;
556130081Sps    u_int8_t	bios_disable_flag;
557130081Sps    u_int8_t	res2;
55887011Smsmith    u_int32_t	logical_drive_identifier;
55987011Smsmith    char	logical_drive_label[64];
560130081Sps    u_int64_t	big_blocks_available;
561130081Sps    u_int8_t	res3[410];
562103870Salfred} __packed;
56387011Smsmith
56487011Smsmith/* CISS_BMIC_ID_LSTATUS */
56587011Smsmithstruct ciss_bmic_id_lstatus {
56687011Smsmith    u_int8_t	status;
56787011Smsmith#define CISS_LSTATUS_OK				0
56887011Smsmith#define CISS_LSTATUS_FAILED			1
56987011Smsmith#define CISS_LSTATUS_NOT_CONFIGURED		2
57087011Smsmith#define CISS_LSTATUS_INTERIM_RECOVERY		3
57187011Smsmith#define CISS_LSTATUS_READY_RECOVERY		4
57287011Smsmith#define CISS_LSTATUS_RECOVERING			5
57387011Smsmith#define CISS_LSTATUS_WRONG_PDRIVE		6
57487011Smsmith#define CISS_LSTATUS_MISSING_PDRIVE		7
57587011Smsmith#define CISS_LSTATUS_EXPANDING			10
57687011Smsmith#define CISS_LSTATUS_BECOMING_READY		11
57787011Smsmith#define CISS_LSTATUS_QUEUED_FOR_EXPANSION	12
57887011Smsmith    u_int32_t	deprecated_drive_failure_map;
57987011Smsmith    u_int8_t	res1[416];
58087011Smsmith    u_int32_t	blocks_to_recover;
58187011Smsmith    u_int8_t	deprecated_drive_rebuilding;
58287011Smsmith    u_int16_t	deprecated_remap_count[32];
58387011Smsmith    u_int32_t	deprecated_replacement_map;
58487011Smsmith    u_int32_t	deprecated_active_spare_map;
58587011Smsmith    u_int8_t	spare_configured:1;
58687011Smsmith    u_int8_t	spare_rebuilding:1;
58787011Smsmith    u_int8_t	spare_rebuilt:1;
58887011Smsmith    u_int8_t	spare_failed:1;
58987011Smsmith    u_int8_t	spare_switched:1;
59087011Smsmith    u_int8_t	spare_available:1;
59187011Smsmith    u_int8_t	res2:2;
59287011Smsmith    u_int8_t	deprecated_spare_to_replace_map[32];
59387011Smsmith    u_int32_t	deprecated_replaced_marked_ok_map;
59487011Smsmith    u_int8_t	media_exchanged;
59587011Smsmith    u_int8_t	cache_failure;
59687011Smsmith    u_int8_t	expand_failure;
59787011Smsmith    u_int8_t	rebuild_read_failure:1;
59887011Smsmith    u_int8_t	rebuild_write_failure:1;
59987011Smsmith    u_int8_t	res3:6;
60087011Smsmith    u_int8_t	drive_failure_map[CISS_BIG_MAP_ENTRIES / 8];
60187011Smsmith    u_int16_t	remap_count[CISS_BIG_MAP_ENTRIES];
60287011Smsmith    u_int8_t	replacement_map[CISS_BIG_MAP_ENTRIES / 8];
60387011Smsmith    u_int8_t	active_spare_map[CISS_BIG_MAP_ENTRIES / 8];
60487011Smsmith    u_int8_t	spare_to_replace_map[CISS_BIG_MAP_ENTRIES];
60587011Smsmith    u_int8_t	replaced_marked_ok_map[CISS_BIG_MAP_ENTRIES / 8];
60687011Smsmith    u_int8_t	drive_rebuilding;
607130129Sps    u_int64_t	big_blocks_to_recover;
608130129Sps    u_int8_t	res4[28];
609103870Salfred} __packed;
61087011Smsmith
61187011Smsmith/* CISS_BMIC_ID_CTLR */
61287011Smsmithstruct ciss_bmic_id_table {
61387011Smsmith    u_int8_t	configured_logical_drives;
61487011Smsmith    u_int32_t	config_signature;
61587011Smsmith    char	running_firmware_revision[4];
61687011Smsmith    char	stored_firmware_revision[4];
61787011Smsmith    u_int8_t	hardware_revision;
61887011Smsmith    u_int8_t	res1[4];
61987011Smsmith    u_int32_t	deprecated_drive_present_map;
62087011Smsmith    u_int32_t	deprecated_external_drive_present_map;
62187011Smsmith    u_int32_t	board_id;
62287011Smsmith    u_int8_t	res2;
62387011Smsmith    u_int32_t	deprecated_non_disk_map;
62487011Smsmith    u_int8_t	res3[5];
62587011Smsmith    char	marketting_revision;
62687011Smsmith    u_int8_t	res4:3;
62787011Smsmith    u_int8_t	more_than_seven_supported:1;
62887011Smsmith    u_int8_t	res5:3;
62987011Smsmith    u_int8_t	big_map_supported:1;		/* must be set! */
63087011Smsmith    u_int8_t	res6[2];
63187011Smsmith    u_int8_t	scsi_bus_count;
63287011Smsmith    u_int32_t	res7;
63387011Smsmith    u_int32_t	controller_clock;
63487011Smsmith    u_int8_t	drives_per_scsi_bus;
63587011Smsmith    u_int8_t	big_drive_present_map[CISS_BIG_MAP_ENTRIES / 8];
63687011Smsmith    u_int8_t	big_external_drive_present_map[CISS_BIG_MAP_ENTRIES / 8];
63787011Smsmith    u_int8_t	big_non_disk_map[CISS_BIG_MAP_ENTRIES / 8];
638103870Salfred} __packed;
63987011Smsmith
64087011Smsmith/* CISS_BMIC_ID_PDRIVE */
64187011Smsmithstruct ciss_bmic_id_pdrive {
64287011Smsmith    u_int8_t	scsi_bus;
64387011Smsmith    u_int8_t	scsi_id;
64487011Smsmith    u_int16_t	block_size;
64587011Smsmith    u_int32_t	total_blocks;
64687011Smsmith    u_int32_t	reserved_blocks;
64787011Smsmith    char	model[40];
64887011Smsmith    char	serial[40];
64987011Smsmith    char	revision[8];
65087011Smsmith    u_int8_t	inquiry_bits;
65187011Smsmith    u_int8_t	res1[2];
65287011Smsmith    u_int8_t	drive_present:1;
65387011Smsmith    u_int8_t	non_disk:1;
65487011Smsmith    u_int8_t	wide:1;
65587011Smsmith    u_int8_t	synchronous:1;
65687011Smsmith    u_int8_t	narrow:1;
65787011Smsmith    u_int8_t	wide_downgraded_to_narrow:1;
65887011Smsmith    u_int8_t	ultra:1;
65987011Smsmith    u_int8_t	ultra2:1;
66087011Smsmith    u_int8_t	SMART:1;
66187011Smsmith    u_int8_t	SMART_errors_recorded:1;
66287011Smsmith    u_int8_t	SMART_errors_enabled:1;
66387011Smsmith    u_int8_t	SMART_errors_detected:1;
66487011Smsmith    u_int8_t	external:1;
66587011Smsmith    u_int8_t	configured:1;
66687011Smsmith    u_int8_t	configured_spare:1;
66787011Smsmith    u_int8_t	cache_saved_enabled:1;
66887011Smsmith    u_int8_t	res2;
66987011Smsmith    u_int8_t	res3:6;
67087011Smsmith    u_int8_t	cache_currently_enabled:1;
67187011Smsmith    u_int8_t	cache_safe:1;
67287011Smsmith    u_int8_t	res4[5];
67387011Smsmith    char	connector[2];
67487011Smsmith    u_int8_t	res5;
67587011Smsmith    u_int8_t	bay;
676128545Sps    u_int16_t	rpm;
677128545Sps    u_int8_t	drive_type;
678128545Sps    u_int8_t	res6[393];
679103870Salfred} __packed;
68087011Smsmith
68187011Smsmith/* CISS_BMIC_BLINK_PDRIVE */
68287011Smsmith/* CISS_BMIC_SENSE_BLINK_PDRIVE */
68387011Smsmithstruct ciss_bmic_blink_pdrive {
68487011Smsmith    u_int32_t	blink_duration;		/* 10ths of a second */
68587011Smsmith    u_int32_t	duration_elapsed;	/* only for sense command  */
68687011Smsmith    u_int8_t	blinktab[256];
68787011Smsmith#define CISS_BMIC_BLINK_ALL	1
68887011Smsmith#define CISS_BMIC_BLINK_TIMED	2
68987011Smsmith    u_int8_t	res2[248];
690103870Salfred} __packed;
69187011Smsmith
69287011Smsmith/* CISS_BMIC_FLUSH_CACHE */
69387011Smsmithstruct ciss_bmic_flush_cache {
69487011Smsmith    u_int16_t	flag;
69587011Smsmith#define CISS_BMIC_FLUSH_AND_ENABLE	0
69687011Smsmith#define CISS_BMIC_FLUSH_AND_DISABLE	1
69787011Smsmith    u_int8_t	res1[510];
698103870Salfred} __packed;
69987011Smsmith
70087011Smsmith#ifdef _KERNEL
70187011Smsmith/*
70287011Smsmith * CISS "simple" transport layer.
70387011Smsmith *
70487011Smsmith * Note that there are two slightly different versions of this interface
70587011Smsmith * with different interrupt mask bits.  There's nothing like consistency...
70687011Smsmith */
70787011Smsmith#define CISS_TL_SIMPLE_BAR_REGS	0x10	/* BAR pointing to register space */
70887011Smsmith#define CISS_TL_SIMPLE_BAR_CFG	0x14	/* BAR pointing to space containing config table */
70987011Smsmith
71087011Smsmith#define CISS_TL_SIMPLE_IDBR	0x20	/* inbound doorbell register */
71187011Smsmith#define CISS_TL_SIMPLE_IDBR_CFG_TABLE	(1<<0)	/* notify controller of config table update */
71287011Smsmith
71387011Smsmith#define CISS_TL_SIMPLE_ISR	0x30	/* interrupt status register */
71487011Smsmith#define CISS_TL_SIMPLE_IMR	0x34	/* interrupt mask register */
71587011Smsmith#define CISS_TL_SIMPLE_INTR_OPQ_SA5	(1<<3)	/* OPQ not empty interrupt, SA5 boards */
71687011Smsmith#define CISS_TL_SIMPLE_INTR_OPQ_SA5B	(1<<2)	/* OPQ not empty interrupt, SA5B boards */
71787011Smsmith
71887011Smsmith#define CISS_TL_SIMPLE_IPQ	0x40	/* inbound post queue */
71987011Smsmith#define CISS_TL_SIMPLE_OPQ	0x44	/* outbound post queue */
72087011Smsmith#define CISS_TL_SIMPLE_OPQ_EMPTY	(~(u_int32_t)0)
72187011Smsmith
722180454Sscottl#define CISS_TL_SIMPLE_OSR	0x9c	/* outbound status register */
723180454Sscottl#define CISS_TL_SIMPLE_ODC	0xa0	/* outbound doorbell clear register */
724180454Sscottl#define CISS_TL_SIMPLE_ODC_CLEAR	(0x1)
725180454Sscottl
72687011Smsmith#define CISS_TL_SIMPLE_CFG_BAR	0xb4	/* should be 0x14 */
72787011Smsmith#define CISS_TL_SIMPLE_CFG_OFF	0xb8	/* offset in BAR at which config table is located */
72887011Smsmith
72987011Smsmith/*
73087011Smsmith * Register access primitives.
73187011Smsmith */
73287011Smsmith#define CISS_TL_SIMPLE_READ(sc, ofs) \
73387011Smsmith	bus_space_read_4(sc->ciss_regs_btag, sc->ciss_regs_bhandle, ofs)
73487011Smsmith#define CISS_TL_SIMPLE_WRITE(sc, ofs, val) \
73587011Smsmith	bus_space_write_4(sc->ciss_regs_btag, sc->ciss_regs_bhandle, ofs, val)
73687011Smsmith
73787011Smsmith#define CISS_TL_SIMPLE_POST_CMD(sc, phys)	CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_IPQ, phys)
73887011Smsmith#define CISS_TL_SIMPLE_FETCH_CMD(sc)		CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_OPQ)
73987011Smsmith
740182422Sscottl#define CISS_TL_PERF_INTR_OPQ	(CISS_TL_SIMPLE_INTR_OPQ_SA5 | CISS_TL_SIMPLE_INTR_OPQ_SA5B)
741182422Sscottl#define CISS_TL_PERF_INTR_MSI	0x01
742182422Sscottl
743197263Sscottl#define CISS_TL_PERF_POST_CMD(sc, cr)		CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_IPQ, cr->cr_ccphys | (cr)->cr_sg_tag)
744180454Sscottl#define CISS_TL_PERF_FLUSH_INT(sc)		CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_OSR)
745180454Sscottl#define CISS_TL_PERF_CLEAR_INT(sc)		CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_ODC, CISS_TL_SIMPLE_ODC_CLEAR)
746180454Sscottl#define CISS_CYCLE_MASK		0x00000001
747180454Sscottl
748197261Sscottl/* Only need one MSI/MSI-X vector */
749197261Sscottl#define CISS_MSI_COUNT	1
750180454Sscottl
751182422Sscottl#define CISS_TL_SIMPLE_DISABLE_INTERRUPTS(sc) \
752182422Sscottl	CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_IMR, \
753182422Sscottl			     CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IMR) | (sc)->ciss_interrupt_mask)
754182422Sscottl#define CISS_TL_SIMPLE_ENABLE_INTERRUPTS(sc) \
755182422Sscottl	CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_IMR, \
756182422Sscottl			     CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IMR) & ~(sc)->ciss_interrupt_mask)
75787011Smsmith
758182422Sscottl
759197263Sscottl
76087011Smsmith#endif /* _KERNEL */
761