1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2021 Marvell. */
4 #include <linux/soc/marvell/octeontx2/asm.h>
5 #include "otx2_cptpf.h"
6 #include "otx2_cptvf.h"
7 #include "otx2_cptlf.h"
10 static void cn10k_cpt_send_cmd(union otx2_cpt_inst_s
*cptinst
, u32 insts_num
,
11 struct otx2_cptlf_info
*lf
);
13 static struct cpt_hw_ops otx2_hw_ops
= {
14 .send_cmd
= otx2_cpt_send_cmd
,
15 .cpt_get_compcode
= otx2_cpt_get_compcode
,
16 .cpt_get_uc_compcode
= otx2_cpt_get_uc_compcode
,
17 .cpt_sg_info_create
= otx2_sg_info_create
,
20 static struct cpt_hw_ops cn10k_hw_ops
= {
21 .send_cmd
= cn10k_cpt_send_cmd
,
22 .cpt_get_compcode
= cn10k_cpt_get_compcode
,
23 .cpt_get_uc_compcode
= cn10k_cpt_get_uc_compcode
,
24 .cpt_sg_info_create
= otx2_sg_info_create
,
27 static void cn10k_cpt_send_cmd(union otx2_cpt_inst_s
*cptinst
, u32 insts_num
,
28 struct otx2_cptlf_info
*lf
)
30 void __iomem
*lmtline
= lf
->lmtline
;
31 u64 val
= (lf
->slot
& 0x7FF);
34 /* tar_addr<6:4> = Size of first LMTST - 1 in units of 128b. */
35 tar_addr
|= (__force u64
)lf
->ioreg
|
36 (((OTX2_CPT_INST_SIZE
/16) - 1) & 0x7) << 4;
38 * Make sure memory areas pointed in CPT_INST_S
39 * are flushed before the instruction is sent to CPT
43 /* Copy CPT command to LMTLINE */
44 memcpy_toio(lmtline
, cptinst
, insts_num
* OTX2_CPT_INST_SIZE
);
45 cn10k_lmt_flush(val
, tar_addr
);
48 int cn10k_cptpf_lmtst_init(struct otx2_cptpf_dev
*cptpf
)
50 struct pci_dev
*pdev
= cptpf
->pdev
;
54 if (!test_bit(CN10K_LMTST
, &cptpf
->cap_flag
)) {
55 cptpf
->lfs
.ops
= &otx2_hw_ops
;
59 cptpf
->lfs
.ops
= &cn10k_hw_ops
;
60 lmt_base
= readq(cptpf
->reg_base
+ RVU_PF_LMTLINE_ADDR
);
62 dev_err(&pdev
->dev
, "PF LMTLINE address not configured\n");
65 size
= pci_resource_len(pdev
, PCI_MBOX_BAR_NUM
);
66 size
-= ((1 + cptpf
->max_vfs
) * MBOX_SIZE
);
67 cptpf
->lfs
.lmt_base
= devm_ioremap_wc(&pdev
->dev
, lmt_base
, size
);
68 if (!cptpf
->lfs
.lmt_base
) {
70 "Mapping of PF LMTLINE address failed\n");
76 EXPORT_SYMBOL_NS_GPL(cn10k_cptpf_lmtst_init
, "CRYPTO_DEV_OCTEONTX2_CPT");
78 int cn10k_cptvf_lmtst_init(struct otx2_cptvf_dev
*cptvf
)
80 struct pci_dev
*pdev
= cptvf
->pdev
;
81 resource_size_t offset
, size
;
83 if (!test_bit(CN10K_LMTST
, &cptvf
->cap_flag
))
86 offset
= pci_resource_start(pdev
, PCI_MBOX_BAR_NUM
);
87 size
= pci_resource_len(pdev
, PCI_MBOX_BAR_NUM
);
88 /* Map VF LMILINE region */
89 cptvf
->lfs
.lmt_base
= devm_ioremap_wc(&pdev
->dev
, offset
, size
);
90 if (!cptvf
->lfs
.lmt_base
) {
91 dev_err(&pdev
->dev
, "Unable to map BAR4\n");
97 EXPORT_SYMBOL_NS_GPL(cn10k_cptvf_lmtst_init
, "CRYPTO_DEV_OCTEONTX2_CPT");
99 void cn10k_cpt_hw_ctx_clear(struct pci_dev
*pdev
,
100 struct cn10k_cpt_errata_ctx
*er_ctx
)
104 if (!is_dev_cn10ka_ax(pdev
))
107 cptr_dma
= er_ctx
->cptr_dma
& ~(BIT_ULL(60));
108 cn10k_cpt_ctx_flush(pdev
, cptr_dma
, true);
109 dma_unmap_single(&pdev
->dev
, cptr_dma
, CN10K_CPT_HW_CTX_SIZE
,
111 kfree(er_ctx
->hw_ctx
);
113 EXPORT_SYMBOL_NS_GPL(cn10k_cpt_hw_ctx_clear
, "CRYPTO_DEV_OCTEONTX2_CPT");
115 void cn10k_cpt_hw_ctx_set(union cn10k_cpt_hw_ctx
*hctx
, u16 ctx_sz
)
117 hctx
->w0
.aop_valid
= 1;
118 hctx
->w0
.ctx_hdr_sz
= 0;
119 hctx
->w0
.ctx_sz
= ctx_sz
;
120 hctx
->w0
.ctx_push_sz
= 1;
122 EXPORT_SYMBOL_NS_GPL(cn10k_cpt_hw_ctx_set
, "CRYPTO_DEV_OCTEONTX2_CPT");
124 int cn10k_cpt_hw_ctx_init(struct pci_dev
*pdev
,
125 struct cn10k_cpt_errata_ctx
*er_ctx
)
127 union cn10k_cpt_hw_ctx
*hctx
;
130 er_ctx
->cptr_dma
= 0;
131 er_ctx
->hw_ctx
= NULL
;
133 if (!is_dev_cn10ka_ax(pdev
))
136 hctx
= kmalloc(CN10K_CPT_HW_CTX_SIZE
, GFP_KERNEL
);
139 cptr_dma
= dma_map_single(&pdev
->dev
, hctx
, CN10K_CPT_HW_CTX_SIZE
,
141 if (dma_mapping_error(&pdev
->dev
, cptr_dma
)) {
146 cn10k_cpt_hw_ctx_set(hctx
, 1);
147 er_ctx
->hw_ctx
= hctx
;
148 er_ctx
->cptr_dma
= cptr_dma
| BIT_ULL(60);
152 EXPORT_SYMBOL_NS_GPL(cn10k_cpt_hw_ctx_init
, "CRYPTO_DEV_OCTEONTX2_CPT");
154 void cn10k_cpt_ctx_flush(struct pci_dev
*pdev
, u64 cptr
, bool inval
)
156 struct otx2_cptvf_dev
*cptvf
= pci_get_drvdata(pdev
);
157 struct otx2_cptlfs_info
*lfs
= &cptvf
->lfs
;
160 reg
= (uintptr_t)cptr
>> 7;
162 reg
= reg
| BIT_ULL(46);
164 otx2_cpt_write64(lfs
->reg_base
, lfs
->blkaddr
, lfs
->lf
[0].slot
,
165 OTX2_CPT_LF_CTX_FLUSH
, reg
);
166 /* Make sure that the FLUSH operation is complete */
168 otx2_cpt_read64(lfs
->reg_base
, lfs
->blkaddr
, lfs
->lf
[0].slot
,
169 OTX2_CPT_LF_CTX_ERR
);
171 EXPORT_SYMBOL_NS_GPL(cn10k_cpt_ctx_flush
, "CRYPTO_DEV_OCTEONTX2_CPT");
173 void cptvf_hw_ops_get(struct otx2_cptvf_dev
*cptvf
)
175 if (test_bit(CN10K_LMTST
, &cptvf
->cap_flag
))
176 cptvf
->lfs
.ops
= &cn10k_hw_ops
;
178 cptvf
->lfs
.ops
= &otx2_hw_ops
;
180 EXPORT_SYMBOL_NS_GPL(cptvf_hw_ops_get
, "CRYPTO_DEV_OCTEONTX2_CPT");