Loading...
Note: File does not exist in v6.2.
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
3
4#ifndef __IAA_CRYPTO_H__
5#define __IAA_CRYPTO_H__
6
7#include <linux/crypto.h>
8#include <linux/idxd.h>
9#include <uapi/linux/idxd.h>
10
11#define IDXD_SUBDRIVER_NAME "crypto"
12
13#define IAA_DECOMP_ENABLE BIT(0)
14#define IAA_DECOMP_FLUSH_OUTPUT BIT(1)
15#define IAA_DECOMP_CHECK_FOR_EOB BIT(2)
16#define IAA_DECOMP_STOP_ON_EOB BIT(3)
17#define IAA_DECOMP_SUPPRESS_OUTPUT BIT(9)
18
19#define IAA_COMP_FLUSH_OUTPUT BIT(1)
20#define IAA_COMP_APPEND_EOB BIT(2)
21
22#define IAA_COMPLETION_TIMEOUT 1000000
23
24#define IAA_ANALYTICS_ERROR 0x0a
25#define IAA_ERROR_DECOMP_BUF_OVERFLOW 0x0b
26#define IAA_ERROR_COMP_BUF_OVERFLOW 0x19
27#define IAA_ERROR_WATCHDOG_EXPIRED 0x24
28
29#define IAA_COMP_MODES_MAX 2
30
31#define FIXED_HDR 0x2
32#define FIXED_HDR_SIZE 3
33
34#define IAA_COMP_FLAGS (IAA_COMP_FLUSH_OUTPUT | \
35 IAA_COMP_APPEND_EOB)
36
37#define IAA_DECOMP_FLAGS (IAA_DECOMP_ENABLE | \
38 IAA_DECOMP_FLUSH_OUTPUT | \
39 IAA_DECOMP_CHECK_FOR_EOB | \
40 IAA_DECOMP_STOP_ON_EOB)
41
42/* Representation of IAA workqueue */
43struct iaa_wq {
44 struct list_head list;
45
46 struct idxd_wq *wq;
47 int ref;
48 bool remove;
49
50 struct iaa_device *iaa_device;
51
52 u64 comp_calls;
53 u64 comp_bytes;
54 u64 decomp_calls;
55 u64 decomp_bytes;
56};
57
58struct iaa_device_compression_mode {
59 const char *name;
60
61 struct aecs_comp_table_record *aecs_comp_table;
62 struct aecs_decomp_table_record *aecs_decomp_table;
63
64 dma_addr_t aecs_comp_table_dma_addr;
65 dma_addr_t aecs_decomp_table_dma_addr;
66};
67
68/* Representation of IAA device with wqs, populated by probe */
69struct iaa_device {
70 struct list_head list;
71 struct idxd_device *idxd;
72
73 struct iaa_device_compression_mode *compression_modes[IAA_COMP_MODES_MAX];
74
75 int n_wq;
76 struct list_head wqs;
77
78 u64 comp_calls;
79 u64 comp_bytes;
80 u64 decomp_calls;
81 u64 decomp_bytes;
82};
83
84struct wq_table_entry {
85 struct idxd_wq **wqs;
86 int max_wqs;
87 int n_wqs;
88 int cur_wq;
89};
90
91#define IAA_AECS_ALIGN 32
92
93/*
94 * Analytics Engine Configuration and State (AECS) contains parameters and
95 * internal state of the analytics engine.
96 */
97struct aecs_comp_table_record {
98 u32 crc;
99 u32 xor_checksum;
100 u32 reserved0[5];
101 u32 num_output_accum_bits;
102 u8 output_accum[256];
103 u32 ll_sym[286];
104 u32 reserved1;
105 u32 reserved2;
106 u32 d_sym[30];
107 u32 reserved_padding[2];
108} __packed;
109
110/* AECS for decompress */
111struct aecs_decomp_table_record {
112 u32 crc;
113 u32 xor_checksum;
114 u32 low_filter_param;
115 u32 high_filter_param;
116 u32 output_mod_idx;
117 u32 drop_init_decomp_out_bytes;
118 u32 reserved[36];
119 u32 output_accum_data[2];
120 u32 out_bits_valid;
121 u32 bit_off_indexing;
122 u32 input_accum_data[64];
123 u8 size_qw[32];
124 u32 decomp_state[1220];
125} __packed;
126
127int iaa_aecs_init_fixed(void);
128void iaa_aecs_cleanup_fixed(void);
129
130typedef int (*iaa_dev_comp_init_fn_t) (struct iaa_device_compression_mode *mode);
131typedef int (*iaa_dev_comp_free_fn_t) (struct iaa_device_compression_mode *mode);
132
133struct iaa_compression_mode {
134 const char *name;
135 u32 *ll_table;
136 int ll_table_size;
137 u32 *d_table;
138 int d_table_size;
139 u32 *header_table;
140 int header_table_size;
141 u16 gen_decomp_table_flags;
142 iaa_dev_comp_init_fn_t init;
143 iaa_dev_comp_free_fn_t free;
144};
145
146int add_iaa_compression_mode(const char *name,
147 const u32 *ll_table,
148 int ll_table_size,
149 const u32 *d_table,
150 int d_table_size,
151 const u8 *header_table,
152 int header_table_size,
153 u16 gen_decomp_table_flags,
154 iaa_dev_comp_init_fn_t init,
155 iaa_dev_comp_free_fn_t free);
156
157void remove_iaa_compression_mode(const char *name);
158
159enum iaa_mode {
160 IAA_MODE_FIXED,
161};
162
163struct iaa_compression_ctx {
164 enum iaa_mode mode;
165 bool verify_compress;
166 bool async_mode;
167 bool use_irq;
168};
169
170extern struct list_head iaa_devices;
171extern struct mutex iaa_devices_lock;
172
173#endif