]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/contrib/octeon-sdk/cvmx-helper.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / contrib / octeon-sdk / cvmx-helper.h
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 #ifndef CVMX_DONT_INCLUDE_CONFIG
56 #include "executive-config.h"
57 #include "cvmx-config.h"
58 #endif
59 #include "cvmx-fpa.h"
60 #include "cvmx-wqe.h"
61
62 #ifdef  __cplusplus
63 extern "C" {
64 #endif
65
66 typedef enum
67 {
68     CVMX_HELPER_INTERFACE_MODE_DISABLED,
69     CVMX_HELPER_INTERFACE_MODE_RGMII,
70     CVMX_HELPER_INTERFACE_MODE_GMII,
71     CVMX_HELPER_INTERFACE_MODE_SPI,
72     CVMX_HELPER_INTERFACE_MODE_PCIE,
73     CVMX_HELPER_INTERFACE_MODE_XAUI,
74     CVMX_HELPER_INTERFACE_MODE_SGMII,
75     CVMX_HELPER_INTERFACE_MODE_PICMG,
76     CVMX_HELPER_INTERFACE_MODE_NPI,
77     CVMX_HELPER_INTERFACE_MODE_LOOP,
78 } cvmx_helper_interface_mode_t;
79
80 typedef union
81 {
82     uint64_t u64;
83     struct
84     {
85         uint64_t    reserved_20_63  : 44;
86         uint64_t    link_up         : 1;    /**< Is the physical link up? */
87         uint64_t    full_duplex     : 1;    /**< 1 if the link is full duplex */
88         uint64_t    speed           : 18;   /**< Speed of the link in Mbps */
89     } s;
90 } cvmx_helper_link_info_t;
91
92 #include "cvmx-helper-fpa.h"
93
94 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
95
96 #include "cvmx-helper-errata.h"
97 #include "cvmx-helper-loop.h"
98 #include "cvmx-helper-npi.h"
99 #include "cvmx-helper-rgmii.h"
100 #include "cvmx-helper-sgmii.h"
101 #include "cvmx-helper-spi.h"
102 #include "cvmx-helper-xaui.h"
103
104 /**
105  * cvmx_override_pko_queue_priority(int ipd_port, uint64_t
106  * priorities[16]) is a function pointer. It is meant to allow
107  * customization of the PKO queue priorities based on the port
108  * number. Users should set this pointer to a function before
109  * calling any cvmx-helper operations.
110  */
111 extern void (*cvmx_override_pko_queue_priority)(int pko_port, uint64_t priorities[16]);
112
113 /**
114  * cvmx_override_ipd_port_setup(int ipd_port) is a function
115  * pointer. It is meant to allow customization of the IPD port
116  * setup before packet input/output comes online. It is called
117  * after cvmx-helper does the default IPD configuration, but
118  * before IPD is enabled. Users should set this pointer to a
119  * function before calling any cvmx-helper operations.
120  */
121 extern void (*cvmx_override_ipd_port_setup)(int ipd_port);
122
123 /**
124  * This function enables the IPD and also enables the packet interfaces.
125  * The packet interfaces (RGMII and SPI) must be enabled after the
126  * IPD.  This should be called by the user program after any additional
127  * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD
128  * is not set in the executive-config.h file.
129  *
130  * @return 0 on success
131  *         -1 on failure
132  */
133 extern int cvmx_helper_ipd_and_packet_input_enable(void);
134
135 /**
136  * Initialize the PIP, IPD, and PKO hardware to support
137  * simple priority based queues for the ethernet ports. Each
138  * port is configured with a number of priority queues based
139  * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
140  * priority than the previous.
141  *
142  * @return Zero on success, non-zero on failure
143  */
144 extern int cvmx_helper_initialize_packet_io_global(void);
145
146 /**
147  * Does core local initialization for packet io
148  *
149  * @return Zero on success, non-zero on failure
150  */
151 extern int cvmx_helper_initialize_packet_io_local(void);
152
153 /**
154  * Returns the number of ports on the given interface.
155  * The interface must be initialized before the port count
156  * can be returned.
157  *
158  * @param interface Which interface to return port count for.
159  *
160  * @return Port count for interface
161  *         -1 for uninitialized interface
162  */
163 extern int cvmx_helper_ports_on_interface(int interface);
164
165 /**
166  * Return the number of interfaces the chip has. Each interface
167  * may have multiple ports. Most chips support two interfaces,
168  * but the CNX0XX and CNX1XX are exceptions. These only support
169  * one interface.
170  *
171  * @return Number of interfaces on chip
172  */
173 extern int cvmx_helper_get_number_of_interfaces(void);
174
175 /**
176  * Get the operating mode of an interface. Depending on the Octeon
177  * chip and configuration, this function returns an enumeration
178  * of the type of packet I/O supported by an interface.
179  *
180  * @param interface Interface to probe
181  *
182  * @return Mode of the interface. Unknown or unsupported interfaces return
183  *         DISABLED.
184  */
185 extern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface);
186
187 /**
188  * Auto configure an IPD/PKO port link state and speed. This
189  * function basically does the equivalent of:
190  * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port));
191  *
192  * @param ipd_port IPD/PKO port to auto configure
193  *
194  * @return Link state after configure
195  */
196 extern cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port);
197
198 /**
199  * Return the link state of an IPD/PKO port as returned by
200  * auto negotiation. The result of this function may not match
201  * Octeon's link config if auto negotiation has changed since
202  * the last call to cvmx_helper_link_set().
203  *
204  * @param ipd_port IPD/PKO port to query
205  *
206  * @return Link state
207  */
208 extern cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port);
209
210 /**
211  * Configure an IPD/PKO port for the specified link state. This
212  * function does not influence auto negotiation at the PHY level.
213  * The passed link state must always match the link state returned
214  * by cvmx_helper_link_get(). It is normally best to use
215  * cvmx_helper_link_autoconf() instead.
216  *
217  * @param ipd_port  IPD/PKO port to configure
218  * @param link_info The new link state
219  *
220  * @return Zero on success, negative on failure
221  */
222 extern int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info);
223
224
225
226 /**
227  * This function probes an interface to determine the actual
228  * number of hardware ports connected to it. It doesn't setup the
229  * ports or enable them. The main goal here is to set the global
230  * interface_port_count[interface] correctly. Hardware setup of the
231  * ports will be performed later.
232  *
233  * @param interface Interface to probe
234  *
235  * @return Zero on success, negative on failure
236  */
237 extern int cvmx_helper_interface_probe(int interface);
238
239 /**
240  * Configure a port for internal and/or external loopback. Internal loopback
241  * causes packets sent by the port to be received by Octeon. External loopback
242  * causes packets received from the wire to sent out again.
243  *
244  * @param ipd_port IPD/PKO port to loopback.
245  * @param enable_internal
246  *                 Non zero if you want internal loopback
247  * @param enable_external
248  *                 Non zero if you want external loopback
249  *
250  * @return Zero on success, negative on failure.
251  */
252 extern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal, int enable_external);
253
254 #include "cvmx-helper-util.h"
255
256 #endif /* CVMX_ENABLE_PKO_FUNCTIONS */
257
258 #ifdef  __cplusplus
259 }
260 #endif
261
262 #endif  /* __CVMX_HELPER_H__ */