@@ -46,7 +46,6 @@ struct nx842_workmem {
46
46
47
47
ktime_t start ;
48
48
49
- struct vas_window * txwin ; /* Used with VAS function */
50
49
char padding [WORKMEM_ALIGN ]; /* unused, to allow alignment */
51
50
} __packed __aligned (WORKMEM_ALIGN );
52
51
@@ -65,7 +64,7 @@ struct nx842_coproc {
65
64
* Send the request to NX engine on the chip for the corresponding CPU
66
65
* where the process is executing. Use with VAS function.
67
66
*/
68
- static DEFINE_PER_CPU (struct nx842_coproc * , coproc_inst ) ;
67
+ static DEFINE_PER_CPU (struct vas_window * , cpu_txwin ) ;
69
68
70
69
/* no cpu hotplug on powernv, so this list never changes after init */
71
70
static LIST_HEAD (nx842_coprocs );
@@ -586,16 +585,11 @@ static int nx842_exec_vas(const unsigned char *in, unsigned int inlen,
586
585
ccw = SET_FIELD (CCW_FC_842 , ccw , fc );
587
586
crb -> ccw = cpu_to_be32 (ccw );
588
587
589
- txwin = wmem -> txwin ;
590
- /* shoudn't happen, we don't load without a coproc */
591
- if (!txwin ) {
592
- pr_err_ratelimited ("NX-842 coprocessor is not available" );
593
- return - ENODEV ;
594
- }
595
-
596
588
do {
597
589
wmem -> start = ktime_get ();
598
590
preempt_disable ();
591
+ txwin = this_cpu_read (cpu_txwin );
592
+
599
593
/*
600
594
* VAS copy CRB into L2 cache. Refer <asm/vas.h>.
601
595
* @crb and @offset.
@@ -689,25 +683,6 @@ static inline void nx842_add_coprocs_list(struct nx842_coproc *coproc,
689
683
list_add (& coproc -> list , & nx842_coprocs );
690
684
}
691
685
692
- /*
693
- * Identify chip ID for each CPU and save coprocesor adddress for the
694
- * corresponding NX engine in percpu coproc_inst.
695
- * coproc_inst is used in crypto_init to open send window on the NX instance
696
- * for the corresponding CPU / chip where the open request is executed.
697
- */
698
- static void nx842_set_per_cpu_coproc (struct nx842_coproc * coproc )
699
- {
700
- unsigned int i , chip_id ;
701
-
702
- for_each_possible_cpu (i ) {
703
- chip_id = cpu_to_chip_id (i );
704
-
705
- if (coproc -> chip_id == chip_id )
706
- per_cpu (coproc_inst , i ) = coproc ;
707
- }
708
- }
709
-
710
-
711
686
static struct vas_window * nx842_alloc_txwin (struct nx842_coproc * coproc )
712
687
{
713
688
struct vas_window * txwin = NULL ;
@@ -725,15 +700,58 @@ static struct vas_window *nx842_alloc_txwin(struct nx842_coproc *coproc)
725
700
* Open a VAS send window which is used to send request to NX.
726
701
*/
727
702
txwin = vas_tx_win_open (coproc -> vas .id , coproc -> ct , & txattr );
728
- if (IS_ERR (txwin )) {
703
+ if (IS_ERR (txwin ))
729
704
pr_err ("ibm,nx-842: Can not open TX window: %ld\n" ,
730
705
PTR_ERR (txwin ));
731
- return NULL ;
732
- }
733
706
734
707
return txwin ;
735
708
}
736
709
710
+ /*
711
+ * Identify chip ID for each CPU, open send wndow for the corresponding NX
712
+ * engine and save txwin in percpu cpu_txwin.
713
+ * cpu_txwin is used in copy/paste operation for each compression /
714
+ * decompression request.
715
+ */
716
+ static int nx842_open_percpu_txwins (void )
717
+ {
718
+ struct nx842_coproc * coproc , * n ;
719
+ unsigned int i , chip_id ;
720
+
721
+ for_each_possible_cpu (i ) {
722
+ struct vas_window * txwin = NULL ;
723
+
724
+ chip_id = cpu_to_chip_id (i );
725
+
726
+ list_for_each_entry_safe (coproc , n , & nx842_coprocs , list ) {
727
+ /*
728
+ * Kernel requests use only high priority FIFOs. So
729
+ * open send windows for these FIFOs.
730
+ */
731
+
732
+ if (coproc -> ct != VAS_COP_TYPE_842_HIPRI )
733
+ continue ;
734
+
735
+ if (coproc -> chip_id == chip_id ) {
736
+ txwin = nx842_alloc_txwin (coproc );
737
+ if (IS_ERR (txwin ))
738
+ return PTR_ERR (txwin );
739
+
740
+ per_cpu (cpu_txwin , i ) = txwin ;
741
+ break ;
742
+ }
743
+ }
744
+
745
+ if (!per_cpu (cpu_txwin , i )) {
746
+ /* shoudn't happen, Each chip will have NX engine */
747
+ pr_err ("NX engine is not availavle for CPU %d\n" , i );
748
+ return - EINVAL ;
749
+ }
750
+ }
751
+
752
+ return 0 ;
753
+ }
754
+
737
755
static int __init vas_cfg_coproc_info (struct device_node * dn , int chip_id ,
738
756
int vasid )
739
757
{
@@ -819,14 +837,6 @@ static int __init vas_cfg_coproc_info(struct device_node *dn, int chip_id,
819
837
coproc -> vas .id = vasid ;
820
838
nx842_add_coprocs_list (coproc , chip_id );
821
839
822
- /*
823
- * Kernel requests use only high priority FIFOs. So save coproc
824
- * info in percpu coproc_inst which will be used to open send
825
- * windows for crypto open requests later.
826
- */
827
- if (coproc -> ct == VAS_COP_TYPE_842_HIPRI )
828
- nx842_set_per_cpu_coproc (coproc );
829
-
830
840
return 0 ;
831
841
832
842
err_out :
@@ -916,6 +926,19 @@ static int __init nx842_powernv_probe(struct device_node *dn)
916
926
static void nx842_delete_coprocs (void )
917
927
{
918
928
struct nx842_coproc * coproc , * n ;
929
+ struct vas_window * txwin ;
930
+ int i ;
931
+
932
+ /*
933
+ * close percpu txwins that are opened for the corresponding coproc.
934
+ */
935
+ for_each_possible_cpu (i ) {
936
+ txwin = per_cpu (cpu_txwin , i );
937
+ if (txwin )
938
+ vas_win_close (txwin );
939
+
940
+ per_cpu (cpu_txwin , i ) = 0 ;
941
+ }
919
942
920
943
list_for_each_entry_safe (coproc , n , & nx842_coprocs , list ) {
921
944
if (coproc -> vas .rxwin )
@@ -942,46 +965,6 @@ static struct nx842_driver nx842_powernv_driver = {
942
965
.decompress = nx842_powernv_decompress ,
943
966
};
944
967
945
- static int nx842_powernv_crypto_init_vas (struct crypto_tfm * tfm )
946
- {
947
- struct nx842_crypto_ctx * ctx = crypto_tfm_ctx (tfm );
948
- struct nx842_workmem * wmem ;
949
- struct nx842_coproc * coproc ;
950
- int ret ;
951
-
952
- ret = nx842_crypto_init (tfm , & nx842_powernv_driver );
953
-
954
- if (ret )
955
- return ret ;
956
-
957
- wmem = PTR_ALIGN ((struct nx842_workmem * )ctx -> wmem , WORKMEM_ALIGN );
958
- coproc = per_cpu (coproc_inst , smp_processor_id ());
959
-
960
- ret = - EINVAL ;
961
- if (coproc && coproc -> vas .rxwin ) {
962
- wmem -> txwin = nx842_alloc_txwin (coproc );
963
- if (!IS_ERR (wmem -> txwin ))
964
- return 0 ;
965
-
966
- ret = PTR_ERR (wmem -> txwin );
967
- }
968
-
969
- return ret ;
970
- }
971
-
972
- void nx842_powernv_crypto_exit_vas (struct crypto_tfm * tfm )
973
- {
974
- struct nx842_crypto_ctx * ctx = crypto_tfm_ctx (tfm );
975
- struct nx842_workmem * wmem ;
976
-
977
- wmem = PTR_ALIGN ((struct nx842_workmem * )ctx -> wmem , WORKMEM_ALIGN );
978
-
979
- if (wmem && wmem -> txwin )
980
- vas_win_close (wmem -> txwin );
981
-
982
- nx842_crypto_exit (tfm );
983
- }
984
-
985
968
static int nx842_powernv_crypto_init (struct crypto_tfm * tfm )
986
969
{
987
970
return nx842_crypto_init (tfm , & nx842_powernv_driver );
@@ -1032,9 +1015,13 @@ static __init int nx842_powernv_init(void)
1032
1015
1033
1016
nx842_powernv_exec = nx842_exec_icswx ;
1034
1017
} else {
1018
+ ret = nx842_open_percpu_txwins ();
1019
+ if (ret ) {
1020
+ nx842_delete_coprocs ();
1021
+ return ret ;
1022
+ }
1023
+
1035
1024
nx842_powernv_exec = nx842_exec_vas ;
1036
- nx842_powernv_alg .cra_init = nx842_powernv_crypto_init_vas ;
1037
- nx842_powernv_alg .cra_exit = nx842_powernv_crypto_exit_vas ;
1038
1025
}
1039
1026
1040
1027
ret = crypto_register_alg (& nx842_powernv_alg );
0 commit comments