1*af866496SDavid Daney /***********************license start*************** 2*af866496SDavid Daney * Author: Cavium Networks 3*af866496SDavid Daney * 4*af866496SDavid Daney * Contact: support@caviumnetworks.com 5*af866496SDavid Daney * This file is part of the OCTEON SDK 6*af866496SDavid Daney * 7*af866496SDavid Daney * Copyright (c) 2003-2008 Cavium Networks 8*af866496SDavid Daney * 9*af866496SDavid Daney * This file is free software; you can redistribute it and/or modify 10*af866496SDavid Daney * it under the terms of the GNU General Public License, Version 2, as 11*af866496SDavid Daney * published by the Free Software Foundation. 12*af866496SDavid Daney * 13*af866496SDavid Daney * This file is distributed in the hope that it will be useful, but 14*af866496SDavid Daney * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 15*af866496SDavid Daney * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 16*af866496SDavid Daney * NONINFRINGEMENT. See the GNU General Public License for more 17*af866496SDavid Daney * details. 18*af866496SDavid Daney * 19*af866496SDavid Daney * You should have received a copy of the GNU General Public License 20*af866496SDavid Daney * along with this file; if not, write to the Free Software 21*af866496SDavid Daney * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22*af866496SDavid Daney * or visit http://www.gnu.org/licenses/. 23*af866496SDavid Daney * 24*af866496SDavid Daney * This file may also be available under a different license from Cavium. 25*af866496SDavid Daney * Contact Cavium Networks for more information 26*af866496SDavid Daney ***********************license end**************************************/ 27*af866496SDavid Daney 28*af866496SDavid Daney /* 29*af866496SDavid Daney * 30*af866496SDavid Daney * Small helper utilities. 31*af866496SDavid Daney * 32*af866496SDavid Daney */ 33*af866496SDavid Daney 34*af866496SDavid Daney #ifndef __CVMX_HELPER_UTIL_H__ 35*af866496SDavid Daney #define __CVMX_HELPER_UTIL_H__ 36*af866496SDavid Daney 37*af866496SDavid Daney /** 38*af866496SDavid Daney * Convert a interface mode into a human readable string 39*af866496SDavid Daney * 40*af866496SDavid Daney * @mode: Mode to convert 41*af866496SDavid Daney * 42*af866496SDavid Daney * Returns String 43*af866496SDavid Daney */ 44*af866496SDavid Daney extern const char 45*af866496SDavid Daney *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode); 46*af866496SDavid Daney 47*af866496SDavid Daney /** 48*af866496SDavid Daney * Debug routine to dump the packet structure to the console 49*af866496SDavid Daney * 50*af866496SDavid Daney * @work: Work queue entry containing the packet to dump 51*af866496SDavid Daney * Returns 52*af866496SDavid Daney */ 53*af866496SDavid Daney extern int cvmx_helper_dump_packet(cvmx_wqe_t *work); 54*af866496SDavid Daney 55*af866496SDavid Daney /** 56*af866496SDavid Daney * Setup Random Early Drop on a specific input queue 57*af866496SDavid Daney * 58*af866496SDavid Daney * @queue: Input queue to setup RED on (0-7) 59*af866496SDavid Daney * @pass_thresh: 60*af866496SDavid Daney * Packets will begin slowly dropping when there are less than 61*af866496SDavid Daney * this many packet buffers free in FPA 0. 62*af866496SDavid Daney * @drop_thresh: 63*af866496SDavid Daney * All incomming packets will be dropped when there are less 64*af866496SDavid Daney * than this many free packet buffers in FPA 0. 65*af866496SDavid Daney * Returns Zero on success. Negative on failure 66*af866496SDavid Daney */ 67*af866496SDavid Daney extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh, 68*af866496SDavid Daney int drop_thresh); 69*af866496SDavid Daney 70*af866496SDavid Daney /** 71*af866496SDavid Daney * Setup Random Early Drop to automatically begin dropping packets. 72*af866496SDavid Daney * 73*af866496SDavid Daney * @pass_thresh: 74*af866496SDavid Daney * Packets will begin slowly dropping when there are less than 75*af866496SDavid Daney * this many packet buffers free in FPA 0. 76*af866496SDavid Daney * @drop_thresh: 77*af866496SDavid Daney * All incomming packets will be dropped when there are less 78*af866496SDavid Daney * than this many free packet buffers in FPA 0. 79*af866496SDavid Daney * Returns Zero on success. Negative on failure 80*af866496SDavid Daney */ 81*af866496SDavid Daney extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh); 82*af866496SDavid Daney 83*af866496SDavid Daney /** 84*af866496SDavid Daney * Get the version of the CVMX libraries. 85*af866496SDavid Daney * 86*af866496SDavid Daney * Returns Version string. Note this buffer is allocated statically 87*af866496SDavid Daney * and will be shared by all callers. 88*af866496SDavid Daney */ 89*af866496SDavid Daney extern const char *cvmx_helper_get_version(void); 90*af866496SDavid Daney 91*af866496SDavid Daney /** 92*af866496SDavid Daney * Setup the common GMX settings that determine the number of 93*af866496SDavid Daney * ports. These setting apply to almost all configurations of all 94*af866496SDavid Daney * chips. 95*af866496SDavid Daney * 96*af866496SDavid Daney * @interface: Interface to configure 97*af866496SDavid Daney * @num_ports: Number of ports on the interface 98*af866496SDavid Daney * 99*af866496SDavid Daney * Returns Zero on success, negative on failure 100*af866496SDavid Daney */ 101*af866496SDavid Daney extern int __cvmx_helper_setup_gmx(int interface, int num_ports); 102*af866496SDavid Daney 103*af866496SDavid Daney /** 104*af866496SDavid Daney * Returns the IPD/PKO port number for a port on the given 105*af866496SDavid Daney * interface. 106*af866496SDavid Daney * 107*af866496SDavid Daney * @interface: Interface to use 108*af866496SDavid Daney * @port: Port on the interface 109*af866496SDavid Daney * 110*af866496SDavid Daney * Returns IPD/PKO port number 111*af866496SDavid Daney */ 112*af866496SDavid Daney extern int cvmx_helper_get_ipd_port(int interface, int port); 113*af866496SDavid Daney 114*af866496SDavid Daney /** 115*af866496SDavid Daney * Returns the IPD/PKO port number for the first port on the given 116*af866496SDavid Daney * interface. 117*af866496SDavid Daney * 118*af866496SDavid Daney * @interface: Interface to use 119*af866496SDavid Daney * 120*af866496SDavid Daney * Returns IPD/PKO port number 121*af866496SDavid Daney */ 122*af866496SDavid Daney static inline int cvmx_helper_get_first_ipd_port(int interface) 123*af866496SDavid Daney { 124*af866496SDavid Daney return cvmx_helper_get_ipd_port(interface, 0); 125*af866496SDavid Daney } 126*af866496SDavid Daney 127*af866496SDavid Daney /** 128*af866496SDavid Daney * Returns the IPD/PKO port number for the last port on the given 129*af866496SDavid Daney * interface. 130*af866496SDavid Daney * 131*af866496SDavid Daney * @interface: Interface to use 132*af866496SDavid Daney * 133*af866496SDavid Daney * Returns IPD/PKO port number 134*af866496SDavid Daney */ 135*af866496SDavid Daney static inline int cvmx_helper_get_last_ipd_port(int interface) 136*af866496SDavid Daney { 137*af866496SDavid Daney extern int cvmx_helper_ports_on_interface(int interface); 138*af866496SDavid Daney 139*af866496SDavid Daney return cvmx_helper_get_first_ipd_port(interface) + 140*af866496SDavid Daney cvmx_helper_ports_on_interface(interface) - 1; 141*af866496SDavid Daney } 142*af866496SDavid Daney 143*af866496SDavid Daney /** 144*af866496SDavid Daney * Free the packet buffers contained in a work queue entry. 145*af866496SDavid Daney * The work queue entry is not freed. 146*af866496SDavid Daney * 147*af866496SDavid Daney * @work: Work queue entry with packet to free 148*af866496SDavid Daney */ 149*af866496SDavid Daney static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work) 150*af866496SDavid Daney { 151*af866496SDavid Daney uint64_t number_buffers; 152*af866496SDavid Daney union cvmx_buf_ptr buffer_ptr; 153*af866496SDavid Daney union cvmx_buf_ptr next_buffer_ptr; 154*af866496SDavid Daney uint64_t start_of_buffer; 155*af866496SDavid Daney 156*af866496SDavid Daney number_buffers = work->word2.s.bufs; 157*af866496SDavid Daney if (number_buffers == 0) 158*af866496SDavid Daney return; 159*af866496SDavid Daney buffer_ptr = work->packet_ptr; 160*af866496SDavid Daney 161*af866496SDavid Daney /* 162*af866496SDavid Daney * Since the number of buffers is not zero, we know this is 163*af866496SDavid Daney * not a dynamic short packet. We need to check if it is a 164*af866496SDavid Daney * packet received with IPD_CTL_STATUS[NO_WPTR]. If this is 165*af866496SDavid Daney * true, we need to free all buffers except for the first 166*af866496SDavid Daney * one. The caller doesn't expect their WQE pointer to be 167*af866496SDavid Daney * freed 168*af866496SDavid Daney */ 169*af866496SDavid Daney start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7; 170*af866496SDavid Daney if (cvmx_ptr_to_phys(work) == start_of_buffer) { 171*af866496SDavid Daney next_buffer_ptr = 172*af866496SDavid Daney *(union cvmx_buf_ptr *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8); 173*af866496SDavid Daney buffer_ptr = next_buffer_ptr; 174*af866496SDavid Daney number_buffers--; 175*af866496SDavid Daney } 176*af866496SDavid Daney 177*af866496SDavid Daney while (number_buffers--) { 178*af866496SDavid Daney /* 179*af866496SDavid Daney * Remember the back pointer is in cache lines, not 180*af866496SDavid Daney * 64bit words 181*af866496SDavid Daney */ 182*af866496SDavid Daney start_of_buffer = 183*af866496SDavid Daney ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7; 184*af866496SDavid Daney /* 185*af866496SDavid Daney * Read pointer to next buffer before we free the 186*af866496SDavid Daney * current buffer. 187*af866496SDavid Daney */ 188*af866496SDavid Daney next_buffer_ptr = 189*af866496SDavid Daney *(union cvmx_buf_ptr *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8); 190*af866496SDavid Daney cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer), 191*af866496SDavid Daney buffer_ptr.s.pool, 0); 192*af866496SDavid Daney buffer_ptr = next_buffer_ptr; 193*af866496SDavid Daney } 194*af866496SDavid Daney } 195*af866496SDavid Daney 196*af866496SDavid Daney /** 197*af866496SDavid Daney * Returns the interface number for an IPD/PKO port number. 198*af866496SDavid Daney * 199*af866496SDavid Daney * @ipd_port: IPD/PKO port number 200*af866496SDavid Daney * 201*af866496SDavid Daney * Returns Interface number 202*af866496SDavid Daney */ 203*af866496SDavid Daney extern int cvmx_helper_get_interface_num(int ipd_port); 204*af866496SDavid Daney 205*af866496SDavid Daney /** 206*af866496SDavid Daney * Returns the interface index number for an IPD/PKO port 207*af866496SDavid Daney * number. 208*af866496SDavid Daney * 209*af866496SDavid Daney * @ipd_port: IPD/PKO port number 210*af866496SDavid Daney * 211*af866496SDavid Daney * Returns Interface index number 212*af866496SDavid Daney */ 213*af866496SDavid Daney extern int cvmx_helper_get_interface_index_num(int ipd_port); 214*af866496SDavid Daney 215*af866496SDavid Daney #endif /* __CVMX_HELPER_H__ */ 216