1*4882a593Smuzhiyun /***********************license start*************** 2*4882a593Smuzhiyun * Author: Cavium Networks 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Contact: support@caviumnetworks.com 5*4882a593Smuzhiyun * This file is part of the OCTEON SDK 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * Copyright (c) 2003-2008 Cavium Networks 8*4882a593Smuzhiyun * 9*4882a593Smuzhiyun * This file is free software; you can redistribute it and/or modify 10*4882a593Smuzhiyun * it under the terms of the GNU General Public License, Version 2, as 11*4882a593Smuzhiyun * published by the Free Software Foundation. 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * This file is distributed in the hope that it will be useful, but 14*4882a593Smuzhiyun * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 15*4882a593Smuzhiyun * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 16*4882a593Smuzhiyun * NONINFRINGEMENT. See the GNU General Public License for more 17*4882a593Smuzhiyun * details. 18*4882a593Smuzhiyun * 19*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License 20*4882a593Smuzhiyun * along with this file; if not, write to the Free Software 21*4882a593Smuzhiyun * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22*4882a593Smuzhiyun * or visit http://www.gnu.org/licenses/. 23*4882a593Smuzhiyun * 24*4882a593Smuzhiyun * This file may also be available under a different license from Cavium. 25*4882a593Smuzhiyun * Contact Cavium Networks for more information 26*4882a593Smuzhiyun ***********************license end**************************************/ 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun /* 29*4882a593Smuzhiyun * 30*4882a593Smuzhiyun * Helper functions for common, but complicated tasks. 31*4882a593Smuzhiyun * 32*4882a593Smuzhiyun */ 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun #ifndef __CVMX_HELPER_H__ 35*4882a593Smuzhiyun #define __CVMX_HELPER_H__ 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun #include <asm/octeon/cvmx-config.h> 38*4882a593Smuzhiyun #include <asm/octeon/cvmx-fpa.h> 39*4882a593Smuzhiyun #include <asm/octeon/cvmx-wqe.h> 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun typedef enum { 42*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_DISABLED, 43*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_RGMII, 44*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_GMII, 45*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_SPI, 46*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_PCIE, 47*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_XAUI, 48*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_SGMII, 49*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_PICMG, 50*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_NPI, 51*4882a593Smuzhiyun CVMX_HELPER_INTERFACE_MODE_LOOP, 52*4882a593Smuzhiyun } cvmx_helper_interface_mode_t; 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun union cvmx_helper_link_info { 55*4882a593Smuzhiyun uint64_t u64; 56*4882a593Smuzhiyun struct { 57*4882a593Smuzhiyun uint64_t reserved_20_63:44; 58*4882a593Smuzhiyun uint64_t link_up:1; /**< Is the physical link up? */ 59*4882a593Smuzhiyun uint64_t full_duplex:1; /**< 1 if the link is full duplex */ 60*4882a593Smuzhiyun uint64_t speed:18; /**< Speed of the link in Mbps */ 61*4882a593Smuzhiyun } s; 62*4882a593Smuzhiyun }; 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-errata.h> 65*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-loop.h> 66*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-npi.h> 67*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-rgmii.h> 68*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-sgmii.h> 69*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-spi.h> 70*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-util.h> 71*4882a593Smuzhiyun #include <asm/octeon/cvmx-helper-xaui.h> 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun /** 74*4882a593Smuzhiyun * This function enables the IPD and also enables the packet interfaces. 75*4882a593Smuzhiyun * The packet interfaces (RGMII and SPI) must be enabled after the 76*4882a593Smuzhiyun * IPD. This should be called by the user program after any additional 77*4882a593Smuzhiyun * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD 78*4882a593Smuzhiyun * is not set in the executive-config.h file. 79*4882a593Smuzhiyun * 80*4882a593Smuzhiyun * Returns 0 on success 81*4882a593Smuzhiyun * -1 on failure 82*4882a593Smuzhiyun */ 83*4882a593Smuzhiyun extern int cvmx_helper_ipd_and_packet_input_enable(void); 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun /** 86*4882a593Smuzhiyun * Initialize the PIP, IPD, and PKO hardware to support 87*4882a593Smuzhiyun * simple priority based queues for the ethernet ports. Each 88*4882a593Smuzhiyun * port is configured with a number of priority queues based 89*4882a593Smuzhiyun * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower 90*4882a593Smuzhiyun * priority than the previous. 91*4882a593Smuzhiyun * 92*4882a593Smuzhiyun * Returns Zero on success, non-zero on failure 93*4882a593Smuzhiyun */ 94*4882a593Smuzhiyun extern int cvmx_helper_initialize_packet_io_global(void); 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun /** 97*4882a593Smuzhiyun * Does core local initialization for packet io 98*4882a593Smuzhiyun * 99*4882a593Smuzhiyun * Returns Zero on success, non-zero on failure 100*4882a593Smuzhiyun */ 101*4882a593Smuzhiyun extern int cvmx_helper_initialize_packet_io_local(void); 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun /** 104*4882a593Smuzhiyun * Returns the number of ports on the given interface. 105*4882a593Smuzhiyun * The interface must be initialized before the port count 106*4882a593Smuzhiyun * can be returned. 107*4882a593Smuzhiyun * 108*4882a593Smuzhiyun * @interface: Which interface to return port count for. 109*4882a593Smuzhiyun * 110*4882a593Smuzhiyun * Returns Port count for interface 111*4882a593Smuzhiyun * -1 for uninitialized interface 112*4882a593Smuzhiyun */ 113*4882a593Smuzhiyun extern int cvmx_helper_ports_on_interface(int interface); 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun /** 116*4882a593Smuzhiyun * Return the number of interfaces the chip has. Each interface 117*4882a593Smuzhiyun * may have multiple ports. Most chips support two interfaces, 118*4882a593Smuzhiyun * but the CNX0XX and CNX1XX are exceptions. These only support 119*4882a593Smuzhiyun * one interface. 120*4882a593Smuzhiyun * 121*4882a593Smuzhiyun * Returns Number of interfaces on chip 122*4882a593Smuzhiyun */ 123*4882a593Smuzhiyun extern int cvmx_helper_get_number_of_interfaces(void); 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun /** 126*4882a593Smuzhiyun * Get the operating mode of an interface. Depending on the Octeon 127*4882a593Smuzhiyun * chip and configuration, this function returns an enumeration 128*4882a593Smuzhiyun * of the type of packet I/O supported by an interface. 129*4882a593Smuzhiyun * 130*4882a593Smuzhiyun * @interface: Interface to probe 131*4882a593Smuzhiyun * 132*4882a593Smuzhiyun * Returns Mode of the interface. Unknown or unsupported interfaces return 133*4882a593Smuzhiyun * DISABLED. 134*4882a593Smuzhiyun */ 135*4882a593Smuzhiyun extern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int 136*4882a593Smuzhiyun interface); 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun /** 139*4882a593Smuzhiyun * Return the link state of an IPD/PKO port as returned by 140*4882a593Smuzhiyun * auto negotiation. The result of this function may not match 141*4882a593Smuzhiyun * Octeon's link config if auto negotiation has changed since 142*4882a593Smuzhiyun * the last call to cvmx_helper_link_set(). 143*4882a593Smuzhiyun * 144*4882a593Smuzhiyun * @ipd_port: IPD/PKO port to query 145*4882a593Smuzhiyun * 146*4882a593Smuzhiyun * Returns Link state 147*4882a593Smuzhiyun */ 148*4882a593Smuzhiyun extern union cvmx_helper_link_info cvmx_helper_link_get(int ipd_port); 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun /** 151*4882a593Smuzhiyun * Configure an IPD/PKO port for the specified link state. This 152*4882a593Smuzhiyun * function does not influence auto negotiation at the PHY level. 153*4882a593Smuzhiyun * The passed link state must always match the link state returned 154*4882a593Smuzhiyun * by cvmx_helper_link_get(). 155*4882a593Smuzhiyun * 156*4882a593Smuzhiyun * @ipd_port: IPD/PKO port to configure 157*4882a593Smuzhiyun * @link_info: The new link state 158*4882a593Smuzhiyun * 159*4882a593Smuzhiyun * Returns Zero on success, negative on failure 160*4882a593Smuzhiyun */ 161*4882a593Smuzhiyun extern int cvmx_helper_link_set(int ipd_port, 162*4882a593Smuzhiyun union cvmx_helper_link_info link_info); 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun /** 165*4882a593Smuzhiyun * This function probes an interface to determine the actual 166*4882a593Smuzhiyun * number of hardware ports connected to it. It doesn't setup the 167*4882a593Smuzhiyun * ports or enable them. The main goal here is to set the global 168*4882a593Smuzhiyun * interface_port_count[interface] correctly. Hardware setup of the 169*4882a593Smuzhiyun * ports will be performed later. 170*4882a593Smuzhiyun * 171*4882a593Smuzhiyun * @interface: Interface to probe 172*4882a593Smuzhiyun * 173*4882a593Smuzhiyun * Returns Zero on success, negative on failure 174*4882a593Smuzhiyun */ 175*4882a593Smuzhiyun extern int cvmx_helper_interface_probe(int interface); 176*4882a593Smuzhiyun extern int cvmx_helper_interface_enumerate(int interface); 177*4882a593Smuzhiyun 178*4882a593Smuzhiyun #endif /* __CVMX_HELPER_H__ */ 179