1/*- 2 * Copyright (c) 1997-2006 by Matthew Jacob 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice immediately at the beginning of the file, without modification, 10 * this list of conditions, and the following disclaimer. 11 * 2. The name of the author may not be used to endorse or promote products 12 * derived from this software without specific prior written permission. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26/* 27 * SBus specific probe and attach routines for Qlogic ISP SCSI adapters. 28 * FreeBSD Version. 29 */ 30 31#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 1997-2006 by Matthew Jacob 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice immediately at the beginning of the file, without modification, 10 * this list of conditions, and the following disclaimer. 11 * 2. The name of the author may not be used to endorse or promote products 12 * derived from this software without specific prior written permission. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26/* 27 * SBus specific probe and attach routines for Qlogic ISP SCSI adapters. 28 * FreeBSD Version. 29 */ 30 31#include <sys/cdefs.h>
|
32__FBSDID("$FreeBSD: stable/10/sys/dev/isp/isp_sbus.c 246713 2013-02-12 16:57:20Z kib $");
| 32__FBSDID("$FreeBSD: stable/10/sys/dev/isp/isp_sbus.c 290785 2015-11-13 19:42:55Z mav $");
|
33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/linker.h> 37#include <sys/firmware.h> 38#include <sys/bus.h> 39#include <sys/kernel.h> 40#include <sys/module.h> 41#include <sys/resource.h> 42 43#include <dev/ofw/ofw_bus.h> 44#include <dev/ofw/openfirm.h> 45 46#include <machine/bus.h> 47#include <machine/ofw_machdep.h> 48#include <machine/resource.h> 49#include <sys/rman.h> 50#include <sparc64/sbus/sbusvar.h> 51 52#include <dev/isp/isp_freebsd.h> 53 54static uint32_t isp_sbus_rd_reg(ispsoftc_t *, int); 55static void isp_sbus_wr_reg(ispsoftc_t *, int, uint32_t);
| 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/linker.h> 37#include <sys/firmware.h> 38#include <sys/bus.h> 39#include <sys/kernel.h> 40#include <sys/module.h> 41#include <sys/resource.h> 42 43#include <dev/ofw/ofw_bus.h> 44#include <dev/ofw/openfirm.h> 45 46#include <machine/bus.h> 47#include <machine/ofw_machdep.h> 48#include <machine/resource.h> 49#include <sys/rman.h> 50#include <sparc64/sbus/sbusvar.h> 51 52#include <dev/isp/isp_freebsd.h> 53 54static uint32_t isp_sbus_rd_reg(ispsoftc_t *, int); 55static void isp_sbus_wr_reg(ispsoftc_t *, int, uint32_t);
|
56static int isp_sbus_rd_isr(ispsoftc_t *, uint32_t *, uint16_t *, uint16_t *);
| 56static int isp_sbus_rd_isr(ispsoftc_t *, uint16_t *, uint16_t *, uint16_t *);
|
57static int isp_sbus_mbxdma(ispsoftc_t *); 58static int isp_sbus_dmasetup(ispsoftc_t *, XS_T *, void *); 59 60 61static void isp_sbus_reset0(ispsoftc_t *); 62static void isp_sbus_reset1(ispsoftc_t *); 63static void isp_sbus_dumpregs(ispsoftc_t *, const char *); 64 65static struct ispmdvec mdvec = { 66 isp_sbus_rd_isr, 67 isp_sbus_rd_reg, 68 isp_sbus_wr_reg, 69 isp_sbus_mbxdma, 70 isp_sbus_dmasetup, 71 isp_common_dmateardown, 72 isp_sbus_reset0, 73 isp_sbus_reset1, 74 isp_sbus_dumpregs, 75 NULL, 76 BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64 77}; 78 79static int isp_sbus_probe (device_t); 80static int isp_sbus_attach (device_t); 81static int isp_sbus_detach (device_t); 82 83 84#define ISP_SBD(isp) ((struct isp_sbussoftc *)isp)->sbus_dev 85struct isp_sbussoftc { 86 ispsoftc_t sbus_isp; 87 device_t sbus_dev; 88 struct resource * regs; 89 void * irq; 90 int iqd; 91 int rgd; 92 void * ih; 93 int16_t sbus_poff[_NREG_BLKS]; 94 sdparam sbus_param; 95 struct isp_spi sbus_spi; 96 struct ispmdvec sbus_mdvec; 97}; 98 99 100static device_method_t isp_sbus_methods[] = { 101 /* Device interface */ 102 DEVMETHOD(device_probe, isp_sbus_probe), 103 DEVMETHOD(device_attach, isp_sbus_attach), 104 DEVMETHOD(device_detach, isp_sbus_detach), 105 { 0, 0 } 106}; 107 108static driver_t isp_sbus_driver = { 109 "isp", isp_sbus_methods, sizeof (struct isp_sbussoftc) 110}; 111static devclass_t isp_devclass; 112DRIVER_MODULE(isp, sbus, isp_sbus_driver, isp_devclass, 0, 0); 113MODULE_DEPEND(isp, cam, 1, 1, 1); 114MODULE_DEPEND(isp, firmware, 1, 1, 1); 115 116static int 117isp_sbus_probe(device_t dev) 118{ 119 int found = 0; 120 const char *name = ofw_bus_get_name(dev); 121 if (strcmp(name, "SUNW,isp") == 0 || 122 strcmp(name, "QLGC,isp") == 0 || 123 strcmp(name, "ptisp") == 0 || 124 strcmp(name, "PTI,ptisp") == 0) { 125 found++; 126 } 127 if (!found) 128 return (ENXIO); 129 130 if (isp_announced == 0 && bootverbose) { 131 printf("Qlogic ISP Driver, FreeBSD Version %d.%d, " 132 "Core Version %d.%d\n", 133 ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR, 134 ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR); 135 isp_announced++; 136 } 137 return (0); 138} 139 140static int 141isp_sbus_attach(device_t dev) 142{ 143 int tval, isp_debug, role, ispburst, default_id; 144 struct isp_sbussoftc *sbs; 145 ispsoftc_t *isp = NULL; 146 int locksetup = 0; 147 int ints_setup = 0; 148 149 sbs = device_get_softc(dev); 150 if (sbs == NULL) { 151 device_printf(dev, "cannot get softc\n"); 152 return (ENOMEM); 153 } 154 155 sbs->sbus_dev = dev; 156 sbs->sbus_mdvec = mdvec; 157 158 /* 159 * Figure out if we're supposed to skip this one. 160 * If we are, we actually go to ISP_ROLE_NONE. 161 */ 162 163 tval = 0; 164 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 165 "disable", &tval) == 0 && tval) { 166 device_printf(dev, "device is disabled\n"); 167 /* but return 0 so the !$)$)*!$*) unit isn't reused */ 168 return (0); 169 } 170 171 role = 0; 172 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 173 "role", &role) == 0 && 174 ((role & ~(ISP_ROLE_INITIATOR|ISP_ROLE_TARGET)) == 0)) { 175 device_printf(dev, "setting role to 0x%x\n", role); 176 } else { 177 role = ISP_DEFAULT_ROLES; 178 } 179 180 sbs->irq = sbs->regs = NULL; 181 sbs->rgd = sbs->iqd = 0; 182 183 sbs->regs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sbs->rgd, 184 RF_ACTIVE); 185 if (sbs->regs == NULL) { 186 device_printf(dev, "unable to map registers\n"); 187 goto bad; 188 } 189 190 sbs->sbus_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF; 191 sbs->sbus_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = SBUS_MBOX_REGS_OFF; 192 sbs->sbus_poff[SXP_BLOCK >> _BLK_REG_SHFT] = SBUS_SXP_REGS_OFF; 193 sbs->sbus_poff[RISC_BLOCK >> _BLK_REG_SHFT] = SBUS_RISC_REGS_OFF; 194 sbs->sbus_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF; 195 isp = &sbs->sbus_isp; 196 isp->isp_bus_tag = rman_get_bustag(sbs->regs); 197 isp->isp_bus_handle = rman_get_bushandle(sbs->regs); 198 isp->isp_mdvec = &sbs->sbus_mdvec; 199 isp->isp_bustype = ISP_BT_SBUS; 200 isp->isp_type = ISP_HA_SCSI_UNKNOWN; 201 isp->isp_param = &sbs->sbus_param; 202 isp->isp_osinfo.pc.ptr = &sbs->sbus_spi; 203 isp->isp_revision = 0; /* XXX */ 204 isp->isp_dev = dev; 205 isp->isp_nchan = 1; 206 ISP_SET_PC(isp, 0, def_role, role); 207 208 /* 209 * Get the clock frequency and convert it from HZ to MHz, 210 * rounding up. This defaults to 25MHz if there isn't a 211 * device specific one in the OFW device tree. 212 */ 213 sbs->sbus_mdvec.dv_clock = (sbus_get_clockfreq(dev) + 500000)/1000000; 214 215 /* 216 * Now figure out what the proper burst sizes, etc., to use. 217 * Unfortunately, there is no ddi_dma_burstsizes here which 218 * walks up the tree finding the limiting burst size node (if 219 * any). We just use what's here for isp. 220 */ 221 ispburst = sbus_get_burstsz(dev); 222 if (ispburst == 0) { 223 ispburst = SBUS_BURST_32 - 1; 224 } 225 sbs->sbus_mdvec.dv_conf1 = 0; 226 if (ispburst & (1 << 5)) { 227 sbs->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_32; 228 } else if (ispburst & (1 << 4)) { 229 sbs->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_16; 230 } else if (ispburst & (1 << 3)) { 231 sbs->sbus_mdvec.dv_conf1 = 232 BIU_SBUS_CONF1_BURST8 | BIU_SBUS_CONF1_FIFO_8; 233 } 234 if (sbs->sbus_mdvec.dv_conf1) { 235 sbs->sbus_mdvec.dv_conf1 |= BIU_BURST_ENABLE; 236 } 237 238 /* 239 * We don't trust NVRAM on SBus cards 240 */ 241 isp->isp_confopts |= ISP_CFG_NONVRAM; 242 243 /* 244 * Mark things if we're a PTI SBus adapter. 245 */ 246 if (strcmp("PTI,ptisp", ofw_bus_get_name(dev)) == 0 || 247 strcmp("ptisp", ofw_bus_get_name(dev)) == 0) { 248 SDPARAM(isp, 0)->isp_ptisp = 1; 249 } 250 251 isp->isp_osinfo.fw = firmware_get("isp_1000"); 252 if (isp->isp_osinfo.fw) { 253 union { 254 const void *cp; 255 uint16_t *sp; 256 } stupid; 257 stupid.cp = isp->isp_osinfo.fw->data; 258 isp->isp_mdvec->dv_ispfw = stupid.sp; 259 } 260 261 tval = 0; 262 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 263 "fwload_disable", &tval) == 0 && tval != 0) { 264 isp->isp_confopts |= ISP_CFG_NORELOAD; 265 } 266 267 default_id = -1; 268 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 269 "iid", &tval) == 0) { 270 default_id = tval; 271 isp->isp_confopts |= ISP_CFG_OWNLOOPID; 272 } 273 if (default_id == -1) { 274 default_id = OF_getscsinitid(dev); 275 } 276 ISP_SPI_PC(isp, 0)->iid = default_id; 277 278 isp_debug = 0; 279 (void) resource_int_value(device_get_name(dev), device_get_unit(dev), 280 "debug", &isp_debug); 281 282 /* Make sure the lock is set up. */ 283 mtx_init(&isp->isp_osinfo.lock, "isp", NULL, MTX_DEF); 284 locksetup++; 285 286 sbs->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sbs->iqd, 287 RF_ACTIVE | RF_SHAREABLE); 288 if (sbs->irq == NULL) { 289 device_printf(dev, "could not allocate interrupt\n"); 290 goto bad; 291 } 292 293 if (isp_setup_intr(dev, sbs->irq, ISP_IFLAGS, NULL, isp_platform_intr, 294 isp, &sbs->ih)) { 295 device_printf(dev, "could not setup interrupt\n"); 296 goto bad; 297 } 298 ints_setup++; 299 300 /* 301 * Set up logging levels. 302 */ 303 if (isp_debug) { 304 isp->isp_dblev = isp_debug; 305 } else { 306 isp->isp_dblev = ISP_LOGWARN|ISP_LOGERR; 307 } 308 if (bootverbose) { 309 isp->isp_dblev |= ISP_LOGCONFIG|ISP_LOGINFO; 310 } 311 312 /* 313 * Make sure we're in reset state. 314 */ 315 ISP_LOCK(isp); 316 isp_reset(isp, 1); 317 if (isp->isp_state != ISP_RESETSTATE) { 318 isp_uninit(isp); 319 ISP_UNLOCK(isp); 320 goto bad; 321 } 322 isp_init(isp); 323 if (isp->isp_state == ISP_INITSTATE) { 324 isp->isp_state = ISP_RUNSTATE; 325 } 326 ISP_UNLOCK(isp); 327 if (isp_attach(isp)) { 328 ISP_LOCK(isp); 329 isp_uninit(isp); 330 ISP_UNLOCK(isp); 331 goto bad; 332 } 333 return (0); 334 335bad: 336 337 if (sbs && ints_setup) { 338 (void) bus_teardown_intr(dev, sbs->irq, sbs->ih); 339 } 340 341 if (sbs && sbs->irq) { 342 bus_release_resource(dev, SYS_RES_IRQ, sbs->iqd, sbs->irq); 343 } 344 345 if (locksetup && isp) { 346 mtx_destroy(&isp->isp_osinfo.lock); 347 } 348 349 if (sbs->regs) { 350 (void) bus_release_resource(dev, SYS_RES_MEMORY, sbs->rgd, 351 sbs->regs); 352 } 353 return (ENXIO); 354} 355 356static int 357isp_sbus_detach(device_t dev) 358{ 359 struct isp_sbussoftc *sbs; 360 ispsoftc_t *isp; 361 int status; 362 363 sbs = device_get_softc(dev); 364 if (sbs == NULL) { 365 return (ENXIO); 366 } 367 isp = (ispsoftc_t *) sbs; 368 status = isp_detach(isp); 369 if (status) 370 return (status); 371 ISP_LOCK(isp); 372 isp_uninit(isp); 373 if (sbs->ih) { 374 (void) bus_teardown_intr(dev, sbs->irq, sbs->ih); 375 } 376 ISP_UNLOCK(isp); 377 mtx_destroy(&isp->isp_osinfo.lock); 378 (void) bus_release_resource(dev, SYS_RES_IRQ, sbs->iqd, sbs->irq); 379 (void) bus_release_resource(dev, SYS_RES_MEMORY, sbs->rgd, sbs->regs); 380 return (0); 381} 382 383#define IspVirt2Off(a, x) \ 384 (((struct isp_sbussoftc *)a)->sbus_poff[((x) & _BLK_REG_MASK) >> \ 385 _BLK_REG_SHFT] + ((x) & 0xff)) 386 387#define BXR2(sbc, off) \ 388 bus_space_read_2(isp->isp_bus_tag, isp->isp_bus_handle, off) 389 390static int
| 57static int isp_sbus_mbxdma(ispsoftc_t *); 58static int isp_sbus_dmasetup(ispsoftc_t *, XS_T *, void *); 59 60 61static void isp_sbus_reset0(ispsoftc_t *); 62static void isp_sbus_reset1(ispsoftc_t *); 63static void isp_sbus_dumpregs(ispsoftc_t *, const char *); 64 65static struct ispmdvec mdvec = { 66 isp_sbus_rd_isr, 67 isp_sbus_rd_reg, 68 isp_sbus_wr_reg, 69 isp_sbus_mbxdma, 70 isp_sbus_dmasetup, 71 isp_common_dmateardown, 72 isp_sbus_reset0, 73 isp_sbus_reset1, 74 isp_sbus_dumpregs, 75 NULL, 76 BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64 77}; 78 79static int isp_sbus_probe (device_t); 80static int isp_sbus_attach (device_t); 81static int isp_sbus_detach (device_t); 82 83 84#define ISP_SBD(isp) ((struct isp_sbussoftc *)isp)->sbus_dev 85struct isp_sbussoftc { 86 ispsoftc_t sbus_isp; 87 device_t sbus_dev; 88 struct resource * regs; 89 void * irq; 90 int iqd; 91 int rgd; 92 void * ih; 93 int16_t sbus_poff[_NREG_BLKS]; 94 sdparam sbus_param; 95 struct isp_spi sbus_spi; 96 struct ispmdvec sbus_mdvec; 97}; 98 99 100static device_method_t isp_sbus_methods[] = { 101 /* Device interface */ 102 DEVMETHOD(device_probe, isp_sbus_probe), 103 DEVMETHOD(device_attach, isp_sbus_attach), 104 DEVMETHOD(device_detach, isp_sbus_detach), 105 { 0, 0 } 106}; 107 108static driver_t isp_sbus_driver = { 109 "isp", isp_sbus_methods, sizeof (struct isp_sbussoftc) 110}; 111static devclass_t isp_devclass; 112DRIVER_MODULE(isp, sbus, isp_sbus_driver, isp_devclass, 0, 0); 113MODULE_DEPEND(isp, cam, 1, 1, 1); 114MODULE_DEPEND(isp, firmware, 1, 1, 1); 115 116static int 117isp_sbus_probe(device_t dev) 118{ 119 int found = 0; 120 const char *name = ofw_bus_get_name(dev); 121 if (strcmp(name, "SUNW,isp") == 0 || 122 strcmp(name, "QLGC,isp") == 0 || 123 strcmp(name, "ptisp") == 0 || 124 strcmp(name, "PTI,ptisp") == 0) { 125 found++; 126 } 127 if (!found) 128 return (ENXIO); 129 130 if (isp_announced == 0 && bootverbose) { 131 printf("Qlogic ISP Driver, FreeBSD Version %d.%d, " 132 "Core Version %d.%d\n", 133 ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR, 134 ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR); 135 isp_announced++; 136 } 137 return (0); 138} 139 140static int 141isp_sbus_attach(device_t dev) 142{ 143 int tval, isp_debug, role, ispburst, default_id; 144 struct isp_sbussoftc *sbs; 145 ispsoftc_t *isp = NULL; 146 int locksetup = 0; 147 int ints_setup = 0; 148 149 sbs = device_get_softc(dev); 150 if (sbs == NULL) { 151 device_printf(dev, "cannot get softc\n"); 152 return (ENOMEM); 153 } 154 155 sbs->sbus_dev = dev; 156 sbs->sbus_mdvec = mdvec; 157 158 /* 159 * Figure out if we're supposed to skip this one. 160 * If we are, we actually go to ISP_ROLE_NONE. 161 */ 162 163 tval = 0; 164 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 165 "disable", &tval) == 0 && tval) { 166 device_printf(dev, "device is disabled\n"); 167 /* but return 0 so the !$)$)*!$*) unit isn't reused */ 168 return (0); 169 } 170 171 role = 0; 172 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 173 "role", &role) == 0 && 174 ((role & ~(ISP_ROLE_INITIATOR|ISP_ROLE_TARGET)) == 0)) { 175 device_printf(dev, "setting role to 0x%x\n", role); 176 } else { 177 role = ISP_DEFAULT_ROLES; 178 } 179 180 sbs->irq = sbs->regs = NULL; 181 sbs->rgd = sbs->iqd = 0; 182 183 sbs->regs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sbs->rgd, 184 RF_ACTIVE); 185 if (sbs->regs == NULL) { 186 device_printf(dev, "unable to map registers\n"); 187 goto bad; 188 } 189 190 sbs->sbus_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF; 191 sbs->sbus_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = SBUS_MBOX_REGS_OFF; 192 sbs->sbus_poff[SXP_BLOCK >> _BLK_REG_SHFT] = SBUS_SXP_REGS_OFF; 193 sbs->sbus_poff[RISC_BLOCK >> _BLK_REG_SHFT] = SBUS_RISC_REGS_OFF; 194 sbs->sbus_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF; 195 isp = &sbs->sbus_isp; 196 isp->isp_bus_tag = rman_get_bustag(sbs->regs); 197 isp->isp_bus_handle = rman_get_bushandle(sbs->regs); 198 isp->isp_mdvec = &sbs->sbus_mdvec; 199 isp->isp_bustype = ISP_BT_SBUS; 200 isp->isp_type = ISP_HA_SCSI_UNKNOWN; 201 isp->isp_param = &sbs->sbus_param; 202 isp->isp_osinfo.pc.ptr = &sbs->sbus_spi; 203 isp->isp_revision = 0; /* XXX */ 204 isp->isp_dev = dev; 205 isp->isp_nchan = 1; 206 ISP_SET_PC(isp, 0, def_role, role); 207 208 /* 209 * Get the clock frequency and convert it from HZ to MHz, 210 * rounding up. This defaults to 25MHz if there isn't a 211 * device specific one in the OFW device tree. 212 */ 213 sbs->sbus_mdvec.dv_clock = (sbus_get_clockfreq(dev) + 500000)/1000000; 214 215 /* 216 * Now figure out what the proper burst sizes, etc., to use. 217 * Unfortunately, there is no ddi_dma_burstsizes here which 218 * walks up the tree finding the limiting burst size node (if 219 * any). We just use what's here for isp. 220 */ 221 ispburst = sbus_get_burstsz(dev); 222 if (ispburst == 0) { 223 ispburst = SBUS_BURST_32 - 1; 224 } 225 sbs->sbus_mdvec.dv_conf1 = 0; 226 if (ispburst & (1 << 5)) { 227 sbs->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_32; 228 } else if (ispburst & (1 << 4)) { 229 sbs->sbus_mdvec.dv_conf1 = BIU_SBUS_CONF1_FIFO_16; 230 } else if (ispburst & (1 << 3)) { 231 sbs->sbus_mdvec.dv_conf1 = 232 BIU_SBUS_CONF1_BURST8 | BIU_SBUS_CONF1_FIFO_8; 233 } 234 if (sbs->sbus_mdvec.dv_conf1) { 235 sbs->sbus_mdvec.dv_conf1 |= BIU_BURST_ENABLE; 236 } 237 238 /* 239 * We don't trust NVRAM on SBus cards 240 */ 241 isp->isp_confopts |= ISP_CFG_NONVRAM; 242 243 /* 244 * Mark things if we're a PTI SBus adapter. 245 */ 246 if (strcmp("PTI,ptisp", ofw_bus_get_name(dev)) == 0 || 247 strcmp("ptisp", ofw_bus_get_name(dev)) == 0) { 248 SDPARAM(isp, 0)->isp_ptisp = 1; 249 } 250 251 isp->isp_osinfo.fw = firmware_get("isp_1000"); 252 if (isp->isp_osinfo.fw) { 253 union { 254 const void *cp; 255 uint16_t *sp; 256 } stupid; 257 stupid.cp = isp->isp_osinfo.fw->data; 258 isp->isp_mdvec->dv_ispfw = stupid.sp; 259 } 260 261 tval = 0; 262 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 263 "fwload_disable", &tval) == 0 && tval != 0) { 264 isp->isp_confopts |= ISP_CFG_NORELOAD; 265 } 266 267 default_id = -1; 268 if (resource_int_value(device_get_name(dev), device_get_unit(dev), 269 "iid", &tval) == 0) { 270 default_id = tval; 271 isp->isp_confopts |= ISP_CFG_OWNLOOPID; 272 } 273 if (default_id == -1) { 274 default_id = OF_getscsinitid(dev); 275 } 276 ISP_SPI_PC(isp, 0)->iid = default_id; 277 278 isp_debug = 0; 279 (void) resource_int_value(device_get_name(dev), device_get_unit(dev), 280 "debug", &isp_debug); 281 282 /* Make sure the lock is set up. */ 283 mtx_init(&isp->isp_osinfo.lock, "isp", NULL, MTX_DEF); 284 locksetup++; 285 286 sbs->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sbs->iqd, 287 RF_ACTIVE | RF_SHAREABLE); 288 if (sbs->irq == NULL) { 289 device_printf(dev, "could not allocate interrupt\n"); 290 goto bad; 291 } 292 293 if (isp_setup_intr(dev, sbs->irq, ISP_IFLAGS, NULL, isp_platform_intr, 294 isp, &sbs->ih)) { 295 device_printf(dev, "could not setup interrupt\n"); 296 goto bad; 297 } 298 ints_setup++; 299 300 /* 301 * Set up logging levels. 302 */ 303 if (isp_debug) { 304 isp->isp_dblev = isp_debug; 305 } else { 306 isp->isp_dblev = ISP_LOGWARN|ISP_LOGERR; 307 } 308 if (bootverbose) { 309 isp->isp_dblev |= ISP_LOGCONFIG|ISP_LOGINFO; 310 } 311 312 /* 313 * Make sure we're in reset state. 314 */ 315 ISP_LOCK(isp); 316 isp_reset(isp, 1); 317 if (isp->isp_state != ISP_RESETSTATE) { 318 isp_uninit(isp); 319 ISP_UNLOCK(isp); 320 goto bad; 321 } 322 isp_init(isp); 323 if (isp->isp_state == ISP_INITSTATE) { 324 isp->isp_state = ISP_RUNSTATE; 325 } 326 ISP_UNLOCK(isp); 327 if (isp_attach(isp)) { 328 ISP_LOCK(isp); 329 isp_uninit(isp); 330 ISP_UNLOCK(isp); 331 goto bad; 332 } 333 return (0); 334 335bad: 336 337 if (sbs && ints_setup) { 338 (void) bus_teardown_intr(dev, sbs->irq, sbs->ih); 339 } 340 341 if (sbs && sbs->irq) { 342 bus_release_resource(dev, SYS_RES_IRQ, sbs->iqd, sbs->irq); 343 } 344 345 if (locksetup && isp) { 346 mtx_destroy(&isp->isp_osinfo.lock); 347 } 348 349 if (sbs->regs) { 350 (void) bus_release_resource(dev, SYS_RES_MEMORY, sbs->rgd, 351 sbs->regs); 352 } 353 return (ENXIO); 354} 355 356static int 357isp_sbus_detach(device_t dev) 358{ 359 struct isp_sbussoftc *sbs; 360 ispsoftc_t *isp; 361 int status; 362 363 sbs = device_get_softc(dev); 364 if (sbs == NULL) { 365 return (ENXIO); 366 } 367 isp = (ispsoftc_t *) sbs; 368 status = isp_detach(isp); 369 if (status) 370 return (status); 371 ISP_LOCK(isp); 372 isp_uninit(isp); 373 if (sbs->ih) { 374 (void) bus_teardown_intr(dev, sbs->irq, sbs->ih); 375 } 376 ISP_UNLOCK(isp); 377 mtx_destroy(&isp->isp_osinfo.lock); 378 (void) bus_release_resource(dev, SYS_RES_IRQ, sbs->iqd, sbs->irq); 379 (void) bus_release_resource(dev, SYS_RES_MEMORY, sbs->rgd, sbs->regs); 380 return (0); 381} 382 383#define IspVirt2Off(a, x) \ 384 (((struct isp_sbussoftc *)a)->sbus_poff[((x) & _BLK_REG_MASK) >> \ 385 _BLK_REG_SHFT] + ((x) & 0xff)) 386 387#define BXR2(sbc, off) \ 388 bus_space_read_2(isp->isp_bus_tag, isp->isp_bus_handle, off) 389 390static int
|
391isp_sbus_rd_isr(ispsoftc_t *isp, uint32_t *isrp, uint16_t *semap, uint16_t *mbp)
| 391isp_sbus_rd_isr(ispsoftc_t *isp, uint16_t *isrp, uint16_t *semap, uint16_t *info)
|
392{ 393 uint16_t isr, sema; 394 395 isr = BXR2(sbc, IspVirt2Off(isp, BIU_ISR)); 396 sema = BXR2(sbc, IspVirt2Off(isp, BIU_SEMA)); 397 isp_prt(isp, ISP_LOGDEBUG3, "ISR 0x%x SEMA 0x%x", isr, sema); 398 isr &= INT_PENDING_MASK(isp); 399 sema &= BIU_SEMA_LOCK; 400 if (isr == 0 && sema == 0) { 401 return (0); 402 } 403 *isrp = isr;
| 392{ 393 uint16_t isr, sema; 394 395 isr = BXR2(sbc, IspVirt2Off(isp, BIU_ISR)); 396 sema = BXR2(sbc, IspVirt2Off(isp, BIU_SEMA)); 397 isp_prt(isp, ISP_LOGDEBUG3, "ISR 0x%x SEMA 0x%x", isr, sema); 398 isr &= INT_PENDING_MASK(isp); 399 sema &= BIU_SEMA_LOCK; 400 if (isr == 0 && sema == 0) { 401 return (0); 402 } 403 *isrp = isr;
|
404 if ((*semap = sema) != 0) { 405 *mbp = BXR2(sbc, IspVirt2Off(isp, OUTMAILBOX0)); 406 }
| 404 if ((*semap = sema) != 0) 405 *info = BXR2(sbc, IspVirt2Off(isp, OUTMAILBOX0));
|
407 return (1); 408} 409 410static uint32_t 411isp_sbus_rd_reg(ispsoftc_t *isp, int regoff) 412{ 413 uint16_t rval; 414 struct isp_sbussoftc *sbs = (struct isp_sbussoftc *) isp; 415 int offset = sbs->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT]; 416 offset += (regoff & 0xff); 417 rval = bus_space_read_2(isp->isp_bus_tag, isp->isp_bus_handle, offset); 418 isp_prt(isp, ISP_LOGDEBUG3, 419 "isp_sbus_rd_reg(off %x) = %x", regoff, rval); 420 return (rval); 421} 422 423static void 424isp_sbus_wr_reg(ispsoftc_t *isp, int regoff, uint32_t val) 425{ 426 struct isp_sbussoftc *sbs = (struct isp_sbussoftc *) isp; 427 int offset = sbs->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT]; 428 offset += (regoff & 0xff); 429 isp_prt(isp, ISP_LOGDEBUG3, 430 "isp_sbus_wr_reg(off %x) = %x", regoff, val); 431 bus_space_write_2(isp->isp_bus_tag, isp->isp_bus_handle, offset, val); 432 MEMORYBARRIER(isp, SYNC_REG, offset, 2, -1); 433} 434 435struct imush { 436 ispsoftc_t *isp; 437 int error; 438}; 439 440static void imc(void *, bus_dma_segment_t *, int, int); 441 442static void 443imc(void *arg, bus_dma_segment_t *segs, int nseg, int error) 444{ 445 struct imush *imushp = (struct imush *) arg; 446 if (error) { 447 imushp->error = error; 448 } else { 449 ispsoftc_t *isp =imushp->isp; 450 bus_addr_t addr = segs->ds_addr; 451 452 isp->isp_rquest_dma = addr; 453 addr += ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); 454 isp->isp_result_dma = addr; 455 } 456} 457 458static int 459isp_sbus_mbxdma(ispsoftc_t *isp) 460{ 461 caddr_t base; 462 uint32_t len; 463 int i, error; 464 struct imush im; 465 466 /* 467 * Already been here? If so, leave... 468 */ 469 if (isp->isp_rquest) { 470 return (0); 471 } 472 473 ISP_UNLOCK(isp); 474 475 len = sizeof (struct isp_pcmd) * isp->isp_maxcmds; 476 isp->isp_osinfo.pcmd_pool = (struct isp_pcmd *) 477 malloc(len, M_DEVBUF, M_WAITOK | M_ZERO); 478 if (isp->isp_osinfo.pcmd_pool == NULL) { 479 isp_prt(isp, ISP_LOGERR, "cannot alloc pcmd pool"); 480 ISP_LOCK(isp); 481 return (1); 482 } 483 484 len = sizeof (isp_hdl_t *) * isp->isp_maxcmds; 485 isp->isp_xflist = (isp_hdl_t *) malloc(len, M_DEVBUF, M_WAITOK | M_ZERO); 486 if (isp->isp_xflist == NULL) { 487 isp_prt(isp, ISP_LOGERR, "cannot alloc xflist array"); 488 ISP_LOCK(isp); 489 return (1); 490 } 491 for (len = 0; len < isp->isp_maxcmds - 1; len++) { 492 isp->isp_xflist[len].cmd = &isp->isp_xflist[len+1]; 493 } 494 isp->isp_xffree = isp->isp_xflist; 495 len = sizeof (bus_dmamap_t) * isp->isp_maxcmds; 496 497 if (isp_dma_tag_create(BUS_DMA_ROOTARG(ISP_SBD(isp)), 1, 498 BUS_SPACE_MAXADDR_24BIT+1, BUS_SPACE_MAXADDR_32BIT, 499 BUS_SPACE_MAXADDR_32BIT, NULL, NULL, BUS_SPACE_MAXSIZE_32BIT, 500 ISP_NSEG_MAX, BUS_SPACE_MAXADDR_24BIT, 0, &isp->isp_osinfo.dmat)) { 501 isp_prt(isp, ISP_LOGERR, "could not create master dma tag"); 502 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 503 free(isp->isp_xflist, M_DEVBUF); 504 ISP_LOCK(isp); 505 return(1); 506 } 507 508 /* 509 * Allocate and map the request, result queues, plus FC scratch area. 510 */ 511 len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); 512 len += ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)); 513 514 if (isp_dma_tag_create(isp->isp_osinfo.dmat, QENTRY_LEN, 515 BUS_SPACE_MAXADDR_24BIT+1, BUS_SPACE_MAXADDR_32BIT, 516 BUS_SPACE_MAXADDR_32BIT, NULL, NULL, len, 1, 517 BUS_SPACE_MAXADDR_24BIT, 0, &isp->isp_osinfo.cdmat)) { 518 isp_prt(isp, ISP_LOGERR, 519 "cannot create a dma tag for control spaces"); 520 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 521 free(isp->isp_xflist, M_DEVBUF); 522 ISP_LOCK(isp); 523 return (1); 524 } 525 526 if (bus_dmamem_alloc(isp->isp_osinfo.cdmat, (void **)&base, BUS_DMA_NOWAIT | BUS_DMA_COHERENT, 527 &isp->isp_osinfo.cdmap) != 0) { 528 isp_prt(isp, ISP_LOGERR, 529 "cannot allocate %d bytes of CCB memory", len); 530 bus_dma_tag_destroy(isp->isp_osinfo.cdmat); 531 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 532 free(isp->isp_xflist, M_DEVBUF); 533 ISP_LOCK(isp); 534 return (1); 535 } 536 537 for (i = 0; i < isp->isp_maxcmds; i++) { 538 struct isp_pcmd *pcmd = &isp->isp_osinfo.pcmd_pool[i]; 539 error = bus_dmamap_create(isp->isp_osinfo.dmat, 0, &pcmd->dmap); 540 if (error) { 541 isp_prt(isp, ISP_LOGERR, 542 "error %d creating per-cmd DMA maps", error); 543 while (--i >= 0) { 544 bus_dmamap_destroy(isp->isp_osinfo.dmat, 545 isp->isp_osinfo.pcmd_pool[i].dmap); 546 } 547 goto bad; 548 } 549 callout_init_mtx(&pcmd->wdog, &isp->isp_osinfo.lock, 0); 550 if (i == isp->isp_maxcmds-1) { 551 pcmd->next = NULL; 552 } else { 553 pcmd->next = &isp->isp_osinfo.pcmd_pool[i+1]; 554 } 555 } 556 isp->isp_osinfo.pcmd_free = &isp->isp_osinfo.pcmd_pool[0]; 557 558 im.isp = isp; 559 im.error = 0; 560 bus_dmamap_load(isp->isp_osinfo.cdmat, isp->isp_osinfo.cdmap, base, len, imc, &im, 0); 561 if (im.error) { 562 isp_prt(isp, ISP_LOGERR, 563 "error %d loading dma map for control areas", im.error); 564 goto bad; 565 } 566 567 isp->isp_rquest = base; 568 base += ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); 569 isp->isp_result = base; 570 ISP_LOCK(isp); 571 return (0); 572 573bad: 574 bus_dmamem_free(isp->isp_osinfo.cdmat, base, isp->isp_osinfo.cdmap); 575 bus_dma_tag_destroy(isp->isp_osinfo.cdmat); 576 free(isp->isp_xflist, M_DEVBUF); 577 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 578 isp->isp_rquest = NULL; 579 ISP_LOCK(isp); 580 return (1); 581} 582 583typedef struct { 584 ispsoftc_t *isp; 585 void *cmd_token; 586 void *rq; /* original request */ 587 int error; 588 bus_size_t mapsize; 589} mush_t; 590 591#define MUSHERR_NOQENTRIES -2 592 593static void dma2(void *, bus_dma_segment_t *, int, int); 594 595static void 596dma2(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error) 597{ 598 mush_t *mp; 599 ispsoftc_t *isp; 600 struct ccb_scsiio *csio; 601 isp_ddir_t ddir; 602 ispreq_t *rq; 603 604 mp = (mush_t *) arg; 605 if (error) { 606 mp->error = error; 607 return; 608 } 609 csio = mp->cmd_token; 610 isp = mp->isp; 611 rq = mp->rq; 612 if (nseg) { 613 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 614 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREREAD); 615 ddir = ISP_FROM_DEVICE; 616 } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) { 617 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREWRITE); 618 ddir = ISP_TO_DEVICE; 619 } else { 620 ddir = ISP_NOXFR; 621 } 622 } else { 623 dm_segs = NULL; 624 nseg = 0; 625 ddir = ISP_NOXFR; 626 } 627 628 if (isp_send_cmd(isp, rq, dm_segs, nseg, XS_XFRLEN(csio), ddir, NULL) != CMD_QUEUED) { 629 mp->error = MUSHERR_NOQENTRIES; 630 } 631} 632 633static int 634isp_sbus_dmasetup(ispsoftc_t *isp, struct ccb_scsiio *csio, void *ff) 635{ 636 mush_t mush, *mp; 637 void (*eptr)(void *, bus_dma_segment_t *, int, int); 638 int error; 639 640 mp = &mush; 641 mp->isp = isp; 642 mp->cmd_token = csio; 643 mp->rq = ff; 644 mp->error = 0; 645 mp->mapsize = 0; 646 647 eptr = dma2; 648 649 error = bus_dmamap_load_ccb(isp->isp_osinfo.dmat, 650 PISP_PCMD(csio)->dmap, (union ccb *)csio, eptr, mp, 0); 651 if (error == EINPROGRESS) { 652 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap); 653 mp->error = EINVAL; 654 isp_prt(isp, ISP_LOGERR, 655 "deferred dma allocation not supported"); 656 } else if (error && mp->error == 0) { 657#ifdef DIAGNOSTIC 658 isp_prt(isp, ISP_LOGERR, "error %d in dma mapping code", error); 659#endif 660 mp->error = error; 661 } 662 if (mp->error) { 663 int retval = CMD_COMPLETE; 664 if (mp->error == MUSHERR_NOQENTRIES) { 665 retval = CMD_EAGAIN; 666 } else if (mp->error == EFBIG) { 667 XS_SETERR(csio, CAM_REQ_TOO_BIG); 668 } else if (mp->error == EINVAL) { 669 XS_SETERR(csio, CAM_REQ_INVALID); 670 } else { 671 XS_SETERR(csio, CAM_UNREC_HBA_ERROR); 672 } 673 return (retval); 674 } 675 return (CMD_QUEUED); 676} 677 678static void 679isp_sbus_reset0(ispsoftc_t *isp) 680{ 681 ISP_DISABLE_INTS(isp); 682} 683 684static void 685isp_sbus_reset1(ispsoftc_t *isp) 686{ 687 ISP_ENABLE_INTS(isp); 688} 689 690static void 691isp_sbus_dumpregs(ispsoftc_t *isp, const char *msg) 692{ 693 if (msg) 694 printf("%s: %s\n", device_get_nameunit(isp->isp_dev), msg); 695 else 696 printf("%s:\n", device_get_nameunit(isp->isp_dev)); 697 printf(" biu_conf1=%x", ISP_READ(isp, BIU_CONF1)); 698 printf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp, BIU_ICR), 699 ISP_READ(isp, BIU_ISR), ISP_READ(isp, BIU_SEMA)); 700 printf("risc_hccr=%x\n", ISP_READ(isp, HCCR)); 701 702 703 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE); 704 printf(" cdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n", 705 ISP_READ(isp, CDMA_CONF), ISP_READ(isp, CDMA_STATUS), 706 ISP_READ(isp, CDMA_FIFO_STS)); 707 printf(" ddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n", 708 ISP_READ(isp, DDMA_CONF), ISP_READ(isp, DDMA_STATUS), 709 ISP_READ(isp, DDMA_FIFO_STS)); 710 printf(" sxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n", 711 ISP_READ(isp, SXP_INTERRUPT), 712 ISP_READ(isp, SXP_GROSS_ERR), 713 ISP_READ(isp, SXP_PINS_CTRL)); 714 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); 715 printf(" mbox regs: %x %x %x %x %x\n", 716 ISP_READ(isp, OUTMAILBOX0), ISP_READ(isp, OUTMAILBOX1), 717 ISP_READ(isp, OUTMAILBOX2), ISP_READ(isp, OUTMAILBOX3), 718 ISP_READ(isp, OUTMAILBOX4)); 719}
| 406 return (1); 407} 408 409static uint32_t 410isp_sbus_rd_reg(ispsoftc_t *isp, int regoff) 411{ 412 uint16_t rval; 413 struct isp_sbussoftc *sbs = (struct isp_sbussoftc *) isp; 414 int offset = sbs->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT]; 415 offset += (regoff & 0xff); 416 rval = bus_space_read_2(isp->isp_bus_tag, isp->isp_bus_handle, offset); 417 isp_prt(isp, ISP_LOGDEBUG3, 418 "isp_sbus_rd_reg(off %x) = %x", regoff, rval); 419 return (rval); 420} 421 422static void 423isp_sbus_wr_reg(ispsoftc_t *isp, int regoff, uint32_t val) 424{ 425 struct isp_sbussoftc *sbs = (struct isp_sbussoftc *) isp; 426 int offset = sbs->sbus_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT]; 427 offset += (regoff & 0xff); 428 isp_prt(isp, ISP_LOGDEBUG3, 429 "isp_sbus_wr_reg(off %x) = %x", regoff, val); 430 bus_space_write_2(isp->isp_bus_tag, isp->isp_bus_handle, offset, val); 431 MEMORYBARRIER(isp, SYNC_REG, offset, 2, -1); 432} 433 434struct imush { 435 ispsoftc_t *isp; 436 int error; 437}; 438 439static void imc(void *, bus_dma_segment_t *, int, int); 440 441static void 442imc(void *arg, bus_dma_segment_t *segs, int nseg, int error) 443{ 444 struct imush *imushp = (struct imush *) arg; 445 if (error) { 446 imushp->error = error; 447 } else { 448 ispsoftc_t *isp =imushp->isp; 449 bus_addr_t addr = segs->ds_addr; 450 451 isp->isp_rquest_dma = addr; 452 addr += ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); 453 isp->isp_result_dma = addr; 454 } 455} 456 457static int 458isp_sbus_mbxdma(ispsoftc_t *isp) 459{ 460 caddr_t base; 461 uint32_t len; 462 int i, error; 463 struct imush im; 464 465 /* 466 * Already been here? If so, leave... 467 */ 468 if (isp->isp_rquest) { 469 return (0); 470 } 471 472 ISP_UNLOCK(isp); 473 474 len = sizeof (struct isp_pcmd) * isp->isp_maxcmds; 475 isp->isp_osinfo.pcmd_pool = (struct isp_pcmd *) 476 malloc(len, M_DEVBUF, M_WAITOK | M_ZERO); 477 if (isp->isp_osinfo.pcmd_pool == NULL) { 478 isp_prt(isp, ISP_LOGERR, "cannot alloc pcmd pool"); 479 ISP_LOCK(isp); 480 return (1); 481 } 482 483 len = sizeof (isp_hdl_t *) * isp->isp_maxcmds; 484 isp->isp_xflist = (isp_hdl_t *) malloc(len, M_DEVBUF, M_WAITOK | M_ZERO); 485 if (isp->isp_xflist == NULL) { 486 isp_prt(isp, ISP_LOGERR, "cannot alloc xflist array"); 487 ISP_LOCK(isp); 488 return (1); 489 } 490 for (len = 0; len < isp->isp_maxcmds - 1; len++) { 491 isp->isp_xflist[len].cmd = &isp->isp_xflist[len+1]; 492 } 493 isp->isp_xffree = isp->isp_xflist; 494 len = sizeof (bus_dmamap_t) * isp->isp_maxcmds; 495 496 if (isp_dma_tag_create(BUS_DMA_ROOTARG(ISP_SBD(isp)), 1, 497 BUS_SPACE_MAXADDR_24BIT+1, BUS_SPACE_MAXADDR_32BIT, 498 BUS_SPACE_MAXADDR_32BIT, NULL, NULL, BUS_SPACE_MAXSIZE_32BIT, 499 ISP_NSEG_MAX, BUS_SPACE_MAXADDR_24BIT, 0, &isp->isp_osinfo.dmat)) { 500 isp_prt(isp, ISP_LOGERR, "could not create master dma tag"); 501 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 502 free(isp->isp_xflist, M_DEVBUF); 503 ISP_LOCK(isp); 504 return(1); 505 } 506 507 /* 508 * Allocate and map the request, result queues, plus FC scratch area. 509 */ 510 len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); 511 len += ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)); 512 513 if (isp_dma_tag_create(isp->isp_osinfo.dmat, QENTRY_LEN, 514 BUS_SPACE_MAXADDR_24BIT+1, BUS_SPACE_MAXADDR_32BIT, 515 BUS_SPACE_MAXADDR_32BIT, NULL, NULL, len, 1, 516 BUS_SPACE_MAXADDR_24BIT, 0, &isp->isp_osinfo.cdmat)) { 517 isp_prt(isp, ISP_LOGERR, 518 "cannot create a dma tag for control spaces"); 519 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 520 free(isp->isp_xflist, M_DEVBUF); 521 ISP_LOCK(isp); 522 return (1); 523 } 524 525 if (bus_dmamem_alloc(isp->isp_osinfo.cdmat, (void **)&base, BUS_DMA_NOWAIT | BUS_DMA_COHERENT, 526 &isp->isp_osinfo.cdmap) != 0) { 527 isp_prt(isp, ISP_LOGERR, 528 "cannot allocate %d bytes of CCB memory", len); 529 bus_dma_tag_destroy(isp->isp_osinfo.cdmat); 530 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 531 free(isp->isp_xflist, M_DEVBUF); 532 ISP_LOCK(isp); 533 return (1); 534 } 535 536 for (i = 0; i < isp->isp_maxcmds; i++) { 537 struct isp_pcmd *pcmd = &isp->isp_osinfo.pcmd_pool[i]; 538 error = bus_dmamap_create(isp->isp_osinfo.dmat, 0, &pcmd->dmap); 539 if (error) { 540 isp_prt(isp, ISP_LOGERR, 541 "error %d creating per-cmd DMA maps", error); 542 while (--i >= 0) { 543 bus_dmamap_destroy(isp->isp_osinfo.dmat, 544 isp->isp_osinfo.pcmd_pool[i].dmap); 545 } 546 goto bad; 547 } 548 callout_init_mtx(&pcmd->wdog, &isp->isp_osinfo.lock, 0); 549 if (i == isp->isp_maxcmds-1) { 550 pcmd->next = NULL; 551 } else { 552 pcmd->next = &isp->isp_osinfo.pcmd_pool[i+1]; 553 } 554 } 555 isp->isp_osinfo.pcmd_free = &isp->isp_osinfo.pcmd_pool[0]; 556 557 im.isp = isp; 558 im.error = 0; 559 bus_dmamap_load(isp->isp_osinfo.cdmat, isp->isp_osinfo.cdmap, base, len, imc, &im, 0); 560 if (im.error) { 561 isp_prt(isp, ISP_LOGERR, 562 "error %d loading dma map for control areas", im.error); 563 goto bad; 564 } 565 566 isp->isp_rquest = base; 567 base += ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); 568 isp->isp_result = base; 569 ISP_LOCK(isp); 570 return (0); 571 572bad: 573 bus_dmamem_free(isp->isp_osinfo.cdmat, base, isp->isp_osinfo.cdmap); 574 bus_dma_tag_destroy(isp->isp_osinfo.cdmat); 575 free(isp->isp_xflist, M_DEVBUF); 576 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF); 577 isp->isp_rquest = NULL; 578 ISP_LOCK(isp); 579 return (1); 580} 581 582typedef struct { 583 ispsoftc_t *isp; 584 void *cmd_token; 585 void *rq; /* original request */ 586 int error; 587 bus_size_t mapsize; 588} mush_t; 589 590#define MUSHERR_NOQENTRIES -2 591 592static void dma2(void *, bus_dma_segment_t *, int, int); 593 594static void 595dma2(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error) 596{ 597 mush_t *mp; 598 ispsoftc_t *isp; 599 struct ccb_scsiio *csio; 600 isp_ddir_t ddir; 601 ispreq_t *rq; 602 603 mp = (mush_t *) arg; 604 if (error) { 605 mp->error = error; 606 return; 607 } 608 csio = mp->cmd_token; 609 isp = mp->isp; 610 rq = mp->rq; 611 if (nseg) { 612 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 613 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREREAD); 614 ddir = ISP_FROM_DEVICE; 615 } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) { 616 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREWRITE); 617 ddir = ISP_TO_DEVICE; 618 } else { 619 ddir = ISP_NOXFR; 620 } 621 } else { 622 dm_segs = NULL; 623 nseg = 0; 624 ddir = ISP_NOXFR; 625 } 626 627 if (isp_send_cmd(isp, rq, dm_segs, nseg, XS_XFRLEN(csio), ddir, NULL) != CMD_QUEUED) { 628 mp->error = MUSHERR_NOQENTRIES; 629 } 630} 631 632static int 633isp_sbus_dmasetup(ispsoftc_t *isp, struct ccb_scsiio *csio, void *ff) 634{ 635 mush_t mush, *mp; 636 void (*eptr)(void *, bus_dma_segment_t *, int, int); 637 int error; 638 639 mp = &mush; 640 mp->isp = isp; 641 mp->cmd_token = csio; 642 mp->rq = ff; 643 mp->error = 0; 644 mp->mapsize = 0; 645 646 eptr = dma2; 647 648 error = bus_dmamap_load_ccb(isp->isp_osinfo.dmat, 649 PISP_PCMD(csio)->dmap, (union ccb *)csio, eptr, mp, 0); 650 if (error == EINPROGRESS) { 651 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap); 652 mp->error = EINVAL; 653 isp_prt(isp, ISP_LOGERR, 654 "deferred dma allocation not supported"); 655 } else if (error && mp->error == 0) { 656#ifdef DIAGNOSTIC 657 isp_prt(isp, ISP_LOGERR, "error %d in dma mapping code", error); 658#endif 659 mp->error = error; 660 } 661 if (mp->error) { 662 int retval = CMD_COMPLETE; 663 if (mp->error == MUSHERR_NOQENTRIES) { 664 retval = CMD_EAGAIN; 665 } else if (mp->error == EFBIG) { 666 XS_SETERR(csio, CAM_REQ_TOO_BIG); 667 } else if (mp->error == EINVAL) { 668 XS_SETERR(csio, CAM_REQ_INVALID); 669 } else { 670 XS_SETERR(csio, CAM_UNREC_HBA_ERROR); 671 } 672 return (retval); 673 } 674 return (CMD_QUEUED); 675} 676 677static void 678isp_sbus_reset0(ispsoftc_t *isp) 679{ 680 ISP_DISABLE_INTS(isp); 681} 682 683static void 684isp_sbus_reset1(ispsoftc_t *isp) 685{ 686 ISP_ENABLE_INTS(isp); 687} 688 689static void 690isp_sbus_dumpregs(ispsoftc_t *isp, const char *msg) 691{ 692 if (msg) 693 printf("%s: %s\n", device_get_nameunit(isp->isp_dev), msg); 694 else 695 printf("%s:\n", device_get_nameunit(isp->isp_dev)); 696 printf(" biu_conf1=%x", ISP_READ(isp, BIU_CONF1)); 697 printf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp, BIU_ICR), 698 ISP_READ(isp, BIU_ISR), ISP_READ(isp, BIU_SEMA)); 699 printf("risc_hccr=%x\n", ISP_READ(isp, HCCR)); 700 701 702 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE); 703 printf(" cdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n", 704 ISP_READ(isp, CDMA_CONF), ISP_READ(isp, CDMA_STATUS), 705 ISP_READ(isp, CDMA_FIFO_STS)); 706 printf(" ddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n", 707 ISP_READ(isp, DDMA_CONF), ISP_READ(isp, DDMA_STATUS), 708 ISP_READ(isp, DDMA_FIFO_STS)); 709 printf(" sxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n", 710 ISP_READ(isp, SXP_INTERRUPT), 711 ISP_READ(isp, SXP_GROSS_ERR), 712 ISP_READ(isp, SXP_PINS_CTRL)); 713 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); 714 printf(" mbox regs: %x %x %x %x %x\n", 715 ISP_READ(isp, OUTMAILBOX0), ISP_READ(isp, OUTMAILBOX1), 716 ISP_READ(isp, OUTMAILBOX2), ISP_READ(isp, OUTMAILBOX3), 717 ISP_READ(isp, OUTMAILBOX4)); 718}
|