ether.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "u.h"
  10. #include "../port/lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. #include "io.h"
  15. #include "../port/error.h"
  16. #include "../port/netif.h"
  17. #include "etherif.h"
  18. Ether*
  19. archetherprobe(int ctlrno, char *type, int (*reset)(Ether *))
  20. {
  21. int i, j;
  22. Ether *ether;
  23. char buf[128], name[32];
  24. snprint(name, sizeof(name), "ether%d", ctlrno);
  25. ether = malloc(sizeof(Ether));
  26. memset(ether, 0, sizeof(Ether));
  27. ether->ctlrno = ctlrno;
  28. ether->tbdf = BUSUNKNOWN;
  29. ether->Netif.mbps = 10;
  30. ether->Netif.minmtu = ETHERMINTU;
  31. ether->Netif.mtu = ETHERMAXTU;
  32. ether->Netif.maxmtu = ETHERMAXTU;
  33. if (reset(ether) < 0)
  34. return nil;
  35. /*
  36. * IRQ2 doesn't really exist, it's used to gang the interrupt
  37. * controllers together. A device set to IRQ2 will appear on
  38. * the second interrupt controller as IRQ9.
  39. */
  40. if(ether->ISAConf.irq == 2)
  41. ether->ISAConf.irq = 9;
  42. /*
  43. * If ether->irq is <0, it is a hack to indicate no interrupt
  44. * used by ethersink.
  45. */
  46. if(ether->ISAConf.irq >= 0)
  47. intrenable(ether->ISAConf.irq, ether->interrupt, ether, ether->tbdf, name);
  48. i = sprint(buf, "#l%d: %s: %dMbps port %#p irq %d tu %d",
  49. ctlrno, type, ether->Netif.mbps, ether->ISAConf.port, ether->ISAConf.irq, ether->Netif.mtu);
  50. if(ether->ISAConf.mem)
  51. i += sprint(buf+i, " addr %#p", ether->ISAConf.mem);
  52. if(ether->ISAConf.size)
  53. i += sprint(buf+i, " size 0x%lX", ether->ISAConf.size);
  54. i += sprint(buf+i, ": %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
  55. ether->ea[0], ether->ea[1], ether->ea[2],
  56. ether->ea[3], ether->ea[4], ether->ea[5]);
  57. sprint(buf+i, "\n");
  58. print(buf);
  59. j = ether->Netif.mbps;
  60. if(j > 1000)
  61. j *= 10;
  62. for(i = 0; j >= 100; i++)
  63. j /= 10;
  64. i = (128<<i)*1024;
  65. netifinit(&ether->Netif, name, Ntypes, i);
  66. if(ether->oq == 0)
  67. ether->oq = qopen(i, Qmsg, 0, 0);
  68. if(ether->oq == 0)
  69. panic("etherreset %s", name);
  70. ether->Netif.alen = Eaddrlen;
  71. memmove(ether->Netif.addr, ether->ea, Eaddrlen);
  72. memset(ether->Netif.bcast, 0xFF, Eaddrlen);
  73. return ether;
  74. }
  75. void
  76. archethershutdown(Ether *ether)
  77. {
  78. if(ether->ISAConf.irq >= 0){
  79. // intrdisable(ether->irq, ether->interrupt, ether, ether->tbdf, name);
  80. }
  81. }