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-2008 Cavium Networks
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 *
308c2ecf20Sopenharmony_ci * Helper functions for common, but complicated tasks.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#ifndef __CVMX_HELPER_H__
358c2ecf20Sopenharmony_ci#define __CVMX_HELPER_H__
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-config.h>
388c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-fpa.h>
398c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-wqe.h>
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_citypedef enum {
428c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_DISABLED,
438c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_RGMII,
448c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_GMII,
458c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_SPI,
468c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_PCIE,
478c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_XAUI,
488c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_SGMII,
498c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_PICMG,
508c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_NPI,
518c2ecf20Sopenharmony_ci	CVMX_HELPER_INTERFACE_MODE_LOOP,
528c2ecf20Sopenharmony_ci} cvmx_helper_interface_mode_t;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciunion cvmx_helper_link_info {
558c2ecf20Sopenharmony_ci	uint64_t u64;
568c2ecf20Sopenharmony_ci	struct {
578c2ecf20Sopenharmony_ci		uint64_t reserved_20_63:44;
588c2ecf20Sopenharmony_ci		uint64_t link_up:1;	    /**< Is the physical link up? */
598c2ecf20Sopenharmony_ci		uint64_t full_duplex:1;	    /**< 1 if the link is full duplex */
608c2ecf20Sopenharmony_ci		uint64_t speed:18;	    /**< Speed of the link in Mbps */
618c2ecf20Sopenharmony_ci	} s;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-errata.h>
658c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-loop.h>
668c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-npi.h>
678c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-rgmii.h>
688c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-sgmii.h>
698c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-spi.h>
708c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-util.h>
718c2ecf20Sopenharmony_ci#include <asm/octeon/cvmx-helper-xaui.h>
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/**
748c2ecf20Sopenharmony_ci * This function enables the IPD and also enables the packet interfaces.
758c2ecf20Sopenharmony_ci * The packet interfaces (RGMII and SPI) must be enabled after the
768c2ecf20Sopenharmony_ci * IPD.	 This should be called by the user program after any additional
778c2ecf20Sopenharmony_ci * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD
788c2ecf20Sopenharmony_ci * is not set in the executive-config.h file.
798c2ecf20Sopenharmony_ci *
808c2ecf20Sopenharmony_ci * Returns 0 on success
818c2ecf20Sopenharmony_ci *	   -1 on failure
828c2ecf20Sopenharmony_ci */
838c2ecf20Sopenharmony_ciextern int cvmx_helper_ipd_and_packet_input_enable(void);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/**
868c2ecf20Sopenharmony_ci * Initialize the PIP, IPD, and PKO hardware to support
878c2ecf20Sopenharmony_ci * simple priority based queues for the ethernet ports. Each
888c2ecf20Sopenharmony_ci * port is configured with a number of priority queues based
898c2ecf20Sopenharmony_ci * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
908c2ecf20Sopenharmony_ci * priority than the previous.
918c2ecf20Sopenharmony_ci *
928c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero on failure
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_ciextern int cvmx_helper_initialize_packet_io_global(void);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/**
978c2ecf20Sopenharmony_ci * Does core local initialization for packet io
988c2ecf20Sopenharmony_ci *
998c2ecf20Sopenharmony_ci * Returns Zero on success, non-zero on failure
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_ciextern int cvmx_helper_initialize_packet_io_local(void);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/**
1048c2ecf20Sopenharmony_ci * Returns the number of ports on the given interface.
1058c2ecf20Sopenharmony_ci * The interface must be initialized before the port count
1068c2ecf20Sopenharmony_ci * can be returned.
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci * @interface: Which interface to return port count for.
1098c2ecf20Sopenharmony_ci *
1108c2ecf20Sopenharmony_ci * Returns Port count for interface
1118c2ecf20Sopenharmony_ci *	   -1 for uninitialized interface
1128c2ecf20Sopenharmony_ci */
1138c2ecf20Sopenharmony_ciextern int cvmx_helper_ports_on_interface(int interface);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/**
1168c2ecf20Sopenharmony_ci * Return the number of interfaces the chip has. Each interface
1178c2ecf20Sopenharmony_ci * may have multiple ports. Most chips support two interfaces,
1188c2ecf20Sopenharmony_ci * but the CNX0XX and CNX1XX are exceptions. These only support
1198c2ecf20Sopenharmony_ci * one interface.
1208c2ecf20Sopenharmony_ci *
1218c2ecf20Sopenharmony_ci * Returns Number of interfaces on chip
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_ciextern int cvmx_helper_get_number_of_interfaces(void);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/**
1268c2ecf20Sopenharmony_ci * Get the operating mode of an interface. Depending on the Octeon
1278c2ecf20Sopenharmony_ci * chip and configuration, this function returns an enumeration
1288c2ecf20Sopenharmony_ci * of the type of packet I/O supported by an interface.
1298c2ecf20Sopenharmony_ci *
1308c2ecf20Sopenharmony_ci * @interface: Interface to probe
1318c2ecf20Sopenharmony_ci *
1328c2ecf20Sopenharmony_ci * Returns Mode of the interface. Unknown or unsupported interfaces return
1338c2ecf20Sopenharmony_ci *	   DISABLED.
1348c2ecf20Sopenharmony_ci */
1358c2ecf20Sopenharmony_ciextern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int
1368c2ecf20Sopenharmony_ci								   interface);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/**
1398c2ecf20Sopenharmony_ci * Return the link state of an IPD/PKO port as returned by
1408c2ecf20Sopenharmony_ci * auto negotiation. The result of this function may not match
1418c2ecf20Sopenharmony_ci * Octeon's link config if auto negotiation has changed since
1428c2ecf20Sopenharmony_ci * the last call to cvmx_helper_link_set().
1438c2ecf20Sopenharmony_ci *
1448c2ecf20Sopenharmony_ci * @ipd_port: IPD/PKO port to query
1458c2ecf20Sopenharmony_ci *
1468c2ecf20Sopenharmony_ci * Returns Link state
1478c2ecf20Sopenharmony_ci */
1488c2ecf20Sopenharmony_ciextern union cvmx_helper_link_info cvmx_helper_link_get(int ipd_port);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/**
1518c2ecf20Sopenharmony_ci * Configure an IPD/PKO port for the specified link state. This
1528c2ecf20Sopenharmony_ci * function does not influence auto negotiation at the PHY level.
1538c2ecf20Sopenharmony_ci * The passed link state must always match the link state returned
1548c2ecf20Sopenharmony_ci * by cvmx_helper_link_get().
1558c2ecf20Sopenharmony_ci *
1568c2ecf20Sopenharmony_ci * @ipd_port:  IPD/PKO port to configure
1578c2ecf20Sopenharmony_ci * @link_info: The new link state
1588c2ecf20Sopenharmony_ci *
1598c2ecf20Sopenharmony_ci * Returns Zero on success, negative on failure
1608c2ecf20Sopenharmony_ci */
1618c2ecf20Sopenharmony_ciextern int cvmx_helper_link_set(int ipd_port,
1628c2ecf20Sopenharmony_ci				union cvmx_helper_link_info link_info);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/**
1658c2ecf20Sopenharmony_ci * This function probes an interface to determine the actual
1668c2ecf20Sopenharmony_ci * number of hardware ports connected to it. It doesn't setup the
1678c2ecf20Sopenharmony_ci * ports or enable them. The main goal here is to set the global
1688c2ecf20Sopenharmony_ci * interface_port_count[interface] correctly. Hardware setup of the
1698c2ecf20Sopenharmony_ci * ports will be performed later.
1708c2ecf20Sopenharmony_ci *
1718c2ecf20Sopenharmony_ci * @interface: Interface to probe
1728c2ecf20Sopenharmony_ci *
1738c2ecf20Sopenharmony_ci * Returns Zero on success, negative on failure
1748c2ecf20Sopenharmony_ci */
1758c2ecf20Sopenharmony_ciextern int cvmx_helper_interface_probe(int interface);
1768c2ecf20Sopenharmony_ciextern int cvmx_helper_interface_enumerate(int interface);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#endif /* __CVMX_HELPER_H__ */
179