1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
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
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
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**************************************/
49 * Helper functions for common, but complicated tasks.
51 * <hr>$Revision: 70030 $<hr>
54 #ifndef __CVMX_HELPER_H__
55 #define __CVMX_HELPER_H__
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"
72 /* Max number of GMXX */
73 #define CVMX_HELPER_MAX_GMX (OCTEON_IS_MODEL(OCTEON_CN68XX) ? 5 : 2)
75 #define CVMX_HELPER_CSR_INIT0 0 /* Do not change as
76 CVMX_HELPER_WRITE_CSR()
78 #define CVMX_HELPER_CSR_INIT_READ -1
81 * CVMX_HELPER_WRITE_CSR--set a field in a CSR with a value.
83 * @param chcsr_init intial value of the csr (CVMX_HELPER_CSR_INIT_READ
84 * means to use the existing csr value as the
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
92 #define CVMX_HELPER_WRITE_CSR(chcsr_init, chcsr_csr, chcsr_type, \
93 chcsr_chip, chcsr_fld, chcsr_val) \
96 if ((chcsr_init) == CVMX_HELPER_CSR_INIT_READ) \
97 csr.u64 = cvmx_read_csr(chcsr_csr); \
99 csr.u64 = (chcsr_init); \
100 csr.chcsr_chip.chcsr_fld = (chcsr_val); \
101 cvmx_write_csr((chcsr_csr), csr.u64); \
105 * CVMX_HELPER_WRITE_CSR0--set a field in a CSR with the initial value of 0
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)
113 * CVMX_HELPER_WRITE_CSR1--set a field in a CSR with the initial value of
114 * the CSR's current value.
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)
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;
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 */
149 } cvmx_helper_link_info_t;
151 #include "cvmx-helper-fpa.h"
153 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
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"
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.
172 extern CVMX_SHARED void (*cvmx_override_pko_queue_priority)(int ipd_port, uint64_t *priorities);
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.
182 extern CVMX_SHARED void (*cvmx_override_ipd_port_setup)(int ipd_port);
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.
191 * @return 0 on success
194 extern int cvmx_helper_ipd_and_packet_input_enable(void);
197 * Initialize and allocate memory for the SSO.
199 * @param wqe_entries The maximum number of work queue entries to be
202 * @return Zero on success, non-zero on failure.
204 extern int cvmx_helper_initialize_sso(int wqe_entries);
207 * Undo the effect of cvmx_helper_initialize_sso().
209 * Warning: since cvmx_bootmem_alloc() memory cannot be freed, the
210 * memory allocated by cvmx_helper_initialize_sso() will be leaked.
212 * @return Zero on success, non-zero on failure.
214 extern int cvmx_helper_uninitialize_sso(void);
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.
223 * @return Zero on success, non-zero on failure
225 extern int cvmx_helper_initialize_packet_io_global(void);
228 * Does core local initialization for packet io
230 * @return Zero on success, non-zero on failure
232 extern int cvmx_helper_initialize_packet_io_local(void);
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.
243 * @return Zero on success, negative on failure.
245 extern int cvmx_helper_shutdown_packet_io_global(void);
248 * Does core local shutdown of packet io
250 * @return Zero on success, non-zero on failure
252 extern int cvmx_helper_shutdown_packet_io_local(void);
255 * Returns the number of ports on the given interface.
256 * The interface must be initialized before the port count
259 * @param interface Which interface to return port count for.
261 * @return Port count for interface
262 * -1 for uninitialized interface
264 extern int cvmx_helper_ports_on_interface(int interface);
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
272 * @return Number of interfaces on chip
274 extern int cvmx_helper_get_number_of_interfaces(void);
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.
281 * @param interface Interface to probe
283 * @return Mode of the interface. Unknown or unsupported interfaces return
286 extern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface);
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));
293 * @param ipd_port IPD/PKO port to auto configure
295 * @return Link state after configure
297 extern cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port);
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().
305 * @param ipd_port IPD/PKO port to query
309 extern cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port);
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.
318 * @param ipd_port IPD/PKO port to configure
319 * @param link_info The new link state
321 * @return Zero on success, negative on failure
323 extern int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info);
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.
334 * @param interface Interface to probe
336 * @return Zero on success, negative on failure
338 extern int cvmx_helper_interface_probe(int interface);
341 * Determine the actual number of hardware ports connected to an
342 * interface. It doesn't setup the ports or enable them.
344 * @param interface Interface to enumerate
346 * @return Zero on success, negative on failure
348 extern int cvmx_helper_interface_enumerate(int interface);
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.
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
361 * @return Zero on success, negative on failure.
363 extern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal, int enable_external);
365 #include "cvmx-helper-util.h"
367 #endif /* CVMX_ENABLE_PKO_FUNCTIONS */
373 #endif /* __CVMX_HELPER_H__ */