1/*- 2 * Copyright (c) 2004 Scott Long 3 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 45 unchanged lines hidden (view full) --- 54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 56 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 58 * POSSIBILITY OF SUCH DAMAGE. 59 */ 60 61#include <sys/cdefs.h> |
62__FBSDID("$FreeBSD: head/sys/dev/esp/esp_sbus.c 226947 2011-10-30 21:17:42Z marius $"); |
63 64#include <sys/param.h> 65#include <sys/systm.h> 66#include <sys/bus.h> 67#include <sys/kernel.h> 68#include <sys/lock.h> 69#include <sys/module.h> 70#include <sys/mutex.h> |
71#include <sys/rman.h> |
72 73#include <dev/ofw/ofw_bus.h> 74#include <dev/ofw/openfirm.h> 75#include <machine/bus.h> 76#include <machine/ofw_machdep.h> 77#include <machine/resource.h> |
78 79#include <cam/cam.h> 80#include <cam/cam_ccb.h> 81#include <cam/scsi/scsi_all.h> 82#include <cam/scsi/scsi_message.h> 83 84#include <sparc64/sbus/lsi64854reg.h> 85#include <sparc64/sbus/lsi64854var.h> 86#include <sparc64/sbus/sbusvar.h> 87 88#include <dev/esp/ncr53c9xreg.h> 89#include <dev/esp/ncr53c9xvar.h> 90 91/* #define ESP_SBUS_DEBUG */ 92 93struct esp_softc { 94 struct ncr53c9x_softc sc_ncr53c9x; /* glue to MI code */ |
95 device_t sc_dev; |
96 97 struct resource *sc_res; 98 99 struct resource *sc_irqres; 100 void *sc_irq; 101 102 struct lsi64854_softc *sc_dma; /* pointer to my DMA */ 103}; 104 |
105static int esp_probe(device_t); 106static int esp_dma_attach(device_t); 107static int esp_dma_detach(device_t); 108static int esp_sbus_attach(device_t); 109static int esp_sbus_detach(device_t); 110static int esp_suspend(device_t); 111static int esp_resume(device_t); 112 113static device_method_t esp_dma_methods[] = { 114 DEVMETHOD(device_probe, esp_probe), 115 DEVMETHOD(device_attach, esp_dma_attach), 116 DEVMETHOD(device_detach, esp_dma_detach), 117 DEVMETHOD(device_suspend, esp_suspend), 118 DEVMETHOD(device_resume, esp_resume), |
119 120 KOBJMETHOD_END |
121}; 122 123static driver_t esp_dma_driver = { 124 "esp", 125 esp_dma_methods, 126 sizeof(struct esp_softc) 127}; 128 129DRIVER_MODULE(esp, dma, esp_dma_driver, esp_devclass, 0, 0); 130MODULE_DEPEND(esp, dma, 1, 1, 1); 131 132static device_method_t esp_sbus_methods[] = { 133 DEVMETHOD(device_probe, esp_probe), 134 DEVMETHOD(device_attach, esp_sbus_attach), 135 DEVMETHOD(device_detach, esp_sbus_detach), 136 DEVMETHOD(device_suspend, esp_suspend), 137 DEVMETHOD(device_resume, esp_resume), |
138 139 KOBJMETHOD_END |
140}; 141 142static driver_t esp_sbus_driver = { 143 "esp", 144 esp_sbus_methods, 145 sizeof(struct esp_softc) 146}; 147 --- 22 unchanged lines hidden (view full) --- 170 esp_write_reg, 171 esp_dma_isintr, 172 esp_dma_reset, 173 esp_dma_intr, 174 esp_dma_setup, 175 esp_dma_go, 176 esp_dma_stop, 177 esp_dma_isactive, |
178}; 179 180static int 181esp_probe(device_t dev) 182{ 183 const char *name; 184 185 name = ofw_bus_get_name(dev); --- 53 unchanged lines hidden (view full) --- 239 240 /* Create a parent DMA tag based on this bus. */ 241 error = bus_dma_tag_create( 242 bus_get_dma_tag(dev), /* parent */ 243 1, 0, /* alignment, boundary */ 244 BUS_SPACE_MAXADDR, /* lowaddr */ 245 BUS_SPACE_MAXADDR, /* highaddr */ 246 NULL, NULL, /* filter, filterarg */ |
247 BUS_SPACE_MAXSIZE, /* maxsize */ 248 BUS_SPACE_UNRESTRICTED, /* nsegments */ 249 BUS_SPACE_MAXSIZE, /* maxsegsize */ |
250 0, /* flags */ 251 NULL, NULL, /* no locking */ 252 &lsc->sc_parent_dmat); 253 if (error != 0) { 254 device_printf(dev, "cannot allocate parent DMA tag\n"); 255 goto fail_sbus_lres; 256 } 257 --- 28 unchanged lines hidden (view full) --- 286 */ 287 if (device_get_children(device_get_parent(dev), &children, 288 &nchildren) != 0) { 289 device_printf(dev, "cannot determine siblings\n"); 290 return (ENXIO); 291 } 292 for (i = 0; i < nchildren; i++) { 293 if (device_is_attached(children[i]) && |
294 sbus_get_slot(children[i]) == 295 sbus_get_slot(dev) && 296 strcmp(ofw_bus_get_name(children[i]), 297 "dma") == 0) { |
298 /* XXX hackery */ 299 esc->sc_dma = (struct lsi64854_softc *) 300 device_get_softc(children[i]); 301 break; 302 } 303 } 304 free(children, M_TEMP); 305 if (esc->sc_dma == NULL) { --- 143 unchanged lines hidden (view full) --- 449espattach(struct esp_softc *esc, const struct ncr53c9x_glue *gluep) 450{ 451 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x; 452 unsigned int uid = 0; 453 int error, i; 454 455 NCR_LOCK_INIT(sc); 456 |
457 sc->sc_id = OF_getscsinitid(esc->sc_dev); 458 459#ifdef ESP_SBUS_DEBUG 460 device_printf(esc->sc_dev, "%s: sc_id %d, freq %d\n", 461 __func__, sc->sc_id, sc->sc_freq); 462#endif 463 464 /* --- 40 unchanged lines hidden (view full) --- 505 sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB; 506 NCR_WRITE_REG(sc, NCR_CFG1, sc->sc_cfg1); 507 sc->sc_cfg2 = 0; 508 NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2); 509 sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_RPE; 510 NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2); 511 512 if ((NCR_READ_REG(sc, NCR_CFG2) & ~NCRCFG2_RSVD) != |
513 (NCRCFG2_SCSI2 | NCRCFG2_RPE)) |
514 sc->sc_rev = NCR_VARIANT_ESP100; |
515 else { |
516 sc->sc_cfg2 = NCRCFG2_SCSI2; 517 NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2); 518 sc->sc_cfg3 = 0; 519 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3); 520 sc->sc_cfg3 = (NCRCFG3_CDB | NCRCFG3_FCLK); 521 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3); 522 if (NCR_READ_REG(sc, NCR_CFG3) != |
523 (NCRCFG3_CDB | NCRCFG3_FCLK)) |
524 sc->sc_rev = NCR_VARIANT_ESP100A; |
525 else { |
526 /* NCRCFG2_FE enables > 64K transfers. */ 527 sc->sc_cfg2 |= NCRCFG2_FE; 528 sc->sc_cfg3 = 0; 529 NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3); 530 if (sc->sc_freq <= 25) 531 sc->sc_rev = NCR_VARIANT_ESP200; 532 else { 533 switch ((uid & 0xf8) >> 3) { 534 case 0x00: 535 sc->sc_rev = NCR_VARIANT_FAS100A; 536 break; 537 538 case 0x02: 539 if ((uid & 0x07) == 0x02) |
540 sc->sc_rev = 541 NCR_VARIANT_FAS216; |
542 else |
543 sc->sc_rev = 544 NCR_VARIANT_FAS236; |
545 break; 546 547 case 0x0a: 548 sc->sc_rev = NCR_VARIANT_FAS366; 549 break; 550 551 default: 552 /* 553 * We could just treat unknown chips 554 * as ESP200 but then we would most 555 * likely drive them out of specs. 556 */ 557 device_printf(esc->sc_dev, 558 "Unknown chip\n"); |
559 error = ENXIO; 560 goto fail_lock; |
561 } 562 } 563 } 564 } 565 566#ifdef ESP_SBUS_DEBUG 567 printf("%s: revision %d, uid 0x%x\n", __func__, sc->sc_rev, uid); 568#endif 569 570 /* |
571 * This is the value used to start sync negotiations 572 * Note that the NCR register "SYNCTP" is programmed 573 * in "clocks per byte", and has a minimum value of 4. 574 * The SCSI period used in negotiation is one-fourth 575 * of the time (in nanoseconds) needed to transfer one byte. 576 * Since the chip's clock is given in MHz, we have the following 577 * formula: 4 * period = (1000 / freq) * 4 578 */ 579 sc->sc_minsync = 1000 / sc->sc_freq; 580 |
581 /* 582 * Except for some variants the maximum transfer size is 64k. 583 */ 584 sc->sc_maxxfer = 64 * 1024; |
585 sc->sc_maxoffset = 15; 586 sc->sc_extended_geom = 1; 587 588 /* 589 * Alas, we must now modify the value a bit, because it's |
590 * only valid when we can switch on FASTCLK and FASTSCSI bits 591 * in the config register 3... |
592 */ 593 switch (sc->sc_rev) { 594 case NCR_VARIANT_ESP100: 595 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_8_BIT; |
596 sc->sc_minsync = 0; /* No synch on old chip? */ 597 break; 598 599 case NCR_VARIANT_ESP100A: |
600 case NCR_VARIANT_ESP200: 601 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_8_BIT; |
602 /* Min clocks/byte is 5 */ 603 sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5); 604 break; 605 606 case NCR_VARIANT_FAS100A: 607 case NCR_VARIANT_FAS216: 608 case NCR_VARIANT_FAS236: 609 /* --- 14 unchanged lines hidden (view full) --- 624 break; 625 626 case NCR_VARIANT_FAS366: 627 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_16_BIT; 628 sc->sc_maxxfer = 16 * 1024 * 1024; 629 break; 630 } 631 |
632 /* 633 * Given that we allocate resources based on sc->sc_maxxfer it doesn't 634 * make sense to supply a value higher than the maximum actually used. 635 */ 636 sc->sc_maxxfer = min(sc->sc_maxxfer, MAXPHYS); 637 638 /* Attach the DMA engine. */ 639 error = lsi64854_attach(esc->sc_dma); 640 if (error != 0) { 641 device_printf(esc->sc_dev, "lsi64854_attach failed\n"); 642 goto fail_lock; 643 } 644 |
645 /* Establish interrupt channel. */ 646 i = 0; 647 if ((esc->sc_irqres = bus_alloc_resource_any(esc->sc_dev, SYS_RES_IRQ, 648 &i, RF_SHAREABLE|RF_ACTIVE)) == NULL) { 649 device_printf(esc->sc_dev, "cannot allocate interrupt\n"); 650 goto fail_lsi; 651 } 652 if (bus_setup_intr(esc->sc_dev, esc->sc_irqres, --- 192 unchanged lines hidden --- |