1 /***********************license start***************
2 * Copyright (c) 2003-2010 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 * Source file for the zip (deflate) block
51 * <hr>$Revision: 70030 $<hr>
54 #include "executive-config.h"
55 #include "cvmx-config.h"
57 #include "cvmx-cmd-queue.h"
60 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
63 * Initialize the ZIP block
65 * @return Zero on success, negative on failure
67 int cvmx_zip_initialize(void)
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)
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 */
89 * Initialize the ZIP QUEUE buffer
91 * @param queue : ZIP instruction queue
92 * @param zcoremask : ZIP coremask to use for this queue
94 * @return Zero on success, negative on failure
96 int cvmx_zip_queue_initialize(int queue, int zcoremask)
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;
104 /* Previous Octeon models has only one instruction queue, call
105 cvmx_zip_inititalize() to initialize the ZIP block */
107 if (!OCTEON_IS_MODEL(OCTEON_CN68XX))
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)
116 /* 1. Program ZIP_QUE0/1_BUF to have the correct buffer pointer and
117 size configured for each instruction queue */
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);
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);
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);
135 /* Use round robin to have equal priority for each instruction queue */
136 cvmx_write_csr(CVMX_ZIP_QUE_PRI, 0x3);
138 int_reg.u64 = cvmx_read_csr(CVMX_ZIP_INT_REG);
140 int_reg.s.doorbell1 = 1;
142 int_reg.s.doorbell0 = 1;
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));
151 * Shutdown the ZIP block. ZIP must be idle when
152 * this function is called.
154 * @return Zero on success, negative on failure
156 int cvmx_zip_shutdown(void)
158 cvmx_zip_cmd_ctl_t zip_cmd_ctl;
160 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_ZIP))
162 cvmx_dprintf("ERROR: cvmx_zip_shutdown: ZIP not idle.\n");
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);
171 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_ZIP);
176 * Shutdown the ZIP block for a queue. ZIP must be idle when
177 * this function is called.
179 * @param queue Zip instruction queue of the command
181 * @return Zero on success, negative on failure
183 int cvmx_zip_queue_shutdown(int queue)
185 cvmx_zip_cmd_ctl_t zip_cmd_ctl;
187 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_ZIP_QUE(queue)))
189 cvmx_dprintf("ERROR: cvmx_zip_shutdown: ZIP not idle.\n");
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);
198 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_ZIP_QUE(queue));
203 * Submit a command to the ZIP block
205 * @param command Zip command to submit
207 * @return Zero on success, negative on failure
209 int cvmx_zip_submit(cvmx_zip_command_t *command)
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);
218 * Submit a command to the ZIP block
220 * @param command Zip command to submit
221 * @param queue Zip instruction queue of the command
223 * @return Zero on success, negative on failure
225 int cvmx_zip_queue_submit(cvmx_zip_command_t *command, int queue)
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);