emac_defs.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * emac definitions for keystone2 devices
  3. *
  4. * (C) Copyright 2012-2014
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #ifndef _EMAC_DEFS_H_
  10. #define _EMAC_DEFS_H_
  11. #include <asm/arch/hardware.h>
  12. #include <asm/io.h>
  13. #define EMAC_EMACSL_BASE_ADDR (KS2_PASS_BASE + 0x00090900)
  14. #define EMAC_MDIO_BASE_ADDR (KS2_PASS_BASE + 0x00090300)
  15. #define EMAC_SGMII_BASE_ADDR (KS2_PASS_BASE + 0x00090100)
  16. #define KEYSTONE2_EMAC_GIG_ENABLE
  17. #define MAC_ID_BASE_ADDR (KS2_DEVICE_STATE_CTRL_BASE + 0x110)
  18. #ifdef CONFIG_SOC_K2HK
  19. /* MDIO module input frequency */
  20. #define EMAC_MDIO_BUS_FREQ (clk_get_rate(pass_pll_clk))
  21. /* MDIO clock output frequency */
  22. #define EMAC_MDIO_CLOCK_FREQ 1000000 /* 1.0 MHz */
  23. #endif
  24. /* MII Status Register */
  25. #define MII_STATUS_REG 1
  26. #define MII_STATUS_LINK_MASK (0x4)
  27. /* Marvell 88E1111 PHY ID */
  28. #define PHY_MARVELL_88E1111 (0x01410cc0)
  29. #define MDIO_CONTROL_IDLE (0x80000000)
  30. #define MDIO_CONTROL_ENABLE (0x40000000)
  31. #define MDIO_CONTROL_FAULT_ENABLE (0x40000)
  32. #define MDIO_CONTROL_FAULT (0x80000)
  33. #define MDIO_USERACCESS0_GO (0x80000000)
  34. #define MDIO_USERACCESS0_WRITE_READ (0x0)
  35. #define MDIO_USERACCESS0_WRITE_WRITE (0x40000000)
  36. #define MDIO_USERACCESS0_ACK (0x20000000)
  37. #define EMAC_MACCONTROL_MIIEN_ENABLE (0x20)
  38. #define EMAC_MACCONTROL_FULLDUPLEX_ENABLE (0x1)
  39. #define EMAC_MACCONTROL_GIGABIT_ENABLE (1 << 7)
  40. #define EMAC_MACCONTROL_GIGFORCE (1 << 17)
  41. #define EMAC_MACCONTROL_RMIISPEED_100 (1 << 15)
  42. #define EMAC_MIN_ETHERNET_PKT_SIZE 60
  43. struct mac_sl_cfg {
  44. u_int32_t max_rx_len; /* Maximum receive packet length. */
  45. u_int32_t ctl; /* Control bitfield */
  46. };
  47. /*
  48. * Definition: Control bitfields used in the ctl field of hwGmacSlCfg_t
  49. */
  50. #define GMACSL_RX_ENABLE_RCV_CONTROL_FRAMES (1 << 24)
  51. #define GMACSL_RX_ENABLE_RCV_SHORT_FRAMES (1 << 23)
  52. #define GMACSL_RX_ENABLE_RCV_ERROR_FRAMES (1 << 22)
  53. #define GMACSL_RX_ENABLE_EXT_CTL (1 << 18)
  54. #define GMACSL_RX_ENABLE_GIG_FORCE (1 << 17)
  55. #define GMACSL_RX_ENABLE_IFCTL_B (1 << 16)
  56. #define GMACSL_RX_ENABLE_IFCTL_A (1 << 15)
  57. #define GMACSL_RX_ENABLE_CMD_IDLE (1 << 11)
  58. #define GMACSL_TX_ENABLE_SHORT_GAP (1 << 10)
  59. #define GMACSL_ENABLE_GIG_MODE (1 << 7)
  60. #define GMACSL_TX_ENABLE_PACE (1 << 6)
  61. #define GMACSL_ENABLE (1 << 5)
  62. #define GMACSL_TX_ENABLE_FLOW_CTL (1 << 4)
  63. #define GMACSL_RX_ENABLE_FLOW_CTL (1 << 3)
  64. #define GMACSL_ENABLE_LOOPBACK (1 << 1)
  65. #define GMACSL_ENABLE_FULL_DUPLEX (1 << 0)
  66. /*
  67. * DEFINTITION: function return values
  68. */
  69. #define GMACSL_RET_OK 0
  70. #define GMACSL_RET_INVALID_PORT -1
  71. #define GMACSL_RET_WARN_RESET_INCOMPLETE -2
  72. #define GMACSL_RET_WARN_MAXLEN_TOO_BIG -3
  73. #define GMACSL_RET_CONFIG_FAIL_RESET_ACTIVE -4
  74. /* Register offsets */
  75. #define CPGMACSL_REG_ID 0x00
  76. #define CPGMACSL_REG_CTL 0x04
  77. #define CPGMACSL_REG_STATUS 0x08
  78. #define CPGMACSL_REG_RESET 0x0c
  79. #define CPGMACSL_REG_MAXLEN 0x10
  80. #define CPGMACSL_REG_BOFF 0x14
  81. #define CPGMACSL_REG_RX_PAUSE 0x18
  82. #define CPGMACSL_REG_TX_PAURSE 0x1c
  83. #define CPGMACSL_REG_EM_CTL 0x20
  84. #define CPGMACSL_REG_PRI 0x24
  85. /* Soft reset register values */
  86. #define CPGMAC_REG_RESET_VAL_RESET_MASK (1 << 0)
  87. #define CPGMAC_REG_RESET_VAL_RESET (1 << 0)
  88. /* Maxlen register values */
  89. #define CPGMAC_REG_MAXLEN_LEN 0x3fff
  90. /* Control bitfields */
  91. #define CPSW_CTL_P2_PASS_PRI_TAGGED (1 << 5)
  92. #define CPSW_CTL_P1_PASS_PRI_TAGGED (1 << 4)
  93. #define CPSW_CTL_P0_PASS_PRI_TAGGED (1 << 3)
  94. #define CPSW_CTL_P0_ENABLE (1 << 2)
  95. #define CPSW_CTL_VLAN_AWARE (1 << 1)
  96. #define CPSW_CTL_FIFO_LOOPBACK (1 << 0)
  97. #define DEVICE_CPSW_NUM_PORTS 5 /* 5 switch ports */
  98. #define DEVICE_CPSW_BASE (0x02090800)
  99. #define target_get_switch_ctl() CPSW_CTL_P0_ENABLE /* Enable port 0 */
  100. #define SWITCH_MAX_PKT_SIZE 9000
  101. /* Register offsets */
  102. #define CPSW_REG_CTL 0x004
  103. #define CPSW_REG_STAT_PORT_EN 0x00c
  104. #define CPSW_REG_MAXLEN 0x040
  105. #define CPSW_REG_ALE_CONTROL 0x608
  106. #define CPSW_REG_ALE_PORTCTL(x) (0x640 + (x)*4)
  107. /* Register values */
  108. #define CPSW_REG_VAL_STAT_ENABLE_ALL 0xf
  109. #define CPSW_REG_VAL_ALE_CTL_RESET_AND_ENABLE ((u_int32_t)0xc0000000)
  110. #define CPSW_REG_VAL_ALE_CTL_BYPASS ((u_int32_t)0x00000010)
  111. #define CPSW_REG_VAL_PORTCTL_FORWARD_MODE 0x3
  112. #define SGMII_REG_STATUS_LOCK BIT(4)
  113. #define SGMII_REG_STATUS_LINK BIT(0)
  114. #define SGMII_REG_STATUS_AUTONEG BIT(2)
  115. #define SGMII_REG_CONTROL_AUTONEG BIT(0)
  116. #define SGMII_REG_CONTROL_MASTER BIT(5)
  117. #define SGMII_REG_MR_ADV_ENABLE BIT(0)
  118. #define SGMII_REG_MR_ADV_LINK BIT(15)
  119. #define SGMII_REG_MR_ADV_FULL_DUPLEX BIT(12)
  120. #define SGMII_REG_MR_ADV_GIG_MODE BIT(11)
  121. #define SGMII_LINK_MAC_MAC_AUTONEG 0
  122. #define SGMII_LINK_MAC_PHY 1
  123. #define SGMII_LINK_MAC_MAC_FORCED 2
  124. #define SGMII_LINK_MAC_FIBER 3
  125. #define SGMII_LINK_MAC_PHY_FORCED 4
  126. #define TARGET_SGMII_BASE KS2_PASS_BASE + 0x00090100
  127. #define TARGET_SGMII_BASE_ADDRESSES {KS2_PASS_BASE + 0x00090100, \
  128. KS2_PASS_BASE + 0x00090200, \
  129. KS2_PASS_BASE + 0x00090400, \
  130. KS2_PASS_BASE + 0x00090500}
  131. #define SGMII_OFFSET(x) ((x <= 1) ? (x * 0x100) : ((x * 0x100) + 0x100))
  132. /*
  133. * SGMII registers
  134. */
  135. #define SGMII_IDVER_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x000)
  136. #define SGMII_SRESET_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x004)
  137. #define SGMII_CTL_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x010)
  138. #define SGMII_STATUS_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x014)
  139. #define SGMII_MRADV_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x018)
  140. #define SGMII_LPADV_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x020)
  141. #define SGMII_TXCFG_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x030)
  142. #define SGMII_RXCFG_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x034)
  143. #define SGMII_AUXCFG_REG(x) (TARGET_SGMII_BASE + SGMII_OFFSET(x) + 0x038)
  144. #define DEVICE_EMACSL_BASE(x) (KS2_PASS_BASE + 0x00090900 + (x) * 0x040)
  145. #define DEVICE_N_GMACSL_PORTS 4
  146. #define DEVICE_EMACSL_RESET_POLL_COUNT 100
  147. #define DEVICE_PSTREAM_CFG_REG_ADDR (KS2_PASS_BASE + 0x604)
  148. #ifdef CONFIG_SOC_K2HK
  149. #define DEVICE_PSTREAM_CFG_REG_VAL_ROUTE_CPPI 0x06060606
  150. #endif
  151. #define hw_config_streaming_switch() \
  152. writel(DEVICE_PSTREAM_CFG_REG_VAL_ROUTE_CPPI,\
  153. DEVICE_PSTREAM_CFG_REG_ADDR);
  154. /* EMAC MDIO Registers Structure */
  155. struct mdio_regs {
  156. dv_reg version;
  157. dv_reg control;
  158. dv_reg alive;
  159. dv_reg link;
  160. dv_reg linkintraw;
  161. dv_reg linkintmasked;
  162. u_int8_t rsvd0[8];
  163. dv_reg userintraw;
  164. dv_reg userintmasked;
  165. dv_reg userintmaskset;
  166. dv_reg userintmaskclear;
  167. u_int8_t rsvd1[80];
  168. dv_reg useraccess0;
  169. dv_reg userphysel0;
  170. dv_reg useraccess1;
  171. dv_reg userphysel1;
  172. };
  173. /* Ethernet MAC Registers Structure */
  174. struct emac_regs {
  175. dv_reg idver;
  176. dv_reg maccontrol;
  177. dv_reg macstatus;
  178. dv_reg soft_reset;
  179. dv_reg rx_maxlen;
  180. u32 rsvd0;
  181. dv_reg rx_pause;
  182. dv_reg tx_pause;
  183. dv_reg emcontrol;
  184. dv_reg pri_map;
  185. u32 rsvd1[6];
  186. };
  187. #define SGMII_ACCESS(port, reg) \
  188. *((volatile unsigned int *)(sgmiis[port] + reg))
  189. struct eth_priv_t {
  190. char int_name[32];
  191. int rx_flow;
  192. int phy_addr;
  193. int slave_port;
  194. int sgmii_link_type;
  195. };
  196. extern struct eth_priv_t eth_priv_cfg[];
  197. int keystone2_emac_initialize(struct eth_priv_t *eth_priv);
  198. void sgmii_serdes_setup_156p25mhz(void);
  199. void sgmii_serdes_shutdown(void);
  200. #endif /* _EMAC_DEFS_H_ */