cvmx-helper-util.h 6.0 KB

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