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 * Small helper utilities.
51 * <hr>$Revision: 70030 $<hr>
54 #ifndef __CVMX_HELPER_UTIL_H__
55 #define __CVMX_HELPER_UTIL_H__
58 #include "cvmx-mio-defs.h"
60 #ifdef CVMX_ENABLE_HELPER_FUNCTIONS
62 typedef char cvmx_pknd_t;
63 typedef char cvmx_bpid_t;
65 #define CVMX_INVALID_PKND ((cvmx_pknd_t) -1)
66 #define CVMX_INVALID_BPID ((cvmx_bpid_t) -1)
67 #define CVMX_MAX_PKND ((cvmx_pknd_t) 64)
68 #define CVMX_MAX_BPID ((cvmx_bpid_t) 64)
70 #define CVMX_HELPER_MAX_IFACE 9
73 * Convert a interface mode into a human readable string
75 * @param mode Mode to convert
79 extern const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode);
82 * Debug routine to dump the packet structure to the console
84 * @param work Work queue entry containing the packet to dump
87 extern int cvmx_helper_dump_packet(cvmx_wqe_t *work);
90 * Setup Random Early Drop on a specific input queue
92 * @param queue Input queue to setup RED on (0-7)
94 * Packets will begin slowly dropping when there are less than
95 * this many packet buffers free in FPA 0.
97 * All incomming packets will be dropped when there are less
98 * than this many free packet buffers in FPA 0.
99 * @return Zero on success. Negative on failure
101 extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh);
104 * Setup Random Early Drop to automatically begin dropping packets.
107 * Packets will begin slowly dropping when there are less than
108 * this many packet buffers free in FPA 0.
110 * All incomming packets will be dropped when there are less
111 * than this many free packet buffers in FPA 0.
112 * @return Zero on success. Negative on failure
114 extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
118 * Get the version of the CVMX libraries.
120 * @return Version string. Note this buffer is allocated statically
121 * and will be shared by all callers.
123 extern const char *cvmx_helper_get_version(void);
128 * Setup the common GMX settings that determine the number of
129 * ports. These setting apply to almost all configurations of all
132 * @param interface Interface to configure
133 * @param num_ports Number of ports on the interface
135 * @return Zero on success, negative on failure
137 extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
141 * Get the number of ipd_ports on an interface.
145 * @return the number of ipd_ports on the interface and -1 for error.
147 extern int __cvmx_helper_get_num_ipd_ports(int interface);
151 * Get the number of pko_ports on an interface.
155 * @return the number of pko_ports on the interface.
157 extern int __cvmx_helper_get_num_pko_ports(int interface);
166 * @return 0 for success and -1 for failure
168 extern int __cvmx_helper_set_link_info(int interface, int port,
169 cvmx_helper_link_info_t link_info);
177 * @return valid link_info on success or -1 on failure
179 extern cvmx_helper_link_info_t __cvmx_helper_get_link_info(int interface,
182 enum cvmx_pko_padding {
183 CVMX_PKO_PADDING_NONE = 0,
184 CVMX_PKO_PADDING_60 = 1,
191 * @param num_ipd_ports is the number of ipd_ports on the interface
192 * @param has_fcs indicates if PKO does FCS for the ports on this
193 * @param pad The padding that PKO should apply.
196 * @return 0 for success and -1 for failure
198 extern int __cvmx_helper_init_interface(int interface, int num_ipd_ports, int has_fcs, enum cvmx_pko_padding pad);
205 * @return 0 if PKO does not do FCS and 1 otherwise.
207 extern int __cvmx_helper_get_has_fcs(int interface);
210 extern enum cvmx_pko_padding __cvmx_helper_get_pko_padding(int interface);
213 * Returns the IPD port number for a port on the given
216 * @param interface Interface to use
217 * @param port Port on the interface
219 * @return IPD port number
221 extern int cvmx_helper_get_ipd_port(int interface, int port);
224 * Returns the PKO port number for a port on the given interface,
225 * This is the base pko_port for o68 and ipd_port for older models.
227 * @param interface Interface to use
228 * @param port Port on the interface
230 * @return PKO port number and -1 on error.
232 extern int cvmx_helper_get_pko_port(int interface, int port);
235 * Returns the IPD/PKO port number for the first port on the given
238 * @param interface Interface to use
240 * @return IPD/PKO port number
242 static inline int cvmx_helper_get_first_ipd_port(int interface)
244 return (cvmx_helper_get_ipd_port (interface, 0));
248 * Returns the IPD/PKO port number for the last port on the given
251 * @param interface Interface to use
253 * @return IPD/PKO port number
255 static inline int cvmx_helper_get_last_ipd_port (int interface)
257 return (cvmx_helper_get_first_ipd_port (interface) +
258 cvmx_helper_ports_on_interface (interface) - 1);
263 * Free the packet buffers contained in a work queue entry.
264 * The work queue entry is not freed.
266 * @param work Work queue entry with packet to free
268 static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work)
270 uint64_t number_buffers;
271 cvmx_buf_ptr_t buffer_ptr;
272 cvmx_buf_ptr_t next_buffer_ptr;
273 uint64_t start_of_buffer;
275 number_buffers = work->word2.s.bufs;
276 if (number_buffers == 0)
278 buffer_ptr = work->packet_ptr;
280 /* Since the number of buffers is not zero, we know this is not a dynamic
281 short packet. We need to check if it is a packet received with
282 IPD_CTL_STATUS[NO_WPTR]. If this is true, we need to free all buffers
283 except for the first one. The caller doesn't expect their WQE pointer
285 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
286 if (cvmx_ptr_to_phys(work) == start_of_buffer)
288 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
289 buffer_ptr = next_buffer_ptr;
293 while (number_buffers--)
295 /* Remember the back pointer is in cache lines, not 64bit words */
296 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
297 /* Read pointer to next buffer before we free the current buffer. */
298 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
299 cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer), buffer_ptr.s.pool, 0);
300 buffer_ptr = next_buffer_ptr;
304 #endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
307 * Returns the interface number for an IPD/PKO port number.
309 * @param ipd_port IPD/PKO port number
311 * @return Interface number
313 extern int cvmx_helper_get_interface_num(int ipd_port);
316 * Returns the interface index number for an IPD/PKO port
319 * @param ipd_port IPD/PKO port number
321 * @return Interface index number
323 extern int cvmx_helper_get_interface_index_num(int ipd_port);
326 * Get port kind for a given port in an interface.
328 * @param interface Interface
329 * @param port index of the port in the interface
331 * @return port kind on sucicess and -1 on failure
333 extern int cvmx_helper_get_pknd(int interface, int port);
336 * Get bpid for a given port in an interface.
338 * @param interface Interface
339 * @param port index of the port in the interface
341 * @return port kind on sucicess and -1 on failure
343 extern int cvmx_helper_get_bpid(int interface, int port);
347 * Internal functions.
349 extern int __cvmx_helper_post_init_interfaces(void);
350 extern void __cvmx_helper_shutdown_interfaces(void);
352 extern void cvmx_helper_show_stats(int port);
354 #endif /* __CVMX_HELPER_H__ */