1210284Sjmallett/***********************license start***************
2215990Sjmallett * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3215990Sjmallett * reserved.
4210284Sjmallett *
5210284Sjmallett *
6215990Sjmallett * Redistribution and use in source and binary forms, with or without
7215990Sjmallett * modification, are permitted provided that the following conditions are
8215990Sjmallett * met:
9210284Sjmallett *
10215990Sjmallett *   * Redistributions of source code must retain the above copyright
11215990Sjmallett *     notice, this list of conditions and the following disclaimer.
12210284Sjmallett *
13215990Sjmallett *   * Redistributions in binary form must reproduce the above
14215990Sjmallett *     copyright notice, this list of conditions and the following
15215990Sjmallett *     disclaimer in the documentation and/or other materials provided
16215990Sjmallett *     with the distribution.
17215990Sjmallett
18215990Sjmallett *   * Neither the name of Cavium Networks nor the names of
19215990Sjmallett *     its contributors may be used to endorse or promote products
20215990Sjmallett *     derived from this software without specific prior written
21215990Sjmallett *     permission.
22215990Sjmallett
23215990Sjmallett * This Software, including technical data, may be subject to U.S. export  control
24215990Sjmallett * laws, including the U.S. Export Administration Act and its  associated
25215990Sjmallett * regulations, and may be subject to export or import  regulations in other
26215990Sjmallett * countries.
27215990Sjmallett
28215990Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29215990Sjmallett * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30215990Sjmallett * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31215990Sjmallett * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32215990Sjmallett * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33215990Sjmallett * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34215990Sjmallett * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35215990Sjmallett * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36215990Sjmallett * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37215990Sjmallett * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38210284Sjmallett ***********************license end**************************************/
39210284Sjmallett
40210284Sjmallett
41210284Sjmallett
42210284Sjmallett
43210284Sjmallett
44210284Sjmallett
45215990Sjmallett
46210284Sjmallett/**
47210284Sjmallett * @file
48210284Sjmallett *
49210284Sjmallett * Helper functions for common, but complicated tasks.
50210284Sjmallett *
51215990Sjmallett * <hr>$Revision: 49448 $<hr>
52210284Sjmallett */
53210284Sjmallett
54210284Sjmallett#ifndef __CVMX_HELPER_H__
55210284Sjmallett#define __CVMX_HELPER_H__
56210284Sjmallett
57215990Sjmallett#ifdef CVMX_BUILD_FOR_LINUX_KERNEL
58215990Sjmallett#include <asm/octeon/cvmx.h>
59215990Sjmallett#include <asm/octeon/cvmx-config.h>
60215990Sjmallett#elif !defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
61210284Sjmallett#include "executive-config.h"
62210284Sjmallett#include "cvmx-config.h"
63210311Sjmallett#endif
64215990Sjmallett
65210284Sjmallett#include "cvmx-fpa.h"
66210284Sjmallett#include "cvmx-wqe.h"
67210284Sjmallett
68210284Sjmallett#ifdef	__cplusplus
69210284Sjmallettextern "C" {
70210284Sjmallett#endif
71210284Sjmallett
72210284Sjmalletttypedef enum
73210284Sjmallett{
74210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_DISABLED,
75210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_RGMII,
76210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_GMII,
77210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_SPI,
78210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_PCIE,
79210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_XAUI,
80210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_SGMII,
81210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_PICMG,
82210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_NPI,
83210284Sjmallett    CVMX_HELPER_INTERFACE_MODE_LOOP,
84215990Sjmallett    CVMX_HELPER_INTERFACE_MODE_SRIO,
85210284Sjmallett} cvmx_helper_interface_mode_t;
86210284Sjmallett
87210284Sjmalletttypedef union
88210284Sjmallett{
89210284Sjmallett    uint64_t u64;
90210284Sjmallett    struct
91210284Sjmallett    {
92210284Sjmallett        uint64_t    reserved_20_63  : 44;
93210284Sjmallett        uint64_t    link_up         : 1;    /**< Is the physical link up? */
94210284Sjmallett        uint64_t    full_duplex     : 1;    /**< 1 if the link is full duplex */
95210284Sjmallett        uint64_t    speed           : 18;   /**< Speed of the link in Mbps */
96210284Sjmallett    } s;
97210284Sjmallett} cvmx_helper_link_info_t;
98210284Sjmallett
99210284Sjmallett#include "cvmx-helper-fpa.h"
100210284Sjmallett
101210284Sjmallett#ifdef CVMX_ENABLE_PKO_FUNCTIONS
102210284Sjmallett
103210284Sjmallett#include "cvmx-helper-errata.h"
104210284Sjmallett#include "cvmx-helper-loop.h"
105210284Sjmallett#include "cvmx-helper-npi.h"
106210284Sjmallett#include "cvmx-helper-rgmii.h"
107210284Sjmallett#include "cvmx-helper-sgmii.h"
108210284Sjmallett#include "cvmx-helper-spi.h"
109215990Sjmallett#include "cvmx-helper-srio.h"
110210284Sjmallett#include "cvmx-helper-xaui.h"
111210284Sjmallett
112210284Sjmallett/**
113210284Sjmallett * cvmx_override_pko_queue_priority(int ipd_port, uint64_t
114210284Sjmallett * priorities[16]) is a function pointer. It is meant to allow
115210284Sjmallett * customization of the PKO queue priorities based on the port
116210284Sjmallett * number. Users should set this pointer to a function before
117210284Sjmallett * calling any cvmx-helper operations.
118210284Sjmallett */
119210284Sjmallettextern void (*cvmx_override_pko_queue_priority)(int pko_port, uint64_t priorities[16]);
120210284Sjmallett
121210284Sjmallett/**
122210284Sjmallett * cvmx_override_ipd_port_setup(int ipd_port) is a function
123210284Sjmallett * pointer. It is meant to allow customization of the IPD port
124210284Sjmallett * setup before packet input/output comes online. It is called
125210284Sjmallett * after cvmx-helper does the default IPD configuration, but
126210284Sjmallett * before IPD is enabled. Users should set this pointer to a
127210284Sjmallett * function before calling any cvmx-helper operations.
128210284Sjmallett */
129210284Sjmallettextern void (*cvmx_override_ipd_port_setup)(int ipd_port);
130210284Sjmallett
131210284Sjmallett/**
132210284Sjmallett * This function enables the IPD and also enables the packet interfaces.
133210284Sjmallett * The packet interfaces (RGMII and SPI) must be enabled after the
134210284Sjmallett * IPD.  This should be called by the user program after any additional
135210284Sjmallett * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD
136210284Sjmallett * is not set in the executive-config.h file.
137210284Sjmallett *
138210284Sjmallett * @return 0 on success
139210284Sjmallett *         -1 on failure
140210284Sjmallett */
141210284Sjmallettextern int cvmx_helper_ipd_and_packet_input_enable(void);
142210284Sjmallett
143210284Sjmallett/**
144210284Sjmallett * Initialize the PIP, IPD, and PKO hardware to support
145210284Sjmallett * simple priority based queues for the ethernet ports. Each
146210284Sjmallett * port is configured with a number of priority queues based
147210284Sjmallett * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
148210284Sjmallett * priority than the previous.
149210284Sjmallett *
150210284Sjmallett * @return Zero on success, non-zero on failure
151210284Sjmallett */
152210284Sjmallettextern int cvmx_helper_initialize_packet_io_global(void);
153210284Sjmallett
154210284Sjmallett/**
155210284Sjmallett * Does core local initialization for packet io
156210284Sjmallett *
157210284Sjmallett * @return Zero on success, non-zero on failure
158210284Sjmallett */
159210284Sjmallettextern int cvmx_helper_initialize_packet_io_local(void);
160210284Sjmallett
161210284Sjmallett/**
162215990Sjmallett * Undo the initialization performed in
163215990Sjmallett * cvmx_helper_initialize_packet_io_global(). After calling this routine and the
164215990Sjmallett * local version on each core, packet IO for Octeon will be disabled and placed
165215990Sjmallett * in the initial reset state. It will then be safe to call the initialize
166215990Sjmallett * later on. Note that this routine does not empty the FPA pools. It frees all
167215990Sjmallett * buffers used by the packet IO hardware to the FPA so a function emptying the
168215990Sjmallett * FPA after shutdown should find all packet buffers in the FPA.
169215990Sjmallett *
170215990Sjmallett * @return Zero on success, negative on failure.
171215990Sjmallett */
172215990Sjmallettextern int cvmx_helper_shutdown_packet_io_global(void);
173215990Sjmallett
174215990Sjmallett/**
175215990Sjmallett * Does core local shutdown of packet io
176215990Sjmallett *
177215990Sjmallett * @return Zero on success, non-zero on failure
178215990Sjmallett */
179215990Sjmallettextern int cvmx_helper_shutdown_packet_io_local(void);
180215990Sjmallett
181215990Sjmallett/**
182210284Sjmallett * Returns the number of ports on the given interface.
183210284Sjmallett * The interface must be initialized before the port count
184210284Sjmallett * can be returned.
185210284Sjmallett *
186210284Sjmallett * @param interface Which interface to return port count for.
187210284Sjmallett *
188210284Sjmallett * @return Port count for interface
189210284Sjmallett *         -1 for uninitialized interface
190210284Sjmallett */
191210284Sjmallettextern int cvmx_helper_ports_on_interface(int interface);
192210284Sjmallett
193210284Sjmallett/**
194210284Sjmallett * Return the number of interfaces the chip has. Each interface
195210284Sjmallett * may have multiple ports. Most chips support two interfaces,
196210284Sjmallett * but the CNX0XX and CNX1XX are exceptions. These only support
197210284Sjmallett * one interface.
198210284Sjmallett *
199210284Sjmallett * @return Number of interfaces on chip
200210284Sjmallett */
201210284Sjmallettextern int cvmx_helper_get_number_of_interfaces(void);
202210284Sjmallett
203210284Sjmallett/**
204210284Sjmallett * Get the operating mode of an interface. Depending on the Octeon
205210284Sjmallett * chip and configuration, this function returns an enumeration
206210284Sjmallett * of the type of packet I/O supported by an interface.
207210284Sjmallett *
208210284Sjmallett * @param interface Interface to probe
209210284Sjmallett *
210210284Sjmallett * @return Mode of the interface. Unknown or unsupported interfaces return
211210284Sjmallett *         DISABLED.
212210284Sjmallett */
213210284Sjmallettextern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface);
214210284Sjmallett
215210284Sjmallett/**
216210284Sjmallett * Auto configure an IPD/PKO port link state and speed. This
217210284Sjmallett * function basically does the equivalent of:
218210284Sjmallett * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port));
219210284Sjmallett *
220210284Sjmallett * @param ipd_port IPD/PKO port to auto configure
221210284Sjmallett *
222210284Sjmallett * @return Link state after configure
223210284Sjmallett */
224210284Sjmallettextern cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port);
225210284Sjmallett
226210284Sjmallett/**
227210284Sjmallett * Return the link state of an IPD/PKO port as returned by
228210284Sjmallett * auto negotiation. The result of this function may not match
229210284Sjmallett * Octeon's link config if auto negotiation has changed since
230210284Sjmallett * the last call to cvmx_helper_link_set().
231210284Sjmallett *
232210284Sjmallett * @param ipd_port IPD/PKO port to query
233210284Sjmallett *
234210284Sjmallett * @return Link state
235210284Sjmallett */
236210284Sjmallettextern cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port);
237210284Sjmallett
238210284Sjmallett/**
239210284Sjmallett * Configure an IPD/PKO port for the specified link state. This
240210284Sjmallett * function does not influence auto negotiation at the PHY level.
241210284Sjmallett * The passed link state must always match the link state returned
242210284Sjmallett * by cvmx_helper_link_get(). It is normally best to use
243210284Sjmallett * cvmx_helper_link_autoconf() instead.
244210284Sjmallett *
245210284Sjmallett * @param ipd_port  IPD/PKO port to configure
246210284Sjmallett * @param link_info The new link state
247210284Sjmallett *
248210284Sjmallett * @return Zero on success, negative on failure
249210284Sjmallett */
250210284Sjmallettextern int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info);
251210284Sjmallett
252210284Sjmallett
253210284Sjmallett
254210284Sjmallett/**
255210284Sjmallett * This function probes an interface to determine the actual
256210284Sjmallett * number of hardware ports connected to it. It doesn't setup the
257210284Sjmallett * ports or enable them. The main goal here is to set the global
258210284Sjmallett * interface_port_count[interface] correctly. Hardware setup of the
259210284Sjmallett * ports will be performed later.
260210284Sjmallett *
261210284Sjmallett * @param interface Interface to probe
262210284Sjmallett *
263210284Sjmallett * @return Zero on success, negative on failure
264210284Sjmallett */
265210284Sjmallettextern int cvmx_helper_interface_probe(int interface);
266210284Sjmallett
267210284Sjmallett/**
268210284Sjmallett * Configure a port for internal and/or external loopback. Internal loopback
269210284Sjmallett * causes packets sent by the port to be received by Octeon. External loopback
270210284Sjmallett * causes packets received from the wire to sent out again.
271210284Sjmallett *
272210284Sjmallett * @param ipd_port IPD/PKO port to loopback.
273210284Sjmallett * @param enable_internal
274210284Sjmallett *                 Non zero if you want internal loopback
275210284Sjmallett * @param enable_external
276210284Sjmallett *                 Non zero if you want external loopback
277210284Sjmallett *
278210284Sjmallett * @return Zero on success, negative on failure.
279210284Sjmallett */
280210284Sjmallettextern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal, int enable_external);
281210284Sjmallett
282210311Sjmallett#include "cvmx-helper-util.h"
283210311Sjmallett
284210284Sjmallett#endif /* CVMX_ENABLE_PKO_FUNCTIONS */
285210284Sjmallett
286210284Sjmallett#ifdef	__cplusplus
287210284Sjmallett}
288210284Sjmallett#endif
289210284Sjmallett
290210284Sjmallett#endif  /* __CVMX_HELPER_H__ */
291