xref: /freebsd/sys/dev/ips/ips.h (revision 03a908f2ce4394b8fd8ec8e4734938c002989d0f)
12aedd662SScott Long /*-
22aedd662SScott Long  * Copyright (c) 2002 Adaptec Inc.
32aedd662SScott Long  * All rights reserved.
42aedd662SScott Long  *
52aedd662SScott Long  * Written by: David Jeffery
62aedd662SScott Long  *
72aedd662SScott Long  * Redistribution and use in source and binary forms, with or without
82aedd662SScott Long  * modification, are permitted provided that the following conditions
92aedd662SScott Long  * are met:
102aedd662SScott Long  * 1. Redistributions of source code must retain the above copyright
112aedd662SScott Long  *    notice, this list of conditions and the following disclaimer.
122aedd662SScott Long  * 2. Redistributions in binary form must reproduce the above copyright
132aedd662SScott Long  *    notice, this list of conditions and the following disclaimer in the
142aedd662SScott Long  *    documentation and/or other materials provided with the distribution.
152aedd662SScott Long  *
162aedd662SScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172aedd662SScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182aedd662SScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192aedd662SScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202aedd662SScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212aedd662SScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222aedd662SScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232aedd662SScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242aedd662SScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252aedd662SScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262aedd662SScott Long  * SUCH DAMAGE.
272aedd662SScott Long  *
282aedd662SScott Long  * $FreeBSD$
292aedd662SScott Long  */
302aedd662SScott Long 
312aedd662SScott Long 
322aedd662SScott Long #include <sys/param.h>
332aedd662SScott Long #include <sys/systm.h>
342aedd662SScott Long #include <sys/kernel.h>
35fe12f24bSPoul-Henning Kamp #include <sys/module.h>
362aedd662SScott Long #include <sys/bus.h>
372aedd662SScott Long #include <sys/conf.h>
382aedd662SScott Long #include <sys/types.h>
392aedd662SScott Long #include <sys/queue.h>
402aedd662SScott Long #include <sys/bio.h>
412aedd662SScott Long #include <sys/malloc.h>
422aedd662SScott Long #include <sys/mutex.h>
43b234a120SScott Long #include <sys/sema.h>
447633e7f1SMartin Blapp #include <sys/time.h>
452aedd662SScott Long 
462aedd662SScott Long #include <machine/bus_memio.h>
472aedd662SScott Long #include <machine/bus.h>
482aedd662SScott Long #include <sys/rman.h>
492aedd662SScott Long #include <machine/resource.h>
502aedd662SScott Long 
5177e6a3b2SWarner Losh #include <dev/pci/pcireg.h>
5277e6a3b2SWarner Losh #include <dev/pci/pcivar.h>
532aedd662SScott Long 
54dd83a01eSScott Long MALLOC_DECLARE(M_IPSBUF);
55dd83a01eSScott Long 
562aedd662SScott Long /*
572aedd662SScott Long  *   IPS CONSTANTS
582aedd662SScott Long  */
592aedd662SScott Long #define IPS_VENDOR_ID                   0x1014
6033ad16c0SScott Long #define IPS_VENDOR_ID_ADAPTEC		0x9005
612aedd662SScott Long #define IPS_MORPHEUS_DEVICE_ID          0x01BD
622aedd662SScott Long #define IPS_COPPERHEAD_DEVICE_ID        0x002E
63dd851eccSScott Long #define IPS_MARCO_DEVICE_ID		0x0250
642aedd662SScott Long #define IPS_CSL				0xff
652aedd662SScott Long #define IPS_POCL			0x30
662aedd662SScott Long 
672aedd662SScott Long /* amounts of memory to allocate for certain commands */
682aedd662SScott Long #define IPS_ADAPTER_INFO_LEN		(sizeof(ips_adapter_info_t))
692aedd662SScott Long #define IPS_DRIVE_INFO_LEN		(sizeof(ips_drive_info_t))
702aedd662SScott Long #define IPS_COMMAND_LEN			24
712aedd662SScott Long #define IPS_MAX_SG_LEN			(sizeof(ips_sg_element_t) * IPS_MAX_SG_ELEMENTS)
722aedd662SScott Long #define IPS_NVRAM_PAGE_SIZE		128
732aedd662SScott Long /* various flags */
7403a908f2SScott Long #define IPS_STATIC_FLAG			0x01
752aedd662SScott Long 
762aedd662SScott Long /* states for the card to be in */
772aedd662SScott Long #define IPS_DEV_OPEN			0x01
782aedd662SScott Long #define IPS_TIMEOUT			0x02 /* command time out, need reset */
792aedd662SScott Long #define IPS_OFFLINE			0x04 /* can't reset card/card failure */
8003a908f2SScott Long #define IPS_STATIC_BUSY			0x08
812aedd662SScott Long 
822aedd662SScott Long /* max number of commands set to something low for now */
832aedd662SScott Long #define IPS_MAX_CMD_NUM			128
842aedd662SScott Long #define IPS_MAX_NUM_DRIVES		8
852aedd662SScott Long #define IPS_MAX_SG_ELEMENTS		32
862aedd662SScott Long #define IPS_MAX_IOBUF_SIZE		(64 * 1024)
872aedd662SScott Long #define IPS_BLKSIZE			512
882aedd662SScott Long 
892aedd662SScott Long /* logical drive states */
902aedd662SScott Long 
912aedd662SScott Long #define IPS_LD_OFFLINE               	0x02
922aedd662SScott Long #define IPS_LD_OKAY                  	0x03
937633e7f1SMartin Blapp #define IPS_LD_DEGRADED			0x04
942aedd662SScott Long #define IPS_LD_FREE                  	0x00
952aedd662SScott Long #define IPS_LD_SYS                   	0x06
962aedd662SScott Long #define IPS_LD_CRS                   	0x24
972aedd662SScott Long 
982aedd662SScott Long /* register offsets */
992aedd662SScott Long #define MORPHEUS_REG_OMR0               0x0018 /* Outbound Msg. Reg. 0 */
1002aedd662SScott Long #define MORPHEUS_REG_OMR1               0x001C /* Outbound Msg. Reg. 1 */
1012aedd662SScott Long #define MORPHEUS_REG_IDR		0x0020 /* Inbound Doorbell Reg. */
1022aedd662SScott Long #define MORPHEUS_REG_IISR               0x0024 /* Inbound IRQ Status Reg. */
1032aedd662SScott Long #define MORPHEUS_REG_IIMR               0x0028 /* Inbound IRQ Mask Reg. */
1042aedd662SScott Long #define MORPHEUS_REG_OISR               0x0030 /* Outbound IRQ Status Reg. */
1052aedd662SScott Long #define MORPHEUS_REG_OIMR               0x0034 /* Outbound IRQ Status Reg. */
1062aedd662SScott Long #define MORPHEUS_REG_IQPR               0x0040 /* Inbound Queue Port Reg. */
1072aedd662SScott Long #define MORPHEUS_REG_OQPR               0x0044 /* Outbound Queue Port Reg. */
1082aedd662SScott Long 
1092aedd662SScott Long #define COPPER_REG_SCPR			0x05	/* Subsystem Ctrl. Port Reg. */
1102aedd662SScott Long #define COPPER_REG_ISPR			0x06	/* IRQ Status Port Reg. */
1112aedd662SScott Long #define COPPER_REG_CBSP			0x07	/* ? Reg. */
1122aedd662SScott Long #define COPPER_REG_HISR			0x08	/* Host IRQ Status Reg.    */
1132aedd662SScott Long #define COPPER_REG_CCSAR		0x10	/* Cmd. Channel Sys Addr Reg.*/
1142aedd662SScott Long #define COPPER_REG_CCCR			0x14	/* Cmd. Channel Ctrl. Reg. */
1152aedd662SScott Long #define COPPER_REG_SQHR                	0x20    /* Status Queue Head Reg.  */
1162aedd662SScott Long #define COPPER_REG_SQTR                	0x24    /* Status Queue Tail Reg.  */
1172aedd662SScott Long #define COPPER_REG_SQER                	0x28    /* Status Queue End Reg.   */
1182aedd662SScott Long #define COPPER_REG_SQSR                	0x2C    /* Status Queue Start Reg. */
1192aedd662SScott Long 
1202aedd662SScott Long /* bit definitions */
1212aedd662SScott Long #define MORPHEUS_BIT_POST1              0x01
1222aedd662SScott Long #define MORPHEUS_BIT_POST2              0x02
1232aedd662SScott Long #define MORPHEUS_BIT_CMD_IRQ		0x08
1242aedd662SScott Long 
1252aedd662SScott Long #define COPPER_CMD_START		0x101A
1262aedd662SScott Long #define COPPER_SEM_BIT			0x08
1272aedd662SScott Long #define COPPER_EI_BIT			0x80
1282aedd662SScott Long #define COPPER_EBM_BIT			0x02
1292aedd662SScott Long #define COPPER_RESET_BIT		0x80
1302aedd662SScott Long #define COPPER_GHI_BIT			0x04
1312aedd662SScott Long #define COPPER_SCE_BIT			0x01
1322aedd662SScott Long #define COPPER_OP_BIT			0x01
1332aedd662SScott Long #define COPPER_ILE_BIT			0x10
1342aedd662SScott Long 
1352aedd662SScott Long /* status defines */
1362aedd662SScott Long #define IPS_POST1_OK                    0x8000
1372aedd662SScott Long #define IPS_POST2_OK                    0x000f
1382aedd662SScott Long 
1392aedd662SScott Long /* command op codes */
1402aedd662SScott Long #define IPS_READ_CMD			0x02
1412aedd662SScott Long #define IPS_WRITE_CMD			0x03
1422aedd662SScott Long #define IPS_ADAPTER_INFO_CMD		0x05
1432aedd662SScott Long #define IPS_CACHE_FLUSH_CMD		0x0A
1442aedd662SScott Long #define IPS_REBUILD_STATUS_CMD		0x0C
1452aedd662SScott Long #define IPS_ERROR_TABLE_CMD		0x17
1462aedd662SScott Long #define IPS_DRIVE_INFO_CMD		0x19
1472aedd662SScott Long #define IPS_SUBSYS_PARAM_CMD		0x40
1482aedd662SScott Long #define IPS_CONFIG_SYNC_CMD		0x58
1492aedd662SScott Long #define IPS_SG_READ_CMD			0x82
1502aedd662SScott Long #define IPS_SG_WRITE_CMD		0x83
1512aedd662SScott Long #define IPS_RW_NVRAM_CMD		0xBC
1527633e7f1SMartin Blapp #define IPS_FFDC_CMD			0xD7
1532aedd662SScott Long 
1542aedd662SScott Long /* error information returned by the adapter */
1552aedd662SScott Long #define IPS_MIN_ERROR			0x02
1562aedd662SScott Long #define IPS_ERROR_STATUS		0x13000200 /* ahh, magic numbers */
1572aedd662SScott Long 
1587633e7f1SMartin Blapp #define IPS_OS_FREEBSD			8
1592aedd662SScott Long #define IPS_VERSION_MAJOR		"0.90"
1607633e7f1SMartin Blapp #define IPS_VERSION_MINOR		".10"
1617633e7f1SMartin Blapp 
1627633e7f1SMartin Blapp /* Adapter Types */
1637633e7f1SMartin Blapp #define IPS_ADAPTER_COPPERHEAD		0x01
1647633e7f1SMartin Blapp #define IPS_ADAPTER_COPPERHEAD2		0x02
1657633e7f1SMartin Blapp #define IPS_ADAPTER_COPPERHEADOB1	0x03
1667633e7f1SMartin Blapp #define IPS_ADAPTER_COPPERHEADOB2	0x04
1677633e7f1SMartin Blapp #define IPS_ADAPTER_CLARINET		0x05
1687633e7f1SMartin Blapp #define IPS_ADAPTER_CLARINETLITE	0x06
1697633e7f1SMartin Blapp #define IPS_ADAPTER_TROMBONE		0x07
1707633e7f1SMartin Blapp #define IPS_ADAPTER_MORPHEUS		0x08
1717633e7f1SMartin Blapp #define IPS_ADAPTER_MORPHEUSLITE	0x09
1727633e7f1SMartin Blapp #define IPS_ADAPTER_NEO			0x0A
1737633e7f1SMartin Blapp #define IPS_ADAPTER_NEOLITE		0x0B
1747633e7f1SMartin Blapp #define IPS_ADAPTER_SARASOTA2		0x0C
1757633e7f1SMartin Blapp #define IPS_ADAPTER_SARASOTA1		0x0D
1767633e7f1SMartin Blapp #define IPS_ADAPTER_MARCO		0x0E
1777633e7f1SMartin Blapp #define IPS_ADAPTER_SEBRING		0x0F
1787633e7f1SMartin Blapp #define IPS_ADAPTER_MAX_T		IPS_ADAPTER_SEBRING
1797633e7f1SMartin Blapp 
1807633e7f1SMartin Blapp /* values for ffdc_settime (from gmtime) */
1817633e7f1SMartin Blapp #define IPS_SECSPERMIN      60
1827633e7f1SMartin Blapp #define IPS_MINSPERHOUR     60
1837633e7f1SMartin Blapp #define IPS_HOURSPERDAY     24
1847633e7f1SMartin Blapp #define IPS_DAYSPERWEEK     7
1857633e7f1SMartin Blapp #define IPS_DAYSPERNYEAR    365
1867633e7f1SMartin Blapp #define IPS_DAYSPERLYEAR    366
1877633e7f1SMartin Blapp #define IPS_SECSPERHOUR     (IPS_SECSPERMIN * IPS_MINSPERHOUR)
1887633e7f1SMartin Blapp #define IPS_SECSPERDAY      ((long) IPS_SECSPERHOUR * IPS_HOURSPERDAY)
1897633e7f1SMartin Blapp #define IPS_MONSPERYEAR     12
1907633e7f1SMartin Blapp #define IPS_EPOCH_YEAR      1970
1917633e7f1SMartin Blapp #define IPS_LEAPS_THRU_END_OF(y)    ((y) / 4 - (y) / 100 + (y) / 400)
1927633e7f1SMartin Blapp #define ips_isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
1932aedd662SScott Long 
1942aedd662SScott Long /*
1952aedd662SScott Long  *  IPS MACROS
1962aedd662SScott Long  */
1972aedd662SScott Long 
1982aedd662SScott Long #define ips_read_1(sc,offset)		bus_space_read_1(sc->bustag, sc->bushandle, offset)
1992aedd662SScott Long #define ips_read_2(sc,offset) 		bus_space_read_2(sc->bustag, sc->bushandle, offset)
2002aedd662SScott Long #define ips_read_4(sc,offset)		bus_space_read_4(sc->bustag, sc->bushandle, offset)
2012aedd662SScott Long 
2022aedd662SScott Long #define ips_write_1(sc,offset,value)	bus_space_write_1(sc->bustag, sc->bushandle, offset, value)
2032aedd662SScott Long #define ips_write_2(sc,offset,value) 	bus_space_write_2(sc->bustag, sc->bushandle, offset, value)
2042aedd662SScott Long #define ips_write_4(sc,offset,value)	bus_space_write_4(sc->bustag, sc->bushandle, offset, value)
2052aedd662SScott Long 
2062aedd662SScott Long /* this is ugly.  It zeros the end elements in an ips_command_t struct starting with the status element */
2072aedd662SScott Long #define clear_ips_command(command)	bzero(&((command)->status), (unsigned long)(&(command)[1])-(unsigned long)&((command)->status))
2082aedd662SScott Long 
2092aedd662SScott Long #define ips_read_request(iobuf)		((iobuf)->bio_cmd == BIO_READ)
2102aedd662SScott Long 
2112aedd662SScott Long #define COMMAND_ERROR(status)		(((status)->fields.basic_status & 0x0f) >= IPS_MIN_ERROR)
2122aedd662SScott Long 
2132aedd662SScott Long #ifndef IPS_DEBUG
2142aedd662SScott Long #define DEVICE_PRINTF(x...)
2152aedd662SScott Long #define PRINTF(x...)
2162aedd662SScott Long #else
2172aedd662SScott Long #define DEVICE_PRINTF(level,x...)	if(IPS_DEBUG >= level)device_printf(x)
2182aedd662SScott Long #define PRINTF(level,x...)		if(IPS_DEBUG >= level)printf(x)
2192aedd662SScott Long #endif
2202aedd662SScott Long /*
2212aedd662SScott Long  *   IPS STRUCTS
2222aedd662SScott Long  */
2232aedd662SScott Long 
2242aedd662SScott Long struct ips_softc;
2252aedd662SScott Long 
2262aedd662SScott Long typedef struct{
2272aedd662SScott Long 	u_int8_t	command;
2282aedd662SScott Long 	u_int8_t	id;
2292aedd662SScott Long 	u_int8_t	drivenum;
2302aedd662SScott Long 	u_int8_t	reserve2;
2312aedd662SScott Long 	u_int32_t	lba;
2322aedd662SScott Long 	u_int32_t	buffaddr;
2332aedd662SScott Long 	u_int32_t	reserve3;
2342aedd662SScott Long } __attribute__ ((packed)) ips_generic_cmd;
2352aedd662SScott Long 
2362aedd662SScott Long typedef struct{
2372aedd662SScott Long 	u_int8_t	command;
2382aedd662SScott Long 	u_int8_t	id;
2392aedd662SScott Long 	u_int8_t	drivenum;
2402aedd662SScott Long 	u_int8_t	segnum;
2412aedd662SScott Long 	u_int32_t	lba;
2422aedd662SScott Long 	u_int32_t	buffaddr;
2432aedd662SScott Long 	u_int16_t	length;
2442aedd662SScott Long 	u_int16_t	reserve1;
2452aedd662SScott Long } __attribute__ ((packed)) ips_io_cmd;
2462aedd662SScott Long 
2472aedd662SScott Long typedef struct{
2482aedd662SScott Long 	u_int8_t	command;
2492aedd662SScott Long 	u_int8_t	id;
2502aedd662SScott Long 	u_int8_t	pagenum;
2512aedd662SScott Long 	u_int8_t	rw;
2522aedd662SScott Long 	u_int32_t	reserve1;
2532aedd662SScott Long 	u_int32_t	buffaddr;
2542aedd662SScott Long 	u_int32_t	reserve3;
2552aedd662SScott Long } __attribute__ ((packed)) ips_rw_nvram_cmd;
2562aedd662SScott Long 
2572aedd662SScott Long typedef struct{
2582aedd662SScott Long 	u_int8_t	command;
2592aedd662SScott Long 	u_int8_t	id;
2602aedd662SScott Long 	u_int8_t	drivenum;
2612aedd662SScott Long 	u_int8_t	reserve1;
2622aedd662SScott Long 	u_int32_t	reserve2;
2632aedd662SScott Long 	u_int32_t	buffaddr;
2642aedd662SScott Long 	u_int32_t	reserve3;
2652aedd662SScott Long } __attribute__ ((packed)) ips_drive_cmd;
2662aedd662SScott Long 
2672aedd662SScott Long typedef struct{
2682aedd662SScott Long 	u_int8_t	command;
2692aedd662SScott Long 	u_int8_t	id;
2702aedd662SScott Long 	u_int8_t	reserve1;
2712aedd662SScott Long 	u_int8_t	commandtype;
2722aedd662SScott Long 	u_int32_t	reserve2;
2732aedd662SScott Long 	u_int32_t	buffaddr;
2742aedd662SScott Long 	u_int32_t	reserve3;
2752aedd662SScott Long } __attribute__((packed)) ips_adapter_info_cmd;
2762aedd662SScott Long 
2777633e7f1SMartin Blapp typedef struct{
2787633e7f1SMartin Blapp 	u_int8_t	command;
2797633e7f1SMartin Blapp 	u_int8_t	id;
2807633e7f1SMartin Blapp 	u_int8_t	reset_count;
2817633e7f1SMartin Blapp 	u_int8_t	reset_type;
2827633e7f1SMartin Blapp 	u_int8_t	second;
2837633e7f1SMartin Blapp 	u_int8_t	minute;
2847633e7f1SMartin Blapp 	u_int8_t	hour;
2857633e7f1SMartin Blapp 	u_int8_t	day;
2867633e7f1SMartin Blapp 	u_int8_t	reserve1[4];
2877633e7f1SMartin Blapp 	u_int8_t	month;
2887633e7f1SMartin Blapp 	u_int8_t	yearH;
2897633e7f1SMartin Blapp 	u_int8_t	yearL;
2907633e7f1SMartin Blapp 	u_int8_t	reserve2;
2917633e7f1SMartin Blapp } __attribute__((packed)) ips_adapter_ffdc_cmd;
2927633e7f1SMartin Blapp 
2932aedd662SScott Long typedef union{
2942aedd662SScott Long 	ips_generic_cmd		generic_cmd;
2952aedd662SScott Long 	ips_drive_cmd 		drive_cmd;
2962aedd662SScott Long 	ips_adapter_info_cmd 	adapter_info_cmd;
2972aedd662SScott Long } ips_cmd_buff_t;
2982aedd662SScott Long 
2992aedd662SScott Long typedef struct {
3002aedd662SScott Long    u_int32_t  signature;
3012aedd662SScott Long    u_int8_t   reserved;
3022aedd662SScott Long    u_int8_t   adapter_slot;
3032aedd662SScott Long    u_int16_t  adapter_type;
3042aedd662SScott Long    u_int8_t   bios_high[4];
3052aedd662SScott Long    u_int8_t   bios_low[4];
3062aedd662SScott Long    u_int16_t  reserve2;
3072aedd662SScott Long    u_int8_t   reserve3;
3082aedd662SScott Long    u_int8_t   operating_system;
3092aedd662SScott Long    u_int8_t   driver_high[4];
3102aedd662SScott Long    u_int8_t   driver_low[4];
3112aedd662SScott Long    u_int8_t   reserve4[100];
3122aedd662SScott Long }__attribute__((packed)) ips_nvram_page5;
3132aedd662SScott Long 
3142aedd662SScott Long typedef struct{
3152aedd662SScott Long 	u_int32_t	addr;
3162aedd662SScott Long 	u_int32_t	len;
3172aedd662SScott Long } ips_sg_element_t;
3182aedd662SScott Long 
3192aedd662SScott Long typedef struct{
3202aedd662SScott Long 	u_int8_t	drivenum;
3212aedd662SScott Long 	u_int8_t	merge_id;
3222aedd662SScott Long 	u_int8_t	raid_lvl;
3232aedd662SScott Long 	u_int8_t	state;
3242aedd662SScott Long 	u_int32_t	sector_count;
3252aedd662SScott Long } __attribute__((packed)) ips_drive_t;
3262aedd662SScott Long 
3272aedd662SScott Long typedef struct{
3282aedd662SScott Long 	u_int8_t	drivecount;
3292aedd662SScott Long 	u_int8_t	reserve1;
3302aedd662SScott Long 	u_int16_t	reserve2;
3312aedd662SScott Long 	ips_drive_t drives[IPS_MAX_NUM_DRIVES];
3322aedd662SScott Long }__attribute__((packed)) ips_drive_info_t;
3332aedd662SScott Long 
3342aedd662SScott Long typedef struct{
3352aedd662SScott Long 	u_int8_t	drivecount;
3362aedd662SScott Long 	u_int8_t	miscflags;
3372aedd662SScott Long 	u_int8_t	SLTflags;
3382aedd662SScott Long 	u_int8_t	BSTflags;
3392aedd662SScott Long 	u_int8_t	pwr_chg_count;
3402aedd662SScott Long 	u_int8_t	wrong_addr_count;
3412aedd662SScott Long 	u_int8_t	unident_count;
3422aedd662SScott Long 	u_int8_t	nvram_dev_chg_count;
3432aedd662SScott Long 	u_int8_t	codeblock_version[8];
3442aedd662SScott Long 	u_int8_t	bootblock_version[8];
3452aedd662SScott Long 	u_int32_t	drive_sector_count[IPS_MAX_NUM_DRIVES];
3462aedd662SScott Long 	u_int8_t	max_concurrent_cmds;
3472aedd662SScott Long 	u_int8_t	max_phys_devices;
3482aedd662SScott Long 	u_int16_t	flash_prog_count;
3492aedd662SScott Long 	u_int8_t	defunct_disks;
3502aedd662SScott Long 	u_int8_t	rebuildflags;
3512aedd662SScott Long 	u_int8_t	offline_drivecount;
3522aedd662SScott Long 	u_int8_t	critical_drivecount;
3532aedd662SScott Long 	u_int16_t	config_update_count;
3542aedd662SScott Long 	u_int8_t	blockedflags;
3552aedd662SScott Long 	u_int8_t	psdn_error;
3562aedd662SScott Long 	u_int16_t	addr_dead_disk[4*16];/* ugly, max # channels * max # scsi devices per channel */
3572aedd662SScott Long }__attribute__((packed)) ips_adapter_info_t;
3582aedd662SScott Long 
3592aedd662SScott Long typedef struct {
3602aedd662SScott Long 	u_int32_t 	status[IPS_MAX_CMD_NUM];
3612aedd662SScott Long 	u_int32_t 	base_phys_addr;
3622aedd662SScott Long 	int 		nextstatus;
3632aedd662SScott Long 	bus_dma_tag_t	dmatag;
3642aedd662SScott Long 	bus_dmamap_t	dmamap;
3652aedd662SScott Long } ips_copper_queue_t;
3662aedd662SScott Long 
3672aedd662SScott Long typedef union {
3682aedd662SScott Long    struct {
3692aedd662SScott Long       u_int8_t  reserved;
3702aedd662SScott Long       u_int8_t  command_id;
3712aedd662SScott Long       u_int8_t  basic_status;
3722aedd662SScott Long       u_int8_t  extended_status;
3732aedd662SScott Long    } fields;
3742aedd662SScott Long    volatile u_int32_t    value;
3752aedd662SScott Long } ips_cmd_status_t;
3762aedd662SScott Long 
3772aedd662SScott Long /* used to keep track of current commands to the card */
3782aedd662SScott Long typedef struct ips_command{
3792aedd662SScott Long 	u_int8_t		command_number;
3802aedd662SScott Long 	u_int8_t 		id;
3812aedd662SScott Long 	u_int8_t		timeout;
3822aedd662SScott Long 	struct ips_softc *	sc;
38303a908f2SScott Long 	bus_dma_tag_t		data_dmatag;
38403a908f2SScott Long 	bus_dmamap_t		data_dmamap;
3852aedd662SScott Long 	bus_dmamap_t		command_dmamap;
3862aedd662SScott Long 	void *			command_buffer;
3872aedd662SScott Long 	u_int32_t		command_phys_addr;/*WARNING! must be changed if 64bit addressing ever used*/
3882aedd662SScott Long 	ips_cmd_status_t	status;
3892aedd662SScott Long 	SLIST_ENTRY(ips_command)	next;
3902aedd662SScott Long 	void *			data_buffer;
3912aedd662SScott Long 	void *			arg;
3922aedd662SScott Long 	void			(* callback)(struct ips_command *command);
3932aedd662SScott Long }ips_command_t;
3942aedd662SScott Long 
3952aedd662SScott Long typedef struct ips_softc{
3962aedd662SScott Long         struct resource *       iores;
3972aedd662SScott Long         struct resource *       irqres;
398faf13262SPaul Saab         struct intr_config_hook ips_ich;
399dea4622dSScott Long         int                     configured;
4002aedd662SScott Long         int                     state;
4012aedd662SScott Long         int                     iotype;
4022aedd662SScott Long         int                     rid;
4032aedd662SScott Long         int                     irqrid;
4042aedd662SScott Long         void *                  irqcookie;
4052aedd662SScott Long         bus_space_tag_t	        bustag;
4062aedd662SScott Long 	bus_space_handle_t      bushandle;
4072aedd662SScott Long 	bus_dma_tag_t	        adapter_dmatag;
4082aedd662SScott Long 	bus_dma_tag_t		command_dmatag;
4092aedd662SScott Long 	bus_dma_tag_t		sg_dmatag;
4102aedd662SScott Long         device_t                dev;
41189c9c53dSPoul-Henning Kamp         struct cdev *device_file;
4122aedd662SScott Long 	struct callout_handle	timer;
4137633e7f1SMartin Blapp 	u_int16_t		adapter_type;
4142aedd662SScott Long 	ips_adapter_info_t	adapter_info;
4152aedd662SScott Long 	device_t		diskdev[IPS_MAX_NUM_DRIVES];
4162aedd662SScott Long 	ips_drive_t		drives[IPS_MAX_NUM_DRIVES];
4172aedd662SScott Long 	u_int8_t		drivecount;
4187633e7f1SMartin Blapp 	u_int16_t		ffdc_resetcount;
4197633e7f1SMartin Blapp 	struct timeval		ffdc_resettime;
4202aedd662SScott Long 	u_int8_t		next_drive;
4212aedd662SScott Long 	u_int8_t		max_cmds;
4222aedd662SScott Long 	volatile u_int8_t	used_commands;
42303a908f2SScott Long 	ips_command_t		*commandarray;
42403a908f2SScott Long 	ips_command_t		*staticcmd;
4252aedd662SScott Long 	SLIST_HEAD(command_list, ips_command) free_cmd_list;
4262aedd662SScott Long 	int			(* ips_adapter_reinit)(struct ips_softc *sc,
4272aedd662SScott Long 						       int force);
4282aedd662SScott Long         void                    (* ips_adapter_intr)(void *sc);
4292aedd662SScott Long 	void			(* ips_issue_cmd)(ips_command_t *command);
4302aedd662SScott Long 	ips_copper_queue_t *	copper_queue;
431b234a120SScott Long 	struct mtx		queue_mtx;
432b234a120SScott Long 	struct bio_queue_head	queue;
43303a908f2SScott Long 	struct sema		cmd_sema;
434b234a120SScott Long 
4352aedd662SScott Long }ips_softc_t;
4362aedd662SScott Long 
4372aedd662SScott Long /* function defines from ips_ioctl.c */
4382aedd662SScott Long extern int ips_ioctl_request(ips_softc_t *sc, u_long ioctl_cmd, caddr_t addr,
4392aedd662SScott Long 				int32_t flags);
4402aedd662SScott Long /* function defines from ips_disk.c */
4412aedd662SScott Long extern void ipsd_finish(struct bio *iobuf);
4422aedd662SScott Long 
4432aedd662SScott Long /* function defines from ips_commands.c */
4442aedd662SScott Long extern int ips_flush_cache(ips_softc_t *sc);
445b234a120SScott Long extern void ips_start_io_request(ips_softc_t *sc);
4462aedd662SScott Long extern int ips_get_drive_info(ips_softc_t *sc);
4472aedd662SScott Long extern int ips_get_adapter_info(ips_softc_t *sc);
4487633e7f1SMartin Blapp extern int ips_ffdc_reset(ips_softc_t *sc);
4492aedd662SScott Long extern int ips_update_nvram(ips_softc_t *sc);
4502aedd662SScott Long extern int ips_clear_adapter(ips_softc_t *sc);
4512aedd662SScott Long 
4522aedd662SScott Long /* function defines from ips.c */
45303a908f2SScott Long extern int ips_get_free_cmd(ips_softc_t *sc, ips_command_t **command, unsigned long flags);
4542aedd662SScott Long extern void ips_insert_free_cmd(ips_softc_t *sc, ips_command_t *command);
4552aedd662SScott Long extern int ips_adapter_init(ips_softc_t *sc);
4562aedd662SScott Long extern int ips_morpheus_reinit(ips_softc_t *sc, int force);
4572aedd662SScott Long extern int ips_adapter_free(ips_softc_t *sc);
4582aedd662SScott Long extern void ips_morpheus_intr(void *sc);
4592aedd662SScott Long extern void ips_issue_morpheus_cmd(ips_command_t *command);
4602aedd662SScott Long extern int ips_copperhead_reinit(ips_softc_t *sc, int force);
4612aedd662SScott Long extern void ips_copperhead_intr(void *sc);
4622aedd662SScott Long extern void ips_issue_copperhead_cmd(ips_command_t *command);
4632aedd662SScott Long 
464