1 /***********************license start***************
2 * Copyright (c) 2003-2008 Cavium Networks (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 Networks 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT
32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
47 * Helper functions for FPA setup.
49 * <hr>$Revision: 41586 $<hr>
52 #include "cvmx-bootmem.h"
54 #include "cvmx-helper-fpa.h"
58 * Allocate memory for and initialize a single FPA pool.
60 * @param pool Pool to initialize
61 * @param buffer_size Size of buffers to allocate in bytes
62 * @param buffers Number of buffers to put in the pool. Zero is allowed
63 * @param name String name of the pool for debugging purposes
64 * @return Zero on success, non-zero on failure
66 static int __cvmx_helper_initialize_fpa_pool(int pool, uint64_t buffer_size,
67 uint64_t buffers, const char *name)
71 uint64_t align = CVMX_CACHE_LINE_SIZE;
73 /* Align the allocation so that power of 2 size buffers are naturally aligned */
74 while (align < buffer_size)
80 current_num = cvmx_read_csr(CVMX_FPA_QUEX_AVAILABLE(pool));
83 cvmx_dprintf("Fpa pool %d(%s) already has %llu buffers. Skipping setup.\n",
84 pool, name, (unsigned long long)current_num);
88 memory = cvmx_bootmem_alloc(buffer_size * buffers, align);
91 cvmx_dprintf("Out of memory initializing fpa pool %d(%s).\n", pool, name);
94 cvmx_fpa_setup_pool(pool, name, memory, buffer_size, buffers);
101 * Allocate memory and initialize the FPA pools using memory
102 * from cvmx-bootmem. Specifying zero for the number of
103 * buffers will cause that FPA pool to not be setup. This is
104 * useful if you aren't using some of the hardware and want
105 * to save memory. Use cvmx_helper_initialize_fpa instead of
106 * this function directly.
108 * @param pip_pool Should always be CVMX_FPA_PACKET_POOL
109 * @param pip_size Should always be CVMX_FPA_PACKET_POOL_SIZE
111 * Number of packet buffers.
112 * @param wqe_pool Should always be CVMX_FPA_WQE_POOL
113 * @param wqe_size Should always be CVMX_FPA_WQE_POOL_SIZE
115 * Number of work queue entries
116 * @param pko_pool Should always be CVMX_FPA_OUTPUT_BUFFER_POOL
117 * @param pko_size Should always be CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE
119 * PKO Command buffers. You should at minimum have two per
121 * @param tim_pool Should always be CVMX_FPA_TIMER_POOL
122 * @param tim_size Should always be CVMX_FPA_TIMER_POOL_SIZE
124 * TIM ring buffer command queues. At least two per timer bucket
126 * @param dfa_pool Should always be CVMX_FPA_DFA_POOL
127 * @param dfa_size Should always be CVMX_FPA_DFA_POOL_SIZE
129 * DFA command buffer. A relatively small (32 for example)
130 * number should work.
131 * @return Zero on success, non-zero if out of memory
133 static int __cvmx_helper_initialize_fpa(int pip_pool, int pip_size, int pip_buffers,
134 int wqe_pool, int wqe_size, int wqe_entries,
135 int pko_pool, int pko_size, int pko_buffers,
136 int tim_pool, int tim_size, int tim_buffers,
137 int dfa_pool, int dfa_size, int dfa_buffers)
143 if ((pip_buffers > 0) && (pip_buffers <= 64))
144 cvmx_dprintf("Warning: %d packet buffers may not be enough for hardware"
145 " prefetch. 65 or more is recommended.\n", pip_buffers);
149 status = __cvmx_helper_initialize_fpa_pool(pip_pool, pip_size, pip_buffers,
157 status = __cvmx_helper_initialize_fpa_pool(wqe_pool, wqe_size, wqe_entries,
158 "Work Queue Entries");
165 status = __cvmx_helper_initialize_fpa_pool(pko_pool, pko_size, pko_buffers,
166 "PKO Command Buffers");
173 status = __cvmx_helper_initialize_fpa_pool(tim_pool, tim_size, tim_buffers,
174 "TIM Command Buffers");
181 status = __cvmx_helper_initialize_fpa_pool(dfa_pool, dfa_size, dfa_buffers,
182 "DFA Command Buffers");
192 * Allocate memory and initialize the FPA pools using memory
193 * from cvmx-bootmem. Sizes of each element in the pools is
194 * controlled by the cvmx-config.h header file. Specifying
195 * zero for any parameter will cause that FPA pool to not be
196 * setup. This is useful if you aren't using some of the
197 * hardware and want to save memory.
199 * @param packet_buffers
200 * Number of packet buffers to allocate
201 * @param work_queue_entries
202 * Number of work queue entries
204 * PKO Command buffers. You should at minimum have two per
207 * TIM ring buffer command queues. At least two per timer bucket
210 * DFA command buffer. A relatively small (32 for example)
211 * number should work.
212 * @return Zero on success, non-zero if out of memory
214 int cvmx_helper_initialize_fpa(int packet_buffers, int work_queue_entries,
215 int pko_buffers, int tim_buffers, int dfa_buffers)
217 #ifndef CVMX_FPA_PACKET_POOL
218 #define CVMX_FPA_PACKET_POOL -1
219 #define CVMX_FPA_PACKET_POOL_SIZE 0
221 #ifndef CVMX_FPA_WQE_POOL
222 #define CVMX_FPA_WQE_POOL -1
223 #define CVMX_FPA_WQE_POOL_SIZE 0
225 #ifndef CVMX_FPA_OUTPUT_BUFFER_POOL
226 #define CVMX_FPA_OUTPUT_BUFFER_POOL -1
227 #define CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE 0
229 #ifndef CVMX_FPA_TIMER_POOL
230 #define CVMX_FPA_TIMER_POOL -1
231 #define CVMX_FPA_TIMER_POOL_SIZE 0
233 #ifndef CVMX_FPA_DFA_POOL
234 #define CVMX_FPA_DFA_POOL -1
235 #define CVMX_FPA_DFA_POOL_SIZE 0
237 return __cvmx_helper_initialize_fpa(
238 CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE, packet_buffers,
239 CVMX_FPA_WQE_POOL, CVMX_FPA_WQE_POOL_SIZE, work_queue_entries,
240 CVMX_FPA_OUTPUT_BUFFER_POOL, CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE, pko_buffers,
241 CVMX_FPA_TIMER_POOL, CVMX_FPA_TIMER_POOL_SIZE, tim_buffers,
242 CVMX_FPA_DFA_POOL, CVMX_FPA_DFA_POOL_SIZE, dfa_buffers);