cvmx-helper.h revision 210284
1277042Sloos/***********************license start*************** 2277042Sloos * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights 3277042Sloos * reserved. 4277042Sloos * 5277042Sloos * 6277042Sloos * Redistribution and use in source and binary forms, with or without 7277042Sloos * modification, are permitted provided that the following conditions are 8277042Sloos * met: 9277042Sloos * 10277042Sloos * * Redistributions of source code must retain the above copyright 11277042Sloos * notice, this list of conditions and the following disclaimer. 12277042Sloos * 13277042Sloos * * Redistributions in binary form must reproduce the above 14277042Sloos * copyright notice, this list of conditions and the following 15277042Sloos * disclaimer in the documentation and/or other materials provided 16277042Sloos * with the distribution. 17277042Sloos * 18277042Sloos * * Neither the name of Cavium Networks nor the names of 19277042Sloos * its contributors may be used to endorse or promote products 20277042Sloos * derived from this software without specific prior written 21277042Sloos * permission. 22277042Sloos * 23277042Sloos * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 24277042Sloos * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS 25277042Sloos * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 26277042Sloos * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 27277042Sloos * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 28277042Sloos * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES 29277042Sloos * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR 30277042Sloos * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET 31277042Sloos * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT 32277042Sloos * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 33277042Sloos * 34277042Sloos * 35277042Sloos * For any questions regarding licensing please contact marketing@caviumnetworks.com 36277042Sloos * 37277042Sloos ***********************license end**************************************/ 38277042Sloos 39277042Sloos 40277042Sloos 41277042Sloos 42277042Sloos 43277042Sloos 44277042Sloos/** 45277042Sloos * @file 46277042Sloos * 47277042Sloos * Helper functions for common, but complicated tasks. 48277042Sloos * 49277042Sloos * <hr>$Revision: 41586 $<hr> 50277042Sloos */ 51277042Sloos 52277042Sloos#ifndef __CVMX_HELPER_H__ 53277042Sloos#define __CVMX_HELPER_H__ 54277042Sloos 55277042Sloos#include "executive-config.h" 56277042Sloos#include "cvmx-config.h" 57277042Sloos#include "cvmx-fpa.h" 58277042Sloos#include "cvmx-wqe.h" 59277042Sloos 60277042Sloos#ifdef __cplusplus 61277042Sloosextern "C" { 62277042Sloos#endif 63277042Sloos 64277042Sloostypedef enum 65277042Sloos{ 66277042Sloos CVMX_HELPER_INTERFACE_MODE_DISABLED, 67277042Sloos CVMX_HELPER_INTERFACE_MODE_RGMII, 68277042Sloos CVMX_HELPER_INTERFACE_MODE_GMII, 69277042Sloos CVMX_HELPER_INTERFACE_MODE_SPI, 70277042Sloos CVMX_HELPER_INTERFACE_MODE_PCIE, 71277042Sloos CVMX_HELPER_INTERFACE_MODE_XAUI, 72277042Sloos CVMX_HELPER_INTERFACE_MODE_SGMII, 73277042Sloos CVMX_HELPER_INTERFACE_MODE_PICMG, 74277042Sloos CVMX_HELPER_INTERFACE_MODE_NPI, 75277042Sloos CVMX_HELPER_INTERFACE_MODE_LOOP, 76277042Sloos} cvmx_helper_interface_mode_t; 77 78typedef union 79{ 80 uint64_t u64; 81 struct 82 { 83 uint64_t reserved_20_63 : 44; 84 uint64_t link_up : 1; /**< Is the physical link up? */ 85 uint64_t full_duplex : 1; /**< 1 if the link is full duplex */ 86 uint64_t speed : 18; /**< Speed of the link in Mbps */ 87 } s; 88} cvmx_helper_link_info_t; 89 90#include "cvmx-helper-fpa.h" 91 92#ifdef CVMX_ENABLE_PKO_FUNCTIONS 93 94#include "cvmx-helper-errata.h" 95#include "cvmx-helper-loop.h" 96#include "cvmx-helper-npi.h" 97#include "cvmx-helper-rgmii.h" 98#include "cvmx-helper-sgmii.h" 99#include "cvmx-helper-spi.h" 100#include "cvmx-helper-util.h" 101#include "cvmx-helper-xaui.h" 102 103/** 104 * cvmx_override_pko_queue_priority(int ipd_port, uint64_t 105 * priorities[16]) is a function pointer. It is meant to allow 106 * customization of the PKO queue priorities based on the port 107 * number. Users should set this pointer to a function before 108 * calling any cvmx-helper operations. 109 */ 110extern void (*cvmx_override_pko_queue_priority)(int pko_port, uint64_t priorities[16]); 111 112/** 113 * cvmx_override_ipd_port_setup(int ipd_port) is a function 114 * pointer. It is meant to allow customization of the IPD port 115 * setup before packet input/output comes online. It is called 116 * after cvmx-helper does the default IPD configuration, but 117 * before IPD is enabled. Users should set this pointer to a 118 * function before calling any cvmx-helper operations. 119 */ 120extern void (*cvmx_override_ipd_port_setup)(int ipd_port); 121 122/** 123 * This function enables the IPD and also enables the packet interfaces. 124 * The packet interfaces (RGMII and SPI) must be enabled after the 125 * IPD. This should be called by the user program after any additional 126 * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD 127 * is not set in the executive-config.h file. 128 * 129 * @return 0 on success 130 * -1 on failure 131 */ 132extern int cvmx_helper_ipd_and_packet_input_enable(void); 133 134/** 135 * Initialize the PIP, IPD, and PKO hardware to support 136 * simple priority based queues for the ethernet ports. Each 137 * port is configured with a number of priority queues based 138 * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower 139 * priority than the previous. 140 * 141 * @return Zero on success, non-zero on failure 142 */ 143extern int cvmx_helper_initialize_packet_io_global(void); 144 145/** 146 * Does core local initialization for packet io 147 * 148 * @return Zero on success, non-zero on failure 149 */ 150extern int cvmx_helper_initialize_packet_io_local(void); 151 152/** 153 * Returns the number of ports on the given interface. 154 * The interface must be initialized before the port count 155 * can be returned. 156 * 157 * @param interface Which interface to return port count for. 158 * 159 * @return Port count for interface 160 * -1 for uninitialized interface 161 */ 162extern int cvmx_helper_ports_on_interface(int interface); 163 164/** 165 * Return the number of interfaces the chip has. Each interface 166 * may have multiple ports. Most chips support two interfaces, 167 * but the CNX0XX and CNX1XX are exceptions. These only support 168 * one interface. 169 * 170 * @return Number of interfaces on chip 171 */ 172extern int cvmx_helper_get_number_of_interfaces(void); 173 174/** 175 * Get the operating mode of an interface. Depending on the Octeon 176 * chip and configuration, this function returns an enumeration 177 * of the type of packet I/O supported by an interface. 178 * 179 * @param interface Interface to probe 180 * 181 * @return Mode of the interface. Unknown or unsupported interfaces return 182 * DISABLED. 183 */ 184extern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface); 185 186/** 187 * Auto configure an IPD/PKO port link state and speed. This 188 * function basically does the equivalent of: 189 * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port)); 190 * 191 * @param ipd_port IPD/PKO port to auto configure 192 * 193 * @return Link state after configure 194 */ 195extern cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port); 196 197/** 198 * Return the link state of an IPD/PKO port as returned by 199 * auto negotiation. The result of this function may not match 200 * Octeon's link config if auto negotiation has changed since 201 * the last call to cvmx_helper_link_set(). 202 * 203 * @param ipd_port IPD/PKO port to query 204 * 205 * @return Link state 206 */ 207extern cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port); 208 209/** 210 * Configure an IPD/PKO port for the specified link state. This 211 * function does not influence auto negotiation at the PHY level. 212 * The passed link state must always match the link state returned 213 * by cvmx_helper_link_get(). It is normally best to use 214 * cvmx_helper_link_autoconf() instead. 215 * 216 * @param ipd_port IPD/PKO port to configure 217 * @param link_info The new link state 218 * 219 * @return Zero on success, negative on failure 220 */ 221extern int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info); 222 223 224 225/** 226 * This function probes an interface to determine the actual 227 * number of hardware ports connected to it. It doesn't setup the 228 * ports or enable them. The main goal here is to set the global 229 * interface_port_count[interface] correctly. Hardware setup of the 230 * ports will be performed later. 231 * 232 * @param interface Interface to probe 233 * 234 * @return Zero on success, negative on failure 235 */ 236extern int cvmx_helper_interface_probe(int interface); 237 238/** 239 * Configure a port for internal and/or external loopback. Internal loopback 240 * causes packets sent by the port to be received by Octeon. External loopback 241 * causes packets received from the wire to sent out again. 242 * 243 * @param ipd_port IPD/PKO port to loopback. 244 * @param enable_internal 245 * Non zero if you want internal loopback 246 * @param enable_external 247 * Non zero if you want external loopback 248 * 249 * @return Zero on success, negative on failure. 250 */ 251extern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal, int enable_external); 252 253#endif /* CVMX_ENABLE_PKO_FUNCTIONS */ 254 255#ifdef __cplusplus 256} 257#endif 258 259#endif /* __CVMX_HELPER_H__ */ 260