cvmx-helper-rgmii.c 17 KB

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