isp_freebsd.h revision 73246
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 73246 2001-03-01 02:15:58Z 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 6 32 33/* 34 * We're not ready for primetime yet 35 */ 36#if 0 37#if ((ISP_PLATFORM_VERSION_MAJOR * 10) + ISP_PLATFORM_VERSION_MINOR) >= 54 38#define ISP_SMPLOCK 1 39#endif 40#endif 41 42 43#include <sys/param.h> 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/kernel.h> 47#include <sys/queue.h> 48#include <sys/malloc.h> 49#include <sys/mutex.h> 50#include <sys/proc.h> 51#include <sys/bus.h> 52 53#include <machine/bus_memio.h> 54#include <machine/bus_pio.h> 55#include <machine/bus.h> 56#include <machine/clock.h> 57#include <machine/cpu.h> 58 59#include <cam/cam.h> 60#include <cam/cam_debug.h> 61#include <cam/cam_ccb.h> 62#include <cam/cam_sim.h> 63#include <cam/cam_xpt.h> 64#include <cam/cam_xpt_sim.h> 65#include <cam/cam_debug.h> 66#include <cam/scsi/scsi_all.h> 67#include <cam/scsi/scsi_message.h> 68 69#include "opt_ddb.h" 70#include "opt_isp.h" 71 72typedef void ispfwfunc __P((int, int, int, const u_int16_t **)); 73 74#ifdef ISP_TARGET_MODE 75typedef struct tstate { 76 struct tstate *next; 77 struct cam_path *owner; 78 struct ccb_hdr_slist atios; 79 struct ccb_hdr_slist inots; 80 lun_id_t lun; 81 u_int32_t hold; 82} tstate_t; 83 84/* 85 * This should work very well for 100% of parallel SCSI cases, 100% 86 * of non-SCCLUN FC cases, and hopefully some larger fraction of the 87 * SCCLUN FC cases. Basically, we index by the low 5 bits of lun and 88 * then linear search. This has to be reasonably zippy, but not crucially 89 * so. 90 */ 91#define LUN_HASH_SIZE 32 92#define LUN_HASH_FUNC(lun) ((lun) & 0x1f) 93 94#endif 95 96struct isposinfo { 97 struct ispsoftc * next; 98 u_int64_t default_port_wwn; 99 u_int64_t default_node_wwn; 100 device_t dev; 101 struct cam_sim *sim; 102 struct cam_path *path; 103 struct cam_sim *sim2; 104 struct cam_path *path2; 105 struct intr_config_hook ehook; 106 u_int8_t mboxwaiting; 107 u_int8_t simqfrozen; 108 u_int8_t drain; 109 u_int8_t intsok; 110#ifdef ISP_SMPLOCK 111 struct mtx lock; 112#else 113 volatile u_int32_t islocked; 114 int splsaved; 115#endif 116#ifdef ISP_TARGET_MODE 117#define TM_WANTED 0x01 118#define TM_BUSY 0x02 119#define TM_TMODE_ENABLED 0x80 120 u_int8_t tmflags; 121 u_int8_t rstatus; 122 u_int16_t rollinfo; 123 tstate_t tsdflt; 124 tstate_t *lun_hash[LUN_HASH_SIZE]; 125#endif 126}; 127 128/* 129 * Locking macros... 130 */ 131 132#ifdef ISP_SMPLOCK 133#define ISP_LOCK(x) mtx_lock(&(x)->isp_osinfo.lock) 134#define ISP_UNLOCK(x) mtx_unlock(&(x)->isp_osinfo.lock) 135#else 136#define ISP_LOCK isp_lock 137#define ISP_UNLOCK isp_unlock 138#endif 139 140 141/* 142 * Required Macros/Defines 143 */ 144 145#define INLINE __inline 146 147#define ISP2100_SCRLEN 0x400 148 149#define MEMZERO bzero 150#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt)) 151#define SNPRINTF snprintf 152#define STRNCAT strncat 153#define USEC_DELAY DELAY 154#define USEC_SLEEP(isp, x) \ 155 if (isp->isp_osinfo.intsok) \ 156 ISP_UNLOCK(isp); \ 157 DELAY(x); \ 158 if (isp->isp_osinfo.intsok) \ 159 ISP_LOCK(isp) 160 161#define NANOTIME_T struct timespec 162#define GET_NANOTIME nanotime 163#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec) 164#define NANOTIME_SUB nanotime_sub 165 166#define MAXISPREQUEST(isp) 256 167 168#ifdef __alpha__ 169#define MEMORYBARRIER(isp, type, offset, size) alpha_mb() 170#else 171#define MEMORYBARRIER(isp, type, offset, size) 172#endif 173 174#define MBOX_ACQUIRE(isp) 175#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 176#define MBOX_NOTIFY_COMPLETE(isp) \ 177 if (isp->isp_osinfo.mboxwaiting) { \ 178 isp->isp_osinfo.mboxwaiting = 0; \ 179 wakeup(&isp->isp_osinfo.mboxwaiting); \ 180 } \ 181 isp->isp_mboxbsy = 0 182#define MBOX_RELEASE(isp) 183 184#ifndef SCSI_GOOD 185#define SCSI_GOOD SCSI_STATUS_OK 186#endif 187#ifndef SCSI_CHECK 188#define SCSI_CHECK SCSI_STATUS_CHECK_COND 189#endif 190#ifndef SCSI_BUSY 191#define SCSI_BUSY SCSI_STATUS_BUSY 192#endif 193#ifndef SCSI_QFULL 194#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL 195#endif 196 197#define XS_T struct ccb_scsiio 198#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1) 199#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)) 200#define XS_TGT(ccb) (ccb)->ccb_h.target_id 201#define XS_LUN(ccb) (ccb)->ccb_h.target_lun 202 203#define XS_CDBP(ccb) \ 204 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \ 205 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes) 206 207#define XS_CDBLEN(ccb) (ccb)->cdb_len 208#define XS_XFRLEN(ccb) (ccb)->dxfer_len 209#define XS_TIME(ccb) (ccb)->ccb_h.timeout 210#define XS_RESID(ccb) (ccb)->resid 211#define XS_STSP(ccb) (&(ccb)->scsi_status) 212#define XS_SNSP(ccb) (&(ccb)->sense_data) 213 214#define XS_SNSLEN(ccb) \ 215 imin((sizeof((ccb)->sense_data)), ccb->sense_len) 216 217#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf) 218#define XS_TAG_P(ccb) \ 219 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \ 220 (ccb)->tag_action != CAM_TAG_ACTION_NONE) 221 222#define XS_TAG_TYPE(ccb) \ 223 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \ 224 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG)) 225 226 227#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \ 228 (ccb)->ccb_h.status |= v, \ 229 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET 230 231# define HBA_NOERROR CAM_REQ_INPROG 232# define HBA_BOTCH CAM_UNREC_HBA_ERROR 233# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT 234# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT 235# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR 236# define HBA_BUSRESET CAM_SCSI_BUS_RESET 237# define HBA_ABORTED CAM_REQ_ABORTED 238# define HBA_DATAOVR CAM_DATA_RUN_ERR 239# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL 240 241 242#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK) 243 244#define XS_NOERR(ccb) \ 245 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \ 246 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) 247 248#define XS_INITERR(ccb) \ 249 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0 250 251#define XS_SAVE_SENSE(xs, sp) \ 252 (xs)->ccb_h.status |= CAM_AUTOSNS_VALID, \ 253 bcopy(sp->req_sense_data, &(xs)->sense_data, \ 254 imin(XS_SNSLEN(xs), sp->req_sense_len)) 255 256#define XS_SET_STATE_STAT(a, b, c) 257 258#define DEFAULT_IID(x) 7 259#define DEFAULT_LOOPID(x) 109 260#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_node_wwn 261#define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.default_port_wwn 262#define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn 263#define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn 264 265#define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \ 266 if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t)) 267#define ISP_SWIZZLE_ICB(a, b) 268#define ISP_SWIZZLE_REQUEST(a, b) 269#define ISP_UNSWIZZLE_RESPONSE(a, b, c) 270#define ISP_SWIZZLE_SNS_REQ(a, b) 271#define ISP_UNSWIZZLE_SNS_RSP(a, b, c) 272#define ISP_SWIZZLE_NVRAM_WORD(isp, x) 273 274/* 275 * Includes of common header files 276 */ 277 278#include <dev/isp/ispreg.h> 279#include <dev/isp/ispvar.h> 280#include <dev/isp/ispmbox.h> 281 282/* 283 * isp_osinfo definiitions && shorthand 284 */ 285#define SIMQFRZ_RESOURCE 0x1 286#define SIMQFRZ_LOOPDOWN 0x2 287#define SIMQFRZ_TIMED 0x4 288 289#define isp_sim isp_osinfo.sim 290#define isp_path isp_osinfo.path 291#define isp_sim2 isp_osinfo.sim2 292#define isp_path2 isp_osinfo.path2 293#define isp_dev isp_osinfo.dev 294 295/* 296 * prototypes for isp_pci && isp_freebsd to share 297 */ 298extern void isp_attach(struct ispsoftc *); 299extern void isp_uninit(struct ispsoftc *); 300 301/* 302 * Platform private flags 303 */ 304#define ISP_SPRIV_ERRSET 0x1 305#define ISP_SPRIV_INWDOG 0x2 306#define ISP_SPRIV_GRACE 0x4 307#define ISP_SPRIV_DONE 0x8 308 309#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG 310#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG 311#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG) 312 313#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE 314#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE 315#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE) 316 317#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE 318#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE 319#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE) 320 321#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0 322/* 323 * Platform specific inline functions 324 */ 325#ifndef ISP_SMPLOCK 326static INLINE void isp_lock(struct ispsoftc *); 327static INLINE void 328isp_lock(struct ispsoftc *isp) 329{ 330 int s = splcam(); 331 if (isp->isp_osinfo.islocked++ == 0) { 332 isp->isp_osinfo.splsaved = s; 333 } else { 334 splx(s); 335 } 336} 337 338static INLINE void isp_unlock(struct ispsoftc *); 339static INLINE void 340isp_unlock(struct ispsoftc *isp) 341{ 342 if (isp->isp_osinfo.islocked) { 343 if (--isp->isp_osinfo.islocked == 0) { 344 splx(isp->isp_osinfo.splsaved); 345 } 346 } 347} 348#endif 349 350static INLINE void isp_mbox_wait_complete(struct ispsoftc *); 351static INLINE void 352isp_mbox_wait_complete(struct ispsoftc *isp) 353{ 354 if (isp->isp_osinfo.intsok) { 355 isp->isp_osinfo.mboxwaiting = 1; 356#ifdef ISP_SMPLOCK 357 (void) msleep(&isp->isp_osinfo.mboxwaiting, 358 &isp->isp_osinfo.lock, PRIBIO, "isp_mboxwaiting", 10 * hz); 359#else 360 (void) tsleep(&isp->isp_osinfo.mboxwaiting, PRIBIO, 361 "isp_mboxwaiting", 10 * hz); 362#endif 363 if (isp->isp_mboxbsy != 0) { 364 isp_prt(isp, ISP_LOGWARN, 365 "Interrupting Mailbox Command (0x%x) Timeout", 366 isp->isp_lastmbxcmd); 367 isp->isp_mboxbsy = 0; 368 } 369 isp->isp_osinfo.mboxwaiting = 0; 370 } else { 371 int j; 372 for (j = 0; j < 60 * 10000; j++) { 373 if (isp_intr(isp) == 0) { 374 USEC_DELAY(500); 375 } 376 if (isp->isp_mboxbsy == 0) { 377 break; 378 } 379 } 380 if (isp->isp_mboxbsy != 0) { 381 isp_prt(isp, ISP_LOGWARN, 382 "Polled Mailbox Command (0x%x) Timeout", 383 isp->isp_lastmbxcmd); 384 } 385 } 386} 387 388static INLINE u_int64_t nanotime_sub(struct timespec *, struct timespec *); 389static INLINE u_int64_t 390nanotime_sub(struct timespec *b, struct timespec *a) 391{ 392 u_int64_t elapsed; 393 struct timespec x = *b; 394 timespecsub(&x, a); 395 elapsed = GET_NANOSEC(&x); 396 if (elapsed == 0) 397 elapsed++; 398 return (elapsed); 399} 400 401static INLINE char *strncat(char *, const char *, size_t); 402static INLINE char * 403strncat(char *d, const char *s, size_t c) 404{ 405 char *t = d; 406 407 if (c) { 408 while (*d) 409 d++; 410 while ((*d++ = *s++)) { 411 if (--c == 0) { 412 *d = '\0'; 413 break; 414 } 415 } 416 } 417 return (t); 418} 419 420/* 421 * Common inline functions 422 */ 423 424#include <dev/isp/isp_inline.h> 425#endif /* _ISP_FREEBSD_H */ 426