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