cvmx-zip.c revision 303975
1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Inc. (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 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 21 * permission. 22 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 26 * countries. 27 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**************************************/ 39 40 41 42 43 44 45 46/** 47 * @file 48 * 49 * Source file for the zip (deflate) block 50 * 51 * <hr>$Revision: 70030 $<hr> 52 */ 53 54#include "executive-config.h" 55#include "cvmx-config.h" 56#include "cvmx.h" 57#include "cvmx-cmd-queue.h" 58#include "cvmx-zip.h" 59 60#ifdef CVMX_ENABLE_PKO_FUNCTIONS 61 62/** 63 * Initialize the ZIP block 64 * 65 * @return Zero on success, negative on failure 66 */ 67int cvmx_zip_initialize(void) 68{ 69 cvmx_zip_cmd_buf_t zip_cmd_buf; 70 cvmx_cmd_queue_result_t result; 71 result = cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_ZIP, 0, 72 CVMX_FPA_OUTPUT_BUFFER_POOL, 73 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE); 74 if (result != CVMX_CMD_QUEUE_SUCCESS) 75 return -1; 76 77 zip_cmd_buf.u64 = 0; 78 zip_cmd_buf.s.dwb = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/128; 79 zip_cmd_buf.s.pool = CVMX_FPA_OUTPUT_BUFFER_POOL; 80 zip_cmd_buf.s.size = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/8; 81 zip_cmd_buf.s.ptr = cvmx_ptr_to_phys(cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_ZIP))>>7; 82 cvmx_write_csr(CVMX_ZIP_CMD_BUF, zip_cmd_buf.u64); 83 cvmx_write_csr(CVMX_ZIP_ERROR, 1); 84 cvmx_read_csr(CVMX_ZIP_CMD_BUF); /* Read to make sure setup is complete */ 85 return 0; 86} 87 88/** 89 * Initialize the ZIP QUEUE buffer 90 * 91 * @param queue : ZIP instruction queue 92 * @param zcoremask : ZIP coremask to use for this queue 93 * 94 * @return Zero on success, negative on failure 95 */ 96int cvmx_zip_queue_initialize(int queue, int zcoremask) 97{ 98 cvmx_zip_quex_buf_t zip_que_buf; 99 cvmx_cmd_queue_result_t result; 100 cvmx_zip_quex_map_t que_map; 101 cvmx_zip_que_ena_t que_ena; 102 cvmx_zip_int_reg_t int_reg; 103 104 /* Previous Octeon models has only one instruction queue, call 105 cvmx_zip_inititalize() to initialize the ZIP block */ 106 107 if (!OCTEON_IS_MODEL(OCTEON_CN68XX)) 108 return -1; 109 110 result = cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_ZIP_QUE(queue), 0, 111 CVMX_FPA_OUTPUT_BUFFER_POOL, 112 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE); 113 if (result != CVMX_CMD_QUEUE_SUCCESS) 114 return -1; 115 116 /* 1. Program ZIP_QUE0/1_BUF to have the correct buffer pointer and 117 size configured for each instruction queue */ 118 zip_que_buf.u64 = 0; 119 zip_que_buf.s.dwb = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/128; 120 zip_que_buf.s.pool = CVMX_FPA_OUTPUT_BUFFER_POOL; 121 zip_que_buf.s.size = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/8; 122 zip_que_buf.s.ptr = cvmx_ptr_to_phys(cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_ZIP_QUE(queue)))>>7; 123 cvmx_write_csr(CVMX_ZIP_QUEX_BUF(queue), zip_que_buf.u64); 124 125 /* 2. Change the queue-to-ZIP core mapping by programming ZIP_QUE0/1_MAP. */ 126 que_map.u64 = cvmx_read_csr(CVMX_ZIP_QUEX_MAP(queue)); 127 que_map.s.zce = zcoremask; 128 cvmx_write_csr(CVMX_ZIP_QUEX_MAP(queue), que_map.u64); 129 130 /* Enable the queue */ 131 que_ena.u64 = cvmx_read_csr(CVMX_ZIP_QUE_ENA); 132 que_ena.s.ena |= (1<<queue); 133 cvmx_write_csr(CVMX_ZIP_QUE_ENA, que_ena.u64); 134 135 /* Use round robin to have equal priority for each instruction queue */ 136 cvmx_write_csr(CVMX_ZIP_QUE_PRI, 0x3); 137 138 int_reg.u64 = cvmx_read_csr(CVMX_ZIP_INT_REG); 139 if (queue) 140 int_reg.s.doorbell1 = 1; 141 else 142 int_reg.s.doorbell0 = 1; 143 144 cvmx_write_csr(CVMX_ZIP_INT_REG, int_reg.u64); 145 /* Read back to make sure the setup is complete */ 146 cvmx_read_csr(CVMX_ZIP_QUEX_BUF(queue)); 147 return 0; 148} 149 150/** 151 * Shutdown the ZIP block. ZIP must be idle when 152 * this function is called. 153 * 154 * @return Zero on success, negative on failure 155 */ 156int cvmx_zip_shutdown(void) 157{ 158 cvmx_zip_cmd_ctl_t zip_cmd_ctl; 159 160 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_ZIP)) 161 { 162 cvmx_dprintf("ERROR: cvmx_zip_shutdown: ZIP not idle.\n"); 163 return -1; 164 } 165 166 zip_cmd_ctl.u64 = cvmx_read_csr(CVMX_ZIP_CMD_CTL); 167 zip_cmd_ctl.s.reset = 1; 168 cvmx_write_csr(CVMX_ZIP_CMD_CTL, zip_cmd_ctl.u64); 169 cvmx_wait(100); 170 171 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_ZIP); 172 return 0; 173} 174 175/** 176 * Shutdown the ZIP block for a queue. ZIP must be idle when 177 * this function is called. 178 * 179 * @param queue Zip instruction queue of the command 180 * 181 * @return Zero on success, negative on failure 182 */ 183int cvmx_zip_queue_shutdown(int queue) 184{ 185 cvmx_zip_cmd_ctl_t zip_cmd_ctl; 186 187 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_ZIP_QUE(queue))) 188 { 189 cvmx_dprintf("ERROR: cvmx_zip_shutdown: ZIP not idle.\n"); 190 return -1; 191 } 192 193 zip_cmd_ctl.u64 = cvmx_read_csr(CVMX_ZIP_CMD_CTL); 194 zip_cmd_ctl.s.reset = 1; 195 cvmx_write_csr(CVMX_ZIP_CMD_CTL, zip_cmd_ctl.u64); 196 cvmx_wait(100); 197 198 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_ZIP_QUE(queue)); 199 return 0; 200} 201 202/** 203 * Submit a command to the ZIP block 204 * 205 * @param command Zip command to submit 206 * 207 * @return Zero on success, negative on failure 208 */ 209int cvmx_zip_submit(cvmx_zip_command_t *command) 210{ 211 cvmx_cmd_queue_result_t result = cvmx_cmd_queue_write(CVMX_CMD_QUEUE_ZIP, 1, 8, command->u64); 212 if (result == CVMX_CMD_QUEUE_SUCCESS) 213 cvmx_write_csr(CVMX_ADDR_DID(CVMX_FULL_DID(7, 0)), 8); 214 return result; 215} 216 217/** 218 * Submit a command to the ZIP block 219 * 220 * @param command Zip command to submit 221 * @param queue Zip instruction queue of the command 222 * 223 * @return Zero on success, negative on failure 224 */ 225int cvmx_zip_queue_submit(cvmx_zip_command_t *command, int queue) 226{ 227 cvmx_cmd_queue_result_t result = cvmx_cmd_queue_write(CVMX_CMD_QUEUE_ZIP_QUE(queue), 1, 8, command->u64); 228 if (result == CVMX_CMD_QUEUE_SUCCESS) 229 cvmx_write_csr((CVMX_ADDR_DID(CVMX_FULL_DID(7, 0)) | queue << 3), 8); 230 return result; 231} 232 233#endif 234 235