ether.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. typedef struct Ether Ether;
  10. typedef struct Etherops Etherops;
  11. typedef struct Conn Conn;
  12. typedef struct Cinfo Cinfo;
  13. typedef struct Buf Buf;
  14. typedef struct Etherpkt Etherpkt;
  15. enum
  16. {
  17. /* controller ids */
  18. Cdc = 0,
  19. A8817x, /* Asis */
  20. A88178,
  21. A88179,
  22. A88772,
  23. S95xx, /* SMSC */
  24. Eaddrlen = 6,
  25. Epktlen = 1514,
  26. Ehdrsize = 2*Eaddrlen + 2,
  27. Maxpkt = 2000, /* no jumbo packets here */
  28. Nconns = 8, /* max number of connections */
  29. Nbufs = 32, /* max number of buffers */
  30. Scether = 6, /* ethernet cdc subclass */
  31. Fnheader = 0, /* Functions */
  32. Fnunion = 6,
  33. Fnether = 15,
  34. Cdcunion = 6, /* CDC Union descriptor subtype */
  35. };
  36. struct Buf
  37. {
  38. int type;
  39. int ndata;
  40. uint8_t* rp;
  41. uint8_t data[Hdrsize+Maxpkt];
  42. };
  43. struct Conn
  44. {
  45. Ref Ref; /* one per file in use */
  46. int nb;
  47. int type;
  48. int headersonly;
  49. int prom;
  50. Channel*rc; /* [2] of Buf* */
  51. };
  52. struct Etherops
  53. {
  54. int (*init)(Ether*, int *epin, int *epout);
  55. int32_t (*bread)(Ether*, Buf*);
  56. int32_t (*bwrite)(Ether*, Buf*);
  57. int (*ctl)(Ether*, char*);
  58. int (*promiscuous)(Ether*, int);
  59. int (*multicast)(Ether*, uint8_t*, int);
  60. char* (*seprintstats)(char*, char*, Ether*);
  61. void (*free)(Ether*);
  62. int bufsize;
  63. char *name;
  64. void* aux;
  65. };
  66. struct Ether
  67. {
  68. QLock QLock;
  69. QLock wlck; /* write one at a time */
  70. int epinid; /* epin address */
  71. int epoutid; /* epout address */
  72. Dev* dev;
  73. Dev* epin;
  74. Dev* epout;
  75. int cid; /* ctlr id */
  76. int phy; /* phy id */
  77. Ref prom; /* nb. of promiscuous conns */
  78. int exiting; /* shutting down */
  79. int wrexited; /* write process died */
  80. uint8_t addr[Eaddrlen]; /* mac */
  81. int nconns; /* nb. of entries used in... */
  82. Conn* conns[Nconns]; /* connections */
  83. int nabufs; /* nb. of allocated buffers */
  84. int nbufs; /* nb. of buffers in use */
  85. int nblock; /* nonblocking (output)? */
  86. int nin;
  87. int nout;
  88. int nierrs;
  89. int noerrs;
  90. int mbps;
  91. int nmcasts;
  92. Channel*rc; /* read channel (of Buf*) */
  93. Channel*wc; /* write channel (of Buf*) */
  94. Channel*bc; /* free buf. chan. (of Buf*) */
  95. Etherops Etherops;
  96. Usbfs fs;
  97. };
  98. struct Cinfo
  99. {
  100. int vid; /* usb vendor id */
  101. int did; /* usb device/product id */
  102. int cid; /* controller id assigned by us */
  103. };
  104. struct Etherpkt
  105. {
  106. uint8_t d[Eaddrlen];
  107. uint8_t s[Eaddrlen];
  108. uint8_t type[2];
  109. uint8_t data[1500];
  110. };
  111. int ethermain(Dev *dev, int argc, char **argv);
  112. int asixreset(Ether*);
  113. int smscreset(Ether*);
  114. int cdcreset(Ether*);
  115. int parseaddr(uint8_t *m, char *s);
  116. void dumpframe(char *tag, void *p, int n);
  117. extern Cinfo cinfo[];
  118. extern int etherdebug;
  119. #define deprint if(etherdebug)fprint