if_ne_isapnp.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* $OpenBSD: if_ne_isapnp.c,v 1.15 2014/11/24 02:03:37 brad Exp $ */
  2. /* $NetBSD: if_ne_isapnp.c,v 1.7 1998/07/23 19:30:45 christos Exp $ */
  3. /*-
  4. * Copyright (c) 1997 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
  9. * NASA Ames Research Center and Matt Thomas of the 3am Software Foundry.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  24. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "bpfilter.h"
  33. #include <sys/param.h>
  34. #include <sys/systm.h>
  35. #include <sys/mbuf.h>
  36. #include <sys/socket.h>
  37. #include <sys/ioctl.h>
  38. #include <sys/errno.h>
  39. #include <sys/syslog.h>
  40. #include <sys/selinfo.h>
  41. #include <sys/device.h>
  42. #include <net/if.h>
  43. #include <net/if_dl.h>
  44. #include <net/if_media.h>
  45. #include <netinet/in.h>
  46. #include <netinet/if_ether.h>
  47. #if NBPFILTER > 0
  48. #include <net/bpf.h>
  49. #endif
  50. #include <machine/intr.h>
  51. #include <machine/bus.h>
  52. #include <dev/ic/dp8390reg.h>
  53. #include <dev/ic/dp8390var.h>
  54. #include <dev/ic/ne2000reg.h>
  55. #include <dev/ic/ne2000var.h>
  56. #include <dev/ic/rtl80x9reg.h>
  57. #include <dev/ic/rtl80x9var.h>
  58. #include <dev/isa/isavar.h>
  59. #include <dev/isa/isapnpreg.h>
  60. static int ne_isapnp_match(struct device *, void *, void *);
  61. static void ne_isapnp_attach(struct device *, struct device *, void *);
  62. struct ne_isapnp_softc {
  63. struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
  64. /* ISA-specific goo. */
  65. void *sc_ih; /* interrupt cookie */
  66. };
  67. struct cfattach ne_isapnp_ca = {
  68. sizeof(struct ne_isapnp_softc), ne_isapnp_match, ne_isapnp_attach
  69. };
  70. static int
  71. ne_isapnp_match(struct device *parent, void *match, void *aux)
  72. {
  73. return (1);
  74. }
  75. static void
  76. ne_isapnp_attach(struct device *parent, struct device *self, void *aux)
  77. {
  78. struct ne_isapnp_softc * const isc = (struct ne_isapnp_softc *)self;
  79. struct ne2000_softc * const nsc = &isc->sc_ne2000;
  80. struct dp8390_softc * const dsc = &nsc->sc_dp8390;
  81. struct isa_attach_args * const ipa = aux;
  82. bus_space_tag_t nict;
  83. bus_space_handle_t nich;
  84. bus_space_tag_t asict;
  85. bus_space_handle_t asich;
  86. const char *typestr;
  87. int netype;
  88. nict = ipa->ia_iot;
  89. nich = ipa->ipa_io[0].h;
  90. asict = nict;
  91. if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
  92. NE2000_ASIC_NPORTS, &asich)) {
  93. printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
  94. return;
  95. }
  96. dsc->sc_regt = nict;
  97. dsc->sc_regh = nich;
  98. nsc->sc_asict = asict;
  99. nsc->sc_asich = asich;
  100. /*
  101. * Detect it again, so we can print some information about the
  102. * interface.
  103. */
  104. netype = ne2000_detect(nsc);
  105. switch (netype) {
  106. case NE2000_TYPE_NE1000:
  107. typestr = "NE1000";
  108. break;
  109. case NE2000_TYPE_NE2000:
  110. typestr = "NE2000";
  111. /*
  112. * Check for a Realtek 8019.
  113. */
  114. bus_space_write_1(nict, nich, ED_P0_CR,
  115. ED_CR_PAGE_0 | ED_CR_STP);
  116. if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) ==
  117. RTL0_8019ID0 &&
  118. bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) ==
  119. RTL0_8019ID1) {
  120. typestr = "NE2000 (RTL8019)";
  121. dsc->sc_mediachange = rtl80x9_mediachange;
  122. dsc->sc_mediastatus = rtl80x9_mediastatus;
  123. dsc->init_card = rtl80x9_init_card;
  124. dsc->sc_media_init = rtl80x9_media_init;
  125. }
  126. break;
  127. default:
  128. printf(": where did the card go?!\n");
  129. return;
  130. }
  131. printf(": %s", typestr);
  132. /* This interface is always enabled. */
  133. dsc->sc_enabled = 1;
  134. /*
  135. * Do generic NE2000 attach. This will read the station address
  136. * from the EEPROM.
  137. */
  138. ne2000_attach(nsc, NULL);
  139. /* Establish the interrupt handler. */
  140. isc->sc_ih = isa_intr_establish(ipa->ia_ic, ipa->ipa_irq[0].num,
  141. IST_EDGE, IPL_NET, dp8390_intr, dsc,
  142. dsc->sc_dev.dv_xname);
  143. if (isc->sc_ih == NULL)
  144. printf(": couldn't establish interrupt handler\n");
  145. }