]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/contrib/octeon-sdk/cvmx-helper.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / contrib / octeon-sdk / cvmx-helper.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Inc. (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 Inc. 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 INC. 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: 70030 $<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 /* Max number of GMXX */
73 #define CVMX_HELPER_MAX_GMX             (OCTEON_IS_MODEL(OCTEON_CN68XX) ? 5 : 2)
74
75 #define CVMX_HELPER_CSR_INIT0           0       /* Do not change as 
76                                                    CVMX_HELPER_WRITE_CSR()
77                                                    assumes it */
78 #define CVMX_HELPER_CSR_INIT_READ       -1
79
80 /*
81  * CVMX_HELPER_WRITE_CSR--set a field in a CSR with a value.
82  *
83  * @param chcsr_init    intial value of the csr (CVMX_HELPER_CSR_INIT_READ
84  *                      means to use the existing csr value as the
85  *                      initial value.)
86  * @param chcsr_csr     the name of the csr
87  * @param chcsr_type    the type of the csr (see the -defs.h)
88  * @param chcsr_chip    the chip for the csr/field
89  * @param chcsr_fld     the field in the csr
90  * @param chcsr_val     the value for field
91  */
92 #define CVMX_HELPER_WRITE_CSR(chcsr_init, chcsr_csr, chcsr_type,        \
93     chcsr_chip, chcsr_fld, chcsr_val)                                   \
94         do {                                                            \
95                 chcsr_type csr;                                         \
96                 if ((chcsr_init) == CVMX_HELPER_CSR_INIT_READ)          \
97                         csr.u64 = cvmx_read_csr(chcsr_csr);             \
98                 else                                                    \
99                         csr.u64 = (chcsr_init);                         \
100                 csr.chcsr_chip.chcsr_fld = (chcsr_val);                 \
101                 cvmx_write_csr((chcsr_csr), csr.u64);                   \
102         } while(0)
103
104 /*
105  * CVMX_HELPER_WRITE_CSR0--set a field in a CSR with the initial value of 0
106  */
107 #define CVMX_HELPER_WRITE_CSR0(chcsr_csr, chcsr_type, chcsr_chip,       \
108     chcsr_fld, chcsr_val)                                               \
109         CVMX_HELPER_WRITE_CSR(CVMX_HELPER_CSR_INIT0, chcsr_csr,         \
110             chcsr_type, chcsr_chip, chcsr_fld, chcsr_val)
111
112 /*
113  * CVMX_HELPER_WRITE_CSR1--set a field in a CSR with the initial value of
114  *                      the CSR's current value.
115  */
116 #define CVMX_HELPER_WRITE_CSR1(chcsr_csr, chcsr_type, chcsr_chip,       \
117     chcsr_fld, chcsr_val)                                               \
118         CVMX_HELPER_WRITE_CSR(CVMX_HELPER_CSR_INIT_READ, chcsr_csr,     \
119             chcsr_type, chcsr_chip, chcsr_fld, chcsr_val)
120
121
122 typedef enum
123 {
124     CVMX_HELPER_INTERFACE_MODE_DISABLED,
125     CVMX_HELPER_INTERFACE_MODE_RGMII,
126     CVMX_HELPER_INTERFACE_MODE_GMII,
127     CVMX_HELPER_INTERFACE_MODE_SPI,
128     CVMX_HELPER_INTERFACE_MODE_PCIE,
129     CVMX_HELPER_INTERFACE_MODE_XAUI,
130     CVMX_HELPER_INTERFACE_MODE_SGMII,
131     CVMX_HELPER_INTERFACE_MODE_PICMG,
132     CVMX_HELPER_INTERFACE_MODE_NPI,
133     CVMX_HELPER_INTERFACE_MODE_LOOP,
134     CVMX_HELPER_INTERFACE_MODE_SRIO,
135     CVMX_HELPER_INTERFACE_MODE_ILK,
136     CVMX_HELPER_INTERFACE_MODE_RXAUI,
137 } cvmx_helper_interface_mode_t;
138
139 typedef union
140 {
141     uint64_t u64;
142     struct
143     {
144         uint64_t    reserved_20_63  : 44;
145         uint64_t    link_up         : 1;    /**< Is the physical link up? */
146         uint64_t    full_duplex     : 1;    /**< 1 if the link is full duplex */
147         uint64_t    speed           : 18;   /**< Speed of the link in Mbps */
148     } s;
149 } cvmx_helper_link_info_t;
150
151 #include "cvmx-helper-fpa.h"
152
153 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
154
155 #include "cvmx-helper-errata.h"
156 #include "cvmx-helper-ilk.h"
157 #include "cvmx-helper-loop.h"
158 #include "cvmx-helper-npi.h"
159 #include "cvmx-helper-rgmii.h"
160 #include "cvmx-helper-sgmii.h"
161 #include "cvmx-helper-spi.h"
162 #include "cvmx-helper-srio.h"
163 #include "cvmx-helper-xaui.h"
164
165 /**
166  * cvmx_override_pko_queue_priority(int ipd_port, uint64_t
167  * priorities[16]) is a function pointer. It is meant to allow
168  * customization of the PKO queue priorities based on the port
169  * number. Users should set this pointer to a function before
170  * calling any cvmx-helper operations.
171  */
172 extern CVMX_SHARED void (*cvmx_override_pko_queue_priority)(int ipd_port, uint64_t *priorities);
173
174 /**
175  * cvmx_override_ipd_port_setup(int ipd_port) is a function
176  * pointer. It is meant to allow customization of the IPD port/port kind
177  * setup before packet input/output comes online. It is called
178  * after cvmx-helper does the default IPD configuration, but
179  * before IPD is enabled. Users should set this pointer to a
180  * function before calling any cvmx-helper operations.
181  */
182 extern CVMX_SHARED void (*cvmx_override_ipd_port_setup)(int ipd_port);
183
184 /**
185  * This function enables the IPD and also enables the packet interfaces.
186  * The packet interfaces (RGMII and SPI) must be enabled after the
187  * IPD.  This should be called by the user program after any additional
188  * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD
189  * is not set in the executive-config.h file.
190  *
191  * @return 0 on success
192  *         -1 on failure
193  */
194 extern int cvmx_helper_ipd_and_packet_input_enable(void);
195
196 /**
197  * Initialize and allocate memory for the SSO.
198  *
199  * @param wqe_entries The maximum number of work queue entries to be
200  * supported.
201  *
202  * @return Zero on success, non-zero on failure.
203  */
204 extern int cvmx_helper_initialize_sso(int wqe_entries);
205
206 /**
207  * Undo the effect of cvmx_helper_initialize_sso().
208  *
209  * Warning: since cvmx_bootmem_alloc() memory cannot be freed, the
210  * memory allocated by cvmx_helper_initialize_sso() will be leaked.
211  *
212  * @return Zero on success, non-zero on failure.
213  */
214 extern int cvmx_helper_uninitialize_sso(void);
215
216 /**
217  * Initialize the PIP, IPD, and PKO hardware to support
218  * simple priority based queues for the ethernet ports. Each
219  * port is configured with a number of priority queues based
220  * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
221  * priority than the previous.
222  *
223  * @return Zero on success, non-zero on failure
224  */
225 extern int cvmx_helper_initialize_packet_io_global(void);
226
227 /**
228  * Does core local initialization for packet io
229  *
230  * @return Zero on success, non-zero on failure
231  */
232 extern int cvmx_helper_initialize_packet_io_local(void);
233
234 /**
235  * Undo the initialization performed in
236  * cvmx_helper_initialize_packet_io_global(). After calling this routine and the
237  * local version on each core, packet IO for Octeon will be disabled and placed
238  * in the initial reset state. It will then be safe to call the initialize
239  * later on. Note that this routine does not empty the FPA pools. It frees all
240  * buffers used by the packet IO hardware to the FPA so a function emptying the
241  * FPA after shutdown should find all packet buffers in the FPA.
242  *
243  * @return Zero on success, negative on failure.
244  */
245 extern int cvmx_helper_shutdown_packet_io_global(void);
246
247 /**
248  * Does core local shutdown of packet io
249  *
250  * @return Zero on success, non-zero on failure
251  */
252 extern int cvmx_helper_shutdown_packet_io_local(void);
253
254 /**
255  * Returns the number of ports on the given interface.
256  * The interface must be initialized before the port count
257  * can be returned.
258  *
259  * @param interface Which interface to return port count for.
260  *
261  * @return Port count for interface
262  *         -1 for uninitialized interface
263  */
264 extern int cvmx_helper_ports_on_interface(int interface);
265
266 /**
267  * Return the number of interfaces the chip has. Each interface
268  * may have multiple ports. Most chips support two interfaces,
269  * but the CNX0XX and CNX1XX are exceptions. These only support
270  * one interface.
271  *
272  * @return Number of interfaces on chip
273  */
274 extern int cvmx_helper_get_number_of_interfaces(void);
275
276 /**
277  * Get the operating mode of an interface. Depending on the Octeon
278  * chip and configuration, this function returns an enumeration
279  * of the type of packet I/O supported by an interface.
280  *
281  * @param interface Interface to probe
282  *
283  * @return Mode of the interface. Unknown or unsupported interfaces return
284  *         DISABLED.
285  */
286 extern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface);
287
288 /**
289  * Auto configure an IPD/PKO port link state and speed. This
290  * function basically does the equivalent of:
291  * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port));
292  *
293  * @param ipd_port IPD/PKO port to auto configure
294  *
295  * @return Link state after configure
296  */
297 extern cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port);
298
299 /**
300  * Return the link state of an IPD/PKO port as returned by
301  * auto negotiation. The result of this function may not match
302  * Octeon's link config if auto negotiation has changed since
303  * the last call to cvmx_helper_link_set().
304  *
305  * @param ipd_port IPD/PKO port to query
306  *
307  * @return Link state
308  */
309 extern cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port);
310
311 /**
312  * Configure an IPD/PKO port for the specified link state. This
313  * function does not influence auto negotiation at the PHY level.
314  * The passed link state must always match the link state returned
315  * by cvmx_helper_link_get(). It is normally best to use
316  * cvmx_helper_link_autoconf() instead.
317  *
318  * @param ipd_port  IPD/PKO port to configure
319  * @param link_info The new link state
320  *
321  * @return Zero on success, negative on failure
322  */
323 extern int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info);
324
325
326
327 /**
328  * This function probes an interface to determine the actual number of
329  * hardware ports connected to it. It does some setup the ports but
330  * doesn't enable them. The main goal here is to set the global
331  * interface_port_count[interface] correctly. Final hardware setup of
332  * the ports will be performed later.
333  *
334  * @param interface Interface to probe
335  *
336  * @return Zero on success, negative on failure
337  */
338 extern int cvmx_helper_interface_probe(int interface);
339
340 /**
341  * Determine the actual number of hardware ports connected to an
342  * interface. It doesn't setup the ports or enable them.
343  *
344  * @param interface Interface to enumerate
345  *
346  * @return Zero on success, negative on failure
347  */
348 extern int cvmx_helper_interface_enumerate(int interface);
349
350 /**
351  * Configure a port for internal and/or external loopback. Internal loopback
352  * causes packets sent by the port to be received by Octeon. External loopback
353  * causes packets received from the wire to sent out again.
354  *
355  * @param ipd_port IPD/PKO port to loopback.
356  * @param enable_internal
357  *                 Non zero if you want internal loopback
358  * @param enable_external
359  *                 Non zero if you want external loopback
360  *
361  * @return Zero on success, negative on failure.
362  */
363 extern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal, int enable_external);
364
365 #include "cvmx-helper-util.h"
366
367 #endif /* CVMX_ENABLE_PKO_FUNCTIONS */
368
369 #ifdef  __cplusplus
370 }
371 #endif
372
373 #endif  /* __CVMX_HELPER_H__ */