1 /* $FreeBSD$ */ 2 /*- 3 * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions 4 * 5 * Copyright (c) 1997-2008 by Matthew Jacob 6 * All rights reserved. 7 * 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 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/endian.h> 35 #include <sys/lock.h> 36 #include <sys/kernel.h> 37 #include <sys/queue.h> 38 #include <sys/malloc.h> 39 #include <sys/mutex.h> 40 #include <sys/condvar.h> 41 #include <sys/sysctl.h> 42 43 #include <sys/proc.h> 44 #include <sys/bus.h> 45 #include <sys/taskqueue.h> 46 47 #include <machine/bus.h> 48 #include <machine/cpu.h> 49 #include <machine/stdarg.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 ISP_PLATFORM_VERSION_MAJOR 7 65 #define ISP_PLATFORM_VERSION_MINOR 10 66 67 /* 68 * Efficiency- get rid of SBus code && tests unless we need them. 69 */ 70 #ifdef __sparc64__ 71 #define ISP_SBUS_SUPPORTED 1 72 #else 73 #define ISP_SBUS_SUPPORTED 0 74 #endif 75 76 #define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE 77 78 #ifdef ISP_TARGET_MODE 79 /* Not quite right, but there was no bump for this change */ 80 #if __FreeBSD_version < 225469 81 #define SDFIXED(x) (&x) 82 #else 83 #define SDFIXED(x) ((struct scsi_sense_data_fixed *)(&x)) 84 #endif 85 86 #define ISP_TARGET_FUNCTIONS 1 87 #define ATPDPSIZE 4096 88 89 #include <dev/isp/isp_target.h> 90 91 typedef struct { 92 void * next; 93 uint32_t orig_datalen; 94 uint32_t bytes_xfered; 95 uint32_t last_xframt; 96 uint32_t tag; /* typically f/w RX_ID */ 97 uint32_t lun; 98 uint32_t nphdl; 99 uint32_t sid; 100 uint32_t portid; 101 uint16_t rxid; /* wire rxid */ 102 uint16_t oxid; /* wire oxid */ 103 uint32_t 104 cdb0 : 8, 105 : 1, 106 dead : 1, 107 tattr : 3, 108 state : 3; 109 } atio_private_data_t; 110 #define ATPD_STATE_FREE 0 111 #define ATPD_STATE_ATIO 1 112 #define ATPD_STATE_CAM 2 113 #define ATPD_STATE_CTIO 3 114 #define ATPD_STATE_LAST_CTIO 4 115 #define ATPD_STATE_PDON 5 116 117 typedef union inot_private_data inot_private_data_t; 118 union inot_private_data { 119 inot_private_data_t *next; 120 struct { 121 isp_notify_t nt; /* must be first! */ 122 uint8_t data[64]; /* sb QENTRY_LEN, but order of definitions is wrong */ 123 uint32_t tag_id, seq_id; 124 } rd; 125 }; 126 127 typedef struct tstate { 128 SLIST_ENTRY(tstate) next; 129 struct cam_path *owner; 130 struct ccb_hdr_slist atios; 131 struct ccb_hdr_slist inots; 132 uint32_t hold; 133 uint32_t 134 enabled : 1, 135 atio_count : 15, 136 inot_count : 15; 137 inot_private_data_t * restart_queue; 138 inot_private_data_t * ntfree; 139 inot_private_data_t ntpool[ATPDPSIZE]; 140 atio_private_data_t * atfree; 141 atio_private_data_t atpool[ATPDPSIZE]; 142 } tstate_t; 143 144 #define LUN_HASH_SIZE 32 145 #define LUN_HASH_FUNC(lun) ((lun) & (LUN_HASH_SIZE - 1)) 146 147 #endif 148 149 /* 150 * Per command info. 151 */ 152 struct isp_pcmd { 153 struct isp_pcmd * next; 154 bus_dmamap_t dmap; /* dma map for this command */ 155 struct ispsoftc * isp; /* containing isp */ 156 struct callout wdog; /* watchdog timer */ 157 uint8_t crn; /* command reference number */ 158 }; 159 #define ISP_PCMD(ccb) (ccb)->ccb_h.spriv_ptr1 160 #define PISP_PCMD(ccb) ((struct isp_pcmd *)ISP_PCMD(ccb)) 161 162 /* 163 * Per channel information 164 */ 165 SLIST_HEAD(tslist, tstate); 166 167 struct isp_fc { 168 struct cam_sim *sim; 169 struct cam_path *path; 170 struct ispsoftc *isp; 171 struct proc *kproc; 172 bus_dma_tag_t tdmat; 173 bus_dmamap_t tdmap; 174 uint64_t def_wwpn; 175 uint64_t def_wwnn; 176 uint32_t loop_down_time; 177 uint32_t loop_down_limit; 178 uint32_t gone_device_time; 179 uint32_t 180 #ifdef ISP_TARGET_MODE 181 #ifdef ISP_INTERNAL_TARGET 182 proc_active : 1, 183 #endif 184 tm_luns_enabled : 1, 185 tm_enable_defer : 1, 186 tm_enabled : 1, 187 #endif 188 simqfrozen : 3, 189 default_id : 8, 190 hysteresis : 8, 191 def_role : 2, /* default role */ 192 gdt_running : 1, 193 loop_dead : 1, 194 fcbsy : 1, 195 ready : 1; 196 struct callout ldt; /* loop down timer */ 197 struct callout gdt; /* gone device timer */ 198 struct task ltask; 199 struct task gtask; 200 #ifdef ISP_TARGET_MODE 201 struct tslist lun_hash[LUN_HASH_SIZE]; 202 #ifdef ISP_INTERNAL_TARGET 203 struct proc * target_proc; 204 #endif 205 #endif 206 uint8_t crnseed; /* next command reference number */ 207 }; 208 209 struct isp_spi { 210 struct cam_sim *sim; 211 struct cam_path *path; 212 uint32_t 213 #ifdef ISP_TARGET_MODE 214 #ifdef ISP_INTERNAL_TARGET 215 proc_active : 1, 216 #endif 217 tm_luns_enabled : 1, 218 tm_enable_defer : 1, 219 tm_enabled : 1, 220 #endif 221 simqfrozen : 3, 222 def_role : 2, 223 iid : 4; 224 #ifdef ISP_TARGET_MODE 225 struct tslist lun_hash[LUN_HASH_SIZE]; 226 #ifdef ISP_INTERNAL_TARGET 227 struct proc * target_proc; 228 #endif 229 #endif 230 }; 231 232 struct isposinfo { 233 /* 234 * Linkage, locking, and identity 235 */ 236 struct mtx lock; 237 device_t dev; 238 struct cdev * cdev; 239 struct intr_config_hook ehook; 240 struct cam_devq * devq; 241 242 /* 243 * Firmware pointer 244 */ 245 const struct firmware * fw; 246 247 /* 248 * DMA related sdtuff 249 */ 250 bus_space_tag_t bus_tag; 251 bus_dma_tag_t dmat; 252 bus_space_handle_t bus_handle; 253 bus_dma_tag_t cdmat; 254 bus_dmamap_t cdmap; 255 256 /* 257 * Command and transaction related related stuff 258 */ 259 struct isp_pcmd * pcmd_pool; 260 struct isp_pcmd * pcmd_free; 261 262 uint32_t 263 #ifdef ISP_TARGET_MODE 264 tmwanted : 1, 265 tmbusy : 1, 266 #else 267 : 2, 268 #endif 269 timer_active : 1, 270 autoconf : 1, 271 ehook_active : 1, 272 disabled : 1, 273 mbox_sleeping : 1, 274 mbox_sleep_ok : 1, 275 mboxcmd_done : 1, 276 mboxbsy : 1; 277 278 struct callout tmo; /* general timer */ 279 280 /* 281 * misc- needs to be sorted better XXXXXX 282 */ 283 int framesize; 284 int exec_throttle; 285 int cont_max; 286 287 #ifdef ISP_TARGET_MODE 288 cam_status * rptr; 289 #endif 290 291 /* 292 * Per-type private storage... 293 */ 294 union { 295 struct isp_fc *fc; 296 struct isp_spi *spi; 297 void *ptr; 298 } pc; 299 }; 300 #define ISP_FC_PC(isp, chan) (&(isp)->isp_osinfo.pc.fc[(chan)]) 301 #define ISP_SPI_PC(isp, chan) (&(isp)->isp_osinfo.pc.spi[(chan)]) 302 #define ISP_GET_PC(isp, chan, tag, rslt) \ 303 if (IS_SCSI(isp)) { \ 304 rslt = ISP_SPI_PC(isp, chan)-> tag; \ 305 } else { \ 306 rslt = ISP_FC_PC(isp, chan)-> tag; \ 307 } 308 #define ISP_GET_PC_ADDR(isp, chan, tag, rp) \ 309 if (IS_SCSI(isp)) { \ 310 rp = &ISP_SPI_PC(isp, chan)-> tag; \ 311 } else { \ 312 rp = &ISP_FC_PC(isp, chan)-> tag; \ 313 } 314 #define ISP_SET_PC(isp, chan, tag, val) \ 315 if (IS_SCSI(isp)) { \ 316 ISP_SPI_PC(isp, chan)-> tag = val; \ 317 } else { \ 318 ISP_FC_PC(isp, chan)-> tag = val; \ 319 } 320 321 #define FCP_NEXT_CRN(isp, cmd, rslt, chan, tgt, lun) \ 322 if ((isp)->isp_osinfo.pc.fc[(chan)].crnseed == 0) { \ 323 (isp)->isp_osinfo.pc.fc[(chan)].crnseed = 1; \ 324 } \ 325 if (cmd) { \ 326 PISP_PCMD(cmd)->crn = (isp)->isp_osinfo.pc.fc[(chan)].crnseed; \ 327 } \ 328 (rslt) = (isp)->isp_osinfo.pc.fc[(chan)].crnseed++ 329 330 331 #define isp_lock isp_osinfo.lock 332 #define isp_bus_tag isp_osinfo.bus_tag 333 #define isp_bus_handle isp_osinfo.bus_handle 334 335 /* 336 * Locking macros... 337 */ 338 #define ISP_LOCK(isp) mtx_lock(&isp->isp_osinfo.lock) 339 #define ISP_UNLOCK(isp) mtx_unlock(&isp->isp_osinfo.lock) 340 341 /* 342 * Required Macros/Defines 343 */ 344 345 #define ISP_FC_SCRLEN 0x1000 346 347 #define ISP_MEMZERO(a, b) memset(a, 0, b) 348 #define ISP_MEMCPY memcpy 349 #define ISP_SNPRINTF snprintf 350 #define ISP_DELAY DELAY 351 #define ISP_SLEEP(isp, x) DELAY(x) 352 353 #define ISP_MIN imin 354 355 #ifndef DIAGNOSTIC 356 #define ISP_INLINE __inline 357 #else 358 #define ISP_INLINE 359 #endif 360 361 #define NANOTIME_T struct timespec 362 #define GET_NANOTIME nanotime 363 #define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec) 364 #define NANOTIME_SUB isp_nanotime_sub 365 366 #define MAXISPREQUEST(isp) ((IS_FC(isp) || IS_ULTRA2(isp))? 1024 : 256) 367 368 #define MEMORYBARRIER(isp, type, offset, size, chan) \ 369 switch (type) { \ 370 case SYNC_SFORDEV: \ 371 { \ 372 struct isp_fc *fc = ISP_FC_PC(isp, chan); \ 373 bus_dmamap_sync(fc->tdmat, fc->tdmap, \ 374 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); \ 375 break; \ 376 } \ 377 case SYNC_REQUEST: \ 378 bus_dmamap_sync(isp->isp_osinfo.cdmat, \ 379 isp->isp_osinfo.cdmap, \ 380 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); \ 381 break; \ 382 case SYNC_SFORCPU: \ 383 { \ 384 struct isp_fc *fc = ISP_FC_PC(isp, chan); \ 385 bus_dmamap_sync(fc->tdmat, fc->tdmap, \ 386 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); \ 387 break; \ 388 } \ 389 case SYNC_RESULT: \ 390 bus_dmamap_sync(isp->isp_osinfo.cdmat, \ 391 isp->isp_osinfo.cdmap, \ 392 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); \ 393 break; \ 394 case SYNC_REG: \ 395 bus_space_barrier(isp->isp_osinfo.bus_tag, \ 396 isp->isp_osinfo.bus_handle, offset, size, \ 397 BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); \ 398 break; \ 399 default: \ 400 break; \ 401 } 402 403 #define MBOX_ACQUIRE isp_mbox_acquire 404 #define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 405 #define MBOX_NOTIFY_COMPLETE isp_mbox_notify_done 406 #define MBOX_RELEASE isp_mbox_release 407 408 #define FC_SCRATCH_ACQUIRE isp_fc_scratch_acquire 409 #define FC_SCRATCH_RELEASE(isp, chan) isp->isp_osinfo.pc.fc[chan].fcbsy = 0 410 411 #ifndef SCSI_GOOD 412 #define SCSI_GOOD SCSI_STATUS_OK 413 #endif 414 #ifndef SCSI_CHECK 415 #define SCSI_CHECK SCSI_STATUS_CHECK_COND 416 #endif 417 #ifndef SCSI_BUSY 418 #define SCSI_BUSY SCSI_STATUS_BUSY 419 #endif 420 #ifndef SCSI_QFULL 421 #define SCSI_QFULL SCSI_STATUS_QUEUE_FULL 422 #endif 423 424 #define XS_T struct ccb_scsiio 425 #define XS_DMA_ADDR_T bus_addr_t 426 #define XS_GET_DMA64_SEG(a, b, c) \ 427 { \ 428 ispds64_t *d = a; \ 429 bus_dma_segment_t *e = b; \ 430 uint32_t f = c; \ 431 e += f; \ 432 d->ds_base = DMA_LO32(e->ds_addr); \ 433 d->ds_basehi = DMA_HI32(e->ds_addr); \ 434 d->ds_count = e->ds_len; \ 435 } 436 #define XS_GET_DMA_SEG(a, b, c) \ 437 { \ 438 ispds_t *d = a; \ 439 bus_dma_segment_t *e = b; \ 440 uint32_t f = c; \ 441 e += f; \ 442 d->ds_base = DMA_LO32(e->ds_addr); \ 443 d->ds_count = e->ds_len; \ 444 } 445 #define XS_ISP(ccb) cam_sim_softc(xpt_path_sim((ccb)->ccb_h.path)) 446 #define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)) 447 #define XS_TGT(ccb) (ccb)->ccb_h.target_id 448 #define XS_LUN(ccb) (ccb)->ccb_h.target_lun 449 450 #define XS_CDBP(ccb) \ 451 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \ 452 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes) 453 454 #define XS_CDBLEN(ccb) (ccb)->cdb_len 455 #define XS_XFRLEN(ccb) (ccb)->dxfer_len 456 #define XS_TIME(ccb) (ccb)->ccb_h.timeout 457 #define XS_GET_RESID(ccb) (ccb)->resid 458 #define XS_SET_RESID(ccb, r) (ccb)->resid = r 459 #define XS_STSP(ccb) (&(ccb)->scsi_status) 460 #define XS_SNSP(ccb) (&(ccb)->sense_data) 461 462 #define XS_SNSLEN(ccb) \ 463 imin((sizeof((ccb)->sense_data)), ccb->sense_len - ccb->sense_resid) 464 465 #define XS_SNSKEY(ccb) (scsi_get_sense_key(&(ccb)->sense_data, \ 466 ccb->sense_len - ccb->sense_resid, \ 467 /*show_errors*/ 1)) 468 469 #define XS_SNSASC(ccb) (scsi_get_asc(&(ccb)->sense_data, \ 470 ccb->sense_len - ccb->sense_resid, \ 471 /*show_errors*/ 1)) 472 473 #define XS_SNSASCQ(ccb) (scsi_get_ascq(&(ccb)->sense_data, \ 474 ccb->sense_len - ccb->sense_resid, \ 475 /*show_errors*/ 1)) 476 #define XS_TAG_P(ccb) \ 477 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \ 478 (ccb)->tag_action != CAM_TAG_ACTION_NONE) 479 480 #define XS_TAG_TYPE(ccb) \ 481 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \ 482 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG)) 483 484 485 #define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \ 486 (ccb)->ccb_h.status |= v, \ 487 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET 488 489 # define HBA_NOERROR CAM_REQ_INPROG 490 # define HBA_BOTCH CAM_UNREC_HBA_ERROR 491 # define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT 492 # define HBA_SELTIMEOUT CAM_SEL_TIMEOUT 493 # define HBA_TGTBSY CAM_SCSI_STATUS_ERROR 494 # define HBA_BUSRESET CAM_SCSI_BUS_RESET 495 # define HBA_ABORTED CAM_REQ_ABORTED 496 # define HBA_DATAOVR CAM_DATA_RUN_ERR 497 # define HBA_ARQFAIL CAM_AUTOSENSE_FAIL 498 499 500 #define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK) 501 502 #define XS_NOERR(ccb) \ 503 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \ 504 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) 505 506 #define XS_INITERR(ccb) \ 507 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0 508 509 #define XS_SAVE_SENSE(xs, sense_ptr, slen) do { \ 510 (xs)->ccb_h.status |= CAM_AUTOSNS_VALID; \ 511 memset(&(xs)->sense_data, 0, sizeof((xs)->sense_data)); \ 512 memcpy(&(xs)->sense_data, sense_ptr, imin(XS_SNSLEN(xs),\ 513 slen)); \ 514 if (slen < (xs)->sense_len) \ 515 (xs)->sense_resid = (xs)->sense_len - slen; \ 516 } while (0); 517 518 #define XS_SENSE_VALID(xs) (((xs)->ccb_h.status & CAM_AUTOSNS_VALID) != 0) 519 520 #define DEFAULT_FRAMESIZE(isp) isp->isp_osinfo.framesize 521 #define DEFAULT_EXEC_THROTTLE(isp) isp->isp_osinfo.exec_throttle 522 523 #define GET_DEFAULT_ROLE(isp, chan) \ 524 (IS_FC(isp)? ISP_FC_PC(isp, chan)->def_role : ISP_SPI_PC(isp, chan)->def_role) 525 #define SET_DEFAULT_ROLE(isp, chan, val) \ 526 if (IS_FC(isp)) { \ 527 ISP_FC_PC(isp, chan)->def_role = val; \ 528 } else { \ 529 ISP_SPI_PC(isp, chan)->def_role = val; \ 530 } 531 532 #define DEFAULT_IID(isp, chan) isp->isp_osinfo.pc.spi[chan].iid 533 534 #define DEFAULT_LOOPID(x, chan) isp->isp_osinfo.pc.fc[chan].default_id 535 536 #define DEFAULT_NODEWWN(isp, chan) isp_default_wwn(isp, chan, 0, 1) 537 #define DEFAULT_PORTWWN(isp, chan) isp_default_wwn(isp, chan, 0, 0) 538 #define ACTIVE_NODEWWN(isp, chan) isp_default_wwn(isp, chan, 1, 1) 539 #define ACTIVE_PORTWWN(isp, chan) isp_default_wwn(isp, chan, 1, 0) 540 541 542 #if BYTE_ORDER == BIG_ENDIAN 543 #ifdef ISP_SBUS_SUPPORTED 544 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 545 #define ISP_IOXPUT_16(isp, s, d) \ 546 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s) 547 #define ISP_IOXPUT_32(isp, s, d) \ 548 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s) 549 #define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 550 #define ISP_IOXGET_16(isp, s, d) \ 551 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 552 *((uint16_t *)s) : bswap16(*((uint16_t *)s)) 553 #define ISP_IOXGET_32(isp, s, d) \ 554 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 555 *((uint32_t *)s) : bswap32(*((uint32_t *)s)) 556 557 #else /* ISP_SBUS_SUPPORTED */ 558 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 559 #define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s) 560 #define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s) 561 #define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 562 #define ISP_IOXGET_16(isp, s, d) d = bswap16(*((uint16_t *)s)) 563 #define ISP_IOXGET_32(isp, s, d) d = bswap32(*((uint32_t *)s)) 564 #endif 565 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp) 566 #define ISP_SWIZZLE_NVRAM_LONG(isp, rp) *rp = bswap32(*rp) 567 568 #define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)s)) 569 #define ISP_IOZGET_16(isp, s, d) d = (*((uint16_t *)s)) 570 #define ISP_IOZGET_32(isp, s, d) d = (*((uint32_t *)s)) 571 #define ISP_IOZPUT_8(isp, s, d) *(d) = s 572 #define ISP_IOZPUT_16(isp, s, d) *(d) = s 573 #define ISP_IOZPUT_32(isp, s, d) *(d) = s 574 575 576 #else 577 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 578 #define ISP_IOXPUT_16(isp, s, d) *(d) = s 579 #define ISP_IOXPUT_32(isp, s, d) *(d) = s 580 #define ISP_IOXGET_8(isp, s, d) d = *(s) 581 #define ISP_IOXGET_16(isp, s, d) d = *(s) 582 #define ISP_IOXGET_32(isp, s, d) d = *(s) 583 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) 584 #define ISP_SWIZZLE_NVRAM_LONG(isp, rp) 585 586 #define ISP_IOZPUT_8(isp, s, d) *(d) = s 587 #define ISP_IOZPUT_16(isp, s, d) *(d) = bswap16(s) 588 #define ISP_IOZPUT_32(isp, s, d) *(d) = bswap32(s) 589 590 #define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)(s))) 591 #define ISP_IOZGET_16(isp, s, d) d = bswap16(*((uint16_t *)(s))) 592 #define ISP_IOZGET_32(isp, s, d) d = bswap32(*((uint32_t *)(s))) 593 594 #endif 595 596 #define ISP_SWAP16(isp, s) bswap16(s) 597 #define ISP_SWAP32(isp, s) bswap32(s) 598 599 /* 600 * Includes of common header files 601 */ 602 603 #include <dev/isp/ispreg.h> 604 #include <dev/isp/ispvar.h> 605 #include <dev/isp/ispmbox.h> 606 607 /* 608 * isp_osinfo definiitions && shorthand 609 */ 610 #define SIMQFRZ_RESOURCE 0x1 611 #define SIMQFRZ_LOOPDOWN 0x2 612 #define SIMQFRZ_TIMED 0x4 613 614 #define isp_dev isp_osinfo.dev 615 616 /* 617 * prototypes for isp_pci && isp_freebsd to share 618 */ 619 extern int isp_attach(ispsoftc_t *); 620 extern int isp_detach(ispsoftc_t *); 621 extern void isp_uninit(ispsoftc_t *); 622 extern uint64_t isp_default_wwn(ispsoftc_t *, int, int, int); 623 624 /* 625 * driver global data 626 */ 627 extern int isp_announced; 628 extern int isp_fabric_hysteresis; 629 extern int isp_loop_down_limit; 630 extern int isp_gone_device_time; 631 extern int isp_quickboot_time; 632 extern int isp_autoconfig; 633 634 /* 635 * Platform private flags 636 */ 637 #define ISP_SPRIV_ERRSET 0x1 638 #define ISP_SPRIV_TACTIVE 0x2 639 #define ISP_SPRIV_DONE 0x8 640 #define ISP_SPRIV_WPEND 0x10 641 642 #define XS_S_TACTIVE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_TACTIVE 643 #define XS_C_TACTIVE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_TACTIVE 644 #define XS_TACTIVE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_TACTIVE) 645 646 #define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE 647 #define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE 648 #define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE) 649 650 #define XS_CMD_S_WPEND(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_WPEND 651 #define XS_CMD_C_WPEND(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_WPEND 652 #define XS_CMD_WPEND_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_WPEND) 653 654 #define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0 655 656 /* 657 * Platform Library Functions 658 */ 659 void isp_prt(ispsoftc_t *, int level, const char *, ...) __printflike(3, 4); 660 void isp_xs_prt(ispsoftc_t *, XS_T *, int level, const char *, ...) __printflike(4, 5); 661 uint64_t isp_nanotime_sub(struct timespec *, struct timespec *); 662 int isp_mbox_acquire(ispsoftc_t *); 663 void isp_mbox_wait_complete(ispsoftc_t *, mbreg_t *); 664 void isp_mbox_notify_done(ispsoftc_t *); 665 void isp_mbox_release(ispsoftc_t *); 666 int isp_fc_scratch_acquire(ispsoftc_t *, int); 667 int isp_mstohz(int); 668 void isp_platform_intr(void *); 669 void isp_common_dmateardown(ispsoftc_t *, struct ccb_scsiio *, uint32_t); 670 671 /* 672 * Platform Version specific defines 673 */ 674 #define BUS_DMA_ROOTARG(x) bus_get_dma_tag(x) 675 #define isp_dma_tag_create(a, b, c, d, e, f, g, h, i, j, k, z) \ 676 bus_dma_tag_create(a, b, c, d, e, f, g, h, i, j, k, \ 677 busdma_lock_mutex, &isp->isp_osinfo.lock, z) 678 679 #define isp_setup_intr bus_setup_intr 680 681 #define isp_sim_alloc(a, b, c, d, e, f, g, h) \ 682 cam_sim_alloc(a, b, c, d, e, &(d)->isp_osinfo.lock, f, g, h) 683 684 /* Should be BUS_SPACE_MAXSIZE, but MAXPHYS is larger than BUS_SPACE_MAXSIZE */ 685 #define ISP_NSEGS ((MAXPHYS / PAGE_SIZE) + 1) 686 687 #define ISP_PATH_PRT(i, l, p, ...) \ 688 if ((l) == ISP_LOGALL || ((l)& (i)->isp_dblev) != 0) { \ 689 xpt_print(p, __VA_ARGS__); \ 690 } 691 692 /* 693 * Platform specific inline functions 694 */ 695 696 /* 697 * ISP General Library functions 698 */ 699 700 #include <dev/isp/isp_library.h> 701 702 #endif /* _ISP_FREEBSD_H */ 703