1 /* $NetBSD: isp_netbsd.h,v 1.63 2007/10/19 11:59:54 ad 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 "opt_isp.h" 60 61 /* 62 * Efficiency- get rid of SBus code && tests unless we need them. 63 */ 64 #if defined(__sparcv9__ ) || defined(__sparc__) 65 #define ISP_SBUS_SUPPORTED 1 66 #else 67 #define ISP_SBUS_SUPPORTED 0 68 #endif 69 70 #define ISP_PLATFORM_VERSION_MAJOR 3 71 #define ISP_PLATFORM_VERSION_MINOR 0 72 73 struct isposinfo { 74 struct device _dev; 75 struct scsipi_channel _chan; 76 struct scsipi_channel _chan_b; 77 struct scsipi_adapter _adapter; 78 bus_dma_tag_t dmatag; 79 bus_dmamap_t rqdmap; 80 bus_dmamap_t rsdmap; 81 bus_dmamap_t scdmap; /* FC only */ 82 int splsaved; 83 int mboxwaiting; 84 uint32_t islocked; 85 uint32_t onintstack; 86 uint32_t loop_down_time; 87 uint32_t loop_down_limit; 88 uint32_t gone_device_time; 89 unsigned int : 16, 90 : 8, 91 gdt_running : 1, 92 loop_checked : 1, 93 mbox_sleeping : 1, 94 mbox_sleep_ok : 1, 95 mboxcmd_done : 1, 96 mboxbsy : 1, 97 paused : 1, 98 blocked : 1; 99 struct callout ldt; /* loop down timer */ 100 struct callout gdt; /* gone device timer */ 101 union { 102 uint64_t _wwn; 103 uint16_t _discovered[2]; 104 #define wwn_seed un._wwn 105 #define discovered un._discovered 106 } un; 107 struct lwp * thread; 108 }; 109 #define isp_dmatag isp_osinfo.dmatag 110 #define isp_rqdmap isp_osinfo.rqdmap 111 #define isp_rsdmap isp_osinfo.rsdmap 112 #define isp_scdmap isp_osinfo.scdmap 113 114 #define ISP_MUSTPOLL(isp) \ 115 (isp->isp_osinfo.onintstack || isp->isp_osinfo.mbox_sleep_ok == 0) 116 117 /* 118 * Required Macros/Defines 119 */ 120 121 #define ISP2100_SCRLEN 0x1000 122 123 #define MEMZERO(dst, amt) memset((dst), 0, (amt)) 124 #define MEMCPY(dst, src, amt) memcpy((dst), (src), (amt)) 125 #define SNPRINTF snprintf 126 #define USEC_DELAY DELAY 127 #define USEC_SLEEP(isp, x) \ 128 if (!ISP_MUSTPOLL(isp)) \ 129 ISP_UNLOCK(isp); \ 130 DELAY(x); \ 131 if (!ISP_MUSTPOLL(isp)) \ 132 ISP_LOCK(isp) 133 134 #define NANOTIME_T struct timeval 135 #define GET_NANOTIME microtime 136 #define GET_NANOSEC(x) (((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000) 137 #define NANOTIME_SUB isp_microtime_sub 138 139 #define MAXISPREQUEST(isp) 256 140 141 142 #define MEMORYBARRIER(isp, type, offset, size) \ 143 switch (type) { \ 144 case SYNC_REQUEST: \ 145 { \ 146 off_t off = (off_t) offset * QENTRY_LEN; \ 147 bus_dmamap_sync(isp->isp_dmatag, isp->isp_rqdmap, \ 148 off, size, BUS_DMASYNC_PREWRITE); \ 149 break; \ 150 } \ 151 case SYNC_RESULT: \ 152 { \ 153 off_t off = (off_t) offset * QENTRY_LEN; \ 154 bus_dmamap_sync(isp->isp_dmatag, isp->isp_rsdmap, \ 155 off, size, BUS_DMASYNC_POSTREAD); \ 156 break; \ 157 } \ 158 case SYNC_SFORDEV: \ 159 { \ 160 off_t off = (off_t) offset; \ 161 bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap, \ 162 off, size, BUS_DMASYNC_PREWRITE); \ 163 break; \ 164 } \ 165 case SYNC_SFORCPU: \ 166 { \ 167 off_t off = (off_t) offset; \ 168 bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap, \ 169 off, size, BUS_DMASYNC_POSTREAD); \ 170 break; \ 171 } \ 172 default: \ 173 break; \ 174 } 175 176 #define MBOX_ACQUIRE isp_mbox_acquire 177 #define MBOX_WAIT_COMPLETE isp_mbox_wait_complete 178 #define MBOX_NOTIFY_COMPLETE isp_mbox_notify_done 179 #define MBOX_RELEASE isp_mbox_release 180 181 #define FC_SCRATCH_ACQUIRE(isp) 182 #define FC_SCRATCH_RELEASE(isp) 183 184 #ifndef SCSI_GOOD 185 #define SCSI_GOOD 0x0 186 #endif 187 #ifndef SCSI_CHECK 188 #define SCSI_CHECK 0x2 189 #endif 190 #ifndef SCSI_BUSY 191 #define SCSI_BUSY 0x8 192 #endif 193 #ifndef SCSI_QFULL 194 #define SCSI_QFULL 0x28 195 #endif 196 197 #define XS_T struct scsipi_xfer 198 #define XS_DMA_ADDR_T bus_addr_t 199 #define XS_CHANNEL(xs) \ 200 ((int) (xs)->xs_periph->periph_channel->chan_channel) 201 #define XS_ISP(xs) \ 202 ((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev) 203 #define XS_LUN(xs) ((int) (xs)->xs_periph->periph_lun) 204 #define XS_TGT(xs) ((int) (xs)->xs_periph->periph_target) 205 #define XS_CDBP(xs) ((uint8_t *) (xs)->cmd) 206 #define XS_CDBLEN(xs) (xs)->cmdlen 207 #define XS_XFRLEN(xs) (xs)->datalen 208 #define XS_TIME(xs) (xs)->timeout 209 #define XS_RESID(xs) (xs)->resid 210 #define XS_STSP(xs) (&(xs)->status) 211 #define XS_SNSP(xs) (&(xs)->sense.scsi_sense) 212 #define XS_SNSLEN(xs) (sizeof (xs)->sense) 213 #define XS_SNSKEY(xs) ((xs)->sense.scsi_sense.flags) 214 /* PORTING NOTES: check to see if there's a better way of checking for tagged */ 215 #define XS_TAG_P(ccb) (((xs)->xs_control & XS_CTL_POLL) != 0) 216 /* PORTING NOTES: We elimited OTAG option for performance */ 217 #define XS_TAG_TYPE(xs) \ 218 (((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : REQFLAG_STAG) 219 220 #define XS_SETERR(xs, v) (xs)->error = v 221 222 # define HBA_NOERROR XS_NOERROR 223 # define HBA_BOTCH XS_DRIVER_STUFFUP 224 # define HBA_CMDTIMEOUT XS_TIMEOUT 225 # define HBA_SELTIMEOUT XS_SELTIMEOUT 226 # define HBA_TGTBSY XS_BUSY 227 # define HBA_BUSRESET XS_RESET 228 # define HBA_ABORTED XS_DRIVER_STUFFUP 229 # define HBA_DATAOVR XS_DRIVER_STUFFUP 230 # define HBA_ARQFAIL XS_DRIVER_STUFFUP 231 232 #define XS_ERR(xs) (xs)->error 233 234 #define XS_NOERR(xs) (xs)->error == XS_NOERROR 235 236 #define XS_INITERR(xs) (xs)->error = 0, XS_CMD_S_CLEAR(xs) 237 238 #define XS_SAVE_SENSE(xs, ptr, len) \ 239 if (xs->error == XS_NOERROR) { \ 240 xs->error = XS_SENSE; \ 241 } \ 242 memcpy(&(xs)->sense, ptr, imin(XS_SNSLEN(xs), len)) 243 244 #define XS_SET_STATE_STAT(a, b, c) 245 246 #define DEFAULT_IID(x) 7 247 #define DEFAULT_LOOPID(x) 108 248 #define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.un._wwn 249 #define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.un._wwn 250 #define ISP_NODEWWN(isp) FCPARAM(isp)->isp_wwnn_nvram 251 #define ISP_PORTWWN(isp) FCPARAM(isp)->isp_wwpn_nvram 252 253 #if _BYTE_ORDER == _BIG_ENDIAN 254 #ifdef ISP_SBUS_SUPPORTED 255 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 256 #define ISP_IOXPUT_16(isp, s, d) \ 257 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s) 258 #define ISP_IOXPUT_32(isp, s, d) \ 259 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s) 260 261 #define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 262 #define ISP_IOXGET_16(isp, s, d) \ 263 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 264 *((uint16_t *)s) : bswap16(*((uint16_t *)s)) 265 #define ISP_IOXGET_32(isp, s, d) \ 266 d = (isp->isp_bustype == ISP_BT_SBUS)? \ 267 *((uint32_t *)s) : bswap32(*((uint32_t *)s)) 268 269 #else /* ISP_SBUS_SUPPORTED */ 270 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 271 #define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s) 272 #define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s) 273 #define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s)) 274 #define ISP_IOXGET_16(isp, s, d) d = bswap16(*((uint16_t *)s)) 275 #define ISP_IOXGET_32(isp, s, d) d = bswap32(*((uint32_t *)s)) 276 #endif /* ISP_SBUS_SUPPORTED */ 277 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp) 278 #define ISP_SWIZZLE_NVRAM_LONG(isp, rp) *rp = bswap32(*rp) 279 280 #define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)s)) 281 #define ISP_IOZGET_16(isp, s, d) d = (*((uint16_t *)s)) 282 #define ISP_IOZGET_32(isp, s, d) d = (*((uint32_t *)s)) 283 #define ISP_IOZPUT_8(isp, s, d) *(d) = s 284 #define ISP_IOZPUT_16(isp, s, d) *(d) = s 285 #define ISP_IOZPUT_32(isp, s, d) *(d) = s 286 287 #else 288 #define ISP_IOXPUT_8(isp, s, d) *(d) = s 289 #define ISP_IOXPUT_16(isp, s, d) *(d) = s 290 #define ISP_IOXPUT_32(isp, s, d) *(d) = s 291 #define ISP_IOXGET_8(isp, s, d) d = *(s) 292 #define ISP_IOXGET_16(isp, s, d) d = *(s) 293 #define ISP_IOXGET_32(isp, s, d) d = *(s) 294 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) 295 #define ISP_SWIZZLE_NVRAM_LONG(isp, rp) 296 297 #define ISP_IOZPUT_8(isp, s, d) *(d) = s 298 #define ISP_IOZPUT_16(isp, s, d) *(d) = bswap16(s) 299 #define ISP_IOZPUT_32(isp, s, d) *(d) = bswap32(s) 300 301 #define ISP_IOZGET_8(isp, s, d) d = (*((uint8_t *)(s))) 302 #define ISP_IOZGET_16(isp, s, d) d = bswap16(*((uint16_t *)(s))) 303 #define ISP_IOZGET_32(isp, s, d) d = bswap32(*((uint32_t *)(s))) 304 305 #endif 306 307 #define ISP_SWAP16(isp, x) bswap16(x) 308 #define ISP_SWAP32(isp, x) bswap32(x) 309 310 /* 311 * Includes of common header files 312 */ 313 314 #include <dev/ic/ispreg.h> 315 #include <dev/ic/ispvar.h> 316 #include <dev/ic/ispmbox.h> 317 318 /* 319 * isp_osinfo definitions, extensions and shorthand. 320 */ 321 #define isp_name isp_osinfo._dev.dv_xname 322 #define isp_unit isp_osinfo._dev.dv_unit 323 #define isp_chanA isp_osinfo._chan 324 #define isp_chanB isp_osinfo._chan_b 325 326 327 /* 328 * Driver prototypes.. 329 */ 330 void isp_attach(ispsoftc_t *); 331 void isp_uninit(ispsoftc_t *); 332 333 /* 334 * Driver wide data... 335 */ 336 337 /* 338 * Locking macros... 339 */ 340 #define ISP_LOCK isp_lock 341 #define ISP_UNLOCK isp_unlock 342 #define ISP_ILOCK(x) isp_lock(x); isp->isp_osinfo.onintstack++ 343 #define ISP_IUNLOCK(x) isp->isp_osinfo.onintstack--; isp_unlock(x) 344 345 /* 346 * Platform private flags 347 */ 348 349 #define XS_PSTS_INWDOG 0x10000000 350 #define XS_PSTS_GRACE 0x20000000 351 #define XS_PSTS_ALL 0x30000000 352 353 #define XS_CMD_S_WDOG(xs) (xs)->xs_status |= XS_PSTS_INWDOG 354 #define XS_CMD_C_WDOG(xs) (xs)->xs_status &= ~XS_PSTS_INWDOG 355 #define XS_CMD_WDOG_P(xs) (((xs)->xs_status & XS_PSTS_INWDOG) != 0) 356 357 #define XS_CMD_S_GRACE(xs) (xs)->xs_status |= XS_PSTS_GRACE 358 #define XS_CMD_C_GRACE(xs) (xs)->xs_status &= ~XS_PSTS_GRACE 359 #define XS_CMD_GRACE_P(xs) (((xs)->xs_status & XS_PSTS_GRACE) != 0) 360 361 #define XS_CMD_S_DONE(xs) (xs)->xs_status |= XS_STS_DONE 362 #define XS_CMD_C_DONE(xs) (xs)->xs_status &= ~XS_STS_DONE 363 #define XS_CMD_DONE_P(xs) (((xs)->xs_status & XS_STS_DONE) != 0) 364 365 #define XS_CMD_S_CLEAR(xs) (xs)->xs_status &= ~XS_PSTS_ALL 366 367 /* 368 * Platform Library Functionw 369 */ 370 void isp_prt(ispsoftc_t *, int level, const char *, ...); 371 void isp_lock(ispsoftc_t *); 372 void isp_unlock(ispsoftc_t *); 373 uint64_t isp_microtime_sub(struct timeval *, struct timeval *); 374 int isp_mbox_acquire(ispsoftc_t *); 375 void isp_mbox_wait_complete(ispsoftc_t *, mbreg_t *); 376 void isp_mbox_notify_done(ispsoftc_t *); 377 void isp_mbox_release(ispsoftc_t *); 378 379 /* 380 * Common Library functions 381 */ 382 #include <dev/ic/isp_library.h> 383 384 #if !defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW) 385 #define ISP_COMPILE_FW 1 386 #endif 387 #endif /* _ISP_NETBSD_H */ 388