cvmx-helper.h revision 210286
1/***********************license start***************
2 *  Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
3 *  reserved.
4 *
5 *
6 *  Redistribution and use in source and binary forms, with or without
7 *  modification, are permitted provided that the following conditions are
8 *  met:
9 *
10 *      * Redistributions of source code must retain the above copyright
11 *        notice, this list of conditions and the following disclaimer.
12 *
13 *      * Redistributions in binary form must reproduce the above
14 *        copyright notice, this list of conditions and the following
15 *        disclaimer in the documentation and/or other materials provided
16 *        with the distribution.
17 *
18 *      * Neither the name of Cavium Networks nor the names of
19 *        its contributors may be used to endorse or promote products
20 *        derived from this software without specific prior written
21 *        permission.
22 *
23 *  TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 *  AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 *  OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 *  RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 *  REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 *  DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 *  PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 *  POSSESSION OR CORRESPONDENCE TO DESCRIPTION.  THE ENTIRE RISK ARISING OUT
32 *  OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
33 *
34 *
35 *  For any questions regarding licensing please contact marketing@caviumnetworks.com
36 *
37 ***********************license end**************************************/
38
39
40
41
42
43
44/**
45 * @file
46 *
47 * Helper functions for common, but complicated tasks.
48 *
49 * <hr>$Revision: 41586 $<hr>
50 */
51
52#ifndef __CVMX_HELPER_H__
53#define __CVMX_HELPER_H__
54
55#include "executive-config.h"
56#include "cvmx-config.h"
57#include "cvmx-fpa.h"
58#include "cvmx-wqe.h"
59
60#ifdef	__cplusplus
61extern "C" {
62#endif
63
64typedef enum
65{
66    CVMX_HELPER_INTERFACE_MODE_DISABLED,
67    CVMX_HELPER_INTERFACE_MODE_RGMII,
68    CVMX_HELPER_INTERFACE_MODE_GMII,
69    CVMX_HELPER_INTERFACE_MODE_SPI,
70    CVMX_HELPER_INTERFACE_MODE_PCIE,
71    CVMX_HELPER_INTERFACE_MODE_XAUI,
72    CVMX_HELPER_INTERFACE_MODE_SGMII,
73    CVMX_HELPER_INTERFACE_MODE_PICMG,
74    CVMX_HELPER_INTERFACE_MODE_NPI,
75    CVMX_HELPER_INTERFACE_MODE_LOOP,
76} 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