cvmx-helper-util.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: [email protected]
  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. * Setup Random Early Drop to automatically begin dropping packets.
  45. *
  46. * @pass_thresh:
  47. * Packets will begin slowly dropping when there are less than
  48. * this many packet buffers free in FPA 0.
  49. * @drop_thresh:
  50. * All incoming packets will be dropped when there are less
  51. * than this many free packet buffers in FPA 0.
  52. * Returns Zero on success. Negative on failure
  53. */
  54. extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
  55. /**
  56. * Get the version of the CVMX libraries.
  57. *
  58. * Returns Version string. Note this buffer is allocated statically
  59. * and will be shared by all callers.
  60. */
  61. extern const char *cvmx_helper_get_version(void);
  62. /**
  63. * Setup the common GMX settings that determine the number of
  64. * ports. These setting apply to almost all configurations of all
  65. * chips.
  66. *
  67. * @interface: Interface to configure
  68. * @num_ports: Number of ports on the interface
  69. *
  70. * Returns Zero on success, negative on failure
  71. */
  72. extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
  73. /**
  74. * Returns the IPD/PKO port number for a port on the given
  75. * interface.
  76. *
  77. * @interface: Interface to use
  78. * @port: Port on the interface
  79. *
  80. * Returns IPD/PKO port number
  81. */
  82. extern int cvmx_helper_get_ipd_port(int interface, int port);
  83. /**
  84. * Returns the IPD/PKO port number for the first port on the given
  85. * interface.
  86. *
  87. * @interface: Interface to use
  88. *
  89. * Returns IPD/PKO port number
  90. */
  91. static inline int cvmx_helper_get_first_ipd_port(int interface)
  92. {
  93. return cvmx_helper_get_ipd_port(interface, 0);
  94. }
  95. /**
  96. * Returns the IPD/PKO port number for the last port on the given
  97. * interface.
  98. *
  99. * @interface: Interface to use
  100. *
  101. * Returns IPD/PKO port number
  102. */
  103. static inline int cvmx_helper_get_last_ipd_port(int interface)
  104. {
  105. extern int cvmx_helper_ports_on_interface(int interface);
  106. return cvmx_helper_get_first_ipd_port(interface) +
  107. cvmx_helper_ports_on_interface(interface) - 1;
  108. }
  109. /**
  110. * Free the packet buffers contained in a work queue entry.
  111. * The work queue entry is not freed.
  112. *
  113. * @work: Work queue entry with packet to free
  114. */
  115. static inline void cvmx_helper_free_packet_data(struct cvmx_wqe *work)
  116. {
  117. uint64_t number_buffers;
  118. union cvmx_buf_ptr buffer_ptr;
  119. union cvmx_buf_ptr next_buffer_ptr;
  120. uint64_t start_of_buffer;
  121. number_buffers = work->word2.s.bufs;
  122. if (number_buffers == 0)
  123. return;
  124. buffer_ptr = work->packet_ptr;
  125. /*
  126. * Since the number of buffers is not zero, we know this is
  127. * not a dynamic short packet. We need to check if it is a
  128. * packet received with IPD_CTL_STATUS[NO_WPTR]. If this is
  129. * true, we need to free all buffers except for the first
  130. * one. The caller doesn't expect their WQE pointer to be
  131. * freed
  132. */
  133. start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
  134. if (cvmx_ptr_to_phys(work) == start_of_buffer) {
  135. next_buffer_ptr =
  136. *(union cvmx_buf_ptr *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
  137. buffer_ptr = next_buffer_ptr;
  138. number_buffers--;
  139. }
  140. while (number_buffers--) {
  141. /*
  142. * Remember the back pointer is in cache lines, not
  143. * 64bit words
  144. */
  145. start_of_buffer =
  146. ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
  147. /*
  148. * Read pointer to next buffer before we free the
  149. * current buffer.
  150. */
  151. next_buffer_ptr =
  152. *(union cvmx_buf_ptr *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
  153. cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer),
  154. buffer_ptr.s.pool, 0);
  155. buffer_ptr = next_buffer_ptr;
  156. }
  157. }
  158. /**
  159. * Returns the interface number for an IPD/PKO port number.
  160. *
  161. * @ipd_port: IPD/PKO port number
  162. *
  163. * Returns Interface number
  164. */
  165. extern int cvmx_helper_get_interface_num(int ipd_port);
  166. /**
  167. * Returns the interface index number for an IPD/PKO port
  168. * number.
  169. *
  170. * @ipd_port: IPD/PKO port number
  171. *
  172. * Returns Interface index number
  173. */
  174. extern int cvmx_helper_get_interface_index_num(int ipd_port);
  175. #endif /* __CVMX_HELPER_H__ */