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 5716df55ceSRandy 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 10516df55ceSRandy 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 159*407710a3SStijn Tintel /* Issuing a reset here seems to hang some CN66XX/CN68XX chips. */ 160*407710a3SStijn Tintel if (!OCTEON_IS_MODEL(OCTEON_CN66XX) && 161*407710a3SStijn Tintel !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS1_X) && 162c0034c30SJanne Huttunen !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X)) 163af866496SDavid Daney xauiCtl.s.reset = 1; 164c0034c30SJanne Huttunen 165af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), xauiCtl.u64); 166af866496SDavid Daney 167af866496SDavid Daney /* Wait for PCS to come out of reset */ 168af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 169af866496SDavid Daney (CVMX_PCSXX_CONTROL1_REG(interface), union cvmx_pcsxx_control1_reg, 170af866496SDavid Daney reset, ==, 0, 10000)) 171af866496SDavid Daney return -1; 172af866496SDavid Daney /* Wait for PCS to be aligned */ 173af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 174af866496SDavid Daney (CVMX_PCSXX_10GBX_STATUS_REG(interface), 175af866496SDavid Daney union cvmx_pcsxx_10gbx_status_reg, alignd, ==, 1, 10000)) 176af866496SDavid Daney return -1; 177af866496SDavid Daney /* Wait for RX to be ready */ 178af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 179af866496SDavid Daney (CVMX_GMXX_RX_XAUI_CTL(interface), union cvmx_gmxx_rx_xaui_ctl, 180af866496SDavid Daney status, ==, 0, 10000)) 181af866496SDavid Daney return -1; 182af866496SDavid Daney 183af866496SDavid Daney /* (6) Configure GMX */ 184af866496SDavid Daney gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface)); 185af866496SDavid Daney gmx_cfg.s.en = 0; 186af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64); 187af866496SDavid Daney 188af866496SDavid Daney /* Wait for GMX RX to be idle */ 189af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 190af866496SDavid Daney (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg, 191af866496SDavid Daney rx_idle, ==, 1, 10000)) 192af866496SDavid Daney return -1; 193af866496SDavid Daney /* Wait for GMX TX to be idle */ 194af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 195af866496SDavid Daney (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg, 196af866496SDavid Daney tx_idle, ==, 1, 10000)) 197af866496SDavid Daney return -1; 198af866496SDavid Daney 199af866496SDavid Daney /* GMX configure */ 200af866496SDavid Daney gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface)); 201af866496SDavid Daney gmx_cfg.s.speed = 1; 202af866496SDavid Daney gmx_cfg.s.speed_msb = 0; 203af866496SDavid Daney gmx_cfg.s.slottime = 1; 204af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), 1); 205af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TXX_SLOT(0, interface), 512); 206af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TXX_BURST(0, interface), 8192); 207af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64); 208af866496SDavid Daney 209af866496SDavid Daney /* (7) Clear out any error state */ 210af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(0, interface), 211af866496SDavid Daney cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(0, interface))); 212af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_INT_REG(interface), 213af866496SDavid Daney cvmx_read_csr(CVMX_GMXX_TX_INT_REG(interface))); 214af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_INT_REG(interface), 215af866496SDavid Daney cvmx_read_csr(CVMX_PCSXX_INT_REG(interface))); 216af866496SDavid Daney 217af866496SDavid Daney /* Wait for receive link */ 218af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 219af866496SDavid Daney (CVMX_PCSXX_STATUS1_REG(interface), union cvmx_pcsxx_status1_reg, 220af866496SDavid Daney rcv_lnk, ==, 1, 10000)) 221af866496SDavid Daney return -1; 222af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 223af866496SDavid Daney (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg, 224af866496SDavid Daney xmtflt, ==, 0, 10000)) 225af866496SDavid Daney return -1; 226af866496SDavid Daney if (CVMX_WAIT_FOR_FIELD64 227af866496SDavid Daney (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg, 228af866496SDavid Daney rcvflt, ==, 0, 10000)) 229af866496SDavid Daney return -1; 230af866496SDavid Daney 231af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), gmx_rx_int_en.u64); 232af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), gmx_tx_int_en.u64); 233af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), pcsx_int_en_reg.u64); 234af866496SDavid Daney 235af866496SDavid Daney /* (8) Enable packet reception */ 236af866496SDavid Daney xauiMiscCtl.s.gmxeno = 0; 237af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64); 238af866496SDavid Daney 239af866496SDavid Daney gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface)); 240af866496SDavid Daney gmx_cfg.s.en = 1; 241af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64); 242af866496SDavid Daney 243af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(0, interface); 244af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(1, interface); 245af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(2, interface); 246af866496SDavid Daney __cvmx_interrupt_pcsx_intx_en_reg_enable(3, interface); 247af866496SDavid Daney __cvmx_interrupt_pcsxx_int_en_reg_enable(interface); 248af866496SDavid Daney __cvmx_interrupt_gmxx_enable(interface); 249af866496SDavid Daney 250af866496SDavid Daney return 0; 251af866496SDavid Daney } 252af866496SDavid Daney 25316df55ceSRandy Dunlap /* 254af866496SDavid Daney * Return the link state of an IPD/PKO port as returned by 255af866496SDavid Daney * auto negotiation. The result of this function may not match 256af866496SDavid Daney * Octeon's link config if auto negotiation has changed since 257af866496SDavid Daney * the last call to cvmx_helper_link_set(). 258af866496SDavid Daney * 259af866496SDavid Daney * @ipd_port: IPD/PKO port to query 260af866496SDavid Daney * 261af866496SDavid Daney * Returns Link state 262af866496SDavid Daney */ 263f7d2bdcbSChris Packham union cvmx_helper_link_info __cvmx_helper_xaui_link_get(int ipd_port) 264af866496SDavid Daney { 265af866496SDavid Daney int interface = cvmx_helper_get_interface_num(ipd_port); 266af866496SDavid Daney union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl; 267af866496SDavid Daney union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl; 268af866496SDavid Daney union cvmx_pcsxx_status1_reg pcsxx_status1_reg; 269f7d2bdcbSChris Packham union cvmx_helper_link_info result; 270af866496SDavid Daney 271af866496SDavid Daney gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface)); 272af866496SDavid Daney gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface)); 273af866496SDavid Daney pcsxx_status1_reg.u64 = 274af866496SDavid Daney cvmx_read_csr(CVMX_PCSXX_STATUS1_REG(interface)); 275af866496SDavid Daney result.u64 = 0; 276af866496SDavid Daney 277af866496SDavid Daney /* Only return a link if both RX and TX are happy */ 278af866496SDavid Daney if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0) && 279af866496SDavid Daney (pcsxx_status1_reg.s.rcv_lnk == 1)) { 280af866496SDavid Daney result.s.link_up = 1; 281af866496SDavid Daney result.s.full_duplex = 1; 282af866496SDavid Daney result.s.speed = 10000; 283af866496SDavid Daney } else { 284af866496SDavid Daney /* Disable GMX and PCSX interrupts. */ 285af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0); 286af866496SDavid Daney cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0); 287af866496SDavid Daney cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0); 288af866496SDavid Daney } 289af866496SDavid Daney return result; 290af866496SDavid Daney } 291af866496SDavid Daney 29216df55ceSRandy Dunlap /* 293af866496SDavid Daney * Configure an IPD/PKO port for the specified link state. This 294af866496SDavid Daney * function does not influence auto negotiation at the PHY level. 295af866496SDavid Daney * The passed link state must always match the link state returned 2962b58a76eSAaro Koskinen * by cvmx_helper_link_get(). 297af866496SDavid Daney * 298af866496SDavid Daney * @ipd_port: IPD/PKO port to configure 299af866496SDavid Daney * @link_info: The new link state 300af866496SDavid Daney * 301af866496SDavid Daney * Returns Zero on success, negative on failure 302af866496SDavid Daney */ 303f7d2bdcbSChris Packham int __cvmx_helper_xaui_link_set(int ipd_port, union cvmx_helper_link_info link_info) 304af866496SDavid Daney { 305af866496SDavid Daney int interface = cvmx_helper_get_interface_num(ipd_port); 306af866496SDavid Daney union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl; 307af866496SDavid Daney union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl; 308af866496SDavid Daney 309af866496SDavid Daney gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface)); 310af866496SDavid Daney gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface)); 311af866496SDavid Daney 312af866496SDavid Daney /* If the link shouldn't be up, then just return */ 313af866496SDavid Daney if (!link_info.s.link_up) 314af866496SDavid Daney return 0; 315af866496SDavid Daney 316af866496SDavid Daney /* Do nothing if both RX and TX are happy */ 317af866496SDavid Daney if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0)) 318af866496SDavid Daney return 0; 319af866496SDavid Daney 320af866496SDavid Daney /* Bring the link up */ 321af866496SDavid Daney return __cvmx_helper_xaui_enable(interface); 322af866496SDavid Daney } 323