1 /* SPDX-License-Identifier: GPL-2.0-only 2 * Copyright (C) 2020 Marvell. 3 */ 4 5 #ifndef __OTX2_CPT_COMMON_H 6 #define __OTX2_CPT_COMMON_H 7 8 #include <linux/pci.h> 9 #include <linux/types.h> 10 #include <linux/module.h> 11 #include <linux/delay.h> 12 #include <linux/crypto.h> 13 #include "otx2_cpt_hw_types.h" 14 #include "rvu.h" 15 #include "mbox.h" 16 17 #define OTX2_CPT_MAX_VFS_NUM 128 18 #define OTX2_CPT_RVU_FUNC_ADDR_S(blk, slot, offs) \ 19 (((blk) << 20) | ((slot) << 12) | (offs)) 20 #define OTX2_CPT_RVU_PFFUNC(pf, func) \ 21 ((((pf) & RVU_PFVF_PF_MASK) << RVU_PFVF_PF_SHIFT) | \ 22 (((func) & RVU_PFVF_FUNC_MASK) << RVU_PFVF_FUNC_SHIFT)) 23 24 #define OTX2_CPT_INVALID_CRYPTO_ENG_GRP 0xFF 25 #define OTX2_CPT_NAME_LENGTH 64 26 #define OTX2_CPT_DMA_MINALIGN 128 27 28 #define BAD_OTX2_CPT_ENG_TYPE OTX2_CPT_MAX_ENG_TYPES 29 30 enum otx2_cpt_eng_type { 31 OTX2_CPT_AE_TYPES = 1, 32 OTX2_CPT_SE_TYPES = 2, 33 OTX2_CPT_IE_TYPES = 3, 34 OTX2_CPT_MAX_ENG_TYPES, 35 }; 36 37 /* Take mbox id from end of CPT mbox range in AF (range 0xA00 - 0xBFF) */ 38 #define MBOX_MSG_GET_ENG_GRP_NUM 0xBFF 39 #define MBOX_MSG_GET_CAPS 0xBFD 40 #define MBOX_MSG_GET_KVF_LIMITS 0xBFC 41 42 /* 43 * Message request and response to get engine group number 44 * which has attached a given type of engines (SE, AE, IE) 45 * This messages are only used between CPT PF <=> CPT VF 46 */ 47 struct otx2_cpt_egrp_num_msg { 48 struct mbox_msghdr hdr; 49 u8 eng_type; 50 }; 51 52 struct otx2_cpt_egrp_num_rsp { 53 struct mbox_msghdr hdr; 54 u8 eng_type; 55 u8 eng_grp_num; 56 }; 57 58 /* 59 * Message request and response to get kernel crypto limits 60 * This messages are only used between CPT PF <-> CPT VF 61 */ 62 struct otx2_cpt_kvf_limits_msg { 63 struct mbox_msghdr hdr; 64 }; 65 66 struct otx2_cpt_kvf_limits_rsp { 67 struct mbox_msghdr hdr; 68 u8 kvf_limits; 69 }; 70 71 /* CPT HW capabilities */ 72 union otx2_cpt_eng_caps { 73 u64 u; 74 struct { 75 u64 reserved_0_4:5; 76 u64 mul:1; 77 u64 sha1_sha2:1; 78 u64 chacha20:1; 79 u64 zuc_snow3g:1; 80 u64 sha3:1; 81 u64 aes:1; 82 u64 kasumi:1; 83 u64 des:1; 84 u64 crc:1; 85 u64 reserved_14_63:50; 86 }; 87 }; 88 89 /* 90 * Message request and response to get HW capabilities for each 91 * engine type (SE, IE, AE). 92 * This messages are only used between CPT PF <=> CPT VF 93 */ 94 struct otx2_cpt_caps_msg { 95 struct mbox_msghdr hdr; 96 }; 97 98 struct otx2_cpt_caps_rsp { 99 struct mbox_msghdr hdr; 100 u16 cpt_pf_drv_version; 101 u8 cpt_revision; 102 union otx2_cpt_eng_caps eng_caps[OTX2_CPT_MAX_ENG_TYPES]; 103 }; 104 105 static inline void otx2_cpt_write64(void __iomem *reg_base, u64 blk, u64 slot, 106 u64 offs, u64 val) 107 { 108 writeq_relaxed(val, reg_base + 109 OTX2_CPT_RVU_FUNC_ADDR_S(blk, slot, offs)); 110 } 111 112 static inline u64 otx2_cpt_read64(void __iomem *reg_base, u64 blk, u64 slot, 113 u64 offs) 114 { 115 return readq_relaxed(reg_base + 116 OTX2_CPT_RVU_FUNC_ADDR_S(blk, slot, offs)); 117 } 118 119 int otx2_cpt_send_ready_msg(struct otx2_mbox *mbox, struct pci_dev *pdev); 120 int otx2_cpt_send_mbox_msg(struct otx2_mbox *mbox, struct pci_dev *pdev); 121 122 int otx2_cpt_send_af_reg_requests(struct otx2_mbox *mbox, 123 struct pci_dev *pdev); 124 int otx2_cpt_add_read_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 125 u64 reg, u64 *val, int blkaddr); 126 int otx2_cpt_add_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 127 u64 reg, u64 val, int blkaddr); 128 int otx2_cpt_read_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 129 u64 reg, u64 *val, int blkaddr); 130 int otx2_cpt_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev, 131 u64 reg, u64 val, int blkaddr); 132 struct otx2_cptlfs_info; 133 int otx2_cpt_attach_rscrs_msg(struct otx2_cptlfs_info *lfs); 134 int otx2_cpt_detach_rsrcs_msg(struct otx2_cptlfs_info *lfs); 135 int otx2_cpt_msix_offset_msg(struct otx2_cptlfs_info *lfs); 136 137 #endif /* __OTX2_CPT_COMMON_H */ 138