cvmx-ipd.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Marvell International Ltd.
  4. *
  5. * Interface to the hardware Input Packet Data unit.
  6. */
  7. #ifndef __CVMX_IPD_H__
  8. #define __CVMX_IPD_H__
  9. #include "cvmx-pki.h"
  10. /* CSR typedefs have been moved to cvmx-ipd-defs.h */
  11. typedef cvmx_ipd_1st_mbuff_skip_t cvmx_ipd_mbuff_not_first_skip_t;
  12. typedef cvmx_ipd_1st_next_ptr_back_t cvmx_ipd_second_next_ptr_back_t;
  13. typedef struct cvmx_ipd_tag_fields {
  14. u64 ipv6_src_ip : 1;
  15. u64 ipv6_dst_ip : 1;
  16. u64 ipv6_src_port : 1;
  17. u64 ipv6_dst_port : 1;
  18. u64 ipv6_next_header : 1;
  19. u64 ipv4_src_ip : 1;
  20. u64 ipv4_dst_ip : 1;
  21. u64 ipv4_src_port : 1;
  22. u64 ipv4_dst_port : 1;
  23. u64 ipv4_protocol : 1;
  24. u64 input_port : 1;
  25. } cvmx_ipd_tag_fields_t;
  26. typedef struct cvmx_pip_port_config {
  27. u64 parse_mode;
  28. u64 tag_type;
  29. u64 tag_mode;
  30. cvmx_ipd_tag_fields_t tag_fields;
  31. } cvmx_pip_port_config_t;
  32. typedef struct cvmx_ipd_config_struct {
  33. u64 first_mbuf_skip;
  34. u64 not_first_mbuf_skip;
  35. u64 ipd_enable;
  36. u64 enable_len_M8_fix;
  37. u64 cache_mode;
  38. cvmx_fpa_pool_config_t packet_pool;
  39. cvmx_fpa_pool_config_t wqe_pool;
  40. cvmx_pip_port_config_t port_config;
  41. } cvmx_ipd_config_t;
  42. extern cvmx_ipd_config_t cvmx_ipd_cfg;
  43. /**
  44. * Gets the fpa pool number of packet pool
  45. */
  46. static inline s64 cvmx_fpa_get_packet_pool(void)
  47. {
  48. return (cvmx_ipd_cfg.packet_pool.pool_num);
  49. }
  50. /**
  51. * Gets the buffer size of packet pool buffer
  52. */
  53. static inline u64 cvmx_fpa_get_packet_pool_block_size(void)
  54. {
  55. return (cvmx_ipd_cfg.packet_pool.buffer_size);
  56. }
  57. /**
  58. * Gets the buffer count of packet pool
  59. */
  60. static inline u64 cvmx_fpa_get_packet_pool_buffer_count(void)
  61. {
  62. return (cvmx_ipd_cfg.packet_pool.buffer_count);
  63. }
  64. /**
  65. * Gets the fpa pool number of wqe pool
  66. */
  67. static inline s64 cvmx_fpa_get_wqe_pool(void)
  68. {
  69. return (cvmx_ipd_cfg.wqe_pool.pool_num);
  70. }
  71. /**
  72. * Gets the buffer size of wqe pool buffer
  73. */
  74. static inline u64 cvmx_fpa_get_wqe_pool_block_size(void)
  75. {
  76. return (cvmx_ipd_cfg.wqe_pool.buffer_size);
  77. }
  78. /**
  79. * Gets the buffer count of wqe pool
  80. */
  81. static inline u64 cvmx_fpa_get_wqe_pool_buffer_count(void)
  82. {
  83. return (cvmx_ipd_cfg.wqe_pool.buffer_count);
  84. }
  85. /**
  86. * Sets the ipd related configuration in internal structure which is then used
  87. * for seting IPD hardware block
  88. */
  89. int cvmx_ipd_set_config(cvmx_ipd_config_t ipd_config);
  90. /**
  91. * Gets the ipd related configuration from internal structure.
  92. */
  93. void cvmx_ipd_get_config(cvmx_ipd_config_t *ipd_config);
  94. /**
  95. * Sets the internal FPA pool data structure for packet buffer pool.
  96. * @param pool fpa pool number yo use
  97. * @param buffer_size buffer size of pool
  98. * @param buffer_count number of buufers to allocate to pool
  99. */
  100. void cvmx_ipd_set_packet_pool_config(s64 pool, u64 buffer_size, u64 buffer_count);
  101. /**
  102. * Sets the internal FPA pool data structure for wqe pool.
  103. * @param pool fpa pool number yo use
  104. * @param buffer_size buffer size of pool
  105. * @param buffer_count number of buufers to allocate to pool
  106. */
  107. void cvmx_ipd_set_wqe_pool_config(s64 pool, u64 buffer_size, u64 buffer_count);
  108. /**
  109. * Gets the FPA packet buffer pool parameters.
  110. */
  111. static inline void cvmx_fpa_get_packet_pool_config(s64 *pool, u64 *buffer_size, u64 *buffer_count)
  112. {
  113. if (pool)
  114. *pool = cvmx_ipd_cfg.packet_pool.pool_num;
  115. if (buffer_size)
  116. *buffer_size = cvmx_ipd_cfg.packet_pool.buffer_size;
  117. if (buffer_count)
  118. *buffer_count = cvmx_ipd_cfg.packet_pool.buffer_count;
  119. }
  120. /**
  121. * Sets the FPA packet buffer pool parameters.
  122. */
  123. static inline void cvmx_fpa_set_packet_pool_config(s64 pool, u64 buffer_size, u64 buffer_count)
  124. {
  125. cvmx_ipd_set_packet_pool_config(pool, buffer_size, buffer_count);
  126. }
  127. /**
  128. * Gets the FPA WQE pool parameters.
  129. */
  130. static inline void cvmx_fpa_get_wqe_pool_config(s64 *pool, u64 *buffer_size, u64 *buffer_count)
  131. {
  132. if (pool)
  133. *pool = cvmx_ipd_cfg.wqe_pool.pool_num;
  134. if (buffer_size)
  135. *buffer_size = cvmx_ipd_cfg.wqe_pool.buffer_size;
  136. if (buffer_count)
  137. *buffer_count = cvmx_ipd_cfg.wqe_pool.buffer_count;
  138. }
  139. /**
  140. * Sets the FPA WQE pool parameters.
  141. */
  142. static inline void cvmx_fpa_set_wqe_pool_config(s64 pool, u64 buffer_size, u64 buffer_count)
  143. {
  144. cvmx_ipd_set_wqe_pool_config(pool, buffer_size, buffer_count);
  145. }
  146. /**
  147. * Configure IPD
  148. *
  149. * @param mbuff_size Packets buffer size in 8 byte words
  150. * @param first_mbuff_skip
  151. * Number of 8 byte words to skip in the first buffer
  152. * @param not_first_mbuff_skip
  153. * Number of 8 byte words to skip in each following buffer
  154. * @param first_back Must be same as first_mbuff_skip / 128
  155. * @param second_back
  156. * Must be same as not_first_mbuff_skip / 128
  157. * @param wqe_fpa_pool
  158. * FPA pool to get work entries from
  159. * @param cache_mode
  160. * @param back_pres_enable_flag
  161. * Enable or disable port back pressure at a global level.
  162. * This should always be 1 as more accurate control can be
  163. * found in IPD_PORTX_BP_PAGE_CNT[BP_ENB].
  164. */
  165. void cvmx_ipd_config(u64 mbuff_size, u64 first_mbuff_skip, u64 not_first_mbuff_skip, u64 first_back,
  166. u64 second_back, u64 wqe_fpa_pool, cvmx_ipd_mode_t cache_mode,
  167. u64 back_pres_enable_flag);
  168. /**
  169. * Enable IPD
  170. */
  171. void cvmx_ipd_enable(void);
  172. /**
  173. * Disable IPD
  174. */
  175. void cvmx_ipd_disable(void);
  176. void __cvmx_ipd_free_ptr(void);
  177. void cvmx_ipd_set_packet_pool_buffer_count(u64 buffer_count);
  178. void cvmx_ipd_set_wqe_pool_buffer_count(u64 buffer_count);
  179. /**
  180. * Setup Random Early Drop on a specific input queue
  181. *
  182. * @param queue Input queue to setup RED on (0-7)
  183. * @param pass_thresh
  184. * Packets will begin slowly dropping when there are less than
  185. * this many packet buffers free in FPA 0.
  186. * @param drop_thresh
  187. * All incoming packets will be dropped when there are less
  188. * than this many free packet buffers in FPA 0.
  189. * Return: Zero on success. Negative on failure
  190. */
  191. int cvmx_ipd_setup_red_queue(int queue, int pass_thresh, int drop_thresh);
  192. /**
  193. * Setup Random Early Drop to automatically begin dropping packets.
  194. *
  195. * @param pass_thresh
  196. * Packets will begin slowly dropping when there are less than
  197. * this many packet buffers free in FPA 0.
  198. * @param drop_thresh
  199. * All incoming packets will be dropped when there are less
  200. * than this many free packet buffers in FPA 0.
  201. * Return: Zero on success. Negative on failure
  202. */
  203. int cvmx_ipd_setup_red(int pass_thresh, int drop_thresh);
  204. #endif /* __CVMX_IPD_H__ */