cvmx-helper-xaui.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2008 Cavium Networks
  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 "cvmx-config.h"
  34. #include "cvmx-helper.h"
  35. #include "cvmx-pko-defs.h"
  36. #include "cvmx-gmxx-defs.h"
  37. #include "cvmx-pcsxx-defs.h"
  38. void __cvmx_interrupt_gmxx_enable(int interface);
  39. void __cvmx_interrupt_pcsx_intx_en_reg_enable(int index, int block);
  40. void __cvmx_interrupt_pcsxx_int_en_reg_enable(int index);
  41. /**
  42. * Probe a XAUI interface and determine the number of ports
  43. * connected to it. The XAUI interface should still be down
  44. * after this call.
  45. *
  46. * @interface: Interface to probe
  47. *
  48. * Returns Number of ports on the interface. Zero to disable.
  49. */
  50. int __cvmx_helper_xaui_probe(int interface)
  51. {
  52. int i;
  53. union cvmx_gmxx_hg2_control gmx_hg2_control;
  54. union cvmx_gmxx_inf_mode mode;
  55. /*
  56. * Due to errata GMX-700 on CN56XXp1.x and CN52XXp1.x, the
  57. * interface needs to be enabled before IPD otherwise per port
  58. * backpressure may not work properly.
  59. */
  60. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  61. mode.s.en = 1;
  62. cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.u64);
  63. __cvmx_helper_setup_gmx(interface, 1);
  64. /*
  65. * Setup PKO to support 16 ports for HiGig2 virtual
  66. * ports. We're pointing all of the PKO packet ports for this
  67. * interface to the XAUI. This allows us to use HiGig2
  68. * backpressure per port.
  69. */
  70. for (i = 0; i < 16; i++) {
  71. union cvmx_pko_mem_port_ptrs pko_mem_port_ptrs;
  72. pko_mem_port_ptrs.u64 = 0;
  73. /*
  74. * We set each PKO port to have equal priority in a
  75. * round robin fashion.
  76. */
  77. pko_mem_port_ptrs.s.static_p = 0;
  78. pko_mem_port_ptrs.s.qos_mask = 0xff;
  79. /* All PKO ports map to the same XAUI hardware port */
  80. pko_mem_port_ptrs.s.eid = interface * 4;
  81. pko_mem_port_ptrs.s.pid = interface * 16 + i;
  82. cvmx_write_csr(CVMX_PKO_MEM_PORT_PTRS, pko_mem_port_ptrs.u64);
  83. }
  84. /* If HiGig2 is enabled return 16 ports, otherwise return 1 port */
  85. gmx_hg2_control.u64 = cvmx_read_csr(CVMX_GMXX_HG2_CONTROL(interface));
  86. if (gmx_hg2_control.s.hg2tx_en)
  87. return 16;
  88. else
  89. return 1;
  90. }
  91. /**
  92. * Bringup and enable a XAUI interface. After this call packet
  93. * I/O should be fully functional. This is called with IPD
  94. * enabled but PKO disabled.
  95. *
  96. * @interface: Interface to bring up
  97. *
  98. * Returns Zero on success, negative on failure
  99. */
  100. int __cvmx_helper_xaui_enable(int interface)
  101. {
  102. union cvmx_gmxx_prtx_cfg gmx_cfg;
  103. union cvmx_pcsxx_control1_reg xauiCtl;
  104. union cvmx_pcsxx_misc_ctl_reg xauiMiscCtl;
  105. union cvmx_gmxx_tx_xaui_ctl gmxXauiTxCtl;
  106. union cvmx_gmxx_rxx_int_en gmx_rx_int_en;
  107. union cvmx_gmxx_tx_int_en gmx_tx_int_en;
  108. union cvmx_pcsxx_int_en_reg pcsx_int_en_reg;
  109. /* (1) Interface has already been enabled. */
  110. /* (2) Disable GMX. */
  111. xauiMiscCtl.u64 = cvmx_read_csr(CVMX_PCSXX_MISC_CTL_REG(interface));
  112. xauiMiscCtl.s.gmxeno = 1;
  113. cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
  114. /* (3) Disable GMX and PCSX interrupts. */
  115. gmx_rx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_EN(0, interface));
  116. cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
  117. gmx_tx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_TX_INT_EN(interface));
  118. cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
  119. pcsx_int_en_reg.u64 = cvmx_read_csr(CVMX_PCSXX_INT_EN_REG(interface));
  120. cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
  121. /* (4) Bring up the PCSX and GMX reconciliation layer. */
  122. /* (4)a Set polarity and lane swapping. */
  123. /* (4)b */
  124. gmxXauiTxCtl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
  125. /* Enable better IFG packing and improves performance */
  126. gmxXauiTxCtl.s.dic_en = 1;
  127. gmxXauiTxCtl.s.uni_en = 0;
  128. cvmx_write_csr(CVMX_GMXX_TX_XAUI_CTL(interface), gmxXauiTxCtl.u64);
  129. /* (4)c Aply reset sequence */
  130. xauiCtl.u64 = cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface));
  131. xauiCtl.s.lo_pwr = 0;
  132. xauiCtl.s.reset = 1;
  133. cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), xauiCtl.u64);
  134. /* Wait for PCS to come out of reset */
  135. if (CVMX_WAIT_FOR_FIELD64
  136. (CVMX_PCSXX_CONTROL1_REG(interface), union cvmx_pcsxx_control1_reg,
  137. reset, ==, 0, 10000))
  138. return -1;
  139. /* Wait for PCS to be aligned */
  140. if (CVMX_WAIT_FOR_FIELD64
  141. (CVMX_PCSXX_10GBX_STATUS_REG(interface),
  142. union cvmx_pcsxx_10gbx_status_reg, alignd, ==, 1, 10000))
  143. return -1;
  144. /* Wait for RX to be ready */
  145. if (CVMX_WAIT_FOR_FIELD64
  146. (CVMX_GMXX_RX_XAUI_CTL(interface), union cvmx_gmxx_rx_xaui_ctl,
  147. status, ==, 0, 10000))
  148. return -1;
  149. /* (6) Configure GMX */
  150. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
  151. gmx_cfg.s.en = 0;
  152. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
  153. /* Wait for GMX RX to be idle */
  154. if (CVMX_WAIT_FOR_FIELD64
  155. (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
  156. rx_idle, ==, 1, 10000))
  157. return -1;
  158. /* Wait for GMX TX to be idle */
  159. if (CVMX_WAIT_FOR_FIELD64
  160. (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
  161. tx_idle, ==, 1, 10000))
  162. return -1;
  163. /* GMX configure */
  164. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
  165. gmx_cfg.s.speed = 1;
  166. gmx_cfg.s.speed_msb = 0;
  167. gmx_cfg.s.slottime = 1;
  168. cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), 1);
  169. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(0, interface), 512);
  170. cvmx_write_csr(CVMX_GMXX_TXX_BURST(0, interface), 8192);
  171. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
  172. /* (7) Clear out any error state */
  173. cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(0, interface),
  174. cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(0, interface)));
  175. cvmx_write_csr(CVMX_GMXX_TX_INT_REG(interface),
  176. cvmx_read_csr(CVMX_GMXX_TX_INT_REG(interface)));
  177. cvmx_write_csr(CVMX_PCSXX_INT_REG(interface),
  178. cvmx_read_csr(CVMX_PCSXX_INT_REG(interface)));
  179. /* Wait for receive link */
  180. if (CVMX_WAIT_FOR_FIELD64
  181. (CVMX_PCSXX_STATUS1_REG(interface), union cvmx_pcsxx_status1_reg,
  182. rcv_lnk, ==, 1, 10000))
  183. return -1;
  184. if (CVMX_WAIT_FOR_FIELD64
  185. (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
  186. xmtflt, ==, 0, 10000))
  187. return -1;
  188. if (CVMX_WAIT_FOR_FIELD64
  189. (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
  190. rcvflt, ==, 0, 10000))
  191. return -1;
  192. cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), gmx_rx_int_en.u64);
  193. cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), gmx_tx_int_en.u64);
  194. cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), pcsx_int_en_reg.u64);
  195. cvmx_helper_link_autoconf(cvmx_helper_get_ipd_port(interface, 0));
  196. /* (8) Enable packet reception */
  197. xauiMiscCtl.s.gmxeno = 0;
  198. cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
  199. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
  200. gmx_cfg.s.en = 1;
  201. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
  202. __cvmx_interrupt_pcsx_intx_en_reg_enable(0, interface);
  203. __cvmx_interrupt_pcsx_intx_en_reg_enable(1, interface);
  204. __cvmx_interrupt_pcsx_intx_en_reg_enable(2, interface);
  205. __cvmx_interrupt_pcsx_intx_en_reg_enable(3, interface);
  206. __cvmx_interrupt_pcsxx_int_en_reg_enable(interface);
  207. __cvmx_interrupt_gmxx_enable(interface);
  208. return 0;
  209. }
  210. /**
  211. * Return the link state of an IPD/PKO port as returned by
  212. * auto negotiation. The result of this function may not match
  213. * Octeon's link config if auto negotiation has changed since
  214. * the last call to cvmx_helper_link_set().
  215. *
  216. * @ipd_port: IPD/PKO port to query
  217. *
  218. * Returns Link state
  219. */
  220. cvmx_helper_link_info_t __cvmx_helper_xaui_link_get(int ipd_port)
  221. {
  222. int interface = cvmx_helper_get_interface_num(ipd_port);
  223. union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
  224. union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
  225. union cvmx_pcsxx_status1_reg pcsxx_status1_reg;
  226. cvmx_helper_link_info_t result;
  227. gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
  228. gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
  229. pcsxx_status1_reg.u64 =
  230. cvmx_read_csr(CVMX_PCSXX_STATUS1_REG(interface));
  231. result.u64 = 0;
  232. /* Only return a link if both RX and TX are happy */
  233. if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0) &&
  234. (pcsxx_status1_reg.s.rcv_lnk == 1)) {
  235. result.s.link_up = 1;
  236. result.s.full_duplex = 1;
  237. result.s.speed = 10000;
  238. } else {
  239. /* Disable GMX and PCSX interrupts. */
  240. cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
  241. cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
  242. cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
  243. }
  244. return result;
  245. }
  246. /**
  247. * Configure an IPD/PKO port for the specified link state. This
  248. * function does not influence auto negotiation at the PHY level.
  249. * The passed link state must always match the link state returned
  250. * by cvmx_helper_link_get(). It is normally best to use
  251. * cvmx_helper_link_autoconf() instead.
  252. *
  253. * @ipd_port: IPD/PKO port to configure
  254. * @link_info: The new link state
  255. *
  256. * Returns Zero on success, negative on failure
  257. */
  258. int __cvmx_helper_xaui_link_set(int ipd_port, cvmx_helper_link_info_t link_info)
  259. {
  260. int interface = cvmx_helper_get_interface_num(ipd_port);
  261. union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
  262. union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
  263. gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
  264. gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
  265. /* If the link shouldn't be up, then just return */
  266. if (!link_info.s.link_up)
  267. return 0;
  268. /* Do nothing if both RX and TX are happy */
  269. if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0))
  270. return 0;
  271. /* Bring the link up */
  272. return __cvmx_helper_xaui_enable(interface);
  273. }
  274. /**
  275. * Configure a port for internal and/or external loopback. Internal loopback
  276. * causes packets sent by the port to be received by Octeon. External loopback
  277. * causes packets received from the wire to sent out again.
  278. *
  279. * @ipd_port: IPD/PKO port to loopback.
  280. * @enable_internal:
  281. * Non zero if you want internal loopback
  282. * @enable_external:
  283. * Non zero if you want external loopback
  284. *
  285. * Returns Zero on success, negative on failure.
  286. */
  287. extern int __cvmx_helper_xaui_configure_loopback(int ipd_port,
  288. int enable_internal,
  289. int enable_external)
  290. {
  291. int interface = cvmx_helper_get_interface_num(ipd_port);
  292. union cvmx_pcsxx_control1_reg pcsxx_control1_reg;
  293. union cvmx_gmxx_xaui_ext_loopback gmxx_xaui_ext_loopback;
  294. /* Set the internal loop */
  295. pcsxx_control1_reg.u64 =
  296. cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface));
  297. pcsxx_control1_reg.s.loopbck1 = enable_internal;
  298. cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface),
  299. pcsxx_control1_reg.u64);
  300. /* Set the external loop */
  301. gmxx_xaui_ext_loopback.u64 =
  302. cvmx_read_csr(CVMX_GMXX_XAUI_EXT_LOOPBACK(interface));
  303. gmxx_xaui_ext_loopback.s.en = enable_external;
  304. cvmx_write_csr(CVMX_GMXX_XAUI_EXT_LOOPBACK(interface),
  305. gmxx_xaui_ext_loopback.u64);
  306. /* Take the link through a reset */
  307. return __cvmx_helper_xaui_enable(interface);
  308. }