tsec.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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 Freescale Semiconductor.
  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 <mpc85xx.h>
  20. #define TSEC_BASE_ADDR (CFG_IMMR + 0x24000)
  21. #define TSEC_SIZE 0x01000
  22. #define MAC_ADDR_LEN 6
  23. /* #define TSEC_TIMEOUT 1000000 */
  24. #define TSEC_TIMEOUT 1000
  25. #define TOUT_LOOP 1000000
  26. /* MAC register bits */
  27. #define MACCFG1_SOFT_RESET 0x80000000
  28. #define MACCFG1_RESET_RX_MC 0x00080000
  29. #define MACCFG1_RESET_TX_MC 0x00040000
  30. #define MACCFG1_RESET_RX_FUN 0x00020000
  31. #define MACCFG1_RESET_TX_FUN 0x00010000
  32. #define MACCFG1_LOOPBACK 0x00000100
  33. #define MACCFG1_RX_FLOW 0x00000020
  34. #define MACCFG1_TX_FLOW 0x00000010
  35. #define MACCFG1_SYNCD_RX_EN 0x00000008
  36. #define MACCFG1_RX_EN 0x00000004
  37. #define MACCFG1_SYNCD_TX_EN 0x00000002
  38. #define MACCFG1_TX_EN 0x00000001
  39. #define MACCFG2_INIT_SETTINGS 0x00007205
  40. #define MACCFG2_FULL_DUPLEX 0x00000001
  41. #define MACCFG2_IF 0x00000300
  42. #define MACCFG2_GMII 0x00000200
  43. #define MACCFG2_MII 0x00000100
  44. #define ECNTRL_INIT_SETTINGS 0x00001000
  45. #define ECNTRL_TBI_MODE 0x00000020
  46. #define miim_end -2
  47. #define miim_read -1
  48. #define TBIPA_VALUE 0x1f
  49. #define MIIMCFG_INIT_VALUE 0x00000003
  50. #define MIIMCFG_RESET 0x80000000
  51. #define MIIMIND_BUSY 0x00000001
  52. #define MIIMIND_NOTVALID 0x00000004
  53. #define MIIM_CONTROL 0x00
  54. #define MIIM_CONTROL_RESET 0x00009140
  55. #define MIIM_CONTROL_INIT 0x00001140
  56. #define MIIM_ANEN 0x00001000
  57. #define MIIM_CR 0x00
  58. #define MIIM_CR_RST 0x00008000
  59. #define MIIM_CR_INIT 0x00001000
  60. #define MIIM_STATUS 0x1
  61. #define MIIM_STATUS_AN_DONE 0x00000020
  62. #define MIIM_STATUS_LINK 0x0004
  63. #define MIIM_PHYIR1 0x2
  64. #define MIIM_PHYIR2 0x3
  65. #define MIIM_ANAR 0x4
  66. #define MIIM_ANAR_INIT 0x1e1
  67. #define MIIM_TBI_ANLPBPA 0x5
  68. #define MIIM_TBI_ANLPBPA_HALF 0x00000040
  69. #define MIIM_TBI_ANLPBPA_FULL 0x00000020
  70. #define MIIM_TBI_ANEX 0x6
  71. #define MIIM_TBI_ANEX_NP 0x00000004
  72. #define MIIM_TBI_ANEX_PRX 0x00000002
  73. #define MIIM_GBIT_CONTROL 0x9
  74. #define MIIM_GBIT_CONTROL_INIT 0xe00
  75. /* Cicada Auxiliary Control/Status Register */
  76. #define MIIM_CIS8201_AUX_CONSTAT 0x1c
  77. #define MIIM_CIS8201_AUXCONSTAT_INIT 0x0004
  78. #define MIIM_CIS8201_AUXCONSTAT_DUPLEX 0x0020
  79. #define MIIM_CIS8201_AUXCONSTAT_SPEED 0x0018
  80. #define MIIM_CIS8201_AUXCONSTAT_GBIT 0x0010
  81. #define MIIM_CIS8201_AUXCONSTAT_100 0x0008
  82. /* Cicada Extended Control Register 1 */
  83. #define MIIM_CIS8201_EXT_CON1 0x17
  84. #define MIIM_CIS8201_EXTCON1_INIT 0x0000
  85. /* Cicada 8204 Extended PHY Control Register 1 */
  86. #define MIIM_CIS8204_EPHY_CON 0x17
  87. #define MIIM_CIS8204_EPHYCON_INIT 0x0006
  88. /* Cicada 8204 Serial LED Control Register */
  89. #define MIIM_CIS8204_SLED_CON 0x1b
  90. #define MIIM_CIS8204_SLEDCON_INIT 0x1115
  91. #define MIIM_GBIT_CON 0x09
  92. #define MIIM_GBIT_CON_ADVERT 0x0e00
  93. /* 88E1011 PHY Status Register */
  94. #define MIIM_88E1011_PHY_STATUS 0x11
  95. #define MIIM_88E1011_PHYSTAT_SPEED 0xc000
  96. #define MIIM_88E1011_PHYSTAT_GBIT 0x8000
  97. #define MIIM_88E1011_PHYSTAT_100 0x4000
  98. #define MIIM_88E1011_PHYSTAT_DUPLEX 0x2000
  99. #define MIIM_88E1011_PHYSTAT_SPDDONE 0x0800
  100. #define MIIM_88E1011_PHYSTAT_LINK 0x0400
  101. /* DM9161 Control register values */
  102. #define MIIM_DM9161_CR_STOP 0x0400
  103. #define MIIM_DM9161_CR_RSTAN 0x1200
  104. #define MIIM_DM9161_SCR 0x10
  105. #define MIIM_DM9161_SCR_INIT 0x0610
  106. /* DM9161 Specified Configuration and Status Register */
  107. #define MIIM_DM9161_SCSR 0x11
  108. #define MIIM_DM9161_SCSR_100F 0x8000
  109. #define MIIM_DM9161_SCSR_100H 0x4000
  110. #define MIIM_DM9161_SCSR_10F 0x2000
  111. #define MIIM_DM9161_SCSR_10H 0x1000
  112. /* DM9161 10BT Configuration/Status */
  113. #define MIIM_DM9161_10BTCSR 0x12
  114. #define MIIM_DM9161_10BTCSR_INIT 0x7800
  115. #define MIIM_READ_COMMAND 0x00000001
  116. #define MRBLR_INIT_SETTINGS PKTSIZE_ALIGN
  117. #define MINFLR_INIT_SETTINGS 0x00000040
  118. #define DMACTRL_INIT_SETTINGS 0x000000c3
  119. #define DMACTRL_GRS 0x00000010
  120. #define DMACTRL_GTS 0x00000008
  121. #define TSTAT_CLEAR_THALT 0x80000000
  122. #define RSTAT_CLEAR_RHALT 0x00800000
  123. #define IEVENT_INIT_CLEAR 0xffffffff
  124. #define IEVENT_BABR 0x80000000
  125. #define IEVENT_RXC 0x40000000
  126. #define IEVENT_BSY 0x20000000
  127. #define IEVENT_EBERR 0x10000000
  128. #define IEVENT_MSRO 0x04000000
  129. #define IEVENT_GTSC 0x02000000
  130. #define IEVENT_BABT 0x01000000
  131. #define IEVENT_TXC 0x00800000
  132. #define IEVENT_TXE 0x00400000
  133. #define IEVENT_TXB 0x00200000
  134. #define IEVENT_TXF 0x00100000
  135. #define IEVENT_IE 0x00080000
  136. #define IEVENT_LC 0x00040000
  137. #define IEVENT_CRL 0x00020000
  138. #define IEVENT_XFUN 0x00010000
  139. #define IEVENT_RXB0 0x00008000
  140. #define IEVENT_GRSC 0x00000100
  141. #define IEVENT_RXF0 0x00000080
  142. #define IMASK_INIT_CLEAR 0x00000000
  143. #define IMASK_TXEEN 0x00400000
  144. #define IMASK_TXBEN 0x00200000
  145. #define IMASK_TXFEN 0x00100000
  146. #define IMASK_RXFEN0 0x00000080
  147. /* Default Attribute fields */
  148. #define ATTR_INIT_SETTINGS 0x000000c0
  149. #define ATTRELI_INIT_SETTINGS 0x00000000
  150. /* TxBD status field bits */
  151. #define TXBD_READY 0x8000
  152. #define TXBD_PADCRC 0x4000
  153. #define TXBD_WRAP 0x2000
  154. #define TXBD_INTERRUPT 0x1000
  155. #define TXBD_LAST 0x0800
  156. #define TXBD_CRC 0x0400
  157. #define TXBD_DEF 0x0200
  158. #define TXBD_HUGEFRAME 0x0080
  159. #define TXBD_LATECOLLISION 0x0080
  160. #define TXBD_RETRYLIMIT 0x0040
  161. #define TXBD_RETRYCOUNTMASK 0x003c
  162. #define TXBD_UNDERRUN 0x0002
  163. #define TXBD_STATS 0x03ff
  164. /* RxBD status field bits */
  165. #define RXBD_EMPTY 0x8000
  166. #define RXBD_RO1 0x4000
  167. #define RXBD_WRAP 0x2000
  168. #define RXBD_INTERRUPT 0x1000
  169. #define RXBD_LAST 0x0800
  170. #define RXBD_FIRST 0x0400
  171. #define RXBD_MISS 0x0100
  172. #define RXBD_BROADCAST 0x0080
  173. #define RXBD_MULTICAST 0x0040
  174. #define RXBD_LARGE 0x0020
  175. #define RXBD_NONOCTET 0x0010
  176. #define RXBD_SHORT 0x0008
  177. #define RXBD_CRCERR 0x0004
  178. #define RXBD_OVERRUN 0x0002
  179. #define RXBD_TRUNCATED 0x0001
  180. #define RXBD_STATS 0x003f
  181. typedef struct txbd8
  182. {
  183. ushort status; /* Status Fields */
  184. ushort length; /* Buffer length */
  185. uint bufPtr; /* Buffer Pointer */
  186. } txbd8_t;
  187. typedef struct rxbd8
  188. {
  189. ushort status; /* Status Fields */
  190. ushort length; /* Buffer Length */
  191. uint bufPtr; /* Buffer Pointer */
  192. } rxbd8_t;
  193. typedef struct rmon_mib
  194. {
  195. /* Transmit and Receive Counters */
  196. uint tr64; /* Transmit and Receive 64-byte Frame Counter */
  197. uint tr127; /* Transmit and Receive 65-127 byte Frame Counter */
  198. uint tr255; /* Transmit and Receive 128-255 byte Frame Counter */
  199. uint tr511; /* Transmit and Receive 256-511 byte Frame Counter */
  200. uint tr1k; /* Transmit and Receive 512-1023 byte Frame Counter */
  201. uint trmax; /* Transmit and Receive 1024-1518 byte Frame Counter */
  202. uint trmgv; /* Transmit and Receive 1519-1522 byte Good VLAN Frame */
  203. /* Receive Counters */
  204. uint rbyt; /* Receive Byte Counter */
  205. uint rpkt; /* Receive Packet Counter */
  206. uint rfcs; /* Receive FCS Error Counter */
  207. uint rmca; /* Receive Multicast Packet (Counter) */
  208. uint rbca; /* Receive Broadcast Packet */
  209. uint rxcf; /* Receive Control Frame Packet */
  210. uint rxpf; /* Receive Pause Frame Packet */
  211. uint rxuo; /* Receive Unknown OP Code */
  212. uint raln; /* Receive Alignment Error */
  213. uint rflr; /* Receive Frame Length Error */
  214. uint rcde; /* Receive Code Error */
  215. uint rcse; /* Receive Carrier Sense Error */
  216. uint rund; /* Receive Undersize Packet */
  217. uint rovr; /* Receive Oversize Packet */
  218. uint rfrg; /* Receive Fragments */
  219. uint rjbr; /* Receive Jabber */
  220. uint rdrp; /* Receive Drop */
  221. /* Transmit Counters */
  222. uint tbyt; /* Transmit Byte Counter */
  223. uint tpkt; /* Transmit Packet */
  224. uint tmca; /* Transmit Multicast Packet */
  225. uint tbca; /* Transmit Broadcast Packet */
  226. uint txpf; /* Transmit Pause Control Frame */
  227. uint tdfr; /* Transmit Deferral Packet */
  228. uint tedf; /* Transmit Excessive Deferral Packet */
  229. uint tscl; /* Transmit Single Collision Packet */
  230. /* (0x2_n700) */
  231. uint tmcl; /* Transmit Multiple Collision Packet */
  232. uint tlcl; /* Transmit Late Collision Packet */
  233. uint txcl; /* Transmit Excessive Collision Packet */
  234. uint tncl; /* Transmit Total Collision */
  235. uint res2;
  236. uint tdrp; /* Transmit Drop Frame */
  237. uint tjbr; /* Transmit Jabber Frame */
  238. uint tfcs; /* Transmit FCS Error */
  239. uint txcf; /* Transmit Control Frame */
  240. uint tovr; /* Transmit Oversize Frame */
  241. uint tund; /* Transmit Undersize Frame */
  242. uint tfrg; /* Transmit Fragments Frame */
  243. /* General Registers */
  244. uint car1; /* Carry Register One */
  245. uint car2; /* Carry Register Two */
  246. uint cam1; /* Carry Register One Mask */
  247. uint cam2; /* Carry Register Two Mask */
  248. } rmon_mib_t;
  249. typedef struct tsec_hash_regs
  250. {
  251. uint iaddr0; /* Individual Address Register 0 */
  252. uint iaddr1; /* Individual Address Register 1 */
  253. uint iaddr2; /* Individual Address Register 2 */
  254. uint iaddr3; /* Individual Address Register 3 */
  255. uint iaddr4; /* Individual Address Register 4 */
  256. uint iaddr5; /* Individual Address Register 5 */
  257. uint iaddr6; /* Individual Address Register 6 */
  258. uint iaddr7; /* Individual Address Register 7 */
  259. uint res1[24];
  260. uint gaddr0; /* Group Address Register 0 */
  261. uint gaddr1; /* Group Address Register 1 */
  262. uint gaddr2; /* Group Address Register 2 */
  263. uint gaddr3; /* Group Address Register 3 */
  264. uint gaddr4; /* Group Address Register 4 */
  265. uint gaddr5; /* Group Address Register 5 */
  266. uint gaddr6; /* Group Address Register 6 */
  267. uint gaddr7; /* Group Address Register 7 */
  268. uint res2[24];
  269. } tsec_hash_t;
  270. typedef struct tsec
  271. {
  272. /* General Control and Status Registers (0x2_n000) */
  273. uint res000[4];
  274. uint ievent; /* Interrupt Event */
  275. uint imask; /* Interrupt Mask */
  276. uint edis; /* Error Disabled */
  277. uint res01c;
  278. uint ecntrl; /* Ethernet Control */
  279. uint minflr; /* Minimum Frame Length */
  280. uint ptv; /* Pause Time Value */
  281. uint dmactrl; /* DMA Control */
  282. uint tbipa; /* TBI PHY Address */
  283. uint res034[3];
  284. uint res040[48];
  285. /* Transmit Control and Status Registers (0x2_n100) */
  286. uint tctrl; /* Transmit Control */
  287. uint tstat; /* Transmit Status */
  288. uint res108;
  289. uint tbdlen; /* Tx BD Data Length */
  290. uint res110[5];
  291. uint ctbptr; /* Current TxBD Pointer */
  292. uint res128[23];
  293. uint tbptr; /* TxBD Pointer */
  294. uint res188[30];
  295. /* (0x2_n200) */
  296. uint res200;
  297. uint tbase; /* TxBD Base Address */
  298. uint res208[42];
  299. uint ostbd; /* Out of Sequence TxBD */
  300. uint ostbdp; /* Out of Sequence Tx Data Buffer Pointer */
  301. uint res2b8[18];
  302. /* Receive Control and Status Registers (0x2_n300) */
  303. uint rctrl; /* Receive Control */
  304. uint rstat; /* Receive Status */
  305. uint res308;
  306. uint rbdlen; /* RxBD Data Length */
  307. uint res310[4];
  308. uint res320;
  309. uint crbptr; /* Current Receive Buffer Pointer */
  310. uint res328[6];
  311. uint mrblr; /* Maximum Receive Buffer Length */
  312. uint res344[16];
  313. uint rbptr; /* RxBD Pointer */
  314. uint res388[30];
  315. /* (0x2_n400) */
  316. uint res400;
  317. uint rbase; /* RxBD Base Address */
  318. uint res408[62];
  319. /* MAC Registers (0x2_n500) */
  320. uint maccfg1; /* MAC Configuration #1 */
  321. uint maccfg2; /* MAC Configuration #2 */
  322. uint ipgifg; /* Inter Packet Gap/Inter Frame Gap */
  323. uint hafdup; /* Half-duplex */
  324. uint maxfrm; /* Maximum Frame */
  325. uint res514;
  326. uint res518;
  327. uint res51c;
  328. uint miimcfg; /* MII Management: Configuration */
  329. uint miimcom; /* MII Management: Command */
  330. uint miimadd; /* MII Management: Address */
  331. uint miimcon; /* MII Management: Control */
  332. uint miimstat; /* MII Management: Status */
  333. uint miimind; /* MII Management: Indicators */
  334. uint res538;
  335. uint ifstat; /* Interface Status */
  336. uint macstnaddr1; /* Station Address, part 1 */
  337. uint macstnaddr2; /* Station Address, part 2 */
  338. uint res548[46];
  339. /* (0x2_n600) */
  340. uint res600[32];
  341. /* RMON MIB Registers (0x2_n680-0x2_n73c) */
  342. rmon_mib_t rmon;
  343. uint res740[48];
  344. /* Hash Function Registers (0x2_n800) */
  345. tsec_hash_t hash;
  346. uint res900[128];
  347. /* Pattern Registers (0x2_nb00) */
  348. uint resb00[62];
  349. uint attr; /* Default Attribute Register */
  350. uint attreli; /* Default Attribute Extract Length and Index */
  351. /* TSEC Future Expansion Space (0x2_nc00-0x2_nffc) */
  352. uint resc00[256];
  353. } tsec_t;
  354. struct tsec_private {
  355. volatile tsec_t *regs;
  356. volatile tsec_t *phyregs;
  357. struct phy_info *phyinfo;
  358. uint phyaddr;
  359. uint gigabit;
  360. uint link;
  361. uint duplexity;
  362. uint speed;
  363. };
  364. /*
  365. * struct phy_cmd: A command for reading or writing a PHY register
  366. *
  367. * mii_reg: The register to read or write
  368. *
  369. * mii_data: For writes, the value to put in the register.
  370. * A value of -1 indicates this is a read.
  371. *
  372. * funct: A function pointer which is invoked for each command.
  373. * For reads, this function will be passed the value read
  374. * from the PHY, and process it.
  375. * For writes, the result of this function will be written
  376. * to the PHY register
  377. */
  378. struct phy_cmd {
  379. uint mii_reg;
  380. uint mii_data;
  381. uint (*funct) (uint mii_reg, struct tsec_private* priv);
  382. };
  383. /* struct phy_info: a structure which defines attributes for a PHY
  384. *
  385. * id will contain a number which represents the PHY. During
  386. * startup, the driver will poll the PHY to find out what its
  387. * UID--as defined by registers 2 and 3--is. The 32-bit result
  388. * gotten from the PHY will be shifted right by "shift" bits to
  389. * discard any bits which may change based on revision numbers
  390. * unimportant to functionality
  391. *
  392. * The struct phy_cmd entries represent pointers to an arrays of
  393. * commands which tell the driver what to do to the PHY.
  394. */
  395. struct phy_info {
  396. uint id;
  397. char *name;
  398. uint shift;
  399. /* Called to configure the PHY, and modify the controller
  400. * based on the results */
  401. struct phy_cmd *config;
  402. /* Called when starting up the controller */
  403. struct phy_cmd *startup;
  404. /* Called when bringing down the controller */
  405. struct phy_cmd *shutdown;
  406. };
  407. #endif /* __TSEC_H */