xilinx_ll_temac.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Xilinx xps_ll_temac ethernet driver for u-boot
  3. *
  4. * LL_TEMAC interface
  5. *
  6. * Copyright (C) 2011 - 2012 Stephan Linz <linz@li-pro.net>
  7. * Copyright (C) 2008 - 2011 Michal Simek <monstr@monstr.eu>
  8. * Copyright (C) 2008 - 2011 PetaLogix
  9. *
  10. * Based on Yoshio Kashiwagi kashiwagi@co-nss.co.jp driver
  11. * Copyright (C) 2008 Nissin Systems Co.,Ltd.
  12. * March 2008 created
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the
  16. * Free Software Foundation; either version 2 of the License, or (at your
  17. * option) any later version.
  18. *
  19. * [0]: http://www.xilinx.com/support/documentation
  20. *
  21. * [S]: [0]/ip_documentation/xps_ll_temac.pdf
  22. * [A]: [0]/application_notes/xapp1041.pdf
  23. */
  24. #ifndef _XILINX_LL_TEMAC_
  25. #define _XILINX_LL_TEMAC_
  26. #include <config.h>
  27. #include <net.h>
  28. #include <phy.h>
  29. #include <miiphy.h>
  30. #include <asm/types.h>
  31. #include <asm/byteorder.h>
  32. #include "xilinx_ll_temac_sdma.h"
  33. #if !defined(__BIG_ENDIAN)
  34. # error LL_TEMAC requires big endianess
  35. #endif
  36. /*
  37. * TEMAC Memory and Register Definition
  38. *
  39. * [1]: [0]/ip_documentation/xps_ll_temac.pdf
  40. * page 19, Memory and Register Descriptions
  41. */
  42. struct temac_reg {
  43. /* direct soft registers (low part) */
  44. u32 raf; /* Reset and Address Filter */
  45. u32 tpf; /* Transmit Pause Frame */
  46. u32 ifgp; /* Transmit Inter Frame Gap Adjustment */
  47. u32 is; /* Interrupt Status */
  48. u32 ip; /* Interrupt Pending */
  49. u32 ie; /* Interrupt Enable */
  50. u32 ttag; /* Transmit VLAN Tag */
  51. u32 rtag; /* Receive VLAN Tag */
  52. /* hard TEMAC registers */
  53. u32 msw; /* Most Significant Word Data */
  54. u32 lsw; /* Least Significant Word Data */
  55. u32 ctl; /* Control */
  56. u32 rdy; /* Ready Status */
  57. /* direct soft registers (high part) */
  58. u32 uawl; /* Unicast Address Word Lower */
  59. u32 uawu; /* Unicast Address Word Upper */
  60. u32 tpid0; /* VLAN TPID Word 0 */
  61. u32 tpid1; /* VLAN TPID Word 1 */
  62. };
  63. /* Reset and Address Filter Registers (raf), [1] p25 */
  64. #define RAF_SR (1 << 13)
  65. #define RAF_EMFE (1 << 12)
  66. #define RAF_NFE (1 << 11)
  67. #define RAF_RVSTM_POS 9
  68. #define RAF_RVSTM_MASK (3 << RAF_RVSTM_POS)
  69. #define RAF_TVSTM_POS 7
  70. #define RAF_TVSTM_MASK (3 << RAF_TVSTM_POS)
  71. #define RAF_RVTM_POS 5
  72. #define RAF_RVTM_MASK (3 << RAF_RVTM_POS)
  73. #define RAF_TVTM_POS 3
  74. #define RAF_TVTM_MASK (3 << RAF_TVTM_POS)
  75. #define RAF_BCREJ (1 << 2)
  76. #define RAF_MCREJ (1 << 1)
  77. #define RAF_HTRST (1 << 0)
  78. /* Transmit Pause Frame Registers (tpf), [1] p28 */
  79. #define TPF_TPFV_POS 0
  80. #define TPF_TPFV_MASK (0xFFFF << TPF_TPFV_POS)
  81. /* Transmit Inter Frame Gap Adjustment Registers (ifgp), [1] p28 */
  82. #define IFGP_POS 0
  83. #define IFGP_MASK (0xFF << IFGP_POS)
  84. /* Interrupt Status, Pending, Enable Registers (is, ip, ie), [1] p29-33 */
  85. #define ISPE_MR (1 << 7)
  86. #define ISPE_RDL (1 << 6)
  87. #define ISPE_TC (1 << 5)
  88. #define ISPE_RFO (1 << 4)
  89. #define ISPE_RR (1 << 3)
  90. #define ISPE_RC (1 << 2)
  91. #define ISPE_AN (1 << 1)
  92. #define ISPE_HAC (1 << 0)
  93. /* Transmit, Receive VLAN Tag Registers (ttag, rtag), [1] p34-35 */
  94. #define TRTAG_TPID_POS 16
  95. #define TRTAG_TPID_MASK (0xFFFF << TRTAG_TPID_POS)
  96. #define TRTAG_PRIO_POS 13
  97. #define TRTAG_PRIO_MASK (7 << TRTAG_PRIO_POS)
  98. #define TRTAG_CFI (1 << 12)
  99. #define TRTAG_VID_POS 0
  100. #define TRTAG_VID_MASK (0xFFF << TRTAG_VID_POS)
  101. /* Most, Least Significant Word Data Register (msw, lsw), [1] p46 */
  102. #define MLSW_POS 0
  103. #define MLSW_MASK (~0UL << MLSW_POS)
  104. /* LSW Data Register for PHY addresses (lsw), [1] p66 */
  105. #define LSW_REGAD_POS 0
  106. #define LSW_REGAD_MASK (0x1F << LSW_REGAD_POS)
  107. #define LSW_PHYAD_POS 5
  108. #define LSW_PHYAD_MASK (0x1F << LSW_PHYAD_POS)
  109. /* LSW Data Register for PHY data (lsw), [1] p66 */
  110. #define LSW_REGDAT_POS 0
  111. #define LSW_REGDAT_MASK (0xFFFF << LSW_REGDAT_POS)
  112. /* Control Register (ctl), [1] p47 */
  113. #define CTL_WEN (1 << 15)
  114. #define CTL_ADDR_POS 0
  115. #define CTL_ADDR_MASK (0x3FF << CTL_ADDR_POS)
  116. /* Ready Status Register Ethernet (rdy), [1] p48 */
  117. #define RSE_HACS_RDY (1 << 14)
  118. #define RSE_CFG_WR (1 << 6)
  119. #define RSE_CFG_RR (1 << 5)
  120. #define RSE_AF_WR (1 << 4)
  121. #define RSE_AF_RR (1 << 3)
  122. #define RSE_MIIM_WR (1 << 2)
  123. #define RSE_MIIM_RR (1 << 1)
  124. #define RSE_FABR_RR (1 << 0)
  125. /* Unicast Address Word Lower, Upper Registers (uawl, uawu), [1] p35-36 */
  126. #define UAWL_UADDR_POS 0
  127. #define UAWL_UADDR_MASK (~0UL << UAWL_UADDR_POS)
  128. #define UAWU_UADDR_POS 0
  129. #define UAWU_UADDR_MASK (0xFFFF << UAWU_UADDR_POS)
  130. /* VLAN TPID Word 0, 1 Registers (tpid0, tpid1), [1] p37 */
  131. #define TPID0_V0_POS 0
  132. #define TPID0_V0_MASK (0xFFFF << TPID0_V0_POS)
  133. #define TPID0_V1_POS 16
  134. #define TPID0_V1_MASK (0xFFFF << TPID0_V1_POS)
  135. #define TPID1_V2_POS 0
  136. #define TPID1_V2_MASK (0xFFFF << TPID1_V2_POS)
  137. #define TPID1_V3_POS 16
  138. #define TPID1_V3_MASK (0xFFFF << TPID1_V3_POS)
  139. /*
  140. * TEMAC Indirectly Addressable Register Index Enumeration
  141. *
  142. * [0]: http://www.xilinx.com/support/documentation
  143. *
  144. * [1]: [0]/ip_documentation/xps_ll_temac.pdf
  145. * page 23, PLB Indirectly Addressable TEMAC Registers
  146. */
  147. enum temac_ctrl {
  148. TEMAC_RCW0 = 0x200,
  149. TEMAC_RCW1 = 0x240,
  150. TEMAC_TC = 0x280,
  151. TEMAC_FCC = 0x2C0,
  152. TEMAC_EMMC = 0x300,
  153. TEMAC_PHYC = 0x320,
  154. TEMAC_MC = 0x340,
  155. TEMAC_UAW0 = 0x380,
  156. TEMAC_UAW1 = 0x384,
  157. TEMAC_MAW0 = 0x388,
  158. TEMAC_MAW1 = 0x38C,
  159. TEMAC_AFM = 0x390,
  160. TEMAC_TIS = 0x3A0,
  161. TEMAC_TIE = 0x3A4,
  162. TEMAC_MIIMWD = 0x3B0,
  163. TEMAC_MIIMAI = 0x3B4
  164. };
  165. /* Receive Configuration Word 0, 1 Registers (RCW0, RCW1), [1] p50-51 */
  166. #define RCW0_PADDR_POS 0
  167. #define RCW0_PADDR_MASK (~0UL << RCW_PADDR_POS)
  168. #define RCW1_RST (1 << 31)
  169. #define RCW1_JUM (1 << 30)
  170. #define RCW1_FCS (1 << 29)
  171. #define RCW1_RX (1 << 28)
  172. #define RCW1_VLAN (1 << 27)
  173. #define RCW1_HD (1 << 26)
  174. #define RCW1_LT_DIS (1 << 25)
  175. #define RCW1_PADDR_POS 0
  176. #define RCW1_PADDR_MASK (0xFFFF << RCW_PADDR_POS)
  177. /* Transmit Configuration Registers (TC), [1] p52 */
  178. #define TC_RST (1 << 31)
  179. #define TC_JUM (1 << 30)
  180. #define TC_FCS (1 << 29)
  181. #define TC_TX (1 << 28)
  182. #define TC_VLAN (1 << 27)
  183. #define TC_HD (1 << 26)
  184. #define TC_IFG (1 << 25)
  185. /* Flow Control Configuration Registers (FCC), [1] p54 */
  186. #define FCC_FCTX (1 << 30)
  187. #define FCC_FCRX (1 << 29)
  188. /* Ethernet MAC Mode Configuration Registers (EMMC), [1] p54 */
  189. #define EMMC_LSPD_POS 30
  190. #define EMMC_LSPD_MASK (3 << EMMC_LSPD_POS)
  191. #define EMMC_LSPD_1000 (2 << EMMC_LSPD_POS)
  192. #define EMMC_LSPD_100 (1 << EMMC_LSPD_POS)
  193. #define EMMC_LSPD_10 0
  194. #define EMMC_RGMII (1 << 29)
  195. #define EMMC_SGMII (1 << 28)
  196. #define EMMC_GPCS (1 << 27)
  197. #define EMMC_HOST (1 << 26)
  198. #define EMMC_TX16 (1 << 25)
  199. #define EMMC_RX16 (1 << 24)
  200. /* RGMII/SGMII Configuration Registers (PHYC), [1] p56 */
  201. #define PHYC_SLSPD_POS 30
  202. #define PHYC_SLSPD_MASK (3 << EMMC_SLSPD_POS)
  203. #define PHYC_SLSPD_1000 (2 << EMMC_SLSPD_POS)
  204. #define PHYC_SLSPD_100 (1 << EMMC_SLSPD_POS)
  205. #define PHYC_SLSPD_10 0
  206. #define PHYC_RLSPD_POS 2
  207. #define PHYC_RLSPD_MASK (3 << EMMC_RLSPD_POS)
  208. #define PHYC_RLSPD_1000 (2 << EMMC_RLSPD_POS)
  209. #define PHYC_RLSPD_100 (1 << EMMC_RLSPD_POS)
  210. #define PHYC_RLSPD_10 0
  211. #define PHYC_RGMII_HD (1 << 1)
  212. #define PHYC_RGMII_LINK (1 << 0)
  213. /* Management Configuration Registers (MC), [1] p57 */
  214. #define MC_MDIOEN (1 << 6)
  215. #define MC_CLKDIV_POS 0
  216. #define MC_CLKDIV_MASK (0x3F << MC_CLKDIV_POS)
  217. /*
  218. * fHOSTCLK fMDC = fHOSTCLK
  219. * fMDC = ------------------- ---------> MC_CLKDIV = -------- - 1
  220. * (1 + MC_CLKDIV) * 2 2.5 MHz 5MHz
  221. */
  222. #define MC_CLKDIV(f, m) ((f / (2 * m)) - 1)
  223. #define MC_CLKDIV_25(f) MC_CLKDIV(f, 2500000)
  224. #define MC_CLKDIV_20(f) MC_CLKDIV(f, 2000000)
  225. #define MC_CLKDIV_15(f) MC_CLKDIV(f, 1500000)
  226. #define MC_CLKDIV_10(f) MC_CLKDIV(f, 1000000)
  227. /* Unicast Address Word 0, 1 Registers (UAW0, UAW1), [1] p58-59 */
  228. #define UAW0_UADDR_POS 0
  229. #define UAW0_UADDR_MASK (~0UL << UAW0_UADDR_POS)
  230. #define UAW1_UADDR_POS 0
  231. #define UAW1_UADDR_MASK (0xFFFF << UAW1_UADDR_POS)
  232. /* Multicast Address Word 0, 1 Registers (MAW0, MAW1), [1] p60 */
  233. #define MAW0_MADDR_POS 0
  234. #define MAW0_MADDR_MASK (~0UL << MAW0_MADDR_POS)
  235. #define MAW1_RNW (1 << 23)
  236. #define MAW1_MAIDX_POS 16
  237. #define MAW1_MAIDX_MASK (3 << MAW1_MAIDX_POS)
  238. #define MAW1_MADDR_POS 0
  239. #define MAW1_MADDR_MASK (0xFFFF << MAW1_MADDR_POS)
  240. /* Address Filter Mode Registers (AFM), [1] p63 */
  241. #define AFM_PM (1 << 31)
  242. /* Interrupt Status, Enable Registers (TIS, TIE), [1] p63-65 */
  243. #define TISE_CFG_W (1 << 6)
  244. #define TISE_CFG_R (1 << 5)
  245. #define TISE_AF_W (1 << 4)
  246. #define TISE_AF_R (1 << 3)
  247. #define TISE_MIIM_W (1 << 2)
  248. #define TISE_MIIM_R (1 << 1)
  249. #define TISE_FABR_R (1 << 0)
  250. /* MII Management Write Data Registers (MIIMWD), [1] p66 */
  251. #define MIIMWD_DATA_POS 0
  252. #define MIIMWD_DATA_MASK (0xFFFF << MIIMWD_DATA_POS)
  253. /* Ethernet interface ready status */
  254. int ll_temac_check_status(struct temac_reg *regs, u32 mask);
  255. /* Indirect write to ll_temac. */
  256. int ll_temac_indirect_set(struct temac_reg *regs, u16 regn, u32 reg_data);
  257. /* Indirect read from ll_temac. */
  258. int ll_temac_indirect_get(struct temac_reg *regs, u16 regn, u32* reg_data);
  259. struct ll_temac {
  260. phys_addr_t ctrladdr;
  261. phys_addr_t sdma_reg_addr[SDMA_CTRL_REGNUMS];
  262. unsigned (*in32)(phys_addr_t);
  263. void (*out32)(phys_addr_t, unsigned);
  264. int (*ctrlinit) (struct eth_device *);
  265. int (*ctrlhalt) (struct eth_device *);
  266. int (*ctrlreset) (struct eth_device *);
  267. int phyaddr;
  268. struct phy_device *phydev;
  269. struct mii_dev *bus;
  270. char mdio_busname[MDIO_NAME_LEN];
  271. };
  272. #endif /* _XILINX_LL_TEMAC_ */