ispvar.h revision 35597
1218822Sdim/* $Id: ispvar.h,v 1.1 1998/04/22 17:54:58 mjacob Exp $ */ 238889Sjdp/* 3218822Sdim * Soft Definitions for for Qlogic ISP SCSI adapters. 4218822Sdim * 538889Sjdp *--------------------------------------- 6218822Sdim * Copyright (c) 1997, 1998 by Matthew Jacob 738889Sjdp * NASA/Ames Research Center 838889Sjdp * All rights reserved. 938889Sjdp *--------------------------------------- 1038889Sjdp * Redistribution and use in source and binary forms, with or without 1138889Sjdp * modification, are permitted provided that the following conditions 1238889Sjdp * are met: 1338889Sjdp * 1. Redistributions of source code must retain the above copyright 1438889Sjdp * notice immediately at the beginning of the file, without modification, 1538889Sjdp * this list of conditions, and the following disclaimer. 1638889Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1738889Sjdp * notice, this list of conditions and the following disclaimer in the 1838889Sjdp * documentation and/or other materials provided with the distribution. 1938889Sjdp * 3. The name of the author may not be used to endorse or promote products 2038889Sjdp * derived from this software without specific prior written permission. 2138889Sjdp * 22218822Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23218822Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2438889Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25218822Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 26218822Sdim * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2738889Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28218822Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2938889Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3038889Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3138889Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3292828Sobrien * SUCH DAMAGE. 3338889Sjdp * 3438889Sjdp */ 3538889Sjdp 3638889Sjdp#ifndef _ISPVAR_H 3738889Sjdp#define _ISPVAR_H 3838889Sjdp 3938889Sjdp#ifdef __NetBSD__ 4038889Sjdp#include <dev/ic/ispmbox.h> 4138889Sjdp#endif 4238889Sjdp#ifdef __FreeBSD__ 4361843Sobrien#include <dev/isp/ispmbox.h> 4461843Sobrien#endif 4561843Sobrien#ifdef __linux__ 4661843Sobrien#include <ispmbox.h> 4761843Sobrien#endif 4861843Sobrien 4961843Sobrien/* 5061843Sobrien * Vector for MD code to provide specific services. 5161843Sobrien */ 5261843Sobrienstruct ispsoftc; 53218822Sdimstruct ispmdvec { 5461843Sobrien u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int)); 5561843Sobrien void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t)); 5661843Sobrien int (*dv_mbxdma) __P((struct ispsoftc *)); 5761843Sobrien int (*dv_dmaset) __P((struct ispsoftc *, 5861843Sobrien ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t)); 5961843Sobrien void (*dv_dmaclr) 6038889Sjdp __P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t)); 6138889Sjdp void (*dv_reset0) __P((struct ispsoftc *)); 6238889Sjdp void (*dv_reset1) __P((struct ispsoftc *)); 6338889Sjdp void (*dv_dregs) __P((struct ispsoftc *)); 6438889Sjdp const u_int16_t *dv_ispfw; /* ptr to f/w */ 6538889Sjdp u_int16_t dv_fwlen; /* length of f/w */ 6638889Sjdp u_int16_t dv_codeorg; /* code ORG for f/w */ 6738889Sjdp u_int16_t dv_fwrev; /* f/w revision */ 6838889Sjdp /* 6938889Sjdp * Initial values for conf1 register 70218822Sdim */ 71218822Sdim u_int16_t dv_conf1; 72218822Sdim u_int16_t dv_clock; /* clock frequency */ 73218822Sdim}; 74218822Sdim 7538889Sjdp#define MAX_TARGETS 16 76218822Sdim#define MAX_LUNS 8 77218822Sdim#define MAX_FC_TARG 126 7838889Sjdp 79218822Sdim#define RQUEST_QUEUE_LEN(isp) MAXISPREQUEST 8038889Sjdp#define RESULT_QUEUE_LEN(isp) (MAXISPREQUEST/4) 81218822Sdim 82218822Sdim#define QENTRY_LEN 64 83218822Sdim 84218822Sdim#define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN)) 85218822Sdim#define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN) 86218822Sdim 87218822Sdim/* 88218822Sdim * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters 89218822Sdim */ 90218822Sdim 91218822Sdimtypedef struct { 92218822Sdim u_int16_t isp_adapter_enabled : 1, 93218822Sdim isp_req_ack_active_neg : 1, 94218822Sdim isp_data_line_active_neg: 1, 95218822Sdim isp_cmd_dma_burst_enable: 1, 96218822Sdim isp_data_dma_burst_enabl: 1, 97218822Sdim isp_fifo_threshold : 2, 98218822Sdim isp_diffmode : 1, 99218822Sdim isp_initiator_id : 4, 100218822Sdim isp_async_data_setup : 4; 101218822Sdim u_int16_t isp_selection_timeout; 102218822Sdim u_int16_t isp_max_queue_depth; 103218822Sdim u_int16_t isp_clock; 104218822Sdim u_int8_t isp_tag_aging; 105218822Sdim u_int8_t isp_bus_reset_delay; 106218822Sdim u_int8_t isp_retry_count; 107218822Sdim u_int8_t isp_retry_delay; 108218822Sdim struct { 10938889Sjdp u_int8_t dev_flags; /* Device Flags - see below */ 110218822Sdim u_int8_t exc_throttle; 111218822Sdim u_int8_t sync_period; 11238889Sjdp u_int8_t sync_offset : 4, 113218822Sdim dev_enable : 1; 114218822Sdim } isp_devparam[MAX_TARGETS]; 115218822Sdim} sdparam; /* scsi device parameters */ 116218822Sdim 117218822Sdim/* 11838889Sjdp * Device Flags 119218822Sdim */ 120218822Sdim#define DPARM_DISC 0x80 12138889Sjdp#define DPARM_PARITY 0x40 122218822Sdim#define DPARM_WIDE 0x20 123218822Sdim#define DPARM_SYNC 0x10 124218822Sdim#define DPARM_TQING 0x08 12538889Sjdp#define DPARM_ARQ 0x04 126218822Sdim#define DPARM_QFRZ 0x02 127218822Sdim#define DPARM_RENEG 0x01 128218822Sdim#define DPARM_DEFAULT (0xff & ~DPARM_QFRZ) 129218822Sdim 130218822Sdim#define ISP_20M_SYNCPARMS 0x080c 131218822Sdim#define ISP_10M_SYNCPARMS 0x0c19 132218822Sdim#define ISP_08M_SYNCPARMS 0x0c25 133218822Sdim#define ISP_05M_SYNCPARMS 0x0c32 134218822Sdim#define ISP_04M_SYNCPARMS 0x0c41 13538889Sjdp 13638889Sjdp/* 13738889Sjdp * Fibre Channel Specifics 13838889Sjdp */ 13938889Sjdptypedef struct { 140218822Sdim u_int64_t isp_wwn; /* WWN of adapter */ 14138889Sjdp u_int8_t isp_loopid; /* FCAL of this adapter inst */ 142218822Sdim u_int8_t isp_retry_count; 14338889Sjdp u_int8_t isp_retry_delay; 14438889Sjdp u_int8_t isp_fwstate; /* ISP F/W state */ 145218822Sdim 14638889Sjdp /* 14738889Sjdp * Scratch DMA mapped in area to fetch Port Database stuff, etc. 14892828Sobrien */ 14938889Sjdp volatile caddr_t isp_scratch; 15038889Sjdp u_int32_t isp_scdma; 151218822Sdim} fcparam; 152218822Sdim 153218822Sdim#define ISP2100_SCRLEN 0x100 154218822Sdim 155218822Sdim#define FW_CONFIG_WAIT 0x0000 156218822Sdim#define FW_WAIT_AL_PA 0x0001 157218822Sdim#define FW_WAIT_LOGIN 0x0002 158218822Sdim#define FW_READY 0x0003 159218822Sdim#define FW_LOSS_OF_SYNC 0x0004 160218822Sdim#define FW_ERROR 0x0005 161218822Sdim#define FW_REINIT 0x0006 162218822Sdim#define FW_NON_PART 0x0007 163218822Sdim 164218822Sdimstatic __inline char *fw_statename __P((u_int8_t x)); 165218822Sdimstatic __inline char * 166218822Sdimfw_statename(x) 167218822Sdim u_int8_t x; 168218822Sdim{ 169218822Sdim switch(x) { 170218822Sdim case FW_CONFIG_WAIT: return "Config Wait"; 171218822Sdim case FW_WAIT_AL_PA: return "Waiting for AL/PA"; 172218822Sdim case FW_WAIT_LOGIN: return "Wait Login"; 173218822Sdim case FW_READY: return "Ready"; 174218822Sdim case FW_LOSS_OF_SYNC: return "Loss Of Sync"; 175218822Sdim case FW_ERROR: return "Error"; 176218822Sdim case FW_REINIT: return "Re-Init"; 177218822Sdim case FW_NON_PART: return "Nonparticipating"; 178218822Sdim default: return "eh?"; 179218822Sdim } 180218822Sdim} 181218822Sdim 182218822Sdim/* 183218822Sdim * Soft Structure per host adapter 184218822Sdim */ 185218822Sdimstruct ispsoftc { 186218822Sdim /* 187218822Sdim * Platform (OS) specific data 188218822Sdim */ 189218822Sdim struct isposinfo isp_osinfo; 190218822Sdim 191218822Sdim /* 192218822Sdim * Pointer to bus specific data 193218822Sdim */ 194218822Sdim struct ispmdvec * isp_mdvec; 195218822Sdim 196218822Sdim /* 197218822Sdim * State, debugging, etc.. 198218822Sdim */ 199218822Sdim 200218822Sdim u_int32_t isp_state : 3, 201218822Sdim isp_dogactive : 1, 202218822Sdim isp_dblev : 4, 20338889Sjdp isp_confopts : 8, 20492828Sobrien isp_fwrev : 16; 20538889Sjdp 20638889Sjdp /* 20738889Sjdp * Host Adapter Type and Parameters. 20838889Sjdp * Some parameters nominally stored in NVRAM on card. 20938889Sjdp */ 21038889Sjdp void * isp_param; 21192828Sobrien u_int8_t isp_type; 21238889Sjdp int16_t isp_nactive; 21338889Sjdp 21438889Sjdp /* 21538889Sjdp * Result and Request Queues. 21638889Sjdp */ 21738889Sjdp volatile u_int8_t isp_reqidx; /* index of next request */ 21838889Sjdp volatile u_int8_t isp_residx; /* index of next result */ 21938889Sjdp volatile u_int8_t isp_sendmarker; 22038889Sjdp volatile u_int8_t isp_seqno; 22138889Sjdp 222218822Sdim /* 22338889Sjdp * Sheer laziness, but it gets us around the problem 22438889Sjdp * where we don't have a clean way of remembering 22538889Sjdp * which transaction is bound to which ISP queue entry. 22638889Sjdp * 22738889Sjdp * There are other more clever ways to do this, but, 22861843Sobrien * jeez, so I blow a couple of KB per host adapter... 229218822Sdim * and it *is* faster. 23061843Sobrien */ 23161843Sobrien volatile ISP_SCSI_XFER_T *isp_xflist[MAXISPREQUEST]; 23299461Sobrien 23361843Sobrien /* 23461843Sobrien * request/result queues 23561843Sobrien */ 23699461Sobrien volatile caddr_t isp_rquest; 23761843Sobrien volatile caddr_t isp_result; 23861843Sobrien u_int32_t isp_rquest_dma; 23961843Sobrien u_int32_t isp_result_dma; 24061843Sobrien}; 24161843Sobrien 24238889Sjdp/* 24338889Sjdp * ISP States 244218822Sdim */ 245218822Sdim#define ISP_NILSTATE 0 246218822Sdim#define ISP_RESETSTATE 1 247218822Sdim#define ISP_INITSTATE 2 248218822Sdim#define ISP_RUNSTATE 3 249218822Sdim 250218822Sdim/* 251218822Sdim * ISP Configuration Options 252218822Sdim */ 253218822Sdim#define ISP_CFG_NORELOAD 0x80 /* don't download f/w */ 254218822Sdim 255218822Sdim/* 256218822Sdim * Adapter Types 257218822Sdim */ 258218822Sdim#define ISP_HA_SCSI 0xf 259218822Sdim#define ISP_HA_SCSI_UNKNOWN 0x0 26038889Sjdp#define ISP_HA_SCSI_1020 0x1 26138889Sjdp#define ISP_HA_SCSI_1040A 0x2 26238889Sjdp#define ISP_HA_SCSI_1040B 0x3 26338889Sjdp#define ISP_HA_FC 0xf0 26438889Sjdp#define ISP_HA_FC_2100 0x10 265218822Sdim 26638889Sjdp/* 267218822Sdim * Macros to read, write ISP registers through MD code 26838889Sjdp */ 26938889Sjdp 27038889Sjdp#define ISP_READ(isp, reg) \ 271218822Sdim (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg)) 27238889Sjdp 27338889Sjdp#define ISP_WRITE(isp, reg, val) \ 27438889Sjdp (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val)) 27538889Sjdp 27638889Sjdp#define ISP_MBOXDMASETUP(isp) \ 27738889Sjdp (*(isp)->isp_mdvec->dv_mbxdma)((isp)) 27838889Sjdp 27938889Sjdp#define ISP_DMASETUP(isp, xs, req, iptrp, optr) \ 28038889Sjdp (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr)) 28138889Sjdp 28238889Sjdp#define ISP_DMAFREE(isp, xs, seqno) \ 28338889Sjdp if ((isp)->isp_mdvec->dv_dmaclr) \ 28438889Sjdp (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno)) 28538889Sjdp 28638889Sjdp#define ISP_RESET0(isp) \ 28738889Sjdp if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp)) 28838889Sjdp#define ISP_RESET1(isp) \ 28938889Sjdp if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp)) 29038889Sjdp#define ISP_DUMPREGS(isp) \ 29138889Sjdp if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp)) 292218822Sdim 293218822Sdim#define ISP_SETBITS(isp, reg, val) \ 29438889Sjdp (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val)) 29538889Sjdp 29638889Sjdp#define ISP_CLRBITS(isp, reg, val) \ 29799461Sobrien (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val)) 29838889Sjdp 29938889Sjdp/* 30038889Sjdp * Function Prototypes 30138889Sjdp */ 30238889Sjdp 30338889Sjdp/* 30438889Sjdp * Reset Hardware. 30538889Sjdp */ 30638889Sjdpvoid isp_reset __P((struct ispsoftc *)); 30738889Sjdp 30838889Sjdp/* 30938889Sjdp * Abort this running command.. 31038889Sjdp * 31138889Sjdp * Second argument is an index into xflist array. 31238889Sjdp * All locks must be held already. 31338889Sjdp */ 31438889Sjdpint isp_abortcmd __P((struct ispsoftc *, int)); 31538889Sjdp 31638889Sjdp/* 31738889Sjdp * Initialize Hardware to known state 31838889Sjdp */ 31938889Sjdpvoid isp_init __P((struct ispsoftc *)); 32038889Sjdp 32138889Sjdp/* 32238889Sjdp * Free any associated resources prior to decommissioning. 32338889Sjdp */ 32438889Sjdpvoid isp_uninit __P((struct ispsoftc *)); 32538889Sjdp 32638889Sjdp/* 32738889Sjdp * Interrupt Service Routine 32838889Sjdp */ 32938889Sjdpint isp_intr __P((void *)); 33038889Sjdp 33138889Sjdp/* 33238889Sjdp * Watchdog Routine 33338889Sjdp */ 33438889Sjdpvoid isp_watch __P((void *)); 33538889Sjdp 33638889Sjdp/* 33738889Sjdp * Command Entry Point 33838889Sjdp */ 33938889Sjdpextern int32_t ispscsicmd __P((ISP_SCSI_XFER_T *)); 34038889Sjdp 34138889Sjdp#endif /* _ISPVAR_H */ 34238889Sjdp