150477Speter/* $FreeBSD: stable/11/sys/dev/isp/ispvar.h 347894 2019-05-16 22:03:25Z ken $ */ 2139749Simp/*- 3330888Smav * Copyright (c) 2009-2018 Alexander Motin <mav@FreeBSD.org> 4196008Smjacob * Copyright (c) 1997-2009 by Matthew Jacob 5167403Smjacob * All rights reserved. 6196008Smjacob * 7167403Smjacob * Redistribution and use in source and binary forms, with or without 8167403Smjacob * modification, are permitted provided that the following conditions 9167403Smjacob * are met: 10196008Smjacob * 11167403Smjacob * 1. Redistributions of source code must retain the above copyright 12167403Smjacob * notice, this list of conditions and the following disclaimer. 13167403Smjacob * 2. Redistributions in binary form must reproduce the above copyright 14167403Smjacob * notice, this list of conditions and the following disclaimer in the 15167403Smjacob * documentation and/or other materials provided with the distribution. 16196008Smjacob * 17167403Smjacob * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18167403Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19167403Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20167403Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21167403Smjacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22167403Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23167403Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24167403Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25167403Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26167403Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27167403Smjacob * SUCH DAMAGE. 28196008Smjacob * 29167403Smjacob */ 30167403Smjacob/* 3135388Smjacob * Soft Definitions for for Qlogic ISP SCSI adapters. 3235388Smjacob */ 3335388Smjacob 3435388Smjacob#ifndef _ISPVAR_H 3535388Smjacob#define _ISPVAR_H 3635388Smjacob 3744819Smjacob#if defined(__NetBSD__) || defined(__OpenBSD__) 38163899Smjacob#include <dev/ic/isp_stds.h> 3935388Smjacob#include <dev/ic/ispmbox.h> 4035388Smjacob#endif 4135388Smjacob#ifdef __FreeBSD__ 42163899Smjacob#include <dev/isp/isp_stds.h> 4335388Smjacob#include <dev/isp/ispmbox.h> 4435388Smjacob#endif 4535388Smjacob#ifdef __linux__ 46163899Smjacob#include "isp_stds.h" 4742131Smjacob#include "ispmbox.h" 4835388Smjacob#endif 49155704Smjacob#ifdef __svr4__ 50163899Smjacob#include "isp_stds.h" 51155704Smjacob#include "ispmbox.h" 5253487Smjacob#endif 5335388Smjacob 54203444Smjacob#define ISP_CORE_VERSION_MAJOR 7 55163899Smjacob#define ISP_CORE_VERSION_MINOR 0 5639235Sgibbs 5735388Smjacob/* 5843420Smjacob * Vector for bus specific code to provide specific services. 5935388Smjacob */ 60155704Smjacobtypedef struct ispsoftc ispsoftc_t; 6135388Smjacobstruct ispmdvec { 62316145Smav void (*dv_run_isr) (ispsoftc_t *); 63163899Smjacob uint32_t (*dv_rd_reg) (ispsoftc_t *, int); 64163899Smjacob void (*dv_wr_reg) (ispsoftc_t *, int, uint32_t); 65155704Smjacob int (*dv_mbxdma) (ispsoftc_t *); 66196008Smjacob int (*dv_dmaset) (ispsoftc_t *, XS_T *, void *); 67163899Smjacob void (*dv_dmaclr) (ispsoftc_t *, XS_T *, uint32_t); 68316084Smav int (*dv_irqsetup) (ispsoftc_t *); 69155704Smjacob void (*dv_dregs) (ispsoftc_t *, const char *); 70167821Smjacob const void * dv_ispfw; /* ptr to f/w */ 71155704Smjacob uint16_t dv_conf1; 72155704Smjacob uint16_t dv_clock; /* clock frequency */ 7335388Smjacob}; 7435388Smjacob 7564087Smjacob/* 7664087Smjacob * Overall parameters 7764087Smjacob */ 7882689Smjacob#define MAX_TARGETS 16 79196008Smjacob#ifndef MAX_FC_TARG 80292765Smav#define MAX_FC_TARG 1024 81196008Smjacob#endif 8249909Smjacob#define ISP_MAX_TARGETS(isp) (IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS) 8361772Smjacob#define ISP_MAX_LUNS(isp) (isp)->isp_maxluns 84316398Smav#define ISP_MAX_IRQS 3 8549909Smjacob 8682689Smjacob/* 8764087Smjacob * Macros to access ISP registers through bus specific layers- 8864087Smjacob * mostly wrappers to vector through the mdvec structure. 8953487Smjacob */ 90316145Smav#define ISP_RUN_ISR(isp) \ 91316145Smav (*(isp)->isp_mdvec->dv_run_isr)(isp) 9253487Smjacob 9353487Smjacob#define ISP_READ(isp, reg) \ 9453487Smjacob (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg)) 9553487Smjacob 9653487Smjacob#define ISP_WRITE(isp, reg, val) \ 9753487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val)) 9853487Smjacob 9953487Smjacob#define ISP_MBOXDMASETUP(isp) \ 10053487Smjacob (*(isp)->isp_mdvec->dv_mbxdma)((isp)) 10153487Smjacob 102196008Smjacob#define ISP_DMASETUP(isp, xs, req) \ 103196008Smjacob (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req)) 10453487Smjacob 105155704Smjacob#define ISP_DMAFREE(isp, xs, hndl) \ 106155704Smjacob if ((isp)->isp_mdvec->dv_dmaclr) \ 10753487Smjacob (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl)) 10853487Smjacob 109316084Smav#define ISP_IRQSETUP(isp) \ 110316084Smav (((isp)->isp_mdvec->dv_irqsetup) ? (*(isp)->isp_mdvec->dv_irqsetup)(isp) : 0) 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) */ 132297858Smav#define SYNC_IFORDEV 6 /* synchrounous IOCB, sync for ISP */ 133297858Smav#define SYNC_IFORCPU 7 /* synchrounous IOCB, sync for CPU */ 13464087Smjacob 13564087Smjacob/* 13664087Smjacob * Request/Response Queue defines and macros. 13764087Smjacob * The maximum is defined per platform (and can be based on board type). 13864087Smjacob */ 13964087Smjacob/* This is the size of a queue entry (request and response) */ 14039235Sgibbs#define QENTRY_LEN 64 14164087Smjacob/* Both request and result queue length must be a power of two */ 14264087Smjacob#define RQUEST_QUEUE_LEN(x) MAXISPREQUEST(x) 14393706Smjacob#ifdef ISP_TARGET_MODE 14493706Smjacob#define RESULT_QUEUE_LEN(x) MAXISPREQUEST(x) 14593706Smjacob#else 14664087Smjacob#define RESULT_QUEUE_LEN(x) \ 14764087Smjacob (((MAXISPREQUEST(x) >> 2) < 64)? 64 : MAXISPREQUEST(x) >> 2) 14893706Smjacob#endif 149155704Smjacob#define ISP_QUEUE_ENTRY(q, idx) (((uint8_t *)q) + ((idx) * QENTRY_LEN)) 15039235Sgibbs#define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN) 15139235Sgibbs#define ISP_NXT_QENTRY(idx, qlen) (((idx) + 1) & ((qlen)-1)) 15265140Smjacob#define ISP_QFREE(in, out, qlen) \ 15339235Sgibbs ((in == out)? (qlen - 1) : ((in > out)? \ 15452347Smjacob ((qlen - 1) - (in - out)) : (out - in - 1))) 15565140Smjacob#define ISP_QAVAIL(isp) \ 15665140Smjacob ISP_QFREE(isp->isp_reqidx, isp->isp_reqodx, RQUEST_QUEUE_LEN(isp)) 15753487Smjacob 158218691Smarius#define ISP_ADD_REQUEST(isp, nxti) \ 159218691Smarius MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN, -1); \ 160218691Smarius ISP_WRITE(isp, isp->isp_rqstinrp, nxti); \ 16187635Smjacob isp->isp_reqidx = nxti 16253487Smjacob 163196008Smjacob#define ISP_SYNC_REQUEST(isp) \ 164218691Smarius MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN, -1); \ 165196008Smjacob isp->isp_reqidx = ISP_NXT_QENTRY(isp->isp_reqidx, RQUEST_QUEUE_LEN(isp)); \ 166196008Smjacob ISP_WRITE(isp, isp->isp_rqstinrp, isp->isp_reqidx) 167196008Smjacob 16835388Smjacob/* 16946968Smjacob * SCSI Specific Host Adapter Parameters- per bus, per target 17035388Smjacob */ 17135388Smjacobtypedef struct { 172196008Smjacob uint32_t : 8, 173196008Smjacob update : 1, 174196008Smjacob sendmarker : 1, 17552347Smjacob isp_req_ack_active_neg : 1, 17652347Smjacob isp_data_line_active_neg: 1, 17735388Smjacob isp_cmd_dma_burst_enable: 1, 17835388Smjacob isp_data_dma_burst_enabl: 1, 17942461Smjacob isp_fifo_threshold : 3, 180163899Smjacob isp_ptisp : 1, 18143420Smjacob isp_ultramode : 1, 18235388Smjacob isp_diffmode : 1, 18345040Smjacob isp_lvdmode : 1, 18465140Smjacob isp_fast_mttr : 1, /* fast sram */ 18535388Smjacob isp_initiator_id : 4, 18652347Smjacob isp_async_data_setup : 4; 187155704Smjacob uint16_t isp_selection_timeout; 188155704Smjacob uint16_t isp_max_queue_depth; 189155704Smjacob uint8_t isp_tag_aging; 190155704Smjacob uint8_t isp_bus_reset_delay; 191155704Smjacob uint8_t isp_retry_count; 192155704Smjacob uint8_t isp_retry_delay; 19335388Smjacob struct { 194196008Smjacob uint32_t 19580582Smjacob exc_throttle : 8, 19646968Smjacob : 1, 19780582Smjacob dev_enable : 1, /* ignored */ 19843420Smjacob dev_update : 1, 19943420Smjacob dev_refresh : 1, 20080582Smjacob actv_offset : 4, 20180582Smjacob goal_offset : 4, 20280582Smjacob nvrm_offset : 4; 203155704Smjacob uint8_t actv_period; /* current sync period */ 204155704Smjacob uint8_t goal_period; /* goal sync period */ 205155704Smjacob uint8_t nvrm_period; /* nvram sync period */ 206155704Smjacob uint16_t actv_flags; /* current device flags */ 207155704Smjacob uint16_t goal_flags; /* goal device flags */ 208155704Smjacob uint16_t nvrm_flags; /* nvram device flags */ 20935388Smjacob } isp_devparam[MAX_TARGETS]; 21046968Smjacob} sdparam; 21135388Smjacob 21235388Smjacob/* 21335388Smjacob * Device Flags 21435388Smjacob */ 21539235Sgibbs#define DPARM_DISC 0x8000 21639235Sgibbs#define DPARM_PARITY 0x4000 21739235Sgibbs#define DPARM_WIDE 0x2000 21839235Sgibbs#define DPARM_SYNC 0x1000 21939235Sgibbs#define DPARM_TQING 0x0800 22039235Sgibbs#define DPARM_ARQ 0x0400 22139235Sgibbs#define DPARM_QFRZ 0x0200 22239235Sgibbs#define DPARM_RENEG 0x0100 22365140Smjacob#define DPARM_NARROW 0x0080 22465140Smjacob#define DPARM_ASYNC 0x0040 22565140Smjacob#define DPARM_PPR 0x0020 22643793Smjacob#define DPARM_DEFAULT (0xFF00 & ~DPARM_QFRZ) 22739235Sgibbs#define DPARM_SAFE_DFLT (DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING)) 22835388Smjacob 22945040Smjacob/* technically, not really correct, as they need to be rated based upon clock */ 23065140Smjacob#define ISP_80M_SYNCPARMS 0x0c09 23165140Smjacob#define ISP_40M_SYNCPARMS 0x0c0a 23265140Smjacob#define ISP_20M_SYNCPARMS 0x0c0c 23365140Smjacob#define ISP_20M_SYNCPARMS_1040 0x080c 23452347Smjacob#define ISP_10M_SYNCPARMS 0x0c19 23552347Smjacob#define ISP_08M_SYNCPARMS 0x0c25 23652347Smjacob#define ISP_05M_SYNCPARMS 0x0c32 23752347Smjacob#define ISP_04M_SYNCPARMS 0x0c41 23835388Smjacob 23935388Smjacob/* 24035388Smjacob * Fibre Channel Specifics 24135388Smjacob */ 242164909Smjacob/* These are for non-2K Login Firmware cards */ 243163899Smjacob#define FL_ID 0x7e /* FL_Port Special ID */ 244163899Smjacob#define SNS_ID 0x80 /* SNS Server Special ID */ 245163899Smjacob#define NPH_MAX 0xfe 24652347Smjacob 247164909Smjacob/* These are for 2K Login Firmware cards */ 248163899Smjacob#define NPH_RESERVED 0x7F0 /* begin of reserved N-port handles */ 249163899Smjacob#define NPH_MGT_ID 0x7FA /* Management Server Special ID */ 250163899Smjacob#define NPH_SNS_ID 0x7FC /* SNS Server Special ID */ 251196008Smjacob#define NPH_FABRIC_CTLR 0x7FD /* Fabric Controller (0xFFFFFD) */ 252196008Smjacob#define NPH_FL_ID 0x7FE /* F Port Special ID (0xFFFFFE) */ 253289890Smav#define NPH_IP_BCST 0x7FF /* IP Broadcast Special ID (0xFFFFFF) */ 254164909Smjacob#define NPH_MAX_2K 0x800 25593837Smjacob 256163899Smjacob/* 257164909Smjacob * "Unassigned" handle to be used internally 258164909Smjacob */ 259164909Smjacob#define NIL_HANDLE 0xffff 260164909Smjacob 261164909Smjacob/* 262163899Smjacob * Limit for devices on an arbitrated loop. 263163899Smjacob */ 264163899Smjacob#define LOCAL_LOOP_LIM 126 265163899Smjacob 266163899Smjacob/* 267196008Smjacob * Limit for (2K login) N-port handle amounts 268196008Smjacob */ 269196008Smjacob#define MAX_NPORT_HANDLE 2048 270196008Smjacob 271196008Smjacob/* 272196008Smjacob * Special Constants 273196008Smjacob */ 274196008Smjacob#define INI_NONE ((uint64_t) 0) 275196008Smjacob#define ISP_NOCHAN 0xff 276196008Smjacob 277196008Smjacob/* 278163899Smjacob * Special Port IDs 279163899Smjacob */ 280163899Smjacob#define MANAGEMENT_PORT_ID 0xFFFFFA 281163899Smjacob#define SNS_PORT_ID 0xFFFFFC 282163899Smjacob#define FABRIC_PORT_ID 0xFFFFFE 283196008Smjacob#define PORT_ANY 0xFFFFFF 284196008Smjacob#define PORT_NONE 0 285291144Smav#define VALID_PORT(port) (port != PORT_NONE && port != PORT_ANY) 286196008Smjacob#define DOMAIN_CONTROLLER_BASE 0xFFFC00 287196008Smjacob#define DOMAIN_CONTROLLER_END 0xFFFCFF 288163899Smjacob 289203444Smjacob/* 290203444Smjacob * Command Handles 291203444Smjacob * 292203444Smjacob * Most QLogic initiator or target have 32 bit handles associated with them. 293203444Smjacob * We want to have a quick way to index back and forth between a local SCSI 294203444Smjacob * command context and what the firmware is passing back to us. We also 295203444Smjacob * want to avoid working on stale information. This structure handles both 296203444Smjacob * at the expense of some local memory. 297203444Smjacob * 298203444Smjacob * The handle is architected thusly: 299203444Smjacob * 300203444Smjacob * 0 means "free handle" 301203444Smjacob * bits 0..12 index commands 302203444Smjacob * bits 13..15 bits index usage 303203444Smjacob * bits 16..31 contain a rolling sequence 304203444Smjacob * 305203444Smjacob * 306203444Smjacob */ 307203444Smjacobtypedef struct { 308203444Smjacob void * cmd; /* associated command context */ 309203444Smjacob uint32_t handle; /* handle associated with this command */ 310203444Smjacob} isp_hdl_t; 311203444Smjacob#define ISP_HANDLE_FREE 0x00000000 312203444Smjacob#define ISP_HANDLE_CMD_MASK 0x00001fff 313203444Smjacob#define ISP_HANDLE_USAGE_MASK 0x0000e000 314203444Smjacob#define ISP_HANDLE_USAGE_SHIFT 13 315203444Smjacob#define ISP_H2HT(hdl) ((hdl & ISP_HANDLE_USAGE_MASK) >> ISP_HANDLE_USAGE_SHIFT) 316203444Smjacob# define ISP_HANDLE_NONE 0 317203444Smjacob# define ISP_HANDLE_INITIATOR 1 318203444Smjacob# define ISP_HANDLE_TARGET 2 319292739Smav# define ISP_HANDLE_CTRL 3 320203444Smjacob#define ISP_HANDLE_SEQ_MASK 0xffff0000 321203444Smjacob#define ISP_HANDLE_SEQ_SHIFT 16 322203444Smjacob#define ISP_H2SEQ(hdl) ((hdl & ISP_HANDLE_SEQ_MASK) >> ISP_HANDLE_SEQ_SHIFT) 323203444Smjacob#define ISP_VALID_HANDLE(c, hdl) \ 324292725Smav ((ISP_H2HT(hdl) == ISP_HANDLE_INITIATOR || \ 325292739Smav ISP_H2HT(hdl) == ISP_HANDLE_TARGET || \ 326292739Smav ISP_H2HT(hdl) == ISP_HANDLE_CTRL) && \ 327292725Smav ((hdl) & ISP_HANDLE_CMD_MASK) < (c)->isp_maxcmds && \ 328292725Smav (hdl) == ((c)->isp_xflist[(hdl) & ISP_HANDLE_CMD_MASK].handle)) 329203444Smjacob#define ISP_BAD_HANDLE_INDEX 0xffffffff 330163899Smjacob 331203444Smjacob 332163899Smjacob/* 333163899Smjacob * FC Port Database entry. 334163899Smjacob * 335163899Smjacob * It has a handle that the f/w uses to address commands to a device. 336163899Smjacob * This handle's value may be assigned by the firmware (e.g., for local loop 337163899Smjacob * devices) or by the driver (e.g., for fabric devices). 338163899Smjacob * 339163899Smjacob * It has a state. If the state if VALID, that means that we've logged into 340285154Smav * the device. 341163899Smjacob * 342163899Smjacob * Local loop devices the firmware automatically performs PLOGI on for us 343163899Smjacob * (which is why that handle is imposed upon us). Fabric devices we assign 344163899Smjacob * a handle to and perform the PLOGI on. 345163899Smjacob * 346163899Smjacob * When a PORT DATABASE CHANGED asynchronous event occurs, we mark all VALID 347163899Smjacob * entries as PROBATIONAL. This allows us, if policy says to, just keep track 348163899Smjacob * of devices whose handles change but are otherwise the same device (and 349163899Smjacob * thus keep 'target' constant). 350163899Smjacob * 351163899Smjacob * In any case, we search all possible local loop handles. For each one that 352163899Smjacob * has a port database entity returned, we search for any PROBATIONAL entry 353163899Smjacob * that matches it and update as appropriate. Otherwise, as a new entry, we 354163899Smjacob * find room for it in the Port Database. We *try* and use the handle as the 355163899Smjacob * index to put it into the Database, but that's just an optimization. We mark 356163899Smjacob * the entry VALID and make sure that the target index is updated and correct. 357163899Smjacob * 358298955Spfg * When we get done searching the local loop, we then search similarly for 359163899Smjacob * a list of devices we've gotten from the fabric name controller (if we're 360298955Spfg * on a fabric). VALID marking is also done similarly. 361163899Smjacob * 362163899Smjacob * When all of this is done, we can march through the database and clean up 363163899Smjacob * any entry that is still PROBATIONAL (these represent devices which have 364163899Smjacob * departed). Then we're done and can resume normal operations. 365163899Smjacob * 366163899Smjacob * Negative invariants that we try and test for are: 367163899Smjacob * 368163899Smjacob * + There can never be two non-NIL entries with the same { Port, Node } WWN 369163899Smjacob * duples. 370163899Smjacob * 371163899Smjacob * + There can never be two non-NIL entries with the same handle. 372163899Smjacob */ 37335388Smjacobtypedef struct { 374164272Smjacob /* 375164272Smjacob * This is the handle that the firmware needs in order for us to 376164272Smjacob * send commands to the device. For pre-24XX cards, this would be 377164272Smjacob * the 'loopid'. 378164272Smjacob */ 379163899Smjacob uint16_t handle; 380196008Smjacob 381164272Smjacob /* 382347894Sken * PRLI word 0 contains the Establish Image Pair bit, which is 383347894Sken * important for knowing when to reset the CRN. 384347894Sken * 385238869Smjacob * PRLI word 3 parameters contains role as well as other things. 386238869Smjacob * 387196008Smjacob * The state is the current state of this entry. 388164272Smjacob * 389285459Smav * The is_target is the current state of target on this port. 390285459Smav * 391285459Smav * The is_initiator is the current state of initiator on this port. 392285459Smav * 393196008Smjacob * Portid is obvious, as are node && port WWNs. The new_role and 394164272Smjacob * new_portid is for when we are pending a change. 395164272Smjacob */ 396347894Sken uint16_t prli_word0; /* PRLI parameters */ 397238869Smjacob uint16_t prli_word3; /* PRLI parameters */ 398347894Sken uint16_t new_prli_word0; /* Incoming new PRLI parameters */ 399238869Smjacob uint16_t new_prli_word3; /* Incoming new PRLI parameters */ 400300052Smav uint16_t : 12, 401291080Smav probational : 1, 402163899Smjacob state : 3; 403285459Smav uint32_t : 6, 404285459Smav is_target : 1, 405285459Smav is_initiator : 1, 406163899Smjacob portid : 24; 407196008Smjacob uint32_t 408285459Smav : 8, 409163899Smjacob new_portid : 24; 410163899Smjacob uint64_t node_wwn; 411163899Smjacob uint64_t port_wwn; 412208119Smjacob uint32_t gone_timer; 413163899Smjacob} fcportdb_t; 414163899Smjacob 415291080Smav#define FC_PORTDB_STATE_NIL 0 /* Empty DB slot */ 416291080Smav#define FC_PORTDB_STATE_DEAD 1 /* Was valid, but no more. */ 417291080Smav#define FC_PORTDB_STATE_CHANGED 2 /* Was valid, but changed. */ 418291080Smav#define FC_PORTDB_STATE_NEW 3 /* Logged in, not announced. */ 419291080Smav#define FC_PORTDB_STATE_ZOMBIE 4 /* Invalid, but announced. */ 420291080Smav#define FC_PORTDB_STATE_VALID 5 /* Valid */ 421163899Smjacob 422285459Smav#define FC_PORTDB_TGT(isp, bus, pdb) (int)(lp - FCPARAM(isp, bus)->portdb) 423285459Smav 424163899Smjacob/* 425163899Smjacob * FC card specific information 426196008Smjacob * 427196008Smjacob * This structure is replicated across multiple channels for multi-id 428196008Smjacob * capapble chipsets, with some entities different on a per-channel basis. 429163899Smjacob */ 430196008Smjacob 431163899Smjacobtypedef struct { 432289219Smav int isp_gbspeed; /* Connection speed */ 433289219Smav int isp_linkstate; /* Link state */ 434289219Smav int isp_fwstate; /* ISP F/W state */ 435289219Smav int isp_loopstate; /* Loop State */ 436289219Smav int isp_topo; /* Connection Type */ 437289219Smav 438291365Smav uint32_t : 4, 439238869Smjacob fctape_enabled : 1, 440196008Smjacob sendmarker : 1, 441196008Smjacob role : 2, 442154704Smjacob isp_portid : 24; /* S_ID */ 443196008Smjacob 444155704Smjacob uint16_t isp_fwoptions; 445160080Smjacob uint16_t isp_xfwoptions; 446160080Smjacob uint16_t isp_zfwoptions; 447196008Smjacob uint16_t isp_loopid; /* hard loop id */ 448196008Smjacob uint16_t isp_sns_hdl; /* N-port handle for SNS */ 449196008Smjacob uint16_t isp_lasthdl; /* only valid for channel 0 */ 450196008Smjacob uint16_t isp_maxalloc; 451237210Smjacob uint16_t isp_fabric_params; 452297915Smav uint16_t isp_login_hdl; /* Logging in handle */ 453155704Smjacob uint8_t isp_retry_delay; 454155704Smjacob uint8_t isp_retry_count; 455321870Smav int isp_use_gft_id; /* Use GFT_ID */ 456321870Smav int isp_use_gff_id; /* Use GFF_ID */ 457196008Smjacob 458196008Smjacob /* 459196008Smjacob * Current active WWNN/WWPN 460196008Smjacob */ 461196008Smjacob uint64_t isp_wwnn; 462196008Smjacob uint64_t isp_wwpn; 463196008Smjacob 464196008Smjacob /* 465196008Smjacob * NVRAM WWNN/WWPN 466196008Smjacob */ 467166120Smjacob uint64_t isp_wwnn_nvram; 468166120Smjacob uint64_t isp_wwpn_nvram; 469164272Smjacob 470164272Smjacob /* 471164272Smjacob * Our Port Data Base 472164272Smjacob */ 473163899Smjacob fcportdb_t portdb[MAX_FC_TARG]; 474164272Smjacob 47535388Smjacob /* 47635388Smjacob * Scratch DMA mapped in area to fetch Port Database stuff, etc. 47735388Smjacob */ 478155704Smjacob void * isp_scratch; 479155704Smjacob XS_DMA_ADDR_T isp_scdma; 480292765Smav 481292765Smav uint8_t isp_scanscratch[ISP_FC_SCRLEN]; 48235388Smjacob} fcparam; 48335388Smjacob 48448484Smjacob#define FW_CONFIG_WAIT 0 485290993Smav#define FW_WAIT_LINK 1 48648484Smjacob#define FW_WAIT_LOGIN 2 48748484Smjacob#define FW_READY 3 48848484Smjacob#define FW_LOSS_OF_SYNC 4 48948484Smjacob#define FW_ERROR 5 49048484Smjacob#define FW_REINIT 6 49148484Smjacob#define FW_NON_PART 7 49235388Smjacob 49348484Smjacob#define LOOP_NIL 0 494291365Smav#define LOOP_HAVE_LINK 1 495297991Smav#define LOOP_HAVE_ADDR 2 496297991Smav#define LOOP_TESTING_LINK 3 497297991Smav#define LOOP_LTEST_DONE 4 498297991Smav#define LOOP_SCANNING_LOOP 5 499297991Smav#define LOOP_LSCAN_DONE 6 500297991Smav#define LOOP_SCANNING_FABRIC 7 501297991Smav#define LOOP_FSCAN_DONE 8 502297991Smav#define LOOP_SYNCING_PDB 9 503297991Smav#define LOOP_READY 10 50435388Smjacob 50559454Smjacob#define TOPO_NL_PORT 0 50659454Smjacob#define TOPO_FL_PORT 1 50759454Smjacob#define TOPO_N_PORT 2 50859454Smjacob#define TOPO_F_PORT 3 50959454Smjacob#define TOPO_PTP_STUB 4 51059454Smjacob 511291080Smav#define TOPO_IS_FABRIC(x) ((x) == TOPO_FL_PORT || (x) == TOPO_F_PORT) 512291080Smav 513318148Sken#define FCP_AL_DA_ALL 0xFF 514318148Sken#define FCP_AL_PA(fcp) ((uint8_t)(fcp->isp_portid)) 515318148Sken#define FCP_IS_DEST_ALPD(fcp, alpd) (FCP_AL_PA((fcp)) == FCP_AL_DA_ALL || FCP_AL_PA((fcp)) == alpd) 516318148Sken 51742131Smjacob/* 51835388Smjacob * Soft Structure per host adapter 51935388Smjacob */ 520155704Smjacobstruct ispsoftc { 52135388Smjacob /* 52235388Smjacob * Platform (OS) specific data 52335388Smjacob */ 52435388Smjacob struct isposinfo isp_osinfo; 52535388Smjacob 52635388Smjacob /* 52753487Smjacob * Pointer to bus specific functions and data 52835388Smjacob */ 52935388Smjacob struct ispmdvec * isp_mdvec; 53035388Smjacob 53135388Smjacob /* 53253487Smjacob * (Mostly) nonvolatile state. Board specific parameters 53353487Smjacob * may contain some volatile state (e.g., current loop state). 53435388Smjacob */ 53535388Smjacob 53653487Smjacob void * isp_param; /* type specific */ 537237210Smjacob uint64_t isp_fwattr; /* firmware attributes */ 538155704Smjacob uint16_t isp_fwrev[3]; /* Loaded F/W revision */ 539155704Smjacob uint16_t isp_maxcmds; /* max possible I/O cmds */ 540155704Smjacob uint8_t isp_type; /* HBA Chip Type */ 541155704Smjacob uint8_t isp_revision; /* HBA Chip H/W Revision */ 542316398Smav uint8_t isp_nirq; /* number of IRQs */ 543237210Smjacob uint16_t isp_nchan; /* number of channels */ 544155704Smjacob uint32_t isp_maxluns; /* maximum luns supported */ 54535388Smjacob 546155704Smjacob uint32_t isp_clock : 8, /* input clock */ 547316400Smav : 5, 548163899Smjacob isp_port : 1, /* 23XX/24XX only */ 54953487Smjacob isp_bustype : 1, /* SBus or PCI */ 55065140Smjacob isp_loaded_fw : 1, /* loaded firmware */ 551196008Smjacob isp_dblev : 16; /* debug log mask */ 55271079Smjacob 55371079Smjacob 554196008Smjacob uint32_t isp_confopts; /* config options */ 555196008Smjacob 556163899Smjacob uint32_t isp_rqstinrp; /* register for REQINP */ 557163899Smjacob uint32_t isp_rqstoutrp; /* register for REQOUTP */ 558163899Smjacob uint32_t isp_respinrp; /* register for RESINP */ 559163899Smjacob uint32_t isp_respoutrp; /* register for RESOUTP */ 56039235Sgibbs 56135388Smjacob /* 56239235Sgibbs * Volatile state 56335388Smjacob */ 56435388Smjacob 565316084Smav volatile u_int isp_mboxbsy; /* mailbox command active */ 566316084Smav volatile u_int isp_state; 567203444Smjacob volatile mbreg_t isp_curmbx; /* currently active mailbox command */ 568163899Smjacob volatile uint32_t isp_reqodx; /* index of last ISP pickup */ 569163899Smjacob volatile uint32_t isp_reqidx; /* index of next request */ 570256705Smav volatile uint32_t isp_residx; /* index of last ISP write */ 571163899Smjacob volatile uint32_t isp_resodx; /* index of next result */ 572256705Smav volatile uint32_t isp_atioodx; /* index of next ATIO */ 573163899Smjacob volatile uint32_t isp_obits; /* mailbox command output */ 574196008Smjacob volatile uint32_t isp_serno; /* rolling serial number */ 575237210Smjacob volatile uint16_t isp_mboxtmp[MAX_MAILBOX]; 576155704Smjacob volatile uint16_t isp_lastmbxcmd; /* last mbox command sent */ 577203444Smjacob volatile uint16_t isp_seqno; /* running sequence number */ 57835388Smjacob 57935388Smjacob /* 58053487Smjacob * Active commands are stored here, indexed by handle functions. 58135388Smjacob */ 582203444Smjacob isp_hdl_t *isp_xflist; 583203444Smjacob isp_hdl_t *isp_xffree; 58435388Smjacob 58535388Smjacob /* 586297858Smav * DMA mapped in area for synchronous IOCB requests. 587297858Smav */ 588297858Smav void * isp_iocb; 589297858Smav XS_DMA_ADDR_T isp_iocb_dma; 590297858Smav 591297858Smav /* 592120018Smjacob * request/result queue pointers and DMA handles for them. 59335388Smjacob */ 594155704Smjacob void * isp_rquest; 595155704Smjacob void * isp_result; 596155704Smjacob XS_DMA_ADDR_T isp_rquest_dma; 597155704Smjacob XS_DMA_ADDR_T isp_result_dma; 598163899Smjacob#ifdef ISP_TARGET_MODE 599163899Smjacob /* for 24XX only */ 600163899Smjacob void * isp_atioq; 601163899Smjacob XS_DMA_ADDR_T isp_atioq_dma; 602163899Smjacob#endif 603155704Smjacob}; 60435388Smjacob 605196008Smjacob#define SDPARAM(isp, chan) (&((sdparam *)(isp)->isp_param)[(chan)]) 606196008Smjacob#define FCPARAM(isp, chan) (&((fcparam *)(isp)->isp_param)[(chan)]) 60749909Smjacob 608196008Smjacob#define ISP_SET_SENDMARKER(isp, chan, val) \ 609196008Smjacob if (IS_FC(isp)) { \ 610196008Smjacob FCPARAM(isp, chan)->sendmarker = val; \ 611196008Smjacob } else { \ 612196008Smjacob SDPARAM(isp, chan)->sendmarker = val; \ 613196008Smjacob } 614196008Smjacob 615196008Smjacob#define ISP_TST_SENDMARKER(isp, chan) \ 616196008Smjacob (IS_FC(isp)? \ 617196008Smjacob FCPARAM(isp, chan)->sendmarker != 0 : \ 618196008Smjacob SDPARAM(isp, chan)->sendmarker != 0) 619196008Smjacob 62035388Smjacob/* 62164087Smjacob * ISP Driver Run States 62235388Smjacob */ 62335388Smjacob#define ISP_NILSTATE 0 624160080Smjacob#define ISP_CRASHED 1 625160080Smjacob#define ISP_RESETSTATE 2 626160080Smjacob#define ISP_INITSTATE 3 627160080Smjacob#define ISP_RUNSTATE 4 62835388Smjacob 62935388Smjacob/* 630237537Smjacob * ISP Runtime Configuration Options 63135388Smjacob */ 63253487Smjacob#define ISP_CFG_FULL_DUPLEX 0x01 /* Full Duplex (Fibre Channel only) */ 633297912Smav#define ISP_CFG_PORT_PREF 0x0e /* Mask for Port Prefs (all FC except 2100) */ 634297912Smav#define ISP_CFG_PORT_DEF 0x00 /* prefer connection type from NVRAM */ 635297912Smav#define ISP_CFG_LPORT_ONLY 0x02 /* insist on {N/F}L-Port connection */ 636297912Smav#define ISP_CFG_NPORT_ONLY 0x04 /* insist on {N/F}-Port connection */ 637297912Smav#define ISP_CFG_LPORT 0x06 /* prefer {N/F}L-Port connection */ 638297912Smav#define ISP_CFG_NPORT 0x08 /* prefer {N/F}-Port connection */ 639330888Smav#define ISP_CFG_1GB 0x10 /* force 1Gb connection (23XX only) */ 640330888Smav#define ISP_CFG_2GB 0x20 /* force 2Gb connection (23XX only) */ 641238869Smjacob#define ISP_CFG_NORELOAD 0x80 /* don't download f/w */ 642238869Smjacob#define ISP_CFG_NONVRAM 0x40 /* ignore NVRAM */ 643238869Smjacob#define ISP_CFG_NOFCTAPE 0x100 /* disable FC-Tape */ 644238869Smjacob#define ISP_CFG_FCTAPE 0x200 /* enable FC-Tape */ 64598281Smjacob#define ISP_CFG_OWNFSZ 0x400 /* override NVRAM frame size */ 64698281Smjacob#define ISP_CFG_OWNLOOPID 0x800 /* override NVRAM loopid */ 64798281Smjacob#define ISP_CFG_OWNEXCTHROTTLE 0x1000 /* override NVRAM execution throttle */ 648330888Smav#define ISP_CFG_4GB 0x2000 /* force 4Gb connection (24XX only) */ 649330888Smav#define ISP_CFG_8GB 0x4000 /* force 8Gb connection (25XX only) */ 650330888Smav#define ISP_CFG_16GB 0x8000 /* force 16Gb connection (26XX only) */ 651330888Smav#define ISP_CFG_32GB 0x10000 /* force 32Gb connection (27XX only) */ 65235388Smjacob 65364087Smjacob/* 654196008Smjacob * For each channel, the outer layers should know what role that channel 655196008Smjacob * will take: ISP_ROLE_NONE, ISP_ROLE_INITIATOR, ISP_ROLE_TARGET, 656196008Smjacob * ISP_ROLE_BOTH. 65771079Smjacob * 65871079Smjacob * If you set ISP_ROLE_NONE, the cards will be reset, new firmware loaded, 65971079Smjacob * NVRAM read, and defaults set, but any further initialization (e.g. 66071079Smjacob * INITIALIZE CONTROL BLOCK commands for 2X00 cards) won't be done. 66171079Smjacob * 66271079Smjacob * If INITIATOR MODE isn't set, attempts to run commands will be stopped 663196008Smjacob * at isp_start and completed with the equivalent of SELECTION TIMEOUT. 66471079Smjacob * 66571079Smjacob * If TARGET MODE is set, it doesn't mean that the rest of target mode support 66671079Smjacob * needs to be enabled, or will even work. What happens with the 2X00 cards 66771079Smjacob * here is that if you have enabled it with TARGET MODE as part of the ICB 66871079Smjacob * options, but you haven't given the f/w any ram resources for ATIOs or 66971079Smjacob * Immediate Notifies, the f/w just handles what it can and you never see 67071079Smjacob * anything. Basically, it sends a single byte of data (the first byte, 67171079Smjacob * which you can set as part of the INITIALIZE CONTROL BLOCK command) for 67271079Smjacob * INQUIRY, and sends back QUEUE FULL status for any other command. 67379235Smjacob * 67471079Smjacob */ 67571079Smjacob#define ISP_ROLE_NONE 0x0 676125544Smjacob#define ISP_ROLE_TARGET 0x1 677125544Smjacob#define ISP_ROLE_INITIATOR 0x2 67871079Smjacob#define ISP_ROLE_BOTH (ISP_ROLE_TARGET|ISP_ROLE_INITIATOR) 67971079Smjacob#define ISP_ROLE_EITHER ISP_ROLE_BOTH 68071079Smjacob#ifndef ISP_DEFAULT_ROLES 681236427Smjacob/* 682236427Smjacob * Counterintuitively, we prefer to default to role 'none' 683236427Smjacob * if we are enable target mode support. This gives us the 684236427Smjacob * maximum flexibility as to which port will do what. 685236427Smjacob */ 686236427Smjacob#ifdef ISP_TARGET_MODE 687236427Smjacob#define ISP_DEFAULT_ROLES ISP_ROLE_NONE 688236427Smjacob#else 68971079Smjacob#define ISP_DEFAULT_ROLES ISP_ROLE_INITIATOR 69071079Smjacob#endif 691236427Smjacob#endif 69271079Smjacob 69371079Smjacob 69471079Smjacob/* 69564087Smjacob * Firmware related defines 69664087Smjacob */ 69771079Smjacob#define ISP_CODE_ORG 0x1000 /* default f/w code start */ 69882689Smjacob#define ISP_CODE_ORG_2300 0x0800 /* ..except for 2300s */ 699163899Smjacob#define ISP_CODE_ORG_2400 0x100000 /* ..and 2400s */ 70045282Smjacob#define ISP_FW_REV(maj, min, mic) ((maj << 24) | (min << 16) | mic) 70182841Smjacob#define ISP_FW_MAJOR(code) ((code >> 24) & 0xff) 70282841Smjacob#define ISP_FW_MINOR(code) ((code >> 16) & 0xff) 70382841Smjacob#define ISP_FW_MICRO(code) ((code >> 8) & 0xff) 70471079Smjacob#define ISP_FW_REVX(xp) ((xp[0]<<24) | (xp[1] << 16) | xp[2]) 70582841Smjacob#define ISP_FW_MAJORX(xp) (xp[0]) 70682841Smjacob#define ISP_FW_MINORX(xp) (xp[1]) 70782841Smjacob#define ISP_FW_MICROX(xp) (xp[2]) 708102012Smjacob#define ISP_FW_NEWER_THAN(i, major, minor, micro) \ 709102012Smjacob (ISP_FW_REVX((i)->isp_fwrev) > ISP_FW_REV(major, minor, micro)) 710163899Smjacob#define ISP_FW_OLDER_THAN(i, major, minor, micro) \ 711163899Smjacob (ISP_FW_REVX((i)->isp_fwrev) < ISP_FW_REV(major, minor, micro)) 71239235Sgibbs 71335388Smjacob/* 71439235Sgibbs * Bus (implementation) types 71535388Smjacob */ 71639235Sgibbs#define ISP_BT_PCI 0 /* PCI Implementations */ 71739235Sgibbs#define ISP_BT_SBUS 1 /* SBus Implementations */ 71839235Sgibbs 71939235Sgibbs/* 72087635Smjacob * If we have not otherwise defined SBus support away make sure 72187635Smjacob * it is defined here such that the code is included as default 72287635Smjacob */ 72387635Smjacob#ifndef ISP_SBUS_SUPPORTED 72487635Smjacob#define ISP_SBUS_SUPPORTED 1 72587635Smjacob#endif 72687635Smjacob 72787635Smjacob/* 72839235Sgibbs * Chip Types 72939235Sgibbs */ 73035388Smjacob#define ISP_HA_SCSI 0xf 73139235Sgibbs#define ISP_HA_SCSI_UNKNOWN 0x1 73239235Sgibbs#define ISP_HA_SCSI_1020 0x2 73339235Sgibbs#define ISP_HA_SCSI_1020A 0x3 73439235Sgibbs#define ISP_HA_SCSI_1040 0x4 73539235Sgibbs#define ISP_HA_SCSI_1040A 0x5 73639235Sgibbs#define ISP_HA_SCSI_1040B 0x6 73745282Smjacob#define ISP_HA_SCSI_1040C 0x7 73854671Smjacob#define ISP_HA_SCSI_1240 0x8 73954671Smjacob#define ISP_HA_SCSI_1080 0x9 74054671Smjacob#define ISP_HA_SCSI_1280 0xa 741104916Smjacob#define ISP_HA_SCSI_10160 0xb 742104916Smjacob#define ISP_HA_SCSI_12160 0xc 74335388Smjacob#define ISP_HA_FC 0xf0 74435388Smjacob#define ISP_HA_FC_2100 0x10 74548484Smjacob#define ISP_HA_FC_2200 0x20 74677365Smjacob#define ISP_HA_FC_2300 0x30 74788855Smjacob#define ISP_HA_FC_2312 0x40 748154704Smjacob#define ISP_HA_FC_2322 0x50 749154704Smjacob#define ISP_HA_FC_2400 0x60 750196008Smjacob#define ISP_HA_FC_2500 0x70 751291654Smav#define ISP_HA_FC_2600 0x80 752330888Smav#define ISP_HA_FC_2700 0x90 75335388Smjacob 75444819Smjacob#define IS_SCSI(isp) (isp->isp_type & ISP_HA_SCSI) 755196008Smjacob#define IS_1020(isp) (isp->isp_type < ISP_HA_SCSI_1240) 75654671Smjacob#define IS_1240(isp) (isp->isp_type == ISP_HA_SCSI_1240) 75744819Smjacob#define IS_1080(isp) (isp->isp_type == ISP_HA_SCSI_1080) 75854671Smjacob#define IS_1280(isp) (isp->isp_type == ISP_HA_SCSI_1280) 759104916Smjacob#define IS_10160(isp) (isp->isp_type == ISP_HA_SCSI_10160) 76057145Smjacob#define IS_12160(isp) (isp->isp_type == ISP_HA_SCSI_12160) 76157145Smjacob 76257145Smjacob#define IS_12X0(isp) (IS_1240(isp) || IS_1280(isp)) 763104916Smjacob#define IS_1X160(isp) (IS_10160(isp) || IS_12160(isp)) 76457145Smjacob#define IS_DUALBUS(isp) (IS_12X0(isp) || IS_12160(isp)) 765104916Smjacob#define IS_ULTRA2(isp) (IS_1080(isp) || IS_1280(isp) || IS_1X160(isp)) 766104916Smjacob#define IS_ULTRA3(isp) (IS_1X160(isp)) 76757145Smjacob 76877365Smjacob#define IS_FC(isp) ((isp)->isp_type & ISP_HA_FC) 76977365Smjacob#define IS_2100(isp) ((isp)->isp_type == ISP_HA_FC_2100) 77077365Smjacob#define IS_2200(isp) ((isp)->isp_type == ISP_HA_FC_2200) 771163899Smjacob#define IS_23XX(isp) ((isp)->isp_type >= ISP_HA_FC_2300 && \ 772163899Smjacob (isp)->isp_type < ISP_HA_FC_2400) 77388855Smjacob#define IS_2300(isp) ((isp)->isp_type == ISP_HA_FC_2300) 77488855Smjacob#define IS_2312(isp) ((isp)->isp_type == ISP_HA_FC_2312) 775154704Smjacob#define IS_2322(isp) ((isp)->isp_type == ISP_HA_FC_2322) 776154704Smjacob#define IS_24XX(isp) ((isp)->isp_type >= ISP_HA_FC_2400) 777196008Smjacob#define IS_25XX(isp) ((isp)->isp_type >= ISP_HA_FC_2500) 778291654Smav#define IS_26XX(isp) ((isp)->isp_type >= ISP_HA_FC_2600) 779330888Smav#define IS_27XX(isp) ((isp)->isp_type >= ISP_HA_FC_2700) 78044819Smjacob 78164087Smjacob/* 782155704Smjacob * DMA related macros 78364087Smjacob */ 784163899Smjacob#define DMA_WD3(x) (((uint16_t)(((uint64_t)x) >> 48)) & 0xffff) 785163899Smjacob#define DMA_WD2(x) (((uint16_t)(((uint64_t)x) >> 32)) & 0xffff) 786163899Smjacob#define DMA_WD1(x) ((uint16_t)((x) >> 16) & 0xffff) 787163899Smjacob#define DMA_WD0(x) ((uint16_t)((x) & 0xffff)) 78857145Smjacob 789155704Smjacob#define DMA_LO32(x) ((uint32_t) (x)) 790155704Smjacob#define DMA_HI32(x) ((uint32_t)(((uint64_t)x) >> 32)) 791155704Smjacob 79235388Smjacob/* 79364087Smjacob * Core System Function Prototypes 79435388Smjacob */ 79535388Smjacob 79635388Smjacob/* 797196008Smjacob * Reset Hardware. Totally. Assumes that you'll follow this with a call to isp_init. 79835388Smjacob */ 799196008Smjacobvoid isp_reset(ispsoftc_t *, int); 80035388Smjacob 80135388Smjacob/* 80235388Smjacob * Initialize Hardware to known state 80335388Smjacob */ 804155704Smjacobvoid isp_init(ispsoftc_t *); 80535388Smjacob 80635388Smjacob/* 80739235Sgibbs * Reset the ISP and call completion for any orphaned commands. 80839235Sgibbs */ 809285459Smavint isp_reinit(ispsoftc_t *, int); 81039235Sgibbs 81139235Sgibbs/* 812316084Smav * Shutdown hardware after use. 813316084Smav */ 814316084Smavvoid isp_shutdown(ispsoftc_t *); 815316084Smav 816316084Smav/* 81782689Smjacob * Internal Interrupt Service Routine 81835388Smjacob */ 819316145Smav#ifdef ISP_TARGET_MODE 820316145Smavvoid isp_intr_atioq(ispsoftc_t *); 821316145Smav#endif 822316145Smavvoid isp_intr_async(ispsoftc_t *, uint16_t event); 823316145Smavvoid isp_intr_mbox(ispsoftc_t *, uint16_t mbox0); 824316145Smavvoid isp_intr_respq(ispsoftc_t *); 82535388Smjacob 82682689Smjacob 82735388Smjacob/* 82864087Smjacob * Command Entry Point- Platform Dependent layers call into this 82935388Smjacob */ 83074229Smjacobint isp_start(XS_T *); 831155704Smjacob 83264087Smjacob/* these values are what isp_start returns */ 83364087Smjacob#define CMD_COMPLETE 101 /* command completed */ 83464087Smjacob#define CMD_EAGAIN 102 /* busy- maybe retry later */ 83564087Smjacob#define CMD_QUEUED 103 /* command has been queued for execution */ 83664087Smjacob#define CMD_RQLATER 104 /* requeue this command later */ 83735388Smjacob 83839235Sgibbs/* 83964087Smjacob * Command Completion Point- Core layers call out from this with completed cmds 84064087Smjacob */ 84174229Smjacobvoid isp_done(XS_T *); 84264087Smjacob 84364087Smjacob/* 84443420Smjacob * Platform Dependent to External to Internal Control Function 84539235Sgibbs * 84672355Smjacob * Assumes locks are held on entry. You should note that with many of 847196008Smjacob * these commands locks may be released while this function is called. 84839235Sgibbs * 849196008Smjacob * ... ISPCTL_RESET_BUS, int channel); 850196008Smjacob * Reset BUS on this channel 851196008Smjacob * ... ISPCTL_RESET_DEV, int channel, int target); 852196008Smjacob * Reset Device on this channel at this target. 853196008Smjacob * ... ISPCTL_ABORT_CMD, XS_T *xs); 854196008Smjacob * Abort active transaction described by xs. 855196008Smjacob * ... IPCTL_UPDATE_PARAMS); 856196008Smjacob * Update any operating parameters (speed, etc.) 857196008Smjacob * ... ISPCTL_FCLINK_TEST, int channel); 858196008Smjacob * Test FC link status on this channel 859290993Smav * ... ISPCTL_SCAN_LOOP, int channel); 860290993Smav * Scan local loop on this channel 861196008Smjacob * ... ISPCTL_SCAN_FABRIC, int channel); 862196008Smjacob * Scan fabric on this channel 863196008Smjacob * ... ISPCTL_PDB_SYNC, int channel); 864196008Smjacob * Synchronize port database on this channel 865196008Smjacob * ... ISPCTL_SEND_LIP, int channel); 866196008Smjacob * Send a LIP on this channel 867196008Smjacob * ... ISPCTL_GET_NAMES, int channel, int np, uint64_t *wwnn, uint64_t *wwpn) 868196008Smjacob * Get a WWNN/WWPN for this N-port handle on this channel 869196008Smjacob * ... ISPCTL_RUN_MBOXCMD, mbreg_t *mbp) 870196008Smjacob * Run this mailbox command 871196008Smjacob * ... ISPCTL_GET_PDB, int channel, int nphandle, isp_pdb_t *pdb) 872196008Smjacob * Get PDB on this channel for this N-port handle 873196008Smjacob * ... ISPCTL_PLOGX, isp_plcmd_t *) 874196008Smjacob * Performa a port login/logout 875285146Smav * ... ISPCTL_CHANGE_ROLE, int channel, int role); 876285146Smav * Change role of specified channel 87772355Smjacob * 87872355Smjacob * ISPCTL_PDB_SYNC is somewhat misnamed. It actually is the final step, in 879290993Smav * order, of ISPCTL_FCLINK_TEST, ISPCTL_SCAN_LOOP, and ISPCTL_SCAN_FABRIC. 88072355Smjacob * The main purpose of ISPCTL_PDB_SYNC is to complete management of logging 88172355Smjacob * and logging out of fabric devices (if one is on a fabric) and then marking 88272355Smjacob * the 'loop state' as being ready to now be used for sending commands to 883290993Smav * devices. 88439235Sgibbs */ 88539235Sgibbstypedef enum { 886196008Smjacob ISPCTL_RESET_BUS, 887196008Smjacob ISPCTL_RESET_DEV, 888196008Smjacob ISPCTL_ABORT_CMD, 889196008Smjacob ISPCTL_UPDATE_PARAMS, 890196008Smjacob ISPCTL_FCLINK_TEST, 891196008Smjacob ISPCTL_SCAN_FABRIC, 892196008Smjacob ISPCTL_SCAN_LOOP, 893196008Smjacob ISPCTL_PDB_SYNC, 894196008Smjacob ISPCTL_SEND_LIP, 895196008Smjacob ISPCTL_GET_NAMES, 896196008Smjacob ISPCTL_RUN_MBOXCMD, 897196008Smjacob ISPCTL_GET_PDB, 898285146Smav ISPCTL_PLOGX, 899285146Smav ISPCTL_CHANGE_ROLE 90039235Sgibbs} ispctl_t; 901196008Smjacobint isp_control(ispsoftc_t *, ispctl_t, ...); 90239235Sgibbs 90339235Sgibbs/* 90443420Smjacob * Platform Dependent to Internal to External Control Function 90543420Smjacob */ 90643420Smjacob 90743420Smjacobtypedef enum { 908196008Smjacob ISPASYNC_NEW_TGT_PARAMS, /* SPI New Target Parameters */ 909196008Smjacob ISPASYNC_BUS_RESET, /* All Bus Was Reset */ 91048484Smjacob ISPASYNC_LOOP_DOWN, /* FC Loop Down */ 91148484Smjacob ISPASYNC_LOOP_UP, /* FC Loop Up */ 912196008Smjacob ISPASYNC_LIP, /* FC LIP Received */ 913196008Smjacob ISPASYNC_LOOP_RESET, /* FC Loop Reset Received */ 91472355Smjacob ISPASYNC_CHANGE_NOTIFY, /* FC Change Notification */ 915196008Smjacob ISPASYNC_DEV_ARRIVED, /* FC Device Arrived */ 916196008Smjacob ISPASYNC_DEV_CHANGED, /* FC Device Changed */ 917196008Smjacob ISPASYNC_DEV_STAYED, /* FC Device Stayed */ 918196008Smjacob ISPASYNC_DEV_GONE, /* FC Device Departure */ 919196008Smjacob ISPASYNC_TARGET_NOTIFY, /* All target async notification */ 920238869Smjacob ISPASYNC_TARGET_NOTIFY_ACK, /* All target notify ack required */ 921196008Smjacob ISPASYNC_TARGET_ACTION, /* All target action requested */ 922196008Smjacob ISPASYNC_FW_CRASH, /* All Firmware has crashed */ 923196008Smjacob ISPASYNC_FW_RESTARTED /* All Firmware has been restarted */ 92443420Smjacob} ispasync_t; 925196008Smjacobvoid isp_async(ispsoftc_t *, ispasync_t, ...); 92643420Smjacob 927196008Smjacob#define ISPASYNC_CHANGE_PDB 0 928196008Smjacob#define ISPASYNC_CHANGE_SNS 1 929196008Smjacob#define ISPASYNC_CHANGE_OTHER 2 93072355Smjacob 93143420Smjacob/* 93264087Smjacob * Platform Dependent Error and Debug Printout 933146073Smjacob * 934205698Smjacob * Two required functions for each platform must be provided: 935146073Smjacob * 936155704Smjacob * void isp_prt(ispsoftc_t *, int level, const char *, ...) 937205698Smjacob * void isp_xs_prt(ispsoftc_t *, XS_T *, int level, const char *, ...) 938146073Smjacob * 939146073Smjacob * but due to compiler differences on different platforms this won't be 940205698Smjacob * formally defined here. Instead, they go in each platform definition file. 94139235Sgibbs */ 94270490Smjacob 94364087Smjacob#define ISP_LOGALL 0x0 /* log always */ 94464087Smjacob#define ISP_LOGCONFIG 0x1 /* log configuration messages */ 94564087Smjacob#define ISP_LOGINFO 0x2 /* log informational messages */ 94664087Smjacob#define ISP_LOGWARN 0x4 /* log warning messages */ 94764087Smjacob#define ISP_LOGERR 0x8 /* log error messages */ 94864087Smjacob#define ISP_LOGDEBUG0 0x10 /* log simple debug messages */ 94964087Smjacob#define ISP_LOGDEBUG1 0x20 /* log intermediate debug messages */ 95064087Smjacob#define ISP_LOGDEBUG2 0x40 /* log most debug messages */ 95179235Smjacob#define ISP_LOGDEBUG3 0x80 /* log high frequency debug messages */ 952238869Smjacob#define ISP_LOG_SANCFG 0x100 /* log SAN configuration */ 953205698Smjacob#define ISP_LOG_CWARN 0x200 /* log SCSI command "warnings" (e.g., check conditions) */ 954238869Smjacob#define ISP_LOG_WARN1 0x400 /* log WARNS we might be interested at some time */ 955196008Smjacob#define ISP_LOGTINFO 0x1000 /* log informational messages (target mode) */ 956196008Smjacob#define ISP_LOGTDEBUG0 0x2000 /* log simple debug messages (target mode) */ 957196008Smjacob#define ISP_LOGTDEBUG1 0x4000 /* log intermediate debug messages (target) */ 958196008Smjacob#define ISP_LOGTDEBUG2 0x8000 /* log all debug messages (target) */ 95939235Sgibbs 96064087Smjacob/* 96164087Smjacob * Each Platform provides it's own isposinfo substructure of the ispsoftc 96264087Smjacob * defined above. 96364087Smjacob * 96464087Smjacob * Each platform must also provide the following macros/defines: 96564087Smjacob * 96664087Smjacob * 967196008Smjacob * ISP_FC_SCRLEN FC scratch area DMA length 96864087Smjacob * 969196008Smjacob * ISP_MEMZERO(dst, src) platform zeroing function 970196008Smjacob * ISP_MEMCPY(dst, src, count) platform copying function 971196008Smjacob * ISP_SNPRINTF(buf, bufsize, fmt, ...) snprintf 972196008Smjacob * ISP_DELAY(usecs) microsecond spindelay function 973196008Smjacob * ISP_SLEEP(isp, usecs) microsecond sleep function 97464087Smjacob * 975196008Smjacob * ISP_INLINE ___inline or not- depending on how 976196008Smjacob * good your debugger is 977219098Smjacob * ISP_MIN shorthand for ((a) < (b))? (a) : (b) 978196008Smjacob * 97964087Smjacob * NANOTIME_T nanosecond time type 98064087Smjacob * 98164087Smjacob * GET_NANOTIME(NANOTIME_T *) get current nanotime. 98264087Smjacob * 983155704Smjacob * GET_NANOSEC(NANOTIME_T *) get uint64_t from NANOTIME_T 98464087Smjacob * 98564087Smjacob * NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *) 98664087Smjacob * subtract two NANOTIME_T values 98764087Smjacob * 988196008Smjacob * MAXISPREQUEST(ispsoftc_t *) maximum request queue size 98964087Smjacob * for this particular board type 99064087Smjacob * 991218691Smarius * MEMORYBARRIER(ispsoftc_t *, barrier_type, offset, size, chan) 99264087Smjacob * 99364087Smjacob * Function/Macro the provides memory synchronization on 99464087Smjacob * various objects so that the ISP's and the system's view 99564087Smjacob * of the same object is consistent. 99664087Smjacob * 997155704Smjacob * MBOX_ACQUIRE(ispsoftc_t *) acquire lock on mailbox regs 998163899Smjacob * MBOX_WAIT_COMPLETE(ispsoftc_t *, mbreg_t *) wait for cmd to be done 999155704Smjacob * MBOX_NOTIFY_COMPLETE(ispsoftc_t *) notification of mbox cmd donee 1000155704Smjacob * MBOX_RELEASE(ispsoftc_t *) release lock on mailbox regs 100164087Smjacob * 1002196008Smjacob * FC_SCRATCH_ACQUIRE(ispsoftc_t *, chan) acquire lock on FC scratch area 1003196008Smjacob * return -1 if you cannot 1004196008Smjacob * FC_SCRATCH_RELEASE(ispsoftc_t *, chan) acquire lock on FC scratch area 100572355Smjacob * 1006237210Smjacob * FCP_NEXT_CRN(ispsoftc_t *, XS_T *, rslt, channel, target, lun) generate the next command reference number. XS_T * may be null. 1007237210Smjacob * 100864087Smjacob * SCSI_GOOD SCSI 'Good' Status 100964087Smjacob * SCSI_CHECK SCSI 'Check Condition' Status 101064087Smjacob * SCSI_BUSY SCSI 'Busy' Status 101164087Smjacob * SCSI_QFULL SCSI 'Queue Full' Status 101264087Smjacob * 1013196008Smjacob * XS_T Platform SCSI transaction type (i.e., command for HBA) 1014196008Smjacob * XS_DMA_ADDR_T Platform PCI DMA Address Type 1015196008Smjacob * XS_GET_DMA_SEG(..) Get 32 bit dma segment list value 1016196008Smjacob * XS_GET_DMA64_SEG(..) Get 64 bit dma segment list value 1017317360Smav * XS_NEED_DMA64_SEG(..) dma segment needs 64 bit storage 1018196008Smjacob * XS_ISP(xs) gets an instance out of an XS_T 1019196008Smjacob * XS_CHANNEL(xs) gets the channel (bus # for DUALBUS cards) "" 1020196008Smjacob * XS_TGT(xs) gets the target "" 1021196008Smjacob * XS_LUN(xs) gets the lun "" 1022196008Smjacob * XS_CDBP(xs) gets a pointer to the scsi CDB "" 1023196008Smjacob * XS_CDBLEN(xs) gets the CDB's length "" 1024196008Smjacob * XS_XFRLEN(xs) gets the associated data transfer length "" 1025316406Smav * XS_TIME(xs) gets the time (in seconds) for this command 1026196008Smjacob * XS_GET_RESID(xs) gets the current residual count 1027196008Smjacob * XS_GET_RESID(xs, resid) sets the current residual count 1028196008Smjacob * XS_STSP(xs) gets a pointer to the SCSI status byte "" 1029196008Smjacob * XS_SNSP(xs) gets a pointer to the associate sense data 1030238869Smjacob * XS_TOT_SNSLEN(xs) gets the total length of sense data storage 1031298955Spfg * XS_CUR_SNSLEN(xs) gets the currently used length of sense data storage 1032196008Smjacob * XS_SNSKEY(xs) dereferences XS_SNSP to get the current stored Sense Key 1033205698Smjacob * XS_SNSASC(xs) dereferences XS_SNSP to get the current stored Additional Sense Code 1034205698Smjacob * XS_SNSASCQ(xs) dereferences XS_SNSP to get the current stored Additional Sense Code Qualifier 1035196008Smjacob * XS_TAG_P(xs) predicate of whether this command should be tagged 1036196008Smjacob * XS_TAG_TYPE(xs) which type of tag to use 1037196008Smjacob * XS_SETERR(xs) set error state 103864087Smjacob * 103964087Smjacob * HBA_NOERROR command has no erros 104064087Smjacob * HBA_BOTCH hba botched something 104164087Smjacob * HBA_CMDTIMEOUT command timed out 104264087Smjacob * HBA_SELTIMEOUT selection timed out (also port logouts for FC) 104364087Smjacob * HBA_TGTBSY target returned a BUSY status 104464087Smjacob * HBA_BUSRESET bus reset destroyed command 104564087Smjacob * HBA_ABORTED command was aborted (by request) 104664087Smjacob * HBA_DATAOVR a data overrun was detected 104764087Smjacob * HBA_ARQFAIL Automatic Request Sense failed 104864087Smjacob * 104964087Smjacob * XS_ERR(xs) return current error state 105064087Smjacob * XS_NOERR(xs) there is no error currently set 105164087Smjacob * XS_INITERR(xs) initialize error state 105264087Smjacob * 1053317357Smav * XS_SAVE_SENSE(xs, sp, len) save sense data 1054238869Smjacob * XS_APPEND_SENSE(xs, sp, len) append more sense data 1055238869Smjacob * 1056205698Smjacob * XS_SENSE_VALID(xs) indicates whether sense is valid 1057205698Smjacob * 1058196008Smjacob * DEFAULT_FRAMESIZE(ispsoftc_t *) Default Frame Size 1059196008Smjacob * DEFAULT_EXEC_THROTTLE(ispsoftc_t *) Default Execution Throttle 106064087Smjacob * 1061291188Smav * DEFAULT_ROLE(ispsoftc_t *, int) Get Default Role for a channel 1062196008Smjacob * DEFAULT_IID(ispsoftc_t *, int) Default SCSI initiator ID 1063196008Smjacob * DEFAULT_LOOPID(ispsoftc_t *, int) Default FC Loop ID 106464087Smjacob * 106567047Smjacob * These establish reasonable defaults for each platform. 106667047Smjacob * These must be available independent of card NVRAM and are 106767047Smjacob * to be used should NVRAM not be readable. 106864087Smjacob * 1069196008Smjacob * DEFAULT_NODEWWN(ispsoftc_t *, chan) Default FC Node WWN to use 1070196008Smjacob * DEFAULT_PORTWWN(ispsoftc_t *, chan) Default FC Port WWN to use 107164087Smjacob * 1072196008Smjacob * These defines are hooks to allow the setting of node and 1073196008Smjacob * port WWNs when NVRAM cannot be read or is to be overriden. 107464087Smjacob * 1075196008Smjacob * ACTIVE_NODEWWN(ispsoftc_t *, chan) FC Node WWN to use 1076196008Smjacob * ACTIVE_PORTWWN(ispsoftc_t *, chan) FC Port WWN to use 107787635Smjacob * 1078196008Smjacob * After NVRAM is read, these will be invoked to get the 1079196008Smjacob * node and port WWNs that will actually be used for this 1080196008Smjacob * channel. 1081196008Smjacob * 1082196008Smjacob * 1083155704Smjacob * ISP_IOXPUT_8(ispsoftc_t *, uint8_t srcval, uint8_t *dstptr) 1084155704Smjacob * ISP_IOXPUT_16(ispsoftc_t *, uint16_t srcval, uint16_t *dstptr) 1085155704Smjacob * ISP_IOXPUT_32(ispsoftc_t *, uint32_t srcval, uint32_t *dstptr) 108687635Smjacob * 1087155704Smjacob * ISP_IOXGET_8(ispsoftc_t *, uint8_t *srcptr, uint8_t dstrval) 1088155704Smjacob * ISP_IOXGET_16(ispsoftc_t *, uint16_t *srcptr, uint16_t dstrval) 1089155704Smjacob * ISP_IOXGET_32(ispsoftc_t *, uint32_t *srcptr, uint32_t dstrval) 109087635Smjacob * 1091155704Smjacob * ISP_SWIZZLE_NVRAM_WORD(ispsoftc_t *, uint16_t *) 1092171159Smjacob * ISP_SWIZZLE_NVRAM_LONG(ispsoftc_t *, uint32_t *) 1093171159Smjacob * ISP_SWAP16(ispsoftc_t *, uint16_t srcval) 1094171159Smjacob * ISP_SWAP32(ispsoftc_t *, uint32_t srcval) 109564087Smjacob */ 109677365Smjacob 1097196008Smjacob#ifdef ISP_TARGET_MODE 1098196008Smjacob/* 1099196008Smjacob * The functions below are for the publicly available 1100196008Smjacob * target mode functions that are internal to the Qlogic driver. 1101196008Smjacob */ 1102196008Smjacob 1103196008Smjacob/* 1104196008Smjacob * This function handles new response queue entry appropriate for target mode. 1105196008Smjacob */ 1106196008Smjacobint isp_target_notify(ispsoftc_t *, void *, uint32_t *); 1107196008Smjacob 1108196008Smjacob/* 1109196008Smjacob * This function externalizes the ability to acknowledge an Immediate Notify request. 1110196008Smjacob */ 1111196008Smjacobint isp_notify_ack(ispsoftc_t *, void *); 1112196008Smjacob 1113196008Smjacob/* 1114196008Smjacob * This function externalized acknowledging (success/fail) an ABTS frame 1115196008Smjacob */ 1116196008Smjacobint isp_acknak_abts(ispsoftc_t *, void *, int); 1117196008Smjacob 1118196008Smjacob/* 1119196008Smjacob * General request queue 'put' routine for target mode entries. 1120196008Smjacob */ 1121196008Smjacobint isp_target_put_entry(ispsoftc_t *isp, void *); 1122196008Smjacob 1123196008Smjacob/* 1124196008Smjacob * General routine to put back an ATIO entry- 1125196008Smjacob * used for replenishing f/w resource counts. 1126196008Smjacob * The argument is a pointer to a source ATIO 1127196008Smjacob * or ATIO2. 1128196008Smjacob */ 1129196008Smjacobint isp_target_put_atio(ispsoftc_t *, void *); 1130196008Smjacob 1131196008Smjacob/* 1132196008Smjacob * General routine to send a final CTIO for a command- used mostly for 1133196008Smjacob * local responses. 1134196008Smjacob */ 1135196008Smjacobint isp_endcmd(ispsoftc_t *, ...); 1136196008Smjacob#define ECMD_SVALID 0x100 1137300218Smav#define ECMD_RVALID 0x200 1138300218Smav#define ECMD_TERMINATE 0x400 1139196008Smjacob 1140196008Smjacob/* 1141196008Smjacob * Handle an asynchronous event 1142196008Smjacob */ 1143316092Smavvoid isp_target_async(ispsoftc_t *, int, int); 1144196008Smjacob#endif 114535388Smjacob#endif /* _ISPVAR_H */ 1146