if_ti_sbus.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* $OpenBSD: if_ti_sbus.c,v 1.3 2014/08/11 12:45:45 mpi Exp $ */
  2. /*
  3. * Copyright (c) 2009 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/socket.h>
  20. #include <sys/systm.h>
  21. #include <net/if.h>
  22. #include <net/if_dl.h>
  23. #include <net/if_media.h>
  24. #include <netinet/in.h>
  25. #include <netinet/if_ether.h>
  26. #include <machine/bus.h>
  27. #include <machine/intr.h>
  28. #include <machine/autoconf.h>
  29. #include <dev/sbus/sbusvar.h>
  30. #include <dev/pci/pcireg.h>
  31. #include <dev/ic/tireg.h>
  32. #include <dev/ic/tivar.h>
  33. struct ti_sbus_softc {
  34. struct ti_softc tsc_sc;
  35. };
  36. int ti_sbus_match(struct device *, void *, void *);
  37. void ti_sbus_attach(struct device *, struct device *, void *);
  38. struct cfattach ti_sbus_ca = {
  39. sizeof(struct ti_sbus_softc), ti_sbus_match, ti_sbus_attach
  40. };
  41. int
  42. ti_sbus_match(struct device *parent, void *match, void *aux)
  43. {
  44. struct sbus_attach_args *sa = aux;
  45. return (strcmp("SUNW,vge", sa->sa_name) == 0);
  46. }
  47. void
  48. ti_sbus_attach(struct device *parent, struct device *self, void *aux)
  49. {
  50. struct sbus_attach_args *sa = aux;
  51. struct ti_sbus_softc *tsc = (void *)self;
  52. struct ti_softc *sc = &tsc->tsc_sc;
  53. bus_space_handle_t ioh;
  54. /* Pass on the bus tags */
  55. sc->ti_btag = sa->sa_bustag;
  56. sc->sc_dmatag = sa->sa_dmatag;
  57. if (sa->sa_nintr < 1) {
  58. printf(": no interrupt\n");
  59. return;
  60. }
  61. if (sa->sa_nreg < 2) {
  62. printf(": only %d register sets\n", sa->sa_nreg);
  63. return;
  64. }
  65. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[1].sbr_slot,
  66. sa->sa_reg[1].sbr_offset, sa->sa_reg[1].sbr_size,
  67. 0, 0, &sc->ti_bhandle)) {
  68. printf(": can't map registers\n");
  69. return;
  70. }
  71. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  72. sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size,
  73. 0, 0, &ioh)) {
  74. printf(": can't map registers\n");
  75. goto unmap;
  76. }
  77. bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0, ti_intr,
  78. sc, self->dv_xname);
  79. bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_CMDSTAT, 0x02000006);
  80. bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_BIST, 0xffffffff);
  81. bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_LOMEM, 0x00000400);
  82. bus_space_unmap(sa->sa_bustag, ioh, sa->sa_reg[0].sbr_size);
  83. sc->ti_sbus = 1;
  84. if (ti_attach(sc) == 0)
  85. return;
  86. unmap:
  87. bus_space_unmap(sa->sa_bustag, sc->ti_bhandle,
  88. sa->sa_reg[1].sbr_size);
  89. }