1 /***********************license start***************
2 * Copyright (c) 2011 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 * Support library for the CN63XX, CN68XX hardware HFA engine.
52 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
53 #include <asm/octeon/cvmx.h>
54 #include <asm/octeon/cvmx-config.h>
55 #include <asm/octeon/cvmx-pko.h>
56 #include <asm/octeon/cvmx-helper.h>
57 #include <asm/octeon/cvmx-clock.h>
58 #include <asm/octeon/cvmx-dfa-defs.h>
59 #include <asm/octeon/cvmx-hfa.h>
61 #include "executive-config.h"
62 #ifdef CVMX_ENABLE_DFA_FUNCTIONS
64 #include "cvmx-config.h"
67 #include "cvmx-cmd-queue.h"
72 #ifdef CVMX_ENABLE_DFA_FUNCTIONS
75 * Initialize the DFA block
77 * @return Zero on success, negative on failure
79 int cvmx_hfa_initialize(void)
81 cvmx_dfa_difctl_t control;
82 cvmx_cmd_queue_result_t result;
83 void *initial_base_address;
86 cmdsize = ((CVMX_FPA_DFA_POOL_SIZE - 8) / sizeof (cvmx_dfa_command_t)) *
87 sizeof (cvmx_dfa_command_t);
88 result = cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_DFA, 0,
89 CVMX_FPA_DFA_POOL, cmdsize + 8);
90 if (result != CVMX_CMD_QUEUE_SUCCESS)
94 control.s.dwbcnt = CVMX_FPA_DFA_POOL_SIZE / 128;
95 control.s.pool = CVMX_FPA_DFA_POOL;
96 control.s.size = cmdsize / sizeof(cvmx_dfa_command_t);
98 cvmx_write_csr(CVMX_DFA_DIFCTL, control.u64);
99 initial_base_address = cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_DFA);
101 cvmx_write_csr(CVMX_DFA_DIFRDPTR, cvmx_ptr_to_phys(initial_base_address));
102 cvmx_read_csr(CVMX_DFA_DIFRDPTR); /* Read to make sure setup is complete */
105 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
106 EXPORT_SYMBOL(cvmx_hfa_initialize);
110 * Shutdown the DFA block. DFA must be idle when
111 * this function is called.
113 * @return Zero on success, negative on failure
115 int cvmx_hfa_shutdown(void)
117 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_DFA))
119 cvmx_dprintf("ERROR: cvmx_hfa_shutdown: DFA not idle.\n");
122 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_DFA);
125 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
126 EXPORT_SYMBOL(cvmx_hfa_shutdown);
130 * Submit a command to the DFA block
132 * @param command DFA command to submit
134 * @return Zero on success, negative on failure
136 int cvmx_hfa_submit(cvmx_dfa_command_t *command)
138 cvmx_cmd_queue_result_t result = cvmx_cmd_queue_write(CVMX_CMD_QUEUE_DFA, 1, 4, command->u64);
139 if (result == CVMX_CMD_QUEUE_SUCCESS)
140 cvmx_write_csr(CVMX_DFA_DBELL, 1);
143 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
144 EXPORT_SYMBOL(cvmx_hfa_submit);
147 void *hfa_bootmem_alloc (uint64_t size, uint64_t alignment)
151 address = cvmx_bootmem_phy_alloc(size, 0, 0, alignment, 0);
154 return cvmx_phys_to_ptr(address);
159 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
160 EXPORT_SYMBOL(hfa_bootmem_alloc);
163 int hfa_bootmem_free (void *ptr, uint64_t size)
166 address = cvmx_ptr_to_phys (ptr);
167 return __cvmx_bootmem_phy_free (address, size, 0);
170 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
171 EXPORT_SYMBOL(hfa_bootmem_free);