cvmx-helper-rgmii.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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-mdio.h>
  34. #include <asm/octeon/cvmx-pko.h>
  35. #include <asm/octeon/cvmx-helper.h>
  36. #include <asm/octeon/cvmx-helper-board.h>
  37. #include <asm/octeon/cvmx-npi-defs.h>
  38. #include <asm/octeon/cvmx-gmxx-defs.h>
  39. #include <asm/octeon/cvmx-asxx-defs.h>
  40. #include <asm/octeon/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. memset(pko_mem_queue_qos_save, 0, sizeof(pko_mem_queue_qos_save));
  300. /* Disable all queues so that TX should become idle */
  301. for (i = 0; i < cvmx_pko_get_num_queues(ipd_port); i++) {
  302. int queue = cvmx_pko_get_base_queue(ipd_port) + i;
  303. cvmx_write_csr(CVMX_PKO_REG_READ_IDX, queue);
  304. pko_mem_queue_qos.u64 = cvmx_read_csr(CVMX_PKO_MEM_QUEUE_QOS);
  305. pko_mem_queue_qos.s.pid = ipd_port;
  306. pko_mem_queue_qos.s.qid = queue;
  307. pko_mem_queue_qos_save[i] = pko_mem_queue_qos;
  308. pko_mem_queue_qos.s.qos_mask = 0;
  309. cvmx_write_csr(CVMX_PKO_MEM_QUEUE_QOS, pko_mem_queue_qos.u64);
  310. }
  311. /* Disable backpressure */
  312. gmx_tx_ovr_bp.u64 = cvmx_read_csr(CVMX_GMXX_TX_OVR_BP(interface));
  313. gmx_tx_ovr_bp_save = gmx_tx_ovr_bp;
  314. gmx_tx_ovr_bp.s.bp &= ~(1 << index);
  315. gmx_tx_ovr_bp.s.en |= 1 << index;
  316. cvmx_write_csr(CVMX_GMXX_TX_OVR_BP(interface), gmx_tx_ovr_bp.u64);
  317. cvmx_read_csr(CVMX_GMXX_TX_OVR_BP(interface));
  318. /*
  319. * Poll the GMX state machine waiting for it to become
  320. * idle. Preferably we should only change speed when it is
  321. * idle. If it doesn't become idle we will still do the speed
  322. * change, but there is a slight chance that GMX will
  323. * lockup.
  324. */
  325. cvmx_write_csr(CVMX_NPI_DBG_SELECT,
  326. interface * 0x800 + index * 0x100 + 0x880);
  327. CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, union cvmx_dbg_data, data & 7,
  328. ==, 0, 10000);
  329. CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, union cvmx_dbg_data, data & 0xf,
  330. ==, 0, 10000);
  331. /* Disable the port before we make any changes */
  332. new_gmx_cfg.s.en = 0;
  333. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
  334. cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  335. /* Set full/half duplex */
  336. if (cvmx_octeon_is_pass1())
  337. /* Half duplex is broken for 38XX Pass 1 */
  338. new_gmx_cfg.s.duplex = 1;
  339. else if (!link_info.s.link_up)
  340. /* Force full duplex on down links */
  341. new_gmx_cfg.s.duplex = 1;
  342. else
  343. new_gmx_cfg.s.duplex = link_info.s.full_duplex;
  344. /* Set the link speed. Anything unknown is set to 1Gbps */
  345. if (link_info.s.speed == 10) {
  346. new_gmx_cfg.s.slottime = 0;
  347. new_gmx_cfg.s.speed = 0;
  348. } else if (link_info.s.speed == 100) {
  349. new_gmx_cfg.s.slottime = 0;
  350. new_gmx_cfg.s.speed = 0;
  351. } else {
  352. new_gmx_cfg.s.slottime = 1;
  353. new_gmx_cfg.s.speed = 1;
  354. }
  355. /* Adjust the clocks */
  356. if (link_info.s.speed == 10) {
  357. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 50);
  358. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x40);
  359. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
  360. } else if (link_info.s.speed == 100) {
  361. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 5);
  362. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x40);
  363. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
  364. } else {
  365. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 1);
  366. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x200);
  367. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0x2000);
  368. }
  369. if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  370. if ((link_info.s.speed == 10) || (link_info.s.speed == 100)) {
  371. union cvmx_gmxx_inf_mode mode;
  372. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  373. /*
  374. * Port .en .type .p0mii Configuration
  375. * ---- --- ----- ------ -----------------------------------------
  376. * X 0 X X All links are disabled.
  377. * 0 1 X 0 Port 0 is RGMII
  378. * 0 1 X 1 Port 0 is MII
  379. * 1 1 0 X Ports 1 and 2 are configured as RGMII ports.
  380. * 1 1 1 X Port 1: GMII/MII; Port 2: disabled. GMII or
  381. * MII port is selected by GMX_PRT1_CFG[SPEED].
  382. */
  383. /* In MII mode, CLK_CNT = 1. */
  384. if (((index == 0) && (mode.s.p0mii == 1))
  385. || ((index != 0) && (mode.s.type == 1))) {
  386. cvmx_write_csr(CVMX_GMXX_TXX_CLK
  387. (index, interface), 1);
  388. }
  389. }
  390. }
  391. /* Do a read to make sure all setup stuff is complete */
  392. cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  393. /* Save the new GMX setting without enabling the port */
  394. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
  395. /* Enable the lowest level RX */
  396. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface),
  397. cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface)) | (1 <<
  398. index));
  399. /* Re-enable the TX path */
  400. for (i = 0; i < cvmx_pko_get_num_queues(ipd_port); i++) {
  401. int queue = cvmx_pko_get_base_queue(ipd_port) + i;
  402. cvmx_write_csr(CVMX_PKO_REG_READ_IDX, queue);
  403. cvmx_write_csr(CVMX_PKO_MEM_QUEUE_QOS,
  404. pko_mem_queue_qos_save[i].u64);
  405. }
  406. /* Restore backpressure */
  407. cvmx_write_csr(CVMX_GMXX_TX_OVR_BP(interface), gmx_tx_ovr_bp_save.u64);
  408. /* Restore the GMX enable state. Port config is complete */
  409. new_gmx_cfg.s.en = original_gmx_cfg.s.en;
  410. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
  411. return result;
  412. }
  413. /**
  414. * Configure a port for internal and/or external loopback. Internal loopback
  415. * causes packets sent by the port to be received by Octeon. External loopback
  416. * causes packets received from the wire to sent out again.
  417. *
  418. * @ipd_port: IPD/PKO port to loopback.
  419. * @enable_internal:
  420. * Non zero if you want internal loopback
  421. * @enable_external:
  422. * Non zero if you want external loopback
  423. *
  424. * Returns Zero on success, negative on failure.
  425. */
  426. int __cvmx_helper_rgmii_configure_loopback(int ipd_port, int enable_internal,
  427. int enable_external)
  428. {
  429. int interface = cvmx_helper_get_interface_num(ipd_port);
  430. int index = cvmx_helper_get_interface_index_num(ipd_port);
  431. int original_enable;
  432. union cvmx_gmxx_prtx_cfg gmx_cfg;
  433. union cvmx_asxx_prt_loop asxx_prt_loop;
  434. /* Read the current enable state and save it */
  435. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  436. original_enable = gmx_cfg.s.en;
  437. /* Force port to be disabled */
  438. gmx_cfg.s.en = 0;
  439. if (enable_internal) {
  440. /* Force speed if we're doing internal loopback */
  441. gmx_cfg.s.duplex = 1;
  442. gmx_cfg.s.slottime = 1;
  443. gmx_cfg.s.speed = 1;
  444. cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 1);
  445. cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x200);
  446. cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0x2000);
  447. }
  448. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  449. /* Set the loopback bits */
  450. asxx_prt_loop.u64 = cvmx_read_csr(CVMX_ASXX_PRT_LOOP(interface));
  451. if (enable_internal)
  452. asxx_prt_loop.s.int_loop |= 1 << index;
  453. else
  454. asxx_prt_loop.s.int_loop &= ~(1 << index);
  455. if (enable_external)
  456. asxx_prt_loop.s.ext_loop |= 1 << index;
  457. else
  458. asxx_prt_loop.s.ext_loop &= ~(1 << index);
  459. cvmx_write_csr(CVMX_ASXX_PRT_LOOP(interface), asxx_prt_loop.u64);
  460. /* Force enables in internal loopback */
  461. if (enable_internal) {
  462. uint64_t tmp;
  463. tmp = cvmx_read_csr(CVMX_ASXX_TX_PRT_EN(interface));
  464. cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(interface),
  465. (1 << index) | tmp);
  466. tmp = cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface));
  467. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface),
  468. (1 << index) | tmp);
  469. original_enable = 1;
  470. }
  471. /* Restore the enable state */
  472. gmx_cfg.s.en = original_enable;
  473. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  474. return 0;
  475. }