tlan.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. #ifndef TLAN_H
  2. #define TLAN_H
  3. /********************************************************************
  4. *
  5. * Linux ThunderLAN Driver
  6. *
  7. * tlan.h
  8. * by James Banks
  9. *
  10. * (C) 1997-1998 Caldera, Inc.
  11. * (C) 1999-2001 Torben Mathiasen
  12. *
  13. * This software may be used and distributed according to the terms
  14. * of the GNU General Public License, incorporated herein by reference.
  15. *
  16. *
  17. * Dec 10, 1999 Torben Mathiasen <torben.mathiasen@compaq.com>
  18. * New Maintainer
  19. *
  20. ********************************************************************/
  21. #include <asm/io.h>
  22. #include <asm/types.h>
  23. #include <linux/netdevice.h>
  24. /*****************************************************************
  25. * TLan Definitions
  26. *
  27. ****************************************************************/
  28. #define TLAN_MIN_FRAME_SIZE 64
  29. #define TLAN_MAX_FRAME_SIZE 1600
  30. #define TLAN_NUM_RX_LISTS 32
  31. #define TLAN_NUM_TX_LISTS 64
  32. #define TLAN_IGNORE 0
  33. #define TLAN_RECORD 1
  34. #define TLAN_DBG(lvl, format, args...) \
  35. do { if (debug&lvl) printk(KERN_DEBUG "TLAN: " format, ##args ); } while(0)
  36. #define TLAN_DEBUG_GNRL 0x0001
  37. #define TLAN_DEBUG_TX 0x0002
  38. #define TLAN_DEBUG_RX 0x0004
  39. #define TLAN_DEBUG_LIST 0x0008
  40. #define TLAN_DEBUG_PROBE 0x0010
  41. #define TX_TIMEOUT (10*HZ) /* We need time for auto-neg */
  42. #define MAX_TLAN_BOARDS 8 /* Max number of boards installed at a time */
  43. /*****************************************************************
  44. * Device Identification Definitions
  45. *
  46. ****************************************************************/
  47. #define PCI_DEVICE_ID_NETELLIGENT_10_T2 0xB012
  48. #define PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100 0xB030
  49. #ifndef PCI_DEVICE_ID_OLICOM_OC2183
  50. #define PCI_DEVICE_ID_OLICOM_OC2183 0x0013
  51. #endif
  52. #ifndef PCI_DEVICE_ID_OLICOM_OC2325
  53. #define PCI_DEVICE_ID_OLICOM_OC2325 0x0012
  54. #endif
  55. #ifndef PCI_DEVICE_ID_OLICOM_OC2326
  56. #define PCI_DEVICE_ID_OLICOM_OC2326 0x0014
  57. #endif
  58. typedef struct tlan_adapter_entry {
  59. u16 vendorId;
  60. u16 deviceId;
  61. char *deviceLabel;
  62. u32 flags;
  63. u16 addrOfs;
  64. } TLanAdapterEntry;
  65. #define TLAN_ADAPTER_NONE 0x00000000
  66. #define TLAN_ADAPTER_UNMANAGED_PHY 0x00000001
  67. #define TLAN_ADAPTER_BIT_RATE_PHY 0x00000002
  68. #define TLAN_ADAPTER_USE_INTERN_10 0x00000004
  69. #define TLAN_ADAPTER_ACTIVITY_LED 0x00000008
  70. #define TLAN_SPEED_DEFAULT 0
  71. #define TLAN_SPEED_10 10
  72. #define TLAN_SPEED_100 100
  73. #define TLAN_DUPLEX_DEFAULT 0
  74. #define TLAN_DUPLEX_HALF 1
  75. #define TLAN_DUPLEX_FULL 2
  76. /*****************************************************************
  77. * EISA Definitions
  78. *
  79. ****************************************************************/
  80. #define EISA_ID 0xc80 /* EISA ID Registers */
  81. #define EISA_ID0 0xc80 /* EISA ID Register 0 */
  82. #define EISA_ID1 0xc81 /* EISA ID Register 1 */
  83. #define EISA_ID2 0xc82 /* EISA ID Register 2 */
  84. #define EISA_ID3 0xc83 /* EISA ID Register 3 */
  85. #define EISA_CR 0xc84 /* EISA Control Register */
  86. #define EISA_REG0 0xc88 /* EISA Configuration Register 0 */
  87. #define EISA_REG1 0xc89 /* EISA Configuration Register 1 */
  88. #define EISA_REG2 0xc8a /* EISA Configuration Register 2 */
  89. #define EISA_REG3 0xc8f /* EISA Configuration Register 3 */
  90. #define EISA_APROM 0xc90 /* Ethernet Address PROM */
  91. /*****************************************************************
  92. * Rx/Tx List Definitions
  93. *
  94. ****************************************************************/
  95. #define TLAN_BUFFERS_PER_LIST 10
  96. #define TLAN_LAST_BUFFER 0x80000000
  97. #define TLAN_CSTAT_UNUSED 0x8000
  98. #define TLAN_CSTAT_FRM_CMP 0x4000
  99. #define TLAN_CSTAT_READY 0x3000
  100. #define TLAN_CSTAT_EOC 0x0800
  101. #define TLAN_CSTAT_RX_ERROR 0x0400
  102. #define TLAN_CSTAT_PASS_CRC 0x0200
  103. #define TLAN_CSTAT_DP_PR 0x0100
  104. typedef struct tlan_buffer_ref_tag {
  105. u32 count;
  106. u32 address;
  107. } TLanBufferRef;
  108. typedef struct tlan_list_tag {
  109. u32 forward;
  110. u16 cStat;
  111. u16 frameSize;
  112. TLanBufferRef buffer[TLAN_BUFFERS_PER_LIST];
  113. } TLanList;
  114. typedef u8 TLanBuffer[TLAN_MAX_FRAME_SIZE];
  115. /*****************************************************************
  116. * PHY definitions
  117. *
  118. ****************************************************************/
  119. #define TLAN_PHY_MAX_ADDR 0x1F
  120. #define TLAN_PHY_NONE 0x20
  121. /*****************************************************************
  122. * TLAN Private Information Structure
  123. *
  124. ****************************************************************/
  125. typedef struct tlan_private_tag {
  126. struct net_device *nextDevice;
  127. struct pci_dev *pciDev;
  128. struct net_device *dev;
  129. void *dmaStorage;
  130. dma_addr_t dmaStorageDMA;
  131. unsigned int dmaSize;
  132. u8 *padBuffer;
  133. TLanList *rxList;
  134. dma_addr_t rxListDMA;
  135. u8 *rxBuffer;
  136. dma_addr_t rxBufferDMA;
  137. u32 rxHead;
  138. u32 rxTail;
  139. u32 rxEocCount;
  140. TLanList *txList;
  141. dma_addr_t txListDMA;
  142. u8 *txBuffer;
  143. dma_addr_t txBufferDMA;
  144. u32 txHead;
  145. u32 txInProgress;
  146. u32 txTail;
  147. u32 txBusyCount;
  148. u32 phyOnline;
  149. u32 timerSetAt;
  150. u32 timerType;
  151. struct timer_list timer;
  152. struct board *adapter;
  153. u32 adapterRev;
  154. u32 aui;
  155. u32 debug;
  156. u32 duplex;
  157. u32 phy[2];
  158. u32 phyNum;
  159. u32 speed;
  160. u8 tlanRev;
  161. u8 tlanFullDuplex;
  162. spinlock_t lock;
  163. u8 link;
  164. u8 is_eisa;
  165. struct work_struct tlan_tqueue;
  166. u8 neg_be_verbose;
  167. } TLanPrivateInfo;
  168. /*****************************************************************
  169. * TLan Driver Timer Definitions
  170. *
  171. ****************************************************************/
  172. #define TLAN_TIMER_LINK_BEAT 1
  173. #define TLAN_TIMER_ACTIVITY 2
  174. #define TLAN_TIMER_PHY_PDOWN 3
  175. #define TLAN_TIMER_PHY_PUP 4
  176. #define TLAN_TIMER_PHY_RESET 5
  177. #define TLAN_TIMER_PHY_START_LINK 6
  178. #define TLAN_TIMER_PHY_FINISH_AN 7
  179. #define TLAN_TIMER_FINISH_RESET 8
  180. #define TLAN_TIMER_ACT_DELAY (HZ/10)
  181. /*****************************************************************
  182. * TLan Driver Eeprom Definitions
  183. *
  184. ****************************************************************/
  185. #define TLAN_EEPROM_ACK 0
  186. #define TLAN_EEPROM_STOP 1
  187. /*****************************************************************
  188. * Host Register Offsets and Contents
  189. *
  190. ****************************************************************/
  191. #define TLAN_HOST_CMD 0x00
  192. #define TLAN_HC_GO 0x80000000
  193. #define TLAN_HC_STOP 0x40000000
  194. #define TLAN_HC_ACK 0x20000000
  195. #define TLAN_HC_CS_MASK 0x1FE00000
  196. #define TLAN_HC_EOC 0x00100000
  197. #define TLAN_HC_RT 0x00080000
  198. #define TLAN_HC_NES 0x00040000
  199. #define TLAN_HC_AD_RST 0x00008000
  200. #define TLAN_HC_LD_TMR 0x00004000
  201. #define TLAN_HC_LD_THR 0x00002000
  202. #define TLAN_HC_REQ_INT 0x00001000
  203. #define TLAN_HC_INT_OFF 0x00000800
  204. #define TLAN_HC_INT_ON 0x00000400
  205. #define TLAN_HC_AC_MASK 0x000000FF
  206. #define TLAN_CH_PARM 0x04
  207. #define TLAN_DIO_ADR 0x08
  208. #define TLAN_DA_ADR_INC 0x8000
  209. #define TLAN_DA_RAM_ADR 0x4000
  210. #define TLAN_HOST_INT 0x0A
  211. #define TLAN_HI_IV_MASK 0x1FE0
  212. #define TLAN_HI_IT_MASK 0x001C
  213. #define TLAN_DIO_DATA 0x0C
  214. /* ThunderLAN Internal Register DIO Offsets */
  215. #define TLAN_NET_CMD 0x00
  216. #define TLAN_NET_CMD_NRESET 0x80
  217. #define TLAN_NET_CMD_NWRAP 0x40
  218. #define TLAN_NET_CMD_CSF 0x20
  219. #define TLAN_NET_CMD_CAF 0x10
  220. #define TLAN_NET_CMD_NOBRX 0x08
  221. #define TLAN_NET_CMD_DUPLEX 0x04
  222. #define TLAN_NET_CMD_TRFRAM 0x02
  223. #define TLAN_NET_CMD_TXPACE 0x01
  224. #define TLAN_NET_SIO 0x01
  225. #define TLAN_NET_SIO_MINTEN 0x80
  226. #define TLAN_NET_SIO_ECLOK 0x40
  227. #define TLAN_NET_SIO_ETXEN 0x20
  228. #define TLAN_NET_SIO_EDATA 0x10
  229. #define TLAN_NET_SIO_NMRST 0x08
  230. #define TLAN_NET_SIO_MCLK 0x04
  231. #define TLAN_NET_SIO_MTXEN 0x02
  232. #define TLAN_NET_SIO_MDATA 0x01
  233. #define TLAN_NET_STS 0x02
  234. #define TLAN_NET_STS_MIRQ 0x80
  235. #define TLAN_NET_STS_HBEAT 0x40
  236. #define TLAN_NET_STS_TXSTOP 0x20
  237. #define TLAN_NET_STS_RXSTOP 0x10
  238. #define TLAN_NET_STS_RSRVD 0x0F
  239. #define TLAN_NET_MASK 0x03
  240. #define TLAN_NET_MASK_MASK7 0x80
  241. #define TLAN_NET_MASK_MASK6 0x40
  242. #define TLAN_NET_MASK_MASK5 0x20
  243. #define TLAN_NET_MASK_MASK4 0x10
  244. #define TLAN_NET_MASK_RSRVD 0x0F
  245. #define TLAN_NET_CONFIG 0x04
  246. #define TLAN_NET_CFG_RCLK 0x8000
  247. #define TLAN_NET_CFG_TCLK 0x4000
  248. #define TLAN_NET_CFG_BIT 0x2000
  249. #define TLAN_NET_CFG_RXCRC 0x1000
  250. #define TLAN_NET_CFG_PEF 0x0800
  251. #define TLAN_NET_CFG_1FRAG 0x0400
  252. #define TLAN_NET_CFG_1CHAN 0x0200
  253. #define TLAN_NET_CFG_MTEST 0x0100
  254. #define TLAN_NET_CFG_PHY_EN 0x0080
  255. #define TLAN_NET_CFG_MSMASK 0x007F
  256. #define TLAN_MAN_TEST 0x06
  257. #define TLAN_DEF_VENDOR_ID 0x08
  258. #define TLAN_DEF_DEVICE_ID 0x0A
  259. #define TLAN_DEF_REVISION 0x0C
  260. #define TLAN_DEF_SUBCLASS 0x0D
  261. #define TLAN_DEF_MIN_LAT 0x0E
  262. #define TLAN_DEF_MAX_LAT 0x0F
  263. #define TLAN_AREG_0 0x10
  264. #define TLAN_AREG_1 0x16
  265. #define TLAN_AREG_2 0x1C
  266. #define TLAN_AREG_3 0x22
  267. #define TLAN_HASH_1 0x28
  268. #define TLAN_HASH_2 0x2C
  269. #define TLAN_GOOD_TX_FRMS 0x30
  270. #define TLAN_TX_UNDERUNS 0x33
  271. #define TLAN_GOOD_RX_FRMS 0x34
  272. #define TLAN_RX_OVERRUNS 0x37
  273. #define TLAN_DEFERRED_TX 0x38
  274. #define TLAN_CRC_ERRORS 0x3A
  275. #define TLAN_CODE_ERRORS 0x3B
  276. #define TLAN_MULTICOL_FRMS 0x3C
  277. #define TLAN_SINGLECOL_FRMS 0x3E
  278. #define TLAN_EXCESSCOL_FRMS 0x40
  279. #define TLAN_LATE_COLS 0x41
  280. #define TLAN_CARRIER_LOSS 0x42
  281. #define TLAN_ACOMMIT 0x43
  282. #define TLAN_LED_REG 0x44
  283. #define TLAN_LED_ACT 0x10
  284. #define TLAN_LED_LINK 0x01
  285. #define TLAN_BSIZE_REG 0x45
  286. #define TLAN_MAX_RX 0x46
  287. #define TLAN_INT_DIS 0x48
  288. #define TLAN_ID_TX_EOC 0x04
  289. #define TLAN_ID_RX_EOF 0x02
  290. #define TLAN_ID_RX_EOC 0x01
  291. /* ThunderLAN Interrupt Codes */
  292. #define TLAN_INT_NUMBER_OF_INTS 8
  293. #define TLAN_INT_NONE 0x0000
  294. #define TLAN_INT_TX_EOF 0x0001
  295. #define TLAN_INT_STAT_OVERFLOW 0x0002
  296. #define TLAN_INT_RX_EOF 0x0003
  297. #define TLAN_INT_DUMMY 0x0004
  298. #define TLAN_INT_TX_EOC 0x0005
  299. #define TLAN_INT_STATUS_CHECK 0x0006
  300. #define TLAN_INT_RX_EOC 0x0007
  301. /* ThunderLAN MII Registers */
  302. /* Generic MII/PHY Registers */
  303. #define MII_GEN_CTL 0x00
  304. #define MII_GC_RESET 0x8000
  305. #define MII_GC_LOOPBK 0x4000
  306. #define MII_GC_SPEEDSEL 0x2000
  307. #define MII_GC_AUTOENB 0x1000
  308. #define MII_GC_PDOWN 0x0800
  309. #define MII_GC_ISOLATE 0x0400
  310. #define MII_GC_AUTORSRT 0x0200
  311. #define MII_GC_DUPLEX 0x0100
  312. #define MII_GC_COLTEST 0x0080
  313. #define MII_GC_RESERVED 0x007F
  314. #define MII_GEN_STS 0x01
  315. #define MII_GS_100BT4 0x8000
  316. #define MII_GS_100BTXFD 0x4000
  317. #define MII_GS_100BTXHD 0x2000
  318. #define MII_GS_10BTFD 0x1000
  319. #define MII_GS_10BTHD 0x0800
  320. #define MII_GS_RESERVED 0x07C0
  321. #define MII_GS_AUTOCMPLT 0x0020
  322. #define MII_GS_RFLT 0x0010
  323. #define MII_GS_AUTONEG 0x0008
  324. #define MII_GS_LINK 0x0004
  325. #define MII_GS_JABBER 0x0002
  326. #define MII_GS_EXTCAP 0x0001
  327. #define MII_GEN_ID_HI 0x02
  328. #define MII_GEN_ID_LO 0x03
  329. #define MII_GIL_OUI 0xFC00
  330. #define MII_GIL_MODEL 0x03F0
  331. #define MII_GIL_REVISION 0x000F
  332. #define MII_AN_ADV 0x04
  333. #define MII_AN_LPA 0x05
  334. #define MII_AN_EXP 0x06
  335. /* ThunderLAN Specific MII/PHY Registers */
  336. #define TLAN_TLPHY_ID 0x10
  337. #define TLAN_TLPHY_CTL 0x11
  338. #define TLAN_TC_IGLINK 0x8000
  339. #define TLAN_TC_SWAPOL 0x4000
  340. #define TLAN_TC_AUISEL 0x2000
  341. #define TLAN_TC_SQEEN 0x1000
  342. #define TLAN_TC_MTEST 0x0800
  343. #define TLAN_TC_RESERVED 0x07F8
  344. #define TLAN_TC_NFEW 0x0004
  345. #define TLAN_TC_INTEN 0x0002
  346. #define TLAN_TC_TINT 0x0001
  347. #define TLAN_TLPHY_STS 0x12
  348. #define TLAN_TS_MINT 0x8000
  349. #define TLAN_TS_PHOK 0x4000
  350. #define TLAN_TS_POLOK 0x2000
  351. #define TLAN_TS_TPENERGY 0x1000
  352. #define TLAN_TS_RESERVED 0x0FFF
  353. #define TLAN_TLPHY_PAR 0x19
  354. #define TLAN_PHY_CIM_STAT 0x0020
  355. #define TLAN_PHY_SPEED_100 0x0040
  356. #define TLAN_PHY_DUPLEX_FULL 0x0080
  357. #define TLAN_PHY_AN_EN_STAT 0x0400
  358. /* National Sem. & Level1 PHY id's */
  359. #define NAT_SEM_ID1 0x2000
  360. #define NAT_SEM_ID2 0x5C01
  361. #define LEVEL1_ID1 0x7810
  362. #define LEVEL1_ID2 0x0000
  363. #define CIRC_INC( a, b ) if ( ++a >= b ) a = 0
  364. /* Routines to access internal registers. */
  365. static inline u8 TLan_DioRead8(u16 base_addr, u16 internal_addr)
  366. {
  367. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  368. return (inb((base_addr + TLAN_DIO_DATA) + (internal_addr & 0x3)));
  369. } /* TLan_DioRead8 */
  370. static inline u16 TLan_DioRead16(u16 base_addr, u16 internal_addr)
  371. {
  372. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  373. return (inw((base_addr + TLAN_DIO_DATA) + (internal_addr & 0x2)));
  374. } /* TLan_DioRead16 */
  375. static inline u32 TLan_DioRead32(u16 base_addr, u16 internal_addr)
  376. {
  377. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  378. return (inl(base_addr + TLAN_DIO_DATA));
  379. } /* TLan_DioRead32 */
  380. static inline void TLan_DioWrite8(u16 base_addr, u16 internal_addr, u8 data)
  381. {
  382. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  383. outb(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x3));
  384. }
  385. static inline void TLan_DioWrite16(u16 base_addr, u16 internal_addr, u16 data)
  386. {
  387. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  388. outw(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x2));
  389. }
  390. static inline void TLan_DioWrite32(u16 base_addr, u16 internal_addr, u32 data)
  391. {
  392. outw(internal_addr, base_addr + TLAN_DIO_ADR);
  393. outl(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x2));
  394. }
  395. #define TLan_ClearBit( bit, port ) outb_p(inb_p(port) & ~bit, port)
  396. #define TLan_GetBit( bit, port ) ((int) (inb_p(port) & bit))
  397. #define TLan_SetBit( bit, port ) outb_p(inb_p(port) | bit, port)
  398. /*
  399. * given 6 bytes, view them as 8 6-bit numbers and return the XOR of those
  400. * the code below is about seven times as fast as the original code
  401. *
  402. * The original code was:
  403. *
  404. * u32 xor( u32 a, u32 b ) { return ( ( a && ! b ) || ( ! a && b ) ); }
  405. *
  406. * #define XOR8( a, b, c, d, e, f, g, h ) \
  407. * xor( a, xor( b, xor( c, xor( d, xor( e, xor( f, xor( g, h ) ) ) ) ) ) )
  408. * #define DA( a, bit ) ( ( (u8) a[bit/8] ) & ( (u8) ( 1 << bit%8 ) ) )
  409. *
  410. * hash = XOR8( DA(a,0), DA(a, 6), DA(a,12), DA(a,18), DA(a,24),
  411. * DA(a,30), DA(a,36), DA(a,42) );
  412. * hash |= XOR8( DA(a,1), DA(a, 7), DA(a,13), DA(a,19), DA(a,25),
  413. * DA(a,31), DA(a,37), DA(a,43) ) << 1;
  414. * hash |= XOR8( DA(a,2), DA(a, 8), DA(a,14), DA(a,20), DA(a,26),
  415. * DA(a,32), DA(a,38), DA(a,44) ) << 2;
  416. * hash |= XOR8( DA(a,3), DA(a, 9), DA(a,15), DA(a,21), DA(a,27),
  417. * DA(a,33), DA(a,39), DA(a,45) ) << 3;
  418. * hash |= XOR8( DA(a,4), DA(a,10), DA(a,16), DA(a,22), DA(a,28),
  419. * DA(a,34), DA(a,40), DA(a,46) ) << 4;
  420. * hash |= XOR8( DA(a,5), DA(a,11), DA(a,17), DA(a,23), DA(a,29),
  421. * DA(a,35), DA(a,41), DA(a,47) ) << 5;
  422. *
  423. */
  424. static inline u32 TLan_HashFunc( const u8 *a )
  425. {
  426. u8 hash;
  427. hash = (a[0]^a[3]); /* & 077 */
  428. hash ^= ((a[0]^a[3])>>6); /* & 003 */
  429. hash ^= ((a[1]^a[4])<<2); /* & 074 */
  430. hash ^= ((a[1]^a[4])>>4); /* & 017 */
  431. hash ^= ((a[2]^a[5])<<4); /* & 060 */
  432. hash ^= ((a[2]^a[5])>>2); /* & 077 */
  433. return (hash & 077);
  434. }
  435. #endif