if_le_dec.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* $OpenBSD: if_le_dec.c,v 1.6 2014/12/22 02:28:51 tedu Exp $ */
  2. /* $NetBSD: if_le_dec.c,v 1.12 2001/11/13 12:49:45 lukem Exp $ */
  3. /*-
  4. * Copyright (c) 1997 Jonathan Stone. All rights reserved.
  5. * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
  6. * Copyright (c) 1992, 1993
  7. * The Regents of the University of California. All rights reserved.
  8. *
  9. * This code is derived from software contributed to Berkeley by
  10. * Ralph Campbell and Rick Macklem.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * 3. Neither the name of the University nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. *
  36. * @(#)if_le.c 8.2 (Berkeley) 11/16/93
  37. */
  38. #include <sys/param.h>
  39. #include <sys/systm.h>
  40. #include <sys/mbuf.h>
  41. #include <sys/syslog.h>
  42. #include <sys/socket.h>
  43. #include <sys/device.h>
  44. #include <net/if.h>
  45. #include <net/if_media.h>
  46. #include <netinet/in.h>
  47. #include <netinet/if_ether.h>
  48. #include <dev/ic/lancereg.h>
  49. #include <dev/ic/lancevar.h>
  50. #include <dev/ic/am7990reg.h>
  51. #include <dev/ic/am7990var.h>
  52. #include <dev/tc/if_levar.h>
  53. #include <dev/tc/tcvar.h>
  54. #include <machine/bus.h>
  55. /* access LANCE registers */
  56. void le_dec_writereg(volatile u_short *regptr, u_short val);
  57. #define LERDWR(cntl, src, dst) { (dst) = (src); tc_mb(); }
  58. #define LEWREG(src, dst) le_dec_writereg(&(dst), (src))
  59. void le_dec_wrcsr(struct lance_softc *, u_int16_t, u_int16_t);
  60. u_int16_t le_dec_rdcsr(struct lance_softc *, u_int16_t);
  61. void
  62. dec_le_common_attach(struct am7990_softc *sc, u_char *eap)
  63. {
  64. struct lance_softc *lsc = &sc->lsc;
  65. int i;
  66. lsc->sc_rdcsr = le_dec_rdcsr;
  67. lsc->sc_wrcsr = le_dec_wrcsr;
  68. lsc->sc_hwinit = NULL;
  69. lsc->sc_conf3 = 0;
  70. lsc->sc_addr = 0;
  71. lsc->sc_memsize = 65536;
  72. /*
  73. * Get the ethernet address out of rom
  74. */
  75. for (i = 0; i < sizeof(lsc->sc_arpcom.ac_enaddr); i++) {
  76. lsc->sc_arpcom.ac_enaddr[i] = *eap;
  77. eap += 4;
  78. }
  79. am7990_config(sc);
  80. }
  81. void
  82. le_dec_wrcsr(struct lance_softc *sc, u_int16_t port, u_int16_t val)
  83. {
  84. struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
  85. LEWREG(port, ler1->ler1_rap);
  86. LERDWR(port, val, ler1->ler1_rdp);
  87. }
  88. u_int16_t
  89. le_dec_rdcsr(struct lance_softc *sc, u_int16_t port)
  90. {
  91. struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
  92. u_int16_t val;
  93. LEWREG(port, ler1->ler1_rap);
  94. LERDWR(0, ler1->ler1_rdp, val);
  95. return (val);
  96. }
  97. /*
  98. * Write a lance register port, reading it back to ensure success. This seems
  99. * to be necessary during initialization, since the chip appears to be a bit
  100. * pokey sometimes.
  101. */
  102. void
  103. le_dec_writereg(volatile u_short *regptr, u_short val)
  104. {
  105. int i = 0;
  106. while (*regptr != val) {
  107. *regptr = val;
  108. tc_mb();
  109. if (++i > 10000) {
  110. printf("le: Reg did not settle (to x%x): x%x\n", val,
  111. *regptr);
  112. return;
  113. }
  114. DELAY(100);
  115. }
  116. }
  117. /*
  118. * Routines for accessing the transmit and receive buffers are provided
  119. * by lance.c, because of the LE_NEED_BUF_* macros defined above.
  120. * Unfortunately, CPU addressing of these buffers is done in one of
  121. * 3 ways:
  122. * - contiguous (for the 3max and turbochannel option card)
  123. * - gap2, which means shorts (2 bytes) interspersed with short (2 byte)
  124. * spaces (for the pmax, vax 3400, and ioasic LANCE descriptors)
  125. * - gap16, which means 16bytes interspersed with 16byte spaces
  126. * for buffers which must begin on a 32byte boundary (for 3min, maxine,
  127. * and alpha)
  128. * The buffer offset is the logical byte offset, assuming contiguous storage.
  129. */