etherec2t.c 4.0 KB

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