Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

tlan.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /**************************************************************************
  2. *
  3. * tlan.c -- Etherboot device driver for the Texas Instruments ThunderLAN
  4. * Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. * Portions of this code (almost all) based on:
  21. * tlan.c: Linux ThunderLan Driver:
  22. *
  23. * by James Banks
  24. *
  25. * (C) 1997-1998 Caldera, Inc.
  26. * (C) 1998 James Banks
  27. * (C) 1999-2001 Torben Mathiasen
  28. * (C) 2002 Samuel Chessman
  29. *
  30. * REVISION HISTORY:
  31. * ================
  32. * v1.0 07-08-2003 timlegge Initial not quite working version
  33. *
  34. * Indent Style: indent -kr -i8
  35. ***************************************************************************/
  36. FILE_LICENCE ( GPL2_OR_LATER );
  37. /*****************************************************************
  38. * TLan Definitions
  39. *
  40. ****************************************************************/
  41. #define FALSE 0
  42. #define TRUE 1
  43. #define TLAN_MIN_FRAME_SIZE 64
  44. #define TLAN_MAX_FRAME_SIZE 1600
  45. #define TLAN_NUM_RX_LISTS 4
  46. #define TLAN_NUM_TX_LISTS 2
  47. #define TLAN_IGNORE 0
  48. #define TLAN_RECORD 1
  49. /*
  50. #define TLAN_DBG(lvl, format, args...) if (debug&lvl) printf("TLAN: " format, ##args );
  51. */
  52. #define TLAN_DEBUG_GNRL 0x0001
  53. #define TLAN_DEBUG_TX 0x0002
  54. #define TLAN_DEBUG_RX 0x0004
  55. #define TLAN_DEBUG_LIST 0x0008
  56. #define TLAN_DEBUG_PROBE 0x0010
  57. #define TX_TIMEOUT (10*HZ) /* We need time for auto-neg */
  58. #define MAX_TLAN_BOARDS 8 /* Max number of boards installed at a time */
  59. /*****************************************************************
  60. * Device Identification Definitions
  61. *
  62. ****************************************************************/
  63. #define PCI_DEVICE_ID_NETELLIGENT_10_T2 0xB012
  64. #define PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100 0xB030
  65. #ifndef PCI_DEVICE_ID_OLICOM_OC2183
  66. #define PCI_DEVICE_ID_OLICOM_OC2183 0x0013
  67. #endif
  68. #ifndef PCI_DEVICE_ID_OLICOM_OC2325
  69. #define PCI_DEVICE_ID_OLICOM_OC2325 0x0012
  70. #endif
  71. #ifndef PCI_DEVICE_ID_OLICOM_OC2326
  72. #define PCI_DEVICE_ID_OLICOM_OC2326 0x0014
  73. #endif
  74. typedef struct tlan_adapter_entry {
  75. u16 vendorId;
  76. u16 deviceId;
  77. char *deviceLabel;
  78. u32 flags;
  79. u16 addrOfs;
  80. } TLanAdapterEntry;
  81. #define TLAN_ADAPTER_NONE 0x00000000
  82. #define TLAN_ADAPTER_UNMANAGED_PHY 0x00000001
  83. #define TLAN_ADAPTER_BIT_RATE_PHY 0x00000002
  84. #define TLAN_ADAPTER_USE_INTERN_10 0x00000004
  85. #define TLAN_ADAPTER_ACTIVITY_LED 0x00000008
  86. #define TLAN_SPEED_DEFAULT 0
  87. #define TLAN_SPEED_10 10
  88. #define TLAN_SPEED_100 100
  89. #define TLAN_DUPLEX_DEFAULT 0
  90. #define TLAN_DUPLEX_HALF 1
  91. #define TLAN_DUPLEX_FULL 2
  92. /*****************************************************************
  93. * EISA Definitions
  94. *
  95. ****************************************************************/
  96. #define EISA_ID 0xc80 /* EISA ID Registers */
  97. #define EISA_ID0 0xc80 /* EISA ID Register 0 */
  98. #define EISA_ID1 0xc81 /* EISA ID Register 1 */
  99. #define EISA_ID2 0xc82 /* EISA ID Register 2 */
  100. #define EISA_ID3 0xc83 /* EISA ID Register 3 */
  101. #define EISA_CR 0xc84 /* EISA Control Register */
  102. #define EISA_REG0 0xc88 /* EISA Configuration Register 0 */
  103. #define EISA_REG1 0xc89 /* EISA Configuration Register 1 */
  104. #define EISA_REG2 0xc8a /* EISA Configuration Register 2 */
  105. #define EISA_REG3 0xc8f /* EISA Configuration Register 3 */
  106. #define EISA_APROM 0xc90 /* Ethernet Address PROM */
  107. /*****************************************************************
  108. * Rx/Tx List Definitions
  109. *
  110. ****************************************************************/
  111. #define TLAN_BUFFERS_PER_LIST 10
  112. #define TLAN_LAST_BUFFER 0x80000000
  113. #define TLAN_CSTAT_UNUSED 0x8000
  114. #define TLAN_CSTAT_FRM_CMP 0x4000
  115. #define TLAN_CSTAT_READY 0x3000
  116. #define TLAN_CSTAT_EOC 0x0800
  117. #define TLAN_CSTAT_RX_ERROR 0x0400
  118. #define TLAN_CSTAT_PASS_CRC 0x0200
  119. #define TLAN_CSTAT_DP_PR 0x0100
  120. /*****************************************************************
  121. * PHY definitions
  122. *
  123. ****************************************************************/
  124. #define TLAN_PHY_MAX_ADDR 0x1F
  125. #define TLAN_PHY_NONE 0x20
  126. /*****************************************************************
  127. * TLan Driver Timer Definitions
  128. *
  129. ****************************************************************/
  130. #define TLAN_TIMER_LINK_BEAT 1
  131. #define TLAN_TIMER_ACTIVITY 2
  132. #define TLAN_TIMER_PHY_PDOWN 3
  133. #define TLAN_TIMER_PHY_PUP 4
  134. #define TLAN_TIMER_PHY_RESET 5
  135. #define TLAN_TIMER_PHY_START_LINK 6
  136. #define TLAN_TIMER_PHY_FINISH_AN 7
  137. #define TLAN_TIMER_FINISH_RESET 8
  138. #define TLAN_TIMER_ACT_DELAY (HZ/10)
  139. /*****************************************************************
  140. * TLan Driver Eeprom Definitions
  141. *
  142. ****************************************************************/
  143. #define TLAN_EEPROM_ACK 0
  144. #define TLAN_EEPROM_STOP 1
  145. /*****************************************************************
  146. * Host Register Offsets and Contents
  147. *
  148. ****************************************************************/
  149. #define TLAN_HOST_CMD 0x00
  150. #define TLAN_HC_GO 0x80000000
  151. #define TLAN_HC_STOP 0x40000000
  152. #define TLAN_HC_ACK 0x20000000
  153. #define TLAN_HC_CS_MASK 0x1FE00000
  154. #define TLAN_HC_EOC 0x00100000
  155. #define TLAN_HC_RT 0x00080000
  156. #define TLAN_HC_NES 0x00040000
  157. #define TLAN_HC_AD_RST 0x00008000
  158. #define TLAN_HC_LD_TMR 0x00004000
  159. #define TLAN_HC_LD_THR 0x00002000
  160. #define TLAN_HC_REQ_INT 0x00001000
  161. #define TLAN_HC_INT_OFF 0x00000800
  162. #define TLAN_HC_INT_ON 0x00000400
  163. #define TLAN_HC_AC_MASK 0x000000FF
  164. #define TLAN_CH_PARM 0x04
  165. #define TLAN_DIO_ADR 0x08
  166. #define TLAN_DA_ADR_INC 0x8000
  167. #define TLAN_DA_RAM_ADR 0x4000
  168. #define TLAN_HOST_INT 0x0A
  169. #define TLAN_HI_IV_MASK 0x1FE0
  170. #define TLAN_HI_IT_MASK 0x001C
  171. #define TLAN_DIO_DATA 0x0C
  172. /* ThunderLAN Internal Register DIO Offsets */
  173. #define TLAN_NET_CMD 0x00
  174. #define TLAN_NET_CMD_NRESET 0x80
  175. #define TLAN_NET_CMD_NWRAP 0x40
  176. #define TLAN_NET_CMD_CSF 0x20
  177. #define TLAN_NET_CMD_CAF 0x10
  178. #define TLAN_NET_CMD_NOBRX 0x08
  179. #define TLAN_NET_CMD_DUPLEX 0x04
  180. #define TLAN_NET_CMD_TRFRAM 0x02
  181. #define TLAN_NET_CMD_TXPACE 0x01
  182. #define TLAN_NET_SIO 0x01
  183. #define TLAN_NET_SIO_MINTEN 0x80
  184. #define TLAN_NET_SIO_ECLOK 0x40
  185. #define TLAN_NET_SIO_ETXEN 0x20
  186. #define TLAN_NET_SIO_EDATA 0x10
  187. #define TLAN_NET_SIO_NMRST 0x08
  188. #define TLAN_NET_SIO_MCLK 0x04
  189. #define TLAN_NET_SIO_MTXEN 0x02
  190. #define TLAN_NET_SIO_MDATA 0x01
  191. #define TLAN_NET_STS 0x02
  192. #define TLAN_NET_STS_MIRQ 0x80
  193. #define TLAN_NET_STS_HBEAT 0x40
  194. #define TLAN_NET_STS_TXSTOP 0x20
  195. #define TLAN_NET_STS_RXSTOP 0x10
  196. #define TLAN_NET_STS_RSRVD 0x0F
  197. #define TLAN_NET_MASK 0x03
  198. #define TLAN_NET_MASK_MASK7 0x80
  199. #define TLAN_NET_MASK_MASK6 0x40
  200. #define TLAN_NET_MASK_MASK5 0x20
  201. #define TLAN_NET_MASK_MASK4 0x10
  202. #define TLAN_NET_MASK_RSRVD 0x0F
  203. #define TLAN_NET_CONFIG 0x04
  204. #define TLAN_NET_CFG_RCLK 0x8000
  205. #define TLAN_NET_CFG_TCLK 0x4000
  206. #define TLAN_NET_CFG_BIT 0x2000
  207. #define TLAN_NET_CFG_RXCRC 0x1000
  208. #define TLAN_NET_CFG_PEF 0x0800
  209. #define TLAN_NET_CFG_1FRAG 0x0400
  210. #define TLAN_NET_CFG_1CHAN 0x0200
  211. #define TLAN_NET_CFG_MTEST 0x0100
  212. #define TLAN_NET_CFG_PHY_EN 0x0080
  213. #define TLAN_NET_CFG_MSMASK 0x007F
  214. #define TLAN_MAN_TEST 0x06
  215. #define TLAN_DEF_VENDOR_ID 0x08
  216. #define TLAN_DEF_DEVICE_ID 0x0A
  217. #define TLAN_DEF_REVISION 0x0C
  218. #define TLAN_DEF_SUBCLASS 0x0D
  219. #define TLAN_DEF_MIN_LAT 0x0E
  220. #define TLAN_DEF_MAX_LAT 0x0F
  221. #define TLAN_AREG_0 0x10
  222. #define TLAN_AREG_1 0x16
  223. #define TLAN_AREG_2 0x1C
  224. #define TLAN_AREG_3 0x22
  225. #define TLAN_HASH_1 0x28
  226. #define TLAN_HASH_2 0x2C
  227. #define TLAN_GOOD_TX_FRMS 0x30
  228. #define TLAN_TX_UNDERUNS 0x33
  229. #define TLAN_GOOD_RX_FRMS 0x34
  230. #define TLAN_RX_OVERRUNS 0x37
  231. #define TLAN_DEFERRED_TX 0x38
  232. #define TLAN_CRC_ERRORS 0x3A
  233. #define TLAN_CODE_ERRORS 0x3B
  234. #define TLAN_MULTICOL_FRMS 0x3C
  235. #define TLAN_SINGLECOL_FRMS 0x3E
  236. #define TLAN_EXCESSCOL_FRMS 0x40
  237. #define TLAN_LATE_COLS 0x41
  238. #define TLAN_CARRIER_LOSS 0x42
  239. #define TLAN_ACOMMIT 0x43
  240. #define TLAN_LED_REG 0x44
  241. #define TLAN_LED_ACT 0x10
  242. #define TLAN_LED_LINK 0x01
  243. #define TLAN_BSIZE_REG 0x45
  244. #define TLAN_MAX_RX 0x46
  245. #define TLAN_INT_DIS 0x48
  246. #define TLAN_ID_TX_EOC 0x04
  247. #define TLAN_ID_RX_EOF 0x02
  248. #define TLAN_ID_RX_EOC 0x01
  249. /* ThunderLAN Interrupt Codes */
  250. #define TLAN_INT_NUMBER_OF_INTS 8
  251. #define TLAN_INT_NONE 0x0000
  252. #define TLAN_INT_TX_EOF 0x0001
  253. #define TLAN_INT_STAT_OVERFLOW 0x0002
  254. #define TLAN_INT_RX_EOF 0x0003
  255. #define TLAN_INT_DUMMY 0x0004
  256. #define TLAN_INT_TX_EOC 0x0005
  257. #define TLAN_INT_STATUS_CHECK 0x0006
  258. #define TLAN_INT_RX_EOC 0x0007
  259. /* ThunderLAN MII Registers */
  260. /* ThunderLAN Specific MII/PHY Registers */
  261. #define TLAN_TLPHY_ID 0x10
  262. #define TLAN_TLPHY_CTL 0x11
  263. #define TLAN_TC_IGLINK 0x8000
  264. #define TLAN_TC_SWAPOL 0x4000
  265. #define TLAN_TC_AUISEL 0x2000
  266. #define TLAN_TC_SQEEN 0x1000
  267. #define TLAN_TC_MTEST 0x0800
  268. #define TLAN_TC_RESERVED 0x07F8
  269. #define TLAN_TC_NFEW 0x0004
  270. #define TLAN_TC_INTEN 0x0002
  271. #define TLAN_TC_TINT 0x0001
  272. #define TLAN_TLPHY_STS 0x12
  273. #define TLAN_TS_MINT 0x8000
  274. #define TLAN_TS_PHOK 0x4000
  275. #define TLAN_TS_POLOK 0x2000
  276. #define TLAN_TS_TPENERGY 0x1000
  277. #define TLAN_TS_RESERVED 0x0FFF
  278. #define TLAN_TLPHY_PAR 0x19
  279. #define TLAN_PHY_CIM_STAT 0x0020
  280. #define TLAN_PHY_SPEED_100 0x0040
  281. #define TLAN_PHY_DUPLEX_FULL 0x0080
  282. #define TLAN_PHY_AN_EN_STAT 0x0400
  283. /* National Sem. & Level1 PHY id's */
  284. #define NAT_SEM_ID1 0x2000
  285. #define NAT_SEM_ID2 0x5C01
  286. #define LEVEL1_ID1 0x7810
  287. #define LEVEL1_ID2 0x0000
  288. #define CIRC_INC( a, b ) if ( ++a >= b ) a = 0
  289. /* Routines to access internal registers. */
  290. static inline u8 TLan_DioRead8(u16 base_addr, u16 internal_addr)
  291. {
  292. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  293. return (inb((base_addr + TLAN_DIO_DATA) + (internal_addr & 0x3)));
  294. } /* TLan_DioRead8 */
  295. static inline u16 TLan_DioRead16(u16 base_addr, u16 internal_addr)
  296. {
  297. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  298. return (inw((base_addr + TLAN_DIO_DATA) + (internal_addr & 0x2)));
  299. } /* TLan_DioRead16 */
  300. static inline u32 TLan_DioRead32(u16 base_addr, u16 internal_addr)
  301. {
  302. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  303. return (inl(base_addr + TLAN_DIO_DATA));
  304. } /* TLan_DioRead32 */
  305. static inline void TLan_DioWrite8(u16 base_addr, u16 internal_addr, u8 data)
  306. {
  307. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  308. outb(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x3));
  309. }
  310. static inline void TLan_DioWrite16(u16 base_addr, u16 internal_addr, u16 data)
  311. {
  312. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  313. outw(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x2));
  314. }
  315. static inline void TLan_DioWrite32(u16 base_addr, u16 internal_addr, u32 data)
  316. {
  317. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  318. outl(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x2));
  319. }
  320. #if 0
  321. static inline void TLan_ClearBit(u8 bit, u16 port)
  322. {
  323. outb_p(inb_p(port) & ~bit, port);
  324. }
  325. static inline int TLan_GetBit(u8 bit, u16 port)
  326. {
  327. return ((int) (inb_p(port) & bit));
  328. }
  329. static inline void TLan_SetBit(u8 bit, u16 port)
  330. {
  331. outb_p(inb_p(port) | bit, port);
  332. }
  333. #endif
  334. #define TLan_ClearBit( bit, port ) outb_p(inb_p(port) & ~bit, port)
  335. #define TLan_GetBit( bit, port ) ((int) (inb_p(port) & bit))
  336. #define TLan_SetBit( bit, port ) outb_p(inb_p(port) | bit, port)
  337. #ifdef I_LIKE_A_FAST_HASH_FUNCTION
  338. /* given 6 bytes, view them as 8 6-bit numbers and return the XOR of those */
  339. /* the code below is about seven times as fast as the original code */
  340. static inline u32 TLan_HashFunc(u8 * a)
  341. {
  342. u8 hash;
  343. hash = (a[0] ^ a[3]); /* & 077 */
  344. hash ^= ((a[0] ^ a[3]) >> 6); /* & 003 */
  345. hash ^= ((a[1] ^ a[4]) << 2); /* & 074 */
  346. hash ^= ((a[1] ^ a[4]) >> 4); /* & 017 */
  347. hash ^= ((a[2] ^ a[5]) << 4); /* & 060 */
  348. hash ^= ((a[2] ^ a[5]) >> 2); /* & 077 */
  349. return (hash & 077);
  350. }
  351. #else /* original code */
  352. static inline u32 xor(u32 a, u32 b)
  353. {
  354. return ((a && !b) || (!a && b));
  355. }
  356. #define XOR8( a, b, c, d, e, f, g, h ) xor( a, xor( b, xor( c, xor( d, xor( e, xor( f, xor( g, h ) ) ) ) ) ) )
  357. #define DA( a, bit ) ( ( (u8) a[bit/8] ) & ( (u8) ( 1 << bit%8 ) ) )
  358. static inline u32 TLan_HashFunc(u8 * a)
  359. {
  360. u32 hash;
  361. hash =
  362. XOR8(DA(a, 0), DA(a, 6), DA(a, 12), DA(a, 18), DA(a, 24),
  363. DA(a, 30), DA(a, 36), DA(a, 42));
  364. hash |=
  365. XOR8(DA(a, 1), DA(a, 7), DA(a, 13), DA(a, 19), DA(a, 25),
  366. DA(a, 31), DA(a, 37), DA(a, 43)) << 1;
  367. hash |=
  368. XOR8(DA(a, 2), DA(a, 8), DA(a, 14), DA(a, 20), DA(a, 26),
  369. DA(a, 32), DA(a, 38), DA(a, 44)) << 2;
  370. hash |=
  371. XOR8(DA(a, 3), DA(a, 9), DA(a, 15), DA(a, 21), DA(a, 27),
  372. DA(a, 33), DA(a, 39), DA(a, 45)) << 3;
  373. hash |=
  374. XOR8(DA(a, 4), DA(a, 10), DA(a, 16), DA(a, 22), DA(a, 28),
  375. DA(a, 34), DA(a, 40), DA(a, 46)) << 4;
  376. hash |=
  377. XOR8(DA(a, 5), DA(a, 11), DA(a, 17), DA(a, 23), DA(a, 29),
  378. DA(a, 35), DA(a, 41), DA(a, 47)) << 5;
  379. return hash;
  380. }
  381. #endif /* I_LIKE_A_FAST_HASH_FUNCTION */