1 /* $NetBSD: isp_netbsd.h,v 1.46 2001/09/01 07:12:24 mjacob Exp $ */ 2 /* 3 * This driver, which is contained in NetBSD in the files: 4 * 5 * sys/dev/ic/isp.c 6 * sys/dev/ic/isp_inline.h 7 * sys/dev/ic/isp_netbsd.c 8 * sys/dev/ic/isp_netbsd.h 9 * sys/dev/ic/isp_target.c 10 * sys/dev/ic/isp_target.h 11 * sys/dev/ic/isp_tpublic.h 12 * sys/dev/ic/ispmbox.h 13 * sys/dev/ic/ispreg.h 14 * sys/dev/ic/ispvar.h 15 * sys/microcode/isp/asm_sbus.h 16 * sys/microcode/isp/asm_1040.h 17 * sys/microcode/isp/asm_1080.h 18 * sys/microcode/isp/asm_12160.h 19 * sys/microcode/isp/asm_2100.h 20 * sys/microcode/isp/asm_2200.h 21 * sys/pci/isp_pci.c 22 * sys/sbus/isp_sbus.c 23 * 24 * Is being actively maintained by Matthew Jacob (mjacob@netbsd.org). 25 * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris, 26 * Linux versions. This tends to be an interesting maintenance problem. 27 * 28 * Please coordinate with Matthew Jacob on changes you wish to make here. 29 */ 30 /* 31 * NetBSD Specific definitions for the Qlogic ISP Host Adapter 32 * Matthew Jacob <mjacob@nas.nasa.gov> 33 */ 34 /* 35 * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration 36 * All rights reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. The name of the author may not be used to endorse or promote products 47 * derived from this software without specific prior written permission 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 51 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 52 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 53 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 58 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 */ 60 #ifndef _ISP_NETBSD_H 61 #define _ISP_NETBSD_H 62 63 #include <sys/types.h> 64 #include <sys/param.h> 65 #include <sys/systm.h> 66 #include <sys/kernel.h> 67 #include <sys/errno.h> 68 #include <sys/ioctl.h> 69 #include <sys/device.h> 70 #include <sys/malloc.h> 71 #include <sys/buf.h> 72 #include <sys/proc.h> 73 #include <sys/user.h> 74 #include <sys/kthread.h> 75 76 77 #include <dev/scsipi/scsi_all.h> 78 #include <dev/scsipi/scsipi_all.h> 79 #include <dev/scsipi/scsiconf.h> 80 81 #include <dev/scsipi/scsi_message.h> 82 #include <dev/scsipi/scsipi_debug.h> 83 84 #include "opt_isp.h" 85 86 87 #define ISP_PLATFORM_VERSION_MAJOR 2 88 #define ISP_PLATFORM_VERSION_MINOR 0 89 90 struct isposinfo { 91 struct device _dev; 92 struct scsipi_channel _chan; 93 struct scsipi_channel _chan_b; 94 struct scsipi_adapter _adapter; 95 int splsaved; 96 int mboxwaiting; 97 u_int32_t islocked; 98 u_int32_t onintstack; 99 unsigned int : 26, 100 loop_checked : 1, 101 mbox_wanted : 1, 102 mbox_locked : 1, 103 no_mbox_ints : 1, 104 paused : 1, 105 blocked : 1; 106 union { 107 u_int64_t _wwn; 108 u_int16_t _discovered[2]; 109 #define wwn_seed un._wwn 110 #define discovered un._discovered 111 } un; 112 u_int32_t threadwork; 113 struct proc *thread; 114 }; 115 #define ISP_MUSTPOLL(isp) \ 116 (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) 117 118 #define HANDLE_LOOPSTATE_IN_OUTER_LAYERS 1 119 120 /* 121 * Required Macros/Defines 122 */ 123 124 #define INLINE __inline 125 126 #define ISP2100_SCRLEN 0x400 127 128 #define MEMZERO(dst, amt) memset((dst), 0, (amt)) 129 #define MEMCPY(dst, src, amt) memcpy((dst), (src), (amt)) 130 #define SNPRINTF snprintf 131 #define STRNCAT strncat 132 #define USEC_DELAY DELAY 133 #define USEC_SLEEP(isp, x) \ 134 if (!ISP_MUSTPOLL(isp)) \ 135 ISP_UNLOCK(isp); \ 136 DELAY(x); \ 137 if (!ISP_MUSTPOLL(isp)) \ 138 ISP_LOCK(isp) 139 140 #define NANOTIME_T struct timeval 141 #define GET_NANOTIME microtime 142 #define GET_NANOSEC(x) (((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000) 143 #define NANOTIME_SUB isp_microtime_sub 144 145 #define MAXISPREQUEST(isp) 256 146 147 #ifdef __alpha__ 148 #define MEMORYBARRIER(isp, type, offset, size) alpha_mb() 149 #else 150 #define MEMORYBARRIER(isp, type, offset, size) 151 #endif 152 153 #define MBOX_ACQUIRE(isp) \ 154 if (isp->isp_osinfo.onintstack) { \ 155 if (isp->isp_osinfo.mbox_locked) { \ 156 mbp->param[0] = MBOX_HOST_INTERFACE_ERROR; \ 157 isp_prt(isp, ISP_LOGERR, "cannot acquire MBOX lock"); \ 158 return; \ 159 } \ 160 } else { \ 161 while (isp->isp_osinfo.mbox_locked) { \ 162 isp->isp_osinfo.mbox_wanted = 1; \ 163 (void) tsleep(&isp->isp_osinfo.mboxwaiting+1, \ 164 PRIBIO, "mbox_acquire", 0); \ 165 } \ 166 } \ 167 isp->isp_osinfo.mbox_locked = 1 168 169 #define MBOX_WAIT_COMPLETE isp_wait_complete 170 171 #define MBOX_NOTIFY_COMPLETE(isp) \ 172 if (isp->isp_osinfo.mboxwaiting) { \ 173 isp->isp_osinfo.mboxwaiting = 0; \ 174 wakeup(&isp->isp_osinfo.mboxwaiting); \ 175 } \ 176 isp->isp_mboxbsy = 0 177 178 #define MBOX_RELEASE(isp) \ 179 if (isp->isp_osinfo.mbox_wanted) { \ 180 isp->isp_osinfo.mbox_wanted = 0; \ 181 wakeup(&isp->isp_osinfo.mboxwaiting+1); \ 182 } \ 183 isp->isp_osinfo.mbox_locked = 0 184 185 #ifndef SCSI_GOOD 186 #define SCSI_GOOD 0x0 187 #endif 188 #ifndef SCSI_CHECK 189 #define SCSI_CHECK 0x2 190 #endif 191 #ifndef SCSI_BUSY 192 #define SCSI_BUSY 0x8 193 #endif 194 #ifndef SCSI_QFULL 195 #define SCSI_QFULL 0x28 196 #endif 197 198 #define XS_T struct scsipi_xfer 199 #define XS_CHANNEL(xs) ((int) (xs)->xs_periph->periph_channel->chan_channel) 200 #define XS_ISP(xs) \ 201 ((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev) 202 #define XS_LUN(xs) ((int) (xs)->xs_periph->periph_lun) 203 #define XS_TGT(xs) ((int) (xs)->xs_periph->periph_target) 204 #define XS_CDBP(xs) ((caddr_t) (xs)->cmd) 205 #define XS_CDBLEN(xs) (xs)->cmdlen 206 #define XS_XFRLEN(xs) (xs)->datalen 207 #define XS_TIME(xs) (xs)->timeout 208 #define XS_RESID(xs) (xs)->resid 209 #define XS_STSP(xs) (&(xs)->status) 210 #define XS_SNSP(xs) (&(xs)->sense.scsi_sense) 211 #define XS_SNSLEN(xs) (sizeof (xs)->sense) 212 #define XS_SNSKEY(xs) ((xs)->sense.scsi_sense.flags) 213 #define XS_TAG_P(ccb) (((xs)->xs_control & XS_CTL_POLL) != 0) 214 #define XS_TAG_TYPE(xs) \ 215 (((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \ 216 ((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG) 217 218 #define XS_SETERR(xs, v) (xs)->error = v 219 220 # define HBA_NOERROR XS_NOERROR 221 # define HBA_BOTCH XS_DRIVER_STUFFUP 222 # define HBA_CMDTIMEOUT XS_TIMEOUT 223 # define HBA_SELTIMEOUT XS_SELTIMEOUT 224 # define HBA_TGTBSY XS_BUSY 225 # define HBA_BUSRESET XS_RESET 226 # define HBA_ABORTED XS_DRIVER_STUFFUP 227 # define HBA_DATAOVR XS_DRIVER_STUFFUP 228 # define HBA_ARQFAIL XS_DRIVER_STUFFUP 229 230 #define XS_ERR(xs) (xs)->error 231 232 #define XS_NOERR(xs) (xs)->error == XS_NOERROR 233 234 #define XS_INITERR(xs) (xs)->error = 0, XS_CMD_S_CLEAR(xs) 235 236 #define XS_SAVE_SENSE(xs, sp) \ 237 if (xs->error == XS_NOERROR) { \ 238 xs->error = XS_SENSE; \ 239 } \ 240 memcpy(&(xs)->sense, sp->req_sense_data, \ 241 imin(XS_SNSLEN(xs), sp->req_sense_len)) 242 243 #define XS_SET_STATE_STAT(a, b, c) 244 245 #define DEFAULT_IID(x) 7 246 #define DEFAULT_LOOPID(x) 108 247 #define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.un._wwn 248 #define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.un._wwn 249 #define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn 250 #define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn 251 252 #if _BYTE_ORDER == _BIG_ENDIAN 253 #define ISP_SWIZZLE_REQUEST isp_swizzle_request 254 #define ISP_UNSWIZZLE_RESPONSE isp_unswizzle_response 255 #define ISP_SWIZZLE_ICB isp_swizzle_icb 256 #define ISP_UNSWIZZLE_AND_COPY_PDBP isp_unswizzle_and_copy_pdbp 257 #define ISP_SWIZZLE_SNS_REQ isp_swizzle_sns_req 258 #define ISP_UNSWIZZLE_SNS_RSP isp_unswizzle_sns_rsp 259 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp) 260 #else 261 #define ISP_SWIZZLE_REQUEST(a, b) 262 #define ISP_UNSWIZZLE_RESPONSE(a, b, c) 263 #define ISP_SWIZZLE_ICB(a, b) 264 #define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \ 265 if((void *)src != (void *)dest) memcpy(dest, src, sizeof (isp_pdb_t)) 266 #define ISP_SWIZZLE_SNS_REQ(a, b) 267 #define ISP_UNSWIZZLE_SNS_RSP(a, b, c) 268 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) 269 #endif 270 271 /* 272 * Includes of common header files 273 */ 274 275 #include <dev/ic/ispreg.h> 276 #include <dev/ic/ispvar.h> 277 #include <dev/ic/ispmbox.h> 278 #include <dev/ic/isp_ioctl.h> 279 280 /* 281 * isp_osinfo definitions, extensions and shorthand. 282 */ 283 #define isp_name isp_osinfo._dev.dv_xname 284 #define isp_unit isp_osinfo._dev.dv_unit 285 #define isp_chanA isp_osinfo._chan 286 #define isp_chanB isp_osinfo._chan_b 287 288 289 /* 290 * Driver prototypes.. 291 */ 292 void isp_attach(struct ispsoftc *); 293 void isp_uninit(struct ispsoftc *); 294 295 static INLINE void isp_lock(struct ispsoftc *); 296 static INLINE void isp_unlock(struct ispsoftc *); 297 static INLINE char *strncat(char *, const char *, size_t); 298 static INLINE u_int64_t 299 isp_microtime_sub(struct timeval *, struct timeval *); 300 static void isp_wait_complete(struct ispsoftc *); 301 #if _BYTE_ORDER == _BIG_ENDIAN 302 static INLINE void isp_swizzle_request(struct ispsoftc *, ispreq_t *); 303 static INLINE void isp_unswizzle_response(struct ispsoftc *, void *, u_int16_t); 304 static INLINE void isp_swizzle_icb(struct ispsoftc *, isp_icb_t *); 305 static INLINE void 306 isp_unswizzle_and_copy_pdbp(struct ispsoftc *, isp_pdb_t *, void *); 307 static INLINE void isp_swizzle_sns_req(struct ispsoftc *, sns_screq_t *); 308 static INLINE void isp_unswizzle_sns_rsp(struct ispsoftc *, sns_scrsp_t *, int); 309 #endif 310 311 /* 312 * Driver wide data... 313 */ 314 315 /* 316 * Locking macros... 317 */ 318 #define ISP_LOCK isp_lock 319 #define ISP_UNLOCK isp_unlock 320 #define ISP_ILOCK(x) isp_lock(x); isp->isp_osinfo.onintstack++ 321 #define ISP_IUNLOCK(x) isp->isp_osinfo.onintstack--; isp_unlock(x) 322 323 /* 324 * Platform private flags 325 */ 326 327 #define XS_PSTS_INWDOG 0x10000000 328 #define XS_PSTS_GRACE 0x20000000 329 #define XS_PSTS_ALL 0x30000000 330 331 #define XS_CMD_S_WDOG(xs) (xs)->xs_status |= XS_PSTS_INWDOG 332 #define XS_CMD_C_WDOG(xs) (xs)->xs_status &= ~XS_PSTS_INWDOG 333 #define XS_CMD_WDOG_P(xs) (((xs)->xs_status & XS_PSTS_INWDOG) != 0) 334 335 #define XS_CMD_S_GRACE(xs) (xs)->xs_status |= XS_PSTS_GRACE 336 #define XS_CMD_C_GRACE(xs) (xs)->xs_status &= ~XS_PSTS_GRACE 337 #define XS_CMD_GRACE_P(xs) (((xs)->xs_status & XS_PSTS_GRACE) != 0) 338 339 #define XS_CMD_S_DONE(xs) (xs)->xs_status |= XS_STS_DONE 340 #define XS_CMD_C_DONE(xs) (xs)->xs_status &= ~XS_STS_DONE 341 #define XS_CMD_DONE_P(xs) (((xs)->xs_status & XS_STS_DONE) != 0) 342 343 #define XS_CMD_S_CLEAR(xs) (xs)->xs_status &= ~XS_PSTS_ALL 344 345 /* 346 * Platform specific 'inline' or support functions 347 */ 348 static INLINE void 349 isp_lock(struct ispsoftc *isp) 350 { 351 int s = splbio(); 352 if (isp->isp_osinfo.islocked++ == 0) { 353 isp->isp_osinfo.splsaved = s; 354 } else { 355 splx(s); 356 } 357 } 358 359 static INLINE void 360 isp_unlock(struct ispsoftc *isp) 361 { 362 if (isp->isp_osinfo.islocked-- <= 1) { 363 isp->isp_osinfo.islocked = 0; 364 splx(isp->isp_osinfo.splsaved); 365 } 366 } 367 368 static INLINE char * 369 strncat(char *d, const char *s, size_t c) 370 { 371 char *t = d; 372 373 if (c) { 374 while (*d) 375 d++; 376 while ((*d++ = *s++)) { 377 if (--c == 0) { 378 *d = '\0'; 379 break; 380 } 381 } 382 } 383 return (t); 384 } 385 386 static INLINE u_int64_t 387 isp_microtime_sub(struct timeval *b, struct timeval *a) 388 { 389 struct timeval x; 390 u_int64_t elapsed; 391 timersub(b, a, &x); 392 elapsed = GET_NANOSEC(&x); 393 if (elapsed == 0) 394 elapsed++; 395 return (elapsed); 396 } 397 398 static INLINE void 399 isp_wait_complete(struct ispsoftc *isp) 400 { 401 if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) { 402 int usecs = 0; 403 /* 404 * For sanity's sake, we don't delay longer 405 * than 5 seconds for polled commands. 406 */ 407 while (usecs < 5 * 1000000) { 408 u_int16_t isr, sema, mbox; 409 if (isp->isp_mboxbsy == 0) { 410 break; 411 } 412 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) { 413 isp_intr(isp, isr, sema, mbox); 414 if (isp->isp_mboxbsy == 0) { 415 break; 416 } 417 } 418 USEC_DELAY(500); 419 usecs += 500; 420 } 421 if (isp->isp_mboxbsy != 0) { 422 isp_prt(isp, ISP_LOGWARN, 423 "Polled Mailbox Command (0x%x) Timeout", 424 isp->isp_lastmbxcmd); 425 } 426 } else { 427 int rv = 0; 428 isp->isp_osinfo.mboxwaiting = 1; 429 while (isp->isp_osinfo.mboxwaiting && rv == 0) { 430 static const struct timeval dtime = { 5, 0 }; 431 int timo; 432 struct timeval tv; 433 microtime(&tv); 434 timeradd(&tv, &dtime, &tv); 435 if ((timo = hzto(&tv)) == 0) { 436 timo = 1; 437 } 438 rv = tsleep(&isp->isp_osinfo.mboxwaiting, 439 PRIBIO, "isp_mboxcmd", timo); 440 } 441 if (rv == EWOULDBLOCK) { 442 isp->isp_mboxbsy = 0; 443 isp->isp_osinfo.mboxwaiting = 0; 444 isp_prt(isp, ISP_LOGWARN, 445 "Interrupting Mailbox Command (0x%x) Timeout", 446 isp->isp_lastmbxcmd); 447 } 448 } 449 } 450 451 #if _BYTE_ORDER == _BIG_ENDIAN 452 static INLINE void 453 isp_swizzle_request(struct ispsoftc *isp, ispreq_t *rq) 454 { 455 if (IS_FC(isp)) { 456 ispreqt2_t *tq = (ispreqt2_t *) rq; 457 tq->req_handle = bswap32(tq->req_handle); 458 tq->req_scclun = bswap16(tq->req_scclun); 459 tq->req_flags = bswap16(tq->req_flags); 460 tq->req_time = bswap16(tq->req_time); 461 tq->req_totalcnt = bswap32(tq->req_totalcnt); 462 } else if (isp->isp_bustype == ISP_BT_SBUS) { 463 _ISP_SWAP8(rq->req_header.rqs_entry_count, 464 rq->req_header.rqs_entry_type); 465 _ISP_SWAP8(rq->req_header.rqs_flags, rq->req_header.rqs_seqno); 466 _ISP_SWAP8(rq->req_target, rq->req_lun_trn); 467 } else { 468 rq->req_handle = bswap32(rq->req_handle); 469 rq->req_cdblen = bswap16(rq->req_cdblen); 470 rq->req_flags = bswap16(rq->req_flags); 471 rq->req_time = bswap16(rq->req_time); 472 } 473 } 474 475 static INLINE void 476 isp_unswizzle_response(struct ispsoftc *isp, void *rp, u_int16_t optr) 477 { 478 ispstatusreq_t *sp = rp; 479 MEMORYBARRIER(isp, SYNC_RESPONSE, optr * QENTRY_LEN, QENTRY_LEN); 480 if (isp->isp_bustype == ISP_BT_SBUS) { 481 _ISP_SWAP8(sp->req_header.rqs_entry_count, 482 sp->req_header.rqs_entry_type); 483 _ISP_SWAP8(sp->req_header.rqs_flags, sp->req_header.rqs_seqno); 484 } else switch (sp->req_header.rqs_entry_type) { 485 case RQSTYPE_RESPONSE: 486 sp->req_handle = bswap32(sp->req_handle); 487 sp->req_scsi_status = bswap16(sp->req_scsi_status); 488 sp->req_completion_status = bswap16(sp->req_completion_status); 489 sp->req_state_flags = bswap16(sp->req_state_flags); 490 sp->req_status_flags = bswap16(sp->req_status_flags); 491 sp->req_time = bswap16(sp->req_time); 492 sp->req_sense_len = bswap16(sp->req_sense_len); 493 sp->req_resid = bswap32(sp->req_resid); 494 break; 495 default: 496 break; 497 } 498 } 499 500 static INLINE void 501 isp_swizzle_icb(struct ispsoftc *isp, isp_icb_t *icbp) 502 { 503 _ISP_SWAP8(icbp->icb_version, icbp->_reserved0); 504 _ISP_SWAP8(icbp->icb_retry_count, icbp->icb_retry_delay); 505 _ISP_SWAP8(icbp->icb_iqdevtype, icbp->icb_logintime); 506 _ISP_SWAP8(icbp->icb_ccnt, icbp->icb_icnt); 507 _ISP_SWAP8(icbp->icb_racctimer, icbp->icb_idelaytimer); 508 icbp->icb_fwoptions = bswap16(icbp->icb_fwoptions); 509 icbp->icb_maxfrmlen = bswap16(icbp->icb_maxfrmlen); 510 icbp->icb_maxalloc = bswap16(icbp->icb_maxalloc); 511 icbp->icb_execthrottle = bswap16(icbp->icb_execthrottle); 512 icbp->icb_hardaddr = bswap16(icbp->icb_hardaddr); 513 icbp->icb_rqstout = bswap16(icbp->icb_rqstout); 514 icbp->icb_rspnsin = bswap16(icbp->icb_rspnsin); 515 icbp->icb_rqstqlen = bswap16(icbp->icb_rqstqlen); 516 icbp->icb_rsltqlen = bswap16(icbp->icb_rsltqlen); 517 icbp->icb_lunenables = bswap16(icbp->icb_lunenables); 518 icbp->icb_lunetimeout = bswap16(icbp->icb_lunetimeout); 519 icbp->icb_xfwoptions = bswap16(icbp->icb_xfwoptions); 520 icbp->icb_zfwoptions = bswap16(icbp->icb_zfwoptions); 521 icbp->icb_rqstaddr[0] = bswap16(icbp->icb_rqstaddr[0]); 522 icbp->icb_rqstaddr[1] = bswap16(icbp->icb_rqstaddr[1]); 523 icbp->icb_rqstaddr[2] = bswap16(icbp->icb_rqstaddr[2]); 524 icbp->icb_rqstaddr[3] = bswap16(icbp->icb_rqstaddr[3]); 525 icbp->icb_respaddr[0] = bswap16(icbp->icb_respaddr[0]); 526 icbp->icb_respaddr[1] = bswap16(icbp->icb_respaddr[1]); 527 icbp->icb_respaddr[2] = bswap16(icbp->icb_respaddr[2]); 528 icbp->icb_respaddr[3] = bswap16(icbp->icb_respaddr[3]); 529 } 530 531 static INLINE void 532 isp_unswizzle_and_copy_pdbp(struct ispsoftc *isp, isp_pdb_t *dst, void *src) 533 { 534 isp_pdb_t *pdbp = src; 535 dst->pdb_options = bswap16(pdbp->pdb_options); 536 dst->pdb_mstate = pdbp->pdb_sstate; 537 dst->pdb_sstate = pdbp->pdb_mstate; 538 dst->pdb_hardaddr_bits[0] = pdbp->pdb_hardaddr_bits[0]; 539 dst->pdb_hardaddr_bits[1] = pdbp->pdb_hardaddr_bits[1]; 540 dst->pdb_hardaddr_bits[2] = pdbp->pdb_hardaddr_bits[2]; 541 dst->pdb_hardaddr_bits[3] = pdbp->pdb_hardaddr_bits[3]; 542 dst->pdb_portid_bits[0] = pdbp->pdb_portid_bits[0]; 543 dst->pdb_portid_bits[1] = pdbp->pdb_portid_bits[1]; 544 dst->pdb_portid_bits[2] = pdbp->pdb_portid_bits[2]; 545 dst->pdb_portid_bits[3] = pdbp->pdb_portid_bits[3]; 546 dst->pdb_nodename[0] = pdbp->pdb_nodename[0]; 547 dst->pdb_nodename[1] = pdbp->pdb_nodename[1]; 548 dst->pdb_nodename[2] = pdbp->pdb_nodename[2]; 549 dst->pdb_nodename[3] = pdbp->pdb_nodename[3]; 550 dst->pdb_nodename[4] = pdbp->pdb_nodename[4]; 551 dst->pdb_nodename[5] = pdbp->pdb_nodename[5]; 552 dst->pdb_nodename[6] = pdbp->pdb_nodename[6]; 553 dst->pdb_nodename[7] = pdbp->pdb_nodename[7]; 554 dst->pdb_portname[0] = pdbp->pdb_portname[0]; 555 dst->pdb_portname[1] = pdbp->pdb_portname[1]; 556 dst->pdb_portname[2] = pdbp->pdb_portname[2]; 557 dst->pdb_portname[3] = pdbp->pdb_portname[3]; 558 dst->pdb_portname[4] = pdbp->pdb_portname[4]; 559 dst->pdb_portname[5] = pdbp->pdb_portname[5]; 560 dst->pdb_portname[6] = pdbp->pdb_portname[6]; 561 dst->pdb_portname[7] = pdbp->pdb_portname[7]; 562 dst->pdb_execthrottle = bswap16(pdbp->pdb_execthrottle); 563 dst->pdb_exec_count = bswap16(pdbp->pdb_exec_count); 564 dst->pdb_resalloc = bswap16(pdbp->pdb_resalloc); 565 dst->pdb_curalloc = bswap16(pdbp->pdb_curalloc); 566 dst->pdb_qhead = bswap16(pdbp->pdb_qhead); 567 dst->pdb_qtail = bswap16(pdbp->pdb_qtail); 568 dst->pdb_tl_next = bswap16(pdbp->pdb_tl_next); 569 dst->pdb_tl_last = bswap16(pdbp->pdb_tl_last); 570 dst->pdb_features = bswap16(pdbp->pdb_features); 571 dst->pdb_pconcurrnt = bswap16(pdbp->pdb_pconcurrnt); 572 dst->pdb_roi = bswap16(pdbp->pdb_roi); 573 dst->pdb_rdsiz = bswap16(pdbp->pdb_rdsiz); 574 dst->pdb_ncseq = bswap16(pdbp->pdb_ncseq); 575 dst->pdb_noseq = bswap16(pdbp->pdb_noseq); 576 dst->pdb_labrtflg = bswap16(pdbp->pdb_labrtflg); 577 dst->pdb_lstopflg = bswap16(pdbp->pdb_lstopflg); 578 dst->pdb_sqhead = bswap16(pdbp->pdb_sqhead); 579 dst->pdb_sqtail = bswap16(pdbp->pdb_sqtail); 580 dst->pdb_ptimer = bswap16(pdbp->pdb_ptimer); 581 dst->pdb_nxt_seqid = bswap16(pdbp->pdb_nxt_seqid); 582 dst->pdb_fcount = bswap16(pdbp->pdb_fcount); 583 dst->pdb_prli_len = bswap16(pdbp->pdb_prli_len); 584 dst->pdb_prli_svc0 = bswap16(pdbp->pdb_prli_svc0); 585 dst->pdb_prli_svc3 = bswap16(pdbp->pdb_prli_svc3); 586 dst->pdb_loopid = bswap16(pdbp->pdb_loopid); 587 dst->pdb_il_ptr = bswap16(pdbp->pdb_il_ptr); 588 dst->pdb_sl_ptr = bswap16(pdbp->pdb_sl_ptr); 589 dst->pdb_retry_count = pdbp->pdb_retry_delay; 590 dst->pdb_retry_delay = pdbp->pdb_retry_count; 591 dst->pdb_target = pdbp->pdb_initiator; 592 dst->pdb_initiator = pdbp->pdb_target; 593 } 594 595 static INLINE void 596 isp_swizzle_sns_req(struct ispsoftc *isp, sns_screq_t *reqp) 597 { 598 u_int16_t index, nwords = reqp->snscb_sblen; 599 reqp->snscb_rblen = bswap16(reqp->snscb_rblen); 600 reqp->snscb_addr[0] = bswap16(reqp->snscb_addr[0]); 601 reqp->snscb_addr[1] = bswap16(reqp->snscb_addr[1]); 602 reqp->snscb_addr[2] = bswap16(reqp->snscb_addr[2]); 603 reqp->snscb_addr[3] = bswap16(reqp->snscb_addr[3]); 604 reqp->snscb_sblen = bswap16(reqp->snscb_sblen); 605 for (index = 0; index < nwords; index++) { 606 reqp->snscb_data[index] = bswap16(reqp->snscb_data[index]); 607 } 608 } 609 610 static INLINE void 611 isp_unswizzle_sns_rsp(struct ispsoftc *isp, sns_scrsp_t *resp, int nwords) 612 { 613 int index; 614 /* 615 * Don't even think about asking. This. Is. So. Lame. 616 */ 617 if (IS_2200(isp) && 618 ISP_FW_REVX(isp->isp_fwrev) == ISP_FW_REV(2, 1, 26)) { 619 nwords = 128; 620 } 621 for (index = 0; index < nwords; index++) { 622 resp->snscb_data[index] = bswap16(resp->snscb_data[index]); 623 } 624 } 625 #endif 626 627 /* 628 * Common inline functions 629 */ 630 #include <dev/ic/isp_inline.h> 631 632 #if !defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW) 633 #define ISP_COMPILE_FW 1 634 #endif 635 #endif /* _ISP_NETBSD_H */ 636