crypto: octeontx2 - add support to map LMTST region for CN10K
authorSrujana Challa <schalla@marvell.com>
Tue, 25 May 2021 11:27:16 +0000 (16:57 +0530)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 3 Jun 2021 12:24:05 +0000 (20:24 +0800)
On CN10K platform transmit/receive buffer alloc and free from/to
hardware had changed to support burst operation. Whereas pervious
silicon's only support single buffer free at a time.
To Support the same firmware allocates a DRAM region for each PF/VF for
storing LMTLINES. These LMTLINES are used to send CPT commands to HW.
PF/VF LMTST region is accessed via BAR4. PFs LMTST region is followed
by its VFs mbox memory. The size of region varies from 2KB to 256KB
based on number of LMTLINES configured.

This patch adds support for mapping of PF/VF LMTST region.

Signed-off-by: Srujana Challa <schalla@marvell.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/marvell/octeontx2/Makefile
drivers/crypto/marvell/octeontx2/cn10k_cpt.c [new file with mode: 0644]
drivers/crypto/marvell/octeontx2/cn10k_cpt.h [new file with mode: 0644]
drivers/crypto/marvell/octeontx2/otx2_cpt_common.h
drivers/crypto/marvell/octeontx2/otx2_cptlf.h
drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c
drivers/crypto/marvell/octeontx2/otx2_cptvf_main.c

index 10e1fe056a9e5646fb77ffb7b7701e11ce7340c5..c242d22008c3351d824e8a493c5ed3a640c988a7 100644 (file)
@@ -2,9 +2,10 @@
 obj-$(CONFIG_CRYPTO_DEV_OCTEONTX2_CPT) += rvu_cptpf.o rvu_cptvf.o
 
 rvu_cptpf-objs := otx2_cptpf_main.o otx2_cptpf_mbox.o \
-                 otx2_cpt_mbox_common.o otx2_cptpf_ucode.o otx2_cptlf.o
+                 otx2_cpt_mbox_common.o otx2_cptpf_ucode.o otx2_cptlf.o \
+                 cn10k_cpt.o
 rvu_cptvf-objs := otx2_cptvf_main.o otx2_cptvf_mbox.o otx2_cptlf.o \
                  otx2_cpt_mbox_common.o otx2_cptvf_reqmgr.o \
-                 otx2_cptvf_algs.o
+                 otx2_cptvf_algs.o cn10k_cpt.o
 
 ccflags-y += -I$(srctree)/drivers/net/ethernet/marvell/octeontx2/af
diff --git a/drivers/crypto/marvell/octeontx2/cn10k_cpt.c b/drivers/crypto/marvell/octeontx2/cn10k_cpt.c
new file mode 100644 (file)
index 0000000..57cf156
--- /dev/null
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2021 Marvell. */
+
+#include "otx2_cptpf.h"
+#include "otx2_cptvf.h"
+#include "otx2_cptlf.h"
+#include "cn10k_cpt.h"
+
+int cn10k_cptpf_lmtst_init(struct otx2_cptpf_dev *cptpf)
+{
+       struct pci_dev *pdev = cptpf->pdev;
+       resource_size_t size;
+       u64 lmt_base;
+
+       if (!test_bit(CN10K_LMTST, &cptpf->cap_flag))
+               return 0;
+
+       lmt_base = readq(cptpf->reg_base + RVU_PF_LMTLINE_ADDR);
+       if (!lmt_base) {
+               dev_err(&pdev->dev, "PF LMTLINE address not configured\n");
+               return -ENOMEM;
+       }
+       size = pci_resource_len(pdev, PCI_MBOX_BAR_NUM);
+       size -= ((1 + cptpf->max_vfs) * MBOX_SIZE);
+       cptpf->lfs.lmt_base = devm_ioremap_wc(&pdev->dev, lmt_base, size);
+       if (!cptpf->lfs.lmt_base) {
+               dev_err(&pdev->dev,
+                       "Mapping of PF LMTLINE address failed\n");
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+int cn10k_cptvf_lmtst_init(struct otx2_cptvf_dev *cptvf)
+{
+       struct pci_dev *pdev = cptvf->pdev;
+       resource_size_t offset, size;
+
+       if (!test_bit(CN10K_LMTST, &cptvf->cap_flag))
+               return 0;
+
+       offset = pci_resource_start(pdev, PCI_MBOX_BAR_NUM);
+       size = pci_resource_len(pdev, PCI_MBOX_BAR_NUM);
+       /* Map VF LMILINE region */
+       cptvf->lfs.lmt_base = devm_ioremap_wc(&pdev->dev, offset, size);
+       if (!cptvf->lfs.lmt_base) {
+               dev_err(&pdev->dev, "Unable to map BAR4\n");
+               return -ENOMEM;
+       }
+
+       return 0;
+}
diff --git a/drivers/crypto/marvell/octeontx2/cn10k_cpt.h b/drivers/crypto/marvell/octeontx2/cn10k_cpt.h
new file mode 100644 (file)
index 0000000..b9a8c46
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ * Copyright (C) 2021 Marvell.
+ */
+#ifndef __CN10K_CPT_H
+#define __CN10K_CPT_H
+
+#include "otx2_cptpf.h"
+#include "otx2_cptvf.h"
+
+int cn10k_cptpf_lmtst_init(struct otx2_cptpf_dev *cptpf);
+int cn10k_cptvf_lmtst_init(struct otx2_cptvf_dev *cptvf);
+
+#endif /* __CN10K_CPTLF_H */
index 414427dcfa61b9637a8cc35aa38476ef16107f1b..c5445b05f53c2315a87c36cf4cb5eb1031c917a1 100644 (file)
@@ -27,6 +27,7 @@
 
 /* HW capability flags */
 #define CN10K_MBOX  0
+#define CN10K_LMTST 1
 
 #define BAD_OTX2_CPT_ENG_TYPE OTX2_CPT_MAX_ENG_TYPES
 
@@ -131,8 +132,10 @@ static inline bool is_dev_otx2(struct pci_dev *pdev)
 static inline void otx2_cpt_set_hw_caps(struct pci_dev *pdev,
                                        unsigned long *cap_flag)
 {
-       if (!is_dev_otx2(pdev))
+       if (!is_dev_otx2(pdev)) {
                __set_bit(CN10K_MBOX, cap_flag);
+               __set_bit(CN10K_LMTST, cap_flag);
+       }
 }
 
 
index ab1678fc564d63710cd3dba8790331ca2d6ad493..c87c18e3117106fd65651f6a514c5048ec4620a9 100644 (file)
@@ -87,6 +87,8 @@ struct otx2_cptlf_info {
 struct otx2_cptlfs_info {
        /* Registers start address of VF/PF LFs are attached to */
        void __iomem *reg_base;
+#define LMTLINE_SIZE  128
+       void __iomem *lmt_base;
        struct pci_dev *pdev;   /* Device LFs are attached to */
        struct otx2_cptlf_info lf[OTX2_CPT_MAX_LFS_NUM];
        struct otx2_mbox *mbox;
index d341aecd3dd2fb249549fb29a8ab678812ece33e..4ec3a4613e74a401a55b7854f9554589bef3c8a2 100644 (file)
@@ -6,6 +6,7 @@
 #include "otx2_cpt_common.h"
 #include "otx2_cptpf_ucode.h"
 #include "otx2_cptpf.h"
+#include "cn10k_cpt.h"
 #include "rvu_reg.h"
 
 #define OTX2_CPT_DRV_NAME    "rvu_cptpf"
@@ -677,6 +678,10 @@ static int otx2_cptpf_probe(struct pci_dev *pdev,
 
        cptpf->max_vfs = pci_sriov_get_totalvfs(pdev);
 
+       err = cn10k_cptpf_lmtst_init(cptpf);
+       if (err)
+               goto unregister_intr;
+
        /* Initialize CPT PF device */
        err = cptpf_device_init(cptpf);
        if (err)
index 5178e0688d755399e9f644a53f8a551546fc30e1..3411e664cf50cb574b72c98b999e80d752575914 100644 (file)
@@ -5,6 +5,7 @@
 #include "otx2_cptvf.h"
 #include "otx2_cptlf.h"
 #include "otx2_cptvf_algs.h"
+#include "cn10k_cpt.h"
 #include <rvu_reg.h>
 
 #define OTX2_CPTVF_DRV_NAME "rvu_cptvf"
@@ -364,6 +365,11 @@ static int otx2_cptvf_probe(struct pci_dev *pdev,
        cptvf->reg_base = pcim_iomap_table(pdev)[PCI_PF_REG_BAR_NUM];
 
        otx2_cpt_set_hw_caps(pdev, &cptvf->cap_flag);
+
+       ret = cn10k_cptvf_lmtst_init(cptvf);
+       if (ret)
+               goto clear_drvdata;
+
        /* Initialize PF<=>VF mailbox */
        ret = cptvf_pfvf_mbox_init(cptvf);
        if (ret)