ethermii.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 Mii Mii;
  10. typedef struct MiiPhy MiiPhy;
  11. enum { /* registers */
  12. Bmcr = 0x00, /* Basic Mode Control */
  13. Bmsr = 0x01, /* Basic Mode Status */
  14. Phyidr1 = 0x02, /* PHY Identifier #1 */
  15. Phyidr2 = 0x03, /* PHY Identifier #2 */
  16. Anar = 0x04, /* Auto-Negotiation Advertisement */
  17. Anlpar = 0x05, /* AN Link Partner Ability */
  18. Aner = 0x06, /* AN Expansion */
  19. Annptr = 0x07, /* AN Next Page TX */
  20. Annprr = 0x08, /* AN Next Page RX */
  21. Mscr = 0x09, /* MASTER-SLAVE Control */
  22. Mssr = 0x0A, /* MASTER-SLAVE Status */
  23. Esr = 0x0F, /* Extended Status */
  24. NMiiPhyr = 32,
  25. NMiiPhy = 32,
  26. };
  27. enum { /* Bmcr */
  28. BmcrSs1 = 0x0040, /* Speed Select[1] */
  29. BmcrCte = 0x0080, /* Collision Test Enable */
  30. BmcrDm = 0x0100, /* Duplex Mode */
  31. BmcrRan = 0x0200, /* Restart Auto-Negotiation */
  32. BmcrI = 0x0400, /* Isolate */
  33. BmcrPd = 0x0800, /* Power Down */
  34. BmcrAne = 0x1000, /* Auto-Negotiation Enable */
  35. BmcrSs0 = 0x2000, /* Speed Select[0] */
  36. BmcrLe = 0x4000, /* Loopback Enable */
  37. BmcrR = 0x8000, /* Reset */
  38. };
  39. enum { /* Bmsr */
  40. BmsrEc = 0x0001, /* Extended Capability */
  41. BmsrJd = 0x0002, /* Jabber Detect */
  42. BmsrLs = 0x0004, /* Link Status */
  43. BmsrAna = 0x0008, /* Auto-Negotiation Ability */
  44. BmsrRf = 0x0010, /* Remote Fault */
  45. BmsrAnc = 0x0020, /* Auto-Negotiation Complete */
  46. BmsrPs = 0x0040, /* Preamble Suppression Capable */
  47. BmsrEs = 0x0100, /* Extended Status */
  48. Bmsr100T2HD = 0x0200, /* 100BASE-T2 HD Capable */
  49. Bmsr100T2FD = 0x0400, /* 100BASE-T2 FD Capable */
  50. Bmsr10THD = 0x0800, /* 100BASE-T HD Capable */
  51. Bmsr10TFD = 0x1000, /* 10BASE-T FD Capable */
  52. Bmsr100TXHD = 0x2000, /* 100BASE-TX HD Capable */
  53. Bmsr100TXFD = 0x4000, /* 100BASE-TX FD Capable */
  54. Bmsr100T4 = 0x8000, /* 100BASE-T4 Capable */
  55. };
  56. enum { /* Anar/Anlpar */
  57. Ana10HD = 0x0020, /* Advertise 10BASE-T */
  58. Ana10FD = 0x0040, /* Advertise 10BASE-T FD */
  59. AnaTXHD = 0x0080, /* Advertise 100BASE-TX */
  60. AnaTXFD = 0x0100, /* Advertise 100BASE-TX FD */
  61. AnaT4 = 0x0200, /* Advertise 100BASE-T4 */
  62. AnaP = 0x0400, /* Pause */
  63. AnaAP = 0x0800, /* Asymmetrical Pause */
  64. AnaRf = 0x2000, /* Remote Fault */
  65. AnaAck = 0x4000, /* Acknowledge */
  66. AnaNp = 0x8000, /* Next Page Indication */
  67. };
  68. enum { /* Mscr */
  69. Mscr1000THD = 0x0100, /* Advertise 1000BASE-T HD */
  70. Mscr1000TFD = 0x0200, /* Advertise 1000BASE-T FD */
  71. };
  72. enum { /* Mssr */
  73. Mssr1000THD = 0x0400, /* Link Partner 1000BASE-T HD able */
  74. Mssr1000TFD = 0x0800, /* Link Partner 1000BASE-T FD able */
  75. };
  76. enum { /* Esr */
  77. Esr1000THD = 0x1000, /* 1000BASE-T HD Capable */
  78. Esr1000TFD = 0x2000, /* 1000BASE-T FD Capable */
  79. Esr1000XHD = 0x4000, /* 1000BASE-X HD Capable */
  80. Esr1000XFD = 0x8000, /* 1000BASE-X FD Capable */
  81. };
  82. typedef struct Mii {
  83. Lock;
  84. int nphy;
  85. int mask;
  86. MiiPhy* phy[NMiiPhy];
  87. MiiPhy* curphy;
  88. void* ctlr;
  89. int (*mir)(Mii*, int, int);
  90. int (*miw)(Mii*, int, int, int);
  91. } Mii;
  92. typedef struct MiiPhy {
  93. Mii* mii;
  94. int oui;
  95. int phyno;
  96. int anar;
  97. int fc;
  98. int mscr;
  99. int link;
  100. int speed;
  101. int fd;
  102. int rfc;
  103. int tfc;
  104. };
  105. extern int mii(Mii*, int);
  106. extern int miiane(Mii*, int, int, int);
  107. extern int miimir(Mii*, int);
  108. extern int miimiw(Mii*, int, int);
  109. extern int miireset(Mii*);
  110. extern int miistatus(Mii*);