ispvar.h revision 171159
150477Speter/* $FreeBSD: head/sys/dev/isp/ispvar.h 171159 2007-07-02 20:08:20Z mjacob $ */ 2139749Simp/*- 3167403Smjacob * Copyright (c) 1997-2007 by Matthew Jacob 4167403Smjacob * All rights reserved. 5167403Smjacob * 6167403Smjacob * Redistribution and use in source and binary forms, with or without 7167403Smjacob * modification, are permitted provided that the following conditions 8167403Smjacob * are met: 9167403Smjacob * 10167403Smjacob * 1. Redistributions of source code must retain the above copyright 11167403Smjacob * notice, this list of conditions and the following disclaimer. 12167403Smjacob * 2. Redistributions in binary form must reproduce the above copyright 13167403Smjacob * notice, this list of conditions and the following disclaimer in the 14167403Smjacob * documentation and/or other materials provided with the distribution. 15167403Smjacob * 16167403Smjacob * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17167403Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18167403Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19167403Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 20167403Smjacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21167403Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22167403Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23167403Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24167403Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25167403Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26167403Smjacob * SUCH DAMAGE. 27167403Smjacob */ 28167403Smjacob/* 2935388Smjacob * Soft Definitions for for Qlogic ISP SCSI adapters. 3035388Smjacob */ 3135388Smjacob 3235388Smjacob#ifndef _ISPVAR_H 3335388Smjacob#define _ISPVAR_H 3435388Smjacob 3544819Smjacob#if defined(__NetBSD__) || defined(__OpenBSD__) 36163899Smjacob#include <dev/ic/isp_stds.h> 3735388Smjacob#include <dev/ic/ispmbox.h> 3835388Smjacob#endif 3935388Smjacob#ifdef __FreeBSD__ 40163899Smjacob#include <dev/isp/isp_stds.h> 4135388Smjacob#include <dev/isp/ispmbox.h> 4235388Smjacob#endif 4335388Smjacob#ifdef __linux__ 44163899Smjacob#include "isp_stds.h" 4542131Smjacob#include "ispmbox.h" 4635388Smjacob#endif 47155704Smjacob#ifdef __svr4__ 48163899Smjacob#include "isp_stds.h" 49155704Smjacob#include "ispmbox.h" 5053487Smjacob#endif 5135388Smjacob 52163899Smjacob#define ISP_CORE_VERSION_MAJOR 3 53163899Smjacob#define ISP_CORE_VERSION_MINOR 0 5439235Sgibbs 5535388Smjacob/* 5643420Smjacob * Vector for bus specific code to provide specific services. 5735388Smjacob */ 58155704Smjacobtypedef struct ispsoftc ispsoftc_t; 5935388Smjacobstruct ispmdvec { 6082689Smjacob int (*dv_rd_isr) 61163899Smjacob (ispsoftc_t *, uint32_t *, uint16_t *, uint16_t *); 62163899Smjacob uint32_t (*dv_rd_reg) (ispsoftc_t *, int); 63163899Smjacob void (*dv_wr_reg) (ispsoftc_t *, int, uint32_t); 64155704Smjacob int (*dv_mbxdma) (ispsoftc_t *); 65155704Smjacob int (*dv_dmaset) 66163899Smjacob (ispsoftc_t *, XS_T *, ispreq_t *, uint32_t *, uint32_t); 67163899Smjacob void (*dv_dmaclr) (ispsoftc_t *, XS_T *, uint32_t); 68155704Smjacob void (*dv_reset0) (ispsoftc_t *); 69155704Smjacob void (*dv_reset1) (ispsoftc_t *); 70155704Smjacob void (*dv_dregs) (ispsoftc_t *, const char *); 71167821Smjacob const void * dv_ispfw; /* ptr to f/w */ 72155704Smjacob uint16_t dv_conf1; 73155704Smjacob uint16_t dv_clock; /* clock frequency */ 7435388Smjacob}; 7535388Smjacob 7664087Smjacob/* 7764087Smjacob * Overall parameters 7864087Smjacob */ 7982689Smjacob#define MAX_TARGETS 16 80164272Smjacob#define MAX_FC_TARG 512 8149909Smjacob#define ISP_MAX_TARGETS(isp) (IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS) 8261772Smjacob#define ISP_MAX_LUNS(isp) (isp)->isp_maxluns 8349909Smjacob 8482689Smjacob/* 8564087Smjacob * Macros to access ISP registers through bus specific layers- 8664087Smjacob * mostly wrappers to vector through the mdvec structure. 8753487Smjacob */ 8882689Smjacob#define ISP_READ_ISR(isp, isrp, semap, mbox0p) \ 8982689Smjacob (*(isp)->isp_mdvec->dv_rd_isr)(isp, isrp, semap, mbox0p) 9053487Smjacob 9153487Smjacob#define ISP_READ(isp, reg) \ 9253487Smjacob (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg)) 9353487Smjacob 9453487Smjacob#define ISP_WRITE(isp, reg, val) \ 9553487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val)) 9653487Smjacob 9753487Smjacob#define ISP_MBOXDMASETUP(isp) \ 9853487Smjacob (*(isp)->isp_mdvec->dv_mbxdma)((isp)) 9953487Smjacob 10053487Smjacob#define ISP_DMASETUP(isp, xs, req, iptrp, optr) \ 10153487Smjacob (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr)) 10253487Smjacob 103155704Smjacob#define ISP_DMAFREE(isp, xs, hndl) \ 104155704Smjacob if ((isp)->isp_mdvec->dv_dmaclr) \ 10553487Smjacob (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl)) 10653487Smjacob 10753487Smjacob#define ISP_RESET0(isp) \ 10853487Smjacob if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp)) 10953487Smjacob#define ISP_RESET1(isp) \ 11053487Smjacob if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp)) 11164087Smjacob#define ISP_DUMPREGS(isp, m) \ 11264087Smjacob if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp),(m)) 11353487Smjacob 11453487Smjacob#define ISP_SETBITS(isp, reg, val) \ 11553487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val)) 11653487Smjacob 11753487Smjacob#define ISP_CLRBITS(isp, reg, val) \ 11853487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val)) 11953487Smjacob 12064087Smjacob/* 12164087Smjacob * The MEMORYBARRIER macro is defined per platform (to provide synchronization 12264087Smjacob * on Request and Response Queues, Scratch DMA areas, and Registers) 12364087Smjacob * 12464087Smjacob * Defined Memory Barrier Synchronization Types 12564087Smjacob */ 12664087Smjacob#define SYNC_REQUEST 0 /* request queue synchronization */ 12764087Smjacob#define SYNC_RESULT 1 /* result queue synchronization */ 12864087Smjacob#define SYNC_SFORDEV 2 /* scratch, sync for ISP */ 12964087Smjacob#define SYNC_SFORCPU 3 /* scratch, sync for CPU */ 13064087Smjacob#define SYNC_REG 4 /* for registers */ 131163899Smjacob#define SYNC_ATIOQ 5 /* atio result queue (24xx) */ 13264087Smjacob 13364087Smjacob/* 13464087Smjacob * Request/Response Queue defines and macros. 13564087Smjacob * The maximum is defined per platform (and can be based on board type). 13664087Smjacob */ 13764087Smjacob/* This is the size of a queue entry (request and response) */ 13839235Sgibbs#define QENTRY_LEN 64 13964087Smjacob/* Both request and result queue length must be a power of two */ 14064087Smjacob#define RQUEST_QUEUE_LEN(x) MAXISPREQUEST(x) 14193706Smjacob#ifdef ISP_TARGET_MODE 14293706Smjacob#define RESULT_QUEUE_LEN(x) MAXISPREQUEST(x) 14393706Smjacob#else 14464087Smjacob#define RESULT_QUEUE_LEN(x) \ 14564087Smjacob (((MAXISPREQUEST(x) >> 2) < 64)? 64 : MAXISPREQUEST(x) >> 2) 14693706Smjacob#endif 147155704Smjacob#define ISP_QUEUE_ENTRY(q, idx) (((uint8_t *)q) + ((idx) * QENTRY_LEN)) 14839235Sgibbs#define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN) 14939235Sgibbs#define ISP_NXT_QENTRY(idx, qlen) (((idx) + 1) & ((qlen)-1)) 15065140Smjacob#define ISP_QFREE(in, out, qlen) \ 15139235Sgibbs ((in == out)? (qlen - 1) : ((in > out)? \ 15252347Smjacob ((qlen - 1) - (in - out)) : (out - in - 1))) 15365140Smjacob#define ISP_QAVAIL(isp) \ 15465140Smjacob ISP_QFREE(isp->isp_reqidx, isp->isp_reqodx, RQUEST_QUEUE_LEN(isp)) 15553487Smjacob 15687635Smjacob#define ISP_ADD_REQUEST(isp, nxti) \ 15787635Smjacob MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN); \ 158163899Smjacob ISP_WRITE(isp, isp->isp_rqstinrp, nxti); \ 15987635Smjacob isp->isp_reqidx = nxti 16053487Smjacob 16135388Smjacob/* 16246968Smjacob * SCSI Specific Host Adapter Parameters- per bus, per target 16335388Smjacob */ 16435388Smjacobtypedef struct { 165167821Smjacob uint32_t : 10, 166167821Smjacob isp_bad_nvram : 1, 167167821Smjacob isp_gotdparms : 1, 16852347Smjacob isp_req_ack_active_neg : 1, 16952347Smjacob isp_data_line_active_neg: 1, 17035388Smjacob isp_cmd_dma_burst_enable: 1, 17135388Smjacob isp_data_dma_burst_enabl: 1, 17242461Smjacob isp_fifo_threshold : 3, 173163899Smjacob isp_ptisp : 1, 17443420Smjacob isp_ultramode : 1, 17535388Smjacob isp_diffmode : 1, 17645040Smjacob isp_lvdmode : 1, 17765140Smjacob isp_fast_mttr : 1, /* fast sram */ 17835388Smjacob isp_initiator_id : 4, 17952347Smjacob isp_async_data_setup : 4; 180155704Smjacob uint16_t isp_selection_timeout; 181155704Smjacob uint16_t isp_max_queue_depth; 182155704Smjacob uint8_t isp_tag_aging; 183155704Smjacob uint8_t isp_bus_reset_delay; 184155704Smjacob uint8_t isp_retry_count; 185155704Smjacob uint8_t isp_retry_delay; 18635388Smjacob struct { 187155704Smjacob uint32_t 18880582Smjacob exc_throttle : 8, 18946968Smjacob : 1, 19080582Smjacob dev_enable : 1, /* ignored */ 19143420Smjacob dev_update : 1, 19243420Smjacob dev_refresh : 1, 19380582Smjacob actv_offset : 4, 19480582Smjacob goal_offset : 4, 19580582Smjacob nvrm_offset : 4; 196155704Smjacob uint8_t actv_period; /* current sync period */ 197155704Smjacob uint8_t goal_period; /* goal sync period */ 198155704Smjacob uint8_t nvrm_period; /* nvram sync period */ 199155704Smjacob uint16_t actv_flags; /* current device flags */ 200155704Smjacob uint16_t goal_flags; /* goal device flags */ 201155704Smjacob uint16_t nvrm_flags; /* nvram device flags */ 20235388Smjacob } isp_devparam[MAX_TARGETS]; 20346968Smjacob} sdparam; 20435388Smjacob 20535388Smjacob/* 20635388Smjacob * Device Flags 20735388Smjacob */ 20839235Sgibbs#define DPARM_DISC 0x8000 20939235Sgibbs#define DPARM_PARITY 0x4000 21039235Sgibbs#define DPARM_WIDE 0x2000 21139235Sgibbs#define DPARM_SYNC 0x1000 21239235Sgibbs#define DPARM_TQING 0x0800 21339235Sgibbs#define DPARM_ARQ 0x0400 21439235Sgibbs#define DPARM_QFRZ 0x0200 21539235Sgibbs#define DPARM_RENEG 0x0100 21665140Smjacob#define DPARM_NARROW 0x0080 21765140Smjacob#define DPARM_ASYNC 0x0040 21865140Smjacob#define DPARM_PPR 0x0020 21943793Smjacob#define DPARM_DEFAULT (0xFF00 & ~DPARM_QFRZ) 22039235Sgibbs#define DPARM_SAFE_DFLT (DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING)) 22135388Smjacob 22245040Smjacob/* technically, not really correct, as they need to be rated based upon clock */ 22365140Smjacob#define ISP_80M_SYNCPARMS 0x0c09 22465140Smjacob#define ISP_40M_SYNCPARMS 0x0c0a 22565140Smjacob#define ISP_20M_SYNCPARMS 0x0c0c 22665140Smjacob#define ISP_20M_SYNCPARMS_1040 0x080c 22752347Smjacob#define ISP_10M_SYNCPARMS 0x0c19 22852347Smjacob#define ISP_08M_SYNCPARMS 0x0c25 22952347Smjacob#define ISP_05M_SYNCPARMS 0x0c32 23052347Smjacob#define ISP_04M_SYNCPARMS 0x0c41 23135388Smjacob 23235388Smjacob/* 23335388Smjacob * Fibre Channel Specifics 23435388Smjacob */ 235164909Smjacob/* These are for non-2K Login Firmware cards */ 236163899Smjacob#define FL_ID 0x7e /* FL_Port Special ID */ 237163899Smjacob#define SNS_ID 0x80 /* SNS Server Special ID */ 238163899Smjacob#define NPH_MAX 0xfe 23952347Smjacob 240164909Smjacob/* These are for 2K Login Firmware cards */ 241163899Smjacob#define NPH_RESERVED 0x7F0 /* begin of reserved N-port handles */ 242163899Smjacob#define NPH_MGT_ID 0x7FA /* Management Server Special ID */ 243163899Smjacob#define NPH_SNS_ID 0x7FC /* SNS Server Special ID */ 244163899Smjacob#define NPH_FL_ID 0x7FE /* FL Port Special ID */ 245164909Smjacob#define NPH_MAX_2K 0x800 24693837Smjacob 247163899Smjacob/* 248164909Smjacob * "Unassigned" handle to be used internally 249164909Smjacob */ 250164909Smjacob#define NIL_HANDLE 0xffff 251164909Smjacob 252164909Smjacob/* 253163899Smjacob * Limit for devices on an arbitrated loop. 254163899Smjacob */ 255163899Smjacob#define LOCAL_LOOP_LIM 126 256163899Smjacob 257163899Smjacob/* 258163899Smjacob * Special Port IDs 259163899Smjacob */ 260163899Smjacob#define MANAGEMENT_PORT_ID 0xFFFFFA 261163899Smjacob#define SNS_PORT_ID 0xFFFFFC 262163899Smjacob#define FABRIC_PORT_ID 0xFFFFFE 263163899Smjacob 264163899Smjacob 265163899Smjacob/* 266163899Smjacob * FC Port Database entry. 267163899Smjacob * 268163899Smjacob * It has a handle that the f/w uses to address commands to a device. 269163899Smjacob * This handle's value may be assigned by the firmware (e.g., for local loop 270163899Smjacob * devices) or by the driver (e.g., for fabric devices). 271163899Smjacob * 272163899Smjacob * It has a state. If the state if VALID, that means that we've logged into 273163899Smjacob * the device. We also *may* have a initiator map index entry. This is a value 274163899Smjacob * from 0..MAX_FC_TARG that is used to index into the isp_ini_map array. If 275163899Smjacob * the value therein is non-zero, then that value minus one is used to index 276163899Smjacob * into the Port Database to find the handle for forming commands. There is 277163899Smjacob * back-index minus one value within to Port Database entry that tells us 278163899Smjacob * which entry in isp_ini_map points to us (to avoid searching). 279163899Smjacob * 280163899Smjacob * Local loop devices the firmware automatically performs PLOGI on for us 281163899Smjacob * (which is why that handle is imposed upon us). Fabric devices we assign 282163899Smjacob * a handle to and perform the PLOGI on. 283163899Smjacob * 284163899Smjacob * When a PORT DATABASE CHANGED asynchronous event occurs, we mark all VALID 285163899Smjacob * entries as PROBATIONAL. This allows us, if policy says to, just keep track 286163899Smjacob * of devices whose handles change but are otherwise the same device (and 287163899Smjacob * thus keep 'target' constant). 288163899Smjacob * 289163899Smjacob * In any case, we search all possible local loop handles. For each one that 290163899Smjacob * has a port database entity returned, we search for any PROBATIONAL entry 291163899Smjacob * that matches it and update as appropriate. Otherwise, as a new entry, we 292163899Smjacob * find room for it in the Port Database. We *try* and use the handle as the 293163899Smjacob * index to put it into the Database, but that's just an optimization. We mark 294163899Smjacob * the entry VALID and make sure that the target index is updated and correct. 295163899Smjacob * 296163899Smjacob * When we get done searching the local loop, we then search similarily for 297163899Smjacob * a list of devices we've gotten from the fabric name controller (if we're 298163899Smjacob * on a fabric). VALID marking is also done similarily. 299163899Smjacob * 300163899Smjacob * When all of this is done, we can march through the database and clean up 301163899Smjacob * any entry that is still PROBATIONAL (these represent devices which have 302163899Smjacob * departed). Then we're done and can resume normal operations. 303163899Smjacob * 304163899Smjacob * Negative invariants that we try and test for are: 305163899Smjacob * 306163899Smjacob * + There can never be two non-NIL entries with the same { Port, Node } WWN 307163899Smjacob * duples. 308163899Smjacob * 309163899Smjacob * + There can never be two non-NIL entries with the same handle. 310163899Smjacob * 311163899Smjacob * + There can never be two non-NIL entries which have the same ini_map_idx 312163899Smjacob * value. 313163899Smjacob */ 31435388Smjacobtypedef struct { 315164272Smjacob /* 316164272Smjacob * This is the handle that the firmware needs in order for us to 317164272Smjacob * send commands to the device. For pre-24XX cards, this would be 318164272Smjacob * the 'loopid'. 319164272Smjacob */ 320163899Smjacob uint16_t handle; 321164272Smjacob /* 322164272Smjacob * The ini_map_idx, if nonzero, is the system virtual target ID (+1) 323164272Smjacob * as a cross-reference with the isp_ini_map. 324164272Smjacob * 325164272Smjacob * A device is 'autologin' if the firmware automatically logs into 326164272Smjacob * it (re-logins as needed). Basically, local private loop devices. 327164272Smjacob * 328164272Smjacob * The state is the current state of thsi entry. 329164272Smjacob * 330164272Smjacob * Role is Initiator, Target, Both 331164272Smjacob * 332164272Smjacob * Portid is obvious, as or node && port WWNs. The new_role and 333164272Smjacob * new_portid is for when we are pending a change. 334164272Smjacob */ 335163899Smjacob uint16_t ini_map_idx : 12, 336163899Smjacob autologin : 1, /* F/W does PLOGI/PLOGO */ 337163899Smjacob state : 3; 338164272Smjacob uint32_t reserved : 6, 339163899Smjacob roles : 2, 340163899Smjacob portid : 24; 341164272Smjacob uint32_t new_reserved : 6, 342163899Smjacob new_roles : 2, 343163899Smjacob new_portid : 24; 344163899Smjacob uint64_t node_wwn; 345163899Smjacob uint64_t port_wwn; 346163899Smjacob} fcportdb_t; 347163899Smjacob 348163899Smjacob#define FC_PORTDB_STATE_NIL 0 349163899Smjacob#define FC_PORTDB_STATE_PROBATIONAL 1 350163899Smjacob#define FC_PORTDB_STATE_DEAD 2 351163899Smjacob#define FC_PORTDB_STATE_CHANGED 3 352163899Smjacob#define FC_PORTDB_STATE_NEW 4 353163899Smjacob#define FC_PORTDB_STATE_PENDING_VALID 5 354164272Smjacob#define FC_PORTDB_STATE_ZOMBIE 6 355163899Smjacob#define FC_PORTDB_STATE_VALID 7 356163899Smjacob 357163899Smjacob/* 358163899Smjacob * FC card specific information 359163899Smjacob */ 360163899Smjacobtypedef struct { 361163899Smjacob uint32_t : 10, 362163899Smjacob isp_tmode : 1, 363163899Smjacob isp_2klogin : 1, 364163899Smjacob isp_sccfw : 1, 365154704Smjacob isp_gbspeed : 3, 366160080Smjacob : 1, 367163899Smjacob : 1, 368167821Smjacob isp_gotdparms : 1, 369167821Smjacob isp_bad_nvram : 1, 37077776Smjacob isp_loopstate : 4, /* Current Loop State */ 371160080Smjacob isp_fwstate : 4, /* ISP F/W state */ 37259454Smjacob isp_topo : 3, 373163899Smjacob loop_seen_once : 1; 374155704Smjacob uint32_t : 8, 375154704Smjacob isp_portid : 24; /* S_ID */ 376155704Smjacob uint16_t isp_fwoptions; 377160080Smjacob uint16_t isp_xfwoptions; 378160080Smjacob uint16_t isp_zfwoptions; 379155704Smjacob uint16_t isp_loopid; /* hard loop id */ 380155704Smjacob uint16_t isp_fwattr; /* firmware attributes */ 381158813Smjacob uint16_t isp_execthrottle; 382155704Smjacob uint8_t isp_retry_delay; 383155704Smjacob uint8_t isp_retry_count; 384155704Smjacob uint8_t isp_reserved; 385155704Smjacob uint16_t isp_maxalloc; 386155704Smjacob uint16_t isp_maxfrmlen; 387166120Smjacob uint64_t isp_wwnn_nvram; 388166120Smjacob uint64_t isp_wwpn_nvram; 389164272Smjacob 390164272Smjacob /* 391164272Smjacob * Our Port Data Base 392164272Smjacob */ 393163899Smjacob fcportdb_t portdb[MAX_FC_TARG]; 394164272Smjacob 395164272Smjacob /* 396164272Smjacob * This maps system virtual 'target' id to a portdb entry. 397164272Smjacob * 398164272Smjacob * The mapping function is to take any non-zero entry and 399164272Smjacob * subtract one to get the portdb index. This means that 400164272Smjacob * entries which are zero are unmapped (i.e., don't exist). 401164272Smjacob */ 402163899Smjacob uint16_t isp_ini_map[MAX_FC_TARG]; 403164272Smjacob 40435388Smjacob /* 40535388Smjacob * Scratch DMA mapped in area to fetch Port Database stuff, etc. 40635388Smjacob */ 407155704Smjacob void * isp_scratch; 408155704Smjacob XS_DMA_ADDR_T isp_scdma; 40990752Smjacob#ifdef ISP_FW_CRASH_DUMP 410155704Smjacob uint16_t * isp_dump_data; 41190752Smjacob#endif 41235388Smjacob} fcparam; 41335388Smjacob 41448484Smjacob#define FW_CONFIG_WAIT 0 41548484Smjacob#define FW_WAIT_AL_PA 1 41648484Smjacob#define FW_WAIT_LOGIN 2 41748484Smjacob#define FW_READY 3 41848484Smjacob#define FW_LOSS_OF_SYNC 4 41948484Smjacob#define FW_ERROR 5 42048484Smjacob#define FW_REINIT 6 42148484Smjacob#define FW_NON_PART 7 42235388Smjacob 42348484Smjacob#define LOOP_NIL 0 42448484Smjacob#define LOOP_LIP_RCVD 1 42548484Smjacob#define LOOP_PDB_RCVD 2 426163899Smjacob#define LOOP_SCANNING_LOOP 3 427163899Smjacob#define LOOP_LSCAN_DONE 4 428163899Smjacob#define LOOP_SCANNING_FABRIC 5 429163899Smjacob#define LOOP_FSCAN_DONE 6 43077776Smjacob#define LOOP_SYNCING_PDB 7 43177776Smjacob#define LOOP_READY 8 43235388Smjacob 43359454Smjacob#define TOPO_NL_PORT 0 43459454Smjacob#define TOPO_FL_PORT 1 43559454Smjacob#define TOPO_N_PORT 2 43659454Smjacob#define TOPO_F_PORT 3 43759454Smjacob#define TOPO_PTP_STUB 4 43859454Smjacob 43942131Smjacob/* 44035388Smjacob * Soft Structure per host adapter 44135388Smjacob */ 442155704Smjacobstruct ispsoftc { 44335388Smjacob /* 44435388Smjacob * Platform (OS) specific data 44535388Smjacob */ 44635388Smjacob struct isposinfo isp_osinfo; 44735388Smjacob 44835388Smjacob /* 44953487Smjacob * Pointer to bus specific functions and data 45035388Smjacob */ 45135388Smjacob struct ispmdvec * isp_mdvec; 45235388Smjacob 45335388Smjacob /* 45453487Smjacob * (Mostly) nonvolatile state. Board specific parameters 45553487Smjacob * may contain some volatile state (e.g., current loop state). 45635388Smjacob */ 45735388Smjacob 45853487Smjacob void * isp_param; /* type specific */ 459155704Smjacob uint16_t isp_fwrev[3]; /* Loaded F/W revision */ 460155704Smjacob uint16_t isp_romfw_rev[3]; /* PROM F/W revision */ 461155704Smjacob uint16_t isp_maxcmds; /* max possible I/O cmds */ 462155704Smjacob uint8_t isp_type; /* HBA Chip Type */ 463155704Smjacob uint8_t isp_revision; /* HBA Chip H/W Revision */ 464155704Smjacob uint32_t isp_maxluns; /* maximum luns supported */ 46535388Smjacob 466155704Smjacob uint32_t isp_clock : 8, /* input clock */ 46790224Smjacob : 4, 468163899Smjacob isp_port : 1, /* 23XX/24XX only */ 46987635Smjacob isp_failed : 1, /* board failed */ 47087635Smjacob isp_open : 1, /* opened (ioctl) */ 47153487Smjacob isp_touched : 1, /* board ever seen? */ 47253487Smjacob isp_bustype : 1, /* SBus or PCI */ 47365140Smjacob isp_loaded_fw : 1, /* loaded firmware */ 47487635Smjacob isp_role : 2, /* roles supported */ 47571079Smjacob isp_dblev : 12; /* debug log mask */ 47671079Smjacob 477155704Smjacob uint32_t isp_confopts; /* config options */ 47871079Smjacob 479163899Smjacob uint32_t isp_rqstinrp; /* register for REQINP */ 480163899Smjacob uint32_t isp_rqstoutrp; /* register for REQOUTP */ 481163899Smjacob uint32_t isp_respinrp; /* register for RESINP */ 482163899Smjacob uint32_t isp_respoutrp; /* register for RESOUTP */ 483163899Smjacob uint32_t isp_atioinrp; /* register for ATIOINP */ 484163899Smjacob uint32_t isp_atiooutrp; /* register for ATIOOUTP */ 48582689Smjacob 48669522Smjacob /* 48769522Smjacob * Instrumentation 48869522Smjacob */ 489155704Smjacob uint64_t isp_intcnt; /* total int count */ 490155704Smjacob uint64_t isp_intbogus; /* spurious int count */ 491155704Smjacob uint64_t isp_intmboxc; /* mbox completions */ 492155704Smjacob uint64_t isp_intoasync; /* other async */ 493155704Smjacob uint64_t isp_rsltccmplt; /* CMDs on result q */ 494155704Smjacob uint64_t isp_fphccmplt; /* CMDs via fastpost */ 495155704Smjacob uint16_t isp_rscchiwater; 496155704Smjacob uint16_t isp_fpcchiwater; 49739235Sgibbs 49835388Smjacob /* 49939235Sgibbs * Volatile state 50035388Smjacob */ 50135388Smjacob 502160080Smjacob volatile uint32_t : 8, 50387635Smjacob isp_mboxbsy : 1, /* mailbox command active */ 50439235Sgibbs isp_state : 3, 50546968Smjacob isp_sendmarker : 2, /* send a marker entry */ 50646968Smjacob isp_update : 2, /* update parameters */ 50752347Smjacob isp_nactive : 16; /* how many commands active */ 508163899Smjacob volatile uint32_t isp_reqodx; /* index of last ISP pickup */ 509163899Smjacob volatile uint32_t isp_reqidx; /* index of next request */ 510163899Smjacob volatile uint32_t isp_residx; /* index of next result */ 511163899Smjacob volatile uint32_t isp_resodx; /* index of next result */ 512163899Smjacob volatile uint32_t isp_rspbsy; 513163899Smjacob volatile uint32_t isp_lasthdls; /* last handle seed */ 514163899Smjacob volatile uint32_t isp_obits; /* mailbox command output */ 515155704Smjacob volatile uint16_t isp_mboxtmp[MAILBOX_STORAGE]; 516155704Smjacob volatile uint16_t isp_lastmbxcmd; /* last mbox command sent */ 517155704Smjacob volatile uint16_t isp_mbxwrk0; 518155704Smjacob volatile uint16_t isp_mbxwrk1; 519155704Smjacob volatile uint16_t isp_mbxwrk2; 520160080Smjacob volatile uint16_t isp_mbxwrk8; 52190224Smjacob void * isp_mbxworkp; 52235388Smjacob 52335388Smjacob /* 52453487Smjacob * Active commands are stored here, indexed by handle functions. 52535388Smjacob */ 52664087Smjacob XS_T **isp_xflist; 52735388Smjacob 528129643Snjl#ifdef ISP_TARGET_MODE 52935388Smjacob /* 530129643Snjl * Active target commands are stored here, indexed by handle function. 531129643Snjl */ 532129643Snjl void **isp_tgtlist; 533129643Snjl#endif 534129643Snjl 535129643Snjl /* 536120018Smjacob * request/result queue pointers and DMA handles for them. 53735388Smjacob */ 538155704Smjacob void * isp_rquest; 539155704Smjacob void * isp_result; 540155704Smjacob XS_DMA_ADDR_T isp_rquest_dma; 541155704Smjacob XS_DMA_ADDR_T isp_result_dma; 542163899Smjacob#ifdef ISP_TARGET_MODE 543163899Smjacob /* for 24XX only */ 544163899Smjacob void * isp_atioq; 545163899Smjacob XS_DMA_ADDR_T isp_atioq_dma; 546163899Smjacob#endif 547155704Smjacob}; 54835388Smjacob 54949909Smjacob#define SDPARAM(isp) ((sdparam *) (isp)->isp_param) 55049909Smjacob#define FCPARAM(isp) ((fcparam *) (isp)->isp_param) 55149909Smjacob 55235388Smjacob/* 55364087Smjacob * ISP Driver Run States 55435388Smjacob */ 55535388Smjacob#define ISP_NILSTATE 0 556160080Smjacob#define ISP_CRASHED 1 557160080Smjacob#define ISP_RESETSTATE 2 558160080Smjacob#define ISP_INITSTATE 3 559160080Smjacob#define ISP_RUNSTATE 4 56035388Smjacob 56135388Smjacob/* 56235388Smjacob * ISP Configuration Options 56335388Smjacob */ 56435388Smjacob#define ISP_CFG_NORELOAD 0x80 /* don't download f/w */ 56543793Smjacob#define ISP_CFG_NONVRAM 0x40 /* ignore NVRAM */ 56684241Smjacob#define ISP_CFG_TWOGB 0x20 /* force 2GB connection (23XX only) */ 56784241Smjacob#define ISP_CFG_ONEGB 0x10 /* force 1GB connection (23XX only) */ 56853487Smjacob#define ISP_CFG_FULL_DUPLEX 0x01 /* Full Duplex (Fibre Channel only) */ 56969522Smjacob#define ISP_CFG_PORT_PREF 0x0C /* Mask for Port Prefs (2200 only) */ 57069522Smjacob#define ISP_CFG_LPORT 0x00 /* prefer {N/F}L-Port connection */ 57169522Smjacob#define ISP_CFG_NPORT 0x04 /* prefer {N/F}-Port connection */ 57269522Smjacob#define ISP_CFG_NPORT_ONLY 0x08 /* insist on {N/F}-Port connection */ 57369522Smjacob#define ISP_CFG_LPORT_ONLY 0x0C /* insist on {N/F}L-Port connection */ 57490752Smjacob#define ISP_CFG_OWNWWPN 0x100 /* override NVRAM wwpn */ 57590752Smjacob#define ISP_CFG_OWNWWNN 0x200 /* override NVRAM wwnn */ 57698281Smjacob#define ISP_CFG_OWNFSZ 0x400 /* override NVRAM frame size */ 57798281Smjacob#define ISP_CFG_OWNLOOPID 0x800 /* override NVRAM loopid */ 57898281Smjacob#define ISP_CFG_OWNEXCTHROTTLE 0x1000 /* override NVRAM execution throttle */ 579163899Smjacob#define ISP_CFG_FOURGB 0x2000 /* force 4GB connection (24XX only) */ 58035388Smjacob 58164087Smjacob/* 58271079Smjacob * Prior to calling isp_reset for the first time, the outer layer 58371079Smjacob * should set isp_role to one of NONE, INITIATOR, TARGET, BOTH. 58471079Smjacob * 58571079Smjacob * If you set ISP_ROLE_NONE, the cards will be reset, new firmware loaded, 58671079Smjacob * NVRAM read, and defaults set, but any further initialization (e.g. 58771079Smjacob * INITIALIZE CONTROL BLOCK commands for 2X00 cards) won't be done. 58871079Smjacob * 58971079Smjacob * If INITIATOR MODE isn't set, attempts to run commands will be stopped 59071079Smjacob * at isp_start and completed with the moral equivalent of SELECTION TIMEOUT. 59171079Smjacob * 59271079Smjacob * If TARGET MODE is set, it doesn't mean that the rest of target mode support 59371079Smjacob * needs to be enabled, or will even work. What happens with the 2X00 cards 59471079Smjacob * here is that if you have enabled it with TARGET MODE as part of the ICB 59571079Smjacob * options, but you haven't given the f/w any ram resources for ATIOs or 59671079Smjacob * Immediate Notifies, the f/w just handles what it can and you never see 59771079Smjacob * anything. Basically, it sends a single byte of data (the first byte, 59871079Smjacob * which you can set as part of the INITIALIZE CONTROL BLOCK command) for 59971079Smjacob * INQUIRY, and sends back QUEUE FULL status for any other command. 60079235Smjacob * 60171079Smjacob */ 60271079Smjacob#define ISP_ROLE_NONE 0x0 603125544Smjacob#define ISP_ROLE_TARGET 0x1 604125544Smjacob#define ISP_ROLE_INITIATOR 0x2 60571079Smjacob#define ISP_ROLE_BOTH (ISP_ROLE_TARGET|ISP_ROLE_INITIATOR) 60671079Smjacob#define ISP_ROLE_EITHER ISP_ROLE_BOTH 60771079Smjacob#ifndef ISP_DEFAULT_ROLES 60871079Smjacob#define ISP_DEFAULT_ROLES ISP_ROLE_INITIATOR 60971079Smjacob#endif 61071079Smjacob 61171079Smjacob 61271079Smjacob/* 61364087Smjacob * Firmware related defines 61464087Smjacob */ 61571079Smjacob#define ISP_CODE_ORG 0x1000 /* default f/w code start */ 61682689Smjacob#define ISP_CODE_ORG_2300 0x0800 /* ..except for 2300s */ 617163899Smjacob#define ISP_CODE_ORG_2400 0x100000 /* ..and 2400s */ 61845282Smjacob#define ISP_FW_REV(maj, min, mic) ((maj << 24) | (min << 16) | mic) 61982841Smjacob#define ISP_FW_MAJOR(code) ((code >> 24) & 0xff) 62082841Smjacob#define ISP_FW_MINOR(code) ((code >> 16) & 0xff) 62182841Smjacob#define ISP_FW_MICRO(code) ((code >> 8) & 0xff) 62271079Smjacob#define ISP_FW_REVX(xp) ((xp[0]<<24) | (xp[1] << 16) | xp[2]) 62382841Smjacob#define ISP_FW_MAJORX(xp) (xp[0]) 62482841Smjacob#define ISP_FW_MINORX(xp) (xp[1]) 62582841Smjacob#define ISP_FW_MICROX(xp) (xp[2]) 626102012Smjacob#define ISP_FW_NEWER_THAN(i, major, minor, micro) \ 627102012Smjacob (ISP_FW_REVX((i)->isp_fwrev) > ISP_FW_REV(major, minor, micro)) 628163899Smjacob#define ISP_FW_OLDER_THAN(i, major, minor, micro) \ 629163899Smjacob (ISP_FW_REVX((i)->isp_fwrev) < ISP_FW_REV(major, minor, micro)) 63039235Sgibbs 63135388Smjacob/* 63239235Sgibbs * Bus (implementation) types 63335388Smjacob */ 63439235Sgibbs#define ISP_BT_PCI 0 /* PCI Implementations */ 63539235Sgibbs#define ISP_BT_SBUS 1 /* SBus Implementations */ 63639235Sgibbs 63739235Sgibbs/* 63887635Smjacob * If we have not otherwise defined SBus support away make sure 63987635Smjacob * it is defined here such that the code is included as default 64087635Smjacob */ 64187635Smjacob#ifndef ISP_SBUS_SUPPORTED 64287635Smjacob#define ISP_SBUS_SUPPORTED 1 64387635Smjacob#endif 64487635Smjacob 64587635Smjacob/* 64639235Sgibbs * Chip Types 64739235Sgibbs */ 64835388Smjacob#define ISP_HA_SCSI 0xf 64939235Sgibbs#define ISP_HA_SCSI_UNKNOWN 0x1 65039235Sgibbs#define ISP_HA_SCSI_1020 0x2 65139235Sgibbs#define ISP_HA_SCSI_1020A 0x3 65239235Sgibbs#define ISP_HA_SCSI_1040 0x4 65339235Sgibbs#define ISP_HA_SCSI_1040A 0x5 65439235Sgibbs#define ISP_HA_SCSI_1040B 0x6 65545282Smjacob#define ISP_HA_SCSI_1040C 0x7 65654671Smjacob#define ISP_HA_SCSI_1240 0x8 65754671Smjacob#define ISP_HA_SCSI_1080 0x9 65854671Smjacob#define ISP_HA_SCSI_1280 0xa 659104916Smjacob#define ISP_HA_SCSI_10160 0xb 660104916Smjacob#define ISP_HA_SCSI_12160 0xc 66135388Smjacob#define ISP_HA_FC 0xf0 66235388Smjacob#define ISP_HA_FC_2100 0x10 66348484Smjacob#define ISP_HA_FC_2200 0x20 66477365Smjacob#define ISP_HA_FC_2300 0x30 66588855Smjacob#define ISP_HA_FC_2312 0x40 666154704Smjacob#define ISP_HA_FC_2322 0x50 667154704Smjacob#define ISP_HA_FC_2400 0x60 66835388Smjacob 66944819Smjacob#define IS_SCSI(isp) (isp->isp_type & ISP_HA_SCSI) 67054671Smjacob#define IS_1240(isp) (isp->isp_type == ISP_HA_SCSI_1240) 67144819Smjacob#define IS_1080(isp) (isp->isp_type == ISP_HA_SCSI_1080) 67254671Smjacob#define IS_1280(isp) (isp->isp_type == ISP_HA_SCSI_1280) 673104916Smjacob#define IS_10160(isp) (isp->isp_type == ISP_HA_SCSI_10160) 67457145Smjacob#define IS_12160(isp) (isp->isp_type == ISP_HA_SCSI_12160) 67557145Smjacob 67657145Smjacob#define IS_12X0(isp) (IS_1240(isp) || IS_1280(isp)) 677104916Smjacob#define IS_1X160(isp) (IS_10160(isp) || IS_12160(isp)) 67857145Smjacob#define IS_DUALBUS(isp) (IS_12X0(isp) || IS_12160(isp)) 679104916Smjacob#define IS_ULTRA2(isp) (IS_1080(isp) || IS_1280(isp) || IS_1X160(isp)) 680104916Smjacob#define IS_ULTRA3(isp) (IS_1X160(isp)) 68157145Smjacob 68277365Smjacob#define IS_FC(isp) ((isp)->isp_type & ISP_HA_FC) 68377365Smjacob#define IS_2100(isp) ((isp)->isp_type == ISP_HA_FC_2100) 68477365Smjacob#define IS_2200(isp) ((isp)->isp_type == ISP_HA_FC_2200) 685163899Smjacob#define IS_23XX(isp) ((isp)->isp_type >= ISP_HA_FC_2300 && \ 686163899Smjacob (isp)->isp_type < ISP_HA_FC_2400) 68788855Smjacob#define IS_2300(isp) ((isp)->isp_type == ISP_HA_FC_2300) 68888855Smjacob#define IS_2312(isp) ((isp)->isp_type == ISP_HA_FC_2312) 689154704Smjacob#define IS_2322(isp) ((isp)->isp_type == ISP_HA_FC_2322) 690154704Smjacob#define IS_24XX(isp) ((isp)->isp_type >= ISP_HA_FC_2400) 69144819Smjacob 69264087Smjacob/* 693155704Smjacob * DMA related macros 69464087Smjacob */ 695163899Smjacob#define DMA_WD3(x) (((uint16_t)(((uint64_t)x) >> 48)) & 0xffff) 696163899Smjacob#define DMA_WD2(x) (((uint16_t)(((uint64_t)x) >> 32)) & 0xffff) 697163899Smjacob#define DMA_WD1(x) ((uint16_t)((x) >> 16) & 0xffff) 698163899Smjacob#define DMA_WD0(x) ((uint16_t)((x) & 0xffff)) 69957145Smjacob 700155704Smjacob#define DMA_LO32(x) ((uint32_t) (x)) 701155704Smjacob#define DMA_HI32(x) ((uint32_t)(((uint64_t)x) >> 32)) 702155704Smjacob 70335388Smjacob/* 70464087Smjacob * Core System Function Prototypes 70535388Smjacob */ 70635388Smjacob 70735388Smjacob/* 70839235Sgibbs * Reset Hardware. Totally. Assumes that you'll follow this with 70939235Sgibbs * a call to isp_init. 71035388Smjacob */ 711155704Smjacobvoid isp_reset(ispsoftc_t *); 71235388Smjacob 71335388Smjacob/* 71435388Smjacob * Initialize Hardware to known state 71535388Smjacob */ 716155704Smjacobvoid isp_init(ispsoftc_t *); 71735388Smjacob 71835388Smjacob/* 71939235Sgibbs * Reset the ISP and call completion for any orphaned commands. 72039235Sgibbs */ 721155704Smjacobvoid isp_reinit(ispsoftc_t *); 72239235Sgibbs 72390752Smjacob#ifdef ISP_FW_CRASH_DUMP 72439235Sgibbs/* 72590752Smjacob * Dump firmware entry point. 72690752Smjacob */ 727155704Smjacobvoid isp_fw_dump(ispsoftc_t *isp); 72890752Smjacob#endif 72990752Smjacob 73090752Smjacob/* 73182689Smjacob * Internal Interrupt Service Routine 73282689Smjacob * 73382689Smjacob * The outer layers do the spade work to get the appropriate status register, 73482689Smjacob * semaphore register and first mailbox register (if appropriate). This also 73582689Smjacob * means that most spurious/bogus interrupts not for us can be filtered first. 73635388Smjacob */ 737163899Smjacobvoid isp_intr(ispsoftc_t *, uint32_t, uint16_t, uint16_t); 73835388Smjacob 73982689Smjacob 74035388Smjacob/* 74164087Smjacob * Command Entry Point- Platform Dependent layers call into this 74235388Smjacob */ 74374229Smjacobint isp_start(XS_T *); 744155704Smjacob 74564087Smjacob/* these values are what isp_start returns */ 74664087Smjacob#define CMD_COMPLETE 101 /* command completed */ 74764087Smjacob#define CMD_EAGAIN 102 /* busy- maybe retry later */ 74864087Smjacob#define CMD_QUEUED 103 /* command has been queued for execution */ 74964087Smjacob#define CMD_RQLATER 104 /* requeue this command later */ 75035388Smjacob 75139235Sgibbs/* 75264087Smjacob * Command Completion Point- Core layers call out from this with completed cmds 75364087Smjacob */ 75474229Smjacobvoid isp_done(XS_T *); 75564087Smjacob 75664087Smjacob/* 75743420Smjacob * Platform Dependent to External to Internal Control Function 75839235Sgibbs * 75972355Smjacob * Assumes locks are held on entry. You should note that with many of 76072355Smjacob * these commands and locks may be released while this is occurring. 76139235Sgibbs * 76272355Smjacob * A few notes about some of these functions: 76372355Smjacob * 76472355Smjacob * ISPCTL_FCLINK_TEST tests to make sure we have good fibre channel link. 76572355Smjacob * The argument is a pointer to an integer which is the time, in microseconds, 76672355Smjacob * we should wait to see whether we have good link. This test, if successful, 76772355Smjacob * lets us know our connection topology and our Loop ID/AL_PA and so on. 76872355Smjacob * You can't get anywhere without this. 76972355Smjacob * 77072355Smjacob * ISPCTL_SCAN_FABRIC queries the name server (if we're on a fabric) for 77172355Smjacob * all entities using the FC Generic Services subcommand GET ALL NEXT. 77272355Smjacob * For each found entity, an ISPASYNC_FABRICDEV event is generated (see 77372355Smjacob * below). 77472355Smjacob * 77572355Smjacob * ISPCTL_SCAN_LOOP does a local loop scan. This is only done if the connection 77672355Smjacob * topology is NL or FL port (private or public loop). Since the Qlogic f/w 77772355Smjacob * 'automatically' manages local loop connections, this function essentially 77872355Smjacob * notes the arrival, departure, and possible shuffling around of local loop 77972355Smjacob * entities. Thus for each arrival and departure this generates an isp_async 78072355Smjacob * event of ISPASYNC_PROMENADE (see below). 78172355Smjacob * 78272355Smjacob * ISPCTL_PDB_SYNC is somewhat misnamed. It actually is the final step, in 78372355Smjacob * order, of ISPCTL_FCLINK_TEST, ISPCTL_SCAN_FABRIC, and ISPCTL_SCAN_LOOP. 78472355Smjacob * The main purpose of ISPCTL_PDB_SYNC is to complete management of logging 78572355Smjacob * and logging out of fabric devices (if one is on a fabric) and then marking 78672355Smjacob * the 'loop state' as being ready to now be used for sending commands to 78772355Smjacob * devices. Originally fabric name server and local loop scanning were 78881794Smjacob * part of this function. It's now been separated to allow for finer control. 78939235Sgibbs */ 79039235Sgibbstypedef enum { 79148484Smjacob ISPCTL_RESET_BUS, /* Reset Bus */ 79248484Smjacob ISPCTL_RESET_DEV, /* Reset Device */ 79348484Smjacob ISPCTL_ABORT_CMD, /* Abort Command */ 79472355Smjacob ISPCTL_UPDATE_PARAMS, /* Update Operating Parameters (SCSI) */ 79555364Smjacob ISPCTL_FCLINK_TEST, /* Test FC Link Status */ 79672355Smjacob ISPCTL_SCAN_FABRIC, /* (Re)scan Fabric Name Server */ 79772355Smjacob ISPCTL_SCAN_LOOP, /* (Re)scan Local Loop */ 79855364Smjacob ISPCTL_PDB_SYNC, /* Synchronize Port Database */ 79972355Smjacob ISPCTL_SEND_LIP, /* Send a LIP */ 800163899Smjacob ISPCTL_GET_PORTNAME, /* get portname from an N-port handle */ 80172938Smjacob ISPCTL_RUN_MBOXCMD, /* run a mailbox command */ 802125544Smjacob ISPCTL_TOGGLE_TMODE, /* toggle target mode */ 803164370Smjacob ISPCTL_GET_PDB, /* get a single port database entry */ 804164370Smjacob ISPCTL_PLOGX /* do a port login/logout */ 80539235Sgibbs} ispctl_t; 806155704Smjacobint isp_control(ispsoftc_t *, ispctl_t, void *); 80739235Sgibbs 80843420Smjacob 80939235Sgibbs/* 81043420Smjacob * Platform Dependent to Internal to External Control Function 81143420Smjacob * (each platform must provide such a function) 81243420Smjacob * 81372355Smjacob * Assumes locks are held. 81472355Smjacob * 81572355Smjacob * A few notes about some of these functions: 81672355Smjacob * 81772355Smjacob * ISPASYNC_CHANGE_NOTIFY notifies the outer layer that a change has 81872355Smjacob * occurred that invalidates the list of fabric devices known and/or 81972355Smjacob * the list of known loop devices. The argument passed is a pointer 82072355Smjacob * whose values are defined below (local loop change, name server 82172355Smjacob * change, other). 'Other' may simply be a LIP, or a change in 82272355Smjacob * connection topology. 82372355Smjacob * 82472355Smjacob * ISPASYNC_FABRIC_DEV announces the next element in a list of 82572355Smjacob * fabric device names we're getting out of the name server. The 82672355Smjacob * argument points to a GET ALL NEXT response structure. The list 82772355Smjacob * is known to terminate with an entry that refers to ourselves. 82872355Smjacob * One of the main purposes of this function is to allow outer 82972355Smjacob * layers, which are OS dependent, to set policy as to which fabric 83072355Smjacob * devices might actually be logged into (and made visible) later 83172355Smjacob * at ISPCTL_PDB_SYNC time. Since there's a finite number of fabric 83272355Smjacob * devices that we can log into (256 less 3 'reserved' for F-port 83372355Smjacob * topologies), and fabrics can grow up to 8 million or so entries 83472355Smjacob * (24 bits of Port Address, less a wad of reserved spaces), clearly 83572355Smjacob * we had better let the OS determine login policy. 83672355Smjacob * 83772355Smjacob * ISPASYNC_PROMENADE has an argument that is a pointer to an integer which 838103826Smjacob * is an index into the portdb in the softc ('target'). Whether that entry's 83972355Smjacob * valid tag is set or not says whether something has arrived or departed. 84072355Smjacob * The name refers to a favorite pastime of many city dwellers- watching 84172355Smjacob * people come and go, talking of Michaelangelo, and so on.. 84272938Smjacob * 84372938Smjacob * ISPASYNC_UNHANDLED_RESPONSE gives outer layers a chance to parse a 84472938Smjacob * response queue entry not otherwise handled. The outer layer should 84587635Smjacob * return non-zero if it handled it. The 'arg' points to an unmassaged 84687635Smjacob * response queue entry. 84743420Smjacob */ 84843420Smjacob 84943420Smjacobtypedef enum { 85072355Smjacob ISPASYNC_NEW_TGT_PARAMS, /* New Target Parameters Negotiated */ 85148484Smjacob ISPASYNC_BUS_RESET, /* Bus Was Reset */ 85248484Smjacob ISPASYNC_LOOP_DOWN, /* FC Loop Down */ 85348484Smjacob ISPASYNC_LOOP_UP, /* FC Loop Up */ 85477365Smjacob ISPASYNC_LIP, /* LIP Received */ 85577365Smjacob ISPASYNC_LOOP_RESET, /* Loop Reset Received */ 85672355Smjacob ISPASYNC_CHANGE_NOTIFY, /* FC Change Notification */ 857163899Smjacob ISPASYNC_DEV_ARRIVED, /* FC Device Arrival */ 858163899Smjacob ISPASYNC_DEV_CHANGED, /* FC Device Change */ 859163899Smjacob ISPASYNC_DEV_STAYED, /* FC Device Stayed the Same */ 860163899Smjacob ISPASYNC_DEV_GONE, /* FC Device Depart */ 861154704Smjacob ISPASYNC_TARGET_NOTIFY, /* target asynchronous notification event */ 862154704Smjacob ISPASYNC_TARGET_ACTION, /* target action requested */ 86372938Smjacob ISPASYNC_CONF_CHANGE, /* Platform Configuration Change */ 86479235Smjacob ISPASYNC_UNHANDLED_RESPONSE, /* Unhandled Response Entry */ 86598281Smjacob ISPASYNC_FW_CRASH, /* Firmware has crashed */ 866102012Smjacob ISPASYNC_FW_DUMPED, /* Firmware crashdump taken */ 86798281Smjacob ISPASYNC_FW_RESTARTED /* Firmware has been restarted */ 86843420Smjacob} ispasync_t; 869155704Smjacobint isp_async(ispsoftc_t *, ispasync_t, void *); 87043420Smjacob 87172355Smjacob#define ISPASYNC_CHANGE_PDB ((void *) 0) 87272355Smjacob#define ISPASYNC_CHANGE_SNS ((void *) 1) 87372355Smjacob#define ISPASYNC_CHANGE_OTHER ((void *) 2) 87472355Smjacob 87543420Smjacob/* 87664087Smjacob * Platform Dependent Error and Debug Printout 877146073Smjacob * 878146073Smjacob * Generally this is: 879146073Smjacob * 880155704Smjacob * void isp_prt(ispsoftc_t *, int level, const char *, ...) 881146073Smjacob * 882146073Smjacob * but due to compiler differences on different platforms this won't be 883146073Smjacob * formally done here. Instead, it goes in each platform definition file. 88439235Sgibbs */ 88570490Smjacob 88664087Smjacob#define ISP_LOGALL 0x0 /* log always */ 88764087Smjacob#define ISP_LOGCONFIG 0x1 /* log configuration messages */ 88864087Smjacob#define ISP_LOGINFO 0x2 /* log informational messages */ 88964087Smjacob#define ISP_LOGWARN 0x4 /* log warning messages */ 89064087Smjacob#define ISP_LOGERR 0x8 /* log error messages */ 89164087Smjacob#define ISP_LOGDEBUG0 0x10 /* log simple debug messages */ 89264087Smjacob#define ISP_LOGDEBUG1 0x20 /* log intermediate debug messages */ 89364087Smjacob#define ISP_LOGDEBUG2 0x40 /* log most debug messages */ 89479235Smjacob#define ISP_LOGDEBUG3 0x80 /* log high frequency debug messages */ 895164272Smjacob#define ISP_LOGSANCFG 0x100 /* log SAN configuration */ 89664087Smjacob#define ISP_LOGTDEBUG0 0x200 /* log simple debug messages (target mode) */ 89764087Smjacob#define ISP_LOGTDEBUG1 0x400 /* log intermediate debug messages (target) */ 89864087Smjacob#define ISP_LOGTDEBUG2 0x800 /* log all debug messages (target) */ 89939235Sgibbs 90064087Smjacob/* 90164087Smjacob * Each Platform provides it's own isposinfo substructure of the ispsoftc 90264087Smjacob * defined above. 90364087Smjacob * 90464087Smjacob * Each platform must also provide the following macros/defines: 90564087Smjacob * 90664087Smjacob * 90764087Smjacob * ISP2100_SCRLEN - length for the Fibre Channel scratch DMA area 90864087Smjacob * 90964087Smjacob * MEMZERO(dst, src) platform zeroing function 91064087Smjacob * MEMCPY(dst, src, count) platform copying function 91164087Smjacob * SNPRINTF(buf, bufsize, fmt, ...) snprintf 91264087Smjacob * USEC_DELAY(usecs) microsecond spindelay function 91369522Smjacob * USEC_SLEEP(isp, usecs) microsecond sleep function 91464087Smjacob * 91564087Smjacob * NANOTIME_T nanosecond time type 91664087Smjacob * 91764087Smjacob * GET_NANOTIME(NANOTIME_T *) get current nanotime. 91864087Smjacob * 919155704Smjacob * GET_NANOSEC(NANOTIME_T *) get uint64_t from NANOTIME_T 92064087Smjacob * 92164087Smjacob * NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *) 92264087Smjacob * subtract two NANOTIME_T values 92364087Smjacob * 92464087Smjacob * 925155704Smjacob * MAXISPREQUEST(ispsoftc_t *) maximum request queue size 92664087Smjacob * for this particular board type 92764087Smjacob * 928155704Smjacob * MEMORYBARRIER(ispsoftc_t *, barrier_type, offset, size) 92964087Smjacob * 93064087Smjacob * Function/Macro the provides memory synchronization on 93164087Smjacob * various objects so that the ISP's and the system's view 93264087Smjacob * of the same object is consistent. 93364087Smjacob * 934155704Smjacob * MBOX_ACQUIRE(ispsoftc_t *) acquire lock on mailbox regs 935163899Smjacob * MBOX_WAIT_COMPLETE(ispsoftc_t *, mbreg_t *) wait for cmd to be done 936155704Smjacob * MBOX_NOTIFY_COMPLETE(ispsoftc_t *) notification of mbox cmd donee 937155704Smjacob * MBOX_RELEASE(ispsoftc_t *) release lock on mailbox regs 93864087Smjacob * 939155704Smjacob * FC_SCRATCH_ACQUIRE(ispsoftc_t *) acquire lock on FC scratch area 940155704Smjacob * FC_SCRATCH_RELEASE(ispsoftc_t *) acquire lock on FC scratch area 94172355Smjacob * 94264087Smjacob * SCSI_GOOD SCSI 'Good' Status 94364087Smjacob * SCSI_CHECK SCSI 'Check Condition' Status 94464087Smjacob * SCSI_BUSY SCSI 'Busy' Status 94564087Smjacob * SCSI_QFULL SCSI 'Queue Full' Status 94664087Smjacob * 94764087Smjacob * XS_T Platform SCSI transaction type (i.e., command for HBA) 948155704Smjacob * XS_DMA_ADDR_T Platform PCI DMA Address Type 94964087Smjacob * XS_ISP(xs) gets an instance out of an XS_T 95064087Smjacob * XS_CHANNEL(xs) gets the channel (bus # for DUALBUS cards) "" 95164087Smjacob * XS_TGT(xs) gets the target "" 95264087Smjacob * XS_LUN(xs) gets the lun "" 95364087Smjacob * XS_CDBP(xs) gets a pointer to the scsi CDB "" 95464087Smjacob * XS_CDBLEN(xs) gets the CDB's length "" 95564087Smjacob * XS_XFRLEN(xs) gets the associated data transfer length "" 95664087Smjacob * XS_TIME(xs) gets the time (in milliseconds) for this command 95764087Smjacob * XS_RESID(xs) gets the current residual count 95864087Smjacob * XS_STSP(xs) gets a pointer to the SCSI status byte "" 95964087Smjacob * XS_SNSP(xs) gets a pointer to the associate sense data 96064087Smjacob * XS_SNSLEN(xs) gets the length of sense data storage 96164087Smjacob * XS_SNSKEY(xs) dereferences XS_SNSP to get the current stored Sense Key 96264087Smjacob * XS_TAG_P(xs) predicate of whether this command should be tagged 96364087Smjacob * XS_TAG_TYPE(xs) which type of tag to use 96464087Smjacob * XS_SETERR(xs) set error state 96564087Smjacob * 96664087Smjacob * HBA_NOERROR command has no erros 96764087Smjacob * HBA_BOTCH hba botched something 96864087Smjacob * HBA_CMDTIMEOUT command timed out 96964087Smjacob * HBA_SELTIMEOUT selection timed out (also port logouts for FC) 97064087Smjacob * HBA_TGTBSY target returned a BUSY status 97164087Smjacob * HBA_BUSRESET bus reset destroyed command 97264087Smjacob * HBA_ABORTED command was aborted (by request) 97364087Smjacob * HBA_DATAOVR a data overrun was detected 97464087Smjacob * HBA_ARQFAIL Automatic Request Sense failed 97564087Smjacob * 97664087Smjacob * XS_ERR(xs) return current error state 97764087Smjacob * XS_NOERR(xs) there is no error currently set 97864087Smjacob * XS_INITERR(xs) initialize error state 97964087Smjacob * 980164272Smjacob * XS_SAVE_SENSE(xs, sp, len) save sense data 98164087Smjacob * 98264087Smjacob * XS_SET_STATE_STAT(isp, sp, xs) platform dependent interpreter of 98364087Smjacob * response queue entry status bits 98464087Smjacob * 98564087Smjacob * 986155704Smjacob * DEFAULT_IID(ispsoftc_t *) Default SCSI initiator ID 987166120Smjacob * DEFAULT_LOOPID(ispsoftc_t *) Default FC Loop ID 988166120Smjacob * DEFAULT_NODEWWN(ispsoftc_t *) Default Node WWN 989166120Smjacob * DEFAULT_PORTWWN(ispsoftc_t *) Default Port WWN 990166120Smjacob * DEFAULT_FRAMESIZE(ispsoftc_t *) Default Frame Size 991155704Smjacob * DEFAULT_EXEC_THROTTLE(ispsoftc_t *) Default Execution Throttle 99267047Smjacob * These establish reasonable defaults for each platform. 99367047Smjacob * These must be available independent of card NVRAM and are 99467047Smjacob * to be used should NVRAM not be readable. 99564087Smjacob * 996166120Smjacob * ISP_NODEWWN(ispsoftc_t *) FC Node WWN to use 997166120Smjacob * ISP_PORTWWN(ispsoftc_t *) FC Port WWN to use 99864087Smjacob * 99967047Smjacob * These are to be used after NVRAM is read. The tags 1000166120Smjacob * in fcparam.isp_ww{n,p}n_nvram reflect the values 100167047Smjacob * read from NVRAM (possibly corrected for card botches). 100267047Smjacob * Each platform can take that information and override 100367047Smjacob * it or ignore and return the Node and Port WWNs to be 1004166120Smjacob * used when sending the Qlogic f/w the Initialization 1005166120Smjacob * Control Block. 100664087Smjacob * 100764087Smjacob * (XXX these do endian specific transformations- in transition XXX) 100887635Smjacob * 1009155704Smjacob * ISP_IOXPUT_8(ispsoftc_t *, uint8_t srcval, uint8_t *dstptr) 1010155704Smjacob * ISP_IOXPUT_16(ispsoftc_t *, uint16_t srcval, uint16_t *dstptr) 1011155704Smjacob * ISP_IOXPUT_32(ispsoftc_t *, uint32_t srcval, uint32_t *dstptr) 101287635Smjacob * 1013155704Smjacob * ISP_IOXGET_8(ispsoftc_t *, uint8_t *srcptr, uint8_t dstrval) 1014155704Smjacob * ISP_IOXGET_16(ispsoftc_t *, uint16_t *srcptr, uint16_t dstrval) 1015155704Smjacob * ISP_IOXGET_32(ispsoftc_t *, uint32_t *srcptr, uint32_t dstrval) 101687635Smjacob * 1017155704Smjacob * ISP_SWIZZLE_NVRAM_WORD(ispsoftc_t *, uint16_t *) 1018171159Smjacob * ISP_SWIZZLE_NVRAM_LONG(ispsoftc_t *, uint32_t *) 1019171159Smjacob * ISP_SWAP16(ispsoftc_t *, uint16_t srcval) 1020171159Smjacob * ISP_SWAP32(ispsoftc_t *, uint32_t srcval) 102164087Smjacob */ 102277365Smjacob 102335388Smjacob#endif /* _ISPVAR_H */ 1024