1 /***********************license start***************
2 * Copyright (c) 2003-2010 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 * 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 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**************************************/
49 * Small helper utilities.
51 * <hr>$Revision: 49448 $<hr>
54 #ifndef __CVMX_HELPER_UTIL_H__
55 #define __CVMX_HELPER_UTIL_H__
58 #ifdef CVMX_ENABLE_HELPER_FUNCTIONS
61 * Convert a interface mode into a human readable string
63 * @param mode Mode to convert
67 extern const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode);
70 * Debug routine to dump the packet structure to the console
72 * @param work Work queue entry containing the packet to dump
75 extern int cvmx_helper_dump_packet(cvmx_wqe_t *work);
78 * Setup Random Early Drop on a specific input queue
80 * @param queue Input queue to setup RED on (0-7)
82 * Packets will begin slowly dropping when there are less than
83 * this many packet buffers free in FPA 0.
85 * All incomming packets will be dropped when there are less
86 * than this many free packet buffers in FPA 0.
87 * @return Zero on success. Negative on failure
89 extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh);
92 * Setup Random Early Drop to automatically begin dropping packets.
95 * Packets will begin slowly dropping when there are less than
96 * this many packet buffers free in FPA 0.
98 * All incomming packets will be dropped when there are less
99 * than this many free packet buffers in FPA 0.
100 * @return Zero on success. Negative on failure
102 extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
106 * Get the version of the CVMX libraries.
108 * @return Version string. Note this buffer is allocated statically
109 * and will be shared by all callers.
111 extern const char *cvmx_helper_get_version(void);
116 * Setup the common GMX settings that determine the number of
117 * ports. These setting apply to almost all configurations of all
120 * @param interface Interface to configure
121 * @param num_ports Number of ports on the interface
123 * @return Zero on success, negative on failure
125 extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
128 * Returns the IPD/PKO port number for a port on the given
131 * @param interface Interface to use
132 * @param port Port on the interface
134 * @return IPD/PKO port number
136 extern int cvmx_helper_get_ipd_port(int interface, int port);
140 * Returns the IPD/PKO port number for the first port on the given
143 * @param interface Interface to use
145 * @return IPD/PKO port number
147 static inline int cvmx_helper_get_first_ipd_port(int interface)
149 return (cvmx_helper_get_ipd_port (interface, 0));
153 * Returns the IPD/PKO port number for the last port on the given
156 * @param interface Interface to use
158 * @return IPD/PKO port number
160 static inline int cvmx_helper_get_last_ipd_port (int interface)
162 return (cvmx_helper_get_first_ipd_port (interface) +
163 cvmx_helper_ports_on_interface (interface) - 1);
168 * Free the packet buffers contained in a work queue entry.
169 * The work queue entry is not freed.
171 * @param work Work queue entry with packet to free
173 static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work)
175 uint64_t number_buffers;
176 cvmx_buf_ptr_t buffer_ptr;
177 cvmx_buf_ptr_t next_buffer_ptr;
178 uint64_t start_of_buffer;
180 number_buffers = work->word2.s.bufs;
181 if (number_buffers == 0)
183 buffer_ptr = work->packet_ptr;
185 /* Since the number of buffers is not zero, we know this is not a dynamic
186 short packet. We need to check if it is a packet received with
187 IPD_CTL_STATUS[NO_WPTR]. If this is true, we need to free all buffers
188 except for the first one. The caller doesn't expect their WQE pointer
190 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
191 if (cvmx_ptr_to_phys(work) == start_of_buffer)
193 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
194 buffer_ptr = next_buffer_ptr;
198 while (number_buffers--)
200 /* Remember the back pointer is in cache lines, not 64bit words */
201 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
202 /* Read pointer to next buffer before we free the current buffer. */
203 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
204 cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer), buffer_ptr.s.pool, 0);
205 buffer_ptr = next_buffer_ptr;
209 #endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
212 * Returns the interface number for an IPD/PKO port number.
214 * @param ipd_port IPD/PKO port number
216 * @return Interface number
218 extern int cvmx_helper_get_interface_num(int ipd_port);
222 * Returns the interface index number for an IPD/PKO port
225 * @param ipd_port IPD/PKO port number
227 * @return Interface index number
229 extern int cvmx_helper_get_interface_index_num(int ipd_port);
231 #endif /* __CVMX_HELPER_H__ */