Path: blob/master/drivers/crypto/marvell/octeontx2/otx2_cpt_common.h
26285 views
/* SPDX-License-Identifier: GPL-2.0-only1* Copyright (C) 2020 Marvell.2*/34#ifndef __OTX2_CPT_COMMON_H5#define __OTX2_CPT_COMMON_H67#include <linux/pci.h>8#include <linux/types.h>9#include <linux/module.h>10#include <linux/delay.h>11#include <linux/crypto.h>12#include <net/devlink.h>13#include "otx2_cpt_hw_types.h"14#include "rvu.h"15#include "mbox.h"1617#define OTX2_CPT_MAX_VFS_NUM 12818#define OTX2_CPT_RVU_FUNC_ADDR_S(blk, slot, offs) \19(((blk) << 20) | ((slot) << 12) | (offs))2021#define OTX2_CPT_RVU_PFFUNC(pdev, pf, func) rvu_make_pcifunc(pdev, pf, func)2223#define OTX2_CPT_INVALID_CRYPTO_ENG_GRP 0xFF24#define OTX2_CPT_NAME_LENGTH 6425#define OTX2_CPT_DMA_MINALIGN 1282627/* HW capability flags */28#define CN10K_MBOX 029#define CN10K_LMTST 13031#define BAD_OTX2_CPT_ENG_TYPE OTX2_CPT_MAX_ENG_TYPES3233enum otx2_cpt_eng_type {34OTX2_CPT_AE_TYPES = 1,35OTX2_CPT_SE_TYPES = 2,36OTX2_CPT_IE_TYPES = 3,37OTX2_CPT_MAX_ENG_TYPES,38};3940/* Take mbox id from end of CPT mbox range in AF (range 0xA00 - 0xBFF) */41#define MBOX_MSG_RX_INLINE_IPSEC_LF_CFG 0xBFE42#define MBOX_MSG_GET_ENG_GRP_NUM 0xBFF43#define MBOX_MSG_GET_CAPS 0xBFD44#define MBOX_MSG_GET_KVF_LIMITS 0xBFC4546/*47* Message request to config cpt lf for inline inbound ipsec.48* This message is only used between CPT PF <-> CPT VF49*/50struct otx2_cpt_rx_inline_lf_cfg {51struct mbox_msghdr hdr;52u16 sso_pf_func;53u16 param1;54u16 param2;55u16 opcode;56u32 credit;57u32 credit_th;58u16 bpid;59u32 reserved;60u8 ctx_ilen_valid : 1;61u8 ctx_ilen : 7;62};6364/*65* Message request and response to get engine group number66* which has attached a given type of engines (SE, AE, IE)67* This messages are only used between CPT PF <=> CPT VF68*/69struct otx2_cpt_egrp_num_msg {70struct mbox_msghdr hdr;71u8 eng_type;72};7374struct otx2_cpt_egrp_num_rsp {75struct mbox_msghdr hdr;76u8 eng_type;77u8 eng_grp_num;78};7980/*81* Message request and response to get kernel crypto limits82* This messages are only used between CPT PF <-> CPT VF83*/84struct otx2_cpt_kvf_limits_msg {85struct mbox_msghdr hdr;86};8788struct otx2_cpt_kvf_limits_rsp {89struct mbox_msghdr hdr;90u8 kvf_limits;91};9293/* CPT HW capabilities */94union otx2_cpt_eng_caps {95u64 u;96struct {97u64 reserved_0_4:5;98u64 mul:1;99u64 sha1_sha2:1;100u64 chacha20:1;101u64 zuc_snow3g:1;102u64 sha3:1;103u64 aes:1;104u64 kasumi:1;105u64 des:1;106u64 crc:1;107u64 mmul:1;108u64 reserved_15_33:19;109u64 pdcp_chain:1;110u64 reserved_35_63:29;111};112};113114/*115* Message request and response to get HW capabilities for each116* engine type (SE, IE, AE).117* This messages are only used between CPT PF <=> CPT VF118*/119struct otx2_cpt_caps_msg {120struct mbox_msghdr hdr;121};122123struct otx2_cpt_caps_rsp {124struct mbox_msghdr hdr;125u16 cpt_pf_drv_version;126u8 cpt_revision;127union otx2_cpt_eng_caps eng_caps[OTX2_CPT_MAX_ENG_TYPES];128};129130static inline void otx2_cpt_write64(void __iomem *reg_base, u64 blk, u64 slot,131u64 offs, u64 val)132{133writeq_relaxed(val, reg_base +134OTX2_CPT_RVU_FUNC_ADDR_S(blk, slot, offs));135}136137static inline u64 otx2_cpt_read64(void __iomem *reg_base, u64 blk, u64 slot,138u64 offs)139{140return readq_relaxed(reg_base +141OTX2_CPT_RVU_FUNC_ADDR_S(blk, slot, offs));142}143144static inline bool is_dev_otx2(struct pci_dev *pdev)145{146return pdev->device == OTX2_CPT_PCI_PF_DEVICE_ID ||147pdev->device == OTX2_CPT_PCI_VF_DEVICE_ID;148}149150static inline bool is_dev_cn10ka(struct pci_dev *pdev)151{152return pdev->subsystem_device == CPT_PCI_SUBSYS_DEVID_CN10K_A;153}154155static inline bool is_dev_cn10ka_ax(struct pci_dev *pdev)156{157return pdev->subsystem_device == CPT_PCI_SUBSYS_DEVID_CN10K_A &&158((pdev->revision & 0xFF) == 4 ||159(pdev->revision & 0xFF) == 0x50 ||160(pdev->revision & 0xFF) == 0x51);161}162163static inline bool is_dev_cn10kb(struct pci_dev *pdev)164{165return pdev->subsystem_device == CPT_PCI_SUBSYS_DEVID_CN10K_B;166}167168static inline bool is_dev_cn10ka_b0(struct pci_dev *pdev)169{170return pdev->subsystem_device == CPT_PCI_SUBSYS_DEVID_CN10K_A &&171(pdev->revision & 0xFF) == 0x54;172}173174static inline void otx2_cpt_set_hw_caps(struct pci_dev *pdev,175unsigned long *cap_flag)176{177if (!is_dev_otx2(pdev)) {178__set_bit(CN10K_MBOX, cap_flag);179__set_bit(CN10K_LMTST, cap_flag);180}181}182183static inline bool cpt_is_errata_38550_exists(struct pci_dev *pdev)184{185return is_dev_otx2(pdev) || is_dev_cn10ka_ax(pdev);186}187188static inline bool cpt_feature_sgv2(struct pci_dev *pdev)189{190return !is_dev_otx2(pdev) && !is_dev_cn10ka_ax(pdev);191}192193int otx2_cpt_send_ready_msg(struct otx2_mbox *mbox, struct pci_dev *pdev);194int otx2_cpt_send_mbox_msg(struct otx2_mbox *mbox, struct pci_dev *pdev);195196int otx2_cpt_send_af_reg_requests(struct otx2_mbox *mbox,197struct pci_dev *pdev);198int otx2_cpt_add_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev,199u64 reg, u64 val, int blkaddr);200int otx2_cpt_read_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev,201u64 reg, u64 *val, int blkaddr);202int otx2_cpt_write_af_reg(struct otx2_mbox *mbox, struct pci_dev *pdev,203u64 reg, u64 val, int blkaddr);204struct otx2_cptlfs_info;205int otx2_cpt_attach_rscrs_msg(struct otx2_cptlfs_info *lfs);206int otx2_cpt_detach_rsrcs_msg(struct otx2_cptlfs_info *lfs);207int otx2_cpt_msix_offset_msg(struct otx2_cptlfs_info *lfs);208int otx2_cpt_sync_mbox_msg(struct otx2_mbox *mbox);209int otx2_cpt_lf_reset_msg(struct otx2_cptlfs_info *lfs, int slot);210int otx2_cpt_lmtst_tbl_setup_msg(struct otx2_cptlfs_info *lfs);211212#endif /* __OTX2_CPT_COMMON_H */213214215