Skip to content

Commit d15cbe7

Browse files
Bharat Bhushanherbertx
authored andcommitted
crypto: octeontx2 - Use dynamic allocated memory region for lmtst
Current driver uses static LMTST region allocated by firmware. Firmware allocated memory for LMTST is available in PF/VF BAR2. Using this memory have performance impact as this is mapped as device memory. There is another option to allocate contiguous memory at run time and map this in LMT MAP table with the help of AF driver. With this patch dynamic allocated memory is used for LMTST. Also add myself as maintainer for crypto octeontx2 driver Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 57b1e1c commit d15cbe7

File tree

11 files changed

+124
-38
lines changed

11 files changed

+124
-38
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14290,6 +14290,7 @@ F: include/uapi/drm/armada_drm.h
1429014290

1429114291
MARVELL CRYPTO DRIVER
1429214292
M: Srujana Challa <schalla@marvell.com>
14293+
M: Bharat Bhushan <bbhushan2@marvell.com>
1429314294
L: linux-crypto@vger.kernel.org
1429414295
S: Maintained
1429514296
F: drivers/crypto/marvell/

drivers/crypto/marvell/octeontx2/cn10k_cpt.c

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "otx2_cptvf.h"
77
#include "otx2_cptlf.h"
88
#include "cn10k_cpt.h"
9+
#include "otx2_cpt_common.h"
910

1011
static void cn10k_cpt_send_cmd(union otx2_cpt_inst_s *cptinst, u32 insts_num,
1112
struct otx2_cptlf_info *lf);
@@ -27,7 +28,7 @@ static struct cpt_hw_ops cn10k_hw_ops = {
2728
static void cn10k_cpt_send_cmd(union otx2_cpt_inst_s *cptinst, u32 insts_num,
2829
struct otx2_cptlf_info *lf)
2930
{
30-
void __iomem *lmtline = lf->lmtline;
31+
void *lmtline = lf->lfs->lmt_info.base + (lf->slot * LMTLINE_SIZE);
3132
u64 val = (lf->slot & 0x7FF);
3233
u64 tar_addr = 0;
3334

@@ -41,34 +42,69 @@ static void cn10k_cpt_send_cmd(union otx2_cpt_inst_s *cptinst, u32 insts_num,
4142
dma_wmb();
4243

4344
/* Copy CPT command to LMTLINE */
44-
memcpy_toio(lmtline, cptinst, insts_num * OTX2_CPT_INST_SIZE);
45+
memcpy(lmtline, cptinst, insts_num * OTX2_CPT_INST_SIZE);
4546
cn10k_lmt_flush(val, tar_addr);
4647
}
4748

49+
void cn10k_cpt_lmtst_free(struct pci_dev *pdev, struct otx2_cptlfs_info *lfs)
50+
{
51+
struct otx2_lmt_info *lmt_info = &lfs->lmt_info;
52+
53+
if (!lmt_info->base)
54+
return;
55+
56+
dma_free_attrs(&pdev->dev, lmt_info->size,
57+
lmt_info->base - lmt_info->align,
58+
lmt_info->iova - lmt_info->align,
59+
DMA_ATTR_FORCE_CONTIGUOUS);
60+
}
61+
EXPORT_SYMBOL_NS_GPL(cn10k_cpt_lmtst_free, "CRYPTO_DEV_OCTEONTX2_CPT");
62+
63+
static int cn10k_cpt_lmtst_alloc(struct pci_dev *pdev,
64+
struct otx2_cptlfs_info *lfs, u32 size)
65+
{
66+
struct otx2_lmt_info *lmt_info = &lfs->lmt_info;
67+
dma_addr_t align_iova;
68+
dma_addr_t iova;
69+
70+
lmt_info->base = dma_alloc_attrs(&pdev->dev, size, &iova, GFP_KERNEL,
71+
DMA_ATTR_FORCE_CONTIGUOUS);
72+
if (!lmt_info->base)
73+
return -ENOMEM;
74+
75+
align_iova = ALIGN((u64)iova, LMTLINE_ALIGN);
76+
lmt_info->iova = align_iova;
77+
lmt_info->align = align_iova - iova;
78+
lmt_info->size = size;
79+
lmt_info->base += lmt_info->align;
80+
return 0;
81+
}
82+
4883
int cn10k_cptpf_lmtst_init(struct otx2_cptpf_dev *cptpf)
4984
{
5085
struct pci_dev *pdev = cptpf->pdev;
51-
resource_size_t size;
52-
u64 lmt_base;
86+
u32 size;
87+
int ret;
5388

5489
if (!test_bit(CN10K_LMTST, &cptpf->cap_flag)) {
5590
cptpf->lfs.ops = &otx2_hw_ops;
5691
return 0;
5792
}
5893

5994
cptpf->lfs.ops = &cn10k_hw_ops;
60-
lmt_base = readq(cptpf->reg_base + RVU_PF_LMTLINE_ADDR);
61-
if (!lmt_base) {
62-
dev_err(&pdev->dev, "PF LMTLINE address not configured\n");
63-
return -ENOMEM;
95+
size = OTX2_CPT_MAX_VFS_NUM * LMTLINE_SIZE + LMTLINE_ALIGN;
96+
ret = cn10k_cpt_lmtst_alloc(pdev, &cptpf->lfs, size);
97+
if (ret) {
98+
dev_err(&pdev->dev, "PF-%d LMTLINE memory allocation failed\n",
99+
cptpf->pf_id);
100+
return ret;
64101
}
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) {
69-
dev_err(&pdev->dev,
70-
"Mapping of PF LMTLINE address failed\n");
71-
return -ENOMEM;
102+
103+
ret = otx2_cpt_lmtst_tbl_setup_msg(&cptpf->lfs);
104+
if (ret) {
105+
dev_err(&pdev->dev, "PF-%d: LMTST Table setup failed\n",
106+
cptpf->pf_id);
107+
cn10k_cpt_lmtst_free(pdev, &cptpf->lfs);
72108
}
73109

74110
return 0;
@@ -78,18 +114,25 @@ EXPORT_SYMBOL_NS_GPL(cn10k_cptpf_lmtst_init, "CRYPTO_DEV_OCTEONTX2_CPT");
78114
int cn10k_cptvf_lmtst_init(struct otx2_cptvf_dev *cptvf)
79115
{
80116
struct pci_dev *pdev = cptvf->pdev;
81-
resource_size_t offset, size;
117+
u32 size;
118+
int ret;
82119

83120
if (!test_bit(CN10K_LMTST, &cptvf->cap_flag))
84121
return 0;
85122

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");
92-
return -ENOMEM;
123+
size = cptvf->lfs.lfs_num * LMTLINE_SIZE + LMTLINE_ALIGN;
124+
ret = cn10k_cpt_lmtst_alloc(pdev, &cptvf->lfs, size);
125+
if (ret) {
126+
dev_err(&pdev->dev, "VF-%d LMTLINE memory allocation failed\n",
127+
cptvf->vf_id);
128+
return ret;
129+
}
130+
131+
ret = otx2_cpt_lmtst_tbl_setup_msg(&cptvf->lfs);
132+
if (ret) {
133+
dev_err(&pdev->dev, "VF-%d: LMTST Table setup failed\n",
134+
cptvf->vf_id);
135+
cn10k_cpt_lmtst_free(pdev, &cptvf->lfs);
93136
}
94137

95138
return 0;

drivers/crypto/marvell/octeontx2/cn10k_cpt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static inline u8 otx2_cpt_get_uc_compcode(union otx2_cpt_res_s *result)
5050

5151
int cn10k_cptpf_lmtst_init(struct otx2_cptpf_dev *cptpf);
5252
int cn10k_cptvf_lmtst_init(struct otx2_cptvf_dev *cptvf);
53+
void cn10k_cpt_lmtst_free(struct pci_dev *pdev, struct otx2_cptlfs_info *lfs);
5354
void cn10k_cpt_ctx_flush(struct pci_dev *pdev, u64 cptr, bool inval);
5455
int cn10k_cpt_hw_ctx_init(struct pci_dev *pdev,
5556
struct cn10k_cpt_errata_ctx *er_ctx);

drivers/crypto/marvell/octeontx2/otx2_cpt_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,6 @@ int otx2_cpt_detach_rsrcs_msg(struct otx2_cptlfs_info *lfs);
209209
int otx2_cpt_msix_offset_msg(struct otx2_cptlfs_info *lfs);
210210
int otx2_cpt_sync_mbox_msg(struct otx2_mbox *mbox);
211211
int otx2_cpt_lf_reset_msg(struct otx2_cptlfs_info *lfs, int slot);
212+
int otx2_cpt_lmtst_tbl_setup_msg(struct otx2_cptlfs_info *lfs);
212213

213214
#endif /* __OTX2_CPT_COMMON_H */

drivers/crypto/marvell/octeontx2/otx2_cpt_mbox_common.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,28 @@ int otx2_cpt_lf_reset_msg(struct otx2_cptlfs_info *lfs, int slot)
255255
return ret;
256256
}
257257
EXPORT_SYMBOL_NS_GPL(otx2_cpt_lf_reset_msg, "CRYPTO_DEV_OCTEONTX2_CPT");
258+
259+
int otx2_cpt_lmtst_tbl_setup_msg(struct otx2_cptlfs_info *lfs)
260+
{
261+
struct otx2_mbox *mbox = lfs->mbox;
262+
struct pci_dev *pdev = lfs->pdev;
263+
struct lmtst_tbl_setup_req *req;
264+
265+
req = (struct lmtst_tbl_setup_req *)
266+
otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*req),
267+
sizeof(struct msg_rsp));
268+
if (!req) {
269+
dev_err(&pdev->dev, "RVU MBOX failed to alloc message.\n");
270+
return -EFAULT;
271+
}
272+
273+
req->hdr.id = MBOX_MSG_LMTST_TBL_SETUP;
274+
req->hdr.sig = OTX2_MBOX_REQ_SIG;
275+
req->hdr.pcifunc = 0;
276+
277+
req->use_local_lmt_region = true;
278+
req->lmt_iova = lfs->lmt_info.iova;
279+
280+
return otx2_cpt_send_mbox_msg(mbox, pdev);
281+
}
282+
EXPORT_SYMBOL_NS_GPL(otx2_cpt_lmtst_tbl_setup_msg, "CRYPTO_DEV_OCTEONTX2_CPT");

drivers/crypto/marvell/octeontx2/otx2_cptlf.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,7 @@ int otx2_cptlf_init(struct otx2_cptlfs_info *lfs, u8 eng_grp_mask, int pri,
433433
for (slot = 0; slot < lfs->lfs_num; slot++) {
434434
lfs->lf[slot].lfs = lfs;
435435
lfs->lf[slot].slot = slot;
436-
if (lfs->lmt_base)
437-
lfs->lf[slot].lmtline = lfs->lmt_base +
438-
(slot * LMTLINE_SIZE);
439-
else
436+
if (!lfs->lmt_info.base)
440437
lfs->lf[slot].lmtline = lfs->reg_base +
441438
OTX2_CPT_RVU_FUNC_ADDR_S(BLKADDR_LMT, slot,
442439
OTX2_CPT_LMT_LF_LMTLINEX(0));

drivers/crypto/marvell/octeontx2/otx2_cptlf.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,19 @@ struct cpt_hw_ops {
105105
gfp_t gfp);
106106
};
107107

108+
#define LMTLINE_SIZE 128
109+
#define LMTLINE_ALIGN 128
110+
struct otx2_lmt_info {
111+
void *base;
112+
dma_addr_t iova;
113+
u32 size;
114+
u8 align;
115+
};
116+
108117
struct otx2_cptlfs_info {
109118
/* Registers start address of VF/PF LFs are attached to */
110119
void __iomem *reg_base;
111-
#define LMTLINE_SIZE 128
112-
void __iomem *lmt_base;
120+
struct otx2_lmt_info lmt_info;
113121
struct pci_dev *pdev; /* Device LFs are attached to */
114122
struct otx2_cptlf_info lf[OTX2_CPT_MAX_LFS_NUM];
115123
struct otx2_mbox *mbox;

drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,19 +792,19 @@ static int otx2_cptpf_probe(struct pci_dev *pdev,
792792
cptpf->max_vfs = pci_sriov_get_totalvfs(pdev);
793793
cptpf->kvf_limits = 1;
794794

795-
err = cn10k_cptpf_lmtst_init(cptpf);
795+
/* Initialize CPT PF device */
796+
err = cptpf_device_init(cptpf);
796797
if (err)
797798
goto unregister_intr;
798799

799-
/* Initialize CPT PF device */
800-
err = cptpf_device_init(cptpf);
800+
err = cn10k_cptpf_lmtst_init(cptpf);
801801
if (err)
802802
goto unregister_intr;
803803

804804
/* Initialize engine groups */
805805
err = otx2_cpt_init_eng_grps(pdev, &cptpf->eng_grps);
806806
if (err)
807-
goto unregister_intr;
807+
goto free_lmtst;
808808

809809
err = sysfs_create_group(&dev->kobj, &cptpf_sysfs_group);
810810
if (err)
@@ -820,6 +820,8 @@ static int otx2_cptpf_probe(struct pci_dev *pdev,
820820
sysfs_remove_group(&dev->kobj, &cptpf_sysfs_group);
821821
cleanup_eng_grps:
822822
otx2_cpt_cleanup_eng_grps(pdev, &cptpf->eng_grps);
823+
free_lmtst:
824+
cn10k_cpt_lmtst_free(pdev, &cptpf->lfs);
823825
unregister_intr:
824826
cptpf_disable_afpf_mbox_intr(cptpf);
825827
destroy_afpf_mbox:
@@ -854,6 +856,8 @@ static void otx2_cptpf_remove(struct pci_dev *pdev)
854856
cptpf_disable_afpf_mbox_intr(cptpf);
855857
/* Destroy AF-PF mbox */
856858
cptpf_afpf_mbox_destroy(cptpf);
859+
/* Free LMTST memory */
860+
cn10k_cpt_lmtst_free(pdev, &cptpf->lfs);
857861
pci_set_drvdata(pdev, NULL);
858862
}
859863

drivers/crypto/marvell/octeontx2/otx2_cptpf_mbox.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ static void process_afpf_mbox_msg(struct otx2_cptpf_dev *cptpf,
502502
case MBOX_MSG_CPT_INLINE_IPSEC_CFG:
503503
case MBOX_MSG_NIX_INLINE_IPSEC_CFG:
504504
case MBOX_MSG_CPT_LF_RESET:
505+
case MBOX_MSG_LMTST_TBL_SETUP:
505506
break;
506507

507508
default:

drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,6 @@ static int otx2_cptvf_probe(struct pci_dev *pdev,
376376

377377
otx2_cpt_set_hw_caps(pdev, &cptvf->cap_flag);
378378

379-
ret = cn10k_cptvf_lmtst_init(cptvf);
380-
if (ret)
381-
goto clear_drvdata;
382-
383379
/* Initialize PF<=>VF mailbox */
384380
ret = cptvf_pfvf_mbox_init(cptvf);
385381
if (ret)
@@ -405,13 +401,19 @@ static int otx2_cptvf_probe(struct pci_dev *pdev,
405401
if (cptvf->eng_caps[OTX2_CPT_SE_TYPES] & BIT_ULL(35))
406402
cptvf->lfs.ops->cpt_sg_info_create = cn10k_sgv2_info_create;
407403

404+
ret = cn10k_cptvf_lmtst_init(cptvf);
405+
if (ret)
406+
goto unregister_interrupts;
407+
408408
/* Initialize CPT LFs */
409409
ret = cptvf_lf_init(cptvf);
410410
if (ret)
411-
goto unregister_interrupts;
411+
goto free_lmtst;
412412

413413
return 0;
414414

415+
free_lmtst:
416+
cn10k_cpt_lmtst_free(pdev, &cptvf->lfs);
415417
unregister_interrupts:
416418
cptvf_disable_pfvf_mbox_intrs(cptvf);
417419
destroy_pfvf_mbox:
@@ -435,6 +437,8 @@ static void otx2_cptvf_remove(struct pci_dev *pdev)
435437
cptvf_disable_pfvf_mbox_intrs(cptvf);
436438
/* Destroy PF-VF mbox */
437439
cptvf_pfvf_mbox_destroy(cptvf);
440+
/* Free LMTST memory */
441+
cn10k_cpt_lmtst_free(pdev, &cptvf->lfs);
438442
pci_set_drvdata(pdev, NULL);
439443
}
440444

0 commit comments

Comments
 (0)