Home | History | Annotate | Line # | Download | only in ic
aic7xxxvar.h revision 1.26.2.3
      1  1.26.2.3   nathanw /*	$NetBSD: aic7xxxvar.h,v 1.26.2.3 2002/02/28 04:13:20 nathanw Exp $	*/
      2       1.7   thorpej 
      3       1.1   mycroft /*
      4       1.4   mycroft  * Interface to the generic driver for the aic7xxx based adaptec
      5       1.4   mycroft  * SCSI controllers.  This is used to implement product specific
      6       1.1   mycroft  * probe and attach routines.
      7       1.1   mycroft  *
      8      1.21      fvdl  * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000 Justin T. Gibbs.
      9       1.1   mycroft  * All rights reserved.
     10       1.1   mycroft  *
     11       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     12       1.1   mycroft  * modification, are permitted provided that the following conditions
     13       1.1   mycroft  * are met:
     14       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     15      1.21      fvdl  *    notice, this list of conditions, and the following disclaimer,
     16      1.21      fvdl  *    without modification.
     17      1.21      fvdl  * 2. The name of the author may not be used to endorse or promote products
     18       1.4   mycroft  *    derived from this software without specific prior written permission.
     19       1.4   mycroft  *
     20      1.21      fvdl  * Alternatively, this software may be distributed under the terms of the
     21      1.21      fvdl  * the GNU Public License ("GPL").
     22      1.21      fvdl  *
     23       1.4   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     24       1.4   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25       1.4   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26       1.4   mycroft  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     27       1.4   mycroft  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28       1.4   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29       1.4   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30       1.4   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31       1.4   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32       1.4   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33       1.4   mycroft  * SUCH DAMAGE.
     34       1.8  explorer  *
     35      1.21      fvdl  * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.h,v 1.16 2000/02/09 21:24:59 gibbs Exp $
     36       1.1   mycroft  */
     37       1.1   mycroft 
     38       1.1   mycroft #ifndef _AIC7XXX_H_
     39       1.1   mycroft #define _AIC7XXX_H_
     40      1.17  sommerfe 
     41      1.21      fvdl #ifndef FALSE
     42      1.21      fvdl #define FALSE 0
     43      1.21      fvdl #endif
     44      1.21      fvdl 
     45      1.21      fvdl #ifndef TRUE
     46      1.21      fvdl #define TRUE 1
     47      1.21      fvdl #endif
     48      1.17  sommerfe 
     49       1.8  explorer /*
     50      1.21      fvdl  * The maximum transfer per S/G segment.
     51       1.8  explorer  */
     52      1.21      fvdl #define AHC_MAXTRANSFER_SIZE	ctob(AHC_NSEG - 1)
     53       1.8  explorer 
     54      1.21      fvdl /*
     55      1.21      fvdl  * Convert FreeBSD queue macro
     56      1.21      fvdl  */
     57      1.21      fvdl #define STAILQ_ENTRY SIMPLEQ_ENTRY
     58      1.16       leo 
     59      1.21      fvdl /*
     60      1.21      fvdl  * The number of dma segments supported.  The current implementation limits
     61      1.21      fvdl  * us to 255 S/G entries (this may change to be unlimited at some point).
     62      1.21      fvdl  * To reduce the driver's memory consumption, we further limit the number
     63      1.21      fvdl  * supported to be sufficient to handle the largest mapping supported by
     64      1.21      fvdl  * the kernel, MAXPHYS.  Assuming the transfer is as fragmented as possible
     65      1.21      fvdl  * and unaligned, this turns out to be the number of paged sized transfers
     66      1.21      fvdl  * in MAXPHYS plus an extra element to handle any unaligned residual.
     67      1.21      fvdl  */
     68      1.21      fvdl #define AHC_NSEG (MIN(btoc(MAXPHYS) + 1, 255))
     69       1.1   mycroft 
     70       1.4   mycroft #define AHC_SCB_MAX	255	/*
     71       1.4   mycroft 				 * Up to 255 SCBs on some types of aic7xxx
     72       1.4   mycroft 				 * based boards.  The aic7870 have 16 internal
     73       1.4   mycroft 				 * SCBs, but external SRAM bumps this to 255.
     74       1.4   mycroft 				 * The aic7770 family have only 4, and the
     75       1.4   mycroft 				 * aic7850 has only 3.
     76       1.1   mycroft 				 */
     77       1.1   mycroft 
     78      1.21      fvdl #define AHC_TMODE_CMDS	256    /*
     79      1.21      fvdl 				* Ring Buffer of incoming target commands.
     80      1.21      fvdl 				* We allocate 256 to simplify the logic
     81      1.21      fvdl 				* in the sequencer by using the natural
     82      1.21      fvdl 				* wrap point of an 8bit counter.
     83      1.21      fvdl 				*/
     84       1.1   mycroft 
     85       1.1   mycroft struct ahc_dma_seg {
     86      1.21      fvdl 	u_int32_t	addr;
     87       1.9     gibbs 	u_int32_t	len;
     88       1.1   mycroft };
     89       1.4   mycroft 
     90       1.4   mycroft typedef enum {
     91      1.21      fvdl 	AHC_NONE	= 0x0000,
     92      1.21      fvdl 	AHC_CHIPID_MASK	= 0x00FF,
     93      1.21      fvdl 	AHC_AIC7770	= 0x0001,
     94      1.21      fvdl 	AHC_AIC7850	= 0x0002,
     95      1.21      fvdl 	AHC_AIC7855	= 0x0003,
     96      1.21      fvdl 	AHC_AIC7859	= 0x0004,
     97      1.21      fvdl 	AHC_AIC7860	= 0x0005,
     98      1.21      fvdl 	AHC_AIC7870	= 0x0006,
     99      1.21      fvdl 	AHC_AIC7880	= 0x0007,
    100      1.21      fvdl 	AHC_AIC7890	= 0x0008,
    101      1.21      fvdl 	AHC_AIC7892	= 0x0009,
    102      1.21      fvdl 	AHC_AIC7895	= 0x000a,
    103      1.21      fvdl 	AHC_AIC7896	= 0x000b,
    104      1.21      fvdl 	AHC_AIC7899	= 0x000c,
    105      1.21      fvdl 	AHC_VL		= 0x0100,	/* Bus type VL */
    106      1.21      fvdl 	AHC_EISA	= 0x0200,	/* Bus type EISA */
    107      1.21      fvdl 	AHC_PCI		= 0x0400,	/* Bus type PCI */
    108      1.21      fvdl 	AHC_BUS_MASK	= 0x0F00
    109      1.21      fvdl } ahc_chip;
    110      1.21      fvdl 
    111      1.25  jdolecek extern const char * const ahc_chip_names[];
    112      1.21      fvdl 
    113      1.21      fvdl typedef enum {
    114      1.21      fvdl 	AHC_FENONE	= 0x0000,
    115      1.21      fvdl 	AHC_ULTRA	= 0x0001,	/* Supports 20MHz Transfers */
    116      1.21      fvdl 	AHC_ULTRA2	= 0x0002,	/* Supports 40MHz Transfers */
    117      1.21      fvdl 	AHC_WIDE  	= 0x0004,	/* Wide Channel */
    118      1.21      fvdl 	AHC_TWIN	= 0x0008,	/* Twin Channel */
    119      1.21      fvdl 	AHC_MORE_SRAM	= 0x0010,	/* 80 bytes instead of 64 */
    120      1.21      fvdl 	AHC_CMD_CHAN	= 0x0020,	/* Has a Command DMA Channel */
    121      1.21      fvdl 	AHC_QUEUE_REGS	= 0x0040,	/* Has Queue management registers */
    122      1.21      fvdl 	AHC_SG_PRELOAD	= 0x0080,	/* Can perform auto-SG preload */
    123      1.21      fvdl 	AHC_SPIOCAP	= 0x0100,	/* Has a Serial Port I/O Cap Register */
    124      1.21      fvdl 	AHC_MULTI_TID	= 0x0200,	/* Has bitmask of TIDs for select-in */
    125      1.21      fvdl 	AHC_HS_MAILBOX	= 0x0400,	/* Has HS_MAILBOX register */
    126      1.21      fvdl 	AHC_DT		= 0x0800,	/* Double Transition transfers */
    127      1.21      fvdl 	AHC_NEW_TERMCTL	= 0x1000,
    128      1.21      fvdl 	AHC_MULTI_FUNC	= 0x2000,	/* Multi-Function Twin Channel Device */
    129      1.21      fvdl 	AHC_TARG_DMABUG	= 0x4000,	/* WideOdd Data-In bug in TMODE */
    130      1.21      fvdl 	AHC_AIC7770_FE	= AHC_TARG_DMABUG,
    131      1.21      fvdl 	AHC_AIC7850_FE	= AHC_TARG_DMABUG|AHC_SPIOCAP,
    132      1.21      fvdl 	AHC_AIC7855_FE	= AHC_AIC7850_FE,
    133      1.21      fvdl 	AHC_AIC7859_FE	= AHC_AIC7850_FE|AHC_ULTRA,
    134      1.21      fvdl 	AHC_AIC7860_FE	= AHC_AIC7859_FE,
    135      1.21      fvdl 	AHC_AIC7870_FE	= AHC_TARG_DMABUG,
    136      1.21      fvdl 	AHC_AIC7880_FE	= AHC_TARG_DMABUG|AHC_ULTRA,
    137      1.21      fvdl 	AHC_AIC7890_FE	= AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|AHC_QUEUE_REGS
    138      1.21      fvdl 			  |AHC_SG_PRELOAD|AHC_MULTI_TID|AHC_HS_MAILBOX
    139      1.21      fvdl 			  |AHC_NEW_TERMCTL,
    140      1.21      fvdl 	AHC_AIC7892_FE	= AHC_AIC7890_FE|AHC_DT,
    141      1.21      fvdl 	AHC_AIC7895_FE	= AHC_AIC7880_FE|AHC_MORE_SRAM
    142      1.21      fvdl 			  |AHC_CMD_CHAN|AHC_MULTI_FUNC,
    143      1.21      fvdl 	AHC_AIC7895C_FE	= AHC_AIC7895_FE|AHC_MULTI_TID,
    144      1.21      fvdl 	AHC_AIC7896_FE	= AHC_AIC7890_FE|AHC_MULTI_FUNC,
    145      1.21      fvdl 	AHC_AIC7899_FE	= AHC_AIC7892_FE|AHC_MULTI_FUNC
    146      1.21      fvdl } ahc_feature;
    147       1.4   mycroft 
    148       1.4   mycroft typedef enum {
    149      1.21      fvdl 	AHC_FNONE		= 0x000,
    150      1.21      fvdl 	AHC_PAGESCBS		= 0x001,/* Enable SCB paging */
    151      1.21      fvdl 	AHC_CHANNEL_B_PRIMARY	= 0x002,/*
    152       1.4   mycroft 					 * On twin channel adapters, probe
    153       1.4   mycroft 					 * channel B first since it is the
    154       1.4   mycroft 					 * primary bus.
    155       1.4   mycroft 					 */
    156      1.21      fvdl 	AHC_USEDEFAULTS		= 0x004,/*
    157       1.4   mycroft 					 * For cards without an seeprom
    158       1.4   mycroft 					 * or a BIOS to initialize the chip's
    159       1.4   mycroft 					 * SRAM, we use the default target
    160       1.4   mycroft 					 * settings.
    161       1.4   mycroft 					 */
    162      1.21      fvdl 	AHC_SHARED_SRAM		= 0x010,
    163      1.21      fvdl 	AHC_LARGE_SEEPROM	= 0x020,/* Uses C56_66 not C46 */
    164      1.21      fvdl 	AHC_RESET_BUS_A		= 0x040,
    165      1.21      fvdl 	AHC_RESET_BUS_B		= 0x080,
    166      1.21      fvdl 	AHC_EXTENDED_TRANS_A	= 0x100,
    167      1.21      fvdl 	AHC_EXTENDED_TRANS_B	= 0x200,
    168      1.21      fvdl 	AHC_TERM_ENB_A		= 0x400,
    169      1.21      fvdl 	AHC_TERM_ENB_B		= 0x800,
    170      1.21      fvdl 	AHC_INITIATORMODE	= 0x1000,/*
    171      1.21      fvdl 					  * Allow initiator operations on
    172      1.21      fvdl 					  * this controller.
    173      1.21      fvdl 					  */
    174      1.21      fvdl 	AHC_TARGETMODE		= 0x2000,/*
    175      1.21      fvdl 					  * Allow target operations on this
    176      1.21      fvdl 					  * controller.
    177      1.21      fvdl 					  */
    178      1.21      fvdl 	AHC_NEWEEPROM_FMT	= 0x4000,
    179      1.21      fvdl 	AHC_RESOURCE_SHORTAGE	= 0x8000,
    180      1.21      fvdl 	AHC_TQINFIFO_BLOCKED	= 0x10000,/* Blocked waiting for ATIOs */
    181  1.26.2.1   nathanw 	AHC_INT50_SPEEDFLEX	= 0x20000 /*
    182      1.21      fvdl 					   * Internal 50pin connector
    183      1.21      fvdl 					   * sits behind an aic3860
    184      1.21      fvdl 					   */
    185      1.21      fvdl } ahc_flag;
    186       1.4   mycroft 
    187       1.4   mycroft typedef enum {
    188       1.9     gibbs 	SCB_FREE		= 0x0000,
    189      1.21      fvdl 	SCB_OTHERTCL_TIMEOUT	= 0x0002,/*
    190      1.21      fvdl 					  * Another device was active
    191      1.21      fvdl 					  * during the first timeout for
    192      1.21      fvdl 					  * this SCB so we gave ourselves
    193      1.21      fvdl 					  * an additional timeout period
    194      1.21      fvdl 					  * in case it was hogging the
    195      1.21      fvdl 					  * bus.
    196      1.21      fvdl 				          */
    197       1.9     gibbs 	SCB_DEVICE_RESET	= 0x0004,
    198      1.21      fvdl 	SCB_SENSE		= 0x0008,
    199      1.21      fvdl 	SCB_FREEZE_QUEUE	= 0x0010,
    200      1.21      fvdl 	SCB_REQUEUE		= 0x0020,
    201      1.21      fvdl 	SCB_RECOVERY_SCB	= 0x0040,
    202      1.21      fvdl 	SCB_ABORT		= 0x1000,
    203      1.21      fvdl 	SCB_QUEUED_MSG		= 0x2000,
    204      1.21      fvdl 	SCB_ACTIVE		= 0x4000,
    205      1.21      fvdl 	SCB_TARGET_IMMEDIATE	= 0x8000
    206      1.21      fvdl } scb_flag;
    207      1.21      fvdl 
    208      1.21      fvdl typedef enum {
    209      1.21      fvdl 	MSGLOOP_IN_PROG,
    210      1.21      fvdl 	MSGLOOP_MSGCOMPLETE,
    211      1.21      fvdl 	MSGLOOP_TERMINATED
    212      1.21      fvdl } msg_loop_stat;
    213      1.21      fvdl 
    214      1.21      fvdl /*
    215      1.21      fvdl  * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
    216  1.26.2.2   nathanw  * consists of a "hardware SCB" mirroring the fields available on the card
    217      1.21      fvdl  * and additional information the kernel stores for each transaction.
    218       1.1   mycroft  */
    219      1.21      fvdl struct hardware_scb {
    220      1.21      fvdl /*0*/   u_int8_t  control;
    221      1.21      fvdl /*1*/	u_int8_t  tcl;		/* 4/1/3 bits */
    222      1.21      fvdl /*2*/	u_int8_t  status;
    223      1.21      fvdl /*3*/	u_int8_t  SG_count;
    224      1.21      fvdl /*4*/	u_int32_t SG_pointer;
    225      1.21      fvdl /*8*/	u_int8_t  residual_SG_count;
    226      1.21      fvdl /*9*/	u_int8_t  residual_data_count[3];
    227      1.21      fvdl /*12*/	u_int32_t data;
    228      1.21      fvdl /*16*/	u_int32_t datalen;		/* Really only three bytes, but its
    229       1.4   mycroft 					 * faster to treat it as a long on
    230       1.4   mycroft 					 * a quad boundary.
    231       1.4   mycroft 					 */
    232      1.21      fvdl /*20*/	u_int32_t cmdpointer;
    233      1.21      fvdl /*24*/	u_int8_t  cmdlen;
    234      1.21      fvdl /*25*/	u_int8_t  tag;			/* Index into our kernel SCB array.
    235       1.4   mycroft 					 * Also used as the tag for tagged I/O
    236       1.4   mycroft 					 */
    237      1.21      fvdl /*26*/	u_int8_t  next;			/* Used for threading SCBs in the
    238       1.4   mycroft 					 * "Waiting for Selection" and
    239       1.4   mycroft 					 * "Disconnected SCB" lists down
    240       1.4   mycroft 					 * in the sequencer.
    241       1.4   mycroft 					 */
    242      1.21      fvdl /*27*/	u_int8_t  scsirate;		/* Value for SCSIRATE register */
    243      1.21      fvdl /*28*/	u_int8_t  scsioffset;		/* Value for SCSIOFFSET register */
    244      1.21      fvdl /*29*/	u_int8_t  spare[3];		/*
    245      1.21      fvdl 					 * Spare space available on
    246      1.21      fvdl 					 * all controller types.
    247      1.21      fvdl 					 */
    248      1.21      fvdl /*32*/	u_int8_t  cmdstore[16];		/*
    249      1.21      fvdl 					 * CDB storage for controllers
    250      1.21      fvdl 					 * supporting 64 byte SCBs.
    251      1.21      fvdl 					 */
    252      1.21      fvdl /*48*/	u_int32_t cmdstore_busaddr;	/*
    253      1.21      fvdl 					 * Address of command store for
    254      1.21      fvdl 					 * 32byte SCB adapters
    255      1.21      fvdl 					 */
    256      1.21      fvdl /*48*/	u_int8_t  spare_64[12];		/*
    257      1.21      fvdl 					 * Pad to 64 bytes.
    258      1.21      fvdl 					 */
    259      1.21      fvdl };
    260      1.21      fvdl 
    261      1.21      fvdl struct scb {
    262      1.21      fvdl 	struct	hardware_scb	*hscb;
    263      1.21      fvdl 	SLIST_ENTRY(scb)	 links;	 /* for chaining */
    264      1.21      fvdl 	LIST_ENTRY(scb)	 	plinks; /* pending chain */
    265      1.21      fvdl 	struct scsipi_xfer	*xs;
    266      1.21      fvdl 	scb_flag		 flags;
    267      1.21      fvdl 	bus_dmamap_t		 dmamap;
    268      1.21      fvdl 	struct	ahc_dma_seg 	*sg_list;
    269      1.21      fvdl 	bus_addr_t		 sg_list_phys;
    270      1.21      fvdl 	u_int			 sg_count;/* How full ahc_dma_seg is */
    271      1.21      fvdl };
    272      1.21      fvdl 
    273      1.21      fvdl /*
    274      1.21      fvdl  * Connection desciptor for select-in requests in target mode.
    275      1.21      fvdl  * The first byte is the connecting target, followed by identify
    276      1.21      fvdl  * message and optional tag information, terminated by 0xFF.  The
    277      1.21      fvdl  * remainder is the command to execute.  The cmd_valid byte is on
    278      1.21      fvdl  * an 8 byte boundary to simplify setting it on aic7880 hardware
    279      1.21      fvdl  * which only has limited direct access to the DMA FIFO.
    280      1.21      fvdl  */
    281      1.21      fvdl struct target_cmd {
    282      1.21      fvdl 	u_int8_t initiator_channel;
    283      1.21      fvdl 	u_int8_t targ_id;	/* Target ID we were selected at */
    284      1.21      fvdl 	u_int8_t identify;	/* Identify message */
    285      1.21      fvdl 	u_int8_t bytes[21];
    286      1.21      fvdl 	u_int8_t cmd_valid;
    287      1.21      fvdl 	u_int8_t pad[7];
    288      1.21      fvdl };
    289      1.21      fvdl 
    290      1.21      fvdl /*
    291      1.21      fvdl  * Number of events we can buffer up if we run out
    292      1.21      fvdl  * of immediate notify ccbs.
    293      1.21      fvdl  */
    294      1.21      fvdl #define AHC_TMODE_EVENT_BUFFER_SIZE 8
    295      1.21      fvdl struct ahc_tmode_event {
    296      1.21      fvdl 	u_int8_t initiator_id;
    297      1.21      fvdl 	u_int8_t event_type;	/* MSG type or EVENT_TYPE_BUS_RESET */
    298      1.21      fvdl #define	EVENT_TYPE_BUS_RESET 0xFF
    299      1.21      fvdl 	u_int8_t event_arg;
    300      1.21      fvdl };
    301      1.21      fvdl 
    302      1.21      fvdl /*
    303      1.21      fvdl  * Per lun target mode state including accept TIO CCB
    304      1.21      fvdl  * and immediate notify CCB pools.
    305      1.21      fvdl  */
    306      1.21      fvdl struct tmode_lstate {
    307      1.21      fvdl #ifdef maybe_later
    308      1.21      fvdl 	struct cam_path *path;
    309      1.21      fvdl 	struct ccb_hdr_slist accept_tios;
    310      1.21      fvdl 	struct ccb_hdr_slist immed_notifies;
    311      1.21      fvdl 	struct ahc_tmode_event event_buffer[AHC_TMODE_EVENT_BUFFER_SIZE];
    312      1.21      fvdl 	u_int8_t event_r_idx;
    313      1.21      fvdl 	u_int8_t event_w_idx;
    314      1.21      fvdl #else
    315      1.21      fvdl 	u_int8_t dummy;
    316      1.21      fvdl #endif
    317      1.21      fvdl };
    318      1.21      fvdl 
    319      1.21      fvdl #define AHC_TRANS_CUR		0x01	/* Modify current neogtiation status */
    320      1.21      fvdl #define AHC_TRANS_ACTIVE	0x03	/* Assume this is the active target */
    321      1.21      fvdl #define AHC_TRANS_GOAL		0x04	/* Modify negotiation goal */
    322      1.21      fvdl #define AHC_TRANS_USER		0x08	/* Modify user negotiation settings */
    323      1.21      fvdl 
    324      1.21      fvdl struct ahc_transinfo {
    325      1.21      fvdl 	u_int8_t width;
    326      1.21      fvdl 	u_int8_t period;
    327      1.21      fvdl 	u_int8_t offset;
    328      1.21      fvdl 	u_int8_t ppr_flags;
    329      1.21      fvdl };
    330      1.21      fvdl 
    331      1.21      fvdl struct ahc_initiator_tinfo {
    332      1.21      fvdl 	u_int8_t scsirate;
    333      1.21      fvdl 	struct ahc_transinfo current;
    334      1.21      fvdl 	struct ahc_transinfo goal;
    335      1.21      fvdl 	struct ahc_transinfo user;
    336      1.21      fvdl };
    337      1.21      fvdl 
    338      1.21      fvdl /*
    339      1.21      fvdl  * Per target mode enabled target state.  Esentially just an array of
    340      1.21      fvdl  * pointers to lun target state as well as sync/wide negotiation information
    341      1.21      fvdl  * for each initiator<->target mapping (including the mapping for when we
    342      1.21      fvdl  * are the initiator).
    343      1.21      fvdl  */
    344      1.21      fvdl struct tmode_tstate {
    345      1.21      fvdl #if 0
    346      1.21      fvdl 	struct tmode_lstate*		enabled_luns[8];
    347      1.21      fvdl #endif
    348      1.21      fvdl 	struct ahc_initiator_tinfo	transinfo[16];
    349      1.15       leo 
    350      1.15       leo 	/*
    351      1.21      fvdl 	 * Per initiator state bitmasks.
    352      1.15       leo 	 */
    353      1.21      fvdl 	u_int16_t		 ultraenb;	/* Using ultra sync rate  */
    354      1.21      fvdl 	u_int16_t	 	 discenable;	/* Disconnection allowed  */
    355      1.21      fvdl 	u_int16_t		 tagenable;	/* Tagged Queuing allowed */
    356  1.26.2.3   nathanw 	u_int16_t		 tagdisable;	/* TQ explicitly disallowed */
    357      1.21      fvdl };
    358      1.21      fvdl 
    359      1.21      fvdl #define AHC_TARGET_WILDCARD -1
    360      1.21      fvdl #define AHC_LUN_WILDCARD -1
    361      1.15       leo 
    362      1.21      fvdl /*
    363      1.21      fvdl  * XXX translate FreeBSD SCSI status byte values to NetBSD, and define
    364      1.21      fvdl  * a few more.
    365      1.21      fvdl  */
    366      1.21      fvdl #define SCSI_STATUS_OK			SCSI_OK
    367      1.21      fvdl #define SCSI_STATUS_CHECK_COND		SCSI_CHECK
    368      1.21      fvdl #define SCSI_STATUS_COND_MET		0x04
    369      1.21      fvdl #define SCSI_STATUS_BUSY		SCSI_BUSY
    370      1.21      fvdl #define SCSI_STATUS_INTERMED		SCSI_INTERM
    371      1.21      fvdl #define SCSI_STATUS_INTERMED_COND_MET	0x14
    372      1.21      fvdl #define SCSI_STATUS_RESERV_CONFLICT	0x18
    373      1.21      fvdl #define SCSI_STATUS_CMD_TERMINATED	0x22
    374      1.21      fvdl #define SCSI_STATUS_QUEUE_FULL		SCSI_QUEUE_FULL
    375      1.21      fvdl 
    376      1.21      fvdl /*
    377      1.21      fvdl  * Define the format of the aic7XXX SEEPROM registers (16 bits).
    378      1.21      fvdl  */
    379      1.21      fvdl 
    380      1.21      fvdl struct seeprom_config {
    381      1.21      fvdl /*
    382      1.21      fvdl  * SCSI ID Configuration Flags
    383      1.21      fvdl  */
    384      1.21      fvdl 	u_int16_t device_flags[16];	/* words 0-15 */
    385      1.21      fvdl #define		CFXFER		0x0007	/* synchronous transfer rate */
    386      1.21      fvdl #define		CFSYNCH		0x0008	/* enable synchronous transfer */
    387      1.21      fvdl #define		CFDISC		0x0010	/* enable disconnection */
    388      1.21      fvdl #define		CFWIDEB		0x0020	/* wide bus device */
    389      1.21      fvdl #define		CFSYNCHISULTRA	0x0040	/* CFSYNCH is an ultra offset (2940AU)*/
    390      1.21      fvdl #define		CFSYNCSINGLE	0x0080	/* Single-Transition signalling */
    391      1.21      fvdl #define		CFSTART		0x0100	/* send start unit SCSI command */
    392      1.21      fvdl #define		CFINCBIOS	0x0200	/* include in BIOS scan */
    393      1.21      fvdl #define		CFRNFOUND	0x0400	/* report even if not found */
    394      1.21      fvdl #define		CFMULTILUN	0x0800	/* Probe multiple luns in BIOS scan */
    395      1.21      fvdl #define		CFWBCACHEENB	0x4000	/* Enable W-Behind Cache on disks */
    396      1.21      fvdl #define		CFWBCACHENOP	0xc000	/* Don't touch W-Behind Cache */
    397      1.21      fvdl 
    398      1.21      fvdl /*
    399      1.21      fvdl  * BIOS Control Bits
    400      1.21      fvdl  */
    401      1.21      fvdl 	u_int16_t bios_control;		/* word 16 */
    402      1.21      fvdl #define		CFSUPREM	0x0001	/* support all removeable drives */
    403      1.21      fvdl #define		CFSUPREMB	0x0002	/* support removeable boot drives */
    404      1.21      fvdl #define		CFBIOSEN	0x0004	/* BIOS enabled */
    405      1.21      fvdl /*		UNUSED		0x0008	*/
    406      1.21      fvdl #define		CFSM2DRV	0x0010	/* support more than two drives */
    407      1.21      fvdl #define		CF284XEXTEND	0x0020	/* extended translation (284x cards) */
    408      1.21      fvdl /*		UNUSED		0x0040	*/
    409      1.21      fvdl #define		CFEXTEND	0x0080	/* extended translation enabled */
    410      1.21      fvdl /*		UNUSED		0xff00	*/
    411      1.21      fvdl 
    412      1.21      fvdl /*
    413      1.21      fvdl  * Host Adapter Control Bits
    414      1.21      fvdl  */
    415      1.21      fvdl 	u_int16_t adapter_control;	/* word 17 */
    416      1.21      fvdl #define		CFAUTOTERM	0x0001	/* Perform Auto termination */
    417      1.21      fvdl #define		CFULTRAEN	0x0002	/* Ultra SCSI speed enable */
    418      1.21      fvdl #define		CF284XSELTO     0x0003	/* Selection timeout (284x cards) */
    419      1.21      fvdl #define		CF284XFIFO      0x000C	/* FIFO Threshold (284x cards) */
    420      1.21      fvdl #define		CFSTERM		0x0004	/* SCSI low byte termination */
    421      1.21      fvdl #define		CFWSTERM	0x0008	/* SCSI high byte termination */
    422      1.21      fvdl #define		CFSPARITY	0x0010	/* SCSI parity */
    423      1.21      fvdl #define		CF284XSTERM     0x0020	/* SCSI low byte term (284x cards) */
    424      1.21      fvdl #define		CFRESETB	0x0040	/* reset SCSI bus at boot */
    425      1.21      fvdl #define		CFCHNLBPRIMARY	0x0100	/* aic7895 probe B channel first */
    426      1.21      fvdl #define		CFSEAUTOTERM	0x0400	/* aic7890 Perform SE Auto Termination*/
    427      1.21      fvdl #define		CFLVDSTERM	0x0800	/* aic7890 LVD Termination */
    428      1.21      fvdl /*		UNUSED		0xf280	*/
    429      1.21      fvdl 
    430      1.21      fvdl /*
    431      1.21      fvdl  * Bus Release, Host Adapter ID
    432      1.21      fvdl  */
    433      1.21      fvdl 	u_int16_t brtime_id;		/* word 18 */
    434      1.21      fvdl #define		CFSCSIID	0x000f	/* host adapter SCSI ID */
    435      1.21      fvdl /*		UNUSED		0x00f0	*/
    436      1.21      fvdl #define		CFBRTIME	0xff00	/* bus release time */
    437      1.21      fvdl 
    438      1.21      fvdl /*
    439      1.21      fvdl  * Maximum targets
    440      1.21      fvdl  */
    441      1.21      fvdl 	u_int16_t max_targets;		/* word 19 */
    442      1.21      fvdl #define		CFMAXTARG	0x00ff	/* maximum targets */
    443      1.21      fvdl /*		UNUSED		0xff00	*/
    444      1.21      fvdl 	u_int16_t res_1[11];		/* words 20-30 */
    445      1.21      fvdl 	u_int16_t checksum;		/* word 31 */
    446      1.21      fvdl };
    447      1.21      fvdl 
    448      1.21      fvdl struct ahc_syncrate {
    449      1.21      fvdl 	int sxfr_u2;
    450      1.21      fvdl 	int sxfr;
    451      1.21      fvdl 	/* Rates in Ultra mode have bit 8 of sxfr set */
    452      1.21      fvdl #define		ULTRA_SXFR 0x100
    453      1.21      fvdl #define		ST_SXFR	   0x010
    454      1.21      fvdl 	u_int8_t period; /* Period to send to SCSI target */
    455      1.21      fvdl 	char *rate;
    456      1.21      fvdl };
    457      1.21      fvdl 
    458      1.21      fvdl typedef enum {
    459      1.21      fvdl 	MSG_TYPE_NONE			= 0x00,
    460      1.21      fvdl 	MSG_TYPE_INITIATOR_MSGOUT	= 0x01,
    461      1.21      fvdl 	MSG_TYPE_INITIATOR_MSGIN	= 0x02,
    462      1.21      fvdl 	MSG_TYPE_TARGET_MSGOUT		= 0x03,
    463      1.21      fvdl 	MSG_TYPE_TARGET_MSGIN		= 0x04
    464      1.21      fvdl } ahc_msg_type;
    465      1.21      fvdl 
    466      1.21      fvdl struct sg_map_node {
    467      1.21      fvdl 	bus_dmamap_t		 sg_dmamap;
    468      1.21      fvdl 	bus_addr_t		 sg_physaddr;
    469      1.21      fvdl 	bus_dma_segment_t	 sg_dmasegs;
    470      1.21      fvdl 	int			 sg_nseg;
    471      1.21      fvdl 	struct ahc_dma_seg*	 sg_vaddr;
    472      1.21      fvdl 	SLIST_ENTRY(sg_map_node) links;
    473      1.21      fvdl };
    474      1.21      fvdl 
    475      1.21      fvdl struct scb_data {
    476      1.21      fvdl 	struct	hardware_scb	*hscbs;	    /* Array of hardware SCBs */
    477      1.21      fvdl 	struct	scb *scbarray;		    /* Array of kernel SCBs */
    478      1.21      fvdl 	SLIST_HEAD(, scb) free_scbs;	/*
    479      1.21      fvdl 					 * Pool of SCBs ready to be assigned
    480      1.21      fvdl 					 * commands to execute.
    481      1.21      fvdl 					 */
    482      1.21      fvdl 	struct	scsipi_sense_data *sense; /* Per SCB sense data */
    483      1.21      fvdl 
    484      1.21      fvdl 	/*
    485      1.21      fvdl 	 * "Bus" addresses of our data structures.
    486      1.21      fvdl 	 */
    487      1.21      fvdl 	bus_dmamap_t	  hscb_dmamap;
    488      1.21      fvdl 	bus_addr_t	  hscb_busaddr;
    489      1.21      fvdl 	bus_dma_segment_t hscb_seg;
    490      1.21      fvdl 	int		  hscb_nseg;
    491      1.21      fvdl 	int		  hscb_size;
    492      1.21      fvdl 
    493      1.21      fvdl 	bus_dmamap_t	  sense_dmamap;
    494      1.21      fvdl 	bus_addr_t	  sense_busaddr;
    495      1.21      fvdl 	bus_dma_segment_t sense_seg;
    496      1.21      fvdl 	int		  sense_nseg;
    497      1.21      fvdl 	int		  sense_size;
    498      1.21      fvdl 
    499      1.21      fvdl 	SLIST_HEAD(, sg_map_node) sg_maps;
    500      1.21      fvdl 	u_int8_t	  numscbs;
    501      1.21      fvdl 	u_int8_t	  maxhscbs;	/* Number of SCBs on the card */
    502      1.21      fvdl 	u_int8_t	  init_level;	/*
    503      1.21      fvdl 					 * How far we've initialized
    504      1.21      fvdl 					 * this structure.
    505      1.21      fvdl 					 */
    506       1.1   mycroft };
    507       1.1   mycroft 
    508      1.21      fvdl struct ahc_softc {
    509      1.21      fvdl 	struct device		sc_dev;
    510      1.21      fvdl 
    511  1.26.2.1   nathanw 	struct  scsipi_channel sc_channel;
    512  1.26.2.1   nathanw 	struct  scsipi_channel sc_channel_b;
    513      1.21      fvdl 	struct  scsipi_adapter sc_adapter;
    514      1.21      fvdl 
    515      1.21      fvdl 	bus_space_tag_t		 tag;
    516      1.21      fvdl 	bus_space_handle_t	 bsh;
    517      1.21      fvdl 	struct scb_data		*scb_data;
    518      1.21      fvdl 
    519      1.21      fvdl #define AHC_NEG_PENDING		0x01
    520      1.21      fvdl #define AHC_NEG_SDTRDONE	0x02
    521      1.21      fvdl #define AHC_NEG_WDTRDONE	0x04
    522      1.21      fvdl 	u_int8_t		inited_targets[16];
    523      1.24      fvdl 	u_int8_t		inited_channels[2];
    524      1.21      fvdl 
    525  1.26.2.3   nathanw 	struct device		*child;
    526  1.26.2.3   nathanw 
    527      1.21      fvdl 	/*
    528      1.21      fvdl 	 * SCBs that have been send to the controller
    529      1.21      fvdl 	 */
    530      1.21      fvdl 	LIST_HEAD(, scb) pending_ccbs;
    531      1.21      fvdl 
    532      1.21      fvdl 	/*
    533      1.21      fvdl 	 * Target mode related state kept on a per enabled lun basis.
    534      1.21      fvdl 	 * Targets that are not enabled will have null entries.
    535      1.21      fvdl 	 * As an initiator, we keep one target entry for our initiator
    536      1.21      fvdl 	 * ID to store our sync/wide transfer settings.
    537      1.21      fvdl 	 */
    538      1.21      fvdl 	struct tmode_tstate*	 enabled_targets[16];
    539      1.21      fvdl 
    540      1.21      fvdl 	/*
    541      1.21      fvdl 	 * The black hole device responsible for handling requests for
    542      1.21      fvdl 	 * disabled luns on enabled targets.
    543      1.21      fvdl 	 */
    544      1.21      fvdl 	struct tmode_lstate*	 black_hole;
    545      1.21      fvdl 
    546      1.21      fvdl 	/*
    547      1.21      fvdl 	 * Device instance currently on the bus awaiting a continue TIO
    548      1.21      fvdl 	 * for a command that was not given the disconnect priveledge.
    549      1.21      fvdl 	 */
    550      1.21      fvdl 	struct tmode_lstate*	 pending_device;
    551      1.21      fvdl 
    552      1.21      fvdl 	/*
    553      1.21      fvdl 	 * Card characteristics
    554      1.21      fvdl 	 */
    555      1.21      fvdl 	ahc_chip		 chip;
    556      1.21      fvdl 	ahc_feature		 features;
    557      1.21      fvdl 	ahc_flag		 flags;
    558      1.21      fvdl 
    559      1.21      fvdl 	/* Values to store in the SEQCTL register for pause and unpause */
    560      1.21      fvdl 	u_int8_t		 unpause;
    561      1.21      fvdl 	u_int8_t		 pause;
    562      1.21      fvdl 
    563      1.21      fvdl 	/* Command Queues */
    564      1.21      fvdl 	u_int8_t		 qoutfifonext;
    565      1.21      fvdl 	u_int8_t		 qinfifonext;
    566      1.21      fvdl 	u_int8_t		*qoutfifo;
    567      1.21      fvdl 	u_int8_t		*qinfifo;
    568      1.21      fvdl 
    569      1.21      fvdl 	/*
    570      1.21      fvdl 	 * 256 byte array storing the SCBID of outstanding
    571      1.21      fvdl 	 * untagged SCBs indexed by TCL.
    572      1.21      fvdl 	 */
    573      1.21      fvdl 	u_int8_t		 *untagged_scbs;
    574      1.21      fvdl 
    575      1.21      fvdl 	/* Channel Names ('A', 'B', etc.) */
    576      1.21      fvdl 	char			 channel;
    577      1.21      fvdl 	char			 channel_b;
    578      1.21      fvdl 
    579      1.21      fvdl 	/* Initiator Bus ID */
    580      1.21      fvdl 	u_int8_t		 our_id;
    581      1.21      fvdl 	u_int8_t		 our_id_b;
    582      1.21      fvdl 
    583      1.21      fvdl 	/* Targets that need negotiation messages */
    584      1.21      fvdl 	u_int16_t		 targ_msg_req;
    585      1.21      fvdl 
    586      1.21      fvdl 	/*
    587      1.21      fvdl 	 * PCI error detection and data for running the
    588      1.21      fvdl 	 * PCI error interrupt handler.
    589      1.21      fvdl 	 */
    590      1.21      fvdl 	int			 unsolicited_ints;
    591      1.21      fvdl 
    592      1.21      fvdl 	/*
    593      1.21      fvdl 	 * Target incoming command FIFO.
    594      1.21      fvdl 	 */
    595      1.21      fvdl 	struct target_cmd	*targetcmds;
    596      1.21      fvdl 	u_int8_t		 tqinfifonext;
    597      1.21      fvdl 
    598      1.21      fvdl 	/*
    599      1.21      fvdl 	 * Incoming and outgoing message handling.
    600      1.21      fvdl 	 */
    601      1.21      fvdl 	u_int8_t		 send_msg_perror;
    602      1.21      fvdl 	ahc_msg_type		 msg_type;
    603      1.21      fvdl 	u_int8_t		 msgout_buf[8];	/* Message we are sending */
    604      1.21      fvdl 	u_int8_t		 msgin_buf[8];	/* Message we are receiving */
    605      1.21      fvdl 	u_int			 msgout_len;	/* Length of message to send */
    606      1.21      fvdl 	u_int			 msgout_index;	/* Current index in msgout */
    607      1.21      fvdl 	u_int			 msgin_index;	/* Current index in msgin */
    608      1.21      fvdl 
    609      1.21      fvdl 	void			*ih;
    610      1.21      fvdl 	bus_dma_tag_t		 parent_dmat;
    611      1.21      fvdl 	int			 sc_dmaflags;
    612      1.21      fvdl 	bus_dmamap_t		 shared_data_dmamap;
    613      1.21      fvdl 	bus_addr_t		 shared_data_busaddr;
    614      1.21      fvdl 	bus_dma_segment_t	 shared_data_seg;
    615      1.21      fvdl 	int			 shared_data_nseg;
    616      1.21      fvdl 	int			 shared_data_size;
    617      1.21      fvdl 	bus_addr_t		 dma_bug_buf;
    618      1.21      fvdl 
    619      1.21      fvdl 	/* Number of enabled target mode device on this card */
    620      1.21      fvdl 	u_int			 enabled_luns;
    621      1.21      fvdl 
    622      1.21      fvdl 	/* Initialization level of this data structure */
    623      1.21      fvdl 	u_int			 init_level;
    624      1.21      fvdl 
    625      1.21      fvdl 	u_int16_t	 	 user_discenable;/* Disconnection allowed  */
    626      1.21      fvdl 	u_int16_t		 user_tagenable;/* Tagged Queuing allowed */
    627      1.21      fvdl 
    628      1.21      fvdl 	void			*bus_data;
    629      1.22      fvdl 	int			(*bus_intr)(struct ahc_softc *);
    630      1.21      fvdl };
    631      1.21      fvdl 
    632      1.21      fvdl struct full_ahc_softc {
    633      1.21      fvdl 	struct ahc_softc softc;
    634      1.21      fvdl 	struct scb_data  scb_data_storage;
    635       1.1   mycroft };
    636       1.4   mycroft 
    637      1.21      fvdl /* #define AHC_DEBUG 0x019f */
    638      1.21      fvdl 
    639       1.4   mycroft #ifdef AHC_DEBUG
    640       1.4   mycroft /* Different debugging levels used when AHC_DEBUG is defined */
    641      1.21      fvdl #define AHC_SHOWMISC		0x0001
    642      1.21      fvdl #define AHC_SHOWCMDS		0x0002
    643      1.21      fvdl #define AHC_SHOWSCBS		0x0004
    644      1.21      fvdl #define AHC_SHOWABORTS		0x0008
    645      1.21      fvdl #define AHC_SHOWSENSE		0x0010
    646      1.21      fvdl #define AHC_SHOWSCBCNT		0x0020
    647      1.21      fvdl #define AHC_SHOWSCBALLOC	0x0040
    648      1.21      fvdl #define AHC_SHOWINTR		0x0080
    649      1.21      fvdl #define AHC_SHOWMSG		0x0100
    650       1.4   mycroft 
    651       1.4   mycroft extern int ahc_debug; /* Initialized in i386/scsi/aic7xxx.c */
    652       1.4   mycroft #endif
    653       1.4   mycroft 
    654      1.21      fvdl char *ahc_name(struct ahc_softc *ahc);
    655      1.21      fvdl 
    656      1.21      fvdl int	ahc_alloc(struct ahc_softc *ahc, bus_space_handle_t sh,
    657      1.21      fvdl 		  bus_space_tag_t st, bus_dma_tag_t parent_dmat,
    658      1.21      fvdl 		  ahc_chip chip, ahc_feature features, ahc_flag flags);
    659      1.21      fvdl int	ahc_reset(struct ahc_softc *ahc);
    660      1.21      fvdl void	ahc_free(struct ahc_softc *);
    661      1.21      fvdl int	ahc_probe_scbs(struct ahc_softc *);
    662      1.21      fvdl int	ahc_init(struct ahc_softc *);
    663      1.21      fvdl int	ahc_attach(struct ahc_softc *);
    664  1.26.2.3   nathanw int	ahc_detach(struct ahc_softc *, int);
    665  1.26.2.3   nathanw int	ahc_activate(struct device *, enum devact);
    666      1.21      fvdl int	ahc_intr(void *arg);
    667      1.21      fvdl 
    668      1.21      fvdl /*
    669      1.21      fvdl  * SEEPROM related functions.
    670      1.21      fvdl  */
    671      1.21      fvdl void	check_extport(struct ahc_softc *ahc, u_int *sxfrctl1);
    672       1.4   mycroft 
    673       1.4   mycroft 
    674      1.21      fvdl #define ahc_inb(ahc, port)				\
    675      1.21      fvdl 	bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
    676       1.4   mycroft 
    677      1.21      fvdl #define ahc_outb(ahc, port, value)			\
    678      1.21      fvdl 	bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
    679       1.4   mycroft 
    680      1.21      fvdl #define ahc_outsb(ahc, port, valp, count)		\
    681      1.21      fvdl 	bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
    682      1.20   thorpej 
    683      1.21      fvdl #define ahc_insb(ahc, port, valp, count)		\
    684      1.21      fvdl 	bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
    685       1.1   mycroft 
    686       1.1   mycroft #endif  /* _AIC7XXX_H_ */
    687