common.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #ifndef __COMMON_H__
  46. #define __COMMON_H__
  47. #include <linux/delay.h>
  48. #include <linux/init.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/io.h>
  51. #include <linux/kernel.h>
  52. #include <linux/module.h>
  53. #include <linux/pci.h>
  54. #include <linux/seq_file.h>
  55. #include <linux/string.h>
  56. #include <linux/types.h>
  57. #include <linux/version.h>
  58. /* Device specific zlib function definitions */
  59. #include "zip_device.h"
  60. /* ZIP device definitions */
  61. #include "zip_main.h"
  62. /* ZIP memory allocation/deallocation related definitions */
  63. #include "zip_mem.h"
  64. /* Device specific structure definitions */
  65. #include "zip_regs.h"
  66. #define ZIP_ERROR -1
  67. #define ZIP_FLUSH_FINISH 4
  68. #define RAW_FORMAT 0 /* for rawpipe */
  69. #define ZLIB_FORMAT 1 /* for zpipe */
  70. #define GZIP_FORMAT 2 /* for gzpipe */
  71. #define LZS_FORMAT 3 /* for lzspipe */
  72. /* Max number of ZIP devices supported */
  73. #define MAX_ZIP_DEVICES 2
  74. /* Configures the number of zip queues to be used */
  75. #define ZIP_NUM_QUEUES 2
  76. #define DYNAMIC_STOP_EXCESS 1024
  77. /* Maximum buffer sizes in direct mode */
  78. #define MAX_INPUT_BUFFER_SIZE (64 * 1024)
  79. #define MAX_OUTPUT_BUFFER_SIZE (64 * 1024)
  80. /**
  81. * struct zip_operation - common data structure for comp and decomp operations
  82. * @input: Next input byte is read from here
  83. * @output: Next output byte written here
  84. * @ctx_addr: Inflate context buffer address
  85. * @history: Pointer to the history buffer
  86. * @input_len: Number of bytes available at next_in
  87. * @input_total_len: Total number of input bytes read
  88. * @output_len: Remaining free space at next_out
  89. * @output_total_len: Total number of bytes output so far
  90. * @csum: Checksum value of the uncompressed data
  91. * @flush: Flush flag
  92. * @format: Format (depends on stream's wrap)
  93. * @speed: Speed depends on stream's level
  94. * @ccode: Compression code ( stream's strategy)
  95. * @lzs_flag: Flag for LZS support
  96. * @begin_file: Beginning of file indication for inflate
  97. * @history_len: Size of the history data
  98. * @end_file: Ending of the file indication for inflate
  99. * @compcode: Completion status of the ZIP invocation
  100. * @bytes_read: Input bytes read in current instruction
  101. * @bits_processed: Total bits processed for entire file
  102. * @sizeofptr: To distinguish between ILP32 and LP64
  103. * @sizeofzops: Optional just for padding
  104. *
  105. * This structure is used to maintain the required meta data for the
  106. * comp and decomp operations.
  107. */
  108. struct zip_operation {
  109. u8 *input;
  110. u8 *output;
  111. u64 ctx_addr;
  112. u64 history;
  113. u32 input_len;
  114. u32 input_total_len;
  115. u32 output_len;
  116. u32 output_total_len;
  117. u32 csum;
  118. u32 flush;
  119. u32 format;
  120. u32 speed;
  121. u32 ccode;
  122. u32 lzs_flag;
  123. u32 begin_file;
  124. u32 history_len;
  125. u32 end_file;
  126. u32 compcode;
  127. u32 bytes_read;
  128. u32 bits_processed;
  129. u32 sizeofptr;
  130. u32 sizeofzops;
  131. };
  132. static inline int zip_poll_result(union zip_zres_s *result)
  133. {
  134. int retries = 1000;
  135. while (!result->s.compcode) {
  136. if (!--retries) {
  137. pr_err("ZIP ERR: request timed out");
  138. return -ETIMEDOUT;
  139. }
  140. udelay(10);
  141. /*
  142. * Force re-reading of compcode which is updated
  143. * by the ZIP coprocessor.
  144. */
  145. rmb();
  146. }
  147. return 0;
  148. }
  149. /* error messages */
  150. #define zip_err(fmt, args...) pr_err("ZIP ERR:%s():%d: " \
  151. fmt "\n", __func__, __LINE__, ## args)
  152. #ifdef MSG_ENABLE
  153. /* Enable all messages */
  154. #define zip_msg(fmt, args...) pr_info("ZIP_MSG:" fmt "\n", ## args)
  155. #else
  156. #define zip_msg(fmt, args...)
  157. #endif
  158. #if defined(ZIP_DEBUG_ENABLE) && defined(MSG_ENABLE)
  159. #ifdef DEBUG_LEVEL
  160. #define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : \
  161. strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
  162. #if DEBUG_LEVEL >= 4
  163. #define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s: %s() : %d: " \
  164. fmt "\n", FILE_NAME, __func__, __LINE__, ## args)
  165. #elif DEBUG_LEVEL >= 3
  166. #define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s: %s() : %d: " \
  167. fmt "\n", FILE_NAME, __func__, __LINE__, ## args)
  168. #elif DEBUG_LEVEL >= 2
  169. #define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s() : %d: " \
  170. fmt "\n", __func__, __LINE__, ## args)
  171. #else
  172. #define zip_dbg(fmt, args...) pr_info("ZIP DBG:" fmt "\n", ## args)
  173. #endif /* DEBUG LEVEL >=4 */
  174. #else
  175. #define zip_dbg(fmt, args...) pr_info("ZIP DBG:" fmt "\n", ## args)
  176. #endif /* DEBUG_LEVEL */
  177. #else
  178. #define zip_dbg(fmt, args...)
  179. #endif /* ZIP_DEBUG_ENABLE && MSG_ENABLE*/
  180. #endif