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