elink.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* $OpenBSD: elink.c,v 1.7 2007/06/29 15:17:02 jasper Exp $ */
  2. /* $NetBSD: elink.c,v 1.9 1996/05/03 19:06:27 christos Exp $ */
  3. /*
  4. * Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
  5. * Copyright (c) 1994, 1995 Charles Hannum. 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. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. All advertising materials mentioning features or use of this software
  16. * must display the following acknowledgement:
  17. * This product includes software developed by Charles Hannum.
  18. * 4. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  22. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /*
  33. * Common code for dealing with 3COM ethernet cards.
  34. */
  35. #include <sys/param.h>
  36. #include <sys/systm.h>
  37. #include <sys/malloc.h>
  38. #include <sys/queue.h>
  39. #include <machine/bus.h>
  40. #include <dev/isa/elink.h>
  41. /*
  42. * This list keeps track of which ISAs have gotten an elink_reset().
  43. */
  44. struct elink_done_reset {
  45. LIST_ENTRY(elink_done_reset) er_link;
  46. int er_bus;
  47. };
  48. static LIST_HEAD(, elink_done_reset) elink_all_resets;
  49. static int elink_all_resets_initialized;
  50. /*
  51. * Issue a `global reset' to all cards, and reset the ID state machines. We
  52. * have to be careful to do the global reset only once during autoconfig, to
  53. * prevent resetting boards that have already been configured.
  54. *
  55. * The "bus" argument here is the unit number of the ISA bus, e.g. "0"
  56. * if the bus is "isa0".
  57. *
  58. * NOTE: the caller MUST provide an i/o handle for ELINK_ID_PORT!
  59. */
  60. void
  61. elink_reset(bus_space_tag_t iot, bus_space_handle_t ioh, int bus)
  62. {
  63. struct elink_done_reset *er;
  64. if (elink_all_resets_initialized == 0) {
  65. LIST_INIT(&elink_all_resets);
  66. elink_all_resets_initialized = 1;
  67. }
  68. /*
  69. * Reset these cards if we haven't done so already.
  70. */
  71. LIST_FOREACH(er, &elink_all_resets, er_link)
  72. if (er->er_bus == bus)
  73. goto out;
  74. /* Mark this bus so we don't do it again. */
  75. er = (struct elink_done_reset *)malloc(sizeof(struct elink_done_reset),
  76. M_DEVBUF, M_NOWAIT);
  77. if (er == NULL)
  78. panic("elink_reset: can't allocate state storage");
  79. er->er_bus = bus;
  80. LIST_INSERT_HEAD(&elink_all_resets, er, er_link);
  81. /* Haven't reset the cards on this bus, yet. */
  82. bus_space_write_1(iot, ioh, 0, ELINK_RESET);
  83. out:
  84. bus_space_write_1(iot, ioh, 0, 0x00);
  85. bus_space_write_1(iot, ioh, 0, 0x00);
  86. }
  87. /*
  88. * The `ID sequence' is really just snapshots of an 8-bit CRC register as 0
  89. * bits are shifted in. Different board types use different polynomials.
  90. *
  91. * NOTE: the caller MUST provide an i/o handle for ELINK_ID_PORT!
  92. */
  93. void
  94. elink_idseq(bus_space_tag_t iot, bus_space_handle_t ioh, u_char p)
  95. {
  96. int i;
  97. u_char c;
  98. c = 0xff;
  99. for (i = 255; i; i--) {
  100. bus_space_write_1(iot, ioh, 0, c);
  101. if (c & 0x80) {
  102. c <<= 1;
  103. c ^= p;
  104. } else
  105. c <<= 1;
  106. }
  107. }