13
13
#include "cc_hash.h"
14
14
#include "cc_aead.h"
15
15
16
- enum dma_buffer_type {
17
- DMA_NULL_TYPE = -1 ,
18
- DMA_SGL_TYPE = 1 ,
19
- DMA_BUFF_TYPE = 2 ,
20
- };
21
-
22
16
union buffer_array_entry {
23
17
struct scatterlist * sgl ;
24
18
dma_addr_t buffer_dma ;
@@ -30,7 +24,6 @@ struct buffer_array {
30
24
unsigned int offset [MAX_NUM_OF_BUFFERS_IN_MLLI ];
31
25
int nents [MAX_NUM_OF_BUFFERS_IN_MLLI ];
32
26
int total_data_len [MAX_NUM_OF_BUFFERS_IN_MLLI ];
33
- enum dma_buffer_type type [MAX_NUM_OF_BUFFERS_IN_MLLI ];
34
27
bool is_last [MAX_NUM_OF_BUFFERS_IN_MLLI ];
35
28
u32 * mlli_nents [MAX_NUM_OF_BUFFERS_IN_MLLI ];
36
29
};
@@ -60,11 +53,7 @@ static void cc_copy_mac(struct device *dev, struct aead_request *req,
60
53
enum cc_sg_cpy_direct dir )
61
54
{
62
55
struct aead_req_ctx * areq_ctx = aead_request_ctx (req );
63
- struct crypto_aead * tfm = crypto_aead_reqtfm (req );
64
- u32 skip = areq_ctx -> assoclen + req -> cryptlen ;
65
-
66
- if (areq_ctx -> is_gcm4543 )
67
- skip += crypto_aead_ivsize (tfm );
56
+ u32 skip = req -> assoclen + req -> cryptlen ;
68
57
69
58
cc_copy_sg_portion (dev , areq_ctx -> backup_mac , req -> src ,
70
59
(skip - areq_ctx -> req_authsize ), skip , dir );
@@ -216,14 +205,8 @@ static int cc_generate_mlli(struct device *dev, struct buffer_array *sg_data,
216
205
u32 tot_len = sg_data -> total_data_len [i ];
217
206
u32 offset = sg_data -> offset [i ];
218
207
219
- if (sg_data -> type [i ] == DMA_SGL_TYPE )
220
- rc = cc_render_sg_to_mlli (dev , entry -> sgl , tot_len ,
221
- offset , & total_nents ,
222
- & mlli_p );
223
- else /*DMA_BUFF_TYPE*/
224
- rc = cc_render_buff_to_mlli (dev , entry -> buffer_dma ,
225
- tot_len , & total_nents ,
226
- & mlli_p );
208
+ rc = cc_render_sg_to_mlli (dev , entry -> sgl , tot_len , offset ,
209
+ & total_nents , & mlli_p );
227
210
if (rc )
228
211
return rc ;
229
212
@@ -249,27 +232,6 @@ static int cc_generate_mlli(struct device *dev, struct buffer_array *sg_data,
249
232
return rc ;
250
233
}
251
234
252
- static void cc_add_buffer_entry (struct device * dev ,
253
- struct buffer_array * sgl_data ,
254
- dma_addr_t buffer_dma , unsigned int buffer_len ,
255
- bool is_last_entry , u32 * mlli_nents )
256
- {
257
- unsigned int index = sgl_data -> num_of_buffers ;
258
-
259
- dev_dbg (dev , "index=%u single_buff=%pad buffer_len=0x%08X is_last=%d\n" ,
260
- index , & buffer_dma , buffer_len , is_last_entry );
261
- sgl_data -> nents [index ] = 1 ;
262
- sgl_data -> entry [index ].buffer_dma = buffer_dma ;
263
- sgl_data -> offset [index ] = 0 ;
264
- sgl_data -> total_data_len [index ] = buffer_len ;
265
- sgl_data -> type [index ] = DMA_BUFF_TYPE ;
266
- sgl_data -> is_last [index ] = is_last_entry ;
267
- sgl_data -> mlli_nents [index ] = mlli_nents ;
268
- if (sgl_data -> mlli_nents [index ])
269
- * sgl_data -> mlli_nents [index ] = 0 ;
270
- sgl_data -> num_of_buffers ++ ;
271
- }
272
-
273
235
static void cc_add_sg_entry (struct device * dev , struct buffer_array * sgl_data ,
274
236
unsigned int nents , struct scatterlist * sgl ,
275
237
unsigned int data_len , unsigned int data_offset ,
@@ -283,7 +245,6 @@ static void cc_add_sg_entry(struct device *dev, struct buffer_array *sgl_data,
283
245
sgl_data -> entry [index ].sgl = sgl ;
284
246
sgl_data -> offset [index ] = data_offset ;
285
247
sgl_data -> total_data_len [index ] = data_len ;
286
- sgl_data -> type [index ] = DMA_SGL_TYPE ;
287
248
sgl_data -> is_last [index ] = is_last_table ;
288
249
sgl_data -> mlli_nents [index ] = mlli_nents ;
289
250
if (sgl_data -> mlli_nents [index ])
@@ -606,17 +567,6 @@ static int cc_aead_chain_iv(struct cc_drvdata *drvdata,
606
567
607
568
dev_dbg (dev , "Mapped iv %u B at va=%pK to dma=%pad\n" ,
608
569
hw_iv_size , req -> iv , & areq_ctx -> gen_ctx .iv_dma_addr );
609
- if (do_chain && areq_ctx -> plaintext_authenticate_only ) {
610
- struct crypto_aead * tfm = crypto_aead_reqtfm (req );
611
- unsigned int iv_size_to_authenc = crypto_aead_ivsize (tfm );
612
- unsigned int iv_ofs = GCM_BLOCK_RFC4_IV_OFFSET ;
613
- /* Chain to given list */
614
- cc_add_buffer_entry (dev , sg_data ,
615
- (areq_ctx -> gen_ctx .iv_dma_addr + iv_ofs ),
616
- iv_size_to_authenc , is_last ,
617
- & areq_ctx -> assoc .mlli_nents );
618
- areq_ctx -> assoc_buff_type = CC_DMA_BUF_MLLI ;
619
- }
620
570
621
571
chain_iv_exit :
622
572
return rc ;
@@ -630,13 +580,8 @@ static int cc_aead_chain_assoc(struct cc_drvdata *drvdata,
630
580
struct aead_req_ctx * areq_ctx = aead_request_ctx (req );
631
581
int rc = 0 ;
632
582
int mapped_nents = 0 ;
633
- struct crypto_aead * tfm = crypto_aead_reqtfm (req );
634
- unsigned int size_of_assoc = areq_ctx -> assoclen ;
635
583
struct device * dev = drvdata_to_dev (drvdata );
636
584
637
- if (areq_ctx -> is_gcm4543 )
638
- size_of_assoc += crypto_aead_ivsize (tfm );
639
-
640
585
if (!sg_data ) {
641
586
rc = - EINVAL ;
642
587
goto chain_assoc_exit ;
@@ -652,7 +597,7 @@ static int cc_aead_chain_assoc(struct cc_drvdata *drvdata,
652
597
goto chain_assoc_exit ;
653
598
}
654
599
655
- mapped_nents = sg_nents_for_len (req -> src , size_of_assoc );
600
+ mapped_nents = sg_nents_for_len (req -> src , areq_ctx -> assoclen );
656
601
if (mapped_nents < 0 )
657
602
return mapped_nents ;
658
603
@@ -845,16 +790,11 @@ static int cc_aead_chain_data(struct cc_drvdata *drvdata,
845
790
u32 src_mapped_nents = 0 , dst_mapped_nents = 0 ;
846
791
u32 offset = 0 ;
847
792
/* non-inplace mode */
848
- unsigned int size_for_map = areq_ctx -> assoclen + req -> cryptlen ;
849
- struct crypto_aead * tfm = crypto_aead_reqtfm (req );
793
+ unsigned int size_for_map = req -> assoclen + req -> cryptlen ;
850
794
u32 sg_index = 0 ;
851
- bool is_gcm4543 = areq_ctx -> is_gcm4543 ;
852
- u32 size_to_skip = areq_ctx -> assoclen ;
795
+ u32 size_to_skip = req -> assoclen ;
853
796
struct scatterlist * sgl ;
854
797
855
- if (is_gcm4543 )
856
- size_to_skip += crypto_aead_ivsize (tfm );
857
-
858
798
offset = size_to_skip ;
859
799
860
800
if (!sg_data )
@@ -863,9 +803,6 @@ static int cc_aead_chain_data(struct cc_drvdata *drvdata,
863
803
areq_ctx -> src_sgl = req -> src ;
864
804
areq_ctx -> dst_sgl = req -> dst ;
865
805
866
- if (is_gcm4543 )
867
- size_for_map += crypto_aead_ivsize (tfm );
868
-
869
806
size_for_map += (direct == DRV_CRYPTO_DIRECTION_ENCRYPT ) ?
870
807
authsize : 0 ;
871
808
src_mapped_nents = cc_get_sgl_nents (dev , req -> src , size_for_map ,
@@ -892,16 +829,13 @@ static int cc_aead_chain_data(struct cc_drvdata *drvdata,
892
829
areq_ctx -> src_offset = offset ;
893
830
894
831
if (req -> src != req -> dst ) {
895
- size_for_map = areq_ctx -> assoclen + req -> cryptlen ;
832
+ size_for_map = req -> assoclen + req -> cryptlen ;
896
833
897
834
if (direct == DRV_CRYPTO_DIRECTION_ENCRYPT )
898
835
size_for_map += authsize ;
899
836
else
900
837
size_for_map -= authsize ;
901
838
902
- if (is_gcm4543 )
903
- size_for_map += crypto_aead_ivsize (tfm );
904
-
905
839
rc = cc_map_sg (dev , req -> dst , size_for_map , DMA_BIDIRECTIONAL ,
906
840
& areq_ctx -> dst .mapped_nents ,
907
841
LLI_MAX_NUM_OF_DATA_ENTRIES , & dst_last_bytes ,
@@ -1008,12 +942,10 @@ int cc_map_aead_request(struct cc_drvdata *drvdata, struct aead_request *req)
1008
942
struct buffer_array sg_data ;
1009
943
unsigned int authsize = areq_ctx -> req_authsize ;
1010
944
int rc = 0 ;
1011
- struct crypto_aead * tfm = crypto_aead_reqtfm (req );
1012
- bool is_gcm4543 = areq_ctx -> is_gcm4543 ;
1013
945
dma_addr_t dma_addr ;
1014
946
u32 mapped_nents = 0 ;
1015
947
u32 dummy = 0 ; /*used for the assoc data fragments */
1016
- u32 size_to_map = 0 ;
948
+ u32 size_to_map ;
1017
949
gfp_t flags = cc_gfp_flags (& req -> base );
1018
950
1019
951
mlli_params -> curr_pool = NULL ;
@@ -1110,14 +1042,13 @@ int cc_map_aead_request(struct cc_drvdata *drvdata, struct aead_request *req)
1110
1042
areq_ctx -> gcm_iv_inc2_dma_addr = dma_addr ;
1111
1043
}
1112
1044
1113
- size_to_map = req -> cryptlen + areq_ctx -> assoclen ;
1045
+ size_to_map = req -> cryptlen + req -> assoclen ;
1114
1046
/* If we do in-place encryption, we also need the auth tag */
1115
1047
if ((areq_ctx -> gen_ctx .op_type == DRV_CRYPTO_DIRECTION_ENCRYPT ) &&
1116
1048
(req -> src == req -> dst )) {
1117
1049
size_to_map += authsize ;
1118
1050
}
1119
- if (is_gcm4543 )
1120
- size_to_map += crypto_aead_ivsize (tfm );
1051
+
1121
1052
rc = cc_map_sg (dev , req -> src , size_to_map , DMA_BIDIRECTIONAL ,
1122
1053
& areq_ctx -> src .mapped_nents ,
1123
1054
(LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES +
0 commit comments