cvmx-helper-xaui.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: [email protected]
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (C) 2003-2018 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. /*
  28. * Functions for XAUI initialization, configuration,
  29. * and monitoring.
  30. *
  31. */
  32. #include <asm/octeon/octeon.h>
  33. #include <asm/octeon/cvmx-config.h>
  34. #include <asm/octeon/cvmx-helper.h>
  35. #include <asm/octeon/cvmx-pko-defs.h>
  36. #include <asm/octeon/cvmx-gmxx-defs.h>
  37. #include <asm/octeon/cvmx-pcsx-defs.h>
  38. #include <asm/octeon/cvmx-pcsxx-defs.h>
  39. int __cvmx_helper_xaui_enumerate(int interface)
  40. {
  41. union cvmx_gmxx_hg2_control gmx_hg2_control;
  42. /* If HiGig2 is enabled return 16 ports, otherwise return 1 port */
  43. gmx_hg2_control.u64 = cvmx_read_csr(CVMX_GMXX_HG2_CONTROL(interface));
  44. if (gmx_hg2_control.s.hg2tx_en)
  45. return 16;
  46. else
  47. return 1;
  48. }
  49. /*
  50. * Probe a XAUI interface and determine the number of ports
  51. * connected to it. The XAUI interface should still be down
  52. * after this call.
  53. *
  54. * @interface: Interface to probe
  55. *
  56. * Returns Number of ports on the interface. Zero to disable.
  57. */
  58. int __cvmx_helper_xaui_probe(int interface)
  59. {
  60. int i;
  61. union cvmx_gmxx_inf_mode mode;
  62. /*
  63. * Due to errata GMX-700 on CN56XXp1.x and CN52XXp1.x, the
  64. * interface needs to be enabled before IPD otherwise per port
  65. * backpressure may not work properly.
  66. */
  67. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  68. mode.s.en = 1;
  69. cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.u64);
  70. __cvmx_helper_setup_gmx(interface, 1);
  71. /*
  72. * Setup PKO to support 16 ports for HiGig2 virtual
  73. * ports. We're pointing all of the PKO packet ports for this
  74. * interface to the XAUI. This allows us to use HiGig2
  75. * backpressure per port.
  76. */
  77. for (i = 0; i < 16; i++) {
  78. union cvmx_pko_mem_port_ptrs pko_mem_port_ptrs;
  79. pko_mem_port_ptrs.u64 = 0;
  80. /*
  81. * We set each PKO port to have equal priority in a
  82. * round robin fashion.
  83. */
  84. pko_mem_port_ptrs.s.static_p = 0;
  85. pko_mem_port_ptrs.s.qos_mask = 0xff;
  86. /* All PKO ports map to the same XAUI hardware port */
  87. pko_mem_port_ptrs.s.eid = interface * 4;
  88. pko_mem_port_ptrs.s.pid = interface * 16 + i;
  89. cvmx_write_csr(CVMX_PKO_MEM_PORT_PTRS, pko_mem_port_ptrs.u64);
  90. }
  91. return __cvmx_helper_xaui_enumerate(interface);
  92. }
  93. /*
  94. * Bringup and enable a XAUI interface. After this call packet
  95. * I/O should be fully functional. This is called with IPD
  96. * enabled but PKO disabled.
  97. *
  98. * @interface: Interface to bring up
  99. *
  100. * Returns Zero on success, negative on failure
  101. */
  102. int __cvmx_helper_xaui_enable(int interface)
  103. {
  104. union cvmx_gmxx_prtx_cfg gmx_cfg;
  105. union cvmx_pcsxx_control1_reg xauiCtl;
  106. union cvmx_pcsxx_misc_ctl_reg xauiMiscCtl;
  107. union cvmx_gmxx_tx_xaui_ctl gmxXauiTxCtl;
  108. union cvmx_gmxx_rxx_int_en gmx_rx_int_en;
  109. union cvmx_gmxx_tx_int_en gmx_tx_int_en;
  110. union cvmx_pcsxx_int_en_reg pcsx_int_en_reg;
  111. /* Setup PKND */
  112. if (octeon_has_feature(OCTEON_FEATURE_PKND)) {
  113. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
  114. gmx_cfg.s.pknd = cvmx_helper_get_ipd_port(interface, 0);
  115. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
  116. }
  117. /* (1) Interface has already been enabled. */
  118. /* (2) Disable GMX. */
  119. xauiMiscCtl.u64 = cvmx_read_csr(CVMX_PCSXX_MISC_CTL_REG(interface));
  120. xauiMiscCtl.s.gmxeno = 1;
  121. cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
  122. /* (3) Disable GMX and PCSX interrupts. */
  123. gmx_rx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_EN(0, interface));
  124. cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
  125. gmx_tx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_TX_INT_EN(interface));
  126. cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
  127. pcsx_int_en_reg.u64 = cvmx_read_csr(CVMX_PCSXX_INT_EN_REG(interface));
  128. cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
  129. /* (4) Bring up the PCSX and GMX reconciliation layer. */
  130. /* (4)a Set polarity and lane swapping. */
  131. /* (4)b */
  132. gmxXauiTxCtl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
  133. /* Enable better IFG packing and improves performance */
  134. gmxXauiTxCtl.s.dic_en = 1;
  135. gmxXauiTxCtl.s.uni_en = 0;
  136. cvmx_write_csr(CVMX_GMXX_TX_XAUI_CTL(interface), gmxXauiTxCtl.u64);
  137. /* (4)c Aply reset sequence */
  138. xauiCtl.u64 = cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface));
  139. xauiCtl.s.lo_pwr = 0;
  140. /* Issuing a reset here seems to hang some CN66XX/CN68XX chips. */
  141. if (!OCTEON_IS_MODEL(OCTEON_CN66XX) &&
  142. !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS1_X) &&
  143. !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X))
  144. xauiCtl.s.reset = 1;
  145. cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), xauiCtl.u64);
  146. /* Wait for PCS to come out of reset */
  147. if (CVMX_WAIT_FOR_FIELD64
  148. (CVMX_PCSXX_CONTROL1_REG(interface), union cvmx_pcsxx_control1_reg,
  149. reset, ==, 0, 10000))
  150. return -1;
  151. /* Wait for PCS to be aligned */
  152. if (CVMX_WAIT_FOR_FIELD64
  153. (CVMX_PCSXX_10GBX_STATUS_REG(interface),
  154. union cvmx_pcsxx_10gbx_status_reg, alignd, ==, 1, 10000))
  155. return -1;
  156. /* Wait for RX to be ready */
  157. if (CVMX_WAIT_FOR_FIELD64
  158. (CVMX_GMXX_RX_XAUI_CTL(interface), union cvmx_gmxx_rx_xaui_ctl,
  159. status, ==, 0, 10000))
  160. return -1;
  161. /* (6) Configure GMX */
  162. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
  163. gmx_cfg.s.en = 0;
  164. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
  165. /* Wait for GMX RX to be idle */
  166. if (CVMX_WAIT_FOR_FIELD64
  167. (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
  168. rx_idle, ==, 1, 10000))
  169. return -1;
  170. /* Wait for GMX TX to be idle */
  171. if (CVMX_WAIT_FOR_FIELD64
  172. (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
  173. tx_idle, ==, 1, 10000))
  174. return -1;
  175. /* GMX configure */
  176. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
  177. gmx_cfg.s.speed = 1;
  178. gmx_cfg.s.speed_msb = 0;
  179. gmx_cfg.s.slottime = 1;
  180. cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), 1);
  181. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(0, interface), 512);
  182. cvmx_write_csr(CVMX_GMXX_TXX_BURST(0, interface), 8192);
  183. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
  184. /* (7) Clear out any error state */
  185. cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(0, interface),
  186. cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(0, interface)));
  187. cvmx_write_csr(CVMX_GMXX_TX_INT_REG(interface),
  188. cvmx_read_csr(CVMX_GMXX_TX_INT_REG(interface)));
  189. cvmx_write_csr(CVMX_PCSXX_INT_REG(interface),
  190. cvmx_read_csr(CVMX_PCSXX_INT_REG(interface)));
  191. /* Wait for receive link */
  192. if (CVMX_WAIT_FOR_FIELD64
  193. (CVMX_PCSXX_STATUS1_REG(interface), union cvmx_pcsxx_status1_reg,
  194. rcv_lnk, ==, 1, 10000))
  195. return -1;
  196. if (CVMX_WAIT_FOR_FIELD64
  197. (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
  198. xmtflt, ==, 0, 10000))
  199. return -1;
  200. if (CVMX_WAIT_FOR_FIELD64
  201. (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
  202. rcvflt, ==, 0, 10000))
  203. return -1;
  204. cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), gmx_rx_int_en.u64);
  205. cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), gmx_tx_int_en.u64);
  206. cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), pcsx_int_en_reg.u64);
  207. /* (8) Enable packet reception */
  208. xauiMiscCtl.s.gmxeno = 0;
  209. cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
  210. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
  211. gmx_cfg.s.en = 1;
  212. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
  213. __cvmx_interrupt_pcsx_intx_en_reg_enable(0, interface);
  214. __cvmx_interrupt_pcsx_intx_en_reg_enable(1, interface);
  215. __cvmx_interrupt_pcsx_intx_en_reg_enable(2, interface);
  216. __cvmx_interrupt_pcsx_intx_en_reg_enable(3, interface);
  217. __cvmx_interrupt_pcsxx_int_en_reg_enable(interface);
  218. __cvmx_interrupt_gmxx_enable(interface);
  219. return 0;
  220. }
  221. /*
  222. * Return the link state of an IPD/PKO port as returned by
  223. * auto negotiation. The result of this function may not match
  224. * Octeon's link config if auto negotiation has changed since
  225. * the last call to cvmx_helper_link_set().
  226. *
  227. * @ipd_port: IPD/PKO port to query
  228. *
  229. * Returns Link state
  230. */
  231. union cvmx_helper_link_info __cvmx_helper_xaui_link_get(int ipd_port)
  232. {
  233. int interface = cvmx_helper_get_interface_num(ipd_port);
  234. union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
  235. union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
  236. union cvmx_pcsxx_status1_reg pcsxx_status1_reg;
  237. union cvmx_helper_link_info result;
  238. gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
  239. gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
  240. pcsxx_status1_reg.u64 =
  241. cvmx_read_csr(CVMX_PCSXX_STATUS1_REG(interface));
  242. result.u64 = 0;
  243. /* Only return a link if both RX and TX are happy */
  244. if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0) &&
  245. (pcsxx_status1_reg.s.rcv_lnk == 1)) {
  246. result.s.link_up = 1;
  247. result.s.full_duplex = 1;
  248. result.s.speed = 10000;
  249. } else {
  250. /* Disable GMX and PCSX interrupts. */
  251. cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
  252. cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
  253. cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
  254. }
  255. return result;
  256. }
  257. /*
  258. * Configure an IPD/PKO port for the specified link state. This
  259. * function does not influence auto negotiation at the PHY level.
  260. * The passed link state must always match the link state returned
  261. * by cvmx_helper_link_get().
  262. *
  263. * @ipd_port: IPD/PKO port to configure
  264. * @link_info: The new link state
  265. *
  266. * Returns Zero on success, negative on failure
  267. */
  268. int __cvmx_helper_xaui_link_set(int ipd_port, union cvmx_helper_link_info link_info)
  269. {
  270. int interface = cvmx_helper_get_interface_num(ipd_port);
  271. union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
  272. union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
  273. gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
  274. gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
  275. /* If the link shouldn't be up, then just return */
  276. if (!link_info.s.link_up)
  277. return 0;
  278. /* Do nothing if both RX and TX are happy */
  279. if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0))
  280. return 0;
  281. /* Bring the link up */
  282. return __cvmx_helper_xaui_enable(interface);
  283. }