1af866496SDavid Daney /***********************license start*************** 2af866496SDavid Daney * Author: Cavium Networks 3af866496SDavid Daney * 4af866496SDavid Daney * Contact: support@caviumnetworks.com 5af866496SDavid Daney * This file is part of the OCTEON SDK 6af866496SDavid Daney * 7af866496SDavid Daney * Copyright (c) 2003-2008 Cavium Networks 8af866496SDavid Daney * 9af866496SDavid Daney * This file is free software; you can redistribute it and/or modify 10af866496SDavid Daney * it under the terms of the GNU General Public License, Version 2, as 11af866496SDavid Daney * published by the Free Software Foundation. 12af866496SDavid Daney * 13af866496SDavid Daney * This file is distributed in the hope that it will be useful, but 14af866496SDavid Daney * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 15af866496SDavid Daney * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 16af866496SDavid Daney * NONINFRINGEMENT. See the GNU General Public License for more 17af866496SDavid Daney * details. 18af866496SDavid Daney * 19af866496SDavid Daney * You should have received a copy of the GNU General Public License 20af866496SDavid Daney * along with this file; if not, write to the Free Software 21af866496SDavid Daney * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22af866496SDavid Daney * or visit http://www.gnu.org/licenses/. 23af866496SDavid Daney * 24af866496SDavid Daney * This file may also be available under a different license from Cavium. 25af866496SDavid Daney * Contact Cavium Networks for more information 26af866496SDavid Daney ***********************license end**************************************/ 27af866496SDavid Daney 28af866496SDavid Daney /* 29af866496SDavid Daney * Functions for XAUI initialization, configuration, 30af866496SDavid Daney * and monitoring. 31af866496SDavid Daney * 32af866496SDavid Daney */ 33af866496SDavid Daney 34af866496SDavid Daney #include <asm/octeon/octeon.h> 35af866496SDavid Daney 36af866496SDavid Daney #include <asm/octeon/cvmx-config.h> 37af866496SDavid Daney 38af866496SDavid Daney #include <asm/octeon/cvmx-helper.h> 39af866496SDavid Daney 40af866496SDavid Daney #include <asm/octeon/cvmx-pko-defs.h> 41af866496SDavid Daney #include <asm/octeon/cvmx-gmxx-defs.h> 42af866496SDavid Daney #include <asm/octeon/cvmx-pcsxx-defs.h> 43af866496SDavid Daney 44af866496SDavid Daney void __cvmx_interrupt_gmxx_enable(int interface); 45af866496SDavid Daney void __cvmx_interrupt_pcsx_intx_en_reg_enable(int index, int block); 46af866496SDavid Daney void __cvmx_interrupt_pcsxx_int_en_reg_enable(int index); 4737d3bfd9SDavid Daney 4837d3bfd9SDavid Daney int __cvmx_helper_xaui_enumerate(int interface) 4937d3bfd9SDavid Daney { 5037d3bfd9SDavid Daney union cvmx_gmxx_hg2_control gmx_hg2_control; 5137d3bfd9SDavid Daney 5237d3bfd9SDavid Daney /* If HiGig2 is enabled return 16 ports, otherwise return 1 port */ 5337d3bfd9SDavid Daney gmx_hg2_control.u64 = cvmx_read_csr(CVMX_GMXX_HG2_CONTROL(interface)); 5437d3bfd9SDavid Daney if (gmx_hg2_control.s.hg2tx_en) 5537d3bfd9SDavid Daney return 16; 5637d3bfd9SDavid Daney else 5737d3bfd9SDavid Daney return 1; 5837d3bfd9SDavid Daney } 5937d3bfd9SDavid Daney 60af866496SDavid Daney /** 61af866496SDavid Daney * Probe a XAUI interface and determine the number of ports 62af866496SDavid Daney * connected to it. The XAUI interface should still be down 63af866496SDavid Daney * after this call. 64af866496SDavid Daney * 65af866496SDavid Daney * @interface: Interface to probe 66af866496SDavid Daney * 67af866496SDavid Daney * Returns Number of ports on the interface. Zero to disable. 68af866496SDavid Daney */ 69af866496SDavid Daney int __cvmx_helper_xaui_probe(int interface) 70af866496SDavid Daney { 71af866496SDavid Daney int i; 72af866496SDavid Daney union cvmx_gmxx_inf_mode mode; 73af866496SDavid Daney 74af866496SDavid Daney /* 75af866496SDavid Daney * Due to errata GMX-700 on CN56XXp1.x and CN52XXp1.x, the 76af866496SDavid Daney * interface needs to be enabled before IPD otherwise per port 77af866496SDavid Daney * backpressure may not work properly. 78af866496SDavid Daney */ 79af866496SDavid Daney mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface)); 80af866496SDavid Daney mode.s.en = 1; 81af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.u64); 82af866496SDavid Daney 83af866496SDavid Daney __cvmx_helper_setup_gmx(interface, 1); 84af866496SDavid Daney 85af866496SDavid Daney /* 86af866496SDavid Daney * Setup PKO to support 16 ports for HiGig2 virtual 87af866496SDavid Daney * ports. We're pointing all of the PKO packet ports for this 88af866496SDavid Daney * interface to the XAUI. This allows us to use HiGig2 89af866496SDavid Daney * backpressure per port. 90af866496SDavid Daney */ 91af866496SDavid Daney for (i = 0; i < 16; i++) { 92af866496SDavid Daney union cvmx_pko_mem_port_ptrs pko_mem_port_ptrs; 93af866496SDavid Daney pko_mem_port_ptrs.u64 = 0; 94af866496SDavid Daney /* 95af866496SDavid Daney * We set each PKO port to have equal priority in a 96af866496SDavid Daney * round robin fashion. 97af866496SDavid Daney */ 98af866496SDavid Daney pko_mem_port_ptrs.s.static_p = 0; 99af866496SDavid Daney pko_mem_port_ptrs.s.qos_mask = 0xff; 100af866496SDavid Daney /* All PKO ports map to the same XAUI hardware port */ 101af866496SDavid Daney pko_mem_port_ptrs.s.eid = interface * 4; 102af866496SDavid Daney pko_mem_port_ptrs.s.pid = interface * 16 + i; 103af866496SDavid Daney cvmx_write_csr(CVMX_PKO_MEM_PORT_PTRS, pko_mem_port_ptrs.u64); 104af866496SDavid Daney } 10537d3bfd9SDavid Daney return __cvmx_helper_xaui_enumerate(interface); 106af866496SDavid Daney } 107af866496SDavid Daney 108af866496SDavid Daney /** 109af866496SDavid Daney * Bringup and enable a XAUI interface. After this call packet 110af866496SDavid Daney * I/O should be fully functional. This is called with IPD 111af866496SDavid Daney * enabled but PKO disabled. 112af866496SDavid Daney * 113af866496SDavid Daney * @interface: Interface to bring up 114af866496SDavid Daney * 115af866496SDavid Daney * Returns Zero on success, negative on failure 116af866496SDavid Daney */ 117af866496SDavid Daney int __cvmx_helper_xaui_enable(int interface) 118af866496SDavid Daney { 119af866496SDavid Daney union cvmx_gmxx_prtx_cfg gmx_cfg; 120af866496SDavid Daney union cvmx_pcsxx_control1_reg xauiCtl; 121af866496SDavid Daney union cvmx_pcsxx_misc_ctl_reg xauiMiscCtl; 122af866496SDavid Daney union cvmx_gmxx_tx_xaui_ctl gmxXauiTxCtl; 123af866496SDavid Daney union cvmx_gmxx_rxx_int_en gmx_rx_int_en; 124af866496SDavid Daney union cvmx_gmxx_tx_int_en gmx_tx_int_en; 125af866496SDavid Daney union cvmx_pcsxx_int_en_reg pcsx_int_en_reg; 126af866496SDavid Daney 12743975645SJanne Huttunen /* Setup PKND */ 12843975645SJanne Huttunen if (octeon_has_feature(OCTEON_FEATURE_PKND)) { 12943975645SJanne Huttunen gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface)); 13043975645SJanne Huttunen gmx_cfg.s.pknd = cvmx_helper_get_ipd_port(interface, 0); 13143975645SJanne Huttunen cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64); 13243975645SJanne Huttunen } 13343975645SJanne Huttunen 134af866496SDavid Daney /* (1) Interface has already been enabled. */ 135af866496SDavid Daney 136af866496SDavid Daney /* (2) Disable GMX. */ 137af866496SDavid Daney xauiMiscCtl.u64 = cvmx_read_csr(CVMX_PCSXX_MISC_CTL_REG(interface)); 138af866496SDavid Daney xauiMiscCtl.s.gmxeno = 1; 139af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64); 140af866496SDavid Daney 141af866496SDavid Daney /* (3) Disable GMX and PCSX interrupts. */ 142af866496SDavid Daney gmx_rx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_EN(0, interface)); 143af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0); 144af866496SDavid Daney gmx_tx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_TX_INT_EN(interface)); 145af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0); 146af866496SDavid Daney pcsx_int_en_reg.u64 = cvmx_read_csr(CVMX_PCSXX_INT_EN_REG(interface)); 147af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0); 148af866496SDavid Daney 149af866496SDavid Daney /* (4) Bring up the PCSX and GMX reconciliation layer. */ 150af866496SDavid Daney /* (4)a Set polarity and lane swapping. */ 151af866496SDavid Daney /* (4)b */ 152af866496SDavid Daney gmxXauiTxCtl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface)); 153af866496SDavid Daney /* Enable better IFG packing and improves performance */ 154af866496SDavid Daney gmxXauiTxCtl.s.dic_en = 1; 155af866496SDavid Daney gmxXauiTxCtl.s.uni_en = 0; 156af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_XAUI_CTL(interface), gmxXauiTxCtl.u64); 157af866496SDavid Daney 158af866496SDavid Daney /* (4)c Aply reset sequence */ 159af866496SDavid Daney xauiCtl.u64 = cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface)); 160af866496SDavid Daney xauiCtl.s.lo_pwr = 0; 161c0034c30SJanne Huttunen 162c0034c30SJanne Huttunen /* Issuing a reset here seems to hang some CN68XX chips. */ 163c0034c30SJanne Huttunen if (!OCTEON_IS_MODEL(OCTEON_CN68XX_PASS1_X) && 164c0034c30SJanne Huttunen !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X)) 165af866496SDavid Daney xauiCtl.s.reset = 1; 166c0034c30SJanne Huttunen 167af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), xauiCtl.u64); 168af866496SDavid Daney 169af866496SDavid Daney /* Wait for PCS to come out of reset */ 170af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 171af866496SDavid Daney (CVMX_PCSXX_CONTROL1_REG(interface), union cvmx_pcsxx_control1_reg, 172af866496SDavid Daney reset, ==, 0, 10000)) 173af866496SDavid Daney return -1; 174af866496SDavid Daney /* Wait for PCS to be aligned */ 175af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 176af866496SDavid Daney (CVMX_PCSXX_10GBX_STATUS_REG(interface), 177af866496SDavid Daney union cvmx_pcsxx_10gbx_status_reg, alignd, ==, 1, 10000)) 178af866496SDavid Daney return -1; 179af866496SDavid Daney /* Wait for RX to be ready */ 180af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 181af866496SDavid Daney (CVMX_GMXX_RX_XAUI_CTL(interface), union cvmx_gmxx_rx_xaui_ctl, 182af866496SDavid Daney status, ==, 0, 10000)) 183af866496SDavid Daney return -1; 184af866496SDavid Daney 185af866496SDavid Daney /* (6) Configure GMX */ 186af866496SDavid Daney gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface)); 187af866496SDavid Daney gmx_cfg.s.en = 0; 188af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64); 189af866496SDavid Daney 190af866496SDavid Daney /* Wait for GMX RX to be idle */ 191af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 192af866496SDavid Daney (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg, 193af866496SDavid Daney rx_idle, ==, 1, 10000)) 194af866496SDavid Daney return -1; 195af866496SDavid Daney /* Wait for GMX TX to be idle */ 196af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 197af866496SDavid Daney (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg, 198af866496SDavid Daney tx_idle, ==, 1, 10000)) 199af866496SDavid Daney return -1; 200af866496SDavid Daney 201af866496SDavid Daney /* GMX configure */ 202af866496SDavid Daney gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface)); 203af866496SDavid Daney gmx_cfg.s.speed = 1; 204af866496SDavid Daney gmx_cfg.s.speed_msb = 0; 205af866496SDavid Daney gmx_cfg.s.slottime = 1; 206af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), 1); 207af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TXX_SLOT(0, interface), 512); 208af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TXX_BURST(0, interface), 8192); 209af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64); 210af866496SDavid Daney 211af866496SDavid Daney /* (7) Clear out any error state */ 212af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(0, interface), 213af866496SDavid Daney cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(0, interface))); 214af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_INT_REG(interface), 215af866496SDavid Daney cvmx_read_csr(CVMX_GMXX_TX_INT_REG(interface))); 216af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_INT_REG(interface), 217af866496SDavid Daney cvmx_read_csr(CVMX_PCSXX_INT_REG(interface))); 218af866496SDavid Daney 219af866496SDavid Daney /* Wait for receive link */ 220af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 221af866496SDavid Daney (CVMX_PCSXX_STATUS1_REG(interface), union cvmx_pcsxx_status1_reg, 222af866496SDavid Daney rcv_lnk, ==, 1, 10000)) 223af866496SDavid Daney return -1; 224af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 225af866496SDavid Daney (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg, 226af866496SDavid Daney xmtflt, ==, 0, 10000)) 227af866496SDavid Daney return -1; 228af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 229af866496SDavid Daney (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg, 230af866496SDavid Daney rcvflt, ==, 0, 10000)) 231af866496SDavid Daney return -1; 232af866496SDavid Daney 233af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), gmx_rx_int_en.u64); 234af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), gmx_tx_int_en.u64); 235af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), pcsx_int_en_reg.u64); 236af866496SDavid Daney 237af866496SDavid Daney /* (8) Enable packet reception */ 238af866496SDavid Daney xauiMiscCtl.s.gmxeno = 0; 239af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64); 240af866496SDavid Daney 241af866496SDavid Daney gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface)); 242af866496SDavid Daney gmx_cfg.s.en = 1; 243af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64); 244af866496SDavid Daney 245af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(0, interface); 246af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(1, interface); 247af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(2, interface); 248af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(3, interface); 249af866496SDavid Daney __cvmx_interrupt_pcsxx_int_en_reg_enable(interface); 250af866496SDavid Daney __cvmx_interrupt_gmxx_enable(interface); 251af866496SDavid Daney 252af866496SDavid Daney return 0; 253af866496SDavid Daney } 254af866496SDavid Daney 255af866496SDavid Daney /** 256af866496SDavid Daney * Return the link state of an IPD/PKO port as returned by 257af866496SDavid Daney * auto negotiation. The result of this function may not match 258af866496SDavid Daney * Octeon's link config if auto negotiation has changed since 259af866496SDavid Daney * the last call to cvmx_helper_link_set(). 260af866496SDavid Daney * 261af866496SDavid Daney * @ipd_port: IPD/PKO port to query 262af866496SDavid Daney * 263af866496SDavid Daney * Returns Link state 264af866496SDavid Daney */ 265af866496SDavid Daney cvmx_helper_link_info_t __cvmx_helper_xaui_link_get(int ipd_port) 266af866496SDavid Daney { 267af866496SDavid Daney int interface = cvmx_helper_get_interface_num(ipd_port); 268af866496SDavid Daney union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl; 269af866496SDavid Daney union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl; 270af866496SDavid Daney union cvmx_pcsxx_status1_reg pcsxx_status1_reg; 271af866496SDavid Daney cvmx_helper_link_info_t result; 272af866496SDavid Daney 273af866496SDavid Daney gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface)); 274af866496SDavid Daney gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface)); 275af866496SDavid Daney pcsxx_status1_reg.u64 = 276af866496SDavid Daney cvmx_read_csr(CVMX_PCSXX_STATUS1_REG(interface)); 277af866496SDavid Daney result.u64 = 0; 278af866496SDavid Daney 279af866496SDavid Daney /* Only return a link if both RX and TX are happy */ 280af866496SDavid Daney if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0) && 281af866496SDavid Daney (pcsxx_status1_reg.s.rcv_lnk == 1)) { 282af866496SDavid Daney result.s.link_up = 1; 283af866496SDavid Daney result.s.full_duplex = 1; 284af866496SDavid Daney result.s.speed = 10000; 285af866496SDavid Daney } else { 286af866496SDavid Daney /* Disable GMX and PCSX interrupts. */ 287af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0); 288af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0); 289af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0); 290af866496SDavid Daney } 291af866496SDavid Daney return result; 292af866496SDavid Daney } 293af866496SDavid Daney 294af866496SDavid Daney /** 295af866496SDavid Daney * Configure an IPD/PKO port for the specified link state. This 296af866496SDavid Daney * function does not influence auto negotiation at the PHY level. 297af866496SDavid Daney * The passed link state must always match the link state returned 298*2b58a76eSAaro Koskinen * by cvmx_helper_link_get(). 299af866496SDavid Daney * 300af866496SDavid Daney * @ipd_port: IPD/PKO port to configure 301af866496SDavid Daney * @link_info: The new link state 302af866496SDavid Daney * 303af866496SDavid Daney * Returns Zero on success, negative on failure 304af866496SDavid Daney */ 305af866496SDavid Daney int __cvmx_helper_xaui_link_set(int ipd_port, cvmx_helper_link_info_t link_info) 306af866496SDavid Daney { 307af866496SDavid Daney int interface = cvmx_helper_get_interface_num(ipd_port); 308af866496SDavid Daney union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl; 309af866496SDavid Daney union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl; 310af866496SDavid Daney 311af866496SDavid Daney gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface)); 312af866496SDavid Daney gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface)); 313af866496SDavid Daney 314af866496SDavid Daney /* If the link shouldn't be up, then just return */ 315af866496SDavid Daney if (!link_info.s.link_up) 316af866496SDavid Daney return 0; 317af866496SDavid Daney 318af866496SDavid Daney /* Do nothing if both RX and TX are happy */ 319af866496SDavid Daney if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0)) 320af866496SDavid Daney return 0; 321af866496SDavid Daney 322af866496SDavid Daney /* Bring the link up */ 323af866496SDavid Daney return __cvmx_helper_xaui_enable(interface); 324af866496SDavid Daney } 325af866496SDavid Daney 326af866496SDavid Daney /** 327af866496SDavid Daney * Configure a port for internal and/or external loopback. Internal loopback 328af866496SDavid Daney * causes packets sent by the port to be received by Octeon. External loopback 329af866496SDavid Daney * causes packets received from the wire to sent out again. 330af866496SDavid Daney * 331af866496SDavid Daney * @ipd_port: IPD/PKO port to loopback. 332af866496SDavid Daney * @enable_internal: 333af866496SDavid Daney * Non zero if you want internal loopback 334af866496SDavid Daney * @enable_external: 335af866496SDavid Daney * Non zero if you want external loopback 336af866496SDavid Daney * 337af866496SDavid Daney * Returns Zero on success, negative on failure. 338af866496SDavid Daney */ 339af866496SDavid Daney extern int __cvmx_helper_xaui_configure_loopback(int ipd_port, 340af866496SDavid Daney int enable_internal, 341af866496SDavid Daney int enable_external) 342af866496SDavid Daney { 343af866496SDavid Daney int interface = cvmx_helper_get_interface_num(ipd_port); 344af866496SDavid Daney union cvmx_pcsxx_control1_reg pcsxx_control1_reg; 345af866496SDavid Daney union cvmx_gmxx_xaui_ext_loopback gmxx_xaui_ext_loopback; 346af866496SDavid Daney 347af866496SDavid Daney /* Set the internal loop */ 348af866496SDavid Daney pcsxx_control1_reg.u64 = 349af866496SDavid Daney cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface)); 350af866496SDavid Daney pcsxx_control1_reg.s.loopbck1 = enable_internal; 351af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), 352af866496SDavid Daney pcsxx_control1_reg.u64); 353af866496SDavid Daney 354af866496SDavid Daney /* Set the external loop */ 355af866496SDavid Daney gmxx_xaui_ext_loopback.u64 = 356af866496SDavid Daney cvmx_read_csr(CVMX_GMXX_XAUI_EXT_LOOPBACK(interface)); 357af866496SDavid Daney gmxx_xaui_ext_loopback.s.en = enable_external; 358af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_XAUI_EXT_LOOPBACK(interface), 359af866496SDavid Daney gmxx_xaui_ext_loopback.u64); 360af866496SDavid Daney 361af866496SDavid Daney /* Take the link through a reset */ 362af866496SDavid Daney return __cvmx_helper_xaui_enable(interface); 363af866496SDavid Daney } 364