ether589.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * 3C589 and 3C562.
  3. * To do:
  4. * check xcvr10Base2 still works (is GlobalReset necessary?).
  5. */
  6. #include "u.h"
  7. #include "../port/lib.h"
  8. #include "mem.h"
  9. #include "dat.h"
  10. #include "fns.h"
  11. #include "io.h"
  12. #include "../port/error.h"
  13. #include "../port/netif.h"
  14. #include "etherif.h"
  15. enum { /* all windows */
  16. CommandR = 0x000E,
  17. IntStatusR = 0x000E,
  18. };
  19. enum { /* Commands */
  20. GlobalReset = 0x0000,
  21. SelectRegisterWindow = 0x0001,
  22. RxReset = 0x0005,
  23. TxReset = 0x000B,
  24. AcknowledgeInterrupt = 0x000D,
  25. };
  26. enum { /* IntStatus bits */
  27. commandInProgress = 0x1000,
  28. };
  29. #define COMMAND(port, cmd, a) outs((port)+CommandR, ((cmd)<<11)|(a))
  30. #define STATUS(port) ins((port)+IntStatusR)
  31. enum { /* Window 0 - setup */
  32. Wsetup = 0x0000,
  33. /* registers */
  34. ManufacturerID = 0x0000, /* 3C5[08]*, 3C59[27] */
  35. ProductID = 0x0002, /* 3C5[08]*, 3C59[27] */
  36. ConfigControl = 0x0004, /* 3C5[08]*, 3C59[27] */
  37. AddressConfig = 0x0006, /* 3C5[08]*, 3C59[27] */
  38. ResourceConfig = 0x0008, /* 3C5[08]*, 3C59[27] */
  39. EepromCommand = 0x000A,
  40. EepromData = 0x000C,
  41. /* AddressConfig Bits */
  42. autoSelect9 = 0x0080,
  43. xcvrMask9 = 0xC000,
  44. /* ConfigControl bits */
  45. Ena = 0x0001,
  46. base10TAvailable9 = 0x0200,
  47. coaxAvailable9 = 0x1000,
  48. auiAvailable9 = 0x2000,
  49. /* EepromCommand bits */
  50. EepromReadRegister = 0x0080,
  51. EepromBusy = 0x8000,
  52. };
  53. enum { /* Window 1 - operating set */
  54. Wop = 0x0001,
  55. };
  56. enum { /* Window 3 - FIFO management */
  57. Wfifo = 0x0003,
  58. /* registers */
  59. InternalConfig = 0x0000, /* 3C509B, 3C589, 3C59[0257] */
  60. /* InternalConfig bits */
  61. xcvr10BaseT = 0x00000000,
  62. xcvr10Base2 = 0x00300000,
  63. };
  64. enum { /* Window 4 - diagnostic */
  65. Wdiagnostic = 0x0004,
  66. /* registers */
  67. MediaStatus = 0x000A,
  68. /* MediaStatus bits */
  69. linkBeatDetect = 0x0800,
  70. };
  71. extern int etherelnk3reset(Ether*);
  72. static char *tcmpcmcia[] = {
  73. "3C589", /* 3COM 589[ABCD] */
  74. "3C562", /* 3COM 562 */
  75. "589E", /* 3COM Megahertz 589E */
  76. nil,
  77. };
  78. static int
  79. configASIC(Ether* ether, int port, int xcvr)
  80. {
  81. int x;
  82. /* set Window 0 configuration registers */
  83. COMMAND(port, SelectRegisterWindow, Wsetup);
  84. outs(port+ConfigControl, Ena);
  85. /* IRQ must be 3 on 3C589/3C562 */
  86. outs(port + ResourceConfig, 0x3F00);
  87. x = ins(port+AddressConfig) & ~xcvrMask9;
  88. x |= (xcvr>>20)<<14;
  89. outs(port+AddressConfig, x);
  90. COMMAND(port, TxReset, 0);
  91. while(STATUS(port) & commandInProgress)
  92. ;
  93. COMMAND(port, RxReset, 0);
  94. while(STATUS(port) & commandInProgress)
  95. ;
  96. return etherelnk3reset(ether);
  97. }
  98. static int
  99. reset(Ether* ether)
  100. {
  101. int i, t, slot;
  102. char *type;
  103. int port;
  104. enum { WantAny, Want10BT, Want10B2 };
  105. int want;
  106. uchar ea[6];
  107. char *p;
  108. if(ether->irq == 0)
  109. ether->irq = 10;
  110. if(ether->port == 0)
  111. ether->port = 0x240;
  112. port = ether->port;
  113. if(ioalloc(port, 0x10, 0, "3C589") < 0)
  114. return -1;
  115. type = nil;
  116. slot = -1;
  117. for(i = 0; tcmpcmcia[i] != nil; i++){
  118. type = tcmpcmcia[i];
  119. if((slot = pcmspecial(type, ether)) >= 0)
  120. break;
  121. }
  122. if(slot < 0){
  123. iofree(port);
  124. return -1;
  125. }
  126. /*
  127. * Read Ethernet address from card memory
  128. * on 3C562, but only if the user has not
  129. * overridden it.
  130. */
  131. memset(ea, 0, sizeof ea);
  132. if(memcmp(ea, ether->ea, 6) == 0 && strcmp(type, "3C562") == 0) {
  133. if(pcmcistuple(slot, 0x88, -1, ea, 6) == 6) {
  134. for(i = 0; i < 6; i += 2){
  135. t = ea[i];
  136. ea[i] = ea[i+1];
  137. ea[i+1] = t;
  138. }
  139. memmove(ether->ea, ea, 6);
  140. }
  141. }
  142. /*
  143. * Allow user to specify desired media in plan9.ini
  144. */
  145. want = WantAny;
  146. for(i = 0; i < ether->nopt; i++){
  147. if(cistrncmp(ether->opt[i], "media=", 6) != 0)
  148. continue;
  149. p = ether->opt[i]+6;
  150. if(cistrcmp(p, "10base2") == 0)
  151. want = Want10B2;
  152. else if(cistrcmp(p, "10baseT") == 0)
  153. want = Want10BT;
  154. }
  155. /* try configuring as a 10BaseT */
  156. if(want==WantAny || want==Want10BT){
  157. if(configASIC(ether, port, xcvr10BaseT) < 0){
  158. pcmspecialclose(slot);
  159. iofree(port);
  160. return -1;
  161. }
  162. delay(100);
  163. COMMAND(port, SelectRegisterWindow, Wdiagnostic);
  164. if((ins(port+MediaStatus)&linkBeatDetect) || want==Want10BT){
  165. COMMAND(port, SelectRegisterWindow, Wop);
  166. print("#l%d: xcvr10BaseT %s\n", ether->ctlrno, type);
  167. return 0;
  168. }
  169. }
  170. /* try configuring as a 10base2 */
  171. if(want==WantAny || want==Want10B2){
  172. COMMAND(port, GlobalReset, 0);
  173. if(configASIC(ether, port, xcvr10Base2) < 0){
  174. pcmspecialclose(slot);
  175. iofree(port);
  176. return -1;
  177. }
  178. print("#l%d: xcvr10Base2 %s\n", ether->ctlrno, type);
  179. return 0;
  180. }
  181. return -1; /* not reached */
  182. }
  183. void
  184. ether589link(void)
  185. {
  186. addethercard("3C589", reset);
  187. addethercard("3C562", reset);
  188. addethercard("589E", reset);
  189. }