ax88180.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* ax88180.h: ASIX AX88180 Non-PCI Gigabit Ethernet u-boot driver */
  2. /*
  3. *
  4. * This program is free software; you can distribute it and/or modify it
  5. * under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. * for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16. *
  17. */
  18. #ifndef _AX88180_H_
  19. #define _AX88180_H_
  20. #include <asm/types.h>
  21. #include <config.h>
  22. typedef enum _ax88180_link_state {
  23. INS_LINK_DOWN,
  24. INS_LINK_UP,
  25. INS_LINK_UNKNOWN
  26. } ax88180_link_state;
  27. struct ax88180_private {
  28. unsigned char BusWidth;
  29. unsigned char PadSize;
  30. unsigned short PhyAddr;
  31. unsigned short PhyID0;
  32. unsigned short FirstTxDesc;
  33. unsigned short NextTxDesc;
  34. ax88180_link_state LinkState;
  35. };
  36. #define BUS_WIDTH_16 1
  37. #define BUS_WIDTH_32 2
  38. #define ENABLE_JUMBO 1
  39. #define DISABLE_JUMBO 0
  40. #define ENABLE_BURST 1
  41. #define DISABLE_BURST 0
  42. #define NORMAL_RX_MODE 0
  43. #define RX_LOOPBACK_MODE 1
  44. #define RX_INIFINIT_LOOP_MODE 2
  45. #define TX_INIFINIT_LOOP_MODE 3
  46. #define DEFAULT_ETH_MTU 1500
  47. /* Jumbo packet size 4086 bytes included 4 bytes CRC*/
  48. #define MAX_JUMBO_MTU 4072
  49. /* Max Tx Jumbo size 4086 bytes included 4 bytes CRC */
  50. #define MAX_TX_JUMBO_SIZE 4086
  51. /* Max Rx Jumbo size is 15K Bytes */
  52. #define MAX_RX_SIZE 0x3C00
  53. #define MARVELL_88E1111_PHYADDR 0x18
  54. #define MARVELL_88E1111_PHYIDR0 0x0141
  55. #define CICADA_CIS8201_PHYADDR 0x01
  56. #define CICADA_CIS8201_PHYIDR0 0x000F
  57. #define MEDIA_AUTO 0
  58. #define MEDIA_1000FULL 1
  59. #define MEDIA_1000HALF 2
  60. #define MEDIA_100FULL 3
  61. #define MEDIA_100HALF 4
  62. #define MEDIA_10FULL 5
  63. #define MEDIA_10HALF 6
  64. #define MEDIA_UNKNOWN 7
  65. #define AUTO_MEDIA 0
  66. #define FORCE_MEDIA 1
  67. #define TXDP_MASK 3
  68. #define TXDP0 0
  69. #define TXDP1 1
  70. #define TXDP2 2
  71. #define TXDP3 3
  72. #define CMD_MAP_SIZE 0x100
  73. #if defined (CONFIG_DRIVER_AX88180_16BIT)
  74. #define AX88180_MEMORY_SIZE 0x00004000
  75. #define START_BASE 0x1000
  76. #define RX_BUF_SIZE 0x1000
  77. #define TX_BUF_SIZE 0x0F00
  78. #define TX_BASE START_BASE
  79. #define CMD_BASE (TX_BASE + TX_BUF_SIZE)
  80. #define RX_BASE (CMD_BASE + CMD_MAP_SIZE)
  81. #else
  82. #define AX88180_MEMORY_SIZE 0x00010000
  83. #define RX_BUF_SIZE 0x8000
  84. #define TX_BUF_SIZE 0x7C00
  85. #define RX_BASE 0x0000
  86. #define TX_BASE (RX_BASE + RX_BUF_SIZE)
  87. #define CMD_BASE (TX_BASE + TX_BUF_SIZE)
  88. #endif
  89. /* AX88180 Memory Mapping Definition */
  90. #define RXBUFFER_START RX_BASE
  91. #define RX_PACKET_LEN_OFFSET 0
  92. #define RX_PAGE_NUM_MASK 0x7FF /* RX pages 0~7FFh */
  93. #define TXBUFFER_START TX_BASE
  94. /* AX88180 MAC Register Definition */
  95. #define DECODE (0)
  96. #define DECODE_EN 0x00000001
  97. #define BASE (6)
  98. #define CMD (CMD_BASE + 0x0000)
  99. #define WAKEMOD 0x00000001
  100. #define TXEN 0x00000100
  101. #define RXEN 0x00000200
  102. #define DEFAULT_CMD WAKEMOD
  103. #define IMR (CMD_BASE + 0x0004)
  104. #define IMR_RXBUFFOVR 0x00000001
  105. #define IMR_WATCHDOG 0x00000002
  106. #define IMR_TX 0x00000008
  107. #define IMR_RX 0x00000010
  108. #define IMR_PHY 0x00000020
  109. #define CLEAR_IMR 0x00000000
  110. #define DEFAULT_IMR (IMR_PHY | IMR_RX | IMR_TX |\
  111. IMR_RXBUFFOVR | IMR_WATCHDOG)
  112. #define ISR (CMD_BASE + 0x0008)
  113. #define ISR_RXBUFFOVR 0x00000001
  114. #define ISR_WATCHDOG 0x00000002
  115. #define ISR_TX 0x00000008
  116. #define ISR_RX 0x00000010
  117. #define ISR_PHY 0x00000020
  118. #define TXCFG (CMD_BASE + 0x0010)
  119. #define AUTOPAD_CRC 0x00000050
  120. #define DEFAULT_TXCFG AUTOPAD_CRC
  121. #define TXCMD (CMD_BASE + 0x0014)
  122. #define TXCMD_TXDP_MASK 0x00006000
  123. #define TXCMD_TXDP0 0x00000000
  124. #define TXCMD_TXDP1 0x00002000
  125. #define TXCMD_TXDP2 0x00004000
  126. #define TXCMD_TXDP3 0x00006000
  127. #define TX_START_WRITE 0x00008000
  128. #define TX_STOP_WRITE 0x00000000
  129. #define DEFAULT_TXCMD 0x00000000
  130. #define TXBS (CMD_BASE + 0x0018)
  131. #define TXDP0_USED 0x00000001
  132. #define TXDP1_USED 0x00000002
  133. #define TXDP2_USED 0x00000004
  134. #define TXDP3_USED 0x00000008
  135. #define DEFAULT_TXBS 0x00000000
  136. #define TXDES0 (CMD_BASE + 0x0020)
  137. #define TXDPx_ENABLE 0x00008000
  138. #define TXDPx_LEN_MASK 0x00001FFF
  139. #define DEFAULT_TXDES0 0x00000000
  140. #define TXDES1 (CMD_BASE + 0x0024)
  141. #define TXDPx_ENABLE 0x00008000
  142. #define TXDPx_LEN_MASK 0x00001FFF
  143. #define DEFAULT_TXDES1 0x00000000
  144. #define TXDES2 (CMD_BASE + 0x0028)
  145. #define TXDPx_ENABLE 0x00008000
  146. #define TXDPx_LEN_MASK 0x00001FFF
  147. #define DEFAULT_TXDES2 0x00000000
  148. #define TXDES3 (CMD_BASE + 0x002C)
  149. #define TXDPx_ENABLE 0x00008000
  150. #define TXDPx_LEN_MASK 0x00001FFF
  151. #define DEFAULT_TXDES3 0x00000000
  152. #define RXCFG (CMD_BASE + 0x0030)
  153. #define RXBUFF_PROTECT 0x00000001
  154. #define RXTCPCRC_CHECK 0x00000010
  155. #define RXFLOW_ENABLE 0x00000100
  156. #define DEFAULT_RXCFG RXBUFF_PROTECT
  157. #define RXCURT (CMD_BASE + 0x0034)
  158. #define DEFAULT_RXCURT 0x00000000
  159. #define RXBOUND (CMD_BASE + 0x0038)
  160. #define DEFAULT_RXBOUND 0x7FF /* RX pages 0~7FFh */
  161. #define MACCFG0 (CMD_BASE + 0x0040)
  162. #define MACCFG0_BIT3_0 0x00000007
  163. #define IPGT_VAL 0x00000150
  164. #define TXFLOW_ENABLE 0x00001000
  165. #define SPEED100 0x00008000
  166. #define DEFAULT_MACCFG0 (IPGT_VAL | MACCFG0_BIT3_0)
  167. #define MACCFG1 (CMD_BASE + 0x0044)
  168. #define RGMII_EN 0x00000002
  169. #define RXFLOW_EN 0x00000020
  170. #define FULLDUPLEX 0x00000040
  171. #define MAX_JUMBO_LEN 0x00000780
  172. #define RXJUMBO_EN 0x00000800
  173. #define GIGA_MODE_EN 0x00001000
  174. #define RXCRC_CHECK 0x00002000
  175. #define RXPAUSE_DA_CHECK 0x00004000
  176. #define JUMBO_LEN_4K 0x00000200
  177. #define JUMBO_LEN_15K 0x00000780
  178. #define DEFAULT_MACCFG1 (RXCRC_CHECK | RXPAUSE_DA_CHECK | \
  179. RGMII_EN)
  180. #define CICADA_DEFAULT_MACCFG1 (RXCRC_CHECK | RXPAUSE_DA_CHECK)
  181. #define MACCFG2 (CMD_BASE + 0x0048)
  182. #define MACCFG2_BIT15_8 0x00000100
  183. #define JAM_LIMIT_MASK 0x000000FC
  184. #define DEFAULT_JAM_LIMIT 0x00000064
  185. #define DEFAULT_MACCFG2 MACCFG2_BIT15_8
  186. #define MACCFG3 (CMD_BASE + 0x004C)
  187. #define IPGR2_VAL 0x0000000E
  188. #define IPGR1_VAL 0x00000600
  189. #define NOABORT 0x00008000
  190. #define DEFAULT_MACCFG3 (IPGR1_VAL | IPGR2_VAL)
  191. #define TXPAUT (CMD_BASE + 0x0054)
  192. #define DEFAULT_TXPAUT 0x001FE000
  193. #define RXBTHD0 (CMD_BASE + 0x0058)
  194. #define DEFAULT_RXBTHD0 0x00000300
  195. #define RXBTHD1 (CMD_BASE + 0x005C)
  196. #define DEFAULT_RXBTHD1 0x00000600
  197. #define RXFULTHD (CMD_BASE + 0x0060)
  198. #define DEFAULT_RXFULTHD 0x00000100
  199. #define MISC (CMD_BASE + 0x0068)
  200. /* Normal operation mode */
  201. #define MISC_NORMAL 0x00000003
  202. /* Clear bit 0 to reset MAC */
  203. #define MISC_RESET_MAC 0x00000002
  204. /* Clear bit 1 to reset PHY */
  205. #define MISC_RESET_PHY 0x00000001
  206. /* Clear bit 0 and 1 to reset MAC and PHY */
  207. #define MISC_RESET_MAC_PHY 0x00000000
  208. #define DEFAULT_MISC MISC_NORMAL
  209. #define MACID0 (CMD_BASE + 0x0070)
  210. #define MACID1 (CMD_BASE + 0x0074)
  211. #define MACID2 (CMD_BASE + 0x0078)
  212. #define TXLEN (CMD_BASE + 0x007C)
  213. #define DEFAULT_TXLEN 0x000005FC
  214. #define RXFILTER (CMD_BASE + 0x0080)
  215. #define RX_RXANY 0x00000001
  216. #define RX_MULTICAST 0x00000002
  217. #define RX_UNICAST 0x00000004
  218. #define RX_BROADCAST 0x00000008
  219. #define RX_MULTI_HASH 0x00000010
  220. #define DISABLE_RXFILTER 0x00000000
  221. #define DEFAULT_RXFILTER (RX_BROADCAST + RX_UNICAST)
  222. #define MDIOCTRL (CMD_BASE + 0x0084)
  223. #define PHY_ADDR_MASK 0x0000001F
  224. #define REG_ADDR_MASK 0x00001F00
  225. #define READ_PHY 0x00004000
  226. #define WRITE_PHY 0x00008000
  227. #define MDIODP (CMD_BASE + 0x0088)
  228. #define GPIOCTRL (CMD_BASE + 0x008C)
  229. #define RXINDICATOR (CMD_BASE + 0x0090)
  230. #define RX_START_READ 0x00000001
  231. #define RX_STOP_READ 0x00000000
  232. #define DEFAULT_RXINDICATOR RX_STOP_READ
  233. #define TXST (CMD_BASE + 0x0094)
  234. #define MDCCLKPAT (CMD_BASE + 0x00A0)
  235. #define RXIPCRCCNT (CMD_BASE + 0x00A4)
  236. #define RXCRCCNT (CMD_BASE + 0x00A8)
  237. #define TXFAILCNT (CMD_BASE + 0x00AC)
  238. #define PROMDP (CMD_BASE + 0x00B0)
  239. #define PROMCTRL (CMD_BASE + 0x00B4)
  240. #define RELOAD_EEPROM 0x00000200
  241. #define MAXRXLEN (CMD_BASE + 0x00B8)
  242. #define HASHTAB0 (CMD_BASE + 0x00C0)
  243. #define HASHTAB1 (CMD_BASE + 0x00C4)
  244. #define HASHTAB2 (CMD_BASE + 0x00C8)
  245. #define HASHTAB3 (CMD_BASE + 0x00CC)
  246. #define DOGTHD0 (CMD_BASE + 0x00E0)
  247. #define DEFAULT_DOGTHD0 0x0000FFFF
  248. #define DOGTHD1 (CMD_BASE + 0x00E4)
  249. #define START_WATCHDOG_TIMER 0x00008000
  250. #define DEFAULT_DOGTHD1 0x00000FFF
  251. #define SOFTRST (CMD_BASE + 0x00EC)
  252. #define SOFTRST_NORMAL 0x00000003
  253. #define SOFTRST_RESET_MAC 0x00000002
  254. /* External PHY Register Definition */
  255. #define BMCR 0x0000
  256. #define LINE_SPEED_MSB 0x0040
  257. #define DUPLEX_MODE 0x0100
  258. #define RESTART_AUTONEG 0x0200
  259. #define POWER_DOWN 0x0800
  260. #define AUTONEG_EN 0x1000
  261. #define LINE_SPEED_LSB 0x2000
  262. #define PHY_RESET 0x8000
  263. #define MEDIAMODE_MASK (LINE_SPEED_MSB | LINE_SPEED_LSB |\
  264. DUPLEX_MODE)
  265. #define BMCR_SPEED_1000 LINE_SPEED_MSB
  266. #define BMCR_SPEED_100 LINE_SPEED_LSB
  267. #define BMCR_SPEED_10 0x0000
  268. #define BMCR_1000FULL (BMCR_SPEED_1000 | DUPLEX_MODE)
  269. #define BMCR_100FULL (BMCR_SPEED_100 | DUPLEX_MODE)
  270. #define BMCR_100HALF BMCR_SPEED_100
  271. #define BMCR_10FULL DUPLEX_MODE
  272. #define BMCR_10HALF 0x0000
  273. #define BMSR 0x0001
  274. #define LINKOK 0x0004
  275. #define AUTONEG_ENABLE_STS 0x0008
  276. #define AUTONEG_COMPLETE 0x0020
  277. #define PHYIDR0 0x0002
  278. #define PHYIDR1 0x0003
  279. #define ANAR 0x0004
  280. #define ANAR_PAUSE 0x0400
  281. #define ANAR_100FULL 0x0100
  282. #define ANAR_100HALF 0x0080
  283. #define ANAR_10FULL 0x0040
  284. #define ANAR_10HALF 0x0020
  285. #define ANAR_8023BIT 0x0001
  286. #define ANLPAR 0x0005
  287. #define ANER 0x0006
  288. #define AUX_1000_CTRL 0x0009
  289. #define ENABLE_1000HALF 0x0100
  290. #define ENABLE_1000FULL 0x0200
  291. #define DEFAULT_AUX_1000_CTRL (ENABLE_1000HALF | ENABLE_1000FULL)
  292. #define AUX_1000_STATUS 0x000A
  293. #define LP_1000HALF 0x0400
  294. #define LP_1000FULL 0x0800
  295. /* Marvell 88E1111 Gigabit PHY Register Definition */
  296. #define M88_SSR 0x0011
  297. #define SSR_SPEED_MASK 0xC000
  298. #define SSR_SPEED_1000 0x8000
  299. #define SSR_SPEED_100 0x4000
  300. #define SSR_SPEED_10 0x0000
  301. #define SSR_DUPLEX 0x2000
  302. #define SSR_MEDIA_RESOLVED_OK 0x0800
  303. #define SSR_MEDIA_MASK (SSR_SPEED_MASK | SSR_DUPLEX)
  304. #define SSR_1000FULL (SSR_SPEED_1000 | SSR_DUPLEX)
  305. #define SSR_1000HALF SSR_SPEED_1000
  306. #define SSR_100FULL (SSR_SPEED_100 | SSR_DUPLEX)
  307. #define SSR_100HALF SSR_SPEED_100
  308. #define SSR_10FULL (SSR_SPEED_10 | SSR_DUPLEX)
  309. #define SSR_10HALF SSR_SPEED_10
  310. #define M88_IER 0x0012
  311. #define LINK_CHANGE_INT 0x0400
  312. #define M88_ISR 0x0013
  313. #define LINK_CHANGE_STATUS 0x0400
  314. #define M88_EXT_SCR 0x0014
  315. #define RGMII_RXCLK_DELAY 0x0080
  316. #define RGMII_TXCLK_DELAY 0x0002
  317. #define DEFAULT_EXT_SCR (RGMII_TXCLK_DELAY | RGMII_RXCLK_DELAY)
  318. #define M88_EXT_SSR 0x001B
  319. #define HWCFG_MODE_MASK 0x000F
  320. #define RGMII_COPPER_MODE 0x000B
  321. /* CICADA CIS8201 Gigabit PHY Register Definition */
  322. #define CIS_IMR 0x0019
  323. #define CIS_INT_ENABLE 0x8000
  324. #define CIS_LINK_CHANGE_INT 0x2000
  325. #define CIS_ISR 0x001A
  326. #define CIS_INT_PENDING 0x8000
  327. #define CIS_LINK_CHANGE_STATUS 0x2000
  328. #define CIS_AUX_CTRL_STATUS 0x001C
  329. #define CIS_AUTONEG_COMPLETE 0x8000
  330. #define CIS_SPEED_MASK 0x0018
  331. #define CIS_SPEED_1000 0x0010
  332. #define CIS_SPEED_100 0x0008
  333. #define CIS_SPEED_10 0x0000
  334. #define CIS_DUPLEX 0x0020
  335. #define CIS_MEDIA_MASK (CIS_SPEED_MASK | CIS_DUPLEX)
  336. #define CIS_1000FULL (CIS_SPEED_1000 | CIS_DUPLEX)
  337. #define CIS_1000HALF CIS_SPEED_1000
  338. #define CIS_100FULL (CIS_SPEED_100 | CIS_DUPLEX)
  339. #define CIS_100HALF CIS_SPEED_100
  340. #define CIS_10FULL (CIS_SPEED_10 | CIS_DUPLEX)
  341. #define CIS_10HALF CIS_SPEED_10
  342. #define CIS_SMI_PRIORITY 0x0004
  343. static inline unsigned short INW (struct eth_device *dev, unsigned long addr)
  344. {
  345. return le16_to_cpu (*(volatile unsigned short *) (addr + dev->iobase));
  346. }
  347. static inline void OUTW (struct eth_device *dev, unsigned short command, unsigned long addr)
  348. {
  349. *(volatile unsigned short *) ((addr + dev->iobase)) = cpu_to_le16 (command);
  350. }
  351. /*
  352. Access RXBUFFER_START/TXBUFFER_START to read RX buffer/write TX buffer
  353. */
  354. #if defined (CONFIG_DRIVER_AX88180_16BIT)
  355. static inline unsigned short READ_RXBUF (struct eth_device *dev)
  356. {
  357. return le16_to_cpu (*(volatile unsigned short *) (RXBUFFER_START + dev->iobase));
  358. }
  359. static inline void WRITE_TXBUF (struct eth_device *dev, unsigned short data)
  360. {
  361. *(volatile unsigned short *) ((TXBUFFER_START + dev->iobase)) = cpu_to_le16 (data);
  362. }
  363. #else
  364. static inline unsigned long READ_RXBUF (struct eth_device *dev)
  365. {
  366. return le32_to_cpu (*(volatile unsigned long *) (RXBUFFER_START + dev->iobase));
  367. }
  368. static inline void WRITE_TXBUF (struct eth_device *dev, unsigned long data)
  369. {
  370. *(volatile unsigned long *) ((TXBUFFER_START + dev->iobase)) = cpu_to_le32 (data);
  371. }
  372. #endif
  373. #endif /* _AX88180_H_ */