cn10k_cpt.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (C) 2021 Marvell. */
  3. #include <linux/soc/marvell/octeontx2/asm.h>
  4. #include "otx2_cptpf.h"
  5. #include "otx2_cptvf.h"
  6. #include "otx2_cptlf.h"
  7. #include "cn10k_cpt.h"
  8. static void cn10k_cpt_send_cmd(union otx2_cpt_inst_s *cptinst, u32 insts_num,
  9. struct otx2_cptlf_info *lf);
  10. static struct cpt_hw_ops otx2_hw_ops = {
  11. .send_cmd = otx2_cpt_send_cmd,
  12. .cpt_get_compcode = otx2_cpt_get_compcode,
  13. .cpt_get_uc_compcode = otx2_cpt_get_uc_compcode,
  14. };
  15. static struct cpt_hw_ops cn10k_hw_ops = {
  16. .send_cmd = cn10k_cpt_send_cmd,
  17. .cpt_get_compcode = cn10k_cpt_get_compcode,
  18. .cpt_get_uc_compcode = cn10k_cpt_get_uc_compcode,
  19. };
  20. static void cn10k_cpt_send_cmd(union otx2_cpt_inst_s *cptinst, u32 insts_num,
  21. struct otx2_cptlf_info *lf)
  22. {
  23. void __iomem *lmtline = lf->lmtline;
  24. u64 val = (lf->slot & 0x7FF);
  25. u64 tar_addr = 0;
  26. /* tar_addr<6:4> = Size of first LMTST - 1 in units of 128b. */
  27. tar_addr |= (__force u64)lf->ioreg |
  28. (((OTX2_CPT_INST_SIZE/16) - 1) & 0x7) << 4;
  29. /*
  30. * Make sure memory areas pointed in CPT_INST_S
  31. * are flushed before the instruction is sent to CPT
  32. */
  33. dma_wmb();
  34. /* Copy CPT command to LMTLINE */
  35. memcpy_toio(lmtline, cptinst, insts_num * OTX2_CPT_INST_SIZE);
  36. cn10k_lmt_flush(val, tar_addr);
  37. }
  38. int cn10k_cptpf_lmtst_init(struct otx2_cptpf_dev *cptpf)
  39. {
  40. struct pci_dev *pdev = cptpf->pdev;
  41. resource_size_t size;
  42. u64 lmt_base;
  43. if (!test_bit(CN10K_LMTST, &cptpf->cap_flag)) {
  44. cptpf->lfs.ops = &otx2_hw_ops;
  45. return 0;
  46. }
  47. cptpf->lfs.ops = &cn10k_hw_ops;
  48. lmt_base = readq(cptpf->reg_base + RVU_PF_LMTLINE_ADDR);
  49. if (!lmt_base) {
  50. dev_err(&pdev->dev, "PF LMTLINE address not configured\n");
  51. return -ENOMEM;
  52. }
  53. size = pci_resource_len(pdev, PCI_MBOX_BAR_NUM);
  54. size -= ((1 + cptpf->max_vfs) * MBOX_SIZE);
  55. cptpf->lfs.lmt_base = devm_ioremap_wc(&pdev->dev, lmt_base, size);
  56. if (!cptpf->lfs.lmt_base) {
  57. dev_err(&pdev->dev,
  58. "Mapping of PF LMTLINE address failed\n");
  59. return -ENOMEM;
  60. }
  61. return 0;
  62. }
  63. EXPORT_SYMBOL_NS_GPL(cn10k_cptpf_lmtst_init, CRYPTO_DEV_OCTEONTX2_CPT);
  64. int cn10k_cptvf_lmtst_init(struct otx2_cptvf_dev *cptvf)
  65. {
  66. struct pci_dev *pdev = cptvf->pdev;
  67. resource_size_t offset, size;
  68. if (!test_bit(CN10K_LMTST, &cptvf->cap_flag)) {
  69. cptvf->lfs.ops = &otx2_hw_ops;
  70. return 0;
  71. }
  72. cptvf->lfs.ops = &cn10k_hw_ops;
  73. offset = pci_resource_start(pdev, PCI_MBOX_BAR_NUM);
  74. size = pci_resource_len(pdev, PCI_MBOX_BAR_NUM);
  75. /* Map VF LMILINE region */
  76. cptvf->lfs.lmt_base = devm_ioremap_wc(&pdev->dev, offset, size);
  77. if (!cptvf->lfs.lmt_base) {
  78. dev_err(&pdev->dev, "Unable to map BAR4\n");
  79. return -ENOMEM;
  80. }
  81. return 0;
  82. }
  83. EXPORT_SYMBOL_NS_GPL(cn10k_cptvf_lmtst_init, CRYPTO_DEV_OCTEONTX2_CPT);