18c2ecf20Sopenharmony_ci/***********************license start***************
28c2ecf20Sopenharmony_ci * Author: Cavium Networks
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Contact: support@caviumnetworks.com
58c2ecf20Sopenharmony_ci * This file is part of the OCTEON SDK
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (C) 2003-2018 Cavium, Inc.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
168c2ecf20Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
178c2ecf20Sopenharmony_ci * details.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
208c2ecf20Sopenharmony_ci * along with this file; if not, write to the Free Software
218c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
228c2ecf20Sopenharmony_ci * or visit http://www.gnu.org/licenses/.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * This file may also be available under a different license from Cavium.
258c2ecf20Sopenharmony_ci * Contact Cavium Networks for more information
268c2ecf20Sopenharmony_ci ***********************license end**************************************/
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * Functions for XAUI initialization, configuration,
308c2ecf20Sopenharmony_ci * and monitoring.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <asm/octeon/octeon.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-config.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-pko-defs.h>
418c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-gmxx-defs.h>
428c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-pcsx-defs.h>
438c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-pcsxx-defs.h>
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciint __cvmx_helper_xaui_enumerate(int interface)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	union cvmx_gmxx_hg2_control gmx_hg2_control;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	/* If HiGig2 is enabled return 16 ports, otherwise return 1 port */
508c2ecf20Sopenharmony_ci	gmx_hg2_control.u64 = cvmx_read_csr(CVMX_GMXX_HG2_CONTROL(interface));
518c2ecf20Sopenharmony_ci	if (gmx_hg2_control.s.hg2tx_en)
528c2ecf20Sopenharmony_ci		return 16;
538c2ecf20Sopenharmony_ci	else
548c2ecf20Sopenharmony_ci		return 1;
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/**
588c2ecf20Sopenharmony_ci * Probe a XAUI interface and determine the number of ports
598c2ecf20Sopenharmony_ci * connected to it. The XAUI interface should still be down
608c2ecf20Sopenharmony_ci * after this call.
618c2ecf20Sopenharmony_ci *
628c2ecf20Sopenharmony_ci * @interface: Interface to probe
638c2ecf20Sopenharmony_ci *
648c2ecf20Sopenharmony_ci * Returns Number of ports on the interface. Zero to disable.
658c2ecf20Sopenharmony_ci */
668c2ecf20Sopenharmony_ciint __cvmx_helper_xaui_probe(int interface)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	int i;
698c2ecf20Sopenharmony_ci	union cvmx_gmxx_inf_mode mode;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	/*
728c2ecf20Sopenharmony_ci	 * Due to errata GMX-700 on CN56XXp1.x and CN52XXp1.x, the
738c2ecf20Sopenharmony_ci	 * interface needs to be enabled before IPD otherwise per port
748c2ecf20Sopenharmony_ci	 * backpressure may not work properly.
758c2ecf20Sopenharmony_ci	 */
768c2ecf20Sopenharmony_ci	mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
778c2ecf20Sopenharmony_ci	mode.s.en = 1;
788c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.u64);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	__cvmx_helper_setup_gmx(interface, 1);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	/*
838c2ecf20Sopenharmony_ci	 * Setup PKO to support 16 ports for HiGig2 virtual
848c2ecf20Sopenharmony_ci	 * ports. We're pointing all of the PKO packet ports for this
858c2ecf20Sopenharmony_ci	 * interface to the XAUI. This allows us to use HiGig2
868c2ecf20Sopenharmony_ci	 * backpressure per port.
878c2ecf20Sopenharmony_ci	 */
888c2ecf20Sopenharmony_ci	for (i = 0; i < 16; i++) {
898c2ecf20Sopenharmony_ci		union cvmx_pko_mem_port_ptrs pko_mem_port_ptrs;
908c2ecf20Sopenharmony_ci		pko_mem_port_ptrs.u64 = 0;
918c2ecf20Sopenharmony_ci		/*
928c2ecf20Sopenharmony_ci		 * We set each PKO port to have equal priority in a
938c2ecf20Sopenharmony_ci		 * round robin fashion.
948c2ecf20Sopenharmony_ci		 */
958c2ecf20Sopenharmony_ci		pko_mem_port_ptrs.s.static_p = 0;
968c2ecf20Sopenharmony_ci		pko_mem_port_ptrs.s.qos_mask = 0xff;
978c2ecf20Sopenharmony_ci		/* All PKO ports map to the same XAUI hardware port */
988c2ecf20Sopenharmony_ci		pko_mem_port_ptrs.s.eid = interface * 4;
998c2ecf20Sopenharmony_ci		pko_mem_port_ptrs.s.pid = interface * 16 + i;
1008c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_PKO_MEM_PORT_PTRS, pko_mem_port_ptrs.u64);
1018c2ecf20Sopenharmony_ci	}
1028c2ecf20Sopenharmony_ci	return __cvmx_helper_xaui_enumerate(interface);
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/**
1068c2ecf20Sopenharmony_ci * Bringup and enable a XAUI interface. After this call packet
1078c2ecf20Sopenharmony_ci * I/O should be fully functional. This is called with IPD
1088c2ecf20Sopenharmony_ci * enabled but PKO disabled.
1098c2ecf20Sopenharmony_ci *
1108c2ecf20Sopenharmony_ci * @interface: Interface to bring up
1118c2ecf20Sopenharmony_ci *
1128c2ecf20Sopenharmony_ci * Returns Zero on success, negative on failure
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_ciint __cvmx_helper_xaui_enable(int interface)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	union cvmx_gmxx_prtx_cfg gmx_cfg;
1178c2ecf20Sopenharmony_ci	union cvmx_pcsxx_control1_reg xauiCtl;
1188c2ecf20Sopenharmony_ci	union cvmx_pcsxx_misc_ctl_reg xauiMiscCtl;
1198c2ecf20Sopenharmony_ci	union cvmx_gmxx_tx_xaui_ctl gmxXauiTxCtl;
1208c2ecf20Sopenharmony_ci	union cvmx_gmxx_rxx_int_en gmx_rx_int_en;
1218c2ecf20Sopenharmony_ci	union cvmx_gmxx_tx_int_en gmx_tx_int_en;
1228c2ecf20Sopenharmony_ci	union cvmx_pcsxx_int_en_reg pcsx_int_en_reg;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	/* Setup PKND */
1258c2ecf20Sopenharmony_ci	if (octeon_has_feature(OCTEON_FEATURE_PKND)) {
1268c2ecf20Sopenharmony_ci		gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
1278c2ecf20Sopenharmony_ci		gmx_cfg.s.pknd = cvmx_helper_get_ipd_port(interface, 0);
1288c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
1298c2ecf20Sopenharmony_ci	}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	/* (1) Interface has already been enabled. */
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	/* (2) Disable GMX. */
1348c2ecf20Sopenharmony_ci	xauiMiscCtl.u64 = cvmx_read_csr(CVMX_PCSXX_MISC_CTL_REG(interface));
1358c2ecf20Sopenharmony_ci	xauiMiscCtl.s.gmxeno = 1;
1368c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	/* (3) Disable GMX and PCSX interrupts. */
1398c2ecf20Sopenharmony_ci	gmx_rx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_EN(0, interface));
1408c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
1418c2ecf20Sopenharmony_ci	gmx_tx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_TX_INT_EN(interface));
1428c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
1438c2ecf20Sopenharmony_ci	pcsx_int_en_reg.u64 = cvmx_read_csr(CVMX_PCSXX_INT_EN_REG(interface));
1448c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	/* (4) Bring up the PCSX and GMX reconciliation layer. */
1478c2ecf20Sopenharmony_ci	/* (4)a Set polarity and lane swapping. */
1488c2ecf20Sopenharmony_ci	/* (4)b */
1498c2ecf20Sopenharmony_ci	gmxXauiTxCtl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
1508c2ecf20Sopenharmony_ci	/* Enable better IFG packing and improves performance */
1518c2ecf20Sopenharmony_ci	gmxXauiTxCtl.s.dic_en = 1;
1528c2ecf20Sopenharmony_ci	gmxXauiTxCtl.s.uni_en = 0;
1538c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_XAUI_CTL(interface), gmxXauiTxCtl.u64);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	/* (4)c Aply reset sequence */
1568c2ecf20Sopenharmony_ci	xauiCtl.u64 = cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface));
1578c2ecf20Sopenharmony_ci	xauiCtl.s.lo_pwr = 0;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	/* Issuing a reset here seems to hang some CN68XX chips. */
1608c2ecf20Sopenharmony_ci	if (!OCTEON_IS_MODEL(OCTEON_CN68XX_PASS1_X) &&
1618c2ecf20Sopenharmony_ci	    !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X))
1628c2ecf20Sopenharmony_ci		xauiCtl.s.reset = 1;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), xauiCtl.u64);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	/* Wait for PCS to come out of reset */
1678c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
1688c2ecf20Sopenharmony_ci	    (CVMX_PCSXX_CONTROL1_REG(interface), union cvmx_pcsxx_control1_reg,
1698c2ecf20Sopenharmony_ci	     reset, ==, 0, 10000))
1708c2ecf20Sopenharmony_ci		return -1;
1718c2ecf20Sopenharmony_ci	/* Wait for PCS to be aligned */
1728c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
1738c2ecf20Sopenharmony_ci	    (CVMX_PCSXX_10GBX_STATUS_REG(interface),
1748c2ecf20Sopenharmony_ci	     union cvmx_pcsxx_10gbx_status_reg, alignd, ==, 1, 10000))
1758c2ecf20Sopenharmony_ci		return -1;
1768c2ecf20Sopenharmony_ci	/* Wait for RX to be ready */
1778c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
1788c2ecf20Sopenharmony_ci	    (CVMX_GMXX_RX_XAUI_CTL(interface), union cvmx_gmxx_rx_xaui_ctl,
1798c2ecf20Sopenharmony_ci		    status, ==, 0, 10000))
1808c2ecf20Sopenharmony_ci		return -1;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	/* (6) Configure GMX */
1838c2ecf20Sopenharmony_ci	gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
1848c2ecf20Sopenharmony_ci	gmx_cfg.s.en = 0;
1858c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	/* Wait for GMX RX to be idle */
1888c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
1898c2ecf20Sopenharmony_ci	    (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
1908c2ecf20Sopenharmony_ci		    rx_idle, ==, 1, 10000))
1918c2ecf20Sopenharmony_ci		return -1;
1928c2ecf20Sopenharmony_ci	/* Wait for GMX TX to be idle */
1938c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
1948c2ecf20Sopenharmony_ci	    (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
1958c2ecf20Sopenharmony_ci		    tx_idle, ==, 1, 10000))
1968c2ecf20Sopenharmony_ci		return -1;
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	/* GMX configure */
1998c2ecf20Sopenharmony_ci	gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
2008c2ecf20Sopenharmony_ci	gmx_cfg.s.speed = 1;
2018c2ecf20Sopenharmony_ci	gmx_cfg.s.speed_msb = 0;
2028c2ecf20Sopenharmony_ci	gmx_cfg.s.slottime = 1;
2038c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), 1);
2048c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TXX_SLOT(0, interface), 512);
2058c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TXX_BURST(0, interface), 8192);
2068c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	/* (7) Clear out any error state */
2098c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(0, interface),
2108c2ecf20Sopenharmony_ci		       cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(0, interface)));
2118c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_INT_REG(interface),
2128c2ecf20Sopenharmony_ci		       cvmx_read_csr(CVMX_GMXX_TX_INT_REG(interface)));
2138c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_INT_REG(interface),
2148c2ecf20Sopenharmony_ci		       cvmx_read_csr(CVMX_PCSXX_INT_REG(interface)));
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	/* Wait for receive link */
2178c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
2188c2ecf20Sopenharmony_ci	    (CVMX_PCSXX_STATUS1_REG(interface), union cvmx_pcsxx_status1_reg,
2198c2ecf20Sopenharmony_ci	     rcv_lnk, ==, 1, 10000))
2208c2ecf20Sopenharmony_ci		return -1;
2218c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
2228c2ecf20Sopenharmony_ci	    (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
2238c2ecf20Sopenharmony_ci	     xmtflt, ==, 0, 10000))
2248c2ecf20Sopenharmony_ci		return -1;
2258c2ecf20Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
2268c2ecf20Sopenharmony_ci	    (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
2278c2ecf20Sopenharmony_ci	     rcvflt, ==, 0, 10000))
2288c2ecf20Sopenharmony_ci		return -1;
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), gmx_rx_int_en.u64);
2318c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), gmx_tx_int_en.u64);
2328c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), pcsx_int_en_reg.u64);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	/* (8) Enable packet reception */
2358c2ecf20Sopenharmony_ci	xauiMiscCtl.s.gmxeno = 0;
2368c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
2398c2ecf20Sopenharmony_ci	gmx_cfg.s.en = 1;
2408c2ecf20Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(0, interface);
2438c2ecf20Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(1, interface);
2448c2ecf20Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(2, interface);
2458c2ecf20Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(3, interface);
2468c2ecf20Sopenharmony_ci	__cvmx_interrupt_pcsxx_int_en_reg_enable(interface);
2478c2ecf20Sopenharmony_ci	__cvmx_interrupt_gmxx_enable(interface);
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	return 0;
2508c2ecf20Sopenharmony_ci}
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/**
2538c2ecf20Sopenharmony_ci * Return the link state of an IPD/PKO port as returned by
2548c2ecf20Sopenharmony_ci * auto negotiation. The result of this function may not match
2558c2ecf20Sopenharmony_ci * Octeon's link config if auto negotiation has changed since
2568c2ecf20Sopenharmony_ci * the last call to cvmx_helper_link_set().
2578c2ecf20Sopenharmony_ci *
2588c2ecf20Sopenharmony_ci * @ipd_port: IPD/PKO port to query
2598c2ecf20Sopenharmony_ci *
2608c2ecf20Sopenharmony_ci * Returns Link state
2618c2ecf20Sopenharmony_ci */
2628c2ecf20Sopenharmony_ciunion cvmx_helper_link_info __cvmx_helper_xaui_link_get(int ipd_port)
2638c2ecf20Sopenharmony_ci{
2648c2ecf20Sopenharmony_ci	int interface = cvmx_helper_get_interface_num(ipd_port);
2658c2ecf20Sopenharmony_ci	union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
2668c2ecf20Sopenharmony_ci	union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
2678c2ecf20Sopenharmony_ci	union cvmx_pcsxx_status1_reg pcsxx_status1_reg;
2688c2ecf20Sopenharmony_ci	union cvmx_helper_link_info result;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
2718c2ecf20Sopenharmony_ci	gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
2728c2ecf20Sopenharmony_ci	pcsxx_status1_reg.u64 =
2738c2ecf20Sopenharmony_ci	    cvmx_read_csr(CVMX_PCSXX_STATUS1_REG(interface));
2748c2ecf20Sopenharmony_ci	result.u64 = 0;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	/* Only return a link if both RX and TX are happy */
2778c2ecf20Sopenharmony_ci	if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0) &&
2788c2ecf20Sopenharmony_ci	    (pcsxx_status1_reg.s.rcv_lnk == 1)) {
2798c2ecf20Sopenharmony_ci		result.s.link_up = 1;
2808c2ecf20Sopenharmony_ci		result.s.full_duplex = 1;
2818c2ecf20Sopenharmony_ci		result.s.speed = 10000;
2828c2ecf20Sopenharmony_ci	} else {
2838c2ecf20Sopenharmony_ci		/* Disable GMX and PCSX interrupts. */
2848c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
2858c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
2868c2ecf20Sopenharmony_ci		cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
2878c2ecf20Sopenharmony_ci	}
2888c2ecf20Sopenharmony_ci	return result;
2898c2ecf20Sopenharmony_ci}
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci/**
2928c2ecf20Sopenharmony_ci * Configure an IPD/PKO port for the specified link state. This
2938c2ecf20Sopenharmony_ci * function does not influence auto negotiation at the PHY level.
2948c2ecf20Sopenharmony_ci * The passed link state must always match the link state returned
2958c2ecf20Sopenharmony_ci * by cvmx_helper_link_get().
2968c2ecf20Sopenharmony_ci *
2978c2ecf20Sopenharmony_ci * @ipd_port:  IPD/PKO port to configure
2988c2ecf20Sopenharmony_ci * @link_info: The new link state
2998c2ecf20Sopenharmony_ci *
3008c2ecf20Sopenharmony_ci * Returns Zero on success, negative on failure
3018c2ecf20Sopenharmony_ci */
3028c2ecf20Sopenharmony_ciint __cvmx_helper_xaui_link_set(int ipd_port, union cvmx_helper_link_info link_info)
3038c2ecf20Sopenharmony_ci{
3048c2ecf20Sopenharmony_ci	int interface = cvmx_helper_get_interface_num(ipd_port);
3058c2ecf20Sopenharmony_ci	union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
3068c2ecf20Sopenharmony_ci	union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
3098c2ecf20Sopenharmony_ci	gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	/* If the link shouldn't be up, then just return */
3128c2ecf20Sopenharmony_ci	if (!link_info.s.link_up)
3138c2ecf20Sopenharmony_ci		return 0;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	/* Do nothing if both RX and TX are happy */
3168c2ecf20Sopenharmony_ci	if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0))
3178c2ecf20Sopenharmony_ci		return 0;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	/* Bring the link up */
3208c2ecf20Sopenharmony_ci	return __cvmx_helper_xaui_enable(interface);
3218c2ecf20Sopenharmony_ci}
322