tsec.h 15 KB

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