cvmx-hfa.c revision 232809
155682Smarkm/***********************license start*************** 255682Smarkm * Copyright (c) 2011 Cavium Inc. (support@cavium.com). All rights 355682Smarkm * reserved. 455682Smarkm * 555682Smarkm * 655682Smarkm * Redistribution and use in source and binary forms, with or without 755682Smarkm * modification, are permitted provided that the following conditions are 855682Smarkm * met: 955682Smarkm * 1055682Smarkm * * Redistributions of source code must retain the above copyright 1155682Smarkm * notice, this list of conditions and the following disclaimer. 1255682Smarkm * 1355682Smarkm * * Redistributions in binary form must reproduce the above 1455682Smarkm * copyright notice, this list of conditions and the following 1555682Smarkm * disclaimer in the documentation and/or other materials provided 1655682Smarkm * with the distribution. 1755682Smarkm 1855682Smarkm * * Neither the name of Cavium Inc. nor the names of 1955682Smarkm * its contributors may be used to endorse or promote products 2055682Smarkm * derived from this software without specific prior written 2155682Smarkm * permission. 2255682Smarkm 2355682Smarkm * This Software, including technical data, may be subject to U.S. export control 2455682Smarkm * laws, including the U.S. Export Administration Act and its associated 2555682Smarkm * regulations, and may be subject to export or import regulations in other 2655682Smarkm * countries. 2755682Smarkm 2855682Smarkm * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 2955682Smarkm * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR 3055682Smarkm * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO 3155682Smarkm * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR 3255682Smarkm * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM 3355682Smarkm * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, 3455682Smarkm * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF 3555682Smarkm * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR 36178825Sdfr * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR 3755682Smarkm * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 3855682Smarkm ***********************license end**************************************/ 3955682Smarkm 4055682Smarkm 4155682Smarkm 4255682Smarkm 4355682Smarkm 4455682Smarkm 45178825Sdfr 4655682Smarkm/** 4755682Smarkm * @file 4855682Smarkm * 4955682Smarkm * Support library for the CN63XX, CN68XX hardware HFA engine. 5055682Smarkm * 5155682Smarkm */ 5255682Smarkm#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 5355682Smarkm#include <asm/octeon/cvmx.h> 5455682Smarkm#include <asm/octeon/cvmx-config.h> 5555682Smarkm#include <asm/octeon/cvmx-pko.h> 5655682Smarkm#include <asm/octeon/cvmx-helper.h> 5755682Smarkm#include <asm/octeon/cvmx-clock.h> 5855682Smarkm#include <asm/octeon/cvmx-dfa-defs.h> 5955682Smarkm#include <asm/octeon/cvmx-hfa.h> 6055682Smarkm#else 6155682Smarkm#include "executive-config.h" 6255682Smarkm#ifdef CVMX_ENABLE_DFA_FUNCTIONS 63 64#include "cvmx-config.h" 65#include "cvmx.h" 66#include "cvmx-fau.h" 67#include "cvmx-cmd-queue.h" 68#include "cvmx-hfa.h" 69#endif 70#endif 71 72#ifdef CVMX_ENABLE_DFA_FUNCTIONS 73 74/** 75 * Initialize the DFA block 76 * 77 * @return Zero on success, negative on failure 78 */ 79int cvmx_hfa_initialize(void) 80{ 81 cvmx_dfa_difctl_t control; 82 cvmx_cmd_queue_result_t result; 83 void *initial_base_address; 84 int cmdsize; 85 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) 91 return -1; 92 93 control.u64 = 0; 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); 97 CVMX_SYNCWS; 98 cvmx_write_csr(CVMX_DFA_DIFCTL, control.u64); 99 initial_base_address = cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_DFA); 100 CVMX_SYNCWS; 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 */ 103 return 0; 104} 105#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 106EXPORT_SYMBOL(cvmx_hfa_initialize); 107#endif 108 109/** 110 * Shutdown the DFA block. DFA must be idle when 111 * this function is called. 112 * 113 * @return Zero on success, negative on failure 114 */ 115int cvmx_hfa_shutdown(void) 116{ 117 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_DFA)) 118 { 119 cvmx_dprintf("ERROR: cvmx_hfa_shutdown: DFA not idle.\n"); 120 return -1; 121 } 122 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_DFA); 123 return 0; 124} 125#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 126EXPORT_SYMBOL(cvmx_hfa_shutdown); 127#endif 128 129/** 130 * Submit a command to the DFA block 131 * 132 * @param command DFA command to submit 133 * 134 * @return Zero on success, negative on failure 135 */ 136int cvmx_hfa_submit(cvmx_dfa_command_t *command) 137{ 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); 141 return result; 142} 143#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 144EXPORT_SYMBOL(cvmx_hfa_submit); 145#endif 146 147void *hfa_bootmem_alloc (uint64_t size, uint64_t alignment) 148{ 149 int64_t address; 150 151 address = cvmx_bootmem_phy_alloc(size, 0, 0, alignment, 0); 152 153 if (address > 0) 154 return cvmx_phys_to_ptr(address); 155 else 156 return NULL; 157} 158 159#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 160EXPORT_SYMBOL(hfa_bootmem_alloc); 161#endif 162 163int hfa_bootmem_free (void *ptr, uint64_t size) 164{ 165 uint64_t address; 166 address = cvmx_ptr_to_phys (ptr); 167 return __cvmx_bootmem_phy_free (address, size, 0); 168} 169 170#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 171EXPORT_SYMBOL(hfa_bootmem_free); 172#endif 173 174#endif 175