cvmx-helper-rgmii.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 RGMII/GMII/MII initialization, configuration,
  29. * and monitoring.
  30. */
  31. #include <asm/octeon/octeon.h>
  32. #include "cvmx-config.h"
  33. #include "cvmx-mdio.h"
  34. #include "cvmx-pko.h"
  35. #include "cvmx-helper.h"
  36. #include "cvmx-helper-board.h"
  37. #include <asm/octeon/cvmx-npi-defs.h>
  38. #include "cvmx-gmxx-defs.h"
  39. #include "cvmx-asxx-defs.h"
  40. #include "cvmx-dbg-defs.h"
  41. void __cvmx_interrupt_gmxx_enable(int interface);
  42. void __cvmx_interrupt_asxx_enable(int block);
  43. /**
  44. * Probe RGMII ports and determine the number present
  45. *
  46. * @interface: Interface to probe
  47. *
  48. * Returns Number of RGMII/GMII/MII ports (0-4).
  49. */
  50. int __cvmx_helper_rgmii_probe(int interface)
  51. {
  52. int num_ports = 0;
  53. union cvmx_gmxx_inf_mode mode;
  54. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  55. if (mode.s.type) {
  56. if (OCTEON_IS_MODEL(OCTEON_CN38XX)
  57. || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
  58. cvmx_dprintf("ERROR: RGMII initialize called in "
  59. "SPI interface\n");
  60. } else if (OCTEON_IS_MODEL(OCTEON_CN31XX)
  61. || OCTEON_IS_MODEL(OCTEON_CN30XX)
  62. || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  63. /*
  64. * On these chips "type" says we're in
  65. * GMII/MII mode. This limits us to 2 ports
  66. */
  67. num_ports = 2;
  68. } else {
  69. cvmx_dprintf("ERROR: Unsupported Octeon model in %s\n",
  70. __func__);
  71. }
  72. } else {
  73. if (OCTEON_IS_MODEL(OCTEON_CN38XX)
  74. || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
  75. num_ports = 4;
  76. } else if (OCTEON_IS_MODEL(OCTEON_CN31XX)
  77. || OCTEON_IS_MODEL(OCTEON_CN30XX)
  78. || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  79. num_ports = 3;
  80. } else {
  81. cvmx_dprintf("ERROR: Unsupported Octeon model in %s\n",
  82. __func__);
  83. }
  84. }
  85. return num_ports;
  86. }
  87. /**
  88. * Put an RGMII interface in loopback mode. Internal packets sent
  89. * out will be received back again on the same port. Externally
  90. * received packets will echo back out.
  91. *
  92. * @port: IPD port number to loop.
  93. */
  94. void cvmx_helper_rgmii_internal_loopback(int port)
  95. {
  96. int interface = (port >> 4) & 1;
  97. int index = port & 0xf;
  98. uint64_t tmp;
  99. union cvmx_gmxx_prtx_cfg gmx_cfg;
  100. gmx_cfg.u64 = 0;
  101. gmx_cfg.s.duplex = 1;
  102. gmx_cfg.s.slottime = 1;
  103. gmx_cfg.s.speed = 1;
  104. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 1);
  105. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x200);
  106. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0x2000);
  107. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  108. tmp = cvmx_read_csr(CVMX_ASXX_PRT_LOOP(interface));
  109. cvmx_write_csr(CVMX_ASXX_PRT_LOOP(interface), (1 << index) | tmp);
  110. tmp = cvmx_read_csr(CVMX_ASXX_TX_PRT_EN(interface));
  111. cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(interface), (1 << index) | tmp);
  112. tmp = cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface));
  113. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface), (1 << index) | tmp);
  114. gmx_cfg.s.en = 1;
  115. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  116. }
  117. /**
  118. * Workaround ASX setup errata with CN38XX pass1
  119. *
  120. * @interface: Interface to setup
  121. * @port: Port to setup (0..3)
  122. * @cpu_clock_hz:
  123. * Chip frequency in Hertz
  124. *
  125. * Returns Zero on success, negative on failure
  126. */
  127. static int __cvmx_helper_errata_asx_pass1(int interface, int port,
  128. int cpu_clock_hz)
  129. {
  130. /* Set hi water mark as per errata GMX-4 */
  131. if (cpu_clock_hz >= 325000000 && cpu_clock_hz < 375000000)
  132. cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 12);
  133. else if (cpu_clock_hz >= 375000000 && cpu_clock_hz < 437000000)
  134. cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 11);
  135. else if (cpu_clock_hz >= 437000000 && cpu_clock_hz < 550000000)
  136. cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 10);
  137. else if (cpu_clock_hz >= 550000000 && cpu_clock_hz < 687000000)
  138. cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 9);
  139. else
  140. cvmx_dprintf("Illegal clock frequency (%d). "
  141. "CVMX_ASXX_TX_HI_WATERX not set\n", cpu_clock_hz);
  142. return 0;
  143. }
  144. /**
  145. * Configure all of the ASX, GMX, and PKO regsiters required
  146. * to get RGMII to function on the supplied interface.
  147. *
  148. * @interface: PKO Interface to configure (0 or 1)
  149. *
  150. * Returns Zero on success
  151. */
  152. int __cvmx_helper_rgmii_enable(int interface)
  153. {
  154. int num_ports = cvmx_helper_ports_on_interface(interface);
  155. int port;
  156. struct cvmx_sysinfo *sys_info_ptr = cvmx_sysinfo_get();
  157. union cvmx_gmxx_inf_mode mode;
  158. union cvmx_asxx_tx_prt_en asx_tx;
  159. union cvmx_asxx_rx_prt_en asx_rx;
  160. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  161. if (mode.s.en == 0)
  162. return -1;
  163. if ((OCTEON_IS_MODEL(OCTEON_CN38XX) ||
  164. OCTEON_IS_MODEL(OCTEON_CN58XX)) && mode.s.type == 1)
  165. /* Ignore SPI interfaces */
  166. return -1;
  167. /* Configure the ASX registers needed to use the RGMII ports */
  168. asx_tx.u64 = 0;
  169. asx_tx.s.prt_en = cvmx_build_mask(num_ports);
  170. cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(interface), asx_tx.u64);
  171. asx_rx.u64 = 0;
  172. asx_rx.s.prt_en = cvmx_build_mask(num_ports);
  173. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface), asx_rx.u64);
  174. /* Configure the GMX registers needed to use the RGMII ports */
  175. for (port = 0; port < num_ports; port++) {
  176. /* Setting of CVMX_GMXX_TXX_THRESH has been moved to
  177. __cvmx_helper_setup_gmx() */
  178. if (cvmx_octeon_is_pass1())
  179. __cvmx_helper_errata_asx_pass1(interface, port,
  180. sys_info_ptr->
  181. cpu_clock_hz);
  182. else {
  183. /*
  184. * Configure more flexible RGMII preamble
  185. * checking. Pass 1 doesn't support this
  186. * feature.
  187. */
  188. union cvmx_gmxx_rxx_frm_ctl frm_ctl;
  189. frm_ctl.u64 =
  190. cvmx_read_csr(CVMX_GMXX_RXX_FRM_CTL
  191. (port, interface));
  192. /* New field, so must be compile time */
  193. frm_ctl.s.pre_free = 1;
  194. cvmx_write_csr(CVMX_GMXX_RXX_FRM_CTL(port, interface),
  195. frm_ctl.u64);
  196. }
  197. /*
  198. * Each pause frame transmitted will ask for about 10M
  199. * bit times before resume. If buffer space comes
  200. * available before that time has expired, an XON
  201. * pause frame (0 time) will be transmitted to restart
  202. * the flow.
  203. */
  204. cvmx_write_csr(CVMX_GMXX_TXX_PAUSE_PKT_TIME(port, interface),
  205. 20000);
  206. cvmx_write_csr(CVMX_GMXX_TXX_PAUSE_PKT_INTERVAL
  207. (port, interface), 19000);
  208. if (OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  209. cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface),
  210. 16);
  211. cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface),
  212. 16);
  213. } else {
  214. cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface),
  215. 24);
  216. cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface),
  217. 24);
  218. }
  219. }
  220. __cvmx_helper_setup_gmx(interface, num_ports);
  221. /* enable the ports now */
  222. for (port = 0; port < num_ports; port++) {
  223. union cvmx_gmxx_prtx_cfg gmx_cfg;
  224. cvmx_helper_link_autoconf(cvmx_helper_get_ipd_port
  225. (interface, port));
  226. gmx_cfg.u64 =
  227. cvmx_read_csr(CVMX_GMXX_PRTX_CFG(port, interface));
  228. gmx_cfg.s.en = 1;
  229. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(port, interface),
  230. gmx_cfg.u64);
  231. }
  232. __cvmx_interrupt_asxx_enable(interface);
  233. __cvmx_interrupt_gmxx_enable(interface);
  234. return 0;
  235. }
  236. /**
  237. * Return the link state of an IPD/PKO port as returned by
  238. * auto negotiation. The result of this function may not match
  239. * Octeon's link config if auto negotiation has changed since
  240. * the last call to cvmx_helper_link_set().
  241. *
  242. * @ipd_port: IPD/PKO port to query
  243. *
  244. * Returns Link state
  245. */
  246. cvmx_helper_link_info_t __cvmx_helper_rgmii_link_get(int ipd_port)
  247. {
  248. int interface = cvmx_helper_get_interface_num(ipd_port);
  249. int index = cvmx_helper_get_interface_index_num(ipd_port);
  250. union cvmx_asxx_prt_loop asxx_prt_loop;
  251. asxx_prt_loop.u64 = cvmx_read_csr(CVMX_ASXX_PRT_LOOP(interface));
  252. if (asxx_prt_loop.s.int_loop & (1 << index)) {
  253. /* Force 1Gbps full duplex on internal loopback */
  254. cvmx_helper_link_info_t result;
  255. result.u64 = 0;
  256. result.s.full_duplex = 1;
  257. result.s.link_up = 1;
  258. result.s.speed = 1000;
  259. return result;
  260. } else
  261. return __cvmx_helper_board_link_get(ipd_port);
  262. }
  263. /**
  264. * Configure an IPD/PKO port for the specified link state. This
  265. * function does not influence auto negotiation at the PHY level.
  266. * The passed link state must always match the link state returned
  267. * by cvmx_helper_link_get(). It is normally best to use
  268. * cvmx_helper_link_autoconf() instead.
  269. *
  270. * @ipd_port: IPD/PKO port to configure
  271. * @link_info: The new link state
  272. *
  273. * Returns Zero on success, negative on failure
  274. */
  275. int __cvmx_helper_rgmii_link_set(int ipd_port,
  276. cvmx_helper_link_info_t link_info)
  277. {
  278. int result = 0;
  279. int interface = cvmx_helper_get_interface_num(ipd_port);
  280. int index = cvmx_helper_get_interface_index_num(ipd_port);
  281. union cvmx_gmxx_prtx_cfg original_gmx_cfg;
  282. union cvmx_gmxx_prtx_cfg new_gmx_cfg;
  283. union cvmx_pko_mem_queue_qos pko_mem_queue_qos;
  284. union cvmx_pko_mem_queue_qos pko_mem_queue_qos_save[16];
  285. union cvmx_gmxx_tx_ovr_bp gmx_tx_ovr_bp;
  286. union cvmx_gmxx_tx_ovr_bp gmx_tx_ovr_bp_save;
  287. int i;
  288. /* Ignore speed sets in the simulator */
  289. if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM)
  290. return 0;
  291. /* Read the current settings so we know the current enable state */
  292. original_gmx_cfg.u64 =
  293. cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  294. new_gmx_cfg = original_gmx_cfg;
  295. /* Disable the lowest level RX */
  296. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface),
  297. cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface)) &
  298. ~(1 << index));
  299. /* Disable all queues so that TX should become idle */
  300. for (i = 0; i < cvmx_pko_get_num_queues(ipd_port); i++) {
  301. int queue = cvmx_pko_get_base_queue(ipd_port) + i;
  302. cvmx_write_csr(CVMX_PKO_REG_READ_IDX, queue);
  303. pko_mem_queue_qos.u64 = cvmx_read_csr(CVMX_PKO_MEM_QUEUE_QOS);
  304. pko_mem_queue_qos.s.pid = ipd_port;
  305. pko_mem_queue_qos.s.qid = queue;
  306. pko_mem_queue_qos_save[i] = pko_mem_queue_qos;
  307. pko_mem_queue_qos.s.qos_mask = 0;
  308. cvmx_write_csr(CVMX_PKO_MEM_QUEUE_QOS, pko_mem_queue_qos.u64);
  309. }
  310. /* Disable backpressure */
  311. gmx_tx_ovr_bp.u64 = cvmx_read_csr(CVMX_GMXX_TX_OVR_BP(interface));
  312. gmx_tx_ovr_bp_save = gmx_tx_ovr_bp;
  313. gmx_tx_ovr_bp.s.bp &= ~(1 << index);
  314. gmx_tx_ovr_bp.s.en |= 1 << index;
  315. cvmx_write_csr(CVMX_GMXX_TX_OVR_BP(interface), gmx_tx_ovr_bp.u64);
  316. cvmx_read_csr(CVMX_GMXX_TX_OVR_BP(interface));
  317. /*
  318. * Poll the GMX state machine waiting for it to become
  319. * idle. Preferably we should only change speed when it is
  320. * idle. If it doesn't become idle we will still do the speed
  321. * change, but there is a slight chance that GMX will
  322. * lockup.
  323. */
  324. cvmx_write_csr(CVMX_NPI_DBG_SELECT,
  325. interface * 0x800 + index * 0x100 + 0x880);
  326. CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, union cvmx_dbg_data, data & 7,
  327. ==, 0, 10000);
  328. CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, union cvmx_dbg_data, data & 0xf,
  329. ==, 0, 10000);
  330. /* Disable the port before we make any changes */
  331. new_gmx_cfg.s.en = 0;
  332. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
  333. cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  334. /* Set full/half duplex */
  335. if (cvmx_octeon_is_pass1())
  336. /* Half duplex is broken for 38XX Pass 1 */
  337. new_gmx_cfg.s.duplex = 1;
  338. else if (!link_info.s.link_up)
  339. /* Force full duplex on down links */
  340. new_gmx_cfg.s.duplex = 1;
  341. else
  342. new_gmx_cfg.s.duplex = link_info.s.full_duplex;
  343. /* Set the link speed. Anything unknown is set to 1Gbps */
  344. if (link_info.s.speed == 10) {
  345. new_gmx_cfg.s.slottime = 0;
  346. new_gmx_cfg.s.speed = 0;
  347. } else if (link_info.s.speed == 100) {
  348. new_gmx_cfg.s.slottime = 0;
  349. new_gmx_cfg.s.speed = 0;
  350. } else {
  351. new_gmx_cfg.s.slottime = 1;
  352. new_gmx_cfg.s.speed = 1;
  353. }
  354. /* Adjust the clocks */
  355. if (link_info.s.speed == 10) {
  356. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 50);
  357. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x40);
  358. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
  359. } else if (link_info.s.speed == 100) {
  360. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 5);
  361. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x40);
  362. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
  363. } else {
  364. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 1);
  365. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x200);
  366. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0x2000);
  367. }
  368. if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  369. if ((link_info.s.speed == 10) || (link_info.s.speed == 100)) {
  370. union cvmx_gmxx_inf_mode mode;
  371. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  372. /*
  373. * Port .en .type .p0mii Configuration
  374. * ---- --- ----- ------ -----------------------------------------
  375. * X 0 X X All links are disabled.
  376. * 0 1 X 0 Port 0 is RGMII
  377. * 0 1 X 1 Port 0 is MII
  378. * 1 1 0 X Ports 1 and 2 are configured as RGMII ports.
  379. * 1 1 1 X Port 1: GMII/MII; Port 2: disabled. GMII or
  380. * MII port is selected by GMX_PRT1_CFG[SPEED].
  381. */
  382. /* In MII mode, CLK_CNT = 1. */
  383. if (((index == 0) && (mode.s.p0mii == 1))
  384. || ((index != 0) && (mode.s.type == 1))) {
  385. cvmx_write_csr(CVMX_GMXX_TXX_CLK
  386. (index, interface), 1);
  387. }
  388. }
  389. }
  390. /* Do a read to make sure all setup stuff is complete */
  391. cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  392. /* Save the new GMX setting without enabling the port */
  393. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
  394. /* Enable the lowest level RX */
  395. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface),
  396. cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface)) | (1 <<
  397. index));
  398. /* Re-enable the TX path */
  399. for (i = 0; i < cvmx_pko_get_num_queues(ipd_port); i++) {
  400. int queue = cvmx_pko_get_base_queue(ipd_port) + i;
  401. cvmx_write_csr(CVMX_PKO_REG_READ_IDX, queue);
  402. cvmx_write_csr(CVMX_PKO_MEM_QUEUE_QOS,
  403. pko_mem_queue_qos_save[i].u64);
  404. }
  405. /* Restore backpressure */
  406. cvmx_write_csr(CVMX_GMXX_TX_OVR_BP(interface), gmx_tx_ovr_bp_save.u64);
  407. /* Restore the GMX enable state. Port config is complete */
  408. new_gmx_cfg.s.en = original_gmx_cfg.s.en;
  409. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
  410. return result;
  411. }
  412. /**
  413. * Configure a port for internal and/or external loopback. Internal loopback
  414. * causes packets sent by the port to be received by Octeon. External loopback
  415. * causes packets received from the wire to sent out again.
  416. *
  417. * @ipd_port: IPD/PKO port to loopback.
  418. * @enable_internal:
  419. * Non zero if you want internal loopback
  420. * @enable_external:
  421. * Non zero if you want external loopback
  422. *
  423. * Returns Zero on success, negative on failure.
  424. */
  425. int __cvmx_helper_rgmii_configure_loopback(int ipd_port, int enable_internal,
  426. int enable_external)
  427. {
  428. int interface = cvmx_helper_get_interface_num(ipd_port);
  429. int index = cvmx_helper_get_interface_index_num(ipd_port);
  430. int original_enable;
  431. union cvmx_gmxx_prtx_cfg gmx_cfg;
  432. union cvmx_asxx_prt_loop asxx_prt_loop;
  433. /* Read the current enable state and save it */
  434. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  435. original_enable = gmx_cfg.s.en;
  436. /* Force port to be disabled */
  437. gmx_cfg.s.en = 0;
  438. if (enable_internal) {
  439. /* Force speed if we're doing internal loopback */
  440. gmx_cfg.s.duplex = 1;
  441. gmx_cfg.s.slottime = 1;
  442. gmx_cfg.s.speed = 1;
  443. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 1);
  444. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x200);
  445. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0x2000);
  446. }
  447. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  448. /* Set the loopback bits */
  449. asxx_prt_loop.u64 = cvmx_read_csr(CVMX_ASXX_PRT_LOOP(interface));
  450. if (enable_internal)
  451. asxx_prt_loop.s.int_loop |= 1 << index;
  452. else
  453. asxx_prt_loop.s.int_loop &= ~(1 << index);
  454. if (enable_external)
  455. asxx_prt_loop.s.ext_loop |= 1 << index;
  456. else
  457. asxx_prt_loop.s.ext_loop &= ~(1 << index);
  458. cvmx_write_csr(CVMX_ASXX_PRT_LOOP(interface), asxx_prt_loop.u64);
  459. /* Force enables in internal loopback */
  460. if (enable_internal) {
  461. uint64_t tmp;
  462. tmp = cvmx_read_csr(CVMX_ASXX_TX_PRT_EN(interface));
  463. cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(interface),
  464. (1 << index) | tmp);
  465. tmp = cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface));
  466. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface),
  467. (1 << index) | tmp);
  468. original_enable = 1;
  469. }
  470. /* Restore the enable state */
  471. gmx_cfg.s.en = original_enable;
  472. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  473. return 0;
  474. }