cvmx-ipd.h 10 KB

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