xilinx_ll_temac.h 9.0 KB

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