1 /* $FreeBSD$ */ 2 /* 3 * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions (CAM version) 4 *--------------------------------------- 5 * Copyright (c) 1997, 1998, 1999 by Matthew Jacob 6 * NASA/Ames Research Center 7 * All rights reserved. 8 *--------------------------------------- 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice immediately at the beginning of the file, without modification, 15 * this list of conditions, and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 #ifndef _ISP_FREEBSD_H 35 #define _ISP_FREEBSD_H 36 37 #define ISP_PLATFORM_VERSION_MAJOR 4 38 #define ISP_PLATFORM_VERSION_MINOR 1 39 40 41 #include <sys/param.h> 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/kernel.h> 45 #include <sys/queue.h> 46 47 #include <machine/bus_memio.h> 48 #include <machine/bus_pio.h> 49 #include <machine/bus.h> 50 #include <machine/clock.h> 51 52 #include <cam/cam.h> 53 #include <cam/cam_debug.h> 54 #include <cam/cam_ccb.h> 55 #include <cam/cam_sim.h> 56 #include <cam/cam_xpt.h> 57 #include <cam/cam_xpt_sim.h> 58 #include <cam/cam_debug.h> 59 #include <cam/scsi/scsi_all.h> 60 #include <cam/scsi/scsi_message.h> 61 62 #include "opt_ddb.h" 63 #include "opt_isp.h" 64 #ifdef SCSI_ISP_FABRIC 65 #define ISP2100_FABRIC 1 66 #define ISP2100_SCRLEN 0x400 67 #else 68 #define ISP2100_SCRLEN 0x100 69 #endif 70 #ifdef SCSI_ISP_SCCLUN 71 #define ISP2100_SCCLUN 1 72 #endif 73 74 #ifndef SCSI_CHECK 75 #define SCSI_CHECK SCSI_STATUS_CHECK_COND 76 #endif 77 #ifndef SCSI_BUSY 78 #define SCSI_BUSY SCSI_STATUS_BUSY 79 #endif 80 #ifndef SCSI_QFULL 81 #define SCSI_QFULL SCSI_STATUS_QUEUE_FULL 82 #endif 83 84 #define ISP_SCSI_XFER_T struct ccb_scsiio 85 struct isposinfo { 86 u_int64_t default_wwn; 87 char name[8]; 88 int unit; 89 struct cam_sim *sim; 90 struct cam_path *path; 91 struct cam_sim *sim2; 92 struct cam_path *path2; 93 volatile char simqfrozen; 94 }; 95 #define SIMQFRZ_RESOURCE 0x1 96 #define SIMQFRZ_LOOPDOWN 0x2 97 #define SIMQFRZ_TIMED 0x4 98 99 #define isp_sim isp_osinfo.sim 100 #define isp_path isp_osinfo.path 101 #define isp_sim2 isp_osinfo.sim2 102 #define isp_path2 isp_osinfo.path2 103 #define isp_unit isp_osinfo.unit 104 #define isp_name isp_osinfo.name 105 106 #define MAXISPREQUEST 256 107 108 #include <dev/isp/ispreg.h> 109 #include <dev/isp/ispvar.h> 110 #include <dev/isp/ispmbox.h> 111 112 #define DFLT_DBLEVEL isp_debug 113 extern int isp_debug; 114 #define ISP_LOCKVAL_DECL int isp_spl_save 115 #define ISP_ILOCKVAL_DECL ISP_LOCKVAL_DECL 116 #define ISP_UNLOCK(isp) (void) splx(isp_spl_save) 117 #define ISP_LOCK(isp) isp_spl_save = splcam() 118 #define ISP_ILOCK(isp) ISP_LOCK(isp) 119 #define ISP_IUNLOCK(isp) ISP_UNLOCK(isp) 120 #define IMASK cam_imask 121 122 #define XS_NULL(ccb) ccb == NULL 123 #define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1) 124 125 #define XS_LUN(ccb) (ccb)->ccb_h.target_lun 126 #define XS_TGT(ccb) (ccb)->ccb_h.target_id 127 #define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)) 128 #define XS_RESID(ccb) (ccb)->resid 129 #define XS_XFRLEN(ccb) (ccb)->dxfer_len 130 #define XS_CDBLEN(ccb) (ccb)->cdb_len 131 #define XS_CDBP(ccb) (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \ 132 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes) 133 #define XS_STS(ccb) (ccb)->scsi_status 134 #define XS_TIME(ccb) (ccb)->ccb_h.timeout 135 #define XS_SNSP(ccb) (&(ccb)->sense_data) 136 #define XS_SNSLEN(ccb) \ 137 imin((sizeof((ccb)->sense_data)), ccb->sense_len) 138 #define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf) 139 140 /* 141 * A little tricky- HBA_NOERROR is "in progress" so 142 * that XS_CMD_DONE can transition this to CAM_REQ_CMP. 143 */ 144 #define HBA_NOERROR CAM_REQ_INPROG 145 #define HBA_BOTCH CAM_UNREC_HBA_ERROR 146 #define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT 147 #define HBA_SELTIMEOUT CAM_SEL_TIMEOUT 148 #define HBA_TGTBSY CAM_SCSI_STATUS_ERROR 149 #define HBA_BUSRESET CAM_SCSI_BUS_RESET 150 #define HBA_ABORTED CAM_REQ_ABORTED 151 #define HBA_DATAOVR CAM_DATA_RUN_ERR 152 #define HBA_ARQFAIL CAM_AUTOSENSE_FAIL 153 154 #define XS_SNS_IS_VALID(ccb) ((ccb)->ccb_h.status |= CAM_AUTOSNS_VALID) 155 #define XS_IS_SNS_VALID(ccb) (((ccb)->ccb_h.status & CAM_AUTOSNS_VALID) != 0) 156 157 #define XS_INITERR(ccb) \ 158 (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \ 159 (ccb)->ccb_h.status |= CAM_REQ_INPROG, \ 160 (ccb)->ccb_h.spriv_field0 = CAM_REQ_INPROG 161 #define XS_SETERR(ccb, v) (ccb)->ccb_h.spriv_field0 = v 162 #define XS_ERR(ccb) (ccb)->ccb_h.spriv_field0 163 #define XS_NOERR(ccb) \ 164 ((ccb)->ccb_h.spriv_field0 == CAM_REQ_INPROG) 165 166 extern void isp_done(struct ccb_scsiio *); 167 #define XS_CMD_DONE(sccb) isp_done(sccb) 168 169 #define XS_IS_CMD_DONE(ccb) \ 170 (((ccb)->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) 171 172 /* 173 * Can we tag? 174 */ 175 #define XS_CANTAG(ccb) (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) \ 176 && (ccb)->tag_action != CAM_TAG_ACTION_NONE) 177 /* 178 * And our favorite tag is.... 179 */ 180 #define XS_KINDOF_TAG(ccb) \ 181 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \ 182 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG)) 183 184 #define CMD_COMPLETE 0 185 #define CMD_EAGAIN 1 186 #define CMD_QUEUED 2 187 #define CMD_RQLATER 3 188 #define STOP_WATCHDOG(f, s) 189 190 extern void isp_attach(struct ispsoftc *); 191 extern void isp_uninit(struct ispsoftc *); 192 193 #define MEMZERO bzero 194 #define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt)) 195 #ifdef __alpha__ 196 #define MemoryBarrier alpha_mb 197 #else 198 #define MemoryBarrier() 199 #endif 200 201 202 #define DMA_MSW(x) (((x) >> 16) & 0xffff) 203 #define DMA_LSW(x) (((x) & 0xffff)) 204 205 #define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \ 206 bcopy(src, dest, sizeof (isp_pdb_t)) 207 #define ISP_SWIZZLE_ICB(a, b) 208 #define ISP_SWIZZLE_REQUEST(a, b) 209 #define ISP_UNSWIZZLE_RESPONSE(a, b) 210 #define ISP_SWIZZLE_SNS_REQ(a, b) 211 #define ISP_UNSWIZZLE_SNS_RSP(a, b, c) 212 213 #define IDPRINTF(lev, x) if (isp->isp_dblev >= (u_int8_t) lev) printf x 214 #define PRINTF printf 215 #define CFGPRINTF if (bootverbose || DFLT_DBLEVEL > 1) printf 216 217 #define SYS_DELAY(x) DELAY(x) 218 219 #define FC_FW_READY_DELAY (5 * 1000000) 220 #define DEFAULT_LOOPID(x) 109 221 #define DEFAULT_WWN(x) (x)->isp_osinfo.default_wwn 222 223 #define INLINE __inline 224 #include <dev/isp/isp_inline.h> 225 #endif /* _ISP_FREEBSD_H */ 226