1 /***********************license start***************
2 * Author: Cavium Networks
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
7 * Copyright (c) 2003-2008 Cavium Networks
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.
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
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/.
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26 ***********************license end**************************************/
31 * Helper functions for FPA setup.
34 #include "executive-config.h"
35 #include "cvmx-config.h"
37 #include "cvmx-bootmem.h"
39 #include "cvmx-helper-fpa.h"
42 * Allocate memory for and initialize a single FPA pool.
44 * @pool: Pool to initialize
45 * @buffer_size: Size of buffers to allocate in bytes
46 * @buffers: Number of buffers to put in the pool. Zero is allowed
47 * @name: String name of the pool for debugging purposes
48 * Returns Zero on success, non-zero on failure
50 static int __cvmx_helper_initialize_fpa_pool(int pool, uint64_t buffer_size,
51 uint64_t buffers, const char *name)
55 uint64_t align = CVMX_CACHE_LINE_SIZE;
58 * Align the allocation so that power of 2 size buffers are
61 while (align < buffer_size)
67 current_num = cvmx_read_csr(CVMX_FPA_QUEX_AVAILABLE(pool));
69 cvmx_dprintf("Fpa pool %d(%s) already has %llu buffers. "
71 pool, name, (unsigned long long)current_num);
75 memory = cvmx_bootmem_alloc(buffer_size * buffers, align);
77 cvmx_dprintf("Out of memory initializing fpa pool %d(%s).\n",
81 cvmx_fpa_setup_pool(pool, name, memory, buffer_size, buffers);
86 * Allocate memory and initialize the FPA pools using memory
87 * from cvmx-bootmem. Specifying zero for the number of
88 * buffers will cause that FPA pool to not be setup. This is
89 * useful if you aren't using some of the hardware and want
90 * to save memory. Use cvmx_helper_initialize_fpa instead of
91 * this function directly.
93 * @pip_pool: Should always be CVMX_FPA_PACKET_POOL
94 * @pip_size: Should always be CVMX_FPA_PACKET_POOL_SIZE
96 * Number of packet buffers.
97 * @wqe_pool: Should always be CVMX_FPA_WQE_POOL
98 * @wqe_size: Should always be CVMX_FPA_WQE_POOL_SIZE
100 * Number of work queue entries
101 * @pko_pool: Should always be CVMX_FPA_OUTPUT_BUFFER_POOL
102 * @pko_size: Should always be CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE
104 * PKO Command buffers. You should at minimum have two per
106 * @tim_pool: Should always be CVMX_FPA_TIMER_POOL
107 * @tim_size: Should always be CVMX_FPA_TIMER_POOL_SIZE
109 * TIM ring buffer command queues. At least two per timer bucket
111 * @dfa_pool: Should always be CVMX_FPA_DFA_POOL
112 * @dfa_size: Should always be CVMX_FPA_DFA_POOL_SIZE
114 * DFA command buffer. A relatively small (32 for example)
115 * number should work.
116 * Returns Zero on success, non-zero if out of memory
118 static int __cvmx_helper_initialize_fpa(int pip_pool, int pip_size,
119 int pip_buffers, int wqe_pool,
120 int wqe_size, int wqe_entries,
121 int pko_pool, int pko_size,
122 int pko_buffers, int tim_pool,
123 int tim_size, int tim_buffers,
124 int dfa_pool, int dfa_size,
131 if ((pip_buffers > 0) && (pip_buffers <= 64))
133 ("Warning: %d packet buffers may not be enough for hardware"
134 " prefetch. 65 or more is recommended.\n", pip_buffers);
138 __cvmx_helper_initialize_fpa_pool(pip_pool, pip_size,
147 __cvmx_helper_initialize_fpa_pool(wqe_pool, wqe_size,
149 "Work Queue Entries");
156 __cvmx_helper_initialize_fpa_pool(pko_pool, pko_size,
158 "PKO Command Buffers");
165 __cvmx_helper_initialize_fpa_pool(tim_pool, tim_size,
167 "TIM Command Buffers");
174 __cvmx_helper_initialize_fpa_pool(dfa_pool, dfa_size,
176 "DFA Command Buffers");
185 * Allocate memory and initialize the FPA pools using memory
186 * from cvmx-bootmem. Sizes of each element in the pools is
187 * controlled by the cvmx-config.h header file. Specifying
188 * zero for any parameter will cause that FPA pool to not be
189 * setup. This is useful if you aren't using some of the
190 * hardware and want to save memory.
193 * Number of packet buffers to allocate
194 * @work_queue_entries:
195 * Number of work queue entries
197 * PKO Command buffers. You should at minimum have two per
200 * TIM ring buffer command queues. At least two per timer bucket
203 * DFA command buffer. A relatively small (32 for example)
204 * number should work.
205 * Returns Zero on success, non-zero if out of memory
207 int cvmx_helper_initialize_fpa(int packet_buffers, int work_queue_entries,
208 int pko_buffers, int tim_buffers,
211 #ifndef CVMX_FPA_PACKET_POOL
212 #define CVMX_FPA_PACKET_POOL -1
213 #define CVMX_FPA_PACKET_POOL_SIZE 0
215 #ifndef CVMX_FPA_WQE_POOL
216 #define CVMX_FPA_WQE_POOL -1
217 #define CVMX_FPA_WQE_POOL_SIZE 0
219 #ifndef CVMX_FPA_OUTPUT_BUFFER_POOL
220 #define CVMX_FPA_OUTPUT_BUFFER_POOL -1
221 #define CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE 0
223 #ifndef CVMX_FPA_TIMER_POOL
224 #define CVMX_FPA_TIMER_POOL -1
225 #define CVMX_FPA_TIMER_POOL_SIZE 0
227 #ifndef CVMX_FPA_DFA_POOL
228 #define CVMX_FPA_DFA_POOL -1
229 #define CVMX_FPA_DFA_POOL_SIZE 0
231 return __cvmx_helper_initialize_fpa(CVMX_FPA_PACKET_POOL,
232 CVMX_FPA_PACKET_POOL_SIZE,
233 packet_buffers, CVMX_FPA_WQE_POOL,
234 CVMX_FPA_WQE_POOL_SIZE,
236 CVMX_FPA_OUTPUT_BUFFER_POOL,
237 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE,
238 pko_buffers, CVMX_FPA_TIMER_POOL,
239 CVMX_FPA_TIMER_POOL_SIZE,
240 tim_buffers, CVMX_FPA_DFA_POOL,
241 CVMX_FPA_DFA_POOL_SIZE,