if_lc_isa.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* $OpenBSD: if_lc_isa.c,v 1.11 2014/08/11 12:45:45 mpi Exp $ */
  2. /* $NetBSD: if_lc_isa.c,v 1.10 2001/06/13 10:46:03 wiz Exp $ */
  3. /*-
  4. * Copyright (c) 1994, 1995, 1997 Matt Thomas <matt@3am-software.com>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. The name of the author may not be used to endorse or promote products
  13. * derived from this software without specific prior written permission
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /*
  27. * DEC EtherWORKS 3 Ethernet Controllers
  28. *
  29. * Written by Matt Thomas
  30. *
  31. * This driver supports the LEMAC (DE203, DE204, and DE205) cards.
  32. */
  33. #include "bpfilter.h"
  34. #include <sys/param.h>
  35. #include <sys/systm.h>
  36. #include <sys/mbuf.h>
  37. #include <sys/socket.h>
  38. #include <sys/ioctl.h>
  39. #include <sys/errno.h>
  40. #include <sys/syslog.h>
  41. #include <sys/selinfo.h>
  42. #include <sys/device.h>
  43. #include <sys/queue.h>
  44. #include <net/if.h>
  45. #include <net/if_dl.h>
  46. #include <net/if_media.h>
  47. #include <netinet/in.h>
  48. #include <netinet/if_ether.h>
  49. #if NBPFILTER > 0
  50. #include <net/bpf.h>
  51. #endif
  52. #include <machine/cpu.h>
  53. #include <machine/bus.h>
  54. #include <machine/intr.h>
  55. #include <dev/ic/lemacreg.h>
  56. #include <dev/ic/lemacvar.h>
  57. #include <dev/isa/isavar.h>
  58. extern struct cfdriver lc_cd;
  59. int lemac_isa_find(struct lemac_softc *, struct isa_attach_args *,
  60. int);
  61. int lemac_isa_probe(struct device *, void *, void *);
  62. void lemac_isa_attach(struct device *, struct device *, void *);
  63. struct cfattach lc_isa_ca = {
  64. sizeof(struct lemac_softc), lemac_isa_probe, lemac_isa_attach
  65. };
  66. int
  67. lemac_isa_find(sc, ia, attach)
  68. struct lemac_softc *sc;
  69. struct isa_attach_args *ia;
  70. int attach;
  71. {
  72. bus_addr_t maddr;
  73. bus_size_t msize;
  74. int rv = 0, irq;
  75. /*
  76. * Disallow wildcarded i/o addresses.
  77. */
  78. if (ia->ia_iobase == IOBASEUNK)
  79. return 0;
  80. /*
  81. * Make sure this is a valid LEMAC address.
  82. */
  83. if (ia->ia_iobase & (LEMAC_IOSIZE - 1))
  84. return 0;
  85. sc->sc_iot = ia->ia_iot;
  86. /*
  87. * Map the LEMAC's port space for the probe sequence.
  88. */
  89. ia->ia_iosize = LEMAC_IOSIZE;
  90. if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0,
  91. &sc->sc_ioh)) {
  92. if (attach)
  93. printf(": can't map i/o space\n");
  94. return (0);
  95. }
  96. /*
  97. * Read the Ethernet address from the EEPROM.
  98. * It must start with one of the DEC OUIs and pass the
  99. * DEC ethernet checksum test.
  100. */
  101. if (lemac_port_check(sc->sc_iot, sc->sc_ioh) == 0)
  102. goto outio;
  103. /*
  104. * Get information about memory space and attempt to map it.
  105. */
  106. lemac_info_get(sc->sc_iot, sc->sc_ioh, &maddr, &msize, &irq);
  107. if (ia->ia_maddr != maddr && ia->ia_maddr != MADDRUNK)
  108. goto outio;
  109. if (maddr != 0 && msize != 0) {
  110. sc->sc_memt = ia->ia_memt;
  111. if (bus_space_map(ia->ia_memt, maddr, msize, 0,
  112. &sc->sc_memh)) {
  113. if (attach)
  114. printf(": can't map mem space\n");
  115. goto outio;
  116. }
  117. }
  118. /*
  119. * Double-check IRQ configuration.
  120. */
  121. if (ia->ia_irq != irq && ia->ia_irq != IRQUNK)
  122. printf("%s: overriding IRQ %d to %d\n", sc->sc_dv.dv_xname,
  123. ia->ia_irq, irq);
  124. if (attach) {
  125. lemac_ifattach(sc);
  126. sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
  127. IPL_NET, lemac_intr, sc, sc->sc_dv.dv_xname);
  128. }
  129. /*
  130. * I guess we've found one.
  131. */
  132. rv = 1;
  133. ia->ia_maddr = maddr;
  134. ia->ia_msize = msize;
  135. ia->ia_irq = irq;
  136. if (maddr != 0 && msize != 0 && (rv == 0 || !attach))
  137. bus_space_unmap(sc->sc_memt, sc->sc_memh, msize);
  138. outio:
  139. if (rv == 0 || !attach)
  140. bus_space_unmap(sc->sc_iot, sc->sc_ioh, LEMAC_IOSIZE);
  141. return (rv);
  142. }
  143. int
  144. lemac_isa_probe(parent, match, aux)
  145. struct device *parent;
  146. void *match;
  147. void *aux;
  148. {
  149. struct isa_attach_args *ia = aux;
  150. struct cfdata *cf = ((struct device *)match)->dv_cfdata;
  151. struct lemac_softc sc;
  152. snprintf(sc.sc_dv.dv_xname, sizeof sc.sc_dv.dv_xname, "%s%d",
  153. lc_cd.cd_name, cf->cf_unit);
  154. return (lemac_isa_find(&sc, ia, 0));
  155. }
  156. void
  157. lemac_isa_attach(parent, self, aux)
  158. struct device *parent;
  159. struct device *self;
  160. void *aux;
  161. {
  162. struct lemac_softc *sc = (void *)self;
  163. struct isa_attach_args *ia = aux;
  164. lemac_isa_find(sc, ia, 1);
  165. }