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