Skip to content

Commit b190447

Browse files
tzanussiherbertx
authored andcommitted
crypto: iaa - Add compression mode management along with fixed mode
Define an in-kernel API for adding and removing compression modes, which can be used by kernel modules or other kernel code that implements IAA compression modes. Also add a separate file, iaa_crypto_comp_fixed.c, containing huffman tables generated for the IAA 'fixed' compression mode. Future compression modes can be added in a similar fashion. One or more crypto compression algorithms will be created for each compression mode, each of which can be selected as the compression algorithm to be used by a particular facility. Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f57bf3f commit b190447

File tree

4 files changed

+504
-2
lines changed

4 files changed

+504
-2
lines changed

drivers/crypto/intel/iaa/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ ccflags-y += -I $(srctree)/drivers/dma/idxd -DDEFAULT_SYMBOL_NAMESPACE=IDXD
77

88
obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) := iaa_crypto.o
99

10-
iaa_crypto-y := iaa_crypto_main.o
10+
iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o

drivers/crypto/intel/iaa/iaa_crypto.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
#define IDXD_SUBDRIVER_NAME "crypto"
1212

13+
#define IAA_COMP_MODES_MAX 2
14+
15+
#define FIXED_HDR 0x2
16+
#define FIXED_HDR_SIZE 3
17+
1318
/* Representation of IAA workqueue */
1419
struct iaa_wq {
1520
struct list_head list;
@@ -18,11 +23,23 @@ struct iaa_wq {
1823
struct iaa_device *iaa_device;
1924
};
2025

26+
struct iaa_device_compression_mode {
27+
const char *name;
28+
29+
struct aecs_comp_table_record *aecs_comp_table;
30+
struct aecs_decomp_table_record *aecs_decomp_table;
31+
32+
dma_addr_t aecs_comp_table_dma_addr;
33+
dma_addr_t aecs_decomp_table_dma_addr;
34+
};
35+
2136
/* Representation of IAA device with wqs, populated by probe */
2237
struct iaa_device {
2338
struct list_head list;
2439
struct idxd_device *idxd;
2540

41+
struct iaa_device_compression_mode *compression_modes[IAA_COMP_MODES_MAX];
42+
2643
int n_wq;
2744
struct list_head wqs;
2845
};
@@ -34,4 +51,72 @@ struct wq_table_entry {
3451
int cur_wq;
3552
};
3653

54+
#define IAA_AECS_ALIGN 32
55+
56+
/*
57+
* Analytics Engine Configuration and State (AECS) contains parameters and
58+
* internal state of the analytics engine.
59+
*/
60+
struct aecs_comp_table_record {
61+
u32 crc;
62+
u32 xor_checksum;
63+
u32 reserved0[5];
64+
u32 num_output_accum_bits;
65+
u8 output_accum[256];
66+
u32 ll_sym[286];
67+
u32 reserved1;
68+
u32 reserved2;
69+
u32 d_sym[30];
70+
u32 reserved_padding[2];
71+
} __packed;
72+
73+
/* AECS for decompress */
74+
struct aecs_decomp_table_record {
75+
u32 crc;
76+
u32 xor_checksum;
77+
u32 low_filter_param;
78+
u32 high_filter_param;
79+
u32 output_mod_idx;
80+
u32 drop_init_decomp_out_bytes;
81+
u32 reserved[36];
82+
u32 output_accum_data[2];
83+
u32 out_bits_valid;
84+
u32 bit_off_indexing;
85+
u32 input_accum_data[64];
86+
u8 size_qw[32];
87+
u32 decomp_state[1220];
88+
} __packed;
89+
90+
int iaa_aecs_init_fixed(void);
91+
void iaa_aecs_cleanup_fixed(void);
92+
93+
typedef int (*iaa_dev_comp_init_fn_t) (struct iaa_device_compression_mode *mode);
94+
typedef int (*iaa_dev_comp_free_fn_t) (struct iaa_device_compression_mode *mode);
95+
96+
struct iaa_compression_mode {
97+
const char *name;
98+
u32 *ll_table;
99+
int ll_table_size;
100+
u32 *d_table;
101+
int d_table_size;
102+
u32 *header_table;
103+
int header_table_size;
104+
u16 gen_decomp_table_flags;
105+
iaa_dev_comp_init_fn_t init;
106+
iaa_dev_comp_free_fn_t free;
107+
};
108+
109+
int add_iaa_compression_mode(const char *name,
110+
const u32 *ll_table,
111+
int ll_table_size,
112+
const u32 *d_table,
113+
int d_table_size,
114+
const u8 *header_table,
115+
int header_table_size,
116+
u16 gen_decomp_table_flags,
117+
iaa_dev_comp_init_fn_t init,
118+
iaa_dev_comp_free_fn_t free);
119+
120+
void remove_iaa_compression_mode(const char *name);
121+
37122
#endif
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
3+
4+
#include "idxd.h"
5+
#include "iaa_crypto.h"
6+
7+
/*
8+
* Fixed Huffman tables the IAA hardware requires to implement RFC-1951.
9+
*/
10+
static const u32 fixed_ll_sym[286] = {
11+
0x40030, 0x40031, 0x40032, 0x40033, 0x40034, 0x40035, 0x40036, 0x40037,
12+
0x40038, 0x40039, 0x4003A, 0x4003B, 0x4003C, 0x4003D, 0x4003E, 0x4003F,
13+
0x40040, 0x40041, 0x40042, 0x40043, 0x40044, 0x40045, 0x40046, 0x40047,
14+
0x40048, 0x40049, 0x4004A, 0x4004B, 0x4004C, 0x4004D, 0x4004E, 0x4004F,
15+
0x40050, 0x40051, 0x40052, 0x40053, 0x40054, 0x40055, 0x40056, 0x40057,
16+
0x40058, 0x40059, 0x4005A, 0x4005B, 0x4005C, 0x4005D, 0x4005E, 0x4005F,
17+
0x40060, 0x40061, 0x40062, 0x40063, 0x40064, 0x40065, 0x40066, 0x40067,
18+
0x40068, 0x40069, 0x4006A, 0x4006B, 0x4006C, 0x4006D, 0x4006E, 0x4006F,
19+
0x40070, 0x40071, 0x40072, 0x40073, 0x40074, 0x40075, 0x40076, 0x40077,
20+
0x40078, 0x40079, 0x4007A, 0x4007B, 0x4007C, 0x4007D, 0x4007E, 0x4007F,
21+
0x40080, 0x40081, 0x40082, 0x40083, 0x40084, 0x40085, 0x40086, 0x40087,
22+
0x40088, 0x40089, 0x4008A, 0x4008B, 0x4008C, 0x4008D, 0x4008E, 0x4008F,
23+
0x40090, 0x40091, 0x40092, 0x40093, 0x40094, 0x40095, 0x40096, 0x40097,
24+
0x40098, 0x40099, 0x4009A, 0x4009B, 0x4009C, 0x4009D, 0x4009E, 0x4009F,
25+
0x400A0, 0x400A1, 0x400A2, 0x400A3, 0x400A4, 0x400A5, 0x400A6, 0x400A7,
26+
0x400A8, 0x400A9, 0x400AA, 0x400AB, 0x400AC, 0x400AD, 0x400AE, 0x400AF,
27+
0x400B0, 0x400B1, 0x400B2, 0x400B3, 0x400B4, 0x400B5, 0x400B6, 0x400B7,
28+
0x400B8, 0x400B9, 0x400BA, 0x400BB, 0x400BC, 0x400BD, 0x400BE, 0x400BF,
29+
0x48190, 0x48191, 0x48192, 0x48193, 0x48194, 0x48195, 0x48196, 0x48197,
30+
0x48198, 0x48199, 0x4819A, 0x4819B, 0x4819C, 0x4819D, 0x4819E, 0x4819F,
31+
0x481A0, 0x481A1, 0x481A2, 0x481A3, 0x481A4, 0x481A5, 0x481A6, 0x481A7,
32+
0x481A8, 0x481A9, 0x481AA, 0x481AB, 0x481AC, 0x481AD, 0x481AE, 0x481AF,
33+
0x481B0, 0x481B1, 0x481B2, 0x481B3, 0x481B4, 0x481B5, 0x481B6, 0x481B7,
34+
0x481B8, 0x481B9, 0x481BA, 0x481BB, 0x481BC, 0x481BD, 0x481BE, 0x481BF,
35+
0x481C0, 0x481C1, 0x481C2, 0x481C3, 0x481C4, 0x481C5, 0x481C6, 0x481C7,
36+
0x481C8, 0x481C9, 0x481CA, 0x481CB, 0x481CC, 0x481CD, 0x481CE, 0x481CF,
37+
0x481D0, 0x481D1, 0x481D2, 0x481D3, 0x481D4, 0x481D5, 0x481D6, 0x481D7,
38+
0x481D8, 0x481D9, 0x481DA, 0x481DB, 0x481DC, 0x481DD, 0x481DE, 0x481DF,
39+
0x481E0, 0x481E1, 0x481E2, 0x481E3, 0x481E4, 0x481E5, 0x481E6, 0x481E7,
40+
0x481E8, 0x481E9, 0x481EA, 0x481EB, 0x481EC, 0x481ED, 0x481EE, 0x481EF,
41+
0x481F0, 0x481F1, 0x481F2, 0x481F3, 0x481F4, 0x481F5, 0x481F6, 0x481F7,
42+
0x481F8, 0x481F9, 0x481FA, 0x481FB, 0x481FC, 0x481FD, 0x481FE, 0x481FF,
43+
0x38000, 0x38001, 0x38002, 0x38003, 0x38004, 0x38005, 0x38006, 0x38007,
44+
0x38008, 0x38009, 0x3800A, 0x3800B, 0x3800C, 0x3800D, 0x3800E, 0x3800F,
45+
0x38010, 0x38011, 0x38012, 0x38013, 0x38014, 0x38015, 0x38016, 0x38017,
46+
0x400C0, 0x400C1, 0x400C2, 0x400C3, 0x400C4, 0x400C5
47+
};
48+
49+
static const u32 fixed_d_sym[30] = {
50+
0x28000, 0x28001, 0x28002, 0x28003, 0x28004, 0x28005, 0x28006, 0x28007,
51+
0x28008, 0x28009, 0x2800A, 0x2800B, 0x2800C, 0x2800D, 0x2800E, 0x2800F,
52+
0x28010, 0x28011, 0x28012, 0x28013, 0x28014, 0x28015, 0x28016, 0x28017,
53+
0x28018, 0x28019, 0x2801A, 0x2801B, 0x2801C, 0x2801D
54+
};
55+
56+
static int init_fixed_mode(struct iaa_device_compression_mode *mode)
57+
{
58+
struct aecs_comp_table_record *comp_table = mode->aecs_comp_table;
59+
u32 bfinal = 1;
60+
u32 offset;
61+
62+
/* Configure aecs table using fixed Huffman table */
63+
comp_table->crc = 0;
64+
comp_table->xor_checksum = 0;
65+
offset = comp_table->num_output_accum_bits / 8;
66+
comp_table->output_accum[offset] = FIXED_HDR | bfinal;
67+
comp_table->num_output_accum_bits = FIXED_HDR_SIZE;
68+
69+
return 0;
70+
}
71+
72+
int iaa_aecs_init_fixed(void)
73+
{
74+
int ret;
75+
76+
ret = add_iaa_compression_mode("fixed",
77+
fixed_ll_sym,
78+
sizeof(fixed_ll_sym),
79+
fixed_d_sym,
80+
sizeof(fixed_d_sym),
81+
NULL, 0, 0,
82+
init_fixed_mode, NULL);
83+
if (!ret)
84+
pr_debug("IAA fixed compression mode initialized\n");
85+
86+
return ret;
87+
}
88+
89+
void iaa_aecs_cleanup_fixed(void)
90+
{
91+
remove_iaa_compression_mode("fixed");
92+
}

0 commit comments

Comments
 (0)