etherec2t.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Supposed NE2000 PCMCIA clones, see the comments in ether2000.c
  3. */
  4. #include "u.h"
  5. #include "../port/lib.h"
  6. #include "mem.h"
  7. #include "dat.h"
  8. #include "fns.h"
  9. #include "io.h"
  10. #include "../port/error.h"
  11. #include "../port/netif.h"
  12. #include "etherif.h"
  13. #include "ether8390.h"
  14. enum {
  15. Data = 0x10, /* offset from I/O base of data port */
  16. Reset = 0x1F, /* offset from I/O base of reset port */
  17. };
  18. typedef struct Ec2t {
  19. char* name;
  20. int iochecksum;
  21. } Ec2t;
  22. static Ec2t ec2tpcmcia[] = {
  23. { "EC2T", 0, }, /* Linksys Combo PCMCIA EthernetCard */
  24. { "PCMPC100", 1, }, /* EtherFast 10/100 PC Card */
  25. { "PCM100", 1, }, /* EtherFast PCM100 Card */
  26. { "EN2216", 0, }, /* Accton EtherPair-PCMCIA */
  27. { "FA410TX", 1, }, /* Netgear FA410TX */
  28. { "FA411", 0 }, /* Netgear FA411 PCMCIA */
  29. { "Network Everywhere", 0, }, /* Linksys NP10T 10BaseT Card */
  30. { "10/100 Port Attached", 1, }, /* SMC 8040TX */
  31. { "8041TX-10/100-PC-Card-V2", 0 }, /* SMC 8041TX */
  32. { "SMC8022", 0}, /* SMC 8022 / EZCard-10-PCMCIA */
  33. { nil, 0, },
  34. };
  35. static int
  36. reset(Ether* ether)
  37. {
  38. ushort buf[16];
  39. ulong port;
  40. Dp8390 *ctlr;
  41. int i, slot;
  42. uchar ea[Eaddrlen], sum, x;
  43. Ec2t *ec2t, tmpec2t;
  44. /*
  45. * Set up the software configuration.
  46. * Use defaults for port, irq, mem and size
  47. * if not specified.
  48. * The manual says 16KB memory, the box
  49. * says 32KB. The manual seems to be correct.
  50. */
  51. if(ether->port == 0)
  52. ether->port = 0x300;
  53. if(ether->irq == 0)
  54. ether->irq = 9;
  55. if(ether->mem == 0)
  56. ether->mem = 0x4000;
  57. if(ether->size == 0)
  58. ether->size = 16*1024;
  59. port = ether->port;
  60. if(ioalloc(ether->port, 0x20, 0, "ec2t") < 0)
  61. return -1;
  62. slot = -1;
  63. for(ec2t = ec2tpcmcia; ec2t->name != nil; ec2t++){
  64. if((slot = pcmspecial(ec2t->name, ether)) >= 0)
  65. break;
  66. }
  67. if(ec2t->name == nil){
  68. ec2t = &tmpec2t;
  69. ec2t->name = nil;
  70. ec2t->iochecksum = 0;
  71. for(i = 0; i < ether->nopt; i++){
  72. if(cistrncmp(ether->opt[i], "id=", 3) == 0){
  73. ec2t->name = &ether->opt[i][3];
  74. slot = pcmspecial(ec2t->name, ether);
  75. }
  76. else if(cistrncmp(ether->opt[i], "iochecksum", 10) == 0)
  77. ec2t->iochecksum = 1;
  78. }
  79. }
  80. if(slot < 0){
  81. iofree(port);
  82. return -1;
  83. }
  84. ether->ctlr = malloc(sizeof(Dp8390));
  85. ctlr = ether->ctlr;
  86. if(ctlr == nil) {
  87. iofree(port);
  88. error(Enomem);
  89. }
  90. ctlr->width = 2;
  91. ctlr->ram = 0;
  92. ctlr->port = port;
  93. ctlr->data = port+Data;
  94. ctlr->tstart = HOWMANY(ether->mem, Dp8390BufSz);
  95. ctlr->pstart = ctlr->tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
  96. ctlr->pstop = ctlr->tstart + HOWMANY(ether->size, Dp8390BufSz);
  97. ctlr->dummyrr = 0;
  98. for(i = 0; i < ether->nopt; i++){
  99. if(cistrcmp(ether->opt[i], "nodummyrr") == 0)
  100. ctlr->dummyrr = 0;
  101. else if(cistrncmp(ether->opt[i], "dummyrr=", 8) == 0)
  102. ctlr->dummyrr = strtol(&ether->opt[i][8], nil, 0);
  103. }
  104. /*
  105. * Reset the board. This is done by doing a read
  106. * followed by a write to the Reset address.
  107. */
  108. buf[0] = inb(port+Reset);
  109. delay(2);
  110. outb(port+Reset, buf[0]);
  111. delay(2);
  112. /*
  113. * Init the (possible) chip, then use the (possible)
  114. * chip to read the (possible) PROM for ethernet address
  115. * and a marker byte.
  116. * Could just look at the DP8390 command register after
  117. * initialisation has been tried, but that wouldn't be
  118. * enough, there are other ethernet boards which could
  119. * match.
  120. */
  121. dp8390reset(ether);
  122. sum = 0;
  123. if(ec2t->iochecksum){
  124. /*
  125. * These cards have the ethernet address in I/O space.
  126. * There's a checksum over 8 bytes which sums to 0xFF.
  127. */
  128. for(i = 0; i < 8; i++){
  129. x = inb(port+0x14+i);
  130. sum += x;
  131. buf[i] = (x<<8)|x;
  132. }
  133. }
  134. else{
  135. memset(buf, 0, sizeof(buf));
  136. dp8390read(ctlr, buf, 0, sizeof(buf));
  137. if((buf[0x0E] & 0xFF) == 0x57 && (buf[0x0F] & 0xFF) == 0x57)
  138. sum = 0xFF;
  139. }
  140. if(sum != 0xFF){
  141. pcmspecialclose(slot);
  142. iofree(ether->port);
  143. free(ether->ctlr);
  144. return -1;
  145. }
  146. /*
  147. * Stupid machine. Shorts were asked for,
  148. * shorts were delivered, although the PROM is a byte array.
  149. * Set the ethernet address.
  150. */
  151. memset(ea, 0, Eaddrlen);
  152. if(memcmp(ea, ether->ea, Eaddrlen) == 0){
  153. for(i = 0; i < sizeof(ether->ea); i++)
  154. ether->ea[i] = buf[i];
  155. }
  156. dp8390setea(ether);
  157. return 0;
  158. }
  159. void
  160. etherec2tlink(void)
  161. {
  162. addethercard("EC2T", reset);
  163. }