cvmx-dfa.c revision 210286
1/***********************license start***************
2 *  Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
3 *  reserved.
4 *
5 *
6 *  Redistribution and use in source and binary forms, with or without
7 *  modification, are permitted provided that the following conditions are
8 *  met:
9 *
10 *      * Redistributions of source code must retain the above copyright
11 *        notice, this list of conditions and the following disclaimer.
12 *
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.
17 *
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
21 *        permission.
22 *
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.
33 *
34 *
35 *  For any questions regarding licensing please contact marketing@caviumnetworks.com
36 *
37 ***********************license end**************************************/
38
39
40
41
42
43
44/**
45 * @file
46 *
47 * Support library for the hardware DFA engine.
48 *
49 * <hr>$Revision: 41586 $<hr>
50 */
51#include "executive-config.h"
52#ifdef CVMX_ENABLE_DFA_FUNCTIONS
53
54#include "cvmx-config.h"
55#include "cvmx.h"
56#include "cvmx-fau.h"
57#include "cvmx-dfa.h"
58
59
60
61/**
62 * Initialize the DFA hardware before use
63 */
64int cvmx_dfa_initialize(void)
65{
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))
70    {
71        cvmx_dprintf("ERROR: attempting to initialize DFA when no DFA hardware present\n.");
72        return -1;
73    }
74
75    control.u64 = 0;
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);
79    CVMX_SYNCWS;
80    cvmx_write_csr(CVMX_DFA_DIFCTL, control.u64);
81
82    initial_base_address = cvmx_fpa_alloc(CVMX_FPA_DFA_POOL);
83
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);
87
88    CVMX_SYNCWS;
89    cvmx_write_csr(CVMX_DFA_DIFRDPTR, cvmx_ptr_to_phys(initial_base_address));
90
91    return 0;
92}
93
94
95/**
96 * Shutdown and cleanup resources used by the DFA
97 */
98void cvmx_dfa_shutdown(void)
99{
100    void *final_base_address;
101    cvmx_dfa_state_t final_state;
102
103    CVMX_SYNCWS;
104
105    final_state.u64 = cvmx_fau_fetch_and_add64(CVMX_FAU_DFA_STATE, 0);
106
107    // make sure the carry is clear
108    final_base_address = CASTPTR(void, (final_state.s2.base_address_div32 * 32ull));
109
110    if (final_base_address)
111    {
112        cvmx_fpa_free(final_base_address, CVMX_FPA_DFA_POOL, 0);
113    }
114
115    CVMX_SYNCWS;
116    final_state.u64 = 0;
117    cvmx_fau_atomic_write64(CVMX_FAU_DFA_STATE, final_state.u64);
118}
119
120#endif
121