cvmx-helper-xaui.c 12 KB

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