1 /***********************license start***************
2 * Copyright (c) 2003-2008 Cavium Networks (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 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
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.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
47 * Small helper utilities.
49 * <hr>$Revision: 41586 $<hr>
52 #ifndef __CVMX_HELPER_UTIL_H__
53 #define __CVMX_HELPER_UTIL_H__
56 #ifdef CVMX_ENABLE_HELPER_FUNCTIONS
59 * Convert a interface mode into a human readable string
61 * @param mode Mode to convert
65 extern const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode);
68 * Debug routine to dump the packet structure to the console
70 * @param work Work queue entry containing the packet to dump
73 extern int cvmx_helper_dump_packet(cvmx_wqe_t *work);
76 * Setup Random Early Drop on a specific input queue
78 * @param queue Input queue to setup RED on (0-7)
80 * Packets will begin slowly dropping when there are less than
81 * this many packet buffers free in FPA 0.
83 * All incomming packets will be dropped when there are less
84 * than this many free packet buffers in FPA 0.
85 * @return Zero on success. Negative on failure
87 extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh);
90 * Setup Random Early Drop to automatically begin dropping packets.
93 * Packets will begin slowly dropping when there are less than
94 * this many packet buffers free in FPA 0.
96 * All incomming packets will be dropped when there are less
97 * than this many free packet buffers in FPA 0.
98 * @return Zero on success. Negative on failure
100 extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
104 * Get the version of the CVMX libraries.
106 * @return Version string. Note this buffer is allocated statically
107 * and will be shared by all callers.
109 extern const char *cvmx_helper_get_version(void);
114 * Setup the common GMX settings that determine the number of
115 * ports. These setting apply to almost all configurations of all
118 * @param interface Interface to configure
119 * @param num_ports Number of ports on the interface
121 * @return Zero on success, negative on failure
123 extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
126 * Returns the IPD/PKO port number for a port on the given
129 * @param interface Interface to use
130 * @param port Port on the interface
132 * @return IPD/PKO port number
134 extern int cvmx_helper_get_ipd_port(int interface, int port);
138 * Returns the IPD/PKO port number for the first port on the given
141 * @param interface Interface to use
143 * @return IPD/PKO port number
145 static inline int cvmx_helper_get_first_ipd_port(int interface)
147 return (cvmx_helper_get_ipd_port (interface, 0));
151 * Returns the IPD/PKO port number for the last port on the given
154 * @param interface Interface to use
156 * @return IPD/PKO port number
158 static inline int cvmx_helper_get_last_ipd_port (int interface)
160 return (cvmx_helper_get_first_ipd_port (interface) +
161 cvmx_helper_ports_on_interface (interface) - 1);
166 * Free the packet buffers contained in a work queue entry.
167 * The work queue entry is not freed.
169 * @param work Work queue entry with packet to free
171 static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work)
173 uint64_t number_buffers;
174 cvmx_buf_ptr_t buffer_ptr;
175 cvmx_buf_ptr_t next_buffer_ptr;
176 uint64_t start_of_buffer;
178 number_buffers = work->word2.s.bufs;
179 if (number_buffers == 0)
181 buffer_ptr = work->packet_ptr;
183 /* Since the number of buffers is not zero, we know this is not a dynamic
184 short packet. We need to check if it is a packet received with
185 IPD_CTL_STATUS[NO_WPTR]. If this is true, we need to free all buffers
186 except for the first one. The caller doesn't expect their WQE pointer
188 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
189 if (cvmx_ptr_to_phys(work) == start_of_buffer)
191 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
192 buffer_ptr = next_buffer_ptr;
196 while (number_buffers--)
198 /* Remember the back pointer is in cache lines, not 64bit words */
199 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
200 /* Read pointer to next buffer before we free the current buffer. */
201 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
202 cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer), buffer_ptr.s.pool, 0);
203 buffer_ptr = next_buffer_ptr;
207 #endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
210 * Returns the interface number for an IPD/PKO port number.
212 * @param ipd_port IPD/PKO port number
214 * @return Interface number
216 extern int cvmx_helper_get_interface_num(int ipd_port);
220 * Returns the interface index number for an IPD/PKO port
223 * @param ipd_port IPD/PKO port number
225 * @return Interface index number
227 extern int cvmx_helper_get_interface_index_num(int ipd_port);
230 * Initialize the internal QLM JTAG logic to allow programming
231 * of the JTAG chain by the cvmx_helper_qlm_jtag_*() functions.
232 * These functions should only be used at the direction of Cavium
233 * Networks. Programming incorrect values into the JTAG chain
234 * can cause chip damage.
236 extern void cvmx_helper_qlm_jtag_init(void);
239 * Write up to 32bits into the QLM jtag chain. Bits are shifted
240 * into the MSB and out the LSB, so you should shift in the low
241 * order bits followed by the high order bits. The JTAG chain is
242 * 4 * 268 bits long, or 1072.
244 * @param qlm QLM to shift value into
245 * @param bits Number of bits to shift in (1-32).
246 * @param data Data to shift in. Bit 0 enters the chain first, followed by
249 * @return The low order bits of the JTAG chain that shifted out of the
252 extern uint32_t cvmx_helper_qlm_jtag_shift(int qlm, int bits, uint32_t data);
255 * Shift long sequences of zeros into the QLM JTAG chain. It is
256 * common to need to shift more than 32 bits of zeros into the
257 * chain. This function is a convience wrapper around
258 * cvmx_helper_qlm_jtag_shift() to shift more than 32 bits of
261 * @param qlm QLM to shift zeros into
264 extern void cvmx_helper_qlm_jtag_shift_zeros(int qlm, int bits);
267 * Program the QLM JTAG chain into all lanes of the QLM. You must
268 * have already shifted in 268*4, or 1072 bits into the JTAG
269 * chain. Updating invalid values can possibly cause chip damage.
271 * @param qlm QLM to program
273 extern void cvmx_helper_qlm_jtag_update(int qlm);
275 #endif /* __CVMX_HELPER_H__ */