isp_freebsd.h revision 77365
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 77365 2001-05-28 21:20:43Z mjacob $ */ 2/* 3 * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions (CAM version) 4 * Copyright (c) 1997, 1998, 1999, 2000 by Matthew Jacob 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice immediately at the beginning of the file, without modification, 11 * this list of conditions, and the following disclaimer. 12 * 2. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27#ifndef _ISP_FREEBSD_H 28#define _ISP_FREEBSD_H 29 30#define ISP_PLATFORM_VERSION_MAJOR 5 31#define ISP_PLATFORM_VERSION_MINOR 7 32 33/* 34 * We're not ready for primetime yet 35 */ 36#define ISP_SMPLOCK 1 37 38#include <sys/param.h> 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#include <sys/queue.h> 43#include <sys/lock.h> 44#include <sys/malloc.h> 45#include <sys/mutex.h> 46#include <sys/condvar.h> 47#include <sys/proc.h> 48#include <sys/bus.h> 49 50#include <machine/bus_memio.h> 51#include <machine/bus_pio.h> 52#include <machine/bus.h> 53#include <machine/clock.h> 54#include <machine/cpu.h> 55 56#include <cam/cam.h> 57#include <cam/cam_debug.h> 58#include <cam/cam_ccb.h> 59#include <cam/cam_sim.h> 60#include <cam/cam_xpt.h> 61#include <cam/cam_xpt_sim.h> 62#include <cam/cam_debug.h> 63#include <cam/scsi/scsi_all.h> 64#include <cam/scsi/scsi_message.h> 65 66#include "opt_ddb.h" 67#include "opt_isp.h" 68 69#define HANDLE_LOOPSTATE_IN_OUTER_LAYERS 1 70 71typedef void ispfwfunc __P((int, int, int, const u_int16_t **)); 72 73#ifdef ISP_TARGET_MODE 74typedef struct tstate { 75 struct tstate *next; 76 struct cam_path *owner; 77 struct ccb_hdr_slist atios; 78 struct ccb_hdr_slist inots; 79 lun_id_t lun; 80 int bus; 81 u_int32_t hold; 82} tstate_t; 83 84#define LUN_HASH_SIZE 32 85#define LUN_HASH_FUNC(isp, port, lun) \ 86 ((IS_DUALBUS(isp)) ? \ 87 (((lun) & ((LUN_HASH_SIZE >> 1) - 1)) << (port)) : \ 88 ((lun) & (LUN_HASH_SIZE - 1))) 89#endif 90 91struct isposinfo { 92 struct ispsoftc * next; 93 u_int64_t default_port_wwn; 94 u_int64_t default_node_wwn; 95 device_t dev; 96 struct cam_sim *sim; 97 struct cam_path *path; 98 struct cam_sim *sim2; 99 struct cam_path *path2; 100 struct intr_config_hook ehook; 101 u_int8_t mboxwaiting; 102 u_int8_t simqfrozen; 103 u_int8_t drain; 104 u_int8_t intsok; 105 struct mtx lock; 106 struct cv kthread_cv; 107 struct proc *kproc; 108#ifdef ISP_TARGET_MODE 109#define TM_WANTED 0x80 110#define TM_BUSY 0x40 111#define TM_TMODE_ENABLED 0x03 112 u_int8_t tmflags; 113 u_int8_t rstatus; 114 u_int16_t rollinfo; 115 tstate_t tsdflt[2]; /* two busses */ 116 tstate_t *lun_hash[LUN_HASH_SIZE]; 117#endif 118}; 119 120#define isp_lock isp_osinfo.lock 121 122/* 123 * Locking macros... 124 */ 125 126#ifdef ISP_SMPLOCK 127#define ISP_LOCK(x) mtx_lock(&(x)->isp_lock) 128#define ISP_UNLOCK(x) mtx_unlock(&(x)->isp_lock) 129#define ISPLOCK_2_CAMLOCK(isp) \ 130 mtx_unlock(&(isp)->isp_lock); mtx_lock(&Giant) 131#define CAMLOCK_2_ISPLOCK(isp) \ 132 mtx_unlock(&Giant); mtx_lock(&(isp)->isp_lock) 133#else 134#define ISP_LOCK(x) 135#define ISP_UNLOCK(x) 136#define ISPLOCK_2_CAMLOCK(x) 137#define CAMLOCK_2_ISPLOCK(x) 138#endif 139 140/* 141 * Required Macros/Defines 142 */ 143 144#define INLINE __inline 145 146#define ISP2100_SCRLEN 0x400 147 148#define MEMZERO bzero 149#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt)) 150#define SNPRINTF snprintf 151#define STRNCAT strncat 152#define USEC_DELAY DELAY 153#define USEC_SLEEP(isp, x) \ 154 if (isp->isp_osinfo.intsok) \ 155 ISP_UNLOCK(isp); \ 156 DELAY(x); \ 157 if (isp->isp_osinfo.intsok) \ 158 ISP_LOCK(isp) 159 160#define NANOTIME_T struct timespec 161#define GET_NANOTIME nanotime 162#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec) 163#define NANOTIME_SUB nanotime_sub 164 165#define MAXISPREQUEST(isp) 256 166 167#ifdef __alpha__ 168#define MEMORYBARRIER(isp, type, offset, size) alpha_mb() 169#else 170#define MEMORYBARRIER(isp, type, offset, size) 171#endif 172 173#define MBOX_ACQUIRE(isp) 174#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 175#define MBOX_NOTIFY_COMPLETE(isp) \ 176 if (isp->isp_osinfo.mboxwaiting) { \ 177 isp->isp_osinfo.mboxwaiting = 0; \ 178 wakeup(&isp->isp_osinfo.mboxwaiting); \ 179 } \ 180 isp->isp_mboxbsy = 0 181#define MBOX_RELEASE(isp) 182 183#ifndef SCSI_GOOD 184#define SCSI_GOOD SCSI_STATUS_OK 185#endif 186#ifndef SCSI_CHECK 187#define SCSI_CHECK SCSI_STATUS_CHECK_COND 188#endif 189#ifndef SCSI_BUSY 190#define SCSI_BUSY SCSI_STATUS_BUSY 191#endif 192#ifndef SCSI_QFULL 193#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL 194#endif 195 196#define XS_T struct ccb_scsiio 197#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1) 198#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)) 199#define XS_TGT(ccb) (ccb)->ccb_h.target_id 200#define XS_LUN(ccb) (ccb)->ccb_h.target_lun 201 202#define XS_CDBP(ccb) \ 203 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \ 204 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes) 205 206#define XS_CDBLEN(ccb) (ccb)->cdb_len 207#define XS_XFRLEN(ccb) (ccb)->dxfer_len 208#define XS_TIME(ccb) (ccb)->ccb_h.timeout 209#define XS_RESID(ccb) (ccb)->resid 210#define XS_STSP(ccb) (&(ccb)->scsi_status) 211#define XS_SNSP(ccb) (&(ccb)->sense_data) 212 213#define XS_SNSLEN(ccb) \ 214 imin((sizeof((ccb)->sense_data)), ccb->sense_len) 215 216#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf) 217#define XS_TAG_P(ccb) \ 218 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \ 219 (ccb)->tag_action != CAM_TAG_ACTION_NONE) 220 221#define XS_TAG_TYPE(ccb) \ 222 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \ 223 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG)) 224 225 226#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \ 227 (ccb)->ccb_h.status |= v, \ 228 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET 229 230# define HBA_NOERROR CAM_REQ_INPROG 231# define HBA_BOTCH CAM_UNREC_HBA_ERROR 232# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT 233# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT 234# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR 235# define HBA_BUSRESET CAM_SCSI_BUS_RESET 236# define HBA_ABORTED CAM_REQ_ABORTED 237# define HBA_DATAOVR CAM_DATA_RUN_ERR 238# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL 239 240 241#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK) 242 243#define XS_NOERR(ccb) \ 244 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \ 245 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) 246 247#define XS_INITERR(ccb) \ 248 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0 249 250#define XS_SAVE_SENSE(xs, sp) \ 251 (xs)->ccb_h.status |= CAM_AUTOSNS_VALID, \ 252 bcopy(sp->req_sense_data, &(xs)->sense_data, \ 253 imin(XS_SNSLEN(xs), sp->req_sense_len)) 254 255#define XS_SET_STATE_STAT(a, b, c) 256 257#define DEFAULT_IID(x) 7 258#define DEFAULT_LOOPID(x) 109 259#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_node_wwn 260#define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.default_port_wwn 261#define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn 262#define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn 263 264#define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \ 265 if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t)) 266#define ISP_SWIZZLE_ICB(a, b) 267#define ISP_SWIZZLE_REQUEST(a, b) 268#define ISP_UNSWIZZLE_RESPONSE(a, b, c) 269#define ISP_SWIZZLE_SNS_REQ(a, b) 270#define ISP_UNSWIZZLE_SNS_RSP(a, b, c) 271#define ISP_SWIZZLE_NVRAM_WORD(isp, x) 272 273/* 274 * Includes of common header files 275 */ 276 277#include <dev/isp/ispreg.h> 278#include <dev/isp/ispvar.h> 279#include <dev/isp/ispmbox.h> 280 281/* 282 * isp_osinfo definiitions && shorthand 283 */ 284#define SIMQFRZ_RESOURCE 0x1 285#define SIMQFRZ_LOOPDOWN 0x2 286#define SIMQFRZ_TIMED 0x4 287 288#define isp_sim isp_osinfo.sim 289#define isp_path isp_osinfo.path 290#define isp_sim2 isp_osinfo.sim2 291#define isp_path2 isp_osinfo.path2 292#define isp_dev isp_osinfo.dev 293 294/* 295 * prototypes for isp_pci && isp_freebsd to share 296 */ 297extern void isp_attach(struct ispsoftc *); 298extern void isp_uninit(struct ispsoftc *); 299 300/* 301 * Platform private flags 302 */ 303#define ISP_SPRIV_ERRSET 0x1 304#define ISP_SPRIV_INWDOG 0x2 305#define ISP_SPRIV_GRACE 0x4 306#define ISP_SPRIV_DONE 0x8 307 308#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG 309#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG 310#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG) 311 312#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE 313#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE 314#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE) 315 316#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE 317#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE 318#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE) 319 320#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0 321/* 322 * Platform specific inline functions 323 */ 324 325static INLINE void isp_mbox_wait_complete(struct ispsoftc *); 326static INLINE void 327isp_mbox_wait_complete(struct ispsoftc *isp) 328{ 329 if (isp->isp_osinfo.intsok) { 330 isp->isp_osinfo.mboxwaiting = 1; 331#ifdef ISP_SMPLOCK 332 (void) msleep(&isp->isp_osinfo.mboxwaiting, 333 &isp->isp_lock, PRIBIO, "isp_mboxwaiting", 10 * hz); 334#else 335 (void) tsleep(&isp->isp_osinfo.mboxwaiting, PRIBIO, 336 "isp_mboxwaiting", 10 * hz); 337#endif 338 if (isp->isp_mboxbsy != 0) { 339 isp_prt(isp, ISP_LOGWARN, 340 "Interrupting Mailbox Command (0x%x) Timeout", 341 isp->isp_lastmbxcmd); 342 isp->isp_mboxbsy = 0; 343 } 344 isp->isp_osinfo.mboxwaiting = 0; 345 } else { 346 int j; 347 for (j = 0; j < 60 * 10000; j++) { 348 if (isp_intr(isp) == 0) { 349 USEC_DELAY(500); 350 } 351 if (isp->isp_mboxbsy == 0) { 352 break; 353 } 354 } 355 if (isp->isp_mboxbsy != 0) { 356 isp_prt(isp, ISP_LOGWARN, 357 "Polled Mailbox Command (0x%x) Timeout", 358 isp->isp_lastmbxcmd); 359 } 360 } 361} 362 363static INLINE u_int64_t nanotime_sub(struct timespec *, struct timespec *); 364static INLINE u_int64_t 365nanotime_sub(struct timespec *b, struct timespec *a) 366{ 367 u_int64_t elapsed; 368 struct timespec x = *b; 369 timespecsub(&x, a); 370 elapsed = GET_NANOSEC(&x); 371 if (elapsed == 0) 372 elapsed++; 373 return (elapsed); 374} 375 376static INLINE char *strncat(char *, const char *, size_t); 377static INLINE char * 378strncat(char *d, const char *s, size_t c) 379{ 380 char *t = d; 381 382 if (c) { 383 while (*d) 384 d++; 385 while ((*d++ = *s++)) { 386 if (--c == 0) { 387 *d = '\0'; 388 break; 389 } 390 } 391 } 392 return (t); 393} 394 395/* 396 * Common inline functions 397 */ 398 399#include <dev/isp/isp_inline.h> 400#endif /* _ISP_FREEBSD_H */ 401