etherec2t.c 3.9 KB

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