162306a36Sopenharmony_ci/***********************license start***************
262306a36Sopenharmony_ci * Author: Cavium Networks
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Contact: support@caviumnetworks.com
562306a36Sopenharmony_ci * This file is part of the OCTEON SDK
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2003-2018 Cavium, Inc.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
1062306a36Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
1162306a36Sopenharmony_ci * published by the Free Software Foundation.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
1462306a36Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
1562306a36Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
1662306a36Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
1762306a36Sopenharmony_ci * details.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License
2062306a36Sopenharmony_ci * along with this file; if not, write to the Free Software
2162306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2262306a36Sopenharmony_ci * or visit http://www.gnu.org/licenses/.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * This file may also be available under a different license from Cavium.
2562306a36Sopenharmony_ci * Contact Cavium Networks for more information
2662306a36Sopenharmony_ci ***********************license end**************************************/
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * Functions for XAUI initialization, configuration,
3062306a36Sopenharmony_ci * and monitoring.
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#include <asm/octeon/octeon.h>
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#include <asm/octeon/cvmx-config.h>
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#include <asm/octeon/cvmx-helper.h>
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#include <asm/octeon/cvmx-pko-defs.h>
4162306a36Sopenharmony_ci#include <asm/octeon/cvmx-gmxx-defs.h>
4262306a36Sopenharmony_ci#include <asm/octeon/cvmx-pcsx-defs.h>
4362306a36Sopenharmony_ci#include <asm/octeon/cvmx-pcsxx-defs.h>
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciint __cvmx_helper_xaui_enumerate(int interface)
4662306a36Sopenharmony_ci{
4762306a36Sopenharmony_ci	union cvmx_gmxx_hg2_control gmx_hg2_control;
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	/* If HiGig2 is enabled return 16 ports, otherwise return 1 port */
5062306a36Sopenharmony_ci	gmx_hg2_control.u64 = cvmx_read_csr(CVMX_GMXX_HG2_CONTROL(interface));
5162306a36Sopenharmony_ci	if (gmx_hg2_control.s.hg2tx_en)
5262306a36Sopenharmony_ci		return 16;
5362306a36Sopenharmony_ci	else
5462306a36Sopenharmony_ci		return 1;
5562306a36Sopenharmony_ci}
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/*
5862306a36Sopenharmony_ci * Probe a XAUI interface and determine the number of ports
5962306a36Sopenharmony_ci * connected to it. The XAUI interface should still be down
6062306a36Sopenharmony_ci * after this call.
6162306a36Sopenharmony_ci *
6262306a36Sopenharmony_ci * @interface: Interface to probe
6362306a36Sopenharmony_ci *
6462306a36Sopenharmony_ci * Returns Number of ports on the interface. Zero to disable.
6562306a36Sopenharmony_ci */
6662306a36Sopenharmony_ciint __cvmx_helper_xaui_probe(int interface)
6762306a36Sopenharmony_ci{
6862306a36Sopenharmony_ci	int i;
6962306a36Sopenharmony_ci	union cvmx_gmxx_inf_mode mode;
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	/*
7262306a36Sopenharmony_ci	 * Due to errata GMX-700 on CN56XXp1.x and CN52XXp1.x, the
7362306a36Sopenharmony_ci	 * interface needs to be enabled before IPD otherwise per port
7462306a36Sopenharmony_ci	 * backpressure may not work properly.
7562306a36Sopenharmony_ci	 */
7662306a36Sopenharmony_ci	mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
7762306a36Sopenharmony_ci	mode.s.en = 1;
7862306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.u64);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	__cvmx_helper_setup_gmx(interface, 1);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci	/*
8362306a36Sopenharmony_ci	 * Setup PKO to support 16 ports for HiGig2 virtual
8462306a36Sopenharmony_ci	 * ports. We're pointing all of the PKO packet ports for this
8562306a36Sopenharmony_ci	 * interface to the XAUI. This allows us to use HiGig2
8662306a36Sopenharmony_ci	 * backpressure per port.
8762306a36Sopenharmony_ci	 */
8862306a36Sopenharmony_ci	for (i = 0; i < 16; i++) {
8962306a36Sopenharmony_ci		union cvmx_pko_mem_port_ptrs pko_mem_port_ptrs;
9062306a36Sopenharmony_ci		pko_mem_port_ptrs.u64 = 0;
9162306a36Sopenharmony_ci		/*
9262306a36Sopenharmony_ci		 * We set each PKO port to have equal priority in a
9362306a36Sopenharmony_ci		 * round robin fashion.
9462306a36Sopenharmony_ci		 */
9562306a36Sopenharmony_ci		pko_mem_port_ptrs.s.static_p = 0;
9662306a36Sopenharmony_ci		pko_mem_port_ptrs.s.qos_mask = 0xff;
9762306a36Sopenharmony_ci		/* All PKO ports map to the same XAUI hardware port */
9862306a36Sopenharmony_ci		pko_mem_port_ptrs.s.eid = interface * 4;
9962306a36Sopenharmony_ci		pko_mem_port_ptrs.s.pid = interface * 16 + i;
10062306a36Sopenharmony_ci		cvmx_write_csr(CVMX_PKO_MEM_PORT_PTRS, pko_mem_port_ptrs.u64);
10162306a36Sopenharmony_ci	}
10262306a36Sopenharmony_ci	return __cvmx_helper_xaui_enumerate(interface);
10362306a36Sopenharmony_ci}
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci/*
10662306a36Sopenharmony_ci * Bringup and enable a XAUI interface. After this call packet
10762306a36Sopenharmony_ci * I/O should be fully functional. This is called with IPD
10862306a36Sopenharmony_ci * enabled but PKO disabled.
10962306a36Sopenharmony_ci *
11062306a36Sopenharmony_ci * @interface: Interface to bring up
11162306a36Sopenharmony_ci *
11262306a36Sopenharmony_ci * Returns Zero on success, negative on failure
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_ciint __cvmx_helper_xaui_enable(int interface)
11562306a36Sopenharmony_ci{
11662306a36Sopenharmony_ci	union cvmx_gmxx_prtx_cfg gmx_cfg;
11762306a36Sopenharmony_ci	union cvmx_pcsxx_control1_reg xauiCtl;
11862306a36Sopenharmony_ci	union cvmx_pcsxx_misc_ctl_reg xauiMiscCtl;
11962306a36Sopenharmony_ci	union cvmx_gmxx_tx_xaui_ctl gmxXauiTxCtl;
12062306a36Sopenharmony_ci	union cvmx_gmxx_rxx_int_en gmx_rx_int_en;
12162306a36Sopenharmony_ci	union cvmx_gmxx_tx_int_en gmx_tx_int_en;
12262306a36Sopenharmony_ci	union cvmx_pcsxx_int_en_reg pcsx_int_en_reg;
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	/* Setup PKND */
12562306a36Sopenharmony_ci	if (octeon_has_feature(OCTEON_FEATURE_PKND)) {
12662306a36Sopenharmony_ci		gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
12762306a36Sopenharmony_ci		gmx_cfg.s.pknd = cvmx_helper_get_ipd_port(interface, 0);
12862306a36Sopenharmony_ci		cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
12962306a36Sopenharmony_ci	}
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	/* (1) Interface has already been enabled. */
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci	/* (2) Disable GMX. */
13462306a36Sopenharmony_ci	xauiMiscCtl.u64 = cvmx_read_csr(CVMX_PCSXX_MISC_CTL_REG(interface));
13562306a36Sopenharmony_ci	xauiMiscCtl.s.gmxeno = 1;
13662306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	/* (3) Disable GMX and PCSX interrupts. */
13962306a36Sopenharmony_ci	gmx_rx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_EN(0, interface));
14062306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
14162306a36Sopenharmony_ci	gmx_tx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_TX_INT_EN(interface));
14262306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
14362306a36Sopenharmony_ci	pcsx_int_en_reg.u64 = cvmx_read_csr(CVMX_PCSXX_INT_EN_REG(interface));
14462306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci	/* (4) Bring up the PCSX and GMX reconciliation layer. */
14762306a36Sopenharmony_ci	/* (4)a Set polarity and lane swapping. */
14862306a36Sopenharmony_ci	/* (4)b */
14962306a36Sopenharmony_ci	gmxXauiTxCtl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
15062306a36Sopenharmony_ci	/* Enable better IFG packing and improves performance */
15162306a36Sopenharmony_ci	gmxXauiTxCtl.s.dic_en = 1;
15262306a36Sopenharmony_ci	gmxXauiTxCtl.s.uni_en = 0;
15362306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_XAUI_CTL(interface), gmxXauiTxCtl.u64);
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci	/* (4)c Aply reset sequence */
15662306a36Sopenharmony_ci	xauiCtl.u64 = cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface));
15762306a36Sopenharmony_ci	xauiCtl.s.lo_pwr = 0;
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	/* Issuing a reset here seems to hang some CN66XX/CN68XX chips. */
16062306a36Sopenharmony_ci	if (!OCTEON_IS_MODEL(OCTEON_CN66XX) &&
16162306a36Sopenharmony_ci	    !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS1_X) &&
16262306a36Sopenharmony_ci	    !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X))
16362306a36Sopenharmony_ci		xauiCtl.s.reset = 1;
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), xauiCtl.u64);
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci	/* Wait for PCS to come out of reset */
16862306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
16962306a36Sopenharmony_ci	    (CVMX_PCSXX_CONTROL1_REG(interface), union cvmx_pcsxx_control1_reg,
17062306a36Sopenharmony_ci	     reset, ==, 0, 10000))
17162306a36Sopenharmony_ci		return -1;
17262306a36Sopenharmony_ci	/* Wait for PCS to be aligned */
17362306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
17462306a36Sopenharmony_ci	    (CVMX_PCSXX_10GBX_STATUS_REG(interface),
17562306a36Sopenharmony_ci	     union cvmx_pcsxx_10gbx_status_reg, alignd, ==, 1, 10000))
17662306a36Sopenharmony_ci		return -1;
17762306a36Sopenharmony_ci	/* Wait for RX to be ready */
17862306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
17962306a36Sopenharmony_ci	    (CVMX_GMXX_RX_XAUI_CTL(interface), union cvmx_gmxx_rx_xaui_ctl,
18062306a36Sopenharmony_ci		    status, ==, 0, 10000))
18162306a36Sopenharmony_ci		return -1;
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	/* (6) Configure GMX */
18462306a36Sopenharmony_ci	gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
18562306a36Sopenharmony_ci	gmx_cfg.s.en = 0;
18662306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci	/* Wait for GMX RX to be idle */
18962306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
19062306a36Sopenharmony_ci	    (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
19162306a36Sopenharmony_ci		    rx_idle, ==, 1, 10000))
19262306a36Sopenharmony_ci		return -1;
19362306a36Sopenharmony_ci	/* Wait for GMX TX to be idle */
19462306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
19562306a36Sopenharmony_ci	    (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
19662306a36Sopenharmony_ci		    tx_idle, ==, 1, 10000))
19762306a36Sopenharmony_ci		return -1;
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci	/* GMX configure */
20062306a36Sopenharmony_ci	gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
20162306a36Sopenharmony_ci	gmx_cfg.s.speed = 1;
20262306a36Sopenharmony_ci	gmx_cfg.s.speed_msb = 0;
20362306a36Sopenharmony_ci	gmx_cfg.s.slottime = 1;
20462306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), 1);
20562306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TXX_SLOT(0, interface), 512);
20662306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TXX_BURST(0, interface), 8192);
20762306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci	/* (7) Clear out any error state */
21062306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(0, interface),
21162306a36Sopenharmony_ci		       cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(0, interface)));
21262306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_INT_REG(interface),
21362306a36Sopenharmony_ci		       cvmx_read_csr(CVMX_GMXX_TX_INT_REG(interface)));
21462306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_INT_REG(interface),
21562306a36Sopenharmony_ci		       cvmx_read_csr(CVMX_PCSXX_INT_REG(interface)));
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci	/* Wait for receive link */
21862306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
21962306a36Sopenharmony_ci	    (CVMX_PCSXX_STATUS1_REG(interface), union cvmx_pcsxx_status1_reg,
22062306a36Sopenharmony_ci	     rcv_lnk, ==, 1, 10000))
22162306a36Sopenharmony_ci		return -1;
22262306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
22362306a36Sopenharmony_ci	    (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
22462306a36Sopenharmony_ci	     xmtflt, ==, 0, 10000))
22562306a36Sopenharmony_ci		return -1;
22662306a36Sopenharmony_ci	if (CVMX_WAIT_FOR_FIELD64
22762306a36Sopenharmony_ci	    (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
22862306a36Sopenharmony_ci	     rcvflt, ==, 0, 10000))
22962306a36Sopenharmony_ci		return -1;
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), gmx_rx_int_en.u64);
23262306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), gmx_tx_int_en.u64);
23362306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), pcsx_int_en_reg.u64);
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci	/* (8) Enable packet reception */
23662306a36Sopenharmony_ci	xauiMiscCtl.s.gmxeno = 0;
23762306a36Sopenharmony_ci	cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci	gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
24062306a36Sopenharmony_ci	gmx_cfg.s.en = 1;
24162306a36Sopenharmony_ci	cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(0, interface);
24462306a36Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(1, interface);
24562306a36Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(2, interface);
24662306a36Sopenharmony_ci	__cvmx_interrupt_pcsx_intx_en_reg_enable(3, interface);
24762306a36Sopenharmony_ci	__cvmx_interrupt_pcsxx_int_en_reg_enable(interface);
24862306a36Sopenharmony_ci	__cvmx_interrupt_gmxx_enable(interface);
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci	return 0;
25162306a36Sopenharmony_ci}
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci/*
25462306a36Sopenharmony_ci * Return the link state of an IPD/PKO port as returned by
25562306a36Sopenharmony_ci * auto negotiation. The result of this function may not match
25662306a36Sopenharmony_ci * Octeon's link config if auto negotiation has changed since
25762306a36Sopenharmony_ci * the last call to cvmx_helper_link_set().
25862306a36Sopenharmony_ci *
25962306a36Sopenharmony_ci * @ipd_port: IPD/PKO port to query
26062306a36Sopenharmony_ci *
26162306a36Sopenharmony_ci * Returns Link state
26262306a36Sopenharmony_ci */
26362306a36Sopenharmony_ciunion cvmx_helper_link_info __cvmx_helper_xaui_link_get(int ipd_port)
26462306a36Sopenharmony_ci{
26562306a36Sopenharmony_ci	int interface = cvmx_helper_get_interface_num(ipd_port);
26662306a36Sopenharmony_ci	union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
26762306a36Sopenharmony_ci	union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
26862306a36Sopenharmony_ci	union cvmx_pcsxx_status1_reg pcsxx_status1_reg;
26962306a36Sopenharmony_ci	union cvmx_helper_link_info result;
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci	gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
27262306a36Sopenharmony_ci	gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
27362306a36Sopenharmony_ci	pcsxx_status1_reg.u64 =
27462306a36Sopenharmony_ci	    cvmx_read_csr(CVMX_PCSXX_STATUS1_REG(interface));
27562306a36Sopenharmony_ci	result.u64 = 0;
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci	/* Only return a link if both RX and TX are happy */
27862306a36Sopenharmony_ci	if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0) &&
27962306a36Sopenharmony_ci	    (pcsxx_status1_reg.s.rcv_lnk == 1)) {
28062306a36Sopenharmony_ci		result.s.link_up = 1;
28162306a36Sopenharmony_ci		result.s.full_duplex = 1;
28262306a36Sopenharmony_ci		result.s.speed = 10000;
28362306a36Sopenharmony_ci	} else {
28462306a36Sopenharmony_ci		/* Disable GMX and PCSX interrupts. */
28562306a36Sopenharmony_ci		cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
28662306a36Sopenharmony_ci		cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
28762306a36Sopenharmony_ci		cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
28862306a36Sopenharmony_ci	}
28962306a36Sopenharmony_ci	return result;
29062306a36Sopenharmony_ci}
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci/*
29362306a36Sopenharmony_ci * Configure an IPD/PKO port for the specified link state. This
29462306a36Sopenharmony_ci * function does not influence auto negotiation at the PHY level.
29562306a36Sopenharmony_ci * The passed link state must always match the link state returned
29662306a36Sopenharmony_ci * by cvmx_helper_link_get().
29762306a36Sopenharmony_ci *
29862306a36Sopenharmony_ci * @ipd_port:  IPD/PKO port to configure
29962306a36Sopenharmony_ci * @link_info: The new link state
30062306a36Sopenharmony_ci *
30162306a36Sopenharmony_ci * Returns Zero on success, negative on failure
30262306a36Sopenharmony_ci */
30362306a36Sopenharmony_ciint __cvmx_helper_xaui_link_set(int ipd_port, union cvmx_helper_link_info link_info)
30462306a36Sopenharmony_ci{
30562306a36Sopenharmony_ci	int interface = cvmx_helper_get_interface_num(ipd_port);
30662306a36Sopenharmony_ci	union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
30762306a36Sopenharmony_ci	union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
31062306a36Sopenharmony_ci	gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci	/* If the link shouldn't be up, then just return */
31362306a36Sopenharmony_ci	if (!link_info.s.link_up)
31462306a36Sopenharmony_ci		return 0;
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci	/* Do nothing if both RX and TX are happy */
31762306a36Sopenharmony_ci	if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0))
31862306a36Sopenharmony_ci		return 0;
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci	/* Bring the link up */
32162306a36Sopenharmony_ci	return __cvmx_helper_xaui_enable(interface);
32262306a36Sopenharmony_ci}
323