148156Sjlemon/*-
257828Sjlemon * Copyright (c) 1999,2000 Jonathan Lemon
348156Sjlemon * All rights reserved.
448156Sjlemon *
548156Sjlemon * Redistribution and use in source and binary forms, with or without
648156Sjlemon * modification, are permitted provided that the following conditions
748156Sjlemon * are met:
848156Sjlemon * 1. Redistributions of source code must retain the above copyright
948156Sjlemon *    notice, this list of conditions and the following disclaimer.
1048156Sjlemon * 2. Redistributions in binary form must reproduce the above copyright
1148156Sjlemon *    notice, this list of conditions and the following disclaimer in the
1248156Sjlemon *    documentation and/or other materials provided with the distribution.
1348156Sjlemon *
1448156Sjlemon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1548156Sjlemon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1648156Sjlemon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1748156Sjlemon * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1848156Sjlemon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1948156Sjlemon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2048156Sjlemon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2148156Sjlemon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2248156Sjlemon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2348156Sjlemon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2448156Sjlemon * SUCH DAMAGE.
2548156Sjlemon *
2650477Speter * $FreeBSD$
2748156Sjlemon */
2848156Sjlemon
2948156Sjlemon/*
3048156Sjlemon * #defines and software structures for the Compaq RAID card
3148156Sjlemon */
3248156Sjlemon
3348156Sjlemon/*
3457828Sjlemon * defines for older EISA controllers (IDA, IDA-2, IAES, SMART)
3548156Sjlemon */
36124471Smdodd#define	R_EISA_INT_MASK			0x01
37124471Smdodd#define	R_EISA_LOCAL_MASK		0x04
38124471Smdodd#define	R_EISA_LOCAL_DOORBELL		0x05
39124471Smdodd#define	R_EISA_SYSTEM_MASK		0x06
40124471Smdodd#define	R_EISA_SYSTEM_DOORBELL		0x07
41124471Smdodd#define	R_EISA_LIST_ADDR		0x08
42124471Smdodd#define	R_EISA_LIST_LEN			0x0c
43124471Smdodd#define	R_EISA_TAG			0x0f
44124471Smdodd#define	R_EISA_COMPLETE_ADDR		0x10
45124471Smdodd#define	R_EISA_LIST_STATUS		0x16
4657828Sjlemon
47124471Smdodd#define	EISA_CHANNEL_BUSY		0x01
48124471Smdodd#define	EISA_CHANNEL_CLEAR		0x02
4957828Sjlemon
5057828Sjlemon/*
5157828Sjlemon * board register offsets for SMART-2 controllers
5257828Sjlemon */
53124471Smdodd#define	R_CMD_FIFO	0x04
54124471Smdodd#define	R_DONE_FIFO	0x08
55124471Smdodd#define	R_INT_MASK	0x0C
56124471Smdodd#define	R_STATUS	0x10
57124471Smdodd#define	R_INT_PENDING	0x14
5848156Sjlemon
5948156Sjlemon/*
6057828Sjlemon * interrupt mask values for SMART series
6148156Sjlemon */
62124471Smdodd#define	INT_DISABLE	0x00
63124471Smdodd#define	INT_ENABLE	0x01
6448156Sjlemon
6548156Sjlemon/*
6657828Sjlemon * board offsets for the 42xx series
6757828Sjlemon */
68124471Smdodd#define	R_42XX_STATUS	0x30
69124471Smdodd#define	R_42XX_INT_MASK	0x34
70124471Smdodd#define	R_42XX_REQUEST	0x40
71124471Smdodd#define	R_42XX_REPLY	0x44
7257828Sjlemon
7357828Sjlemon/*
7457828Sjlemon * interrupt values for 42xx series
7557828Sjlemon */
76124471Smdodd#define	INT_ENABLE_42XX			0x00
77124471Smdodd#define	INT_DISABLE_42XX		0x08
78124471Smdodd#define	STATUS_42XX_INT_PENDING		0x08
7957828Sjlemon
8057828Sjlemon/*
8148156Sjlemon * return status codes
8248156Sjlemon */
83124539Smdodd#define	SOFT_ERROR	0x02	/* Non-fatal error. */
84124539Smdodd#define	HARD_ERROR	0x04	/* Fatal error. */
85124539Smdodd#define	INVALID_ERROR	0x10	/* Invalid Request Block. */
86124471Smdodd#define	CMD_REJECTED	0x14
8748156Sjlemon
8848156Sjlemon/*
89144991Smdodd * command types
9048156Sjlemon */
91124539Smdodd#define	CMD_GET_LOG_DRV_INFO	0x10	/* Identify controller */
92124539Smdodd#define	CMD_GET_CTRL_INFO	0x11	/* Identify logical driver */
93124539Smdodd#define	CMD_SENSE_DRV_STATUS	0x12	/* Sense logical drive status */
94124539Smdodd#define	CMD_START_RECOVERY	0x13	/* Start recover */
95124539Smdodd#define	CMD_GET_PHYS_DRV_INFO	0x15	/* Identify physical drive */
96124539Smdodd#define	CMD_BLINK_DRV_LEDS	0x16	/* Blink drive tray LEDs */
97124539Smdodd#define	CMD_SENSE_DRV_LEDS	0x17	/* Sense Blinking drive tray LEDs */
98124539Smdodd#define	CMD_GET_LOG_DRV_EXT	0x18	/* Identify logical drive, Extended */
99124539Smdodd#define	CMD_READ		0x20	/* Read */
100124539Smdodd#define	CMD_WRITE		0x30	/* Write */
101124539Smdodd#define	CMD_WRITE_MEDIA		0x31	/* Write media */
102124539Smdodd#define	CMD_RESET_CTRL		0x40	/* Reset controller */
103144992Smdodd#define	CMD_DIAG_PASS_THRU	0x41	/* ??? */
104124539Smdodd#define	CMD_GET_CONFIG		0x50	/* Sense configuration */
105124539Smdodd#define	CMD_SET_CONFIG		0x51	/* Set configuration */
106144992Smdodd
107144992Smdodd#define	CMD_BYPASS_VOL_STATE	0x52	/* ??? */
108144992Smdodd#define	CMD_SS_CREATE_VOL	0x53	/* ??? */
109144992Smdodd#define	CMD_CHANGE_CONFIG	0x54	/* ??? */
110144992Smdodd#define	CMD_SENSE_ORIG_CONF	0x55	/* ??? */
111144992Smdodd#define	CMD_REORDER_LOG_DRV	0x56	/* ??? */
112144992Smdodd
113124539Smdodd#define	CMD_LABEL_LOG_DRV	0x57	/* Label logical drive */
114144992Smdodd#define	CMD_SS_TO_VOL		0x58	/* ??? */
115124539Smdodd#define	CMD_SET_SURFACE_DELAY	0x60	/* Set surface delay */
116144992Smdodd#define	CMD_SET_OVERHEAT_DELAY	0x61	/* ??? */
117124539Smdodd#define	CMD_SENSE_BUS_PARAMS	0x65	/* Sense bus parameters */
118124539Smdodd#define	CMD_SENSE_SUBSYS_INFO	0x66	/* Sense Subsystem Information */
119124539Smdodd#define	CMD_SENSE_SURFACE_ATS	0x70	/* Sense surface analysis task status */
120124539Smdodd#define	CMD_PASSTHROUGH		0x90	/* Pass-through operation */
121144992Smdodd#define	CMD_PASSTHROUGH_A	0x91	/* ??? */
122124539Smdodd#define	CMD_RESET_SCSI_DEV	0x94	/* Reset SCSI device */
123124539Smdodd#define	CMD_PAUSE_BG_ACT	0x98	/* Pause Background Activity */
124124539Smdodd#define	CMD_RESUME_BG_ACT	0x99	/* Resume Background Activity */
125124539Smdodd#define	CMD_START_FIRMWARE	0x99	/* for integrated RAID */
126124539Smdodd#define	CMD_SENSE_DRV_ERR_LOG	0xa6	/* Sense drive error log */
127124539Smdodd#define	CMD_START_CPM		0xa7	/* Start controller performance monitoring */
128124539Smdodd#define	CMD_SENSE_CP		0xa8	/* Sense controller performance */
129124539Smdodd#define	CMD_STOP_CPM		0xa9	/* Stop controller performance monitoring */
130124539Smdodd#define	CMD_FLUSH_CACHE		0xc2	/* Flush/disable write cache */
131144992Smdodd#define	CMD_COLLECT_BUFFER	0xd2	/* ??? */
132124539Smdodd#define	CMD_ACCEPT_MEDIA_EXCH	0xe0	/* Accept Media Exchange */
13348156Sjlemon
134144992Smdodd#define	CMD_FLASH_READ		0xf6	/* Read FLASH */
135144992Smdodd#define	CMD_FLASH_WRITE		0xf7	/* Write FLASH */
136144992Smdodd
137124539Smdodd/* logical drive parameter table */
138124539Smdoddstruct ida_drive_param {
13963934Sjlemon	u_int16_t	ncylinders;
14063934Sjlemon	u_int8_t	nheads;
14163934Sjlemon	u_int8_t	signature;
14263934Sjlemon	u_int8_t	psectors;
14363934Sjlemon	u_int16_t	wprecomp;
14463934Sjlemon	u_int8_t	max_acc;
14563934Sjlemon	u_int8_t	control;
14663934Sjlemon	u_int16_t	pcylinders;
14763934Sjlemon	u_int8_t	ptracks;
14863934Sjlemon	u_int16_t	landing_zone;
14963934Sjlemon	u_int8_t	nsectors;
15063934Sjlemon	u_int8_t	checksum;
151103870Salfred} __packed;
15248156Sjlemon
153124539Smdodd#define	IDA_RAID0	0	/* No fault tolerance. */
154124539Smdodd#define	IDA_RAID4	1	/* Data Guard */
155124539Smdodd#define	IDA_RAID1	2	/* Mirroring */
156124539Smdodd#define	IDA_RAID5	3	/* Distributed Data Guard */
157124539Smdodd
158124539Smdodd/*
159124539Smdodd * CMD_GET_LOG_DRV_INFO (0x10)
160124539Smdodd * Identify Logical Drive
161124539Smdodd */
162124539Smdoddstruct ida_drive_info {
163124539Smdodd	u_int16_t	secsize;	/* block size in bytes */
164124539Smdodd	u_int32_t	secperunit;	/* blocks available */
165124539Smdodd	struct ida_drive_param	dp;	/* logical drive parameter table */
166124539Smdodd	u_int8_t	mirror;		/* fault tolerance */
167124539Smdodd	u_int8_t	reserved;
168124539Smdodd	u_int8_t	bios_disable;
169124539Smdodd} __packed;
170124539Smdodd
171124539Smdodd/*
172124539Smdodd * CMD_GET_LOG_DRV_EXT (0x18)
173124539Smdodd * Identify Logical Drive, Extended
174124539Smdodd */
175124539Smdoddstruct ida_drive_info_ext {
176124539Smdodd	u_int16_t	secsize;	/* block size in bytes */
177124539Smdodd	u_int32_t	secperunit;	/* blocks available */
178124539Smdodd	struct ida_drive_param	dp;	/* logical drive parameter table */
179124539Smdodd	u_int8_t	mirror;		/* fault tolerance */
180124539Smdodd	u_int8_t	reserved;
181124539Smdodd	u_int8_t	bios_disable;
182124539Smdodd	u_int32_t	ld_id;		/* Logical drive identifier */
183124539Smdodd	u_int8_t	ld_label[64];	/* Logical drive label */
184124539Smdodd} __packed;
185124539Smdodd
186124539Smdodd/*
187124539Smdodd * CMD_GET_CTRL_INFO (0x11)
188124539Smdodd * Identify Controller
189124539Smdodd */
19048156Sjlemonstruct ida_controller_info {
191124539Smdodd	u_int8_t	num_drvs;	/* Number of configured logical drives */
192124539Smdodd	u_int32_t	signature;	/* Configuration signature */
193124539Smdodd	u_int8_t	firm_rev[4];	/* ASCII firmware revision */
194124539Smdodd	u_int8_t	rom_rev[4];	/* ROM firmware revision */
195124539Smdodd	u_int8_t	hw_rev;		/* Revision level of the hardware */
196124539Smdodd	u_int32_t	bb_rev;
197124539Smdodd	u_int32_t	dp_map;		/* Drive present bit map */
198124539Smdodd	u_int32_t	ed_map;		/* External drive bit map */
199124539Smdodd	u_int32_t	board_id;
200124539Smdodd	u_int8_t	cfg_error;
201124539Smdodd	u_int32_t	nd_map;		/* Non-disk map */
202124539Smdodd	u_int8_t	bad_ram_addr;
203124539Smdodd	u_int8_t	cpu_rev;
204124539Smdodd	u_int8_t	pdpi_rev;
205124539Smdodd	u_int8_t	epic_rev;
206124539Smdodd	u_int8_t	wcxc_rev;
207124539Smdodd	u_int8_t	mkt_rev;	/* Marketing revision */
208124539Smdodd	u_int8_t	cflag;		/* Controller flags */
209124539Smdodd#define	IDA_CI_CFLAG_7DPB	(1<<3)
210124539Smdodd#define	IDA_CI_CFLAG_BIGMAP	(1<<7)
211124539Smdodd	u_int8_t	hflag;
212124539Smdodd	u_int8_t	expand_dis;
213124539Smdodd	u_int8_t	scsi_cc;	/* SCSI chip count */
214124539Smdodd	u_int32_t	max_req_blocks;
215124539Smdodd	u_int32_t	cclock;		/* Controller Clock */
216124539Smdodd	u_int8_t	dp_scsi;	/* Drives per SCSI bus */
217124539Smdodd	u_int16_t	big_dp_map[8];	/* Big drive present bit map */
218124539Smdodd	u_int16_t	big_ed_map[8];	/* Big external drive bit map */
219124539Smdodd	u_int16_t	big_nd_map[8];	/* Big non-disk map */
220124539Smdodd	u_int16_t	task_flags;
221124539Smdodd	u_int8_t	icl_bus;
222124539Smdodd	u_int8_t	red_modes;
223124539Smdodd	u_int8_t	cur_red_mode;
224124539Smdodd	u_int8_t	red_ctlr_stat;
225124539Smdodd	u_int8_t	red_fail_reason;
226124539Smdodd	u_int8_t	reserved[403];
227103870Salfred} __packed;
22863934Sjlemon
229144991Smdodd/*
230124539Smdodd * CMD_SENSE_DRV_STATUS (0x12)
231124539Smdodd * Sense logical drive status
232124539Smdodd */
23363934Sjlemonstruct ida_drive_status {
23463934Sjlemon	u_int8_t	status;
23563934Sjlemon	u_int32_t	failure_map;
236124539Smdodd	u_int16_t	read_err[32];
237124539Smdodd	u_int16_t	write_error[32];
238124539Smdodd	u_int8_t	reserved0[288];
23963934Sjlemon	u_int32_t	secrecover;
24063934Sjlemon	u_int8_t	rebuilding;
241124539Smdodd	u_int16_t	remap_cnt[32];
24263934Sjlemon	u_int32_t	repl_map;
24363934Sjlemon	u_int32_t	spare_map;
24463934Sjlemon	u_int8_t	spare_status;
24563934Sjlemon	u_int8_t	spare_repl_map[32];
24663934Sjlemon	u_int32_t	repl_ok_map;
24763934Sjlemon	u_int8_t	media_exchange;
24863934Sjlemon	u_int8_t	cache_failure;
24963934Sjlemon	u_int8_t	expand_failure;
25063934Sjlemon	u_int8_t	unit_flags;
25163934Sjlemon	u_int16_t	big_failure_map[8];
25263934Sjlemon	u_int16_t	big_remap_cnt[128];
25363934Sjlemon	u_int16_t	big_repl_map[8];
25463934Sjlemon	u_int16_t	big_act_spare_map[8];
25563934Sjlemon	u_int8_t	big_spare_repl_map[128];
25663934Sjlemon	u_int16_t	big_repl_ok_map[8];
25763934Sjlemon	u_int8_t	big_rebuilding;
258124539Smdodd	u_int8_t	reserved1[36];
259103870Salfred} __packed;
260124539Smdodd
261124539Smdodd/*
262124539Smdodd * CMD_GET_PHYS_DRV_INFO (0x15)
263124539Smdodd * Identify Physical Drive
264124539Smdodd */
265124539Smdoddstruct ida_phys_drv_info {
266124539Smdodd	u_int8_t	scsi_bus;	/* SCSI Bus */
267124539Smdodd	u_int8_t	scsi_id;	/* SCSI ID */
268124539Smdodd	u_int16_t	blksize;	/* block size in bytes */
269124539Smdodd	u_int32_t	blkcount;	/* total blocks */
270124539Smdodd	u_int32_t	blkreserved;	/* reserved blocks */
271124539Smdodd	u_int8_t	drv_model[40];	/* drive model */
272124539Smdodd	u_int8_t	drv_serial[40];	/* drive serial number */
273124539Smdodd	u_int8_t	drv_fwrev[8];	/* drive firmware revision */
274124539Smdodd	u_int8_t	scsi_inq;	/* SCSI inquiry bits */
275124539Smdodd	u_int8_t	cpq_drv_stmp;
276124539Smdodd	u_int8_t	last_fail;
277124539Smdodd	u_int8_t	pd_flags;	/* physical drive flags */
278124539Smdodd#define	PDF_DISK_PRESENT	0x01
279124539Smdodd#define	PDF_NONDISK_PRESENT	0x02
280124539Smdodd#define	PDF_WIDE_ENABLED	0x04
281124539Smdodd#define	PDF_SYNC		0x08
282124539Smdodd#define	PDF_NARROW_TRAY		0x10
283124539Smdodd#define	PDF_WIDEFAIL		0x20
284124539Smdodd#define	PDF_ULTRA		0x40
285124539Smdodd#define	PDF_ULTRA2		0x80
286124539Smdodd	u_int8_t	mpd_flags;	/* more physical drive flags */
287124539Smdodd#define	MPDF_SMART_SUPPORT	0x01	/* S.M.A.R.T supported */
288124539Smdodd#define	MPDF_SMART_ERRORS	0x02	/* S.M.A.R.T errors recorded */
289124539Smdodd#define	MPDF_SMART_ENABLED	0x04	/* S.M.A.R.T predictive failure is enabled */
290124539Smdodd#define	MPDF_SMART_ERR_RESET	0x08	/* S.M.A.R.T errors recorded since last reset */
291124539Smdodd#define	MPDF_DRIVE_EXTERNAL	0x10	/* Connected to external connector. */
292124539Smdodd#define	MPDF_DRIVE_CONF_LVOL	0x20	/* Configured as part of a logical volume */
293124539Smdodd#define	MPDF_DRIVE_CONF_SPARE	0x40	/* Configured as a spare */
294124539Smdodd#define	MPDF_DRIVE_WCE		0x80	/* Drive WCE set on spinup */
295124539Smdodd	u_int8_t	scsi_lun;
296124539Smdodd	u_int8_t	ympd_flags;	/* yet more physical drive flags */
297124539Smdodd#define	YMPDF_DRIVE_WCE_SET	0x40	/* WCE currently set */
298124539Smdodd#define	YMPDF_DRIVE_WCE_CHNG	0x80	/* WCE changable */
299124539Smdodd	u_int8_t	reserved;
300124539Smdodd	u_int32_t	spi_speed_rules;
301124539Smdodd	u_int8_t	phys_con[2];	/* Physical Connector */
302124539Smdodd	u_int8_t	phys_box;	/* Physical Box on Bus */
303124539Smdodd	u_int8_t	phys_bay;	/* Physical Bay in Box */
304124539Smdodd} __packed;
305124539Smdodd
306124539Smdodd/*
307124539Smdodd * CMD_BLINK_DRV_LEDS (0x16)
308124539Smdodd * Blink Drive Tray LEDs
309124539Smdodd *
310124539Smdodd * CMD_SENSE_DRV_LEDS (0x17)
311124539Smdodd * Sense Blinking Drive Tray LEDs
312124539Smdodd */
313124539Smdoddstruct ida_blink_drv_leds {
314124539Smdodd	u_int32_t	bd;		/* Blink duration (in 10ths sec) */
315124539Smdodd	u_int32_t	bte;		/* Blink time elapsed (sense only) */
316124539Smdodd	u_int8_t	bse[256];	/* Blink/seek enable */
317124539Smdodd	u_int8_t	reserved1[248];
318124539Smdodd} __packed;
319124539Smdodd
320124539Smdodd/*
321124539Smdodd * CMD_LABEL_LOG_DRV (0x57)
322124539Smdodd * Label Logical Drive
323124539Smdodd */
324124539Smdoddstruct ida_label_logical {
325124539Smdodd	u_int32_t	ld_id;		/* Logical drive identifier */
326124539Smdodd	u_int8_t	ld_label[64];	/* Logical drive label */
327124539Smdodd} __packed;
328