1 /* $NetBSD: ispvar.h,v 1.7 1997/08/27 11:24:56 bouyer Exp $ */ 2 3 /* 4 * Soft Definitions for for Qlogic ISP SCSI adapters. 5 * 6 * Copyright (c) 1997 by Matthew Jacob 7 * NASA/Ames Research Center 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice immediately at the beginning of the file, without modification, 15 * this list of conditions, and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #ifndef _ISPVAR_H 36 #define _ISPVAR_H 37 38 #include <dev/ic/ispmbox.h> 39 40 /* 41 * Vector for MD code to provide specific services. 42 */ 43 struct ispsoftc; 44 struct ispmdvec { 45 u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int)); 46 void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t)); 47 int (*dv_mbxdma) __P((struct ispsoftc *)); 48 int (*dv_dmaset) __P((struct ispsoftc *, 49 struct scsipi_xfer *, ispreq_t *, u_int8_t *, u_int8_t)); 50 void (*dv_dmaclr) 51 __P((struct ispsoftc *, struct scsipi_xfer *, u_int32_t)); 52 void (*dv_reset0) __P((struct ispsoftc *)); 53 void (*dv_reset1) __P((struct ispsoftc *)); 54 void (*dv_dregs) __P((struct ispsoftc *)); 55 const u_int16_t *dv_ispfw; /* ptr to f/w */ 56 u_int16_t dv_fwlen; /* length of f/w */ 57 u_int16_t dv_codeorg; /* code ORG for f/w */ 58 u_int16_t dv_fwrev; /* f/w revision */ 59 /* 60 * Initial values for conf1 register 61 */ 62 u_int16_t dv_conf1; 63 u_int16_t dv_clock; /* clock frequency */ 64 }; 65 66 #define MAX_TARGETS 16 67 #define MAX_LUNS 8 68 #define MAX_FC_TARG 126 69 70 #define MAXISPREQUEST 256 71 #define RQUEST_QUEUE_LEN(isp) MAXISPREQUEST 72 #define RESULT_QUEUE_LEN(isp) (RQUEST_QUEUE_LEN(isp) >> 2) 73 #define QENTRY_LEN 64 74 75 #define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN)) 76 #define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN) 77 78 /* 79 * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters 80 */ 81 82 typedef struct { 83 u_int16_t isp_adapter_enabled : 1, 84 isp_req_ack_active_neg : 1, 85 isp_data_line_active_neg: 1, 86 isp_cmd_dma_burst_enable: 1, 87 isp_data_dma_burst_enabl: 1, 88 isp_fifo_threshold : 2, 89 isp_diffmode : 1, 90 isp_initiator_id : 4, 91 isp_async_data_setup : 4; 92 u_int16_t isp_selection_timeout; 93 u_int16_t isp_max_queue_depth; 94 u_int16_t isp_clock; 95 u_int8_t isp_tag_aging; 96 u_int8_t isp_bus_reset_delay; 97 u_int8_t isp_retry_count; 98 u_int8_t isp_retry_delay; 99 struct { 100 u_int8_t dev_flags; /* Device Flags - see below */ 101 u_int8_t exc_throttle; 102 u_int8_t sync_period; 103 u_int8_t sync_offset : 4, 104 dev_enable : 1; 105 } isp_devparam[MAX_TARGETS]; 106 } sdparam; /* scsi device parameters */ 107 108 /* 109 * Device Flags 110 */ 111 #define DPARM_DISC 0x80 112 #define DPARM_PARITY 0x40 113 #define DPARM_WIDE 0x20 114 #define DPARM_SYNC 0x10 115 #define DPARM_TQING 0x08 116 #define DPARM_ARQ 0x04 117 #define DPARM_QFRZ 0x02 118 #define DPARM_RENEG 0x01 119 #define DPARM_DEFAULT (0xff & ~DPARM_QFRZ) 120 121 #define ISP_20M_SYNCPARMS 0x080c 122 #define ISP_10M_SYNCPARMS 0x0c19 123 #define ISP_08M_SYNCPARMS 0x0c25 124 #define ISP_05M_SYNCPARMS 0x0c32 125 #define ISP_04M_SYNCPARMS 0x0c41 126 127 /* 128 * Fibre Channel Specifics 129 */ 130 typedef struct { 131 u_int64_t isp_wwn; /* WWN of adapter */ 132 u_int8_t isp_loopid; /* FCAL of this adapter inst */ 133 u_int8_t isp_retry_count; 134 u_int8_t isp_retry_delay; 135 u_int8_t isp_fwstate; /* ISP F/W state */ 136 137 /* 138 * Scratch DMA mapped in area to fetch Port Database stuff, etc. 139 */ 140 volatile caddr_t isp_scratch; 141 u_int32_t isp_scdma; 142 } fcparam; 143 144 #define ISP2100_SCRLEN 0x100 145 146 #define FW_CONFIG_WAIT 0x0000 147 #define FW_WAIT_AL_PA 0x0001 148 #define FW_WAIT_LOGIN 0x0002 149 #define FW_READY 0x0003 150 #define FW_LOSS_OF_SYNC 0x0004 151 #define FW_ERROR 0x0005 152 #define FW_REINIT 0x0006 153 #define FW_NON_PART 0x0007 154 155 /* 156 * Soft Structure per host adapter 157 */ 158 struct ispsoftc { 159 struct device isp_dev; 160 struct ispmdvec * isp_mdvec; 161 #define isp_name isp_dev.dv_xname 162 struct scsipi_link isp_link; 163 u_int8_t isp_state; 164 int8_t isp_dblev; 165 u_int16_t isp_fwrev; 166 167 /* 168 * Host Adapter Type and Parameters. 169 * Some parameters nominally stored in NVRAM on card. 170 */ 171 u_int8_t isp_type; 172 void * isp_param; 173 174 /* 175 * Result and Request Queues. 176 */ 177 volatile u_int8_t isp_reqidx; /* index of next request */ 178 volatile u_int8_t isp_residx; /* index of next result */ 179 volatile u_int8_t isp_sendmarker; 180 volatile u_int8_t isp_seqno; 181 182 /* 183 * Sheer laziness, but it gets us around the problem 184 * where we don't have a clean way of remembering 185 * which scsipi_xfer is bound to which ISP queue entry. 186 * 187 * There are other more clever ways to do this, but, 188 * jeez, so I blow a couple of KB per host adapter... 189 * and it *is* faster. 190 */ 191 volatile struct scsipi_xfer *isp_xflist[MAXISPREQUEST]; 192 193 /* 194 * request/result queues 195 */ 196 volatile caddr_t isp_rquest; 197 volatile caddr_t isp_result; 198 u_int32_t isp_rquest_dma; 199 u_int32_t isp_result_dma; 200 }; 201 202 /* 203 * Adapter Variants 204 */ 205 #define ISP_HA_SCSI 0xf 206 #define ISP_HA_SCSI_UNKNOWN 0x0 207 #define ISP_HA_SCSI_1020 0x1 208 #define ISP_HA_SCSI_1040A 0x2 209 #define ISP_HA_SCSI_1040B 0x3 210 #define ISP_HA_FC 0xf0 211 #define ISP_HA_FC_2100 0x10 212 213 /* 214 * ISP States 215 */ 216 #define ISP_NILSTATE 0 217 #define ISP_RESETSTATE 1 218 #define ISP_INITSTATE 2 219 #define ISP_RUNSTATE 3 220 221 222 223 224 /* 225 * Macros to read, write ISP registers through MD code 226 */ 227 228 #define ISP_READ(isp, reg) \ 229 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg)) 230 231 #define ISP_WRITE(isp, reg, val) \ 232 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val)) 233 234 #define ISP_MBOXDMASETUP(isp) \ 235 (*(isp)->isp_mdvec->dv_mbxdma)((isp)) 236 237 #define ISP_DMASETUP(isp, xs, req, iptrp, optr) \ 238 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr)) 239 240 #define ISP_DMAFREE(isp, xs, seqno) \ 241 if ((isp)->isp_mdvec->dv_dmaclr) \ 242 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno)) 243 244 #define ISP_RESET0(isp) \ 245 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp)) 246 #define ISP_RESET1(isp) \ 247 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp)) 248 #define ISP_DUMPREGS(isp) \ 249 if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp)) 250 251 #define ISP_SETBITS(isp, reg, val) \ 252 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val)) 253 254 #define ISP_CLRBITS(isp, reg, val) \ 255 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val)) 256 257 /* 258 * Function Prototypes 259 */ 260 /* 261 * Reset Hardware. 262 * 263 * Only looks at sc_dev.dv_xname, sc_iot and sc_ioh fields. 264 */ 265 void isp_reset __P((struct ispsoftc *)); 266 267 /* 268 * Initialize Hardware to known state 269 */ 270 void isp_init __P((struct ispsoftc *)); 271 272 /* 273 * Complete attachment of Hardware 274 */ 275 void isp_attach __P((struct ispsoftc *)); 276 277 /* 278 * Free any associated resources prior to decommissioning. 279 */ 280 void isp_uninit __P((struct ispsoftc *)); 281 282 /* 283 * Interrupt Service Routine 284 */ 285 int isp_intr __P((void *)); 286 287 288 289 290 #endif /* _ISPVAR_H */ 291