isp_freebsd.h revision 205236
150477Speter/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 205236 2010-03-17 02:48:14Z mjacob $ */ 2139749Simp/*- 380313Smjacob * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions 435388Smjacob * 5196008Smjacob * Copyright (c) 1997-2008 by Matthew Jacob 6154704Smjacob * All rights reserved. 7154704Smjacob * 835388Smjacob * Redistribution and use in source and binary forms, with or without 935388Smjacob * modification, are permitted provided that the following conditions 1035388Smjacob * are met: 1135388Smjacob * 1. Redistributions of source code must retain the above copyright 1235388Smjacob * notice immediately at the beginning of the file, without modification, 1335388Smjacob * this list of conditions, and the following disclaimer. 1466189Smjacob * 2. The name of the author may not be used to endorse or promote products 1566189Smjacob * derived from this software without specific prior written permission. 1635388Smjacob * 1735388Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1835388Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1935388Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2035388Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 2135388Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2235388Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2335388Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2435388Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2535388Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2635388Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2735388Smjacob * SUCH DAMAGE. 2835388Smjacob */ 2935388Smjacob#ifndef _ISP_FREEBSD_H 3035388Smjacob#define _ISP_FREEBSD_H 3135388Smjacob 3239445Smjacob#include <sys/param.h> 3348487Smjacob#include <sys/systm.h> 3495533Smike#include <sys/endian.h> 3574914Sjhb#include <sys/lock.h> 36157943Smjacob#include <sys/kernel.h> 37157943Smjacob#include <sys/queue.h> 3859452Smjacob#include <sys/malloc.h> 3967365Sjhb#include <sys/mutex.h> 4077365Smjacob#include <sys/condvar.h> 41157943Smjacob 4262496Smjacob#include <sys/proc.h> 4373246Smjacob#include <sys/bus.h> 4439445Smjacob 4548487Smjacob#include <machine/bus.h> 4662496Smjacob#include <machine/cpu.h> 47196008Smjacob#include <machine/stdarg.h> 4839445Smjacob 4948487Smjacob#include <cam/cam.h> 5048487Smjacob#include <cam/cam_debug.h> 5148487Smjacob#include <cam/cam_ccb.h> 5248487Smjacob#include <cam/cam_sim.h> 5348487Smjacob#include <cam/cam_xpt.h> 5448487Smjacob#include <cam/cam_xpt_sim.h> 5548487Smjacob#include <cam/cam_debug.h> 5648487Smjacob#include <cam/scsi/scsi_all.h> 5748487Smjacob#include <cam/scsi/scsi_message.h> 5848487Smjacob 5952348Smjacob#include "opt_ddb.h" 6048487Smjacob#include "opt_isp.h" 61102272Smjacob 62196008Smjacob#define ISP_PLATFORM_VERSION_MAJOR 7 63196008Smjacob#define ISP_PLATFORM_VERSION_MINOR 0 64158656Smjacob 6587635Smjacob/* 6687635Smjacob * Efficiency- get rid of SBus code && tests unless we need them. 6787635Smjacob */ 68153072Sru#ifdef __sparc64__ 6987635Smjacob#define ISP_SBUS_SUPPORTED 1 7087635Smjacob#else 7187635Smjacob#define ISP_SBUS_SUPPORTED 0 7287635Smjacob#endif 7339235Sgibbs 74100680Smjacob#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 75100680Smjacob 7655366Smjacob#ifdef ISP_TARGET_MODE 7787635Smjacob#define ISP_TARGET_FUNCTIONS 1 78196008Smjacob#define ATPDPSIZE 4096 79196008Smjacob 80196008Smjacob#include <dev/isp/isp_target.h> 81196008Smjacob 8284242Smjacobtypedef struct { 83196008Smjacob void * next; 84155704Smjacob uint32_t orig_datalen; 85155704Smjacob uint32_t bytes_xfered; 86155704Smjacob uint32_t last_xframt; 87196008Smjacob uint32_t tag; 88196008Smjacob uint32_t lun; 89196008Smjacob uint32_t nphdl; 90196008Smjacob uint32_t sid; 91196008Smjacob uint32_t portid; 92196008Smjacob uint32_t 93196008Smjacob oxid : 16, 94196008Smjacob cdb0 : 8, 95196008Smjacob : 1, 96196008Smjacob dead : 1, 97196008Smjacob tattr : 3, 9898288Smjacob state : 3; 9984242Smjacob} atio_private_data_t; 10098288Smjacob#define ATPD_STATE_FREE 0 10198288Smjacob#define ATPD_STATE_ATIO 1 10298288Smjacob#define ATPD_STATE_CAM 2 10398288Smjacob#define ATPD_STATE_CTIO 3 10498288Smjacob#define ATPD_STATE_LAST_CTIO 4 10598288Smjacob#define ATPD_STATE_PDON 5 10684242Smjacob 107196008Smjacobtypedef union inot_private_data inot_private_data_t; 108196008Smjacobunion inot_private_data { 109196008Smjacob inot_private_data_t *next; 110196008Smjacob struct { 111196008Smjacob isp_notify_t nt; /* must be first! */ 112196008Smjacob uint8_t data[64]; /* sb QENTRY_LEN, but order of definitions is wrong */ 113196008Smjacob uint32_t tag_id, seq_id; 114196008Smjacob } rd; 115196008Smjacob}; 116196008Smjacob 11755366Smjacobtypedef struct tstate { 118196008Smjacob SLIST_ENTRY(tstate) next; 11955366Smjacob struct cam_path *owner; 12055366Smjacob struct ccb_hdr_slist atios; 12155366Smjacob struct ccb_hdr_slist inots; 122155704Smjacob uint32_t hold; 12398288Smjacob int atio_count; 124125548Smjacob int inot_count; 125196008Smjacob inot_private_data_t * restart_queue; 126196008Smjacob inot_private_data_t * ntfree; 127196008Smjacob inot_private_data_t ntpool[ATPDPSIZE]; 128196008Smjacob atio_private_data_t * atfree; 129196008Smjacob atio_private_data_t atpool[ATPDPSIZE]; 13055366Smjacob} tstate_t; 13155366Smjacob 132196008Smjacob#define LUN_HASH_SIZE 32 133196008Smjacob#define LUN_HASH_FUNC(lun) ((lun) & (LUN_HASH_SIZE - 1)) 134196008Smjacob 13555366Smjacob#endif 13655366Smjacob 137169292Smjacob/* 138169292Smjacob * Per command info. 139169292Smjacob */ 140169292Smjacobstruct isp_pcmd { 141169292Smjacob struct isp_pcmd * next; 142169292Smjacob bus_dmamap_t dmap; /* dma map for this command */ 143169292Smjacob struct ispsoftc * isp; /* containing isp */ 144169292Smjacob struct callout wdog; /* watchdog timer */ 145169292Smjacob}; 146169292Smjacob#define ISP_PCMD(ccb) (ccb)->ccb_h.spriv_ptr1 147169292Smjacob#define PISP_PCMD(ccb) ((struct isp_pcmd *)ISP_PCMD(ccb)) 148169292Smjacob 149196008Smjacob/* 150196008Smjacob * Per channel information 151196008Smjacob */ 152196008SmjacobSLIST_HEAD(tslist, tstate); 153196008Smjacob 154196008Smjacobstruct isp_fc { 155196008Smjacob struct cam_sim *sim; 156196008Smjacob struct cam_path *path; 157196008Smjacob struct ispsoftc *isp; 158196008Smjacob struct proc *kproc; 159196008Smjacob bus_dma_tag_t tdmat; 160196008Smjacob bus_dmamap_t tdmap; 161196008Smjacob uint64_t def_wwpn; 162196008Smjacob uint64_t def_wwnn; 163196008Smjacob uint32_t loop_down_time; 164196008Smjacob uint32_t loop_down_limit; 165196008Smjacob uint32_t gone_device_time; 166196008Smjacob uint32_t 167196008Smjacob#ifdef ISP_TARGET_MODE 168196008Smjacob#ifdef ISP_INTERNAL_TARGET 169196008Smjacob proc_active : 1, 170196008Smjacob#endif 171196008Smjacob tm_luns_enabled : 1, 172196008Smjacob tm_enable_defer : 1, 173196008Smjacob tm_enabled : 1, 174196008Smjacob#endif 175163899Smjacob simqfrozen : 3, 176196008Smjacob default_id : 8, 177163899Smjacob hysteresis : 8, 178205236Smjacob def_role : 2, /* default role */ 179164272Smjacob gdt_running : 1, 180196008Smjacob loop_dead : 1, 181200089Smjacob fcbsy : 1, 182200089Smjacob ready : 1; 183196008Smjacob struct callout ldt; /* loop down timer */ 184196008Smjacob struct callout gdt; /* gone device timer */ 185196008Smjacob#ifdef ISP_TARGET_MODE 186196008Smjacob struct tslist lun_hash[LUN_HASH_SIZE]; 187196008Smjacob#ifdef ISP_INTERNAL_TARGET 188196008Smjacob struct proc * target_proc; 189196008Smjacob#endif 190196008Smjacob#endif 191196008Smjacob}; 192196008Smjacob 193196008Smjacobstruct isp_spi { 194196008Smjacob struct cam_sim *sim; 195196008Smjacob struct cam_path *path; 196196008Smjacob uint32_t 197196008Smjacob#ifdef ISP_TARGET_MODE 198196008Smjacob#ifdef ISP_INTERNAL_TARGET 199196008Smjacob proc_active : 1, 200196008Smjacob#endif 201196008Smjacob tm_luns_enabled : 1, 202196008Smjacob tm_enable_defer : 1, 203196008Smjacob tm_enabled : 1, 204196008Smjacob#endif 205196008Smjacob simqfrozen : 3, 206205236Smjacob def_role : 2, 207196008Smjacob iid : 4; 208196008Smjacob#ifdef ISP_TARGET_MODE 209196008Smjacob struct tslist lun_hash[LUN_HASH_SIZE]; 210196008Smjacob#ifdef ISP_INTERNAL_TARGET 211196008Smjacob struct proc * target_proc; 212196008Smjacob#endif 213196008Smjacob#endif 214196008Smjacob}; 215196008Smjacob 216196008Smjacobstruct isposinfo { 217196008Smjacob /* 218196008Smjacob * Linkage, locking, and identity 219196008Smjacob */ 220169292Smjacob struct mtx lock; 221196008Smjacob device_t dev; 222196008Smjacob struct cdev * cdev; 223196008Smjacob struct intr_config_hook ehook; 224196008Smjacob struct cam_devq * devq; 225196008Smjacob 226196008Smjacob /* 227196008Smjacob * Firmware pointer 228196008Smjacob */ 229166756Sluigi const struct firmware * fw; 230196008Smjacob 231196008Smjacob /* 232196008Smjacob * DMA related sdtuff 233196008Smjacob */ 234196008Smjacob bus_space_tag_t bus_tag; 235196008Smjacob bus_dma_tag_t dmat; 236196008Smjacob bus_space_handle_t bus_handle; 23793706Smjacob bus_dma_tag_t cdmat; 23893706Smjacob bus_dmamap_t cdmap; 239196008Smjacob 240169292Smjacob /* 241196008Smjacob * Command and transaction related related stuff 242169292Smjacob */ 243169292Smjacob struct isp_pcmd * pcmd_pool; 244169292Smjacob struct isp_pcmd * pcmd_free; 245169292Smjacob 246196008Smjacob uint32_t 24755366Smjacob#ifdef ISP_TARGET_MODE 248196008Smjacob tmwanted : 1, 249196008Smjacob tmbusy : 1, 250196008Smjacob#else 251196008Smjacob : 2, 25255366Smjacob#endif 253196008Smjacob forcemulti : 1, 254196008Smjacob timer_active : 1, 255196008Smjacob autoconf : 1, 256196008Smjacob ehook_active : 1, 257196008Smjacob disabled : 1, 258196008Smjacob mbox_sleeping : 1, 259196008Smjacob mbox_sleep_ok : 1, 260196008Smjacob mboxcmd_done : 1, 261196008Smjacob mboxbsy : 1; 262196008Smjacob 263196008Smjacob struct callout tmo; /* general timer */ 264196008Smjacob 265196008Smjacob /* 266196008Smjacob * misc- needs to be sorted better XXXXXX 267196008Smjacob */ 268196008Smjacob int framesize; 269196008Smjacob int exec_throttle; 270196008Smjacob int cont_max; 271196008Smjacob 272196008Smjacob#ifdef ISP_TARGET_MODE 273196008Smjacob cam_status * rptr; 274196008Smjacob#endif 275196008Smjacob 276196008Smjacob /* 277196008Smjacob * Per-type private storage... 278196008Smjacob */ 279196008Smjacob union { 280196008Smjacob struct isp_fc *fc; 281196008Smjacob struct isp_spi *spi; 282196008Smjacob void *ptr; 283196008Smjacob } pc; 28435388Smjacob}; 285196008Smjacob#define ISP_FC_PC(isp, chan) (&(isp)->isp_osinfo.pc.fc[(chan)]) 286196008Smjacob#define ISP_SPI_PC(isp, chan) (&(isp)->isp_osinfo.pc.spi[(chan)]) 287196008Smjacob#define ISP_GET_PC(isp, chan, tag, rslt) \ 288196008Smjacob if (IS_SCSI(isp)) { \ 289196008Smjacob rslt = ISP_SPI_PC(isp, chan)-> tag; \ 290196008Smjacob } else { \ 291196008Smjacob rslt = ISP_FC_PC(isp, chan)-> tag; \ 292196008Smjacob } 293196008Smjacob#define ISP_GET_PC_ADDR(isp, chan, tag, rp) \ 294196008Smjacob if (IS_SCSI(isp)) { \ 295196008Smjacob rp = &ISP_SPI_PC(isp, chan)-> tag; \ 296196008Smjacob } else { \ 297196008Smjacob rp = &ISP_FC_PC(isp, chan)-> tag; \ 298196008Smjacob } 299196008Smjacob#define ISP_SET_PC(isp, chan, tag, val) \ 300196008Smjacob if (IS_SCSI(isp)) { \ 301196008Smjacob ISP_SPI_PC(isp, chan)-> tag = val; \ 302196008Smjacob } else { \ 303196008Smjacob ISP_FC_PC(isp, chan)-> tag = val; \ 304196008Smjacob } 30539235Sgibbs 30677365Smjacob#define isp_lock isp_osinfo.lock 307167501Smjacob#define isp_bus_tag isp_osinfo.bus_tag 308167501Smjacob#define isp_bus_handle isp_osinfo.bus_handle 30977365Smjacob 31064092Smjacob/* 31169525Smjacob * Locking macros... 31269525Smjacob */ 313169292Smjacob#define ISP_LOCK(isp) mtx_lock(&isp->isp_osinfo.lock) 314169292Smjacob#define ISP_UNLOCK(isp) mtx_unlock(&isp->isp_osinfo.lock) 31569525Smjacob 31669525Smjacob/* 31764092Smjacob * Required Macros/Defines 31864092Smjacob */ 31948487Smjacob 320196008Smjacob#define ISP_FC_SCRLEN 0x1000 32145284Smjacob 322196008Smjacob#define ISP_MEMZERO(a, b) memset(a, 0, b) 323196008Smjacob#define ISP_MEMCPY memcpy 324196008Smjacob#define ISP_SNPRINTF snprintf 325196008Smjacob#define ISP_DELAY DELAY 326196008Smjacob#define ISP_SLEEP(isp, x) DELAY(x) 32735388Smjacob 328196008Smjacob#ifndef DIAGNOSTIC 329196008Smjacob#define ISP_INLINE __inline 330196008Smjacob#else 331196008Smjacob#define ISP_INLINE 332196008Smjacob#endif 333196008Smjacob 33464092Smjacob#define NANOTIME_T struct timespec 33564092Smjacob#define GET_NANOTIME nanotime 33664092Smjacob#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec) 337164272Smjacob#define NANOTIME_SUB isp_nanotime_sub 33862496Smjacob 33999598Smjacob#define MAXISPREQUEST(isp) ((IS_FC(isp) || IS_ULTRA2(isp))? 1024 : 256) 34062496Smjacob 34193706Smjacob#define MEMORYBARRIER(isp, type, offset, size) \ 34293706Smjacobswitch (type) { \ 34393706Smjacobcase SYNC_SFORDEV: \ 34493706Smjacobcase SYNC_REQUEST: \ 345196008Smjacob bus_dmamap_sync(isp->isp_osinfo.cdmat, \ 346196008Smjacob isp->isp_osinfo.cdmap, \ 34793706Smjacob BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); \ 34893706Smjacob break; \ 34993706Smjacobcase SYNC_SFORCPU: \ 35093706Smjacobcase SYNC_RESULT: \ 351196008Smjacob bus_dmamap_sync(isp->isp_osinfo.cdmat, \ 352196008Smjacob isp->isp_osinfo.cdmap, \ 35393706Smjacob BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); \ 35493706Smjacob break; \ 355167501Smjacobcase SYNC_REG: \ 356196008Smjacob bus_space_barrier(isp->isp_osinfo.bus_tag, \ 357196008Smjacob isp->isp_osinfo.bus_handle, offset, size, \ 358167501Smjacob BUS_SPACE_BARRIER_READ); \ 359167501Smjacob break; \ 36093706Smjacobdefault: \ 36193706Smjacob break; \ 36293706Smjacob} 36362496Smjacob 364163899Smjacob#define MBOX_ACQUIRE isp_mbox_acquire 36564092Smjacob#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 366164272Smjacob#define MBOX_NOTIFY_COMPLETE isp_mbox_notify_done 367163899Smjacob#define MBOX_RELEASE isp_mbox_release 36862496Smjacob 369196008Smjacob#define FC_SCRATCH_ACQUIRE isp_fc_scratch_acquire 370196008Smjacob#define FC_SCRATCH_RELEASE(isp, chan) isp->isp_osinfo.pc.fc[chan].fcbsy = 0 37190224Smjacob 37264092Smjacob#ifndef SCSI_GOOD 37364092Smjacob#define SCSI_GOOD SCSI_STATUS_OK 37464092Smjacob#endif 37564092Smjacob#ifndef SCSI_CHECK 37664092Smjacob#define SCSI_CHECK SCSI_STATUS_CHECK_COND 37764092Smjacob#endif 37864092Smjacob#ifndef SCSI_BUSY 37964092Smjacob#define SCSI_BUSY SCSI_STATUS_BUSY 38064092Smjacob#endif 38164092Smjacob#ifndef SCSI_QFULL 38264092Smjacob#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL 38364092Smjacob#endif 38464092Smjacob 38564092Smjacob#define XS_T struct ccb_scsiio 386155704Smjacob#define XS_DMA_ADDR_T bus_addr_t 387196008Smjacob#define XS_GET_DMA64_SEG(a, b, c) \ 388196008Smjacob{ \ 389196008Smjacob ispds64_t *d = a; \ 390196008Smjacob bus_dma_segment_t *e = b; \ 391196008Smjacob uint32_t f = c; \ 392196008Smjacob e += f; \ 393196008Smjacob d->ds_base = DMA_LO32(e->ds_addr); \ 394196008Smjacob d->ds_basehi = DMA_HI32(e->ds_addr); \ 395196008Smjacob d->ds_count = e->ds_len; \ 396196008Smjacob} 397196008Smjacob#define XS_GET_DMA_SEG(a, b, c) \ 398196008Smjacob{ \ 399196008Smjacob ispds_t *d = a; \ 400196008Smjacob bus_dma_segment_t *e = b; \ 401196008Smjacob uint32_t f = c; \ 402196008Smjacob e += f; \ 403196008Smjacob d->ds_base = DMA_LO32(e->ds_addr); \ 404196008Smjacob d->ds_count = e->ds_len; \ 405196008Smjacob} 406169292Smjacob#define XS_ISP(ccb) cam_sim_softc(xpt_path_sim((ccb)->ccb_h.path)) 40764092Smjacob#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)) 40864092Smjacob#define XS_TGT(ccb) (ccb)->ccb_h.target_id 40964092Smjacob#define XS_LUN(ccb) (ccb)->ccb_h.target_lun 41035388Smjacob 41164092Smjacob#define XS_CDBP(ccb) \ 41264092Smjacob (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \ 41364092Smjacob (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes) 41464092Smjacob 41564092Smjacob#define XS_CDBLEN(ccb) (ccb)->cdb_len 41648487Smjacob#define XS_XFRLEN(ccb) (ccb)->dxfer_len 41748487Smjacob#define XS_TIME(ccb) (ccb)->ccb_h.timeout 418196008Smjacob#define XS_GET_RESID(ccb) (ccb)->resid 419196008Smjacob#define XS_SET_RESID(ccb, r) (ccb)->resid = r 42064092Smjacob#define XS_STSP(ccb) (&(ccb)->scsi_status) 42148487Smjacob#define XS_SNSP(ccb) (&(ccb)->sense_data) 42264092Smjacob 42352348Smjacob#define XS_SNSLEN(ccb) \ 42452348Smjacob imin((sizeof((ccb)->sense_data)), ccb->sense_len) 42564092Smjacob 42648487Smjacob#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf) 42764092Smjacob#define XS_TAG_P(ccb) \ 42864092Smjacob (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \ 42964092Smjacob (ccb)->tag_action != CAM_TAG_ACTION_NONE) 43035388Smjacob 43164092Smjacob#define XS_TAG_TYPE(ccb) \ 43264092Smjacob ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \ 43364092Smjacob ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG)) 43464092Smjacob 43564092Smjacob 43664092Smjacob#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \ 43764092Smjacob (ccb)->ccb_h.status |= v, \ 43864092Smjacob (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET 43964092Smjacob 44064092Smjacob# define HBA_NOERROR CAM_REQ_INPROG 44164092Smjacob# define HBA_BOTCH CAM_UNREC_HBA_ERROR 44264092Smjacob# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT 44364092Smjacob# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT 44464092Smjacob# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR 44564092Smjacob# define HBA_BUSRESET CAM_SCSI_BUS_RESET 44664092Smjacob# define HBA_ABORTED CAM_REQ_ABORTED 44764092Smjacob# define HBA_DATAOVR CAM_DATA_RUN_ERR 44864092Smjacob# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL 44964092Smjacob 45064092Smjacob 45164092Smjacob#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK) 45264092Smjacob 45364092Smjacob#define XS_NOERR(ccb) \ 45464092Smjacob (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \ 45564092Smjacob ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) 45664092Smjacob 45764092Smjacob#define XS_INITERR(ccb) \ 45864092Smjacob XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0 45964092Smjacob 460164272Smjacob#define XS_SAVE_SENSE(xs, sense_ptr, sense_len) \ 461164272Smjacob (xs)->ccb_h.status |= CAM_AUTOSNS_VALID; \ 462164272Smjacob memcpy(&(xs)->sense_data, sense_ptr, imin(XS_SNSLEN(xs), sense_len)) 46364092Smjacob 46464092Smjacob#define XS_SET_STATE_STAT(a, b, c) 46564092Smjacob 466196008Smjacob#define DEFAULT_FRAMESIZE(isp) isp->isp_osinfo.framesize 467196008Smjacob#define DEFAULT_EXEC_THROTTLE(isp) isp->isp_osinfo.exec_throttle 46864092Smjacob 469196008Smjacob#define GET_DEFAULT_ROLE(isp, chan) \ 470205236Smjacob (IS_FC(isp)? ISP_FC_PC(isp, chan)->def_role : ISP_SPI_PC(isp, chan)->def_role) 471196008Smjacob#define SET_DEFAULT_ROLE(isp, chan, val) \ 472196008Smjacob if (IS_FC(isp)) { \ 473205236Smjacob ISP_FC_PC(isp, chan)->def_role = val; \ 474196008Smjacob } else { \ 475205236Smjacob ISP_SPI_PC(isp, chan)->def_role = val; \ 476196008Smjacob } 477167473Smjacob 478196008Smjacob#define DEFAULT_IID(isp, chan) isp->isp_osinfo.pc.spi[chan].iid 479167473Smjacob 480196008Smjacob#define DEFAULT_LOOPID(x, chan) isp->isp_osinfo.pc.fc[chan].default_id 481196008Smjacob 482196008Smjacob#define DEFAULT_NODEWWN(isp, chan) isp_default_wwn(isp, chan, 0, 1) 483196008Smjacob#define DEFAULT_PORTWWN(isp, chan) isp_default_wwn(isp, chan, 0, 0) 484196008Smjacob#define ACTIVE_NODEWWN(isp, chan) isp_default_wwn(isp, chan, 1, 1) 485196008Smjacob#define ACTIVE_PORTWWN(isp, chan) isp_default_wwn(isp, chan, 1, 0) 486196008Smjacob 487196008Smjacob 48887635Smjacob#if BYTE_ORDER == BIG_ENDIAN 48987635Smjacob#ifdef ISP_SBUS_SUPPORTED 49087635Smjacob#define ISP_IOXPUT_8(isp, s, d) *(d) = s 49187635Smjacob#define ISP_IOXPUT_16(isp, s, d) \ 49287635Smjacob *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s) 49387635Smjacob#define ISP_IOXPUT_32(isp, s, d) \ 49487635Smjacob *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s) 495155704Smjacob#define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 49687635Smjacob#define ISP_IOXGET_16(isp, s, d) \ 49787635Smjacob d = (isp->isp_bustype == ISP_BT_SBUS)? \ 498155704Smjacob *((uint16_t *)s) : bswap16(*((uint16_t *)s)) 49987635Smjacob#define ISP_IOXGET_32(isp, s, d) \ 50087635Smjacob d = (isp->isp_bustype == ISP_BT_SBUS)? \ 501155704Smjacob *((uint32_t *)s) : bswap32(*((uint32_t *)s)) 502163899Smjacob 503163899Smjacob#else /* ISP_SBUS_SUPPORTED */ 50487635Smjacob#define ISP_IOXPUT_8(isp, s, d) *(d) = s 50587635Smjacob#define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s) 50687635Smjacob#define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s) 507155704Smjacob#define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 508155704Smjacob#define ISP_IOXGET_16(isp, s, d) d = bswap16(*((uint16_t *)s)) 509155704Smjacob#define ISP_IOXGET_32(isp, s, d) d = bswap32(*((uint32_t *)s)) 51087635Smjacob#endif 51187635Smjacob#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp) 512171159Smjacob#define ISP_SWIZZLE_NVRAM_LONG(isp, rp) *rp = bswap32(*rp) 513163899Smjacob 514163899Smjacob#define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)s)) 515163899Smjacob#define ISP_IOZGET_16(isp, s, d) d = (*((uint16_t *)s)) 516163899Smjacob#define ISP_IOZGET_32(isp, s, d) d = (*((uint32_t *)s)) 517163899Smjacob#define ISP_IOZPUT_8(isp, s, d) *(d) = s 518163899Smjacob#define ISP_IOZPUT_16(isp, s, d) *(d) = s 519163899Smjacob#define ISP_IOZPUT_32(isp, s, d) *(d) = s 520163899Smjacob 521163899Smjacob 52287635Smjacob#else 52387635Smjacob#define ISP_IOXPUT_8(isp, s, d) *(d) = s 52487635Smjacob#define ISP_IOXPUT_16(isp, s, d) *(d) = s 52587635Smjacob#define ISP_IOXPUT_32(isp, s, d) *(d) = s 52687635Smjacob#define ISP_IOXGET_8(isp, s, d) d = *(s) 52787635Smjacob#define ISP_IOXGET_16(isp, s, d) d = *(s) 52887635Smjacob#define ISP_IOXGET_32(isp, s, d) d = *(s) 52987635Smjacob#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) 530171159Smjacob#define ISP_SWIZZLE_NVRAM_LONG(isp, rp) 531163899Smjacob 532163899Smjacob#define ISP_IOZPUT_8(isp, s, d) *(d) = s 533163899Smjacob#define ISP_IOZPUT_16(isp, s, d) *(d) = bswap16(s) 534163899Smjacob#define ISP_IOZPUT_32(isp, s, d) *(d) = bswap32(s) 535163899Smjacob 536163899Smjacob#define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)(s))) 537163899Smjacob#define ISP_IOZGET_16(isp, s, d) d = bswap16(*((uint16_t *)(s))) 538163899Smjacob#define ISP_IOZGET_32(isp, s, d) d = bswap32(*((uint32_t *)(s))) 539163899Smjacob 54087635Smjacob#endif 54164092Smjacob 542171159Smjacob#define ISP_SWAP16(isp, s) bswap16(s) 543171159Smjacob#define ISP_SWAP32(isp, s) bswap32(s) 544171159Smjacob 54548487Smjacob/* 54664092Smjacob * Includes of common header files 54748487Smjacob */ 54835388Smjacob 54964092Smjacob#include <dev/isp/ispreg.h> 55064092Smjacob#include <dev/isp/ispvar.h> 55164092Smjacob#include <dev/isp/ispmbox.h> 55235388Smjacob 55364092Smjacob/* 55464092Smjacob * isp_osinfo definiitions && shorthand 55564092Smjacob */ 55664092Smjacob#define SIMQFRZ_RESOURCE 0x1 55764092Smjacob#define SIMQFRZ_LOOPDOWN 0x2 55864092Smjacob#define SIMQFRZ_TIMED 0x4 55964092Smjacob 56073246Smjacob#define isp_dev isp_osinfo.dev 56164092Smjacob 56264092Smjacob/* 56364092Smjacob * prototypes for isp_pci && isp_freebsd to share 56464092Smjacob */ 565196008Smjacobextern int isp_attach(ispsoftc_t *); 566196008Smjacobextern void isp_detach(ispsoftc_t *); 567157943Smjacobextern void isp_uninit(ispsoftc_t *); 568196008Smjacobextern uint64_t isp_default_wwn(ispsoftc_t *, int, int, int); 56964092Smjacob 57064092Smjacob/* 57199756Smjacob * driver global data 57299756Smjacob */ 57399756Smjacobextern int isp_announced; 574163899Smjacobextern int isp_fabric_hysteresis; 575163899Smjacobextern int isp_loop_down_limit; 576164272Smjacobextern int isp_gone_device_time; 577163899Smjacobextern int isp_quickboot_time; 578196008Smjacobextern int isp_autoconfig; 57999756Smjacob 58099756Smjacob/* 58164092Smjacob * Platform private flags 58264092Smjacob */ 58362172Smjacob#define ISP_SPRIV_ERRSET 0x1 58462172Smjacob#define ISP_SPRIV_DONE 0x8 58562172Smjacob 58662172Smjacob#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE 58762172Smjacob#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE 58862172Smjacob#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE) 58962172Smjacob 59062172Smjacob#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0 591155228Smjacob 59239235Sgibbs/* 593164272Smjacob * Platform Library Functions 594164272Smjacob */ 595164272Smjacobvoid isp_prt(ispsoftc_t *, int level, const char *, ...) __printflike(3, 4); 596164272Smjacobuint64_t isp_nanotime_sub(struct timespec *, struct timespec *); 597164272Smjacobint isp_mbox_acquire(ispsoftc_t *); 598164272Smjacobvoid isp_mbox_wait_complete(ispsoftc_t *, mbreg_t *); 599164272Smjacobvoid isp_mbox_notify_done(ispsoftc_t *); 600164272Smjacobvoid isp_mbox_release(ispsoftc_t *); 601196008Smjacobint isp_fc_scratch_acquire(ispsoftc_t *, int); 602164272Smjacobint isp_mstohz(int); 603169292Smjacobvoid isp_platform_intr(void *); 604169292Smjacobvoid isp_common_dmateardown(ispsoftc_t *, struct ccb_scsiio *, uint32_t); 605164272Smjacob 606164272Smjacob/* 607169292Smjacob * Platform Version specific defines 608166177Smjacob */ 609169292Smjacob#define BUS_DMA_ROOTARG(x) bus_get_dma_tag(x) 610169292Smjacob#define isp_dma_tag_create(a, b, c, d, e, f, g, h, i, j, k, z) \ 611169292Smjacob bus_dma_tag_create(a, b, c, d, e, f, g, h, i, j, k, \ 612169292Smjacob busdma_lock_mutex, &isp->isp_osinfo.lock, z) 613169292Smjacob 614166935Smjacob#define isp_setup_intr bus_setup_intr 615166177Smjacob 616169292Smjacob#define isp_sim_alloc(a, b, c, d, e, f, g, h) \ 617169292Smjacob cam_sim_alloc(a, b, c, d, e, &(d)->isp_osinfo.lock, f, g, h) 618169292Smjacob 619166177Smjacob/* Should be BUS_SPACE_MAXSIZE, but MAXPHYS is larger than BUS_SPACE_MAXSIZE */ 620196008Smjacob#define ISP_NSEGS ((MAXPHYS / PAGE_SIZE) + 1) 621166177Smjacob 622196008Smjacob#define ISP_PATH_PRT(i, l, p, ...) \ 623196008Smjacob if ((l) == ISP_LOGALL || ((l)& (i)->isp_dblev) != 0) { \ 624196008Smjacob xpt_print(p, __VA_ARGS__); \ 625196008Smjacob } 626196008Smjacob 627166177Smjacob/* 62864092Smjacob * Platform specific inline functions 62939235Sgibbs */ 63044819Smjacob 63164092Smjacob/* 632164272Smjacob * ISP General Library functions 63364092Smjacob */ 63444819Smjacob 635155228Smjacob#include <dev/isp/isp_library.h> 636155228Smjacob 63735388Smjacob#endif /* _ISP_FREEBSD_H */ 638