1 /* $Id: ispvar.h,v 1.17 1999/07/05 20:42:08 mjacob Exp $ */ 2 /* 3 * Soft Definitions for for Qlogic ISP SCSI adapters. 4 * 5 *--------------------------------------- 6 * Copyright (c) 1997, 1998, 1999 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 #if defined(__NetBSD__) || defined(__OpenBSD__) 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 #define ISP_CORE_VERSION_MAJOR 1 50 #define ISP_CORE_VERSION_MINOR 9 51 52 /* 53 * Vector for bus specific code to provide specific services. 54 */ 55 struct ispsoftc; 56 struct ispmdvec { 57 u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int)); 58 void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t)); 59 int (*dv_mbxdma) __P((struct ispsoftc *)); 60 int (*dv_dmaset) __P((struct ispsoftc *, 61 ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t)); 62 void (*dv_dmaclr) 63 __P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t)); 64 void (*dv_reset0) __P((struct ispsoftc *)); 65 void (*dv_reset1) __P((struct ispsoftc *)); 66 void (*dv_dregs) __P((struct ispsoftc *)); 67 const u_int16_t *dv_ispfw; /* ptr to f/w */ 68 u_int16_t dv_fwlen; /* length of f/w */ 69 u_int16_t dv_codeorg; /* code ORG for f/w */ 70 u_int32_t dv_fwrev; /* f/w revision */ 71 /* 72 * Initial values for conf1 register 73 */ 74 u_int16_t dv_conf1; 75 u_int16_t dv_clock; /* clock frequency */ 76 }; 77 78 #define MAX_TARGETS 16 79 #ifdef ISP2100_FABRIC 80 #define MAX_FC_TARG 256 81 #else 82 #define MAX_FC_TARG 126 83 #endif 84 85 #define ISP_MAX_TARGETS(isp) (IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS) 86 #ifdef ISP2100_SCCLUN 87 #define _ISP_FC_LUN(isp) 65536 88 #else 89 #define _ISP_FC_LUN(isp) 16 90 #endif 91 #define _ISP_SCSI_LUN(isp) \ 92 ((ISP_FW_REVX(isp->isp_fwrev) >= ISP_FW_REV(7, 55, 0))? 32 : 8) 93 #define ISP_MAX_LUNS(isp) \ 94 (IS_FC(isp)? _ISP_FC_LUN(isp) : _ISP_SCSI_LUN(isp)) 95 96 /* queue length must be a power of two */ 97 #define QENTRY_LEN 64 98 #define RQUEST_QUEUE_LEN MAXISPREQUEST 99 #define RESULT_QUEUE_LEN (MAXISPREQUEST/2) 100 #define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN)) 101 #define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN) 102 #define ISP_NXT_QENTRY(idx, qlen) (((idx) + 1) & ((qlen)-1)) 103 #define ISP_QAVAIL(in, out, qlen) \ 104 ((in == out)? (qlen - 1) : ((in > out)? \ 105 ((qlen - 1) - (in - out)) : (out - in - 1))) 106 /* 107 * SCSI Specific Host Adapter Parameters- per bus, per target 108 */ 109 110 typedef struct { 111 u_int isp_gotdparms : 1, 112 isp_req_ack_active_neg : 1, 113 isp_data_line_active_neg: 1, 114 isp_cmd_dma_burst_enable: 1, 115 isp_data_dma_burst_enabl: 1, 116 isp_fifo_threshold : 3, 117 isp_ultramode : 1, 118 isp_diffmode : 1, 119 isp_lvdmode : 1, 120 : 1, 121 isp_initiator_id : 4, 122 isp_async_data_setup : 4; 123 u_int16_t isp_selection_timeout; 124 u_int16_t isp_max_queue_depth; 125 u_int8_t isp_tag_aging; 126 u_int8_t isp_bus_reset_delay; 127 u_int8_t isp_retry_count; 128 u_int8_t isp_retry_delay; 129 struct { 130 u_int dev_enable : 1, /* ignored */ 131 : 1, 132 dev_update : 1, 133 dev_refresh : 1, 134 exc_throttle : 8, 135 cur_offset : 4, 136 sync_offset : 4; 137 u_int8_t cur_period; /* current sync period */ 138 u_int8_t sync_period; /* goal sync period */ 139 u_int16_t dev_flags; /* goal device flags */ 140 u_int16_t cur_dflags; /* current device flags */ 141 } isp_devparam[MAX_TARGETS]; 142 } sdparam; 143 144 /* 145 * Device Flags 146 */ 147 #define DPARM_DISC 0x8000 148 #define DPARM_PARITY 0x4000 149 #define DPARM_WIDE 0x2000 150 #define DPARM_SYNC 0x1000 151 #define DPARM_TQING 0x0800 152 #define DPARM_ARQ 0x0400 153 #define DPARM_QFRZ 0x0200 154 #define DPARM_RENEG 0x0100 155 #define DPARM_NARROW 0x0080 /* Possibly only available with >= 7.55 fw */ 156 #define DPARM_ASYNC 0x0040 /* Possibly only available with >= 7.55 fw */ 157 #define DPARM_DEFAULT (0xFF00 & ~DPARM_QFRZ) 158 #define DPARM_SAFE_DFLT (DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING)) 159 160 161 /* technically, not really correct, as they need to be rated based upon clock */ 162 #define ISP_40M_SYNCPARMS 0x080a 163 #define ISP_20M_SYNCPARMS 0x080c 164 #define ISP_10M_SYNCPARMS 0x0c19 165 #define ISP_08M_SYNCPARMS 0x0c25 166 #define ISP_05M_SYNCPARMS 0x0c32 167 #define ISP_04M_SYNCPARMS 0x0c41 168 169 /* 170 * Fibre Channel Specifics 171 */ 172 typedef struct { 173 u_int isp_fwoptions : 16, 174 : 7, 175 loop_seen_once : 1, 176 isp_loopstate : 3, /* Current Loop State */ 177 isp_fwstate : 3, /* ISP F/W state */ 178 isp_gotdparms : 1, 179 isp_onfabric : 1; 180 u_int8_t isp_loopid; /* hard loop id */ 181 u_int8_t isp_alpa; /* ALPA */ 182 u_int32_t isp_portid; 183 u_int8_t isp_execthrottle; 184 u_int8_t isp_retry_delay; 185 u_int8_t isp_retry_count; 186 u_int16_t isp_maxalloc; 187 u_int16_t isp_maxfrmlen; 188 u_int64_t isp_nodewwn; 189 u_int64_t isp_portwwn; 190 /* 191 * Port Data Base. This is indexed by 'target', which is invariate. 192 * However, elements within can move around due to loop changes, 193 * so the actual loop ID passed to the F/W is in this structure. 194 * The first time the loop is seen up, loopid will match the index 195 * (except for fabric nodes which are above mapped above FC_SNS_ID 196 * and are completely virtual), but subsequent LIPs can cause things 197 * to move around. 198 */ 199 struct lportdb { 200 u_int 201 loopid : 8, 202 : 4, 203 fabdev : 1, 204 roles : 2, 205 valid : 1; 206 u_int32_t portid; 207 u_int64_t node_wwn; 208 u_int64_t port_wwn; 209 } portdb[MAX_FC_TARG]; 210 211 /* 212 * Scratch DMA mapped in area to fetch Port Database stuff, etc. 213 */ 214 caddr_t isp_scratch; 215 u_int32_t isp_scdma; 216 } fcparam; 217 218 #define FW_CONFIG_WAIT 0 219 #define FW_WAIT_AL_PA 1 220 #define FW_WAIT_LOGIN 2 221 #define FW_READY 3 222 #define FW_LOSS_OF_SYNC 4 223 #define FW_ERROR 5 224 #define FW_REINIT 6 225 #define FW_NON_PART 7 226 227 #define LOOP_NIL 0 228 #define LOOP_LIP_RCVD 1 229 #define LOOP_PDB_RCVD 2 230 #define LOOP_READY 7 231 232 #define FL_PORT_ID 0x7e /* FL_Port Special ID */ 233 #define FC_PORT_ID 0x7f /* Fabric Controller Special ID */ 234 #define FC_SNS_ID 0x80 /* SNS Server Special ID */ 235 236 #ifdef ISP_TARGET_MODE 237 /* 238 * Some temporary Target Mode definitions 239 */ 240 typedef struct tmd_cmd { 241 u_int8_t cd_iid; /* initiator */ 242 u_int8_t cd_tgt; /* target */ 243 u_int8_t cd_lun; /* LUN for this command */ 244 u_int8_t cd_state; 245 u_int8_t cd_cdb[16]; /* command bytes */ 246 u_int8_t cd_sensedata[20]; 247 u_int16_t cd_rxid; 248 u_int32_t cd_datalen; 249 u_int32_t cd_totbytes; 250 void * cd_hba; 251 } tmd_cmd_t; 252 253 /* 254 * Async Target Mode Event Definitions 255 */ 256 #define TMD_BUS_RESET 0 257 #define TMD_BDR 1 258 259 /* 260 * Immediate Notify data structure. 261 */ 262 #define NOTIFY_MSGLEN 5 263 typedef struct { 264 u_int8_t nt_iid; /* initiator */ 265 u_int8_t nt_tgt; /* target */ 266 u_int8_t nt_lun; /* LUN for this command */ 267 u_int8_t nt_msg[NOTIFY_MSGLEN]; /* SCSI message byte(s) */ 268 } tmd_notify_t; 269 270 #endif 271 272 /* 273 * Soft Structure per host adapter 274 */ 275 struct ispsoftc { 276 /* 277 * Platform (OS) specific data 278 */ 279 struct isposinfo isp_osinfo; 280 281 /* 282 * Pointer to bus specific data 283 */ 284 struct ispmdvec * isp_mdvec; 285 286 /* 287 * Mostly nonvolatile state. 288 */ 289 290 u_int isp_clock : 8, 291 isp_confopts : 8, 292 isp_fast_mttr : 1, 293 : 1, 294 isp_used : 1, 295 isp_dblev : 3, 296 isp_dogactive : 1, 297 isp_bustype : 1, /* BUS Implementation */ 298 isp_type : 8; /* HBA Type and Revision */ 299 300 u_int16_t isp_fwrev[3]; /* Running F/W revision */ 301 u_int16_t isp_romfw_rev[3]; /* 'ROM' F/W revision */ 302 void * isp_param; 303 304 /* 305 * Volatile state 306 */ 307 308 volatile u_int 309 : 13, 310 isp_state : 3, 311 : 2, 312 isp_sendmarker : 2, /* send a marker entry */ 313 isp_update : 2, /* update parameters */ 314 isp_nactive : 10; /* how many commands active */ 315 316 /* 317 * Result and Request Queue indices. 318 */ 319 volatile u_int8_t isp_reqodx; /* index of last ISP pickup */ 320 volatile u_int8_t isp_reqidx; /* index of next request */ 321 volatile u_int8_t isp_residx; /* index of next result */ 322 volatile u_int8_t isp_seqno; /* rolling sequence # */ 323 324 /* 325 * Sheer laziness, but it gets us around the problem 326 * where we don't have a clean way of remembering 327 * which transaction is bound to which ISP queue entry. 328 * 329 * There are other more clever ways to do this, but, 330 * jeez, so I blow a couple of KB per host adapter... 331 * and it *is* faster. 332 */ 333 ISP_SCSI_XFER_T *isp_xflist[RQUEST_QUEUE_LEN]; 334 335 /* 336 * request/result queues and dma handles for them. 337 */ 338 caddr_t isp_rquest; 339 caddr_t isp_result; 340 u_int32_t isp_rquest_dma; 341 u_int32_t isp_result_dma; 342 343 #ifdef ISP_TARGET_MODE 344 /* 345 * Vectors for handling target mode support. 346 * 347 * isp_tmd_newcmd is for feeding a newly arrived command to some 348 * upper layer. 349 * 350 * isp_tmd_event is for notifying some upper layer that an event has 351 * occurred that is not necessarily tied to any target (e.g., a SCSI 352 * Bus Reset). 353 * 354 * isp_tmd_notify is for notifying some upper layer that some 355 * event is now occurring that is either pertinent for a specific 356 * device or for a specific command (e.g., BDR or ABORT TAG). 357 * 358 * It is left undefined (for now) how pools of commands are managed. 359 */ 360 void (*isp_tmd_newcmd) __P((void *, tmd_cmd_t *)); 361 void (*isp_tmd_event) __P((void *, int)); 362 void (*isp_tmd_notify) __P((void *, tmd_notify_t *)); 363 #endif 364 }; 365 366 #define SDPARAM(isp) ((sdparam *) (isp)->isp_param) 367 #define FCPARAM(isp) ((fcparam *) (isp)->isp_param) 368 369 /* 370 * ISP States 371 */ 372 #define ISP_NILSTATE 0 373 #define ISP_RESETSTATE 1 374 #define ISP_INITSTATE 2 375 #define ISP_RUNSTATE 3 376 377 /* 378 * ISP Configuration Options 379 */ 380 #define ISP_CFG_NORELOAD 0x80 /* don't download f/w */ 381 #define ISP_CFG_NONVRAM 0x40 /* ignore NVRAM */ 382 #define ISP_CFG_FULL_DUPLEX 0x01 /* Fibre Channel Only */ 383 384 #define ISP_FW_REV(maj, min, mic) ((maj << 24) | (min << 16) | mic) 385 #define ISP_FW_REVX(xp) ((xp[0]<<24) | (xp[1] << 16) | xp[2]) 386 387 388 /* 389 * Bus (implementation) types 390 */ 391 #define ISP_BT_PCI 0 /* PCI Implementations */ 392 #define ISP_BT_SBUS 1 /* SBus Implementations */ 393 394 /* 395 * Chip Types 396 */ 397 #define ISP_HA_SCSI 0xf 398 #define ISP_HA_SCSI_UNKNOWN 0x1 399 #define ISP_HA_SCSI_1020 0x2 400 #define ISP_HA_SCSI_1020A 0x3 401 #define ISP_HA_SCSI_1040 0x4 402 #define ISP_HA_SCSI_1040A 0x5 403 #define ISP_HA_SCSI_1040B 0x6 404 #define ISP_HA_SCSI_1040C 0x7 405 #define ISP_HA_SCSI_1080 0xd 406 #define ISP_HA_SCSI_12X0 0xe 407 #define ISP_HA_FC 0xf0 408 #define ISP_HA_FC_2100 0x10 409 #define ISP_HA_FC_2200 0x20 410 411 #define IS_SCSI(isp) (isp->isp_type & ISP_HA_SCSI) 412 #define IS_1080(isp) (isp->isp_type == ISP_HA_SCSI_1080) 413 #define IS_12X0(isp) (isp->isp_type == ISP_HA_SCSI_12X0) 414 #define IS_FC(isp) (isp->isp_type & ISP_HA_FC) 415 416 /* 417 * Macros to read, write ISP registers through bus specific code. 418 */ 419 420 #define ISP_READ(isp, reg) \ 421 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg)) 422 423 #define ISP_WRITE(isp, reg, val) \ 424 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val)) 425 426 #define ISP_MBOXDMASETUP(isp) \ 427 (*(isp)->isp_mdvec->dv_mbxdma)((isp)) 428 429 #define ISP_DMASETUP(isp, xs, req, iptrp, optr) \ 430 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr)) 431 432 #define ISP_DMAFREE(isp, xs, seqno) \ 433 if ((isp)->isp_mdvec->dv_dmaclr) \ 434 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno)) 435 436 #define ISP_RESET0(isp) \ 437 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp)) 438 #define ISP_RESET1(isp) \ 439 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp)) 440 #define ISP_DUMPREGS(isp) \ 441 if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp)) 442 443 #define ISP_SETBITS(isp, reg, val) \ 444 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val)) 445 446 #define ISP_CLRBITS(isp, reg, val) \ 447 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val)) 448 449 /* 450 * Function Prototypes 451 */ 452 453 /* 454 * Reset Hardware. Totally. Assumes that you'll follow this with 455 * a call to isp_init. 456 */ 457 void isp_reset __P((struct ispsoftc *)); 458 459 /* 460 * Initialize Hardware to known state 461 */ 462 void isp_init __P((struct ispsoftc *)); 463 464 /* 465 * Reset the ISP and call completion for any orphaned commands. 466 */ 467 void isp_restart __P((struct ispsoftc *)); 468 469 /* 470 * Interrupt Service Routine 471 */ 472 int isp_intr __P((void *)); 473 474 /* 475 * Command Entry Point 476 */ 477 int32_t ispscsicmd __P((ISP_SCSI_XFER_T *)); 478 479 /* 480 * Platform Dependent to External to Internal Control Function 481 * 482 * Assumes all locks are held and that no reentrancy issues need be dealt with. 483 * 484 */ 485 typedef enum { 486 ISPCTL_RESET_BUS, /* Reset Bus */ 487 ISPCTL_RESET_DEV, /* Reset Device */ 488 ISPCTL_ABORT_CMD, /* Abort Command */ 489 ISPCTL_UPDATE_PARAMS, /* Update Operating Parameters */ 490 ISPCTL_FCLINK_TEST /* Test FC Link Status */ 491 } ispctl_t; 492 int isp_control __P((struct ispsoftc *, ispctl_t, void *)); 493 494 495 /* 496 * Platform Dependent to Internal to External Control Function 497 * (each platform must provide such a function) 498 * 499 * Assumes all locks are held and that no reentrancy issues need be dealt with. 500 * 501 */ 502 503 typedef enum { 504 ISPASYNC_NEW_TGT_PARAMS, 505 ISPASYNC_BUS_RESET, /* Bus Was Reset */ 506 ISPASYNC_LOOP_DOWN, /* FC Loop Down */ 507 ISPASYNC_LOOP_UP, /* FC Loop Up */ 508 ISPASYNC_PDB_CHANGED, /* FC Port Data Base Changed */ 509 ISPASYNC_CHANGE_NOTIFY, /* FC SNS Change Notification */ 510 ISPASYNC_FABRIC_DEV, /* FC New Fabric Device */ 511 } ispasync_t; 512 int isp_async __P((struct ispsoftc *, ispasync_t, void *)); 513 514 /* 515 * lost command routine (XXXX IN TRANSITION XXXX) 516 */ 517 void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *)); 518 519 520 #endif /* _ISPVAR_H */ 521