You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3c90x.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * 3c90x.c -- This file implements the 3c90x driver for etherboot. Written
  3. * by Greg Beeley, Greg.Beeley@LightSys.org. Modified by Steve Smith,
  4. * Steve.Smith@Juno.Com. Alignment bug fix Neil Newell (nn@icenoir.net).
  5. *
  6. * Port from etherboot to iPXE API, implementation of tx/rx ring support
  7. * by Thomas Miletich, thomas.miletich@gmail.com
  8. * Thanks to Marty Connor and Stefan Hajnoczi for their help and feedback.
  9. *
  10. * This program Copyright (C) 1999 LightSys Technology Services, Inc.
  11. * Portions Copyright (C) 1999 Steve Smith
  12. *
  13. * This program may be re-distributed in source or binary form, modified,
  14. * sold, or copied for any purpose, provided that the above copyright message
  15. * and this text are included with all source copies or derivative works, and
  16. * provided that the above copyright message and this text are included in the
  17. * documentation of any binary-only distributions. This program is distributed
  18. * WITHOUT ANY WARRANTY, without even the warranty of FITNESS FOR A PARTICULAR
  19. * PURPOSE or MERCHANTABILITY. Please read the associated documentation
  20. * "3c90x.txt" before compiling and using this driver.
  21. *
  22. * --------
  23. *
  24. * Program written with the assistance of the 3com documentation for
  25. * the 3c905B-TX card, as well as with some assistance from the 3c59x
  26. * driver Donald Becker wrote for the Linux kernel, and with some assistance
  27. * from the remainder of the Etherboot distribution.
  28. *
  29. * REVISION HISTORY:
  30. *
  31. * v0.10 1-26-1998 GRB Initial implementation.
  32. * v0.90 1-27-1998 GRB System works.
  33. * v1.00pre1 2-11-1998 GRB Got prom boot issue fixed.
  34. * v2.0 9-24-1999 SCS Modified for 3c905 (from 3c905b code)
  35. * Re-wrote poll and transmit for
  36. * better error recovery and heavy
  37. * network traffic operation
  38. * v2.01 5-26-2003 NN Fixed driver alignment issue which
  39. * caused system lockups if driver structures
  40. * not 8-byte aligned.
  41. * v2.02 11-28-2007 GSt Got polling working again by replacing
  42. * "for(i=0;i<40000;i++);" with "mdelay(1);"
  43. *
  44. *
  45. * indent options: indent -kr -i8 3c90x.c
  46. */
  47. FILE_LICENCE ( BSD2 );
  48. #ifndef __3C90X_H_
  49. #define __3C90X_H_
  50. static struct net_device_operations a3c90x_operations;
  51. #define XCVR_MAGIC (0x5A00)
  52. /* Register definitions for the 3c905 */
  53. enum Registers {
  54. regPowerMgmtCtrl_w = 0x7c, /* 905B Revision Only */
  55. regUpMaxBurst_w = 0x7a, /* 905B Revision Only */
  56. regDnMaxBurst_w = 0x78, /* 905B Revision Only */
  57. regDebugControl_w = 0x74, /* 905B Revision Only */
  58. regDebugData_l = 0x70, /* 905B Revision Only */
  59. regRealTimeCnt_l = 0x40, /* Universal */
  60. regUpBurstThresh_b = 0x3e, /* 905B Revision Only */
  61. regUpPoll_b = 0x3d, /* 905B Revision Only */
  62. regUpPriorityThresh_b = 0x3c, /* 905B Revision Only */
  63. regUpListPtr_l = 0x38, /* Universal */
  64. regCountdown_w = 0x36, /* Universal */
  65. regFreeTimer_w = 0x34, /* Universal */
  66. regUpPktStatus_l = 0x30, /* Universal with Exception, pg 130 */
  67. regTxFreeThresh_b = 0x2f, /* 90X Revision Only */
  68. regDnPoll_b = 0x2d, /* 905B Revision Only */
  69. regDnPriorityThresh_b = 0x2c, /* 905B Revision Only */
  70. regDnBurstThresh_b = 0x2a, /* 905B Revision Only */
  71. regDnListPtr_l = 0x24, /* Universal with Exception, pg 107 */
  72. regDmaCtrl_l = 0x20, /* Universal with Exception, pg 106 */
  73. /* */
  74. regIntStatusAuto_w = 0x1e, /* 905B Revision Only */
  75. regTxStatus_b = 0x1b, /* Universal with Exception, pg 113 */
  76. regTimer_b = 0x1a, /* Universal */
  77. regTxPktId_b = 0x18, /* 905B Revision Only */
  78. regCommandIntStatus_w = 0x0e, /* Universal (Command Variations) */
  79. };
  80. /* following are windowed registers */
  81. enum Registers7 {
  82. regPowerMgmtEvent_7_w = 0x0c, /* 905B Revision Only */
  83. regVlanEtherType_7_w = 0x04, /* 905B Revision Only */
  84. regVlanMask_7_w = 0x00, /* 905B Revision Only */
  85. };
  86. enum Registers6 {
  87. regBytesXmittedOk_6_w = 0x0c, /* Universal */
  88. regBytesRcvdOk_6_w = 0x0a, /* Universal */
  89. regUpperFramesOk_6_b = 0x09, /* Universal */
  90. regFramesDeferred_6_b = 0x08, /* Universal */
  91. regFramesRecdOk_6_b = 0x07, /* Universal with Exceptions, pg 142 */
  92. regFramesXmittedOk_6_b = 0x06, /* Universal */
  93. regRxOverruns_6_b = 0x05, /* Universal */
  94. regLateCollisions_6_b = 0x04, /* Universal */
  95. regSingleCollisions_6_b = 0x03, /* Universal */
  96. regMultipleCollisions_6_b = 0x02, /* Universal */
  97. regSqeErrors_6_b = 0x01, /* Universal */
  98. regCarrierLost_6_b = 0x00, /* Universal */
  99. };
  100. enum Registers5 {
  101. regIndicationEnable_5_w = 0x0c, /* Universal */
  102. regInterruptEnable_5_w = 0x0a, /* Universal */
  103. regTxReclaimThresh_5_b = 0x09, /* 905B Revision Only */
  104. regRxFilter_5_b = 0x08, /* Universal */
  105. regRxEarlyThresh_5_w = 0x06, /* Universal */
  106. regTxStartThresh_5_w = 0x00, /* Universal */
  107. };
  108. enum Registers4 {
  109. regUpperBytesOk_4_b = 0x0d, /* Universal */
  110. regBadSSD_4_b = 0x0c, /* Universal */
  111. regMediaStatus_4_w = 0x0a, /* Universal with Exceptions, pg 201 */
  112. regPhysicalMgmt_4_w = 0x08, /* Universal */
  113. regNetworkDiagnostic_4_w = 0x06, /* Universal with Exceptions, pg 203 */
  114. regFifoDiagnostic_4_w = 0x04, /* Universal with Exceptions, pg 196 */
  115. regVcoDiagnostic_4_w = 0x02, /* Undocumented? */
  116. };
  117. enum Registers3 {
  118. regTxFree_3_w = 0x0c, /* Universal */
  119. regRxFree_3_w = 0x0a, /* Universal with Exceptions, pg 125 */
  120. regResetMediaOptions_3_w = 0x08, /* Media Options on B Revision, */
  121. /* Reset Options on Non-B Revision */
  122. regMacControl_3_w = 0x06, /* Universal with Exceptions, pg 199 */
  123. regMaxPktSize_3_w = 0x04, /* 905B Revision Only */
  124. regInternalConfig_3_l = 0x00, /* Universal, different bit */
  125. /* definitions, pg 59 */
  126. };
  127. enum Registers2 {
  128. regResetOptions_2_w = 0x0c, /* 905B Revision Only */
  129. regStationMask_2_3w = 0x06, /* Universal with Exceptions, pg 127 */
  130. regStationAddress_2_3w = 0x00, /* Universal with Exceptions, pg 127 */
  131. };
  132. enum Registers1 {
  133. regRxStatus_1_w = 0x0a, /* 90X Revision Only, Pg 126 */
  134. };
  135. enum Registers0 {
  136. regEepromData_0_w = 0x0c, /* Universal */
  137. regEepromCommand_0_w = 0x0a, /* Universal */
  138. regBiosRomData_0_b = 0x08, /* 905B Revision Only */
  139. regBiosRomAddr_0_l = 0x04, /* 905B Revision Only */
  140. };
  141. /* The names for the eight register windows */
  142. enum Windows {
  143. winNone = 0xff,
  144. winPowerVlan7 = 0x07,
  145. winStatistics6 = 0x06,
  146. winTxRxControl5 = 0x05,
  147. winDiagnostics4 = 0x04,
  148. winTxRxOptions3 = 0x03,
  149. winAddressing2 = 0x02,
  150. winUnused1 = 0x01,
  151. winEepromBios0 = 0x00,
  152. };
  153. /* Command definitions for the 3c90X */
  154. enum Commands {
  155. cmdGlobalReset = 0x00, /* Universal with Exceptions, pg 151 */
  156. cmdSelectRegisterWindow = 0x01, /* Universal */
  157. cmdEnableDcConverter = 0x02, /* */
  158. cmdRxDisable = 0x03, /* */
  159. cmdRxEnable = 0x04, /* Universal */
  160. cmdRxReset = 0x05, /* Universal */
  161. cmdStallCtl = 0x06, /* Universal */
  162. cmdTxEnable = 0x09, /* Universal */
  163. cmdTxDisable = 0x0A, /* */
  164. cmdTxReset = 0x0B, /* Universal */
  165. cmdRequestInterrupt = 0x0C, /* */
  166. cmdAcknowledgeInterrupt = 0x0D, /* Universal */
  167. cmdSetInterruptEnable = 0x0E, /* Universal */
  168. cmdSetIndicationEnable = 0x0F, /* Universal */
  169. cmdSetRxFilter = 0x10, /* Universal */
  170. cmdSetRxEarlyThresh = 0x11, /* */
  171. cmdSetTxStartThresh = 0x13, /* */
  172. cmdStatisticsEnable = 0x15, /* */
  173. cmdStatisticsDisable = 0x16, /* */
  174. cmdDisableDcConverter = 0x17, /* */
  175. cmdSetTxReclaimThresh = 0x18, /* */
  176. cmdSetHashFilterBit = 0x19, /* */
  177. };
  178. enum GlobalResetParams {
  179. globalResetAll = 0,
  180. globalResetMaskNetwork = (1<<2),
  181. globalResetMaskAll = 0x1ff,
  182. };
  183. enum FrameStartHeader {
  184. fshTxIndicate = 0x8000,
  185. fshDnComplete = 0x10000,
  186. fshRndupDefeat = 0x10000000,
  187. };
  188. enum UpDownDesc {
  189. upLastFrag = (1 << 31),
  190. downLastFrag = (1 << 31),
  191. };
  192. enum UpPktStatus {
  193. upComplete = (1 << 15),
  194. upError = (1 << 14),
  195. };
  196. enum Stalls {
  197. upStall = 0x00,
  198. upUnStall = 0x01,
  199. dnStall = 0x02,
  200. dnUnStall = 0x03,
  201. };
  202. enum Resources {
  203. resRxRing = 0x00,
  204. resTxRing = 0x02,
  205. resRxIOBuf = 0x04
  206. };
  207. enum eeprom {
  208. eepromBusy = (1 << 15),
  209. eepromRead = ((0x02) << 6),
  210. eepromRead_556 = 0x230,
  211. eepromHwAddrOffset = 0x0a,
  212. };
  213. /* Bit 4 is only used in revison B and upwards */
  214. enum linktype {
  215. link10BaseT = 0x00,
  216. linkAUI = 0x01,
  217. link10Base2 = 0x03,
  218. link100BaseFX = 0x05,
  219. linkMII = 0x06,
  220. linkAutoneg = 0x08,
  221. linkExternalMII = 0x09,
  222. };
  223. /* Values for int status register bitmask */
  224. #define INT_INTERRUPTLATCH (1<<0)
  225. #define INT_HOSTERROR (1<<1)
  226. #define INT_TXCOMPLETE (1<<2)
  227. #define INT_RXCOMPLETE (1<<4)
  228. #define INT_RXEARLY (1<<5)
  229. #define INT_INTREQUESTED (1<<6)
  230. #define INT_UPDATESTATS (1<<7)
  231. #define INT_LINKEVENT (1<<8)
  232. #define INT_DNCOMPLETE (1<<9)
  233. #define INT_UPCOMPLETE (1<<10)
  234. #define INT_CMDINPROGRESS (1<<12)
  235. #define INT_WINDOWNUMBER (7<<13)
  236. /* Buffer sizes */
  237. #define TX_RING_SIZE 8
  238. #define RX_RING_SIZE 8
  239. #define TX_RING_ALIGN 16
  240. #define RX_RING_ALIGN 16
  241. #define RX_BUF_SIZE 1536
  242. /* Timeouts for eeprom and command completion */
  243. /* Timeout 1 second, to be save */
  244. #define EEPROM_TIMEOUT 1 * 1000 * 1000
  245. /* TX descriptor */
  246. struct TXD {
  247. volatile unsigned int DnNextPtr;
  248. volatile unsigned int FrameStartHeader;
  249. volatile unsigned int DataAddr;
  250. volatile unsigned int DataLength;
  251. } __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
  252. /* RX descriptor */
  253. struct RXD {
  254. volatile unsigned int UpNextPtr;
  255. volatile unsigned int UpPktStatus;
  256. volatile unsigned int DataAddr;
  257. volatile unsigned int DataLength;
  258. } __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
  259. /* Private NIC dats */
  260. struct INF_3C90X {
  261. unsigned int is3c556;
  262. unsigned char isBrev;
  263. unsigned char CurrentWindow;
  264. unsigned int IOAddr;
  265. unsigned short eeprom[0x21];
  266. unsigned int tx_cur; /* current entry in tx_ring */
  267. unsigned int tx_cnt; /* current number of used tx descriptors */
  268. unsigned int tx_tail; /* entry of last finished packet */
  269. unsigned int rx_cur;
  270. struct TXD *tx_ring;
  271. struct RXD *rx_ring;
  272. struct io_buffer *tx_iobuf[TX_RING_SIZE];
  273. struct io_buffer *rx_iobuf[RX_RING_SIZE];
  274. struct nvs_device nvs;
  275. };
  276. #endif