diff options
Diffstat (limited to 'sys/contrib/octeon-sdk/cvmx-fpa.h')
-rw-r--r-- | sys/contrib/octeon-sdk/cvmx-fpa.h | 155 |
1 files changed, 87 insertions, 68 deletions
diff --git a/sys/contrib/octeon-sdk/cvmx-fpa.h b/sys/contrib/octeon-sdk/cvmx-fpa.h index b172116..88de805 100644 --- a/sys/contrib/octeon-sdk/cvmx-fpa.h +++ b/sys/contrib/octeon-sdk/cvmx-fpa.h @@ -1,58 +1,61 @@ /***********************license start*************** - * Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights - * reserved. + * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights + * reserved. * * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * * Neither the name of Cavium Networks nor the names of - * its contributors may be used to endorse or promote products - * derived from this software without specific prior written - * permission. - * - * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" - * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS - * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH - * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY - * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT - * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES - * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR - * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET - * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT - * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. - * - * - * For any questions regarding licensing please contact marketing@caviumnetworks.com + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + + * * Neither the name of Cavium Networks nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written + * permission. + + * This Software, including technical data, may be subject to U.S. export control + * laws, including the U.S. Export Administration Act and its associated + * regulations, and may be subject to export or import regulations in other + * countries. + + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" + * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR + * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO + * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR + * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM + * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, + * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF + * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR + * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. ***********************license end**************************************/ - - - - /** * @file * * Interface to the hardware Free Pool Allocator. * - * <hr>$Revision: 41586 $<hr> + * <hr>$Revision: 50048 $<hr> * */ #ifndef __CVMX_FPA_H__ #define __CVMX_FPA_H__ +#include "cvmx-scratch.h" + +#ifdef CVMX_BUILD_FOR_LINUX_KERNEL +#include "cvmx-fpa-defs.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -92,7 +95,7 @@ typedef struct */ extern cvmx_fpa_pool_info_t cvmx_fpa_pool_info[CVMX_FPA_NUM_POOLS]; -/* CSR typedefs have been moved to cvmx-csr-*.h */ +/* CSR typedefs have been moved to cvmx-fpa-defs.h */ /** * Return the name of the pool @@ -131,8 +134,6 @@ static inline int cvmx_fpa_is_member(uint64_t pool, void *ptr) ((char*)ptr < ((char*)(cvmx_fpa_pool_info[pool].base)) + cvmx_fpa_pool_info[pool].size * cvmx_fpa_pool_info[pool].starting_element_count)); } - - /** * Enable the FPA for use. Must be performed after any CSR * configuration but before any other FPA functions. @@ -147,28 +148,11 @@ static inline void cvmx_fpa_enable(void) cvmx_dprintf("Warning: Enabling FPA when FPA already enabled.\n"); } - /* Do runtime check as we allow pass1 compiled code to run on pass2 chips */ - if (cvmx_octeon_is_pass1()) - { - cvmx_fpa_fpf_marks_t marks; - int i; - for (i=1; i<8; i++) - { - marks.u64 = cvmx_read_csr(CVMX_FPA_FPF1_MARKS + (i-1)*8ull); - marks.s.fpf_wr = 0xe0; - cvmx_write_csr(CVMX_FPA_FPF1_MARKS + (i-1)*8ull, marks.u64); - } - - /* Enforce a 10 cycle delay between config and enable */ - cvmx_wait(10); - } - - status.u64 = 0; /* FIXME: CVMX_FPA_CTL_STATUS read is unmodelled */ + status.u64 = 0; status.s.enb = 1; cvmx_write_csr(CVMX_FPA_CTL_STATUS, status.u64); } - /** * Get a new block from the FPA * @@ -177,17 +161,28 @@ static inline void cvmx_fpa_enable(void) */ static inline void *cvmx_fpa_alloc(uint64_t pool) { - uint64_t address = cvmx_read_csr(CVMX_ADDR_DID(CVMX_FULL_DID(CVMX_OCT_DID_FPA,pool))); - if (address) - return cvmx_phys_to_ptr(address); - else - return NULL; + uint64_t address; + + for (;;) { + address = cvmx_read_csr(CVMX_ADDR_DID(CVMX_FULL_DID(CVMX_OCT_DID_FPA,pool))); + if (cvmx_likely(address)) { + return cvmx_phys_to_ptr(address); + } else { + /* If pointers are available, continuously retry. */ + if (cvmx_read_csr(CVMX_FPA_QUEX_AVAILABLE(pool)) > 0) + cvmx_wait(50); + else + return NULL; + } + } } - /** * Asynchronously get a new block from the FPA * + * The result of cvmx_fpa_async_alloc() may be retrieved using + * cvmx_fpa_async_alloc_finish(). + * * @param scr_addr Local scratch address to put response in. This is a byte address, * but must be 8 byte aligned. * @param pool Pool to get the block from @@ -206,6 +201,29 @@ static inline void cvmx_fpa_async_alloc(uint64_t scr_addr, uint64_t pool) cvmx_send_single(data.u64); } +/** + * Retrieve the result of cvmx_fpa_async_alloc + * + * @param scr_addr The Local scratch address. Must be the same value + * passed to cvmx_fpa_async_alloc(). + * + * @param pool Pool the block came from. Must be the same value + * passed to cvmx_fpa_async_alloc. + * + * @return Pointer to the block or NULL on failure + */ +static inline void *cvmx_fpa_async_alloc_finish(uint64_t scr_addr, uint64_t pool) +{ + uint64_t address; + + CVMX_SYNCIOBDMA; + + address = cvmx_scratch_read64(scr_addr); + if (cvmx_likely(address)) + return cvmx_phys_to_ptr(address); + else + return cvmx_fpa_alloc(pool); +} /** * Free a block allocated with a FPA pool. @@ -248,7 +266,6 @@ static inline void cvmx_fpa_free(void *ptr, uint64_t pool, uint64_t num_cache_li cvmx_write_io(newptr.u64, num_cache_lines); } - /** * Setup a FPA pool to control a new block of memory. * This can only be called once per pool. Make sure proper @@ -269,21 +286,23 @@ static inline void cvmx_fpa_free(void *ptr, uint64_t pool, uint64_t num_cache_li extern int cvmx_fpa_setup_pool(uint64_t pool, const char *name, void *buffer, uint64_t block_size, uint64_t num_blocks); - /** * Shutdown a Memory pool and validate that it had all of * the buffers originally placed in it. This should only be * called by one processor after all hardware has finished - * using the pool. + * using the pool. Most like you will want to have called + * cvmx_helper_shutdown_packet_io_global() before this + * function to make sure all FPA buffers are out of the packet + * IO hardware. * * @param pool Pool to shutdown + * * @return Zero on success * - Positive is count of missing buffers * - Negative is too many buffers or corrupted pointers */ extern uint64_t cvmx_fpa_shutdown_pool(uint64_t pool); - /** * Get the size of blocks controlled by the pool * This is resolved to a constant at compile time. @@ -297,4 +316,4 @@ uint64_t cvmx_fpa_get_block_size(uint64_t pool); } #endif -#endif // __CVM_FPA_H__ +#endif /* __CVM_FPA_H__ */ |