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/systm.h> 35#include <sys/endian.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.h> 46#include <machine/clock.h> 47#include <machine/cpu.h> 48 49#include <cam/cam.h> 50#include <cam/cam_debug.h> 51#include <cam/cam_ccb.h> 52#include <cam/cam_sim.h> 53#include <cam/cam_xpt.h> 54#include <cam/cam_xpt_sim.h> 55#include <cam/cam_debug.h> 56#include <cam/scsi/scsi_all.h> 57#include <cam/scsi/scsi_message.h> 58 59#include "opt_ddb.h" 60#include "opt_isp.h" 61 62#ifdef PAE 63#define ISP_DAC_SUPPORTED 1 64#endif 65 66/* 67 * Efficiency- get rid of SBus code && tests unless we need them. 68 */ 69#ifdef __sparc64__ 70#define ISP_SBUS_SUPPORTED 1 71#else 72#define ISP_SBUS_SUPPORTED 0 73#endif 74 75#define HANDLE_LOOPSTATE_IN_OUTER_LAYERS 1 76/* #define ISP_SMPLOCK 1 */ 77 78#ifdef ISP_SMPLOCK 79#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 80#else 81#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY 82#endif 83 84typedef void ispfwfunc(int, int, int, u_int16_t **); 85 86#ifdef ISP_TARGET_MODE 87#define ISP_TARGET_FUNCTIONS 1 88#define ATPDPSIZE 256 89typedef struct { 90 u_int32_t orig_datalen; 91 u_int32_t bytes_xfered; 92 u_int32_t last_xframt; 93 u_int32_t tag : 16, 94 lun : 13, /* not enough */ 95 state : 3; 96} atio_private_data_t; 97#define ATPD_STATE_FREE 0 98#define ATPD_STATE_ATIO 1 99#define ATPD_STATE_CAM 2 100#define ATPD_STATE_CTIO 3 101#define ATPD_STATE_LAST_CTIO 4 102#define ATPD_STATE_PDON 5 103 104typedef struct tstate { 105 struct tstate *next; 106 struct cam_path *owner; 107 struct ccb_hdr_slist atios; 108 struct ccb_hdr_slist inots; 109 lun_id_t lun; 110 int bus; 111 u_int32_t hold; 112 int atio_count; 113 int inot_count; 114} tstate_t; 115 116#define LUN_HASH_SIZE 32 117#define LUN_HASH_FUNC(isp, port, lun) \ 118 ((IS_DUALBUS(isp)) ? \ 119 (((lun) & ((LUN_HASH_SIZE >> 1) - 1)) << (port)) : \ 120 ((lun) & (LUN_HASH_SIZE - 1))) 121#endif 122 123struct isposinfo { 124 struct ispsoftc * next; 125 u_int64_t default_port_wwn; 126 u_int64_t default_node_wwn; 127 u_int32_t default_id; 128 device_t dev; 129 struct cam_sim *sim; 130 struct cam_path *path; 131 struct cam_sim *sim2; 132 struct cam_path *path2; 133 struct intr_config_hook ehook; 134 u_int8_t : 1, 135 fcbsy : 1, 136 ktmature : 1, 137 mboxwaiting : 1, 138 intsok : 1, 139 simqfrozen : 3; 140 struct mtx lock; 141 struct cv kthread_cv; 142 struct proc *kproc; 143 bus_dma_tag_t cdmat; 144 bus_dmamap_t cdmap; 145#define isp_cdmat isp_osinfo.cdmat 146#define isp_cdmap isp_osinfo.cdmap 147#ifdef ISP_TARGET_MODE 148#define TM_WILDCARD_ENABLED 0x02 149#define TM_TMODE_ENABLED 0x01 150 u_int8_t tmflags[2]; /* two busses */ 151#define NLEACT 4 152 union ccb * leact[NLEACT]; 153 tstate_t tsdflt[2]; /* two busses */ 154 tstate_t *lun_hash[LUN_HASH_SIZE]; 155 atio_private_data_t atpdp[ATPDPSIZE]; 156#endif 157}; 158 159#define isp_lock isp_osinfo.lock 160 161/* 162 * Locking macros... 163 */ 164 165#ifdef ISP_SMPLOCK 166#define ISP_LOCK(x) mtx_lock(&(x)->isp_lock) 167#define ISP_UNLOCK(x) mtx_unlock(&(x)->isp_lock) 168#define ISPLOCK_2_CAMLOCK(isp) \ 169 mtx_unlock(&(isp)->isp_lock); mtx_lock(&Giant) 170#define CAMLOCK_2_ISPLOCK(isp) \ 171 mtx_unlock(&Giant); mtx_lock(&(isp)->isp_lock) 172#else 173#define ISP_LOCK(x) do { } while (0) 174#define ISP_UNLOCK(x) do { } while (0) 175#define ISPLOCK_2_CAMLOCK(isp) do { } while (0) 176#define CAMLOCK_2_ISPLOCK(isp) do { } while (0) 177#endif 178 179/* 180 * Required Macros/Defines 181 */ 182 183#define INLINE __inline 184 185#define ISP2100_SCRLEN 0x800 186 187#define MEMZERO bzero 188#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt)) 189#define SNPRINTF snprintf 190#define USEC_DELAY DELAY 191#define USEC_SLEEP(isp, x) \ 192 if (isp->isp_osinfo.intsok) \ 193 ISP_UNLOCK(isp); \ 194 DELAY(x); \ 195 if (isp->isp_osinfo.intsok) \ 196 ISP_LOCK(isp) 197 198#define NANOTIME_T struct timespec 199#define GET_NANOTIME nanotime 200#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec) 201#define NANOTIME_SUB nanotime_sub 202 203#define MAXISPREQUEST(isp) ((IS_FC(isp) || IS_ULTRA2(isp))? 1024 : 256) 204 205#define MEMORYBARRIER(isp, type, offset, size) \ 206switch (type) { \ 207case SYNC_SFORDEV: \ 208case SYNC_REQUEST: \ 209 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \ 210 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); \ 211 break; \ 212case SYNC_SFORCPU: \ 213case SYNC_RESULT: \ 214 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \ 215 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); \ 216 break; \ 217default: \ 218 break; \ 219} 220 221#define MBOX_ACQUIRE(isp) 222#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 223#define MBOX_NOTIFY_COMPLETE(isp) \ 224 if (isp->isp_osinfo.mboxwaiting) { \ 225 isp->isp_osinfo.mboxwaiting = 0; \ 226 wakeup(&isp->isp_mbxworkp); \ 227 } \ 228 isp->isp_mboxbsy = 0 229#define MBOX_RELEASE(isp) 230 231#define FC_SCRATCH_ACQUIRE(isp) \ 232 if (isp->isp_osinfo.fcbsy) { \ 233 isp_prt(isp, ISP_LOGWARN, \ 234 "FC scratch area busy (line %d)!", __LINE__); \ 235 } else \ 236 isp->isp_osinfo.fcbsy = 1 237#define FC_SCRATCH_RELEASE(isp) isp->isp_osinfo.fcbsy = 0 238 239#ifndef SCSI_GOOD 240#define SCSI_GOOD SCSI_STATUS_OK 241#endif 242#ifndef SCSI_CHECK 243#define SCSI_CHECK SCSI_STATUS_CHECK_COND 244#endif 245#ifndef SCSI_BUSY 246#define SCSI_BUSY SCSI_STATUS_BUSY 247#endif 248#ifndef SCSI_QFULL 249#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL 250#endif 251 252#define XS_T struct ccb_scsiio 253#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1) 254#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)) 255#define XS_TGT(ccb) (ccb)->ccb_h.target_id 256#define XS_LUN(ccb) (ccb)->ccb_h.target_lun 257 258#define XS_CDBP(ccb) \ 259 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \ 260 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes) 261 262#define XS_CDBLEN(ccb) (ccb)->cdb_len 263#define XS_XFRLEN(ccb) (ccb)->dxfer_len 264#define XS_TIME(ccb) (ccb)->ccb_h.timeout 265#define XS_RESID(ccb) (ccb)->resid 266#define XS_STSP(ccb) (&(ccb)->scsi_status) 267#define XS_SNSP(ccb) (&(ccb)->sense_data) 268 269#define XS_SNSLEN(ccb) \ 270 imin((sizeof((ccb)->sense_data)), ccb->sense_len) 271 272#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf) 273#define XS_TAG_P(ccb) \ 274 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \ 275 (ccb)->tag_action != CAM_TAG_ACTION_NONE) 276 277#define XS_TAG_TYPE(ccb) \ 278 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \ 279 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG)) 280 281 282#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \ 283 (ccb)->ccb_h.status |= v, \ 284 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET 285 286# define HBA_NOERROR CAM_REQ_INPROG 287# define HBA_BOTCH CAM_UNREC_HBA_ERROR 288# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT 289# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT 290# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR 291# define HBA_BUSRESET CAM_SCSI_BUS_RESET 292# define HBA_ABORTED CAM_REQ_ABORTED 293# define HBA_DATAOVR CAM_DATA_RUN_ERR 294# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL 295 296 297#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK) 298 299#define XS_NOERR(ccb) \ 300 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \ 301 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) 302 303#define XS_INITERR(ccb) \ 304 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0 305 306#define XS_SAVE_SENSE(xs, sp) \ 307 (xs)->ccb_h.status |= CAM_AUTOSNS_VALID, \ 308 bcopy(sp->req_sense_data, &(xs)->sense_data, \ 309 imin(XS_SNSLEN(xs), sp->req_sense_len)) 310 311#define XS_SET_STATE_STAT(a, b, c) 312 313#define DEFAULT_IID(x) (isp)->isp_osinfo.default_id 314#define DEFAULT_LOOPID(x) (isp)->isp_osinfo.default_id 315#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_node_wwn 316#define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.default_port_wwn 317#define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn 318#define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn 319 320#if BYTE_ORDER == BIG_ENDIAN 321#ifdef ISP_SBUS_SUPPORTED 322#define ISP_IOXPUT_8(isp, s, d) *(d) = s 323#define ISP_IOXPUT_16(isp, s, d) \ 324 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s) 325#define ISP_IOXPUT_32(isp, s, d) \ 326 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s) 327#define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s)) 328#define ISP_IOXGET_16(isp, s, d) \ 329 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 330 *((u_int16_t *)s) : bswap16(*((u_int16_t *)s)) 331#define ISP_IOXGET_32(isp, s, d) \ 332 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 333 *((u_int32_t *)s) : bswap32(*((u_int32_t *)s)) 334#else 335#define ISP_IOXPUT_8(isp, s, d) *(d) = s 336#define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s) 337#define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s) 338#define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s)) 339#define ISP_IOXGET_16(isp, s, d) d = bswap16(*((u_int16_t *)s)) 340#define ISP_IOXGET_32(isp, s, d) d = bswap32(*((u_int32_t *)s)) 341#endif 342#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp) 343#else 344#define ISP_IOXPUT_8(isp, s, d) *(d) = s 345#define ISP_IOXPUT_16(isp, s, d) *(d) = s 346#define ISP_IOXPUT_32(isp, s, d) *(d) = s 347#define ISP_IOXGET_8(isp, s, d) d = *(s) 348#define ISP_IOXGET_16(isp, s, d) d = *(s) 349#define ISP_IOXGET_32(isp, s, d) d = *(s) 350#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) 351#endif 352 353/* 354 * Includes of common header files 355 */ 356 357#include <dev/isp/ispreg.h> 358#include <dev/isp/ispvar.h> 359#include <dev/isp/ispmbox.h> 360 361void isp_prt(struct ispsoftc *, int level, const char *, ...) 362 __printflike(3, 4); 363/* 364 * isp_osinfo definiitions && shorthand 365 */ 366#define SIMQFRZ_RESOURCE 0x1 367#define SIMQFRZ_LOOPDOWN 0x2 368#define SIMQFRZ_TIMED 0x4 369 370#define isp_sim isp_osinfo.sim 371#define isp_path isp_osinfo.path 372#define isp_sim2 isp_osinfo.sim2 373#define isp_path2 isp_osinfo.path2 374#define isp_dev isp_osinfo.dev 375 376/* 377 * prototypes for isp_pci && isp_freebsd to share 378 */ 379extern void isp_attach(struct ispsoftc *); 380extern void isp_uninit(struct ispsoftc *); 381 382/* 383 * driver global data 384 */ 385extern int isp_announced; 386 387/* 388 * Platform private flags 389 */ 390#define ISP_SPRIV_ERRSET 0x1 391#define ISP_SPRIV_INWDOG 0x2 392#define ISP_SPRIV_GRACE 0x4 393#define ISP_SPRIV_DONE 0x8 394 395#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG 396#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG 397#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG) 398 399#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE 400#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE 401#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE) 402 403#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE 404#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE 405#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE) 406 407#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0 408/* 409 * Platform specific inline functions 410 */ 411 412static INLINE void isp_mbox_wait_complete(struct ispsoftc *); 413static INLINE void 414isp_mbox_wait_complete(struct ispsoftc *isp) 415{ 416 if (isp->isp_osinfo.intsok) { 417 int lim = ((isp->isp_mbxwrk0)? 120 : 20) * hz; 418 isp->isp_osinfo.mboxwaiting = 1; 419#ifdef ISP_SMPLOCK 420 (void) msleep(&isp->isp_mbxworkp, 421 &isp->isp_lock, PRIBIO, "isp_mboxwaiting", lim); 422#else 423 (void) tsleep(&isp->isp_mbxworkp, 424 PRIBIO, "isp_mboxwaiting", lim); 425#endif 426 if (isp->isp_mboxbsy != 0) { 427 isp_prt(isp, ISP_LOGWARN, 428 "Interrupting Mailbox Command (0x%x) Timeout", 429 isp->isp_lastmbxcmd); 430 isp->isp_mboxbsy = 0; 431 } 432 isp->isp_osinfo.mboxwaiting = 0; 433 } else { 434 int lim = ((isp->isp_mbxwrk0)? 240 : 60) * 10000; 435 int j; 436 for (j = 0; j < lim; j++) { 437 u_int16_t isr, sema, mbox; 438 if (isp->isp_mboxbsy == 0) { 439 break; 440 } 441 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) { 442 isp_intr(isp, isr, sema, mbox); 443 if (isp->isp_mboxbsy == 0) { 444 break; 445 } 446 } 447 USEC_DELAY(500); 448 } 449 if (isp->isp_mboxbsy != 0) { 450 isp_prt(isp, ISP_LOGWARN, 451 "Polled Mailbox Command (0x%x) Timeout", 452 isp->isp_lastmbxcmd); 453 } 454 } 455} 456 457static INLINE u_int64_t nanotime_sub(struct timespec *, struct timespec *); 458static INLINE u_int64_t 459nanotime_sub(struct timespec *b, struct timespec *a) 460{ 461 u_int64_t elapsed; 462 struct timespec x = *b; 463 timespecsub(&x, a); 464 elapsed = GET_NANOSEC(&x); 465 if (elapsed == 0) 466 elapsed++; 467 return (elapsed); 468} 469 470static INLINE char *strncat(char *, const char *, size_t); 471static INLINE char * 472strncat(char *d, const char *s, size_t c) 473{ 474 char *t = d; 475 476 if (c) { 477 while (*d) 478 d++; 479 while ((*d++ = *s++)) { 480 if (--c == 0) { 481 *d = '\0'; 482 break; 483 } 484 } 485 } 486 return (t); 487} 488 489/* 490 * Common inline functions 491 */ 492 493#include <dev/isp/isp_inline.h> 494#endif /* _ISP_FREEBSD_H */
| 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice immediately at the beginning of the file, without modification, 13 * this list of conditions, and the following disclaimer. 14 * 2. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29#ifndef _ISP_FREEBSD_H 30#define _ISP_FREEBSD_H 31 32#define ISP_PLATFORM_VERSION_MAJOR 5 33#define ISP_PLATFORM_VERSION_MINOR 9 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/endian.h> 38#include <sys/kernel.h> 39#include <sys/queue.h> 40#include <sys/lock.h> 41#include <sys/malloc.h> 42#include <sys/mutex.h> 43#include <sys/condvar.h> 44#include <sys/proc.h> 45#include <sys/bus.h> 46 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#ifdef PAE 65#define ISP_DAC_SUPPORTED 1 66#endif 67 68/* 69 * Efficiency- get rid of SBus code && tests unless we need them. 70 */ 71#ifdef __sparc64__ 72#define ISP_SBUS_SUPPORTED 1 73#else 74#define ISP_SBUS_SUPPORTED 0 75#endif 76 77#define HANDLE_LOOPSTATE_IN_OUTER_LAYERS 1 78/* #define ISP_SMPLOCK 1 */ 79 80#ifdef ISP_SMPLOCK 81#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 82#else 83#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY 84#endif 85 86typedef void ispfwfunc(int, int, int, u_int16_t **); 87 88#ifdef ISP_TARGET_MODE 89#define ISP_TARGET_FUNCTIONS 1 90#define ATPDPSIZE 256 91typedef struct { 92 u_int32_t orig_datalen; 93 u_int32_t bytes_xfered; 94 u_int32_t last_xframt; 95 u_int32_t tag : 16, 96 lun : 13, /* not enough */ 97 state : 3; 98} atio_private_data_t; 99#define ATPD_STATE_FREE 0 100#define ATPD_STATE_ATIO 1 101#define ATPD_STATE_CAM 2 102#define ATPD_STATE_CTIO 3 103#define ATPD_STATE_LAST_CTIO 4 104#define ATPD_STATE_PDON 5 105 106typedef struct tstate { 107 struct tstate *next; 108 struct cam_path *owner; 109 struct ccb_hdr_slist atios; 110 struct ccb_hdr_slist inots; 111 lun_id_t lun; 112 int bus; 113 u_int32_t hold; 114 int atio_count; 115 int inot_count; 116} tstate_t; 117 118#define LUN_HASH_SIZE 32 119#define LUN_HASH_FUNC(isp, port, lun) \ 120 ((IS_DUALBUS(isp)) ? \ 121 (((lun) & ((LUN_HASH_SIZE >> 1) - 1)) << (port)) : \ 122 ((lun) & (LUN_HASH_SIZE - 1))) 123#endif 124 125struct isposinfo { 126 struct ispsoftc * next; 127 u_int64_t default_port_wwn; 128 u_int64_t default_node_wwn; 129 u_int32_t default_id; 130 device_t dev; 131 struct cam_sim *sim; 132 struct cam_path *path; 133 struct cam_sim *sim2; 134 struct cam_path *path2; 135 struct intr_config_hook ehook; 136 u_int8_t : 1, 137 fcbsy : 1, 138 ktmature : 1, 139 mboxwaiting : 1, 140 intsok : 1, 141 simqfrozen : 3; 142 struct mtx lock; 143 struct cv kthread_cv; 144 struct proc *kproc; 145 bus_dma_tag_t cdmat; 146 bus_dmamap_t cdmap; 147#define isp_cdmat isp_osinfo.cdmat 148#define isp_cdmap isp_osinfo.cdmap 149#ifdef ISP_TARGET_MODE 150#define TM_WILDCARD_ENABLED 0x02 151#define TM_TMODE_ENABLED 0x01 152 u_int8_t tmflags[2]; /* two busses */ 153#define NLEACT 4 154 union ccb * leact[NLEACT]; 155 tstate_t tsdflt[2]; /* two busses */ 156 tstate_t *lun_hash[LUN_HASH_SIZE]; 157 atio_private_data_t atpdp[ATPDPSIZE]; 158#endif 159}; 160 161#define isp_lock isp_osinfo.lock 162 163/* 164 * Locking macros... 165 */ 166 167#ifdef ISP_SMPLOCK 168#define ISP_LOCK(x) mtx_lock(&(x)->isp_lock) 169#define ISP_UNLOCK(x) mtx_unlock(&(x)->isp_lock) 170#define ISPLOCK_2_CAMLOCK(isp) \ 171 mtx_unlock(&(isp)->isp_lock); mtx_lock(&Giant) 172#define CAMLOCK_2_ISPLOCK(isp) \ 173 mtx_unlock(&Giant); mtx_lock(&(isp)->isp_lock) 174#else 175#define ISP_LOCK(x) do { } while (0) 176#define ISP_UNLOCK(x) do { } while (0) 177#define ISPLOCK_2_CAMLOCK(isp) do { } while (0) 178#define CAMLOCK_2_ISPLOCK(isp) do { } while (0) 179#endif 180 181/* 182 * Required Macros/Defines 183 */ 184 185#define INLINE __inline 186 187#define ISP2100_SCRLEN 0x800 188 189#define MEMZERO bzero 190#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt)) 191#define SNPRINTF snprintf 192#define USEC_DELAY DELAY 193#define USEC_SLEEP(isp, x) \ 194 if (isp->isp_osinfo.intsok) \ 195 ISP_UNLOCK(isp); \ 196 DELAY(x); \ 197 if (isp->isp_osinfo.intsok) \ 198 ISP_LOCK(isp) 199 200#define NANOTIME_T struct timespec 201#define GET_NANOTIME nanotime 202#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec) 203#define NANOTIME_SUB nanotime_sub 204 205#define MAXISPREQUEST(isp) ((IS_FC(isp) || IS_ULTRA2(isp))? 1024 : 256) 206 207#define MEMORYBARRIER(isp, type, offset, size) \ 208switch (type) { \ 209case SYNC_SFORDEV: \ 210case SYNC_REQUEST: \ 211 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \ 212 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); \ 213 break; \ 214case SYNC_SFORCPU: \ 215case SYNC_RESULT: \ 216 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \ 217 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); \ 218 break; \ 219default: \ 220 break; \ 221} 222 223#define MBOX_ACQUIRE(isp) 224#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 225#define MBOX_NOTIFY_COMPLETE(isp) \ 226 if (isp->isp_osinfo.mboxwaiting) { \ 227 isp->isp_osinfo.mboxwaiting = 0; \ 228 wakeup(&isp->isp_mbxworkp); \ 229 } \ 230 isp->isp_mboxbsy = 0 231#define MBOX_RELEASE(isp) 232 233#define FC_SCRATCH_ACQUIRE(isp) \ 234 if (isp->isp_osinfo.fcbsy) { \ 235 isp_prt(isp, ISP_LOGWARN, \ 236 "FC scratch area busy (line %d)!", __LINE__); \ 237 } else \ 238 isp->isp_osinfo.fcbsy = 1 239#define FC_SCRATCH_RELEASE(isp) isp->isp_osinfo.fcbsy = 0 240 241#ifndef SCSI_GOOD 242#define SCSI_GOOD SCSI_STATUS_OK 243#endif 244#ifndef SCSI_CHECK 245#define SCSI_CHECK SCSI_STATUS_CHECK_COND 246#endif 247#ifndef SCSI_BUSY 248#define SCSI_BUSY SCSI_STATUS_BUSY 249#endif 250#ifndef SCSI_QFULL 251#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL 252#endif 253 254#define XS_T struct ccb_scsiio 255#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1) 256#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)) 257#define XS_TGT(ccb) (ccb)->ccb_h.target_id 258#define XS_LUN(ccb) (ccb)->ccb_h.target_lun 259 260#define XS_CDBP(ccb) \ 261 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \ 262 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes) 263 264#define XS_CDBLEN(ccb) (ccb)->cdb_len 265#define XS_XFRLEN(ccb) (ccb)->dxfer_len 266#define XS_TIME(ccb) (ccb)->ccb_h.timeout 267#define XS_RESID(ccb) (ccb)->resid 268#define XS_STSP(ccb) (&(ccb)->scsi_status) 269#define XS_SNSP(ccb) (&(ccb)->sense_data) 270 271#define XS_SNSLEN(ccb) \ 272 imin((sizeof((ccb)->sense_data)), ccb->sense_len) 273 274#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf) 275#define XS_TAG_P(ccb) \ 276 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \ 277 (ccb)->tag_action != CAM_TAG_ACTION_NONE) 278 279#define XS_TAG_TYPE(ccb) \ 280 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \ 281 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG)) 282 283 284#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \ 285 (ccb)->ccb_h.status |= v, \ 286 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET 287 288# define HBA_NOERROR CAM_REQ_INPROG 289# define HBA_BOTCH CAM_UNREC_HBA_ERROR 290# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT 291# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT 292# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR 293# define HBA_BUSRESET CAM_SCSI_BUS_RESET 294# define HBA_ABORTED CAM_REQ_ABORTED 295# define HBA_DATAOVR CAM_DATA_RUN_ERR 296# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL 297 298 299#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK) 300 301#define XS_NOERR(ccb) \ 302 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \ 303 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) 304 305#define XS_INITERR(ccb) \ 306 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0 307 308#define XS_SAVE_SENSE(xs, sp) \ 309 (xs)->ccb_h.status |= CAM_AUTOSNS_VALID, \ 310 bcopy(sp->req_sense_data, &(xs)->sense_data, \ 311 imin(XS_SNSLEN(xs), sp->req_sense_len)) 312 313#define XS_SET_STATE_STAT(a, b, c) 314 315#define DEFAULT_IID(x) (isp)->isp_osinfo.default_id 316#define DEFAULT_LOOPID(x) (isp)->isp_osinfo.default_id 317#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_node_wwn 318#define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.default_port_wwn 319#define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn 320#define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn 321 322#if BYTE_ORDER == BIG_ENDIAN 323#ifdef ISP_SBUS_SUPPORTED 324#define ISP_IOXPUT_8(isp, s, d) *(d) = s 325#define ISP_IOXPUT_16(isp, s, d) \ 326 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s) 327#define ISP_IOXPUT_32(isp, s, d) \ 328 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s) 329#define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s)) 330#define ISP_IOXGET_16(isp, s, d) \ 331 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 332 *((u_int16_t *)s) : bswap16(*((u_int16_t *)s)) 333#define ISP_IOXGET_32(isp, s, d) \ 334 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 335 *((u_int32_t *)s) : bswap32(*((u_int32_t *)s)) 336#else 337#define ISP_IOXPUT_8(isp, s, d) *(d) = s 338#define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s) 339#define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s) 340#define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s)) 341#define ISP_IOXGET_16(isp, s, d) d = bswap16(*((u_int16_t *)s)) 342#define ISP_IOXGET_32(isp, s, d) d = bswap32(*((u_int32_t *)s)) 343#endif 344#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp) 345#else 346#define ISP_IOXPUT_8(isp, s, d) *(d) = s 347#define ISP_IOXPUT_16(isp, s, d) *(d) = s 348#define ISP_IOXPUT_32(isp, s, d) *(d) = s 349#define ISP_IOXGET_8(isp, s, d) d = *(s) 350#define ISP_IOXGET_16(isp, s, d) d = *(s) 351#define ISP_IOXGET_32(isp, s, d) d = *(s) 352#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) 353#endif 354 355/* 356 * Includes of common header files 357 */ 358 359#include <dev/isp/ispreg.h> 360#include <dev/isp/ispvar.h> 361#include <dev/isp/ispmbox.h> 362 363void isp_prt(struct ispsoftc *, int level, const char *, ...) 364 __printflike(3, 4); 365/* 366 * isp_osinfo definiitions && shorthand 367 */ 368#define SIMQFRZ_RESOURCE 0x1 369#define SIMQFRZ_LOOPDOWN 0x2 370#define SIMQFRZ_TIMED 0x4 371 372#define isp_sim isp_osinfo.sim 373#define isp_path isp_osinfo.path 374#define isp_sim2 isp_osinfo.sim2 375#define isp_path2 isp_osinfo.path2 376#define isp_dev isp_osinfo.dev 377 378/* 379 * prototypes for isp_pci && isp_freebsd to share 380 */ 381extern void isp_attach(struct ispsoftc *); 382extern void isp_uninit(struct ispsoftc *); 383 384/* 385 * driver global data 386 */ 387extern int isp_announced; 388 389/* 390 * Platform private flags 391 */ 392#define ISP_SPRIV_ERRSET 0x1 393#define ISP_SPRIV_INWDOG 0x2 394#define ISP_SPRIV_GRACE 0x4 395#define ISP_SPRIV_DONE 0x8 396 397#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG 398#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG 399#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG) 400 401#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE 402#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE 403#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE) 404 405#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE 406#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE 407#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE) 408 409#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0 410/* 411 * Platform specific inline functions 412 */ 413 414static INLINE void isp_mbox_wait_complete(struct ispsoftc *); 415static INLINE void 416isp_mbox_wait_complete(struct ispsoftc *isp) 417{ 418 if (isp->isp_osinfo.intsok) { 419 int lim = ((isp->isp_mbxwrk0)? 120 : 20) * hz; 420 isp->isp_osinfo.mboxwaiting = 1; 421#ifdef ISP_SMPLOCK 422 (void) msleep(&isp->isp_mbxworkp, 423 &isp->isp_lock, PRIBIO, "isp_mboxwaiting", lim); 424#else 425 (void) tsleep(&isp->isp_mbxworkp, 426 PRIBIO, "isp_mboxwaiting", lim); 427#endif 428 if (isp->isp_mboxbsy != 0) { 429 isp_prt(isp, ISP_LOGWARN, 430 "Interrupting Mailbox Command (0x%x) Timeout", 431 isp->isp_lastmbxcmd); 432 isp->isp_mboxbsy = 0; 433 } 434 isp->isp_osinfo.mboxwaiting = 0; 435 } else { 436 int lim = ((isp->isp_mbxwrk0)? 240 : 60) * 10000; 437 int j; 438 for (j = 0; j < lim; j++) { 439 u_int16_t isr, sema, mbox; 440 if (isp->isp_mboxbsy == 0) { 441 break; 442 } 443 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) { 444 isp_intr(isp, isr, sema, mbox); 445 if (isp->isp_mboxbsy == 0) { 446 break; 447 } 448 } 449 USEC_DELAY(500); 450 } 451 if (isp->isp_mboxbsy != 0) { 452 isp_prt(isp, ISP_LOGWARN, 453 "Polled Mailbox Command (0x%x) Timeout", 454 isp->isp_lastmbxcmd); 455 } 456 } 457} 458 459static INLINE u_int64_t nanotime_sub(struct timespec *, struct timespec *); 460static INLINE u_int64_t 461nanotime_sub(struct timespec *b, struct timespec *a) 462{ 463 u_int64_t elapsed; 464 struct timespec x = *b; 465 timespecsub(&x, a); 466 elapsed = GET_NANOSEC(&x); 467 if (elapsed == 0) 468 elapsed++; 469 return (elapsed); 470} 471 472static INLINE char *strncat(char *, const char *, size_t); 473static INLINE char * 474strncat(char *d, const char *s, size_t c) 475{ 476 char *t = d; 477 478 if (c) { 479 while (*d) 480 d++; 481 while ((*d++ = *s++)) { 482 if (--c == 0) { 483 *d = '\0'; 484 break; 485 } 486 } 487 } 488 return (t); 489} 490 491/* 492 * Common inline functions 493 */ 494 495#include <dev/isp/isp_inline.h> 496#endif /* _ISP_FREEBSD_H */
|