Skip to content

Commit 640035a

Browse files
Mahipal Challaherbertx
authored andcommitted
crypto: zip - Add ThunderX ZIP driver core
Add a driver for the ZIP engine found on Cavium ThunderX SOCs. The ZIP engine supports hardware accelerated compression and decompression. It includes 2 independent ZIP cores and supports: - DEFLATE compression and decompression (RFC 1951) - LZS compression and decompression (RFC 2395 and ANSI X3.241-1994) - ADLER32 and CRC32 checksums for ZLIB (RFC 1950) and GZIP (RFC 1952) The ZIP engine is presented as a PCI device. It supports DMA and scatter-gather. 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>
1 parent 27c539a commit 640035a

File tree

13 files changed

+2805
-0
lines changed

13 files changed

+2805
-0
lines changed

drivers/crypto/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,13 @@ config CRYPTO_DEV_MXS_DCP
515515
source "drivers/crypto/qat/Kconfig"
516516
source "drivers/crypto/cavium/cpt/Kconfig"
517517

518+
config CRYPTO_DEV_CAVIUM_ZIP
519+
tristate "Cavium ZIP driver"
520+
depends on PCI && 64BIT && (ARM64 || COMPILE_TEST)
521+
---help---
522+
Select this option if you want to enable compression/decompression
523+
acceleration on Cavium's ARM based SoCs
524+
518525
config CRYPTO_DEV_QCE
519526
tristate "Qualcomm crypto engine accelerator"
520527
depends on (ARCH_QCOM || COMPILE_TEST) && HAS_DMA && HAS_IOMEM

drivers/crypto/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ obj-$(CONFIG_CRYPTO_DEV_ATMEL_AES) += atmel-aes.o
22
obj-$(CONFIG_CRYPTO_DEV_ATMEL_SHA) += atmel-sha.o
33
obj-$(CONFIG_CRYPTO_DEV_ATMEL_TDES) += atmel-tdes.o
44
obj-$(CONFIG_CRYPTO_DEV_BFIN_CRC) += bfin_crc.o
5+
obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += cavium/
56
obj-$(CONFIG_CRYPTO_DEV_CCP) += ccp/
67
obj-$(CONFIG_CRYPTO_DEV_CHELSIO) += chelsio/
78
obj-$(CONFIG_CRYPTO_DEV_CPT) += cavium/cpt/

drivers/crypto/cavium/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#
2+
# Makefile for Cavium crypto device drivers
3+
#
4+
obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += zip/

drivers/crypto/cavium/zip/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Makefile for Cavium's ZIP Driver.
3+
#
4+
5+
obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += thunderx_zip.o
6+
thunderx_zip-y := zip_main.o \
7+
zip_device.o \
8+
zip_mem.o

drivers/crypto/cavium/zip/common.h

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

0 commit comments

Comments
 (0)