cvmx-helper-util.h revision 210286
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 extern int cvmx_helper_ports_on_interface (int interface); 161 162 return (cvmx_helper_get_first_ipd_port (interface) + 163 cvmx_helper_ports_on_interface (interface) - 1); 164} 165 166 167/** 168 * Free the packet buffers contained in a work queue entry. 169 * The work queue entry is not freed. 170 * 171 * @param work Work queue entry with packet to free 172 */ 173static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work) 174{ 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; 179 180 number_buffers = work->word2.s.bufs; 181 if (number_buffers == 0) 182 return; 183 buffer_ptr = work->packet_ptr; 184 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 189 to be freed */ 190 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7; 191 if (cvmx_ptr_to_phys(work) == start_of_buffer) 192 { 193 next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8); 194 buffer_ptr = next_buffer_ptr; 195 number_buffers--; 196 } 197 198 while (number_buffers--) 199 { 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; 206 } 207} 208 209#endif /* CVMX_ENABLE_HELPER_FUNCTIONS */ 210 211/** 212 * Returns the interface number for an IPD/PKO port number. 213 * 214 * @param ipd_port IPD/PKO port number 215 * 216 * @return Interface number 217 */ 218extern int cvmx_helper_get_interface_num(int ipd_port); 219 220 221/** 222 * Returns the interface index number for an IPD/PKO port 223 * number. 224 * 225 * @param ipd_port IPD/PKO port number 226 * 227 * @return Interface index number 228 */ 229extern int cvmx_helper_get_interface_index_num(int ipd_port); 230 231/** 232 * Initialize the internal QLM JTAG logic to allow programming 233 * of the JTAG chain by the cvmx_helper_qlm_jtag_*() functions. 234 * These functions should only be used at the direction of Cavium 235 * Networks. Programming incorrect values into the JTAG chain 236 * can cause chip damage. 237 */ 238extern void cvmx_helper_qlm_jtag_init(void); 239 240/** 241 * Write up to 32bits into the QLM jtag chain. Bits are shifted 242 * into the MSB and out the LSB, so you should shift in the low 243 * order bits followed by the high order bits. The JTAG chain is 244 * 4 * 268 bits long, or 1072. 245 * 246 * @param qlm QLM to shift value into 247 * @param bits Number of bits to shift in (1-32). 248 * @param data Data to shift in. Bit 0 enters the chain first, followed by 249 * bit 1, etc. 250 * 251 * @return The low order bits of the JTAG chain that shifted out of the 252 * circle. 253 */ 254extern uint32_t cvmx_helper_qlm_jtag_shift(int qlm, int bits, uint32_t data); 255 256/** 257 * Shift long sequences of zeros into the QLM JTAG chain. It is 258 * common to need to shift more than 32 bits of zeros into the 259 * chain. This function is a convience wrapper around 260 * cvmx_helper_qlm_jtag_shift() to shift more than 32 bits of 261 * zeros at a time. 262 * 263 * @param qlm QLM to shift zeros into 264 * @param bits 265 */ 266extern void cvmx_helper_qlm_jtag_shift_zeros(int qlm, int bits); 267 268/** 269 * Program the QLM JTAG chain into all lanes of the QLM. You must 270 * have already shifted in 268*4, or 1072 bits into the JTAG 271 * chain. Updating invalid values can possibly cause chip damage. 272 * 273 * @param qlm QLM to program 274 */ 275extern void cvmx_helper_qlm_jtag_update(int qlm); 276 277#endif /* __CVMX_HELPER_H__ */ 278