Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: zip - Wire-up Compression / decompression HW offload

This contains changes for adding compression/decompression h/w offload
functionality for both DEFLATE and LZS.

Signed-off-by: Mahipal Challa <Mahipal.Challa@cavium.com>
Signed-off-by: Jan Glauber <jglauber@cavium.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Mahipal Challa and committed by
Herbert Xu
f05845fc 640035a2

+845 -58
+4 -1
drivers/crypto/cavium/zip/Makefile
··· 5 5 obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += thunderx_zip.o 6 6 thunderx_zip-y := zip_main.o \ 7 7 zip_device.o \ 8 - zip_mem.o 8 + zip_crypto.o \ 9 + zip_mem.o \ 10 + zip_deflate.o \ 11 + zip_inflate.o
+313
drivers/crypto/cavium/zip/zip_crypto.c
··· 1 + /***********************license start************************************ 2 + * Copyright (c) 2003-2017 Cavium, Inc. 3 + * All rights reserved. 4 + * 5 + * License: one of 'Cavium License' or 'GNU General Public License Version 2' 6 + * 7 + * This file is provided under the terms of the Cavium License (see below) 8 + * or under the terms of GNU General Public License, Version 2, as 9 + * published by the Free Software Foundation. When using or redistributing 10 + * this file, you may do so under either license. 11 + * 12 + * Cavium License: Redistribution and use in source and binary forms, with 13 + * or without modification, are permitted provided that the following 14 + * conditions are met: 15 + * 16 + * * Redistributions of source code must retain the above copyright 17 + * notice, this list of conditions and the following disclaimer. 18 + * 19 + * * Redistributions in binary form must reproduce the above 20 + * copyright notice, this list of conditions and the following 21 + * disclaimer in the documentation and/or other materials provided 22 + * with the distribution. 23 + * 24 + * * Neither the name of Cavium Inc. nor the names of its contributors may be 25 + * used to endorse or promote products derived from this software without 26 + * specific prior written permission. 27 + * 28 + * This Software, including technical data, may be subject to U.S. export 29 + * control laws, including the U.S. Export Administration Act and its 30 + * associated regulations, and may be subject to export or import 31 + * regulations in other countries. 32 + * 33 + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 34 + * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS 35 + * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 36 + * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 37 + * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 38 + * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) 39 + * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A 40 + * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET 41 + * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE 42 + * ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES 43 + * WITH YOU. 44 + ***********************license end**************************************/ 45 + 46 + #include "zip_crypto.h" 47 + 48 + static void zip_static_init_zip_ops(struct zip_operation *zip_ops, 49 + int lzs_flag) 50 + { 51 + zip_ops->flush = ZIP_FLUSH_FINISH; 52 + 53 + /* equivalent to level 6 of opensource zlib */ 54 + zip_ops->speed = 1; 55 + 56 + if (!lzs_flag) { 57 + zip_ops->ccode = 0; /* Auto Huffman */ 58 + zip_ops->lzs_flag = 0; 59 + zip_ops->format = ZLIB_FORMAT; 60 + } else { 61 + zip_ops->ccode = 3; /* LZS Encoding */ 62 + zip_ops->lzs_flag = 1; 63 + zip_ops->format = LZS_FORMAT; 64 + } 65 + zip_ops->begin_file = 1; 66 + zip_ops->history_len = 0; 67 + zip_ops->end_file = 1; 68 + zip_ops->compcode = 0; 69 + zip_ops->csum = 1; /* Adler checksum desired */ 70 + } 71 + 72 + int zip_ctx_init(struct zip_kernel_ctx *zip_ctx, int lzs_flag) 73 + { 74 + struct zip_operation *comp_ctx = &zip_ctx->zip_comp; 75 + struct zip_operation *decomp_ctx = &zip_ctx->zip_decomp; 76 + 77 + zip_static_init_zip_ops(comp_ctx, lzs_flag); 78 + zip_static_init_zip_ops(decomp_ctx, lzs_flag); 79 + 80 + comp_ctx->input = zip_data_buf_alloc(MAX_INPUT_BUFFER_SIZE); 81 + if (!comp_ctx->input) 82 + return -ENOMEM; 83 + 84 + comp_ctx->output = zip_data_buf_alloc(MAX_OUTPUT_BUFFER_SIZE); 85 + if (!comp_ctx->output) 86 + goto err_comp_input; 87 + 88 + decomp_ctx->input = zip_data_buf_alloc(MAX_INPUT_BUFFER_SIZE); 89 + if (!decomp_ctx->input) 90 + goto err_comp_output; 91 + 92 + decomp_ctx->output = zip_data_buf_alloc(MAX_OUTPUT_BUFFER_SIZE); 93 + if (!decomp_ctx->output) 94 + goto err_decomp_input; 95 + 96 + return 0; 97 + 98 + err_decomp_input: 99 + zip_data_buf_free(decomp_ctx->input, MAX_INPUT_BUFFER_SIZE); 100 + 101 + err_comp_output: 102 + zip_data_buf_free(comp_ctx->output, MAX_OUTPUT_BUFFER_SIZE); 103 + 104 + err_comp_input: 105 + zip_data_buf_free(comp_ctx->input, MAX_INPUT_BUFFER_SIZE); 106 + 107 + return -ENOMEM; 108 + } 109 + 110 + void zip_ctx_exit(struct zip_kernel_ctx *zip_ctx) 111 + { 112 + struct zip_operation *comp_ctx = &zip_ctx->zip_comp; 113 + struct zip_operation *dec_ctx = &zip_ctx->zip_decomp; 114 + 115 + zip_data_buf_free(comp_ctx->input, MAX_INPUT_BUFFER_SIZE); 116 + zip_data_buf_free(comp_ctx->output, MAX_OUTPUT_BUFFER_SIZE); 117 + 118 + zip_data_buf_free(dec_ctx->input, MAX_INPUT_BUFFER_SIZE); 119 + zip_data_buf_free(dec_ctx->output, MAX_OUTPUT_BUFFER_SIZE); 120 + } 121 + 122 + int zip_compress(const u8 *src, unsigned int slen, 123 + u8 *dst, unsigned int *dlen, 124 + struct zip_kernel_ctx *zip_ctx) 125 + { 126 + struct zip_operation *zip_ops = NULL; 127 + struct zip_state zip_state; 128 + struct zip_device *zip = NULL; 129 + int ret; 130 + 131 + if (!zip_ctx || !src || !dst || !dlen) 132 + return -ENOMEM; 133 + 134 + zip = zip_get_device(zip_get_node_id()); 135 + if (!zip) 136 + return -ENODEV; 137 + 138 + memset(&zip_state, 0, sizeof(struct zip_state)); 139 + zip_ops = &zip_ctx->zip_comp; 140 + 141 + zip_ops->input_len = slen; 142 + zip_ops->output_len = *dlen; 143 + memcpy(zip_ops->input, src, slen); 144 + 145 + ret = zip_deflate(zip_ops, &zip_state, zip); 146 + 147 + if (!ret) { 148 + *dlen = zip_ops->output_len; 149 + memcpy(dst, zip_ops->output, *dlen); 150 + } 151 + 152 + return ret; 153 + } 154 + 155 + int zip_decompress(const u8 *src, unsigned int slen, 156 + u8 *dst, unsigned int *dlen, 157 + struct zip_kernel_ctx *zip_ctx) 158 + { 159 + struct zip_operation *zip_ops = NULL; 160 + struct zip_state zip_state; 161 + struct zip_device *zip = NULL; 162 + int ret; 163 + 164 + if (!zip_ctx || !src || !dst || !dlen) 165 + return -ENOMEM; 166 + 167 + zip = zip_get_device(zip_get_node_id()); 168 + if (!zip) 169 + return -ENODEV; 170 + 171 + memset(&zip_state, 0, sizeof(struct zip_state)); 172 + zip_ops = &zip_ctx->zip_decomp; 173 + memcpy(zip_ops->input, src, slen); 174 + 175 + /* Work around for a bug in zlib which needs an extra bytes sometimes */ 176 + if (zip_ops->ccode != 3) /* Not LZS Encoding */ 177 + zip_ops->input[slen++] = 0; 178 + 179 + zip_ops->input_len = slen; 180 + zip_ops->output_len = *dlen; 181 + 182 + ret = zip_inflate(zip_ops, &zip_state, zip); 183 + 184 + if (!ret) { 185 + *dlen = zip_ops->output_len; 186 + memcpy(dst, zip_ops->output, *dlen); 187 + } 188 + 189 + return ret; 190 + } 191 + 192 + /* Legacy Compress framework start */ 193 + int zip_alloc_comp_ctx_deflate(struct crypto_tfm *tfm) 194 + { 195 + int ret; 196 + struct zip_kernel_ctx *zip_ctx = crypto_tfm_ctx(tfm); 197 + 198 + ret = zip_ctx_init(zip_ctx, 0); 199 + 200 + return ret; 201 + } 202 + 203 + int zip_alloc_comp_ctx_lzs(struct crypto_tfm *tfm) 204 + { 205 + int ret; 206 + struct zip_kernel_ctx *zip_ctx = crypto_tfm_ctx(tfm); 207 + 208 + ret = zip_ctx_init(zip_ctx, 1); 209 + 210 + return ret; 211 + } 212 + 213 + void zip_free_comp_ctx(struct crypto_tfm *tfm) 214 + { 215 + struct zip_kernel_ctx *zip_ctx = crypto_tfm_ctx(tfm); 216 + 217 + zip_ctx_exit(zip_ctx); 218 + } 219 + 220 + int zip_comp_compress(struct crypto_tfm *tfm, 221 + const u8 *src, unsigned int slen, 222 + u8 *dst, unsigned int *dlen) 223 + { 224 + int ret; 225 + struct zip_kernel_ctx *zip_ctx = crypto_tfm_ctx(tfm); 226 + 227 + ret = zip_compress(src, slen, dst, dlen, zip_ctx); 228 + 229 + return ret; 230 + } 231 + 232 + int zip_comp_decompress(struct crypto_tfm *tfm, 233 + const u8 *src, unsigned int slen, 234 + u8 *dst, unsigned int *dlen) 235 + { 236 + int ret; 237 + struct zip_kernel_ctx *zip_ctx = crypto_tfm_ctx(tfm); 238 + 239 + ret = zip_decompress(src, slen, dst, dlen, zip_ctx); 240 + 241 + return ret; 242 + } /* Legacy compress framework end */ 243 + 244 + /* SCOMP framework start */ 245 + void *zip_alloc_scomp_ctx_deflate(struct crypto_scomp *tfm) 246 + { 247 + int ret; 248 + struct zip_kernel_ctx *zip_ctx; 249 + 250 + zip_ctx = kzalloc(sizeof(*zip_ctx), GFP_KERNEL); 251 + if (!zip_ctx) 252 + return ERR_PTR(-ENOMEM); 253 + 254 + ret = zip_ctx_init(zip_ctx, 0); 255 + 256 + if (ret) { 257 + kzfree(zip_ctx); 258 + return ERR_PTR(ret); 259 + } 260 + 261 + return zip_ctx; 262 + } 263 + 264 + void *zip_alloc_scomp_ctx_lzs(struct crypto_scomp *tfm) 265 + { 266 + int ret; 267 + struct zip_kernel_ctx *zip_ctx; 268 + 269 + zip_ctx = kzalloc(sizeof(*zip_ctx), GFP_KERNEL); 270 + if (!zip_ctx) 271 + return ERR_PTR(-ENOMEM); 272 + 273 + ret = zip_ctx_init(zip_ctx, 1); 274 + 275 + if (ret) { 276 + kzfree(zip_ctx); 277 + return ERR_PTR(ret); 278 + } 279 + 280 + return zip_ctx; 281 + } 282 + 283 + void zip_free_scomp_ctx(struct crypto_scomp *tfm, void *ctx) 284 + { 285 + struct zip_kernel_ctx *zip_ctx = ctx; 286 + 287 + zip_ctx_exit(zip_ctx); 288 + kzfree(zip_ctx); 289 + } 290 + 291 + int zip_scomp_compress(struct crypto_scomp *tfm, 292 + const u8 *src, unsigned int slen, 293 + u8 *dst, unsigned int *dlen, void *ctx) 294 + { 295 + int ret; 296 + struct zip_kernel_ctx *zip_ctx = ctx; 297 + 298 + ret = zip_compress(src, slen, dst, dlen, zip_ctx); 299 + 300 + return ret; 301 + } 302 + 303 + int zip_scomp_decompress(struct crypto_scomp *tfm, 304 + const u8 *src, unsigned int slen, 305 + u8 *dst, unsigned int *dlen, void *ctx) 306 + { 307 + int ret; 308 + struct zip_kernel_ctx *zip_ctx = ctx; 309 + 310 + ret = zip_decompress(src, slen, dst, dlen, zip_ctx); 311 + 312 + return ret; 313 + } /* SCOMP framework end */
+2
drivers/crypto/cavium/zip/zip_crypto.h
··· 49 49 #include <linux/crypto.h> 50 50 #include <crypto/internal/scompress.h> 51 51 #include "common.h" 52 + #include "zip_deflate.h" 53 + #include "zip_inflate.h" 52 54 53 55 struct zip_kernel_ctx { 54 56 struct zip_operation zip_comp;
+190
drivers/crypto/cavium/zip/zip_deflate.c
··· 1 + /***********************license start************************************ 2 + * Copyright (c) 2003-2017 Cavium, Inc. 3 + * All rights reserved. 4 + * 5 + * License: one of 'Cavium License' or 'GNU General Public License Version 2' 6 + * 7 + * This file is provided under the terms of the Cavium License (see below) 8 + * or under the terms of GNU General Public License, Version 2, as 9 + * published by the Free Software Foundation. When using or redistributing 10 + * this file, you may do so under either license. 11 + * 12 + * Cavium License: Redistribution and use in source and binary forms, with 13 + * or without modification, are permitted provided that the following 14 + * conditions are met: 15 + * 16 + * * Redistributions of source code must retain the above copyright 17 + * notice, this list of conditions and the following disclaimer. 18 + * 19 + * * Redistributions in binary form must reproduce the above 20 + * copyright notice, this list of conditions and the following 21 + * disclaimer in the documentation and/or other materials provided 22 + * with the distribution. 23 + * 24 + * * Neither the name of Cavium Inc. nor the names of its contributors may be 25 + * used to endorse or promote products derived from this software without 26 + * specific prior written permission. 27 + * 28 + * This Software, including technical data, may be subject to U.S. export 29 + * control laws, including the U.S. Export Administration Act and its 30 + * associated regulations, and may be subject to export or import 31 + * regulations in other countries. 32 + * 33 + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 34 + * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS 35 + * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 36 + * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 37 + * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 38 + * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) 39 + * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A 40 + * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET 41 + * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE 42 + * ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES 43 + * WITH YOU. 44 + ***********************license end**************************************/ 45 + 46 + #include <linux/delay.h> 47 + #include <linux/sched.h> 48 + 49 + #include "common.h" 50 + #include "zip_deflate.h" 51 + 52 + /* Prepares the deflate zip command */ 53 + static int prepare_zip_command(struct zip_operation *zip_ops, 54 + struct zip_state *s, union zip_inst_s *zip_cmd) 55 + { 56 + union zip_zres_s *result_ptr = &s->result; 57 + 58 + memset(zip_cmd, 0, sizeof(s->zip_cmd)); 59 + memset(result_ptr, 0, sizeof(s->result)); 60 + 61 + /* IWORD #0 */ 62 + /* History gather */ 63 + zip_cmd->s.hg = 0; 64 + /* compression enable = 1 for deflate */ 65 + zip_cmd->s.ce = 1; 66 + /* sf (sync flush) */ 67 + zip_cmd->s.sf = 1; 68 + /* ef (end of file) */ 69 + if (zip_ops->flush == ZIP_FLUSH_FINISH) { 70 + zip_cmd->s.ef = 1; 71 + zip_cmd->s.sf = 0; 72 + } 73 + 74 + zip_cmd->s.cc = zip_ops->ccode; 75 + /* ss (compression speed/storage) */ 76 + zip_cmd->s.ss = zip_ops->speed; 77 + 78 + /* IWORD #1 */ 79 + /* adler checksum */ 80 + zip_cmd->s.adlercrc32 = zip_ops->csum; 81 + zip_cmd->s.historylength = zip_ops->history_len; 82 + zip_cmd->s.dg = 0; 83 + 84 + /* IWORD # 6 and 7 - compression input/history pointer */ 85 + zip_cmd->s.inp_ptr_addr.s.addr = __pa(zip_ops->input); 86 + zip_cmd->s.inp_ptr_ctl.s.length = (zip_ops->input_len + 87 + zip_ops->history_len); 88 + zip_cmd->s.ds = 0; 89 + 90 + /* IWORD # 8 and 9 - Output pointer */ 91 + zip_cmd->s.out_ptr_addr.s.addr = __pa(zip_ops->output); 92 + zip_cmd->s.out_ptr_ctl.s.length = zip_ops->output_len; 93 + /* maximum number of output-stream bytes that can be written */ 94 + zip_cmd->s.totaloutputlength = zip_ops->output_len; 95 + 96 + /* IWORD # 10 and 11 - Result pointer */ 97 + zip_cmd->s.res_ptr_addr.s.addr = __pa(result_ptr); 98 + /* Clearing completion code */ 99 + result_ptr->s.compcode = 0; 100 + 101 + return 0; 102 + } 103 + 104 + /** 105 + * zip_deflate - API to offload deflate operation to hardware 106 + * @zip_ops: Pointer to zip operation structure 107 + * @s: Pointer to the structure representing zip state 108 + * @zip_dev: Pointer to zip device structure 109 + * 110 + * This function prepares the zip deflate command and submits it to the zip 111 + * engine for processing. 112 + * 113 + * Return: 0 if successful or error code 114 + */ 115 + int zip_deflate(struct zip_operation *zip_ops, struct zip_state *s, 116 + struct zip_device *zip_dev) 117 + { 118 + union zip_inst_s *zip_cmd = &s->zip_cmd; 119 + union zip_zres_s *result_ptr = &s->result; 120 + u32 queue; 121 + 122 + /* Prepares zip command based on the input parameters */ 123 + prepare_zip_command(zip_ops, s, zip_cmd); 124 + 125 + /* Loads zip command into command queues and rings door bell */ 126 + queue = zip_load_instr(zip_cmd, zip_dev); 127 + 128 + while (!result_ptr->s.compcode) 129 + continue; 130 + 131 + zip_ops->compcode = result_ptr->s.compcode; 132 + switch (zip_ops->compcode) { 133 + case ZIP_CMD_NOTDONE: 134 + zip_dbg("Zip instruction not yet completed"); 135 + return ZIP_ERROR; 136 + 137 + case ZIP_CMD_SUCCESS: 138 + zip_dbg("Zip instruction completed successfully"); 139 + zip_update_cmd_bufs(zip_dev, queue); 140 + break; 141 + 142 + case ZIP_CMD_DTRUNC: 143 + zip_dbg("Output Truncate error"); 144 + /* Returning ZIP_ERROR to avoid copy to user */ 145 + return ZIP_ERROR; 146 + 147 + default: 148 + zip_err("Zip instruction failed. Code:%d", zip_ops->compcode); 149 + return ZIP_ERROR; 150 + } 151 + 152 + /* Update the CRC depending on the format */ 153 + switch (zip_ops->format) { 154 + case RAW_FORMAT: 155 + zip_dbg("RAW Format: %d ", zip_ops->format); 156 + /* Get checksum from engine, need to feed it again */ 157 + zip_ops->csum = result_ptr->s.adler32; 158 + break; 159 + 160 + case ZLIB_FORMAT: 161 + zip_dbg("ZLIB Format: %d ", zip_ops->format); 162 + zip_ops->csum = result_ptr->s.adler32; 163 + break; 164 + 165 + case GZIP_FORMAT: 166 + zip_dbg("GZIP Format: %d ", zip_ops->format); 167 + zip_ops->csum = result_ptr->s.crc32; 168 + break; 169 + 170 + case LZS_FORMAT: 171 + zip_dbg("LZS Format: %d ", zip_ops->format); 172 + break; 173 + 174 + default: 175 + zip_err("Unknown Format:%d\n", zip_ops->format); 176 + } 177 + 178 + /* Update output_len */ 179 + if (zip_ops->output_len < result_ptr->s.totalbyteswritten) { 180 + /* Dynamic stop && strm->output_len < zipconstants[onfsize] */ 181 + zip_err("output_len (%d) < total bytes written(%d)\n", 182 + zip_ops->output_len, result_ptr->s.totalbyteswritten); 183 + zip_ops->output_len = 0; 184 + 185 + } else { 186 + zip_ops->output_len = result_ptr->s.totalbyteswritten; 187 + } 188 + 189 + return 0; 190 + }
+62
drivers/crypto/cavium/zip/zip_deflate.h
··· 1 + /***********************license start************************************ 2 + * Copyright (c) 2003-2017 Cavium, Inc. 3 + * All rights reserved. 4 + * 5 + * License: one of 'Cavium License' or 'GNU General Public License Version 2' 6 + * 7 + * This file is provided under the terms of the Cavium License (see below) 8 + * or under the terms of GNU General Public License, Version 2, as 9 + * published by the Free Software Foundation. When using or redistributing 10 + * this file, you may do so under either license. 11 + * 12 + * Cavium License: Redistribution and use in source and binary forms, with 13 + * or without modification, are permitted provided that the following 14 + * conditions are met: 15 + * 16 + * * Redistributions of source code must retain the above copyright 17 + * notice, this list of conditions and the following disclaimer. 18 + * 19 + * * Redistributions in binary form must reproduce the above 20 + * copyright notice, this list of conditions and the following 21 + * disclaimer in the documentation and/or other materials provided 22 + * with the distribution. 23 + * 24 + * * Neither the name of Cavium Inc. nor the names of its contributors may be 25 + * used to endorse or promote products derived from this software without 26 + * specific prior written permission. 27 + * 28 + * This Software, including technical data, may be subject to U.S. export 29 + * control laws, including the U.S. Export Administration Act and its 30 + * associated regulations, and may be subject to export or import 31 + * regulations in other countries. 32 + * 33 + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 34 + * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS 35 + * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 36 + * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 37 + * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 38 + * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) 39 + * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A 40 + * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET 41 + * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE 42 + * ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES 43 + * WITH YOU. 44 + ***********************license end**************************************/ 45 + 46 + #ifndef __ZIP_DEFLATE_H__ 47 + #define __ZIP_DEFLATE_H__ 48 + 49 + /** 50 + * zip_deflate - API to offload deflate operation to hardware 51 + * @zip_ops: Pointer to zip operation structure 52 + * @s: Pointer to the structure representing zip state 53 + * @zip_dev: Pointer to the structure representing zip device 54 + * 55 + * This function prepares the zip deflate command and submits it to the zip 56 + * engine by ringing the doorbell. 57 + * 58 + * Return: 0 if successful or error code 59 + */ 60 + int zip_deflate(struct zip_operation *zip_ops, struct zip_state *s, 61 + struct zip_device *zip_dev); 62 + #endif
+1
drivers/crypto/cavium/zip/zip_device.c
··· 44 44 ***********************license end**************************************/ 45 45 46 46 #include "common.h" 47 + #include "zip_deflate.h" 47 48 48 49 /** 49 50 * zip_cmd_queue_consumed - Calculates the space consumed in the command queue.
+211
drivers/crypto/cavium/zip/zip_inflate.c
··· 1 + /***********************license start************************************ 2 + * Copyright (c) 2003-2017 Cavium, Inc. 3 + * All rights reserved. 4 + * 5 + * License: one of 'Cavium License' or 'GNU General Public License Version 2' 6 + * 7 + * This file is provided under the terms of the Cavium License (see below) 8 + * or under the terms of GNU General Public License, Version 2, as 9 + * published by the Free Software Foundation. When using or redistributing 10 + * this file, you may do so under either license. 11 + * 12 + * Cavium License: Redistribution and use in source and binary forms, with 13 + * or without modification, are permitted provided that the following 14 + * conditions are met: 15 + * 16 + * * Redistributions of source code must retain the above copyright 17 + * notice, this list of conditions and the following disclaimer. 18 + * 19 + * * Redistributions in binary form must reproduce the above 20 + * copyright notice, this list of conditions and the following 21 + * disclaimer in the documentation and/or other materials provided 22 + * with the distribution. 23 + * 24 + * * Neither the name of Cavium Inc. nor the names of its contributors may be 25 + * used to endorse or promote products derived from this software without 26 + * specific prior written permission. 27 + * 28 + * This Software, including technical data, may be subject to U.S. export 29 + * control laws, including the U.S. Export Administration Act and its 30 + * associated regulations, and may be subject to export or import 31 + * regulations in other countries. 32 + * 33 + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 34 + * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS 35 + * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 36 + * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 37 + * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 38 + * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) 39 + * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A 40 + * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET 41 + * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE 42 + * ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES 43 + * WITH YOU. 44 + ***********************license end**************************************/ 45 + 46 + #include <linux/delay.h> 47 + #include <linux/sched.h> 48 + 49 + #include "common.h" 50 + #include "zip_inflate.h" 51 + 52 + static int prepare_inflate_zcmd(struct zip_operation *zip_ops, 53 + struct zip_state *s, union zip_inst_s *zip_cmd) 54 + { 55 + union zip_zres_s *result_ptr = &s->result; 56 + 57 + memset(zip_cmd, 0, sizeof(s->zip_cmd)); 58 + memset(result_ptr, 0, sizeof(s->result)); 59 + 60 + /* IWORD#0 */ 61 + 62 + /* Decompression History Gather list - no gather list */ 63 + zip_cmd->s.hg = 0; 64 + /* For decompression, CE must be 0x0. */ 65 + zip_cmd->s.ce = 0; 66 + /* For decompression, SS must be 0x0. */ 67 + zip_cmd->s.ss = 0; 68 + /* For decompression, SF should always be set. */ 69 + zip_cmd->s.sf = 1; 70 + 71 + /* Begin File */ 72 + if (zip_ops->begin_file == 0) 73 + zip_cmd->s.bf = 0; 74 + else 75 + zip_cmd->s.bf = 1; 76 + 77 + zip_cmd->s.ef = 1; 78 + /* 0: for Deflate decompression, 3: for LZS decompression */ 79 + zip_cmd->s.cc = zip_ops->ccode; 80 + 81 + /* IWORD #1*/ 82 + 83 + /* adler checksum */ 84 + zip_cmd->s.adlercrc32 = zip_ops->csum; 85 + 86 + /* 87 + * HISTORYLENGTH must be 0x0 for any ZIP decompress operation. 88 + * History data is added to a decompression operation via IWORD3. 89 + */ 90 + zip_cmd->s.historylength = 0; 91 + zip_cmd->s.ds = 0; 92 + 93 + /* IWORD # 8 and 9 - Output pointer */ 94 + zip_cmd->s.out_ptr_addr.s.addr = __pa(zip_ops->output); 95 + zip_cmd->s.out_ptr_ctl.s.length = zip_ops->output_len; 96 + 97 + /* Maximum number of output-stream bytes that can be written */ 98 + zip_cmd->s.totaloutputlength = zip_ops->output_len; 99 + 100 + zip_dbg("Data Direct Input case "); 101 + 102 + /* IWORD # 6 and 7 - input pointer */ 103 + zip_cmd->s.dg = 0; 104 + zip_cmd->s.inp_ptr_addr.s.addr = __pa((u8 *)zip_ops->input); 105 + zip_cmd->s.inp_ptr_ctl.s.length = zip_ops->input_len; 106 + 107 + /* IWORD # 10 and 11 - Result pointer */ 108 + zip_cmd->s.res_ptr_addr.s.addr = __pa(result_ptr); 109 + 110 + /* Clearing completion code */ 111 + result_ptr->s.compcode = 0; 112 + 113 + /* Returning 0 for time being.*/ 114 + return 0; 115 + } 116 + 117 + /** 118 + * zip_inflate - API to offload inflate operation to hardware 119 + * @zip_ops: Pointer to zip operation structure 120 + * @s: Pointer to the structure representing zip state 121 + * @zip_dev: Pointer to zip device structure 122 + * 123 + * This function prepares the zip inflate command and submits it to the zip 124 + * engine for processing. 125 + * 126 + * Return: 0 if successful or error code 127 + */ 128 + int zip_inflate(struct zip_operation *zip_ops, struct zip_state *s, 129 + struct zip_device *zip_dev) 130 + { 131 + union zip_inst_s *zip_cmd = &s->zip_cmd; 132 + union zip_zres_s *result_ptr = &s->result; 133 + u32 queue; 134 + 135 + /* Prepare inflate zip command */ 136 + prepare_inflate_zcmd(zip_ops, s, zip_cmd); 137 + 138 + /* Load inflate command to zip queue and ring the doorbell */ 139 + queue = zip_load_instr(zip_cmd, zip_dev); 140 + 141 + while (!result_ptr->s.compcode) 142 + continue; 143 + 144 + zip_ops->compcode = result_ptr->s.compcode; 145 + switch (zip_ops->compcode) { 146 + case ZIP_CMD_NOTDONE: 147 + zip_dbg("Zip Instruction not yet completed\n"); 148 + return ZIP_ERROR; 149 + 150 + case ZIP_CMD_SUCCESS: 151 + zip_dbg("Zip Instruction completed successfully\n"); 152 + break; 153 + 154 + case ZIP_CMD_DYNAMIC_STOP: 155 + zip_dbg(" Dynamic stop Initiated\n"); 156 + break; 157 + 158 + default: 159 + zip_dbg("Instruction failed. Code = %d\n", zip_ops->compcode); 160 + zip_update_cmd_bufs(zip_dev, queue); 161 + return ZIP_ERROR; 162 + } 163 + 164 + zip_update_cmd_bufs(zip_dev, queue); 165 + 166 + if ((zip_ops->ccode == 3) && (zip_ops->flush == 4) && 167 + (zip_ops->compcode != ZIP_CMD_DYNAMIC_STOP)) 168 + result_ptr->s.ef = 1; 169 + 170 + zip_ops->csum = result_ptr->s.adler32; 171 + 172 + if (zip_ops->output_len < result_ptr->s.totalbyteswritten) { 173 + zip_err("output_len (%d) < total bytes written (%d)\n", 174 + zip_ops->output_len, result_ptr->s.totalbyteswritten); 175 + zip_ops->output_len = 0; 176 + } else { 177 + zip_ops->output_len = result_ptr->s.totalbyteswritten; 178 + } 179 + 180 + zip_ops->bytes_read = result_ptr->s.totalbytesread; 181 + zip_ops->bits_processed = result_ptr->s.totalbitsprocessed; 182 + zip_ops->end_file = result_ptr->s.ef; 183 + if (zip_ops->end_file) { 184 + switch (zip_ops->format) { 185 + case RAW_FORMAT: 186 + zip_dbg("RAW Format: %d ", zip_ops->format); 187 + /* Get checksum from engine */ 188 + zip_ops->csum = result_ptr->s.adler32; 189 + break; 190 + 191 + case ZLIB_FORMAT: 192 + zip_dbg("ZLIB Format: %d ", zip_ops->format); 193 + zip_ops->csum = result_ptr->s.adler32; 194 + break; 195 + 196 + case GZIP_FORMAT: 197 + zip_dbg("GZIP Format: %d ", zip_ops->format); 198 + zip_ops->csum = result_ptr->s.crc32; 199 + break; 200 + 201 + case LZS_FORMAT: 202 + zip_dbg("LZS Format: %d ", zip_ops->format); 203 + break; 204 + 205 + default: 206 + zip_err("Format error:%d\n", zip_ops->format); 207 + } 208 + } 209 + 210 + return 0; 211 + }
+62
drivers/crypto/cavium/zip/zip_inflate.h
··· 1 + /***********************license start************************************ 2 + * Copyright (c) 2003-2017 Cavium, Inc. 3 + * All rights reserved. 4 + * 5 + * License: one of 'Cavium License' or 'GNU General Public License Version 2' 6 + * 7 + * This file is provided under the terms of the Cavium License (see below) 8 + * or under the terms of GNU General Public License, Version 2, as 9 + * published by the Free Software Foundation. When using or redistributing 10 + * this file, you may do so under either license. 11 + * 12 + * Cavium License: Redistribution and use in source and binary forms, with 13 + * or without modification, are permitted provided that the following 14 + * conditions are met: 15 + * 16 + * * Redistributions of source code must retain the above copyright 17 + * notice, this list of conditions and the following disclaimer. 18 + * 19 + * * Redistributions in binary form must reproduce the above 20 + * copyright notice, this list of conditions and the following 21 + * disclaimer in the documentation and/or other materials provided 22 + * with the distribution. 23 + * 24 + * * Neither the name of Cavium Inc. nor the names of its contributors may be 25 + * used to endorse or promote products derived from this software without 26 + * specific prior written permission. 27 + * 28 + * This Software, including technical data, may be subject to U.S. export 29 + * control laws, including the U.S. Export Administration Act and its 30 + * associated regulations, and may be subject to export or import 31 + * regulations in other countries. 32 + * 33 + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 34 + * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS 35 + * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 36 + * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 37 + * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 38 + * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) 39 + * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A 40 + * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET 41 + * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE 42 + * ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES 43 + * WITH YOU. 44 + ***********************license end**************************************/ 45 + 46 + #ifndef __ZIP_INFLATE_H__ 47 + #define __ZIP_INFLATE_H__ 48 + 49 + /** 50 + * zip_inflate - API to offload inflate operation to hardware 51 + * @zip_ops: Pointer to zip operation structure 52 + * @s: Pointer to the structure representing zip state 53 + * @zip_dev: Pointer to the structure representing zip device 54 + * 55 + * This function prepares the zip inflate command and submits it to the zip 56 + * engine for processing. 57 + * 58 + * Return: 0 if successful or error code 59 + */ 60 + int zip_inflate(struct zip_operation *zip_ops, struct zip_state *s, 61 + struct zip_device *zip_dev); 62 + #endif
-57
drivers/crypto/cavium/zip/zip_main.c
··· 339 339 zip_dev[zip->index] = NULL; 340 340 } 341 341 342 - /* Dummy Functions */ 343 - int zip_alloc_comp_ctx_deflate(struct crypto_tfm *tfm) 344 - { 345 - return 0; 346 - } 347 - 348 - int zip_alloc_comp_ctx_lzs(struct crypto_tfm *tfm) 349 - { 350 - return 0; 351 - } 352 - 353 - void zip_free_comp_ctx(struct crypto_tfm *tfm) 354 - { 355 - } 356 - 357 - int zip_comp_compress(struct crypto_tfm *tfm, 358 - const u8 *src, unsigned int slen, 359 - u8 *dst, unsigned int *dlen) 360 - { 361 - return 0; 362 - } 363 - 364 - int zip_comp_decompress(struct crypto_tfm *tfm, 365 - const u8 *src, unsigned int slen, 366 - u8 *dst, unsigned int *dlen) 367 - { 368 - return 0; 369 - } 370 - 371 - void *zip_alloc_scomp_ctx_deflate(struct crypto_scomp *tfm) 372 - { 373 - return NULL; 374 - } 375 - 376 - void *zip_alloc_scomp_ctx_lzs(struct crypto_scomp *tfm) 377 - { 378 - return NULL; 379 - } 380 - 381 - void zip_free_scomp_ctx(struct crypto_scomp *tfm, void *zip_ctx) 382 - { 383 - } 384 - 385 - int zip_scomp_compress(struct crypto_scomp *tfm, 386 - const u8 *src, unsigned int slen, 387 - u8 *dst, unsigned int *dlen, void *ctx) 388 - { 389 - return 0; 390 - } 391 - 392 - int zip_scomp_decompress(struct crypto_scomp *tfm, 393 - const u8 *src, unsigned int slen, 394 - u8 *dst, unsigned int *dlen, void *ctx) 395 - { 396 - return 0; 397 - } 398 - 399 342 /* PCI Sub-System Interface */ 400 343 static struct pci_driver zip_driver = { 401 344 .name = DRV_NAME,