1212
1313#define pr_fmt (fmt ) "PM: " fmt
1414
15+ #include <crypto/acompress.h>
1516#include <linux/module.h>
1617#include <linux/file.h>
1718#include <linux/delay.h>
@@ -635,7 +636,8 @@ static int crc32_threadfn(void *data)
635636 */
636637struct cmp_data {
637638 struct task_struct * thr ; /* thread */
638- struct crypto_comp * cc ; /* crypto compressor stream */
639+ struct crypto_acomp * cc ; /* crypto compressor */
640+ struct acomp_req * cr ; /* crypto request */
639641 atomic_t ready ; /* ready to start flag */
640642 atomic_t stop ; /* ready to stop flag */
641643 int ret ; /* return code */
@@ -656,7 +658,6 @@ static atomic_t compressed_size = ATOMIC_INIT(0);
656658static int compress_threadfn (void * data )
657659{
658660 struct cmp_data * d = data ;
659- unsigned int cmp_len = 0 ;
660661
661662 while (1 ) {
662663 wait_event (d -> go , atomic_read_acquire (& d -> ready ) ||
@@ -670,11 +671,13 @@ static int compress_threadfn(void *data)
670671 }
671672 atomic_set (& d -> ready , 0 );
672673
673- cmp_len = CMP_SIZE - CMP_HEADER ;
674- d -> ret = crypto_comp_compress (d -> cc , d -> unc , d -> unc_len ,
675- d -> cmp + CMP_HEADER ,
676- & cmp_len );
677- d -> cmp_len = cmp_len ;
674+ acomp_request_set_callback (d -> cr , CRYPTO_TFM_REQ_MAY_SLEEP ,
675+ NULL , NULL );
676+ acomp_request_set_src_nondma (d -> cr , d -> unc , d -> unc_len );
677+ acomp_request_set_dst_nondma (d -> cr , d -> cmp + CMP_HEADER ,
678+ CMP_SIZE - CMP_HEADER );
679+ d -> ret = crypto_acomp_compress (d -> cr );
680+ d -> cmp_len = d -> cr -> dlen ;
678681
679682 atomic_set (& compressed_size , atomic_read (& compressed_size ) + d -> cmp_len );
680683 atomic_set_release (& d -> stop , 1 );
@@ -745,13 +748,20 @@ static int save_compressed_image(struct swap_map_handle *handle,
745748 init_waitqueue_head (& data [thr ].go );
746749 init_waitqueue_head (& data [thr ].done );
747750
748- data [thr ].cc = crypto_alloc_comp (hib_comp_algo , 0 , 0 );
751+ data [thr ].cc = crypto_alloc_acomp (hib_comp_algo , 0 , CRYPTO_ALG_ASYNC );
749752 if (IS_ERR_OR_NULL (data [thr ].cc )) {
750753 pr_err ("Could not allocate comp stream %ld\n" , PTR_ERR (data [thr ].cc ));
751754 ret = - EFAULT ;
752755 goto out_clean ;
753756 }
754757
758+ data [thr ].cr = acomp_request_alloc (data [thr ].cc );
759+ if (!data [thr ].cr ) {
760+ pr_err ("Could not allocate comp request\n" );
761+ ret = - ENOMEM ;
762+ goto out_clean ;
763+ }
764+
755765 data [thr ].thr = kthread_run (compress_threadfn ,
756766 & data [thr ],
757767 "image_compress/%u" , thr );
@@ -899,8 +909,8 @@ static int save_compressed_image(struct swap_map_handle *handle,
899909 for (thr = 0 ; thr < nr_threads ; thr ++ ) {
900910 if (data [thr ].thr )
901911 kthread_stop (data [thr ].thr );
902- if (data [thr ].cc )
903- crypto_free_comp (data [thr ].cc );
912+ acomp_request_free (data [thr ].cr );
913+ crypto_free_acomp (data [thr ].cc );
904914 }
905915 vfree (data );
906916 }
@@ -1142,7 +1152,8 @@ static int load_image(struct swap_map_handle *handle,
11421152 */
11431153struct dec_data {
11441154 struct task_struct * thr ; /* thread */
1145- struct crypto_comp * cc ; /* crypto compressor stream */
1155+ struct crypto_acomp * cc ; /* crypto compressor */
1156+ struct acomp_req * cr ; /* crypto request */
11461157 atomic_t ready ; /* ready to start flag */
11471158 atomic_t stop ; /* ready to stop flag */
11481159 int ret ; /* return code */
@@ -1160,7 +1171,6 @@ struct dec_data {
11601171static int decompress_threadfn (void * data )
11611172{
11621173 struct dec_data * d = data ;
1163- unsigned int unc_len = 0 ;
11641174
11651175 while (1 ) {
11661176 wait_event (d -> go , atomic_read_acquire (& d -> ready ) ||
@@ -1174,10 +1184,13 @@ static int decompress_threadfn(void *data)
11741184 }
11751185 atomic_set (& d -> ready , 0 );
11761186
1177- unc_len = UNC_SIZE ;
1178- d -> ret = crypto_comp_decompress (d -> cc , d -> cmp + CMP_HEADER , d -> cmp_len ,
1179- d -> unc , & unc_len );
1180- d -> unc_len = unc_len ;
1187+ acomp_request_set_callback (d -> cr , CRYPTO_TFM_REQ_MAY_SLEEP ,
1188+ NULL , NULL );
1189+ acomp_request_set_src_nondma (d -> cr , d -> cmp + CMP_HEADER ,
1190+ d -> cmp_len );
1191+ acomp_request_set_dst_nondma (d -> cr , d -> unc , UNC_SIZE );
1192+ d -> ret = crypto_acomp_decompress (d -> cr );
1193+ d -> unc_len = d -> cr -> dlen ;
11811194
11821195 if (clean_pages_on_decompress )
11831196 flush_icache_range ((unsigned long )d -> unc ,
@@ -1254,13 +1267,20 @@ static int load_compressed_image(struct swap_map_handle *handle,
12541267 init_waitqueue_head (& data [thr ].go );
12551268 init_waitqueue_head (& data [thr ].done );
12561269
1257- data [thr ].cc = crypto_alloc_comp (hib_comp_algo , 0 , 0 );
1270+ data [thr ].cc = crypto_alloc_acomp (hib_comp_algo , 0 , CRYPTO_ALG_ASYNC );
12581271 if (IS_ERR_OR_NULL (data [thr ].cc )) {
12591272 pr_err ("Could not allocate comp stream %ld\n" , PTR_ERR (data [thr ].cc ));
12601273 ret = - EFAULT ;
12611274 goto out_clean ;
12621275 }
12631276
1277+ data [thr ].cr = acomp_request_alloc (data [thr ].cc );
1278+ if (!data [thr ].cr ) {
1279+ pr_err ("Could not allocate comp request\n" );
1280+ ret = - ENOMEM ;
1281+ goto out_clean ;
1282+ }
1283+
12641284 data [thr ].thr = kthread_run (decompress_threadfn ,
12651285 & data [thr ],
12661286 "image_decompress/%u" , thr );
@@ -1507,8 +1527,8 @@ static int load_compressed_image(struct swap_map_handle *handle,
15071527 for (thr = 0 ; thr < nr_threads ; thr ++ ) {
15081528 if (data [thr ].thr )
15091529 kthread_stop (data [thr ].thr );
1510- if (data [thr ].cc )
1511- crypto_free_comp (data [thr ].cc );
1530+ acomp_request_free (data [thr ].cr );
1531+ crypto_free_acomp (data [thr ].cc );
15121532 }
15131533 vfree (data );
15141534 }
0 commit comments