]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/cvmx-helper.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / octeon-sdk / cvmx-helper.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  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  * This Software, including technical data, may be subject to U.S. export  control
24  * laws, including the U.S. Export Administration Act and its  associated
25  * regulations, and may be subject to export or import  regulations in other
26  * countries.
27
28  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29  * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30  * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31  * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32  * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33  * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34  * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35  * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36  * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37  * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38  ***********************license end**************************************/
39
40
41
42
43
44
45
46 /**
47  * @file
48  *
49  * Helper functions for common, but complicated tasks.
50  *
51  * <hr>$Revision: 49448 $<hr>
52  */
53
54 #ifndef __CVMX_HELPER_H__
55 #define __CVMX_HELPER_H__
56
57 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
58 #include <asm/octeon/cvmx.h>
59 #include <asm/octeon/cvmx-config.h>
60 #elif !defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
61 #include "executive-config.h"
62 #include "cvmx-config.h"
63 #endif
64
65 #include "cvmx-fpa.h"
66 #include "cvmx-wqe.h"
67
68 #ifdef  __cplusplus
69 extern "C" {
70 #endif
71
72 typedef enum
73 {
74     CVMX_HELPER_INTERFACE_MODE_DISABLED,
75     CVMX_HELPER_INTERFACE_MODE_RGMII,
76     CVMX_HELPER_INTERFACE_MODE_GMII,
77     CVMX_HELPER_INTERFACE_MODE_SPI,
78     CVMX_HELPER_INTERFACE_MODE_PCIE,
79     CVMX_HELPER_INTERFACE_MODE_XAUI,
80     CVMX_HELPER_INTERFACE_MODE_SGMII,
81     CVMX_HELPER_INTERFACE_MODE_PICMG,
82     CVMX_HELPER_INTERFACE_MODE_NPI,
83     CVMX_HELPER_INTERFACE_MODE_LOOP,
84     CVMX_HELPER_INTERFACE_MODE_SRIO,
85 } cvmx_helper_interface_mode_t;
86
87 typedef union
88 {
89     uint64_t u64;
90     struct
91     {
92         uint64_t    reserved_20_63  : 44;
93         uint64_t    link_up         : 1;    /**< Is the physical link up? */
94         uint64_t    full_duplex     : 1;    /**< 1 if the link is full duplex */
95         uint64_t    speed           : 18;   /**< Speed of the link in Mbps */
96     } s;
97 } cvmx_helper_link_info_t;
98
99 #include "cvmx-helper-fpa.h"
100
101 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
102
103 #include "cvmx-helper-errata.h"
104 #include "cvmx-helper-loop.h"
105 #include "cvmx-helper-npi.h"
106 #include "cvmx-helper-rgmii.h"
107 #include "cvmx-helper-sgmii.h"
108 #include "cvmx-helper-spi.h"
109 #include "cvmx-helper-srio.h"
110 #include "cvmx-helper-xaui.h"
111
112 /**
113  * cvmx_override_pko_queue_priority(int ipd_port, uint64_t
114  * priorities[16]) is a function pointer. It is meant to allow
115  * customization of the PKO queue priorities based on the port
116  * number. Users should set this pointer to a function before
117  * calling any cvmx-helper operations.
118  */
119 extern void (*cvmx_override_pko_queue_priority)(int pko_port, uint64_t priorities[16]);
120
121 /**
122  * cvmx_override_ipd_port_setup(int ipd_port) is a function
123  * pointer. It is meant to allow customization of the IPD port
124  * setup before packet input/output comes online. It is called
125  * after cvmx-helper does the default IPD configuration, but
126  * before IPD is enabled. Users should set this pointer to a
127  * function before calling any cvmx-helper operations.
128  */
129 extern void (*cvmx_override_ipd_port_setup)(int ipd_port);
130
131 /**
132  * This function enables the IPD and also enables the packet interfaces.
133  * The packet interfaces (RGMII and SPI) must be enabled after the
134  * IPD.  This should be called by the user program after any additional
135  * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD
136  * is not set in the executive-config.h file.
137  *
138  * @return 0 on success
139  *         -1 on failure
140  */
141 extern int cvmx_helper_ipd_and_packet_input_enable(void);
142
143 /**
144  * Initialize the PIP, IPD, and PKO hardware to support
145  * simple priority based queues for the ethernet ports. Each
146  * port is configured with a number of priority queues based
147  * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
148  * priority than the previous.
149  *
150  * @return Zero on success, non-zero on failure
151  */
152 extern int cvmx_helper_initialize_packet_io_global(void);
153
154 /**
155  * Does core local initialization for packet io
156  *
157  * @return Zero on success, non-zero on failure
158  */
159 extern int cvmx_helper_initialize_packet_io_local(void);
160
161 /**
162  * Undo the initialization performed in
163  * cvmx_helper_initialize_packet_io_global(). After calling this routine and the
164  * local version on each core, packet IO for Octeon will be disabled and placed
165  * in the initial reset state. It will then be safe to call the initialize
166  * later on. Note that this routine does not empty the FPA pools. It frees all
167  * buffers used by the packet IO hardware to the FPA so a function emptying the
168  * FPA after shutdown should find all packet buffers in the FPA.
169  *
170  * @return Zero on success, negative on failure.
171  */
172 extern int cvmx_helper_shutdown_packet_io_global(void);
173
174 /**
175  * Does core local shutdown of packet io
176  *
177  * @return Zero on success, non-zero on failure
178  */
179 extern int cvmx_helper_shutdown_packet_io_local(void);
180
181 /**
182  * Returns the number of ports on the given interface.
183  * The interface must be initialized before the port count
184  * can be returned.
185  *
186  * @param interface Which interface to return port count for.
187  *
188  * @return Port count for interface
189  *         -1 for uninitialized interface
190  */
191 extern int cvmx_helper_ports_on_interface(int interface);
192
193 /**
194  * Return the number of interfaces the chip has. Each interface
195  * may have multiple ports. Most chips support two interfaces,
196  * but the CNX0XX and CNX1XX are exceptions. These only support
197  * one interface.
198  *
199  * @return Number of interfaces on chip
200  */
201 extern int cvmx_helper_get_number_of_interfaces(void);
202
203 /**
204  * Get the operating mode of an interface. Depending on the Octeon
205  * chip and configuration, this function returns an enumeration
206  * of the type of packet I/O supported by an interface.
207  *
208  * @param interface Interface to probe
209  *
210  * @return Mode of the interface. Unknown or unsupported interfaces return
211  *         DISABLED.
212  */
213 extern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface);
214
215 /**
216  * Auto configure an IPD/PKO port link state and speed. This
217  * function basically does the equivalent of:
218  * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port));
219  *
220  * @param ipd_port IPD/PKO port to auto configure
221  *
222  * @return Link state after configure
223  */
224 extern cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port);
225
226 /**
227  * Return the link state of an IPD/PKO port as returned by
228  * auto negotiation. The result of this function may not match
229  * Octeon's link config if auto negotiation has changed since
230  * the last call to cvmx_helper_link_set().
231  *
232  * @param ipd_port IPD/PKO port to query
233  *
234  * @return Link state
235  */
236 extern cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port);
237
238 /**
239  * Configure an IPD/PKO port for the specified link state. This
240  * function does not influence auto negotiation at the PHY level.
241  * The passed link state must always match the link state returned
242  * by cvmx_helper_link_get(). It is normally best to use
243  * cvmx_helper_link_autoconf() instead.
244  *
245  * @param ipd_port  IPD/PKO port to configure
246  * @param link_info The new link state
247  *
248  * @return Zero on success, negative on failure
249  */
250 extern int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info);
251
252
253
254 /**
255  * This function probes an interface to determine the actual
256  * number of hardware ports connected to it. It doesn't setup the
257  * ports or enable them. The main goal here is to set the global
258  * interface_port_count[interface] correctly. Hardware setup of the
259  * ports will be performed later.
260  *
261  * @param interface Interface to probe
262  *
263  * @return Zero on success, negative on failure
264  */
265 extern int cvmx_helper_interface_probe(int interface);
266
267 /**
268  * Configure a port for internal and/or external loopback. Internal loopback
269  * causes packets sent by the port to be received by Octeon. External loopback
270  * causes packets received from the wire to sent out again.
271  *
272  * @param ipd_port IPD/PKO port to loopback.
273  * @param enable_internal
274  *                 Non zero if you want internal loopback
275  * @param enable_external
276  *                 Non zero if you want external loopback
277  *
278  * @return Zero on success, negative on failure.
279  */
280 extern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal, int enable_external);
281
282 #include "cvmx-helper-util.h"
283
284 #endif /* CVMX_ENABLE_PKO_FUNCTIONS */
285
286 #ifdef  __cplusplus
287 }
288 #endif
289
290 #endif  /* __CVMX_HELPER_H__ */