Home | History | Annotate | Line # | Download | only in ic
ihavar.h revision 1.2
      1 /*	$NetBSD: ihavar.h,v 1.2 2001/06/09 13:43:02 tsutsui Exp $ */
      2 /*
      3  * Initio INI-9xxxU/UW SCSI Device Driver
      4  *
      5  * Copyright (c) 2000 Ken Westerback
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer,
     13  *    without modification, immediately at the beginning of the file.
     14  * 2. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     23  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     26  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     27  * THE POSSIBILITY OF SUCH DAMAGE.
     28  *
     29  *-------------------------------------------------------------------------
     30  *
     31  * Ported from i91uscsi.h, provided by Initio Corporation, which probably
     32  * came from the same people who provided i91u.c:
     33  *
     34  * Device driver for the INI-9XXXU/UW or INIC-940/950  PCI SCSI Controller.
     35  *
     36  * FreeBSD
     37  *
     38  *  Written for 386bsd and FreeBSD by
     39  *	Winston Hung		<winstonh (at) initio.com>
     40  *
     41  * Copyright (c) 1997-99 Initio Corp.  All rights reserved.
     42  *
     43  *-------------------------------------------------------------------------
     44  */
     45 
     46 /*
     47  * Ported to NetBSD by Izumi Tsutsui <tsutsui (at) ceres.dti.ne.jp> from OpenBSD:
     48  * $OpenBSD: iha.h,v 1.2 2001/02/08 17:35:05 krw Exp $
     49  */
     50 
     51 #define IHA_MAX_SG_ENTRIES	33
     52 #define IHA_MAX_TARGETS		16
     53 #define IHA_MAX_SCB		32
     54 #define IHA_MAX_EXTENDED_MSG	 4 /* SDTR(3) and WDTR(4) only */
     55 #define IHA_MAX_OFFSET		15
     56 
     57 #define SCSI_CONDITION_MET    0x04 /* SCSI Status codes not defined */
     58 #define SCSI_INTERM_COND_MET  0x14 /*     in scsi_all.h             */
     59 
     60 /*
     61  *   Scatter-Gather Element Structure
     62  */
     63 struct iha_sg_element {
     64 	u_int32_t sg_addr;	/* Data Pointer */
     65 	u_int32_t sg_len;	/* Data Length  */
     66 };
     67 
     68 struct iha_sglist {
     69 	struct iha_sg_element sg_element[IHA_MAX_SG_ENTRIES];
     70 };
     71 
     72 #define IHA_SG_SIZE (sizeof(struct iha_sglist))
     73 
     74 /*
     75  * iha_scsi_req_q - SCSI Request structure used by the
     76  *		    Tulip (aka inic-950). Note that 32
     77  *		    bit pointers and ints are assumed!
     78  */
     79 
     80 struct iha_scsi_req_q {
     81 	TAILQ_ENTRY(iha_scsi_req_q) chain;
     82 
     83 	bus_dmamap_t dmap;		/* maps xs->buf xfer buffer	*/
     84 
     85 	int status;			/* Current status of the SCB	*/
     86 #define  STATUS_QUEUED	0		/*  SCB one of Free/Done/Pend	*/
     87 #define  STATUS_RENT	1		/*  SCB allocated, not queued	*/
     88 #define  STATUS_SELECT	2		/*  SCB being selected		*/
     89 #define  STATUS_BUSY	3		/*  SCB I/O is active		*/
     90 	int nextstat;			/* Next state function to apply	*/
     91 	int sg_index;			/* Scatter/Gather Index		*/
     92 	int sg_max;			/* Scatter/Gather # valid entries */
     93 	int flags;			/* SCB Flags (xs->flags + private)*/
     94 #define  FLAG_RSENS	0x00010000	/*  Request Sense sent		*/
     95 #define  FLAG_SG	0x00020000	/*  Scatter/Gather used		*/
     96 	int target;			/* Target Id			*/
     97 	int lun;			/* Lun				*/
     98 
     99 	u_int32_t bufaddr;		/* Data Buffer Physical Addr	*/
    100 	u_int32_t buflen;		/* Data Allocation Length	*/
    101 	int ha_stat;			/* Status of Host Adapter	*/
    102 #define  HOST_OK	0x00		/*  OK - operation a success	*/
    103 #define  HOST_TIMED_OUT	0x01		/*  Request timed out		*/
    104 #define  HOST_SPERR	0x10		/*  SCSI parity error		*/
    105 #define  HOST_SEL_TOUT	0x11		/*  Selection Timeout		*/
    106 #define  HOST_DO_DU	0x12		/*  Data Over/Underrun		*/
    107 #define  HOST_BAD_PHAS	0x14		/*  Unexpected SCSI bus phase	*/
    108 #define  HOST_SCSI_RST	0x1B		/*  SCSI bus was reset		*/
    109 #define  HOST_DEV_RST	0x1C		/*  Device was reset		*/
    110 	int ta_stat;			/* SCSI Status Byte		*/
    111 	int timeout;			/* in milliseconds		*/
    112 
    113 	struct scsipi_xfer *xs;		/* xs this SCB is executing	*/
    114 	struct tcs *tcs;		/* tcs for SCB_Target	   	*/
    115 	struct iha_sg_element *sglist;
    116 	bus_size_t sgoffset;		/* xfer buf offset              */
    117 
    118 	int sg_size;			/* # of valid entries in sg_list */
    119 	u_int32_t sg_addr;		/* SGList Physical Address	*/
    120 
    121 
    122 	int cmdlen;			/* CDB Length			*/
    123 	u_int8_t cmd[12];		/* SCSI Command			*/
    124 
    125 	u_int8_t scb_id;		/* Identity Message		*/
    126 	u_int8_t scb_tagmsg;		/* Tag Message			*/
    127 	u_int8_t scb_tagid;		/* Queue Tag			*/
    128 };
    129 
    130 /*
    131  *   Target Device Control Structure
    132  */
    133 struct tcs {
    134 	int flags;
    135 #define		      FLAG_SCSI_RATE	 0x0007 /* Index into tul_rate_tbl[] */
    136 #define		      FLAG_EN_DISC	 0x0008 /* Enable disconnect	     */
    137 #define		      FLAG_NO_SYNC	 0x0010 /* No sync data transfer     */
    138 #define		      FLAG_NO_WIDE	 0x0020 /* No wide data transfer     */
    139 #define		      FLAG_1GIGA	 0x0040 /* 255 hd/63 sec (64/32)     */
    140 #define		      FLAG_SPINUP	 0x0080 /* Start disk drive	     */
    141 #define		      FLAG_WIDE_DONE	 0x0100 /* WDTR msg has been sent    */
    142 #define		      FLAG_SYNC_DONE	 0x0200 /* SDTR msg has been sent    */
    143 #define		      FLAG_NO_NEG_SYNC   (FLAG_NO_SYNC | FLAG_SYNC_DONE)
    144 #define		      FLAG_NO_NEG_WIDE   (FLAG_NO_WIDE | FLAG_WIDE_DONE)
    145 #define		      FLAG_NO_NEGOTIATE	 (FLAG_NO_NEG_SYNC | FLAG_NO_NEG_WIDE)
    146 	int period;
    147 	int offset;
    148 	int tagcnt;
    149 
    150 	struct iha_scsi_req_q *ntagscb;
    151 
    152 	u_int8_t  syncm;
    153 	u_int8_t  sconfig0;
    154 };
    155 
    156 struct iha_softc {
    157 	struct device sc_dev;
    158 
    159 	bus_space_tag_t sc_iot;
    160 	bus_space_handle_t sc_ioh;
    161 
    162 	bus_dma_tag_t sc_dmat;
    163 	bus_dmamap_t sc_dmamap;
    164 
    165 	struct scsipi_adapter sc_adapter;
    166 	struct scsipi_channel sc_channel;
    167 
    168 	int sc_id;
    169 	void *sc_ih;
    170 
    171 	/*
    172 	 *   Initio specific fields
    173 	 */
    174 	int sc_flags;
    175 #define		      FLAG_EXPECT_DISC	     0x01
    176 #define		      FLAG_EXPECT_SELECT     0x02
    177 #define		      FLAG_EXPECT_RESET	     0x10
    178 #define		      FLAG_EXPECT_DONE_DISC  0x20
    179 	int sc_semaph;
    180 #define		      SEMAPH_IN_MAIN	     0x00   /* Already in tulip_main */
    181 	int sc_phase;			  	    /* MSG  C/D	 I/O	     */
    182 #define		      PHASE_DATA_OUT	     0x00   /*	0    0	  0	     */
    183 #define		      PHASE_DATA_IN	     0x01   /*	0    0	  1	     */
    184 #define		      PHASE_CMD_OUT	     0x02   /*	0    1	  0	     */
    185 #define		      PHASE_STATUS_IN	     0x03   /*	0    1	  1	     */
    186 #define		      PHASE_MSG_OUT	     0x06   /*	1    1	  0	     */
    187 #define		      PHASE_MSG_IN	     0x07   /*	1    1	  1	     */
    188 
    189 	struct iha_scsi_req_q *sc_scb;		    /* SCB array	     */
    190 	struct iha_scsi_req_q *sc_actscb;	    /* SCB using SCSI bus    */
    191 	struct iha_sglist *sc_sglist;
    192 
    193 	TAILQ_HEAD(, iha_scsi_req_q) sc_freescb,
    194 				     sc_pendscb,
    195 				     sc_donescb;
    196 
    197 	struct tcs sc_tcs[IHA_MAX_TARGETS];
    198 
    199 	u_int8_t  sc_msg[IHA_MAX_EXTENDED_MSG];    /* [0] len, [1] Msg Code */
    200 	u_int8_t  sc_sistat;
    201 	u_int8_t  sc_status0;
    202 	u_int8_t  sc_status1;
    203 	u_int8_t  sc_sconf1;
    204 };
    205 
    206 /*
    207  *   EEPROM for one SCSI Channel
    208  */
    209 
    210 #define EEPROM_SIZE	32
    211 #define EEP_LBYTE(x)	((x) & 0xff)
    212 #define EEP_HBYTE(x)	((x) >> 8)
    213 #define EEP_WORD(l, h)	(((h) & 0xff) << 8 | ((l) && 0xff))
    214 #define EEP_WAIT()	DELAY(5)
    215 
    216 struct eeprom_adapter {
    217 	u_int16_t config1;		/* 0x00 Channel Adapter SCSI Id  */
    218 #define  CFG_ID_MASK	0x000f
    219 #define  CFG_ID(cfg)	((cfg) & CFG_ID_MASK)
    220 #define  CFG_SCSI_RESET	0x0100		/*     Reset bus at power up     */
    221 #define  CFG_EN_PAR	0x0200		/*     SCSI parity enable        */
    222 #define  CFG_ACT_TERM1	0x0400		/*     Enable active term 1      */
    223 #define  CFG_ACT_TERM2	0x0800		/*     Enable active term 2      */
    224 #define  CFG_AUTO_TERM	0x1000		/*     Enable auto terminator    */
    225 #define  CFG_EN_PWR	0x8000		/*     Enable power mgmt         */
    226 #define  CFG_DEFAULT	(CFG_SCSI_RESET | CFG_AUTO_TERM | CFG_EN_PAR)
    227 	u_int16_t config2;
    228 #define  CFG_CFG2(x)	EEP_LBYTE(x)	/* 0x02 Unused Channel Cfg byte 2*/
    229 #define  CFG_TARGET(x)	EEP_HBYTE(x)	/* 0x03 Number of SCSI targets   */
    230 					/* 0x04 Lower bytes of targ flags*/
    231 	u_int16_t tflags[IHA_MAX_TARGETS / sizeof(u_int16_t)];
    232 #define  FLAG_DEFAULT	(FLAG_NO_WIDE | FLAG_1GIGA | FLAG_EN_DISC)
    233 };
    234 
    235 /*
    236  * Tulip (aka ini-950) Serial EEPROM Layout
    237  */
    238 struct iha_eeprom {
    239 	/* ---------- Header ------------------------------------------------*/
    240 	u_int16_t signature;		       /* 0x00 NVRAM Signature	     */
    241 #define EEP_SIGNATURE	0xC925
    242 	u_int16_t revision;
    243 #define EEP_SIZE(x)	EEP_LBYTE(x)	       /* 0x02 Size of data structure*/
    244 #define EEP_REV(x)	EEP_HBYTE(x)	       /* 0x03 Rev. of data structure*/
    245 	/* ---------- Host Adapter Structure --------------------------------*/
    246 	u_int16_t model;		       /* 0x04 Model number          */
    247 	u_int16_t modelinfo;
    248 #define EEP_INFO(x)	EEP_LBYTE(x)	       /* 0x06 Model information     */
    249 #define EEP_CHAN(x)	EEP_HBYTE(x)	       /* 0x07 Number of SCSI channel*/
    250 	u_int16_t bioscfg;		       /* 0x08 BIOS configuration 1  */
    251 #define EEP_BIOSCFG_ENABLE	0x0001	       /*      BIOS enable	     */
    252 #define EEP_BIOSCFG_8DRIVE	0x0002	       /*      Support > 2 drives    */
    253 #define EEP_BIOSCFG_REMOVABLE	0x0004	       /*      Support removable drv */
    254 #define EEP_BIOSCFG_INT19	0x0008	       /*      Intercept int 19h     */
    255 #define EEP_BIOSCFG_BIOSSCAN	0x0010	       /*      Dynamic BIOS scan     */
    256 #define EEP_BIOSCFG_LUNSUPPORT	0x0040	       /*      Support LUN	     */
    257 #define EEP_BIOSCFG_DEFAULT	EEP_BIOSCFG_ENABLE
    258 	u_int16_t hacfg;		       /* 0x0a Host adapter config 1 */
    259 #define EEP_HACFG_BOOTIDMASK	0x000F	       /*      Boot ID number	     */
    260 #define EEP_HACFG_LUNMASK	0x0070	       /*      Boot LUN number	     */
    261 #define EEP_HACFG_CHANMASK	0x0080	       /*      Boot Channel number   */
    262 	struct eeprom_adapter adapter[2];      /* 0x0c		             */
    263 	u_int16_t reserved[5];		       /* 0x34			     */
    264 
    265 	/* --------- CheckSum -----------------------------------------------*/
    266 	u_int16_t checksum;		       /* 0x3E Checksum of NVRam     */
    267 };
    268 
    269 /* Functions used by higher SCSI layers, the kernel, or iha.c and iha_pci.c  */
    270 
    271 int iha_intr(void *);
    272 void iha_attach(struct iha_softc *);
    273