Skip to content

Commit 976dd64

Browse files
Haren Mynenimpe
authored andcommitted
crypto/nx: Use percpu send window for NX requests
For P9 NX, the send window is opened for each crypto session and closed upon free. But VAS supports 64K windows per chip for all coprocessors including in user space support. So there is a possibility of not getting the window for kernel requests. This patch reserves windows for each coprocessor type (NX842) and are available forever for kernel requests, Opens each window for each CPU on the corresponding chip during driver initialization. So then use the percpu txwin for NX requests depends on the CPU on which the process is executing. Signed-off-by: Haren Myneni <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 6c8e6bb commit 976dd64

File tree

1 file changed

+68
-81
lines changed

1 file changed

+68
-81
lines changed

drivers/crypto/nx/nx-842-powernv.c

Lines changed: 68 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct nx842_workmem {
4646

4747
ktime_t start;
4848

49-
struct vas_window *txwin; /* Used with VAS function */
5049
char padding[WORKMEM_ALIGN]; /* unused, to allow alignment */
5150
} __packed __aligned(WORKMEM_ALIGN);
5251

@@ -65,7 +64,7 @@ struct nx842_coproc {
6564
* Send the request to NX engine on the chip for the corresponding CPU
6665
* where the process is executing. Use with VAS function.
6766
*/
68-
static DEFINE_PER_CPU(struct nx842_coproc *, coproc_inst);
67+
static DEFINE_PER_CPU(struct vas_window *, cpu_txwin);
6968

7069
/* no cpu hotplug on powernv, so this list never changes after init */
7170
static LIST_HEAD(nx842_coprocs);
@@ -586,16 +585,11 @@ static int nx842_exec_vas(const unsigned char *in, unsigned int inlen,
586585
ccw = SET_FIELD(CCW_FC_842, ccw, fc);
587586
crb->ccw = cpu_to_be32(ccw);
588587

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-
596588
do {
597589
wmem->start = ktime_get();
598590
preempt_disable();
591+
txwin = this_cpu_read(cpu_txwin);
592+
599593
/*
600594
* VAS copy CRB into L2 cache. Refer <asm/vas.h>.
601595
* @crb and @offset.
@@ -689,25 +683,6 @@ static inline void nx842_add_coprocs_list(struct nx842_coproc *coproc,
689683
list_add(&coproc->list, &nx842_coprocs);
690684
}
691685

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-
711686
static struct vas_window *nx842_alloc_txwin(struct nx842_coproc *coproc)
712687
{
713688
struct vas_window *txwin = NULL;
@@ -725,15 +700,58 @@ static struct vas_window *nx842_alloc_txwin(struct nx842_coproc *coproc)
725700
* Open a VAS send window which is used to send request to NX.
726701
*/
727702
txwin = vas_tx_win_open(coproc->vas.id, coproc->ct, &txattr);
728-
if (IS_ERR(txwin)) {
703+
if (IS_ERR(txwin))
729704
pr_err("ibm,nx-842: Can not open TX window: %ld\n",
730705
PTR_ERR(txwin));
731-
return NULL;
732-
}
733706

734707
return txwin;
735708
}
736709

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+
737755
static int __init vas_cfg_coproc_info(struct device_node *dn, int chip_id,
738756
int vasid)
739757
{
@@ -819,14 +837,6 @@ static int __init vas_cfg_coproc_info(struct device_node *dn, int chip_id,
819837
coproc->vas.id = vasid;
820838
nx842_add_coprocs_list(coproc, chip_id);
821839

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-
830840
return 0;
831841

832842
err_out:
@@ -916,6 +926,19 @@ static int __init nx842_powernv_probe(struct device_node *dn)
916926
static void nx842_delete_coprocs(void)
917927
{
918928
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+
}
919942

920943
list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) {
921944
if (coproc->vas.rxwin)
@@ -942,46 +965,6 @@ static struct nx842_driver nx842_powernv_driver = {
942965
.decompress = nx842_powernv_decompress,
943966
};
944967

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-
985968
static int nx842_powernv_crypto_init(struct crypto_tfm *tfm)
986969
{
987970
return nx842_crypto_init(tfm, &nx842_powernv_driver);
@@ -1032,9 +1015,13 @@ static __init int nx842_powernv_init(void)
10321015

10331016
nx842_powernv_exec = nx842_exec_icswx;
10341017
} else {
1018+
ret = nx842_open_percpu_txwins();
1019+
if (ret) {
1020+
nx842_delete_coprocs();
1021+
return ret;
1022+
}
1023+
10351024
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;
10381025
}
10391026

10401027
ret = crypto_register_alg(&nx842_powernv_alg);

0 commit comments

Comments
 (0)