ispvar.h revision 35597
1/* $Id: ispvar.h,v 1.1 1998/04/22 17:54:58 mjacob Exp $ */ 2/* 3 * Soft Definitions for for Qlogic ISP SCSI adapters. 4 * 5 *--------------------------------------- 6 * Copyright (c) 1997, 1998 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 36#ifndef _ISPVAR_H 37#define _ISPVAR_H 38 39#ifdef __NetBSD__ 40#include <dev/ic/ispmbox.h> 41#endif 42#ifdef __FreeBSD__ 43#include <dev/isp/ispmbox.h> 44#endif 45#ifdef __linux__ 46#include <ispmbox.h> 47#endif 48 49/* 50 * Vector for MD code to provide specific services. 51 */ 52struct ispsoftc; 53struct ispmdvec { 54 u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int)); 55 void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t)); 56 int (*dv_mbxdma) __P((struct ispsoftc *)); 57 int (*dv_dmaset) __P((struct ispsoftc *, 58 ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t)); 59 void (*dv_dmaclr) 60 __P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t)); 61 void (*dv_reset0) __P((struct ispsoftc *)); 62 void (*dv_reset1) __P((struct ispsoftc *)); 63 void (*dv_dregs) __P((struct ispsoftc *)); 64 const u_int16_t *dv_ispfw; /* ptr to f/w */ 65 u_int16_t dv_fwlen; /* length of f/w */ 66 u_int16_t dv_codeorg; /* code ORG for f/w */ 67 u_int16_t dv_fwrev; /* f/w revision */ 68 /* 69 * Initial values for conf1 register 70 */ 71 u_int16_t dv_conf1; 72 u_int16_t dv_clock; /* clock frequency */ 73}; 74 75#define MAX_TARGETS 16 76#define MAX_LUNS 8 77#define MAX_FC_TARG 126 78 79#define RQUEST_QUEUE_LEN(isp) MAXISPREQUEST 80#define RESULT_QUEUE_LEN(isp) (MAXISPREQUEST/4) 81 82#define QENTRY_LEN 64 83 84#define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN)) 85#define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN) 86 87/* 88 * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters 89 */ 90 91typedef struct { 92 u_int16_t isp_adapter_enabled : 1, 93 isp_req_ack_active_neg : 1, 94 isp_data_line_active_neg: 1, 95 isp_cmd_dma_burst_enable: 1, 96 isp_data_dma_burst_enabl: 1, 97 isp_fifo_threshold : 2, 98 isp_diffmode : 1, 99 isp_initiator_id : 4, 100 isp_async_data_setup : 4; 101 u_int16_t isp_selection_timeout; 102 u_int16_t isp_max_queue_depth; 103 u_int16_t isp_clock; 104 u_int8_t isp_tag_aging; 105 u_int8_t isp_bus_reset_delay; 106 u_int8_t isp_retry_count; 107 u_int8_t isp_retry_delay; 108 struct { 109 u_int8_t dev_flags; /* Device Flags - see below */ 110 u_int8_t exc_throttle; 111 u_int8_t sync_period; 112 u_int8_t sync_offset : 4, 113 dev_enable : 1; 114 } isp_devparam[MAX_TARGETS]; 115} sdparam; /* scsi device parameters */ 116 117/* 118 * Device Flags 119 */ 120#define DPARM_DISC 0x80 121#define DPARM_PARITY 0x40 122#define DPARM_WIDE 0x20 123#define DPARM_SYNC 0x10 124#define DPARM_TQING 0x08 125#define DPARM_ARQ 0x04 126#define DPARM_QFRZ 0x02 127#define DPARM_RENEG 0x01 128#define DPARM_DEFAULT (0xff & ~DPARM_QFRZ) 129 130#define ISP_20M_SYNCPARMS 0x080c 131#define ISP_10M_SYNCPARMS 0x0c19 132#define ISP_08M_SYNCPARMS 0x0c25 133#define ISP_05M_SYNCPARMS 0x0c32 134#define ISP_04M_SYNCPARMS 0x0c41 135 136/* 137 * Fibre Channel Specifics 138 */ 139typedef struct { 140 u_int64_t isp_wwn; /* WWN of adapter */ 141 u_int8_t isp_loopid; /* FCAL of this adapter inst */ 142 u_int8_t isp_retry_count; 143 u_int8_t isp_retry_delay; 144 u_int8_t isp_fwstate; /* ISP F/W state */ 145 146 /* 147 * Scratch DMA mapped in area to fetch Port Database stuff, etc. 148 */ 149 volatile caddr_t isp_scratch; 150 u_int32_t isp_scdma; 151} fcparam; 152 153#define ISP2100_SCRLEN 0x100 154 155#define FW_CONFIG_WAIT 0x0000 156#define FW_WAIT_AL_PA 0x0001 157#define FW_WAIT_LOGIN 0x0002 158#define FW_READY 0x0003 159#define FW_LOSS_OF_SYNC 0x0004 160#define FW_ERROR 0x0005 161#define FW_REINIT 0x0006 162#define FW_NON_PART 0x0007 163 164static __inline char *fw_statename __P((u_int8_t x)); 165static __inline char * 166fw_statename(x) 167 u_int8_t x; 168{ 169 switch(x) { 170 case FW_CONFIG_WAIT: return "Config Wait"; 171 case FW_WAIT_AL_PA: return "Waiting for AL/PA"; 172 case FW_WAIT_LOGIN: return "Wait Login"; 173 case FW_READY: return "Ready"; 174 case FW_LOSS_OF_SYNC: return "Loss Of Sync"; 175 case FW_ERROR: return "Error"; 176 case FW_REINIT: return "Re-Init"; 177 case FW_NON_PART: return "Nonparticipating"; 178 default: return "eh?"; 179 } 180} 181 182/* 183 * Soft Structure per host adapter 184 */ 185struct ispsoftc { 186 /* 187 * Platform (OS) specific data 188 */ 189 struct isposinfo isp_osinfo; 190 191 /* 192 * Pointer to bus specific data 193 */ 194 struct ispmdvec * isp_mdvec; 195 196 /* 197 * State, debugging, etc.. 198 */ 199 200 u_int32_t isp_state : 3, 201 isp_dogactive : 1, 202 isp_dblev : 4, 203 isp_confopts : 8, 204 isp_fwrev : 16; 205 206 /* 207 * Host Adapter Type and Parameters. 208 * Some parameters nominally stored in NVRAM on card. 209 */ 210 void * isp_param; 211 u_int8_t isp_type; 212 int16_t isp_nactive; 213 214 /* 215 * Result and Request Queues. 216 */ 217 volatile u_int8_t isp_reqidx; /* index of next request */ 218 volatile u_int8_t isp_residx; /* index of next result */ 219 volatile u_int8_t isp_sendmarker; 220 volatile u_int8_t isp_seqno; 221 222 /* 223 * Sheer laziness, but it gets us around the problem 224 * where we don't have a clean way of remembering 225 * which transaction is bound to which ISP queue entry. 226 * 227 * There are other more clever ways to do this, but, 228 * jeez, so I blow a couple of KB per host adapter... 229 * and it *is* faster. 230 */ 231 volatile ISP_SCSI_XFER_T *isp_xflist[MAXISPREQUEST]; 232 233 /* 234 * request/result queues 235 */ 236 volatile caddr_t isp_rquest; 237 volatile caddr_t isp_result; 238 u_int32_t isp_rquest_dma; 239 u_int32_t isp_result_dma; 240}; 241 242/* 243 * ISP States 244 */ 245#define ISP_NILSTATE 0 246#define ISP_RESETSTATE 1 247#define ISP_INITSTATE 2 248#define ISP_RUNSTATE 3 249 250/* 251 * ISP Configuration Options 252 */ 253#define ISP_CFG_NORELOAD 0x80 /* don't download f/w */ 254 255/* 256 * Adapter Types 257 */ 258#define ISP_HA_SCSI 0xf 259#define ISP_HA_SCSI_UNKNOWN 0x0 260#define ISP_HA_SCSI_1020 0x1 261#define ISP_HA_SCSI_1040A 0x2 262#define ISP_HA_SCSI_1040B 0x3 263#define ISP_HA_FC 0xf0 264#define ISP_HA_FC_2100 0x10 265 266/* 267 * Macros to read, write ISP registers through MD code 268 */ 269 270#define ISP_READ(isp, reg) \ 271 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg)) 272 273#define ISP_WRITE(isp, reg, val) \ 274 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val)) 275 276#define ISP_MBOXDMASETUP(isp) \ 277 (*(isp)->isp_mdvec->dv_mbxdma)((isp)) 278 279#define ISP_DMASETUP(isp, xs, req, iptrp, optr) \ 280 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr)) 281 282#define ISP_DMAFREE(isp, xs, seqno) \ 283 if ((isp)->isp_mdvec->dv_dmaclr) \ 284 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno)) 285 286#define ISP_RESET0(isp) \ 287 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp)) 288#define ISP_RESET1(isp) \ 289 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp)) 290#define ISP_DUMPREGS(isp) \ 291 if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp)) 292 293#define ISP_SETBITS(isp, reg, val) \ 294 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val)) 295 296#define ISP_CLRBITS(isp, reg, val) \ 297 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val)) 298 299/* 300 * Function Prototypes 301 */ 302 303/* 304 * Reset Hardware. 305 */ 306void isp_reset __P((struct ispsoftc *)); 307 308/* 309 * Abort this running command.. 310 * 311 * Second argument is an index into xflist array. 312 * All locks must be held already. 313 */ 314int isp_abortcmd __P((struct ispsoftc *, int)); 315 316/* 317 * Initialize Hardware to known state 318 */ 319void isp_init __P((struct ispsoftc *)); 320 321/* 322 * Free any associated resources prior to decommissioning. 323 */ 324void isp_uninit __P((struct ispsoftc *)); 325 326/* 327 * Interrupt Service Routine 328 */ 329int isp_intr __P((void *)); 330 331/* 332 * Watchdog Routine 333 */ 334void isp_watch __P((void *)); 335 336/* 337 * Command Entry Point 338 */ 339extern int32_t ispscsicmd __P((ISP_SCSI_XFER_T *)); 340 341#endif /* _ISPVAR_H */ 342