18c2ecf20Sopenharmony_ci/***********************license start************************************ 28c2ecf20Sopenharmony_ci * Copyright (c) 2003-2017 Cavium, Inc. 38c2ecf20Sopenharmony_ci * All rights reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * License: one of 'Cavium License' or 'GNU General Public License Version 2' 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * This file is provided under the terms of the Cavium License (see below) 88c2ecf20Sopenharmony_ci * or under the terms of GNU General Public License, Version 2, as 98c2ecf20Sopenharmony_ci * published by the Free Software Foundation. When using or redistributing 108c2ecf20Sopenharmony_ci * this file, you may do so under either license. 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Cavium License: Redistribution and use in source and binary forms, with 138c2ecf20Sopenharmony_ci * or without modification, are permitted provided that the following 148c2ecf20Sopenharmony_ci * conditions are met: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * * Redistributions of source code must retain the above copyright 178c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * * Redistributions in binary form must reproduce the above 208c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 218c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials provided 228c2ecf20Sopenharmony_ci * with the distribution. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * * Neither the name of Cavium Inc. nor the names of its contributors may be 258c2ecf20Sopenharmony_ci * used to endorse or promote products derived from this software without 268c2ecf20Sopenharmony_ci * specific prior written permission. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * This Software, including technical data, may be subject to U.S. export 298c2ecf20Sopenharmony_ci * control laws, including the U.S. Export Administration Act and its 308c2ecf20Sopenharmony_ci * associated regulations, and may be subject to export or import 318c2ecf20Sopenharmony_ci * regulations in other countries. 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 348c2ecf20Sopenharmony_ci * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS 358c2ecf20Sopenharmony_ci * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 368c2ecf20Sopenharmony_ci * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 378c2ecf20Sopenharmony_ci * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 388c2ecf20Sopenharmony_ci * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) 398c2ecf20Sopenharmony_ci * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A 408c2ecf20Sopenharmony_ci * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET 418c2ecf20Sopenharmony_ci * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE 428c2ecf20Sopenharmony_ci * ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES 438c2ecf20Sopenharmony_ci * WITH YOU. 448c2ecf20Sopenharmony_ci ***********************license end**************************************/ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#ifndef __COMMON_H__ 478c2ecf20Sopenharmony_ci#define __COMMON_H__ 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#include <linux/delay.h> 508c2ecf20Sopenharmony_ci#include <linux/init.h> 518c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 528c2ecf20Sopenharmony_ci#include <linux/io.h> 538c2ecf20Sopenharmony_ci#include <linux/kernel.h> 548c2ecf20Sopenharmony_ci#include <linux/module.h> 558c2ecf20Sopenharmony_ci#include <linux/pci.h> 568c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 578c2ecf20Sopenharmony_ci#include <linux/string.h> 588c2ecf20Sopenharmony_ci#include <linux/types.h> 598c2ecf20Sopenharmony_ci#include <linux/version.h> 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/* Device specific zlib function definitions */ 628c2ecf20Sopenharmony_ci#include "zip_device.h" 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* ZIP device definitions */ 658c2ecf20Sopenharmony_ci#include "zip_main.h" 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* ZIP memory allocation/deallocation related definitions */ 688c2ecf20Sopenharmony_ci#include "zip_mem.h" 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Device specific structure definitions */ 718c2ecf20Sopenharmony_ci#include "zip_regs.h" 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define ZIP_ERROR -1 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define ZIP_FLUSH_FINISH 4 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#define RAW_FORMAT 0 /* for rawpipe */ 788c2ecf20Sopenharmony_ci#define ZLIB_FORMAT 1 /* for zpipe */ 798c2ecf20Sopenharmony_ci#define GZIP_FORMAT 2 /* for gzpipe */ 808c2ecf20Sopenharmony_ci#define LZS_FORMAT 3 /* for lzspipe */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* Max number of ZIP devices supported */ 838c2ecf20Sopenharmony_ci#define MAX_ZIP_DEVICES 2 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* Configures the number of zip queues to be used */ 868c2ecf20Sopenharmony_ci#define ZIP_NUM_QUEUES 2 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define DYNAMIC_STOP_EXCESS 1024 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/* Maximum buffer sizes in direct mode */ 918c2ecf20Sopenharmony_ci#define MAX_INPUT_BUFFER_SIZE (64 * 1024) 928c2ecf20Sopenharmony_ci#define MAX_OUTPUT_BUFFER_SIZE (64 * 1024) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/** 958c2ecf20Sopenharmony_ci * struct zip_operation - common data structure for comp and decomp operations 968c2ecf20Sopenharmony_ci * @input: Next input byte is read from here 978c2ecf20Sopenharmony_ci * @output: Next output byte written here 988c2ecf20Sopenharmony_ci * @ctx_addr: Inflate context buffer address 998c2ecf20Sopenharmony_ci * @history: Pointer to the history buffer 1008c2ecf20Sopenharmony_ci * @input_len: Number of bytes available at next_in 1018c2ecf20Sopenharmony_ci * @input_total_len: Total number of input bytes read 1028c2ecf20Sopenharmony_ci * @output_len: Remaining free space at next_out 1038c2ecf20Sopenharmony_ci * @output_total_len: Total number of bytes output so far 1048c2ecf20Sopenharmony_ci * @csum: Checksum value of the uncompressed data 1058c2ecf20Sopenharmony_ci * @flush: Flush flag 1068c2ecf20Sopenharmony_ci * @format: Format (depends on stream's wrap) 1078c2ecf20Sopenharmony_ci * @speed: Speed depends on stream's level 1088c2ecf20Sopenharmony_ci * @ccode: Compression code ( stream's strategy) 1098c2ecf20Sopenharmony_ci * @lzs_flag: Flag for LZS support 1108c2ecf20Sopenharmony_ci * @begin_file: Beginning of file indication for inflate 1118c2ecf20Sopenharmony_ci * @history_len: Size of the history data 1128c2ecf20Sopenharmony_ci * @end_file: Ending of the file indication for inflate 1138c2ecf20Sopenharmony_ci * @compcode: Completion status of the ZIP invocation 1148c2ecf20Sopenharmony_ci * @bytes_read: Input bytes read in current instruction 1158c2ecf20Sopenharmony_ci * @bits_processed: Total bits processed for entire file 1168c2ecf20Sopenharmony_ci * @sizeofptr: To distinguish between ILP32 and LP64 1178c2ecf20Sopenharmony_ci * @sizeofzops: Optional just for padding 1188c2ecf20Sopenharmony_ci * 1198c2ecf20Sopenharmony_ci * This structure is used to maintain the required meta data for the 1208c2ecf20Sopenharmony_ci * comp and decomp operations. 1218c2ecf20Sopenharmony_ci */ 1228c2ecf20Sopenharmony_cistruct zip_operation { 1238c2ecf20Sopenharmony_ci u8 *input; 1248c2ecf20Sopenharmony_ci u8 *output; 1258c2ecf20Sopenharmony_ci u64 ctx_addr; 1268c2ecf20Sopenharmony_ci u64 history; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci u32 input_len; 1298c2ecf20Sopenharmony_ci u32 input_total_len; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci u32 output_len; 1328c2ecf20Sopenharmony_ci u32 output_total_len; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci u32 csum; 1358c2ecf20Sopenharmony_ci u32 flush; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci u32 format; 1388c2ecf20Sopenharmony_ci u32 speed; 1398c2ecf20Sopenharmony_ci u32 ccode; 1408c2ecf20Sopenharmony_ci u32 lzs_flag; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci u32 begin_file; 1438c2ecf20Sopenharmony_ci u32 history_len; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci u32 end_file; 1468c2ecf20Sopenharmony_ci u32 compcode; 1478c2ecf20Sopenharmony_ci u32 bytes_read; 1488c2ecf20Sopenharmony_ci u32 bits_processed; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci u32 sizeofptr; 1518c2ecf20Sopenharmony_ci u32 sizeofzops; 1528c2ecf20Sopenharmony_ci}; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic inline int zip_poll_result(union zip_zres_s *result) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci int retries = 1000; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci while (!result->s.compcode) { 1598c2ecf20Sopenharmony_ci if (!--retries) { 1608c2ecf20Sopenharmony_ci pr_err("ZIP ERR: request timed out"); 1618c2ecf20Sopenharmony_ci return -ETIMEDOUT; 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci udelay(10); 1648c2ecf20Sopenharmony_ci /* 1658c2ecf20Sopenharmony_ci * Force re-reading of compcode which is updated 1668c2ecf20Sopenharmony_ci * by the ZIP coprocessor. 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_ci rmb(); 1698c2ecf20Sopenharmony_ci } 1708c2ecf20Sopenharmony_ci return 0; 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci/* error messages */ 1748c2ecf20Sopenharmony_ci#define zip_err(fmt, args...) pr_err("ZIP ERR:%s():%d: " \ 1758c2ecf20Sopenharmony_ci fmt "\n", __func__, __LINE__, ## args) 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci#ifdef MSG_ENABLE 1788c2ecf20Sopenharmony_ci/* Enable all messages */ 1798c2ecf20Sopenharmony_ci#define zip_msg(fmt, args...) pr_info("ZIP_MSG:" fmt "\n", ## args) 1808c2ecf20Sopenharmony_ci#else 1818c2ecf20Sopenharmony_ci#define zip_msg(fmt, args...) 1828c2ecf20Sopenharmony_ci#endif 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci#if defined(ZIP_DEBUG_ENABLE) && defined(MSG_ENABLE) 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci#ifdef DEBUG_LEVEL 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci#define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : \ 1898c2ecf20Sopenharmony_ci strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci#if DEBUG_LEVEL >= 4 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s: %s() : %d: " \ 1948c2ecf20Sopenharmony_ci fmt "\n", FILE_NAME, __func__, __LINE__, ## args) 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#elif DEBUG_LEVEL >= 3 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci#define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s: %s() : %d: " \ 1998c2ecf20Sopenharmony_ci fmt "\n", FILE_NAME, __func__, __LINE__, ## args) 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci#elif DEBUG_LEVEL >= 2 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci#define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s() : %d: " \ 2048c2ecf20Sopenharmony_ci fmt "\n", __func__, __LINE__, ## args) 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci#else 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci#define zip_dbg(fmt, args...) pr_info("ZIP DBG:" fmt "\n", ## args) 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci#endif /* DEBUG LEVEL >=4 */ 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#else 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci#define zip_dbg(fmt, args...) pr_info("ZIP DBG:" fmt "\n", ## args) 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci#endif /* DEBUG_LEVEL */ 2178c2ecf20Sopenharmony_ci#else 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#define zip_dbg(fmt, args...) 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci#endif /* ZIP_DEBUG_ENABLE && MSG_ENABLE*/ 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci#endif 224