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

source code of linux/drivers/crypto/cavium/zip/common.h