1 /* $NetBSD: isp_netbsd.h,v 1.66 2008/05/11 02:08:11 mjacob Exp $ */ 2 /* 3 * NetBSD Specific definitions for the Qlogic ISP Host Adapter 4 */ 5 /* 6 * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration 7 * All rights reserved. 8 * 9 * Additional Copyright (C) 2000-2007 by Matthew Jacob 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 #ifndef _ISP_NETBSD_H 35 #define _ISP_NETBSD_H 36 37 #include <sys/types.h> 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/kernel.h> 41 #include <sys/errno.h> 42 #include <sys/ioctl.h> 43 #include <sys/device.h> 44 #include <sys/malloc.h> 45 #include <sys/buf.h> 46 #include <sys/proc.h> 47 #include <sys/user.h> 48 #include <sys/kthread.h> 49 50 #include <sys/bus.h> 51 52 #include <dev/scsipi/scsi_all.h> 53 #include <dev/scsipi/scsipi_all.h> 54 #include <dev/scsipi/scsiconf.h> 55 56 #include <dev/scsipi/scsi_message.h> 57 #include <dev/scsipi/scsipi_debug.h> 58 59 #include <machine/stdarg.h> 60 61 #include "opt_isp.h" 62 63 /* 64 * Efficiency- get rid of SBus code && tests unless we need them. 65 */ 66 #if defined(__sparcv9__ ) || defined(__sparc__) 67 #define ISP_SBUS_SUPPORTED 1 68 #else 69 #define ISP_SBUS_SUPPORTED 0 70 #endif 71 72 #define ISP_PLATFORM_VERSION_MAJOR 4 73 #define ISP_PLATFORM_VERSION_MINOR 0 74 75 struct isposinfo { 76 struct device dev; 77 struct scsipi_adapter adapter; 78 struct scsipi_channel * chan; 79 bus_dma_tag_t dmatag; 80 bus_dmamap_t rqdmap; 81 bus_dmamap_t rsdmap; 82 bus_dmamap_t scdmap; /* FC only */ 83 int splsaved; 84 int mboxwaiting; 85 uint32_t islocked; 86 uint32_t onintstack; 87 uint32_t loop_down_time; 88 uint32_t loop_down_limit; 89 uint32_t gone_device_time; 90 unsigned int : 16, 91 : 8, 92 gdt_running : 1, 93 loop_checked : 1, 94 mbox_sleeping : 1, 95 mbox_sleep_ok : 1, 96 mboxcmd_done : 1, 97 mboxbsy : 1, 98 paused : 1, 99 blocked : 1; 100 struct callout ldt; /* loop down timer */ 101 struct callout gdt; /* gone device timer */ 102 uint64_t wwn; 103 uint16_t framesize; 104 uint16_t exec_throttle; 105 struct lwp * thread; 106 }; 107 #define isp_dmatag isp_osinfo.dmatag 108 #define isp_rqdmap isp_osinfo.rqdmap 109 #define isp_rsdmap isp_osinfo.rsdmap 110 #define isp_scdmap isp_osinfo.scdmap 111 112 #define ISP_MUSTPOLL(isp) \ 113 (isp->isp_osinfo.onintstack || isp->isp_osinfo.mbox_sleep_ok == 0) 114 115 /* 116 * Required Macros/Defines 117 */ 118 119 #define ISP_FC_SCRLEN 0x1000 120 121 #define MEMZERO(dst, amt) memset((dst), 0, (amt)) 122 #define MEMCPY(dst, src, amt) memcpy((dst), (src), (amt)) 123 #define SNPRINTF snprintf 124 #define USEC_DELAY DELAY 125 #define USEC_SLEEP(isp, x) \ 126 if (!ISP_MUSTPOLL(isp)) \ 127 ISP_UNLOCK(isp); \ 128 DELAY(x); \ 129 if (!ISP_MUSTPOLL(isp)) \ 130 ISP_LOCK(isp) 131 132 #define NANOTIME_T struct timeval 133 #define GET_NANOTIME microtime 134 #define GET_NANOSEC(x) (((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000) 135 #define NANOTIME_SUB isp_microtime_sub 136 137 #define MAXISPREQUEST(isp) 256 138 139 140 #define MEMORYBARRIER(isp, type, offset, size) \ 141 switch (type) { \ 142 case SYNC_REQUEST: \ 143 { \ 144 off_t off = (off_t) offset * QENTRY_LEN; \ 145 bus_dmamap_sync(isp->isp_dmatag, isp->isp_rqdmap, \ 146 off, size, BUS_DMASYNC_PREWRITE); \ 147 break; \ 148 } \ 149 case SYNC_RESULT: \ 150 { \ 151 off_t off = (off_t) offset * QENTRY_LEN; \ 152 bus_dmamap_sync(isp->isp_dmatag, isp->isp_rsdmap, \ 153 off, size, BUS_DMASYNC_POSTREAD); \ 154 break; \ 155 } \ 156 case SYNC_SFORDEV: \ 157 { \ 158 off_t off = (off_t) offset; \ 159 bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap, \ 160 off, size, BUS_DMASYNC_PREWRITE); \ 161 break; \ 162 } \ 163 case SYNC_SFORCPU: \ 164 { \ 165 off_t off = (off_t) offset; \ 166 bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap, \ 167 off, size, BUS_DMASYNC_POSTREAD); \ 168 break; \ 169 } \ 170 default: \ 171 break; \ 172 } 173 174 #define MBOX_ACQUIRE isp_mbox_acquire 175 #define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 176 #define MBOX_NOTIFY_COMPLETE isp_mbox_notify_done 177 #define MBOX_RELEASE isp_mbox_release 178 179 #define FC_SCRATCH_ACQUIRE(isp, chan) 0 180 #define FC_SCRATCH_RELEASE(isp, chan) do { } while (0) 181 182 #ifndef SCSI_GOOD 183 #define SCSI_GOOD 0x0 184 #endif 185 #ifndef SCSI_CHECK 186 #define SCSI_CHECK 0x2 187 #endif 188 #ifndef SCSI_BUSY 189 #define SCSI_BUSY 0x8 190 #endif 191 #ifndef SCSI_QFULL 192 #define SCSI_QFULL 0x28 193 #endif 194 195 #define XS_T struct scsipi_xfer 196 #define XS_DMA_ADDR_T bus_addr_t 197 #define XS_CHANNEL(xs) \ 198 ((int) (xs)->xs_periph->periph_channel->chan_channel) 199 #define XS_ISP(xs) \ 200 ((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev) 201 #define XS_LUN(xs) ((int) (xs)->xs_periph->periph_lun) 202 #define XS_TGT(xs) ((int) (xs)->xs_periph->periph_target) 203 #define XS_CDBP(xs) ((uint8_t *) (xs)->cmd) 204 #define XS_CDBLEN(xs) (xs)->cmdlen 205 #define XS_XFRLEN(xs) (xs)->datalen 206 #define XS_TIME(xs) (xs)->timeout 207 #define XS_RESID(xs) (xs)->resid 208 #define XS_STSP(xs) (&(xs)->status) 209 #define XS_SNSP(xs) (&(xs)->sense.scsi_sense) 210 #define XS_SNSLEN(xs) (sizeof (xs)->sense) 211 #define XS_SNSKEY(xs) ((xs)->sense.scsi_sense.flags) 212 /* PORTING NOTES: check to see if there's a better way of checking for tagged */ 213 #define XS_TAG_P(ccb) (((xs)->xs_control & XS_CTL_POLL) != 0) 214 /* PORTING NOTES: We elimited OTAG option for performance */ 215 #define XS_TAG_TYPE(xs) \ 216 (((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : REQFLAG_STAG) 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, ptr, len) \ 237 if (xs->error == XS_NOERROR) { \ 238 xs->error = XS_SENSE; \ 239 } \ 240 memcpy(&(xs)->sense, ptr, imin(XS_SNSLEN(xs), len)) 241 242 #define XS_SET_STATE_STAT(a, b, c) 243 244 #define DEFAULT_FRAMESIZE(isp) (isp)->isp_osinfo.framesize 245 #define DEFAULT_EXEC_THROTTLE(isp) (isp)->isp_osinfo.exec_throttle 246 #define GET_DEFAULT_ROLE(isp, chan) ISP_ROLE_INITIATOR 247 #define SET_DEFAULT_ROLE(isp, chan) do { } while (0) 248 #define DEFAULT_IID(x, chan) 7 249 #define DEFAULT_LOOPID(x, chan) 108 250 #define DEFAULT_NODEWWN(isp, chan) (isp)->isp_osinfo.wwn 251 #define DEFAULT_PORTWWN(isp, chan) (isp)->isp_osinfo.wwn 252 #define ACTIVE_NODEWWN(isp, chan) \ 253 (isp)->isp_osinfo.wwn? (isp)->isp_osinfo.wwn : \ 254 FCPARAM(isp, chan)->isp_wwnn_nvram 255 #define ACTIVE_PORTWWN(isp, chan) \ 256 (isp)->isp_osinfo.wwn? (isp)->isp_osinfo.wwn : \ 257 FCPARAM(isp, chan)->isp_wwpn_nvram 258 259 #if _BYTE_ORDER == _BIG_ENDIAN 260 #ifdef ISP_SBUS_SUPPORTED 261 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 262 #define ISP_IOXPUT_16(isp, s, d) \ 263 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s) 264 #define ISP_IOXPUT_32(isp, s, d) \ 265 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s) 266 267 #define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 268 #define ISP_IOXGET_16(isp, s, d) \ 269 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 270 *((uint16_t *)s) : bswap16(*((uint16_t *)s)) 271 #define ISP_IOXGET_32(isp, s, d) \ 272 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 273 *((uint32_t *)s) : bswap32(*((uint32_t *)s)) 274 275 #else /* ISP_SBUS_SUPPORTED */ 276 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 277 #define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s) 278 #define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s) 279 #define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 280 #define ISP_IOXGET_16(isp, s, d) d = bswap16(*((uint16_t *)s)) 281 #define ISP_IOXGET_32(isp, s, d) d = bswap32(*((uint32_t *)s)) 282 #endif /* ISP_SBUS_SUPPORTED */ 283 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp) 284 #define ISP_SWIZZLE_NVRAM_LONG(isp, rp) *rp = bswap32(*rp) 285 286 #define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)s)) 287 #define ISP_IOZGET_16(isp, s, d) d = (*((uint16_t *)s)) 288 #define ISP_IOZGET_32(isp, s, d) d = (*((uint32_t *)s)) 289 #define ISP_IOZPUT_8(isp, s, d) *(d) = s 290 #define ISP_IOZPUT_16(isp, s, d) *(d) = s 291 #define ISP_IOZPUT_32(isp, s, d) *(d) = s 292 293 #else 294 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 295 #define ISP_IOXPUT_16(isp, s, d) *(d) = s 296 #define ISP_IOXPUT_32(isp, s, d) *(d) = s 297 #define ISP_IOXGET_8(isp, s, d) d = *(s) 298 #define ISP_IOXGET_16(isp, s, d) d = *(s) 299 #define ISP_IOXGET_32(isp, s, d) d = *(s) 300 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) 301 #define ISP_SWIZZLE_NVRAM_LONG(isp, rp) 302 303 #define ISP_IOZPUT_8(isp, s, d) *(d) = s 304 #define ISP_IOZPUT_16(isp, s, d) *(d) = bswap16(s) 305 #define ISP_IOZPUT_32(isp, s, d) *(d) = bswap32(s) 306 307 #define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)(s))) 308 #define ISP_IOZGET_16(isp, s, d) d = bswap16(*((uint16_t *)(s))) 309 #define ISP_IOZGET_32(isp, s, d) d = bswap32(*((uint32_t *)(s))) 310 311 #endif 312 313 #define ISP_SWAP16(isp, x) bswap16(x) 314 #define ISP_SWAP32(isp, x) bswap32(x) 315 316 /* 317 * Includes of common header files 318 */ 319 320 #include <dev/ic/ispreg.h> 321 #include <dev/ic/ispvar.h> 322 #include <dev/ic/ispmbox.h> 323 324 /* 325 * isp_osinfo definitions, extensions and shorthand. 326 */ 327 #define isp_unit isp_osinfo.dev.dv_unit 328 329 330 /* 331 * Driver prototypes.. 332 */ 333 void isp_attach(ispsoftc_t *); 334 void isp_uninit(ispsoftc_t *); 335 336 /* 337 * Driver wide data... 338 */ 339 340 /* 341 * Locking macros... 342 */ 343 #define ISP_LOCK isp_lock 344 #define ISP_UNLOCK isp_unlock 345 #define ISP_ILOCK(x) isp_lock(x); isp->isp_osinfo.onintstack++ 346 #define ISP_IUNLOCK(x) isp->isp_osinfo.onintstack--; isp_unlock(x) 347 348 /* 349 * Platform private flags 350 */ 351 352 #define XS_PSTS_INWDOG 0x10000000 353 #define XS_PSTS_GRACE 0x20000000 354 #define XS_PSTS_ALL 0x30000000 355 356 #define XS_CMD_S_WDOG(xs) (xs)->xs_status |= XS_PSTS_INWDOG 357 #define XS_CMD_C_WDOG(xs) (xs)->xs_status &= ~XS_PSTS_INWDOG 358 #define XS_CMD_WDOG_P(xs) (((xs)->xs_status & XS_PSTS_INWDOG) != 0) 359 360 #define XS_CMD_S_GRACE(xs) (xs)->xs_status |= XS_PSTS_GRACE 361 #define XS_CMD_C_GRACE(xs) (xs)->xs_status &= ~XS_PSTS_GRACE 362 #define XS_CMD_GRACE_P(xs) (((xs)->xs_status & XS_PSTS_GRACE) != 0) 363 364 #define XS_CMD_S_DONE(xs) (xs)->xs_status |= XS_STS_DONE 365 #define XS_CMD_C_DONE(xs) (xs)->xs_status &= ~XS_STS_DONE 366 #define XS_CMD_DONE_P(xs) (((xs)->xs_status & XS_STS_DONE) != 0) 367 368 #define XS_CMD_S_CLEAR(xs) (xs)->xs_status &= ~XS_PSTS_ALL 369 370 /* 371 * Platform Library Functionw 372 */ 373 void isp_prt(ispsoftc_t *, int level, const char *, ...); 374 void isp_lock(ispsoftc_t *); 375 void isp_unlock(ispsoftc_t *); 376 uint64_t isp_microtime_sub(struct timeval *, struct timeval *); 377 int isp_mbox_acquire(ispsoftc_t *); 378 void isp_mbox_wait_complete(ispsoftc_t *, mbreg_t *); 379 void isp_mbox_notify_done(ispsoftc_t *); 380 void isp_mbox_release(ispsoftc_t *); 381 382 /* 383 * Common Library functions 384 */ 385 #include <dev/ic/isp_library.h> 386 387 #if !defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW) 388 #define ISP_COMPILE_FW 1 389 #endif 390 #endif /* _ISP_NETBSD_H */ 391