cvmx-helper-util.h revision 210311
1/***********************license start*************** 2 * Copyright (c) 2003-2008 Cavium Networks (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 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 21 * permission. 22 * 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. 33 * 34 * 35 * For any questions regarding licensing please contact marketing@caviumnetworks.com 36 * 37 ***********************license end**************************************/ 38 39 40 41 42 43 44/** 45 * @file 46 * 47 * Small helper utilities. 48 * 49 * <hr>$Revision: 41586 $<hr> 50 */ 51 52#ifndef __CVMX_HELPER_UTIL_H__ 53#define __CVMX_HELPER_UTIL_H__ 54 55 56#ifdef CVMX_ENABLE_HELPER_FUNCTIONS 57 58/** 59 * Convert a interface mode into a human readable string 60 * 61 * @param mode Mode to convert 62 * 63 * @return String 64 */ 65extern const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode); 66 67/** 68 * Debug routine to dump the packet structure to the console 69 * 70 * @param work Work queue entry containing the packet to dump 71 * @return 72 */ 73extern int cvmx_helper_dump_packet(cvmx_wqe_t *work); 74 75/** 76 * Setup Random Early Drop on a specific input queue 77 * 78 * @param queue Input queue to setup RED on (0-7) 79 * @param pass_thresh 80 * Packets will begin slowly dropping when there are less than 81 * this many packet buffers free in FPA 0. 82 * @param drop_thresh 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 86 */ 87extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh); 88 89/** 90 * Setup Random Early Drop to automatically begin dropping packets. 91 * 92 * @param pass_thresh 93 * Packets will begin slowly dropping when there are less than 94 * this many packet buffers free in FPA 0. 95 * @param drop_thresh 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 99 */ 100extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh); 101 102 103/** 104 * Get the version of the CVMX libraries. 105 * 106 * @return Version string. Note this buffer is allocated statically 107 * and will be shared by all callers. 108 */ 109extern const char *cvmx_helper_get_version(void); 110 111 112/** 113 * @INTERNAL 114 * Setup the common GMX settings that determine the number of 115 * ports. These setting apply to almost all configurations of all 116 * chips. 117 * 118 * @param interface Interface to configure 119 * @param num_ports Number of ports on the interface 120 * 121 * @return Zero on success, negative on failure 122 */ 123extern int __cvmx_helper_setup_gmx(int interface, int num_ports); 124 125/** 126 * Returns the IPD/PKO port number for a port on the given 127 * interface. 128 * 129 * @param interface Interface to use 130 * @param port Port on the interface 131 * 132 * @return IPD/PKO port number 133 */ 134extern int cvmx_helper_get_ipd_port(int interface, int port); 135 136 137/** 138 * Returns the IPD/PKO port number for the first port on the given 139 * interface. 140 * 141 * @param interface Interface to use 142 * 143 * @return IPD/PKO port number 144 */ 145static inline int cvmx_helper_get_first_ipd_port(int interface) 146{ 147 return (cvmx_helper_get_ipd_port (interface, 0)); 148} 149 150/** 151 * Returns the IPD/PKO port number for the last port on the given 152 * interface. 153 * 154 * @param interface Interface to use 155 * 156 * @return IPD/PKO port number 157 */ 158static inline int cvmx_helper_get_last_ipd_port (int interface) 159{ 160 return (cvmx_helper_get_first_ipd_port (interface) + 161 cvmx_helper_ports_on_interface (interface) - 1); 162} 163 164 165/** 166 * Free the packet buffers contained in a work queue entry. 167 * The work queue entry is not freed. 168 * 169 * @param work Work queue entry with packet to free 170 */ 171static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work) 172{ 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; 177 178 number_buffers = work->word2.s.bufs; 179 if (number_buffers == 0) 180 return; 181 buffer_ptr = work->packet_ptr; 182 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 187 to be freed */ 188 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7; 189 if (cvmx_ptr_to_phys(work) == start_of_buffer) 190 { 191 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8); 192 buffer_ptr = next_buffer_ptr; 193 number_buffers--; 194 } 195 196 while (number_buffers--) 197 { 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; 204 } 205} 206 207#endif /* CVMX_ENABLE_HELPER_FUNCTIONS */ 208 209/** 210 * Returns the interface number for an IPD/PKO port number. 211 * 212 * @param ipd_port IPD/PKO port number 213 * 214 * @return Interface number 215 */ 216extern int cvmx_helper_get_interface_num(int ipd_port); 217 218 219/** 220 * Returns the interface index number for an IPD/PKO port 221 * number. 222 * 223 * @param ipd_port IPD/PKO port number 224 * 225 * @return Interface index number 226 */ 227extern int cvmx_helper_get_interface_index_num(int ipd_port); 228 229/** 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. 235 */ 236extern void cvmx_helper_qlm_jtag_init(void); 237 238/** 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. 243 * 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 247 * bit 1, etc. 248 * 249 * @return The low order bits of the JTAG chain that shifted out of the 250 * circle. 251 */ 252extern uint32_t cvmx_helper_qlm_jtag_shift(int qlm, int bits, uint32_t data); 253 254/** 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 259 * zeros at a time. 260 * 261 * @param qlm QLM to shift zeros into 262 * @param bits 263 */ 264extern void cvmx_helper_qlm_jtag_shift_zeros(int qlm, int bits); 265 266/** 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. 270 * 271 * @param qlm QLM to program 272 */ 273extern void cvmx_helper_qlm_jtag_update(int qlm); 274 275#endif /* __CVMX_HELPER_H__ */ 276