qla_sbus.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* $OpenBSD: qla_sbus.c,v 1.2 2014/07/12 18:48:52 tedu Exp $ */
  2. /*
  3. * Copyright (c) 2014 Mark Kettenis
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <sys/param.h>
  18. #include <sys/device.h>
  19. #include <sys/malloc.h>
  20. #include <sys/systm.h>
  21. #include <machine/bus.h>
  22. #include <machine/intr.h>
  23. #include <machine/autoconf.h>
  24. #include <dev/sbus/sbusvar.h>
  25. #include <dev/pci/pcireg.h>
  26. #include <dev/pci/pcivar.h>
  27. #include <dev/pci/pcidevs.h>
  28. #include <scsi/scsi_all.h>
  29. #include <scsi/scsiconf.h>
  30. #include <dev/ic/qlareg.h>
  31. #include <dev/ic/qlavar.h>
  32. #define QLA_SBUS_REG_OFFSET 0x100
  33. #define QLA_SBUS_REG_SIZE 0x300
  34. int qla_sbus_match(struct device *, void *, void *);
  35. void qla_sbus_attach(struct device *, struct device *, void *);
  36. struct cfattach qla_sbus_ca = {
  37. sizeof(struct qla_softc),
  38. qla_sbus_match,
  39. qla_sbus_attach
  40. };
  41. int
  42. qla_sbus_match(struct device *parent, void *cf, void *aux)
  43. {
  44. struct sbus_attach_args *sa = aux;
  45. if (strcmp("SUNW,qlc", sa->sa_name) == 0 ||
  46. strcmp("QLGC,qla", sa->sa_name) == 0)
  47. return 2;
  48. return 0;
  49. }
  50. void
  51. qla_sbus_attach(struct device *parent, struct device *self, void *aux)
  52. {
  53. struct qla_softc *sc = (void *)self;
  54. struct sbus_attach_args *sa = aux;
  55. struct sparc_bus_space_tag *iot;
  56. bus_space_handle_t ioh;
  57. pcireg_t id, class;
  58. char devinfo[256];
  59. if (sa->sa_nintr < 1) {
  60. printf(": no interrupt\n");
  61. return;
  62. }
  63. if (sa->sa_nreg < 1) {
  64. printf(": no registers\n");
  65. return;
  66. }
  67. /*
  68. * These cards have a standard PCI chips that sit behind an
  69. * FPGA with some bridging logic. Since the PCI bus is
  70. * little-endian, we need a little-endian bus tag. So we
  71. * build one here.
  72. */
  73. iot = malloc(sizeof(*iot), M_DEVBUF, M_NOWAIT);
  74. if (iot == NULL) {
  75. printf(": can't allocate bus tag\n");
  76. return;
  77. }
  78. *iot = *sa->sa_bustag;
  79. iot->asi = ASI_PRIMARY_LITTLE;
  80. if (sbus_bus_map(iot, sa->sa_slot, sa->sa_offset,
  81. sa->sa_size, 0, 0, &ioh) != 0) {
  82. printf(": can't map registers\n");
  83. goto free;
  84. }
  85. /*
  86. * PCI config space is mapped at the start of the SBus
  87. * register space. We use it to identify the ISP chip.
  88. */
  89. id = bus_space_read_4(iot, ioh, PCI_ID_REG);
  90. class = bus_space_read_4(iot, ioh, PCI_CLASS_REG);
  91. pci_devinfo(id, class, 0, devinfo, sizeof(devinfo));
  92. printf(": %s\n", devinfo);
  93. switch (PCI_PRODUCT(id)) {
  94. case PCI_PRODUCT_QLOGIC_ISP2200:
  95. sc->sc_isp_gen = QLA_GEN_ISP2200;
  96. sc->sc_isp_type = QLA_ISP2200;
  97. break;
  98. case PCI_PRODUCT_QLOGIC_ISP2300:
  99. sc->sc_isp_gen = QLA_GEN_ISP23XX;
  100. sc->sc_isp_type = QLA_ISP2300;
  101. break;
  102. case PCI_PRODUCT_QLOGIC_ISP2312:
  103. sc->sc_isp_gen = QLA_GEN_ISP23XX;
  104. sc->sc_isp_type = QLA_ISP2312;
  105. break;
  106. default:
  107. printf("%s: unsupported ISP chip\n", DEVNAME(sc));
  108. goto unmap;
  109. }
  110. if (bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_BIO, 0,
  111. qla_intr, sc, sc->sc_dev.dv_xname) == NULL) {
  112. printf("%s: can't establish interrupt\n", DEVNAME(sc));
  113. goto unmap;
  114. }
  115. if (bus_space_subregion(iot, ioh, QLA_SBUS_REG_OFFSET,
  116. QLA_SBUS_REG_SIZE, &sc->sc_ioh) != 0) {
  117. printf("%s: can't submap registers\n", DEVNAME(sc));
  118. goto unmap;
  119. }
  120. sc->sc_iot = iot;
  121. sc->sc_ios = QLA_SBUS_REG_SIZE;
  122. sc->sc_dmat = sa->sa_dmatag;
  123. qla_attach(sc);
  124. return;
  125. unmap:
  126. bus_space_unmap(iot, ioh, sa->sa_size);
  127. free:
  128. free(iot, M_DEVBUF, 0);
  129. }