ispvar.h revision 48602
1142425Snectar/* $Id: ispvar.h,v 1.16 1999/07/02 22:46:31 mjacob Exp $ */ 2142425Snectar/* release_6_5_99 */ 3142425Snectar/* 4142425Snectar * Soft Definitions for for Qlogic ISP SCSI adapters. 5142425Snectar * 6142425Snectar *--------------------------------------- 7142425Snectar * Copyright (c) 1997, 1998, 1999 by Matthew Jacob 8142425Snectar * NASA/Ames Research Center 9142425Snectar * All rights reserved. 10142425Snectar *--------------------------------------- 11142425Snectar * Redistribution and use in source and binary forms, with or without 12142425Snectar * modification, are permitted provided that the following conditions 13142425Snectar * are met: 14238405Sjkim * 1. Redistributions of source code must retain the above copyright 15160814Ssimon * notice immediately at the beginning of the file, without modification, 16142425Snectar * this list of conditions, and the following disclaimer. 17160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 18160814Ssimon * notice, this list of conditions and the following disclaimer in the 19142425Snectar * documentation and/or other materials provided with the distribution. 20142425Snectar * 3. The name of the author may not be used to endorse or promote products 21142425Snectar * derived from this software without specific prior written permission. 22142425Snectar * 23142425Snectar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24142425Snectar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25142425Snectar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26162911Ssimon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 27194206Ssimon * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28194206Ssimon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29238405Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30142425Snectar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31142425Snectar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32142425Snectar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33142425Snectar * SUCH DAMAGE. 34142425Snectar * 35142425Snectar */ 36142425Snectar 37142425Snectar#ifndef _ISPVAR_H 38142425Snectar#define _ISPVAR_H 39142425Snectar 40142425Snectar#if defined(__NetBSD__) || defined(__OpenBSD__) 41142425Snectar#include <dev/ic/ispmbox.h> 42142425Snectar#endif 43142425Snectar#ifdef __FreeBSD__ 44238405Sjkim#include <dev/isp/ispmbox.h> 45142425Snectar#endif 46142425Snectar#ifdef __linux__ 47142425Snectar#include "ispmbox.h" 48160814Ssimon#endif 49160814Ssimon 50160814Ssimon#define ISP_CORE_VERSION_MAJOR 1 51238405Sjkim#define ISP_CORE_VERSION_MINOR 9 52238405Sjkim 53238405Sjkim/* 54238405Sjkim * Vector for bus specific code to provide specific services. 55238405Sjkim */ 56238405Sjkimstruct ispsoftc; 57160814Ssimonstruct ispmdvec { 58194206Ssimon u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int)); 59238405Sjkim void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t)); 60238405Sjkim int (*dv_mbxdma) __P((struct ispsoftc *)); 61238405Sjkim int (*dv_dmaset) __P((struct ispsoftc *, 62238405Sjkim ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t)); 63238405Sjkim void (*dv_dmaclr) 64238405Sjkim __P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t)); 65238405Sjkim void (*dv_reset0) __P((struct ispsoftc *)); 66238405Sjkim void (*dv_reset1) __P((struct ispsoftc *)); 67238405Sjkim void (*dv_dregs) __P((struct ispsoftc *)); 68290207Sjkim const u_int16_t *dv_ispfw; /* ptr to f/w */ 69290207Sjkim u_int16_t dv_fwlen; /* length of f/w */ 70290207Sjkim u_int16_t dv_codeorg; /* code ORG for f/w */ 71290207Sjkim u_int16_t dv_fwrev; /* f/w revision */ 72194206Ssimon /* 73238405Sjkim * Initial values for conf1 register 74238405Sjkim */ 75290207Sjkim u_int16_t dv_conf1; 76290207Sjkim u_int16_t dv_clock; /* clock frequency */ 77238405Sjkim}; 78238405Sjkim 79238405Sjkim#define MAX_TARGETS 16 80290207Sjkim#ifdef ISP2100_FABRIC 81290207Sjkim#define MAX_FC_TARG 256 82290207Sjkim#else 83290207Sjkim#define MAX_FC_TARG 126 84238405Sjkim#endif 85238405Sjkim 86238405Sjkim/* queue length must be a power of two */ 87238405Sjkim#define QENTRY_LEN 64 88238405Sjkim#define RQUEST_QUEUE_LEN MAXISPREQUEST 89238405Sjkim#define RESULT_QUEUE_LEN (MAXISPREQUEST/2) 90238405Sjkim#define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN)) 91290207Sjkim#define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN) 92290207Sjkim#define ISP_NXT_QENTRY(idx, qlen) (((idx) + 1) & ((qlen)-1)) 93290207Sjkim#define ISP_QAVAIL(in, out, qlen) \ 94290207Sjkim ((in == out)? (qlen - 1) : ((in > out)? \ 95238405Sjkim ((qlen - 1) - (in - out)) : (out - in - 1))) 96238405Sjkim/* 97238405Sjkim * SCSI Specific Host Adapter Parameters- per bus, per target 98290207Sjkim */ 99290207Sjkim 100238405Sjkimtypedef struct { 101142425Snectar u_int isp_gotdparms : 1, 102290207Sjkim isp_req_ack_active_neg : 1, 103142425Snectar isp_data_line_active_neg: 1, 104142425Snectar isp_cmd_dma_burst_enable: 1, 105142425Snectar isp_data_dma_burst_enabl: 1, 106142425Snectar isp_fifo_threshold : 3, 107142425Snectar isp_ultramode : 1, 108142425Snectar isp_diffmode : 1, 109160814Ssimon isp_lvdmode : 1, 110160814Ssimon : 1, 111160814Ssimon isp_initiator_id : 4, 112142425Snectar isp_async_data_setup : 4; 113142425Snectar u_int16_t isp_selection_timeout; 114142425Snectar u_int16_t isp_max_queue_depth; 115142425Snectar u_int8_t isp_tag_aging; 116142425Snectar u_int8_t isp_bus_reset_delay; 117142425Snectar u_int8_t isp_retry_count; 118142425Snectar u_int8_t isp_retry_delay; 119142425Snectar struct { 120142425Snectar u_int dev_enable : 1, /* ignored */ 121142425Snectar : 1, 122142425Snectar dev_update : 1, 123142425Snectar dev_refresh : 1, 124142425Snectar exc_throttle : 8, 125284283Sjkim cur_offset : 4, 126284283Sjkim sync_offset : 4; 127142425Snectar u_int8_t cur_period; /* current sync period */ 128160814Ssimon u_int8_t sync_period; /* goal sync period */ 129142425Snectar u_int16_t dev_flags; /* goal device flags */ 130142425Snectar u_int16_t cur_dflags; /* current device flags */ 131142425Snectar } isp_devparam[MAX_TARGETS]; 132142425Snectar} sdparam; 133142425Snectar 134142425Snectar/* 135142425Snectar * Device Flags 136325335Sjkim */ 137142425Snectar#define DPARM_DISC 0x8000 138142425Snectar#define DPARM_PARITY 0x4000 139142425Snectar#define DPARM_WIDE 0x2000 140238405Sjkim#define DPARM_SYNC 0x1000 141238405Sjkim#define DPARM_TQING 0x0800 142238405Sjkim#define DPARM_ARQ 0x0400 143238405Sjkim#define DPARM_QFRZ 0x0200 144142425Snectar#define DPARM_RENEG 0x0100 145238405Sjkim#define DPARM_NARROW 0x0080 /* Possibly only available with >= 7.55 fw */ 146238405Sjkim#define DPARM_ASYNC 0x0040 /* Possibly only available with >= 7.55 fw */ 147238405Sjkim#define DPARM_DEFAULT (0xFF00 & ~DPARM_QFRZ) 148142425Snectar#define DPARM_SAFE_DFLT (DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING)) 149142425Snectar 150167612Ssimon 151167612Ssimon/* technically, not really correct, as they need to be rated based upon clock */ 152167612Ssimon#define ISP_40M_SYNCPARMS 0x080a 153167612Ssimon#define ISP_20M_SYNCPARMS 0x080c 154167612Ssimon#define ISP_10M_SYNCPARMS 0x0c19 155167612Ssimon#define ISP_08M_SYNCPARMS 0x0c25 156167612Ssimon#define ISP_05M_SYNCPARMS 0x0c32 157238405Sjkim#define ISP_04M_SYNCPARMS 0x0c41 158238405Sjkim 159238405Sjkim/* 160238405Sjkim * Fibre Channel Specifics 161238405Sjkim */ 162238405Sjkimtypedef struct { 163238405Sjkim u_int isp_fwoptions : 16, 164194206Ssimon : 7, 165194206Ssimon loop_seen_once : 1, 166194206Ssimon isp_loopstate : 3, /* Current Loop State */ 167194206Ssimon isp_fwstate : 3, /* ISP F/W state */ 168290207Sjkim isp_gotdparms : 1, 169194206Ssimon isp_onfabric : 1; 170194206Ssimon u_int8_t isp_loopid; /* hard loop id */ 171194206Ssimon u_int8_t isp_alpa; /* ALPA */ 172 u_int32_t isp_portid; 173 u_int8_t isp_execthrottle; 174 u_int8_t isp_retry_delay; 175 u_int8_t isp_retry_count; 176 u_int16_t isp_maxalloc; 177 u_int16_t isp_maxfrmlen; 178 u_int64_t isp_nodewwn; 179 u_int64_t isp_portwwn; 180 /* 181 * Port Data Base. This is indexed by 'target', which is invariate. 182 * However, elements within can move around due to loop changes, 183 * so the actual loop ID passed to the F/W is in this structure. 184 * The first time the loop is seen up, loopid will match the index 185 * (except for fabric nodes which are above mapped above FC_SNS_ID 186 * and are completely virtual), but subsequent LIPs can cause things 187 * to move around. 188 */ 189 struct lportdb { 190 u_int 191 loopid : 8, 192 : 4, 193 fabdev : 1, 194 roles : 2, 195 valid : 1; 196 u_int32_t portid; 197 u_int64_t node_wwn; 198 u_int64_t port_wwn; 199 } portdb[MAX_FC_TARG]; 200 201 /* 202 * Scratch DMA mapped in area to fetch Port Database stuff, etc. 203 */ 204 caddr_t isp_scratch; 205 u_int32_t isp_scdma; 206} fcparam; 207 208#define FW_CONFIG_WAIT 0 209#define FW_WAIT_AL_PA 1 210#define FW_WAIT_LOGIN 2 211#define FW_READY 3 212#define FW_LOSS_OF_SYNC 4 213#define FW_ERROR 5 214#define FW_REINIT 6 215#define FW_NON_PART 7 216 217#define LOOP_NIL 0 218#define LOOP_LIP_RCVD 1 219#define LOOP_PDB_RCVD 2 220#define LOOP_READY 7 221 222#define FL_PORT_ID 0x7e /* FL_Port Special ID */ 223#define FC_PORT_ID 0x7f /* Fabric Controller Special ID */ 224#define FC_SNS_ID 0x80 /* SNS Server Special ID */ 225 226#ifdef ISP_TARGET_MODE 227/* 228 * Some temporary Target Mode definitions 229 */ 230typedef struct tmd_cmd { 231 u_int8_t cd_iid; /* initiator */ 232 u_int8_t cd_tgt; /* target */ 233 u_int8_t cd_lun; /* LUN for this command */ 234 u_int8_t cd_state; 235 u_int8_t cd_cdb[16]; /* command bytes */ 236 u_int8_t cd_sensedata[20]; 237 u_int16_t cd_rxid; 238 u_int32_t cd_datalen; 239 u_int32_t cd_totbytes; 240 void * cd_hba; 241} tmd_cmd_t; 242 243/* 244 * Async Target Mode Event Definitions 245 */ 246#define TMD_BUS_RESET 0 247#define TMD_BDR 1 248 249/* 250 * Immediate Notify data structure. 251 */ 252#define NOTIFY_MSGLEN 5 253typedef struct { 254 u_int8_t nt_iid; /* initiator */ 255 u_int8_t nt_tgt; /* target */ 256 u_int8_t nt_lun; /* LUN for this command */ 257 u_int8_t nt_msg[NOTIFY_MSGLEN]; /* SCSI message byte(s) */ 258} tmd_notify_t; 259 260#endif 261 262/* 263 * Soft Structure per host adapter 264 */ 265struct ispsoftc { 266 /* 267 * Platform (OS) specific data 268 */ 269 struct isposinfo isp_osinfo; 270 271 /* 272 * Pointer to bus specific data 273 */ 274 struct ispmdvec * isp_mdvec; 275 276 /* 277 * Mostly nonvolatile state. 278 */ 279 280 u_int isp_clock : 8, 281 isp_confopts : 8, 282 isp_fast_mttr : 1, 283 : 1, 284 isp_used : 1, 285 isp_dblev : 3, 286 isp_dogactive : 1, 287 isp_bustype : 1, /* BUS Implementation */ 288 isp_type : 8; /* HBA Type and Revision */ 289 290 u_int16_t isp_fwrev[3]; /* Running F/W revision */ 291 u_int16_t isp_romfw_rev[3]; /* 'ROM' F/W revision */ 292 void * isp_param; 293 294 /* 295 * Volatile state 296 */ 297 298 volatile u_int 299 : 13, 300 isp_state : 3, 301 : 2, 302 isp_sendmarker : 2, /* send a marker entry */ 303 isp_update : 2, /* update parameters */ 304 isp_nactive : 10; /* how many commands active */ 305 306 /* 307 * Result and Request Queue indices. 308 */ 309 volatile u_int8_t isp_reqodx; /* index of last ISP pickup */ 310 volatile u_int8_t isp_reqidx; /* index of next request */ 311 volatile u_int8_t isp_residx; /* index of next result */ 312 volatile u_int8_t isp_seqno; /* rolling sequence # */ 313 314 /* 315 * Sheer laziness, but it gets us around the problem 316 * where we don't have a clean way of remembering 317 * which transaction is bound to which ISP queue entry. 318 * 319 * There are other more clever ways to do this, but, 320 * jeez, so I blow a couple of KB per host adapter... 321 * and it *is* faster. 322 */ 323 ISP_SCSI_XFER_T *isp_xflist[RQUEST_QUEUE_LEN]; 324 325 /* 326 * request/result queues and dma handles for them. 327 */ 328 caddr_t isp_rquest; 329 caddr_t isp_result; 330 u_int32_t isp_rquest_dma; 331 u_int32_t isp_result_dma; 332 333#ifdef ISP_TARGET_MODE 334 /* 335 * Vectors for handling target mode support. 336 * 337 * isp_tmd_newcmd is for feeding a newly arrived command to some 338 * upper layer. 339 * 340 * isp_tmd_event is for notifying some upper layer that an event has 341 * occurred that is not necessarily tied to any target (e.g., a SCSI 342 * Bus Reset). 343 * 344 * isp_tmd_notify is for notifying some upper layer that some 345 * event is now occurring that is either pertinent for a specific 346 * device or for a specific command (e.g., BDR or ABORT TAG). 347 * 348 * It is left undefined (for now) how pools of commands are managed. 349 */ 350 void (*isp_tmd_newcmd) __P((void *, tmd_cmd_t *)); 351 void (*isp_tmd_event) __P((void *, int)); 352 void (*isp_tmd_notify) __P((void *, tmd_notify_t *)); 353#endif 354}; 355 356/* 357 * ISP States 358 */ 359#define ISP_NILSTATE 0 360#define ISP_RESETSTATE 1 361#define ISP_INITSTATE 2 362#define ISP_RUNSTATE 3 363 364/* 365 * ISP Configuration Options 366 */ 367#define ISP_CFG_NORELOAD 0x80 /* don't download f/w */ 368#define ISP_CFG_NONVRAM 0x40 /* ignore NVRAM */ 369#define ISP_CFG_FULL_DUPLEX 0x01 /* Fibre Channel Only */ 370 371#define ISP_FW_REV(maj, min, mic) ((maj << 24) | (min << 16) | mic) 372#define ISP_FW_REVX(xp) ((xp[0]<<24) | (xp[1] << 16) | xp[2]) 373 374 375/* 376 * Bus (implementation) types 377 */ 378#define ISP_BT_PCI 0 /* PCI Implementations */ 379#define ISP_BT_SBUS 1 /* SBus Implementations */ 380 381/* 382 * Chip Types 383 */ 384#define ISP_HA_SCSI 0xf 385#define ISP_HA_SCSI_UNKNOWN 0x1 386#define ISP_HA_SCSI_1020 0x2 387#define ISP_HA_SCSI_1020A 0x3 388#define ISP_HA_SCSI_1040 0x4 389#define ISP_HA_SCSI_1040A 0x5 390#define ISP_HA_SCSI_1040B 0x6 391#define ISP_HA_SCSI_1040C 0x7 392#define ISP_HA_SCSI_1080 0xd 393#define ISP_HA_SCSI_12X0 0xe 394#define ISP_HA_FC 0xf0 395#define ISP_HA_FC_2100 0x10 396#define ISP_HA_FC_2200 0x20 397 398#define IS_SCSI(isp) (isp->isp_type & ISP_HA_SCSI) 399#define IS_1080(isp) (isp->isp_type == ISP_HA_SCSI_1080) 400#define IS_12X0(isp) (isp->isp_type == ISP_HA_SCSI_12X0) 401#define IS_FC(isp) (isp->isp_type & ISP_HA_FC) 402 403/* 404 * Macros to read, write ISP registers through bus specific code. 405 */ 406 407#define ISP_READ(isp, reg) \ 408 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg)) 409 410#define ISP_WRITE(isp, reg, val) \ 411 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val)) 412 413#define ISP_MBOXDMASETUP(isp) \ 414 (*(isp)->isp_mdvec->dv_mbxdma)((isp)) 415 416#define ISP_DMASETUP(isp, xs, req, iptrp, optr) \ 417 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr)) 418 419#define ISP_DMAFREE(isp, xs, seqno) \ 420 if ((isp)->isp_mdvec->dv_dmaclr) \ 421 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno)) 422 423#define ISP_RESET0(isp) \ 424 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp)) 425#define ISP_RESET1(isp) \ 426 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp)) 427#define ISP_DUMPREGS(isp) \ 428 if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp)) 429 430#define ISP_SETBITS(isp, reg, val) \ 431 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val)) 432 433#define ISP_CLRBITS(isp, reg, val) \ 434 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val)) 435 436/* 437 * Function Prototypes 438 */ 439 440/* 441 * Reset Hardware. Totally. Assumes that you'll follow this with 442 * a call to isp_init. 443 */ 444void isp_reset __P((struct ispsoftc *)); 445 446/* 447 * Initialize Hardware to known state 448 */ 449void isp_init __P((struct ispsoftc *)); 450 451/* 452 * Reset the ISP and call completion for any orphaned commands. 453 */ 454void isp_restart __P((struct ispsoftc *)); 455 456/* 457 * Interrupt Service Routine 458 */ 459int isp_intr __P((void *)); 460 461/* 462 * Command Entry Point 463 */ 464int32_t ispscsicmd __P((ISP_SCSI_XFER_T *)); 465 466/* 467 * Platform Dependent to External to Internal Control Function 468 * 469 * Assumes all locks are held and that no reentrancy issues need be dealt with. 470 * 471 */ 472typedef enum { 473 ISPCTL_RESET_BUS, /* Reset Bus */ 474 ISPCTL_RESET_DEV, /* Reset Device */ 475 ISPCTL_ABORT_CMD, /* Abort Command */ 476 ISPCTL_UPDATE_PARAMS, /* Update Operating Parameters */ 477 ISPCTL_FCLINK_TEST /* Test FC Link Status */ 478} ispctl_t; 479int isp_control __P((struct ispsoftc *, ispctl_t, void *)); 480 481 482/* 483 * Platform Dependent to Internal to External Control Function 484 * (each platform must provide such a function) 485 * 486 * Assumes all locks are held and that no reentrancy issues need be dealt with. 487 * 488 */ 489 490typedef enum { 491 ISPASYNC_NEW_TGT_PARAMS, 492 ISPASYNC_BUS_RESET, /* Bus Was Reset */ 493 ISPASYNC_LOOP_DOWN, /* FC Loop Down */ 494 ISPASYNC_LOOP_UP, /* FC Loop Up */ 495 ISPASYNC_PDB_CHANGED, /* FC Port Data Base Changed */ 496 ISPASYNC_CHANGE_NOTIFY, /* FC SNS Change Notification */ 497 ISPASYNC_FABRIC_DEV, /* FC New Fabric Device */ 498} ispasync_t; 499int isp_async __P((struct ispsoftc *, ispasync_t, void *)); 500 501/* 502 * lost command routine (XXXX IN TRANSITION XXXX) 503 */ 504void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *)); 505 506 507#endif /* _ISPVAR_H */ 508