qlw_sbus.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* $OpenBSD: qlw_sbus.c,v 1.1 2014/03/15 21:49:47 kettenis 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 <scsi/scsi_all.h>
  26. #include <scsi/scsiconf.h>
  27. #include <dev/ic/qlwreg.h>
  28. #include <dev/ic/qlwvar.h>
  29. #ifndef ISP_NOFIRMWARE
  30. #include <dev/microcode/isp/asm_sbus.h>
  31. #endif
  32. int qlw_sbus_match(struct device *, void *, void *);
  33. void qlw_sbus_attach(struct device *, struct device *, void *);
  34. struct cfattach qlw_sbus_ca = {
  35. sizeof(struct qlw_softc),
  36. qlw_sbus_match,
  37. qlw_sbus_attach
  38. };
  39. int
  40. qlw_sbus_match(struct device *parent, void *cf, void *aux)
  41. {
  42. struct sbus_attach_args *sa = aux;
  43. if (strcmp("ptisp", sa->sa_name) == 0 ||
  44. strcmp("PTI,ptisp", sa->sa_name) == 0 ||
  45. strcmp("SUNW,isp", sa->sa_name) == 0 ||
  46. strcmp("QLGC,isp", sa->sa_name) == 0)
  47. return 2;
  48. return 0;
  49. }
  50. void
  51. qlw_sbus_attach(struct device *parent, struct device *self, void *aux)
  52. {
  53. struct qlw_softc *sc = (void *)self;
  54. struct sbus_attach_args *sa = aux;
  55. u_int32_t sbusburst, burst;
  56. int freq;
  57. if (sa->sa_nintr < 1) {
  58. printf(": no interrupt\n");
  59. return;
  60. }
  61. if (sa->sa_nreg < 1) {
  62. printf(": no registers\n");
  63. return;
  64. }
  65. if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, sa->sa_offset,
  66. sa->sa_size, 0, 0, &sc->sc_ioh) != 0) {
  67. printf(": can't map registers\n");
  68. return;
  69. }
  70. printf(": %s\n", sa->sa_name);
  71. if (bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_BIO, 0,
  72. qlw_intr, sc, sc->sc_dev.dv_xname) == NULL) {
  73. printf("%s: can't establish interrupt\n", DEVNAME(sc));
  74. goto unmap;
  75. }
  76. /*
  77. * Get transfer burst size from PROM
  78. */
  79. sbusburst = ((struct sbus_softc *)parent)->sc_burst;
  80. if (sbusburst == 0)
  81. sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
  82. burst = getpropint(sa->sa_node, "burst-sizes", -1);
  83. if (burst == -1)
  84. burst = sbusburst;
  85. /* Clamp at parent's burst sizes */
  86. burst &= sbusburst;
  87. if ((burst & SBUS_BURST_32))
  88. sc->sc_isp_config = QLW_BURST_ENABLE | QLW_SBUS_FIFO_32;
  89. else if ((burst & SBUS_BURST_16))
  90. sc->sc_isp_config = QLW_BURST_ENABLE | QLW_SBUS_FIFO_16;
  91. else if ((burst & SBUS_BURST_8))
  92. sc->sc_isp_config = QLW_BURST_ENABLE | QLW_SBUS_BURST_8;
  93. sc->sc_iot = sa->sa_bustag;
  94. sc->sc_ios = sa->sa_size;
  95. sc->sc_dmat = sa->sa_dmatag;
  96. sc->sc_isp_gen = QLW_GEN_ISP1000;
  97. sc->sc_isp_type = QLW_ISP1000;
  98. sc->sc_numbusses = 1;
  99. freq = getpropint(sa->sa_node, "clock-frequency", 40000000);
  100. sc->sc_clock = (freq + 500000) / 1000000;
  101. #ifndef ISP_NOFIRMWARE
  102. /*
  103. * Some early versions of the PTI cards don't support loading
  104. * a new firmware, so only do this in the Sun or QLogic
  105. * branded ones.
  106. */
  107. if (strcmp("SUNW,isp", sa->sa_name) == 0 ||
  108. strcmp("QLGC,isp", sa->sa_name) == 0)
  109. sc->sc_firmware = isp_1000_risc_code;
  110. #endif
  111. sc->sc_initiator[0] = getpropint(sa->sa_node, "scsi-initiator-id", 6);
  112. sc->sc_host_cmd_ctrl = QLW_HOST_CMD_CTRL_SBUS;
  113. sc->sc_mbox_base = QLW_MBOX_BASE_SBUS;
  114. qlw_attach(sc);
  115. return;
  116. unmap:
  117. bus_space_unmap(sa->sa_bustag, sc->sc_ioh, sa->sa_size);
  118. }