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 * Support library for the hardware DFA engine.
49 * <hr>$Revision: 41586 $<hr>
51 #include "executive-config.h"
52 #ifdef CVMX_ENABLE_DFA_FUNCTIONS
54 #include "cvmx-config.h"
62 * Initialize the DFA hardware before use
64 int cvmx_dfa_initialize(void)
66 cvmx_dfa_difctl_t control;
67 void *initial_base_address;
68 cvmx_dfa_state_t initial_state;
69 if (!octeon_has_feature(OCTEON_FEATURE_DFA))
71 cvmx_dprintf("ERROR: attempting to initialize DFA when no DFA hardware present\n.");
76 control.s.dwbcnt = CVMX_FPA_DFA_POOL_SIZE / 128;
77 control.s.pool = CVMX_FPA_DFA_POOL;
78 control.s.size = (CVMX_FPA_DFA_POOL_SIZE - 8) / sizeof(cvmx_dfa_command_t);
80 cvmx_write_csr(CVMX_DFA_DIFCTL, control.u64);
82 initial_base_address = cvmx_fpa_alloc(CVMX_FPA_DFA_POOL);
84 initial_state.u64 = 0;
85 initial_state.s.base_address_div16 = (CAST64(initial_base_address))/16;
86 cvmx_fau_atomic_write64(CVMX_FAU_DFA_STATE, initial_state.u64);
89 cvmx_write_csr(CVMX_DFA_DIFRDPTR, cvmx_ptr_to_phys(initial_base_address));
96 * Shutdown and cleanup resources used by the DFA
98 void cvmx_dfa_shutdown(void)
100 void *final_base_address;
101 cvmx_dfa_state_t final_state;
105 final_state.u64 = cvmx_fau_fetch_and_add64(CVMX_FAU_DFA_STATE, 0);
107 // make sure the carry is clear
108 final_base_address = CASTPTR(void, (final_state.s2.base_address_div32 * 32ull));
110 if (final_base_address)
112 cvmx_fpa_free(final_base_address, CVMX_FPA_DFA_POOL, 0);
117 cvmx_fau_atomic_write64(CVMX_FAU_DFA_STATE, final_state.u64);