1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
49 * Helper functions for FPA setup.
51 * <hr>$Revision: 70030 $<hr>
54 #include "cvmx-bootmem.h"
56 #include "cvmx-helper-fpa.h"
60 * Allocate memory for and initialize a single FPA pool.
62 * @param pool Pool to initialize
63 * @param buffer_size Size of buffers to allocate in bytes
64 * @param buffers Number of buffers to put in the pool. Zero is allowed
65 * @param name String name of the pool for debugging purposes
66 * @return Zero on success, non-zero on failure
68 static int __cvmx_helper_initialize_fpa_pool(int pool, uint64_t buffer_size,
69 uint64_t buffers, const char *name)
73 uint64_t align = CVMX_CACHE_LINE_SIZE;
75 /* Align the allocation so that power of 2 size buffers are naturally aligned */
76 while (align < buffer_size)
82 current_num = cvmx_read_csr(CVMX_FPA_QUEX_AVAILABLE(pool));
85 cvmx_dprintf("Fpa pool %d(%s) already has %llu buffers. Skipping setup.\n",
86 pool, name, (unsigned long long)current_num);
90 memory = cvmx_bootmem_alloc(buffer_size * buffers, align);
93 cvmx_dprintf("Out of memory initializing fpa pool %d(%s).\n", pool, name);
96 cvmx_fpa_setup_pool(pool, name, memory, buffer_size, buffers);
103 * Allocate memory and initialize the FPA pools using memory
104 * from cvmx-bootmem. Specifying zero for the number of
105 * buffers will cause that FPA pool to not be setup. This is
106 * useful if you aren't using some of the hardware and want
107 * to save memory. Use cvmx_helper_initialize_fpa instead of
108 * this function directly.
110 * @param pip_pool Should always be CVMX_FPA_PACKET_POOL
111 * @param pip_size Should always be CVMX_FPA_PACKET_POOL_SIZE
113 * Number of packet buffers.
114 * @param wqe_pool Should always be CVMX_FPA_WQE_POOL
115 * @param wqe_size Should always be CVMX_FPA_WQE_POOL_SIZE
117 * Number of work queue entries
118 * @param pko_pool Should always be CVMX_FPA_OUTPUT_BUFFER_POOL
119 * @param pko_size Should always be CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE
121 * PKO Command buffers. You should at minimum have two per
123 * @param tim_pool Should always be CVMX_FPA_TIMER_POOL
124 * @param tim_size Should always be CVMX_FPA_TIMER_POOL_SIZE
126 * TIM ring buffer command queues. At least two per timer bucket
128 * @param dfa_pool Should always be CVMX_FPA_DFA_POOL
129 * @param dfa_size Should always be CVMX_FPA_DFA_POOL_SIZE
131 * DFA command buffer. A relatively small (32 for example)
132 * number should work.
133 * @return Zero on success, non-zero if out of memory
135 static int __cvmx_helper_initialize_fpa(int pip_pool, int pip_size, int pip_buffers,
136 int wqe_pool, int wqe_size, int wqe_entries,
137 int pko_pool, int pko_size, int pko_buffers,
138 int tim_pool, int tim_size, int tim_buffers,
139 int dfa_pool, int dfa_size, int dfa_buffers)
145 if ((pip_buffers > 0) && (pip_buffers <= 64))
146 cvmx_dprintf("Warning: %d packet buffers may not be enough for hardware"
147 " prefetch. 65 or more is recommended.\n", pip_buffers);
151 status = __cvmx_helper_initialize_fpa_pool(pip_pool, pip_size, pip_buffers,
159 status = __cvmx_helper_initialize_fpa_pool(wqe_pool, wqe_size, wqe_entries,
160 "Work Queue Entries");
167 status = __cvmx_helper_initialize_fpa_pool(pko_pool, pko_size, pko_buffers,
168 "PKO Command Buffers");
175 status = __cvmx_helper_initialize_fpa_pool(tim_pool, tim_size, tim_buffers,
176 "TIM Command Buffers");
183 status = __cvmx_helper_initialize_fpa_pool(dfa_pool, dfa_size, dfa_buffers,
184 "DFA Command Buffers");
194 * Allocate memory and initialize the FPA pools using memory
195 * from cvmx-bootmem. Sizes of each element in the pools is
196 * controlled by the cvmx-config.h header file. Specifying
197 * zero for any parameter will cause that FPA pool to not be
198 * setup. This is useful if you aren't using some of the
199 * hardware and want to save memory.
201 * @param packet_buffers
202 * Number of packet buffers to allocate
203 * @param work_queue_entries
204 * Number of work queue entries
206 * PKO Command buffers. You should at minimum have two per
209 * TIM ring buffer command queues. At least two per timer bucket
212 * DFA command buffer. A relatively small (32 for example)
213 * number should work.
214 * @return Zero on success, non-zero if out of memory
216 int cvmx_helper_initialize_fpa(int packet_buffers, int work_queue_entries,
217 int pko_buffers, int tim_buffers, int dfa_buffers)
219 #ifndef CVMX_FPA_PACKET_POOL
220 #define CVMX_FPA_PACKET_POOL -1
221 #define CVMX_FPA_PACKET_POOL_SIZE 0
223 #ifndef CVMX_FPA_WQE_POOL
224 #define CVMX_FPA_WQE_POOL -1
225 #define CVMX_FPA_WQE_POOL_SIZE 0
227 #ifndef CVMX_FPA_OUTPUT_BUFFER_POOL
228 #define CVMX_FPA_OUTPUT_BUFFER_POOL -1
229 #define CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE 0
231 #ifndef CVMX_FPA_TIMER_POOL
232 #define CVMX_FPA_TIMER_POOL -1
233 #define CVMX_FPA_TIMER_POOL_SIZE 0
235 #ifndef CVMX_FPA_DFA_POOL
236 #define CVMX_FPA_DFA_POOL -1
237 #define CVMX_FPA_DFA_POOL_SIZE 0
239 return __cvmx_helper_initialize_fpa(
240 CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE, packet_buffers,
241 CVMX_FPA_WQE_POOL, CVMX_FPA_WQE_POOL_SIZE, work_queue_entries,
242 CVMX_FPA_OUTPUT_BUFFER_POOL, CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE, pko_buffers,
243 CVMX_FPA_TIMER_POOL, CVMX_FPA_TIMER_POOL_SIZE, tim_buffers,
244 CVMX_FPA_DFA_POOL, CVMX_FPA_DFA_POOL_SIZE, dfa_buffers);