ether2000.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "u.h"
  2. #include "lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "io.h"
  7. #include "etherif.h"
  8. #include "ether8390.h"
  9. /*
  10. * Driver written for the 'Notebook Computer Ethernet LAN Adapter',
  11. * a plug-in to the bus-slot on the rear of the Gateway NOMAD 425DXL
  12. * laptop. The manual says NE2000 compatible.
  13. * The interface appears to be pretty well described in the National
  14. * Semiconductor Local Area Network Databook (1992) as one of the
  15. * AT evaluation cards.
  16. *
  17. * The NE2000 is really just a DP8390[12] plus a data port
  18. * and a reset port.
  19. */
  20. enum {
  21. Data = 0x10, /* offset from I/O base of data port */
  22. Reset = 0x1F, /* offset from I/O base of reset port */
  23. };
  24. int
  25. ne2000reset(Ether* ether)
  26. {
  27. ushort buf[16];
  28. ulong port;
  29. Dp8390 *ctlr;
  30. int i;
  31. uchar ea[Eaddrlen];
  32. /*
  33. * Set up the software configuration.
  34. * Use defaults for port, irq, mem and size
  35. * if not specified.
  36. */
  37. if(ether->port == 0)
  38. ether->port = 0x300;
  39. if(ether->irq == 0)
  40. ether->irq = 2;
  41. if(ether->mem == 0)
  42. ether->mem = 0x4000;
  43. if(ether->size == 0)
  44. ether->size = 16*1024;
  45. port = ether->port;
  46. ether->ctlr = malloc(sizeof(Dp8390));
  47. ctlr = ether->ctlr;
  48. ctlr->width = 2;
  49. ctlr->ram = 0;
  50. ctlr->port = port;
  51. ctlr->data = port+Data;
  52. ctlr->tstart = HOWMANY(ether->mem, Dp8390BufSz);
  53. ctlr->pstart = ctlr->tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
  54. ctlr->pstop = ctlr->tstart + HOWMANY(ether->size, Dp8390BufSz);
  55. ctlr->dummyrr = 1;
  56. for(i = 0; i < ether->nopt; i++){
  57. if(strcmp(ether->opt[i], "nodummyrr"))
  58. continue;
  59. ctlr->dummyrr = 0;
  60. break;
  61. }
  62. /*
  63. * Reset the board. This is done by doing a read
  64. * followed by a write to the Reset address.
  65. */
  66. buf[0] = inb(port+Reset);
  67. delay(2);
  68. outb(port+Reset, buf[0]);
  69. delay(2);
  70. /*
  71. * Init the (possible) chip, then use the (possible)
  72. * chip to read the (possible) PROM for ethernet address
  73. * and a marker byte.
  74. * Could just look at the DP8390 command register after
  75. * initialisation has been tried, but that wouldn't be
  76. * enough, there are other ethernet boards which could
  77. * match.
  78. */
  79. dp8390reset(ether);
  80. memset(buf, 0, sizeof(buf));
  81. dp8390read(ctlr, buf, 0, sizeof(buf));
  82. if((buf[0x0E] & 0xFF) != 0x57 || (buf[0x0F] & 0xFF) != 0x57){
  83. free(ether->ctlr);
  84. return -1;
  85. }
  86. /*
  87. * Stupid machine. Shorts were asked for,
  88. * shorts were delivered, although the PROM is a byte array.
  89. * Set the ethernet address.
  90. */
  91. memset(ea, 0, Eaddrlen);
  92. if(memcmp(ea, ether->ea, Eaddrlen) == 0){
  93. for(i = 0; i < sizeof(ether->ea); i++)
  94. ether->ea[i] = buf[i];
  95. }
  96. dp8390setea(ether);
  97. return 0;
  98. }