tsec.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * tsec.h
  3. *
  4. * Driver for the Motorola Triple Speed Ethernet Controller
  5. *
  6. * This software may be used and distributed according to the
  7. * terms of the GNU Public License, Version 2, incorporated
  8. * herein by reference.
  9. *
  10. * Copyright 2004, 2007, 2009, 2011, 2013 Freescale Semiconductor, Inc.
  11. * (C) Copyright 2003, Motorola, Inc.
  12. * maintained by Xianghua Xiao (x.xiao@motorola.com)
  13. * author Andy Fleming
  14. *
  15. */
  16. #ifndef __TSEC_H
  17. #define __TSEC_H
  18. #include <net.h>
  19. #include <config.h>
  20. #include <phy.h>
  21. #include <asm/fsl_enet.h>
  22. #define TSEC_SIZE 0x01000
  23. #define TSEC_MDIO_OFFSET 0x01000
  24. #define CONFIG_SYS_MDIO_BASE_ADDR (MDIO_BASE_ADDR + 0x520)
  25. #define TSEC_GET_REGS(num, offset) \
  26. (struct tsec __iomem *)\
  27. (TSEC_BASE_ADDR + (((num) - 1) * (offset)))
  28. #define TSEC_GET_REGS_BASE(num) \
  29. TSEC_GET_REGS((num), TSEC_SIZE)
  30. #define TSEC_GET_MDIO_REGS(num, offset) \
  31. (struct tsec_mii_mng __iomem *)\
  32. (CONFIG_SYS_MDIO_BASE_ADDR + ((num) - 1) * (offset))
  33. #define TSEC_GET_MDIO_REGS_BASE(num) \
  34. TSEC_GET_MDIO_REGS((num), TSEC_MDIO_OFFSET)
  35. #define DEFAULT_MII_NAME "FSL_MDIO"
  36. #define STD_TSEC_INFO(num) \
  37. { \
  38. .regs = TSEC_GET_REGS_BASE(num), \
  39. .miiregs_sgmii = TSEC_GET_MDIO_REGS_BASE(num), \
  40. .devname = CONFIG_TSEC##num##_NAME, \
  41. .phyaddr = TSEC##num##_PHY_ADDR, \
  42. .flags = TSEC##num##_FLAGS, \
  43. .mii_devname = DEFAULT_MII_NAME \
  44. }
  45. #define SET_STD_TSEC_INFO(x, num) \
  46. { \
  47. x.regs = TSEC_GET_REGS_BASE(num); \
  48. x.miiregs_sgmii = TSEC_GET_MDIO_REGS_BASE(num); \
  49. x.devname = CONFIG_TSEC##num##_NAME; \
  50. x.phyaddr = TSEC##num##_PHY_ADDR; \
  51. x.flags = TSEC##num##_FLAGS;\
  52. x.mii_devname = DEFAULT_MII_NAME;\
  53. }
  54. #define MAC_ADDR_LEN 6
  55. /* #define TSEC_TIMEOUT 1000000 */
  56. #define TSEC_TIMEOUT 1000
  57. #define TOUT_LOOP 1000000
  58. /* TBI register addresses */
  59. #define TBI_CR 0x00
  60. #define TBI_SR 0x01
  61. #define TBI_ANA 0x04
  62. #define TBI_ANLPBPA 0x05
  63. #define TBI_ANEX 0x06
  64. #define TBI_TBICON 0x11
  65. /* TBI MDIO register bit fields*/
  66. #define TBICON_CLK_SELECT 0x0020
  67. #define TBIANA_ASYMMETRIC_PAUSE 0x0100
  68. #define TBIANA_SYMMETRIC_PAUSE 0x0080
  69. #define TBIANA_HALF_DUPLEX 0x0040
  70. #define TBIANA_FULL_DUPLEX 0x0020
  71. #define TBICR_PHY_RESET 0x8000
  72. #define TBICR_ANEG_ENABLE 0x1000
  73. #define TBICR_RESTART_ANEG 0x0200
  74. #define TBICR_FULL_DUPLEX 0x0100
  75. #define TBICR_SPEED1_SET 0x0040
  76. /* MAC register bits */
  77. #define MACCFG1_SOFT_RESET 0x80000000
  78. #define MACCFG1_RESET_RX_MC 0x00080000
  79. #define MACCFG1_RESET_TX_MC 0x00040000
  80. #define MACCFG1_RESET_RX_FUN 0x00020000
  81. #define MACCFG1_RESET_TX_FUN 0x00010000
  82. #define MACCFG1_LOOPBACK 0x00000100
  83. #define MACCFG1_RX_FLOW 0x00000020
  84. #define MACCFG1_TX_FLOW 0x00000010
  85. #define MACCFG1_SYNCD_RX_EN 0x00000008
  86. #define MACCFG1_RX_EN 0x00000004
  87. #define MACCFG1_SYNCD_TX_EN 0x00000002
  88. #define MACCFG1_TX_EN 0x00000001
  89. #define MACCFG2_INIT_SETTINGS 0x00007205
  90. #define MACCFG2_FULL_DUPLEX 0x00000001
  91. #define MACCFG2_IF 0x00000300
  92. #define MACCFG2_GMII 0x00000200
  93. #define MACCFG2_MII 0x00000100
  94. #define ECNTRL_INIT_SETTINGS 0x00001000
  95. #define ECNTRL_TBI_MODE 0x00000020
  96. #define ECNTRL_REDUCED_MODE 0x00000010
  97. #define ECNTRL_R100 0x00000008
  98. #define ECNTRL_REDUCED_MII_MODE 0x00000004
  99. #define ECNTRL_SGMII_MODE 0x00000002
  100. #ifndef CONFIG_SYS_TBIPA_VALUE
  101. #define CONFIG_SYS_TBIPA_VALUE 0x1f
  102. #endif
  103. #define MRBLR_INIT_SETTINGS PKTSIZE_ALIGN
  104. #define MINFLR_INIT_SETTINGS 0x00000040
  105. #define DMACTRL_INIT_SETTINGS 0x000000c3
  106. #define DMACTRL_GRS 0x00000010
  107. #define DMACTRL_GTS 0x00000008
  108. #define TSTAT_CLEAR_THALT 0x80000000
  109. #define RSTAT_CLEAR_RHALT 0x00800000
  110. #define IEVENT_INIT_CLEAR 0xffffffff
  111. #define IEVENT_BABR 0x80000000
  112. #define IEVENT_RXC 0x40000000
  113. #define IEVENT_BSY 0x20000000
  114. #define IEVENT_EBERR 0x10000000
  115. #define IEVENT_MSRO 0x04000000
  116. #define IEVENT_GTSC 0x02000000
  117. #define IEVENT_BABT 0x01000000
  118. #define IEVENT_TXC 0x00800000
  119. #define IEVENT_TXE 0x00400000
  120. #define IEVENT_TXB 0x00200000
  121. #define IEVENT_TXF 0x00100000
  122. #define IEVENT_IE 0x00080000
  123. #define IEVENT_LC 0x00040000
  124. #define IEVENT_CRL 0x00020000
  125. #define IEVENT_XFUN 0x00010000
  126. #define IEVENT_RXB0 0x00008000
  127. #define IEVENT_GRSC 0x00000100
  128. #define IEVENT_RXF0 0x00000080
  129. #define IMASK_INIT_CLEAR 0x00000000
  130. #define IMASK_TXEEN 0x00400000
  131. #define IMASK_TXBEN 0x00200000
  132. #define IMASK_TXFEN 0x00100000
  133. #define IMASK_RXFEN0 0x00000080
  134. /* Default Attribute fields */
  135. #define ATTR_INIT_SETTINGS 0x000000c0
  136. #define ATTRELI_INIT_SETTINGS 0x00000000
  137. /* TxBD status field bits */
  138. #define TXBD_READY 0x8000
  139. #define TXBD_PADCRC 0x4000
  140. #define TXBD_WRAP 0x2000
  141. #define TXBD_INTERRUPT 0x1000
  142. #define TXBD_LAST 0x0800
  143. #define TXBD_CRC 0x0400
  144. #define TXBD_DEF 0x0200
  145. #define TXBD_HUGEFRAME 0x0080
  146. #define TXBD_LATECOLLISION 0x0080
  147. #define TXBD_RETRYLIMIT 0x0040
  148. #define TXBD_RETRYCOUNTMASK 0x003c
  149. #define TXBD_UNDERRUN 0x0002
  150. #define TXBD_STATS 0x03ff
  151. /* RxBD status field bits */
  152. #define RXBD_EMPTY 0x8000
  153. #define RXBD_RO1 0x4000
  154. #define RXBD_WRAP 0x2000
  155. #define RXBD_INTERRUPT 0x1000
  156. #define RXBD_LAST 0x0800
  157. #define RXBD_FIRST 0x0400
  158. #define RXBD_MISS 0x0100
  159. #define RXBD_BROADCAST 0x0080
  160. #define RXBD_MULTICAST 0x0040
  161. #define RXBD_LARGE 0x0020
  162. #define RXBD_NONOCTET 0x0010
  163. #define RXBD_SHORT 0x0008
  164. #define RXBD_CRCERR 0x0004
  165. #define RXBD_OVERRUN 0x0002
  166. #define RXBD_TRUNCATED 0x0001
  167. #define RXBD_STATS 0x003f
  168. typedef struct txbd8
  169. {
  170. ushort status; /* Status Fields */
  171. ushort length; /* Buffer length */
  172. uint bufptr; /* Buffer Pointer */
  173. } txbd8_t;
  174. typedef struct rxbd8
  175. {
  176. ushort status; /* Status Fields */
  177. ushort length; /* Buffer Length */
  178. uint bufptr; /* Buffer Pointer */
  179. } rxbd8_t;
  180. typedef struct rmon_mib
  181. {
  182. /* Transmit and Receive Counters */
  183. uint tr64; /* Transmit and Receive 64-byte Frame Counter */
  184. uint tr127; /* Transmit and Receive 65-127 byte Frame Counter */
  185. uint tr255; /* Transmit and Receive 128-255 byte Frame Counter */
  186. uint tr511; /* Transmit and Receive 256-511 byte Frame Counter */
  187. uint tr1k; /* Transmit and Receive 512-1023 byte Frame Counter */
  188. uint trmax; /* Transmit and Receive 1024-1518 byte Frame Counter */
  189. uint trmgv; /* Transmit and Receive 1519-1522 byte Good VLAN Frame */
  190. /* Receive Counters */
  191. uint rbyt; /* Receive Byte Counter */
  192. uint rpkt; /* Receive Packet Counter */
  193. uint rfcs; /* Receive FCS Error Counter */
  194. uint rmca; /* Receive Multicast Packet (Counter) */
  195. uint rbca; /* Receive Broadcast Packet */
  196. uint rxcf; /* Receive Control Frame Packet */
  197. uint rxpf; /* Receive Pause Frame Packet */
  198. uint rxuo; /* Receive Unknown OP Code */
  199. uint raln; /* Receive Alignment Error */
  200. uint rflr; /* Receive Frame Length Error */
  201. uint rcde; /* Receive Code Error */
  202. uint rcse; /* Receive Carrier Sense Error */
  203. uint rund; /* Receive Undersize Packet */
  204. uint rovr; /* Receive Oversize Packet */
  205. uint rfrg; /* Receive Fragments */
  206. uint rjbr; /* Receive Jabber */
  207. uint rdrp; /* Receive Drop */
  208. /* Transmit Counters */
  209. uint tbyt; /* Transmit Byte Counter */
  210. uint tpkt; /* Transmit Packet */
  211. uint tmca; /* Transmit Multicast Packet */
  212. uint tbca; /* Transmit Broadcast Packet */
  213. uint txpf; /* Transmit Pause Control Frame */
  214. uint tdfr; /* Transmit Deferral Packet */
  215. uint tedf; /* Transmit Excessive Deferral Packet */
  216. uint tscl; /* Transmit Single Collision Packet */
  217. /* (0x2_n700) */
  218. uint tmcl; /* Transmit Multiple Collision Packet */
  219. uint tlcl; /* Transmit Late Collision Packet */
  220. uint txcl; /* Transmit Excessive Collision Packet */
  221. uint tncl; /* Transmit Total Collision */
  222. uint res2;
  223. uint tdrp; /* Transmit Drop Frame */
  224. uint tjbr; /* Transmit Jabber Frame */
  225. uint tfcs; /* Transmit FCS Error */
  226. uint txcf; /* Transmit Control Frame */
  227. uint tovr; /* Transmit Oversize Frame */
  228. uint tund; /* Transmit Undersize Frame */
  229. uint tfrg; /* Transmit Fragments Frame */
  230. /* General Registers */
  231. uint car1; /* Carry Register One */
  232. uint car2; /* Carry Register Two */
  233. uint cam1; /* Carry Register One Mask */
  234. uint cam2; /* Carry Register Two Mask */
  235. } rmon_mib_t;
  236. typedef struct tsec_hash_regs
  237. {
  238. uint iaddr0; /* Individual Address Register 0 */
  239. uint iaddr1; /* Individual Address Register 1 */
  240. uint iaddr2; /* Individual Address Register 2 */
  241. uint iaddr3; /* Individual Address Register 3 */
  242. uint iaddr4; /* Individual Address Register 4 */
  243. uint iaddr5; /* Individual Address Register 5 */
  244. uint iaddr6; /* Individual Address Register 6 */
  245. uint iaddr7; /* Individual Address Register 7 */
  246. uint res1[24];
  247. uint gaddr0; /* Group Address Register 0 */
  248. uint gaddr1; /* Group Address Register 1 */
  249. uint gaddr2; /* Group Address Register 2 */
  250. uint gaddr3; /* Group Address Register 3 */
  251. uint gaddr4; /* Group Address Register 4 */
  252. uint gaddr5; /* Group Address Register 5 */
  253. uint gaddr6; /* Group Address Register 6 */
  254. uint gaddr7; /* Group Address Register 7 */
  255. uint res2[24];
  256. } tsec_hash_t;
  257. struct tsec {
  258. /* General Control and Status Registers (0x2_n000) */
  259. uint res000[4];
  260. uint ievent; /* Interrupt Event */
  261. uint imask; /* Interrupt Mask */
  262. uint edis; /* Error Disabled */
  263. uint res01c;
  264. uint ecntrl; /* Ethernet Control */
  265. uint minflr; /* Minimum Frame Length */
  266. uint ptv; /* Pause Time Value */
  267. uint dmactrl; /* DMA Control */
  268. uint tbipa; /* TBI PHY Address */
  269. uint res034[3];
  270. uint res040[48];
  271. /* Transmit Control and Status Registers (0x2_n100) */
  272. uint tctrl; /* Transmit Control */
  273. uint tstat; /* Transmit Status */
  274. uint res108;
  275. uint tbdlen; /* Tx BD Data Length */
  276. uint res110[5];
  277. uint ctbptr; /* Current TxBD Pointer */
  278. uint res128[23];
  279. uint tbptr; /* TxBD Pointer */
  280. uint res188[30];
  281. /* (0x2_n200) */
  282. uint res200;
  283. uint tbase; /* TxBD Base Address */
  284. uint res208[42];
  285. uint ostbd; /* Out of Sequence TxBD */
  286. uint ostbdp; /* Out of Sequence Tx Data Buffer Pointer */
  287. uint res2b8[18];
  288. /* Receive Control and Status Registers (0x2_n300) */
  289. uint rctrl; /* Receive Control */
  290. uint rstat; /* Receive Status */
  291. uint res308;
  292. uint rbdlen; /* RxBD Data Length */
  293. uint res310[4];
  294. uint res320;
  295. uint crbptr; /* Current Receive Buffer Pointer */
  296. uint res328[6];
  297. uint mrblr; /* Maximum Receive Buffer Length */
  298. uint res344[16];
  299. uint rbptr; /* RxBD Pointer */
  300. uint res388[30];
  301. /* (0x2_n400) */
  302. uint res400;
  303. uint rbase; /* RxBD Base Address */
  304. uint res408[62];
  305. /* MAC Registers (0x2_n500) */
  306. uint maccfg1; /* MAC Configuration #1 */
  307. uint maccfg2; /* MAC Configuration #2 */
  308. uint ipgifg; /* Inter Packet Gap/Inter Frame Gap */
  309. uint hafdup; /* Half-duplex */
  310. uint maxfrm; /* Maximum Frame */
  311. uint res514;
  312. uint res518;
  313. uint res51c;
  314. uint resmdio[6];
  315. uint res538;
  316. uint ifstat; /* Interface Status */
  317. uint macstnaddr1; /* Station Address, part 1 */
  318. uint macstnaddr2; /* Station Address, part 2 */
  319. uint res548[46];
  320. /* (0x2_n600) */
  321. uint res600[32];
  322. /* RMON MIB Registers (0x2_n680-0x2_n73c) */
  323. rmon_mib_t rmon;
  324. uint res740[48];
  325. /* Hash Function Registers (0x2_n800) */
  326. tsec_hash_t hash;
  327. uint res900[128];
  328. /* Pattern Registers (0x2_nb00) */
  329. uint resb00[62];
  330. uint attr; /* Default Attribute Register */
  331. uint attreli; /* Default Attribute Extract Length and Index */
  332. /* TSEC Future Expansion Space (0x2_nc00-0x2_nffc) */
  333. uint resc00[256];
  334. };
  335. #define TSEC_GIGABIT (1 << 0)
  336. /* These flags currently only have meaning if we're using the eTSEC */
  337. #define TSEC_REDUCED (1 << 1) /* MAC-PHY interface uses RGMII */
  338. #define TSEC_SGMII (1 << 2) /* MAC-PHY interface uses SGMII */
  339. struct tsec_private {
  340. struct tsec __iomem *regs;
  341. struct tsec_mii_mng __iomem *phyregs_sgmii;
  342. struct phy_device *phydev;
  343. phy_interface_t interface;
  344. struct mii_dev *bus;
  345. uint phyaddr;
  346. char mii_devname[16];
  347. u32 flags;
  348. };
  349. struct tsec_info_struct {
  350. struct tsec __iomem *regs;
  351. struct tsec_mii_mng __iomem *miiregs_sgmii;
  352. char *devname;
  353. char *mii_devname;
  354. phy_interface_t interface;
  355. unsigned int phyaddr;
  356. u32 flags;
  357. };
  358. int tsec_standard_init(bd_t *bis);
  359. int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsec_info, int num);
  360. #endif /* __TSEC_H */