cvmx-ipd.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. * Interface to the hardware Input Packet Data unit.
  30. */
  31. #ifndef __CVMX_IPD_H__
  32. #define __CVMX_IPD_H__
  33. #include <asm/octeon/octeon-feature.h>
  34. #include <asm/octeon/cvmx-ipd-defs.h>
  35. enum cvmx_ipd_mode {
  36. CVMX_IPD_OPC_MODE_STT = 0LL, /* All blocks DRAM, not cached in L2 */
  37. CVMX_IPD_OPC_MODE_STF = 1LL, /* All blocks into L2 */
  38. CVMX_IPD_OPC_MODE_STF1_STT = 2LL, /* 1st block L2, rest DRAM */
  39. CVMX_IPD_OPC_MODE_STF2_STT = 3LL /* 1st, 2nd blocks L2, rest DRAM */
  40. };
  41. #ifndef CVMX_ENABLE_LEN_M8_FIX
  42. #define CVMX_ENABLE_LEN_M8_FIX 0
  43. #endif
  44. /* CSR typedefs have been moved to cvmx-csr-*.h */
  45. typedef union cvmx_ipd_1st_mbuff_skip cvmx_ipd_mbuff_first_skip_t;
  46. typedef union cvmx_ipd_1st_next_ptr_back cvmx_ipd_first_next_ptr_back_t;
  47. typedef cvmx_ipd_mbuff_first_skip_t cvmx_ipd_mbuff_not_first_skip_t;
  48. typedef cvmx_ipd_first_next_ptr_back_t cvmx_ipd_second_next_ptr_back_t;
  49. /**
  50. * Configure IPD
  51. *
  52. * @mbuff_size: Packets buffer size in 8 byte words
  53. * @first_mbuff_skip:
  54. * Number of 8 byte words to skip in the first buffer
  55. * @not_first_mbuff_skip:
  56. * Number of 8 byte words to skip in each following buffer
  57. * @first_back: Must be same as first_mbuff_skip / 128
  58. * @second_back:
  59. * Must be same as not_first_mbuff_skip / 128
  60. * @wqe_fpa_pool:
  61. * FPA pool to get work entries from
  62. * @cache_mode:
  63. * @back_pres_enable_flag:
  64. * Enable or disable port back pressure
  65. */
  66. static inline void cvmx_ipd_config(uint64_t mbuff_size,
  67. uint64_t first_mbuff_skip,
  68. uint64_t not_first_mbuff_skip,
  69. uint64_t first_back,
  70. uint64_t second_back,
  71. uint64_t wqe_fpa_pool,
  72. enum cvmx_ipd_mode cache_mode,
  73. uint64_t back_pres_enable_flag)
  74. {
  75. cvmx_ipd_mbuff_first_skip_t first_skip;
  76. cvmx_ipd_mbuff_not_first_skip_t not_first_skip;
  77. union cvmx_ipd_packet_mbuff_size size;
  78. cvmx_ipd_first_next_ptr_back_t first_back_struct;
  79. cvmx_ipd_second_next_ptr_back_t second_back_struct;
  80. union cvmx_ipd_wqe_fpa_queue wqe_pool;
  81. union cvmx_ipd_ctl_status ipd_ctl_reg;
  82. first_skip.u64 = 0;
  83. first_skip.s.skip_sz = first_mbuff_skip;
  84. cvmx_write_csr(CVMX_IPD_1ST_MBUFF_SKIP, first_skip.u64);
  85. not_first_skip.u64 = 0;
  86. not_first_skip.s.skip_sz = not_first_mbuff_skip;
  87. cvmx_write_csr(CVMX_IPD_NOT_1ST_MBUFF_SKIP, not_first_skip.u64);
  88. size.u64 = 0;
  89. size.s.mb_size = mbuff_size;
  90. cvmx_write_csr(CVMX_IPD_PACKET_MBUFF_SIZE, size.u64);
  91. first_back_struct.u64 = 0;
  92. first_back_struct.s.back = first_back;
  93. cvmx_write_csr(CVMX_IPD_1st_NEXT_PTR_BACK, first_back_struct.u64);
  94. second_back_struct.u64 = 0;
  95. second_back_struct.s.back = second_back;
  96. cvmx_write_csr(CVMX_IPD_2nd_NEXT_PTR_BACK, second_back_struct.u64);
  97. wqe_pool.u64 = 0;
  98. wqe_pool.s.wqe_pool = wqe_fpa_pool;
  99. cvmx_write_csr(CVMX_IPD_WQE_FPA_QUEUE, wqe_pool.u64);
  100. ipd_ctl_reg.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS);
  101. ipd_ctl_reg.s.opc_mode = cache_mode;
  102. ipd_ctl_reg.s.pbp_en = back_pres_enable_flag;
  103. cvmx_write_csr(CVMX_IPD_CTL_STATUS, ipd_ctl_reg.u64);
  104. /* Note: the example RED code that used to be here has been moved to
  105. cvmx_helper_setup_red */
  106. }
  107. /**
  108. * Enable IPD
  109. */
  110. static inline void cvmx_ipd_enable(void)
  111. {
  112. union cvmx_ipd_ctl_status ipd_reg;
  113. ipd_reg.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS);
  114. if (ipd_reg.s.ipd_en) {
  115. cvmx_dprintf
  116. ("Warning: Enabling IPD when IPD already enabled.\n");
  117. }
  118. ipd_reg.s.ipd_en = 1;
  119. #if CVMX_ENABLE_LEN_M8_FIX
  120. if (!OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
  121. ipd_reg.s.len_m8 = TRUE;
  122. #endif
  123. cvmx_write_csr(CVMX_IPD_CTL_STATUS, ipd_reg.u64);
  124. }
  125. /**
  126. * Disable IPD
  127. */
  128. static inline void cvmx_ipd_disable(void)
  129. {
  130. union cvmx_ipd_ctl_status ipd_reg;
  131. ipd_reg.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS);
  132. ipd_reg.s.ipd_en = 0;
  133. cvmx_write_csr(CVMX_IPD_CTL_STATUS, ipd_reg.u64);
  134. }
  135. /**
  136. * Supportive function for cvmx_fpa_shutdown_pool.
  137. */
  138. static inline void cvmx_ipd_free_ptr(void)
  139. {
  140. /* Only CN38XXp{1,2} cannot read pointer out of the IPD */
  141. if (!OCTEON_IS_MODEL(OCTEON_CN38XX_PASS1)
  142. && !OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2)) {
  143. int no_wptr = 0;
  144. union cvmx_ipd_ptr_count ipd_ptr_count;
  145. ipd_ptr_count.u64 = cvmx_read_csr(CVMX_IPD_PTR_COUNT);
  146. /* Handle Work Queue Entry in cn56xx and cn52xx */
  147. if (octeon_has_feature(OCTEON_FEATURE_NO_WPTR)) {
  148. union cvmx_ipd_ctl_status ipd_ctl_status;
  149. ipd_ctl_status.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS);
  150. if (ipd_ctl_status.s.no_wptr)
  151. no_wptr = 1;
  152. }
  153. /* Free the prefetched WQE */
  154. if (ipd_ptr_count.s.wqev_cnt) {
  155. union cvmx_ipd_wqe_ptr_valid ipd_wqe_ptr_valid;
  156. ipd_wqe_ptr_valid.u64 =
  157. cvmx_read_csr(CVMX_IPD_WQE_PTR_VALID);
  158. if (no_wptr)
  159. cvmx_fpa_free(cvmx_phys_to_ptr
  160. ((uint64_t) ipd_wqe_ptr_valid.s.
  161. ptr << 7), CVMX_FPA_PACKET_POOL,
  162. 0);
  163. else
  164. cvmx_fpa_free(cvmx_phys_to_ptr
  165. ((uint64_t) ipd_wqe_ptr_valid.s.
  166. ptr << 7), CVMX_FPA_WQE_POOL, 0);
  167. }
  168. /* Free all WQE in the fifo */
  169. if (ipd_ptr_count.s.wqe_pcnt) {
  170. int i;
  171. union cvmx_ipd_pwp_ptr_fifo_ctl ipd_pwp_ptr_fifo_ctl;
  172. ipd_pwp_ptr_fifo_ctl.u64 =
  173. cvmx_read_csr(CVMX_IPD_PWP_PTR_FIFO_CTL);
  174. for (i = 0; i < ipd_ptr_count.s.wqe_pcnt; i++) {
  175. ipd_pwp_ptr_fifo_ctl.s.cena = 0;
  176. ipd_pwp_ptr_fifo_ctl.s.raddr =
  177. ipd_pwp_ptr_fifo_ctl.s.max_cnts +
  178. (ipd_pwp_ptr_fifo_ctl.s.wraddr +
  179. i) % ipd_pwp_ptr_fifo_ctl.s.max_cnts;
  180. cvmx_write_csr(CVMX_IPD_PWP_PTR_FIFO_CTL,
  181. ipd_pwp_ptr_fifo_ctl.u64);
  182. ipd_pwp_ptr_fifo_ctl.u64 =
  183. cvmx_read_csr(CVMX_IPD_PWP_PTR_FIFO_CTL);
  184. if (no_wptr)
  185. cvmx_fpa_free(cvmx_phys_to_ptr
  186. ((uint64_t)
  187. ipd_pwp_ptr_fifo_ctl.s.
  188. ptr << 7),
  189. CVMX_FPA_PACKET_POOL, 0);
  190. else
  191. cvmx_fpa_free(cvmx_phys_to_ptr
  192. ((uint64_t)
  193. ipd_pwp_ptr_fifo_ctl.s.
  194. ptr << 7),
  195. CVMX_FPA_WQE_POOL, 0);
  196. }
  197. ipd_pwp_ptr_fifo_ctl.s.cena = 1;
  198. cvmx_write_csr(CVMX_IPD_PWP_PTR_FIFO_CTL,
  199. ipd_pwp_ptr_fifo_ctl.u64);
  200. }
  201. /* Free the prefetched packet */
  202. if (ipd_ptr_count.s.pktv_cnt) {
  203. union cvmx_ipd_pkt_ptr_valid ipd_pkt_ptr_valid;
  204. ipd_pkt_ptr_valid.u64 =
  205. cvmx_read_csr(CVMX_IPD_PKT_PTR_VALID);
  206. cvmx_fpa_free(cvmx_phys_to_ptr
  207. (ipd_pkt_ptr_valid.s.ptr << 7),
  208. CVMX_FPA_PACKET_POOL, 0);
  209. }
  210. /* Free the per port prefetched packets */
  211. if (1) {
  212. int i;
  213. union cvmx_ipd_prc_port_ptr_fifo_ctl
  214. ipd_prc_port_ptr_fifo_ctl;
  215. ipd_prc_port_ptr_fifo_ctl.u64 =
  216. cvmx_read_csr(CVMX_IPD_PRC_PORT_PTR_FIFO_CTL);
  217. for (i = 0; i < ipd_prc_port_ptr_fifo_ctl.s.max_pkt;
  218. i++) {
  219. ipd_prc_port_ptr_fifo_ctl.s.cena = 0;
  220. ipd_prc_port_ptr_fifo_ctl.s.raddr =
  221. i % ipd_prc_port_ptr_fifo_ctl.s.max_pkt;
  222. cvmx_write_csr(CVMX_IPD_PRC_PORT_PTR_FIFO_CTL,
  223. ipd_prc_port_ptr_fifo_ctl.u64);
  224. ipd_prc_port_ptr_fifo_ctl.u64 =
  225. cvmx_read_csr
  226. (CVMX_IPD_PRC_PORT_PTR_FIFO_CTL);
  227. cvmx_fpa_free(cvmx_phys_to_ptr
  228. ((uint64_t)
  229. ipd_prc_port_ptr_fifo_ctl.s.
  230. ptr << 7), CVMX_FPA_PACKET_POOL,
  231. 0);
  232. }
  233. ipd_prc_port_ptr_fifo_ctl.s.cena = 1;
  234. cvmx_write_csr(CVMX_IPD_PRC_PORT_PTR_FIFO_CTL,
  235. ipd_prc_port_ptr_fifo_ctl.u64);
  236. }
  237. /* Free all packets in the holding fifo */
  238. if (ipd_ptr_count.s.pfif_cnt) {
  239. int i;
  240. union cvmx_ipd_prc_hold_ptr_fifo_ctl
  241. ipd_prc_hold_ptr_fifo_ctl;
  242. ipd_prc_hold_ptr_fifo_ctl.u64 =
  243. cvmx_read_csr(CVMX_IPD_PRC_HOLD_PTR_FIFO_CTL);
  244. for (i = 0; i < ipd_ptr_count.s.pfif_cnt; i++) {
  245. ipd_prc_hold_ptr_fifo_ctl.s.cena = 0;
  246. ipd_prc_hold_ptr_fifo_ctl.s.raddr =
  247. (ipd_prc_hold_ptr_fifo_ctl.s.praddr +
  248. i) % ipd_prc_hold_ptr_fifo_ctl.s.max_pkt;
  249. cvmx_write_csr(CVMX_IPD_PRC_HOLD_PTR_FIFO_CTL,
  250. ipd_prc_hold_ptr_fifo_ctl.u64);
  251. ipd_prc_hold_ptr_fifo_ctl.u64 =
  252. cvmx_read_csr
  253. (CVMX_IPD_PRC_HOLD_PTR_FIFO_CTL);
  254. cvmx_fpa_free(cvmx_phys_to_ptr
  255. ((uint64_t)
  256. ipd_prc_hold_ptr_fifo_ctl.s.
  257. ptr << 7), CVMX_FPA_PACKET_POOL,
  258. 0);
  259. }
  260. ipd_prc_hold_ptr_fifo_ctl.s.cena = 1;
  261. cvmx_write_csr(CVMX_IPD_PRC_HOLD_PTR_FIFO_CTL,
  262. ipd_prc_hold_ptr_fifo_ctl.u64);
  263. }
  264. /* Free all packets in the fifo */
  265. if (ipd_ptr_count.s.pkt_pcnt) {
  266. int i;
  267. union cvmx_ipd_pwp_ptr_fifo_ctl ipd_pwp_ptr_fifo_ctl;
  268. ipd_pwp_ptr_fifo_ctl.u64 =
  269. cvmx_read_csr(CVMX_IPD_PWP_PTR_FIFO_CTL);
  270. for (i = 0; i < ipd_ptr_count.s.pkt_pcnt; i++) {
  271. ipd_pwp_ptr_fifo_ctl.s.cena = 0;
  272. ipd_pwp_ptr_fifo_ctl.s.raddr =
  273. (ipd_pwp_ptr_fifo_ctl.s.praddr +
  274. i) % ipd_pwp_ptr_fifo_ctl.s.max_cnts;
  275. cvmx_write_csr(CVMX_IPD_PWP_PTR_FIFO_CTL,
  276. ipd_pwp_ptr_fifo_ctl.u64);
  277. ipd_pwp_ptr_fifo_ctl.u64 =
  278. cvmx_read_csr(CVMX_IPD_PWP_PTR_FIFO_CTL);
  279. cvmx_fpa_free(cvmx_phys_to_ptr
  280. ((uint64_t) ipd_pwp_ptr_fifo_ctl.
  281. s.ptr << 7),
  282. CVMX_FPA_PACKET_POOL, 0);
  283. }
  284. ipd_pwp_ptr_fifo_ctl.s.cena = 1;
  285. cvmx_write_csr(CVMX_IPD_PWP_PTR_FIFO_CTL,
  286. ipd_pwp_ptr_fifo_ctl.u64);
  287. }
  288. /* Reset the IPD to get all buffers out of it */
  289. {
  290. union cvmx_ipd_ctl_status ipd_ctl_status;
  291. ipd_ctl_status.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS);
  292. ipd_ctl_status.s.reset = 1;
  293. cvmx_write_csr(CVMX_IPD_CTL_STATUS, ipd_ctl_status.u64);
  294. }
  295. /* Reset the PIP */
  296. {
  297. union cvmx_pip_sft_rst pip_sft_rst;
  298. pip_sft_rst.u64 = cvmx_read_csr(CVMX_PIP_SFT_RST);
  299. pip_sft_rst.s.rst = 1;
  300. cvmx_write_csr(CVMX_PIP_SFT_RST, pip_sft_rst.u64);
  301. }
  302. }
  303. }
  304. #endif /* __CVMX_IPD_H__ */