if_gem_sbus.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* $OpenBSD: if_gem_sbus.c,v 1.8 2014/08/11 12:45:45 mpi Exp $ */
  2. /* $NetBSD: if_gem_sbus.c,v 1.1 2006/11/24 13:23:32 martin Exp $ */
  3. /*-
  4. * Copyright (c) 2006 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Martin Husemann.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  23. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /*
  32. * SBus front-end for the GEM network driver
  33. */
  34. #include <sys/param.h>
  35. #include <sys/systm.h>
  36. #include <sys/syslog.h>
  37. #include <sys/device.h>
  38. #include <sys/malloc.h>
  39. #include <sys/socket.h>
  40. #include <net/if.h>
  41. #include <net/if_dl.h>
  42. #include <net/if_media.h>
  43. #include <netinet/in.h>
  44. #include <netinet/if_ether.h>
  45. #include <dev/mii/mii.h>
  46. #include <dev/mii/miivar.h>
  47. #include <machine/bus.h>
  48. #include <machine/intr.h>
  49. #include <machine/autoconf.h>
  50. #include <dev/sbus/sbusvar.h>
  51. #include <dev/ic/gemreg.h>
  52. #include <dev/ic/gemvar.h>
  53. #include <dev/ofw/openfirm.h>
  54. struct gem_sbus_softc {
  55. struct gem_softc gsc_gem; /* GEM device */
  56. };
  57. int gemmatch_sbus(struct device *, void *, void *);
  58. void gemattach_sbus(struct device *, struct device *, void *);
  59. struct cfattach gem_sbus_ca = {
  60. sizeof(struct gem_sbus_softc), gemmatch_sbus, gemattach_sbus
  61. };
  62. int
  63. gemmatch_sbus(struct device *parent, void *vcf, void *aux)
  64. {
  65. struct sbus_attach_args *sa = aux;
  66. return (strcmp("network", sa->sa_name) == 0);
  67. }
  68. void
  69. gemattach_sbus(struct device *parent, struct device *self, void *aux)
  70. {
  71. struct sbus_attach_args *sa = aux;
  72. struct gem_sbus_softc *gsc = (void *)self;
  73. struct gem_softc *sc = &gsc->gsc_gem;
  74. /* XXX the following declaration should be elsewhere */
  75. extern void myetheraddr(u_char *);
  76. /* Pass on the bus tags */
  77. sc->sc_bustag = sa->sa_bustag;
  78. sc->sc_dmatag = sa->sa_dmatag;
  79. if (sa->sa_nintr < 1) {
  80. printf(": no interrupt\n");
  81. return;
  82. }
  83. if (sa->sa_nreg < 2) {
  84. printf(": only %d register sets\n", sa->sa_nreg);
  85. return;
  86. }
  87. sc->sc_variant = GEM_SUN_GEM;
  88. /*
  89. * Map two register banks:
  90. *
  91. * bank 0: status, config, reset
  92. * bank 1: various gem parts
  93. *
  94. */
  95. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  96. (bus_addr_t)sa->sa_reg[0].sbr_offset,
  97. (bus_size_t)sa->sa_reg[0].sbr_size, 0, 0,
  98. &sc->sc_h2) != 0) {
  99. printf(": can't map registers\n");
  100. return;
  101. }
  102. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  103. (bus_addr_t)sa->sa_reg[1].sbr_offset,
  104. (bus_size_t)sa->sa_reg[1].sbr_size, 0, 0,
  105. &sc->sc_h1) != 0) {
  106. printf(": can't map registers\n");
  107. return;
  108. }
  109. if (OF_getprop(sa->sa_node, "local-mac-address",
  110. sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN) <= 0)
  111. myetheraddr(sc->sc_arpcom.ac_enaddr);
  112. /*
  113. * SBUS config
  114. */
  115. (void) bus_space_read_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_RESET);
  116. delay(100);
  117. bus_space_write_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_CONFIG,
  118. GEM_SBUS_CFG_BSIZE128|GEM_SBUS_CFG_PARITY|GEM_SBUS_CFG_BMODE64);
  119. /* Establish interrupt handler */
  120. bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0, gem_intr,
  121. sc, self->dv_xname);
  122. gem_config(sc);
  123. }