1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 /* $FreeBSD$ */ 4 #ifndef _QAT_OCF_MEM_POOL_H_ 5 #define _QAT_OCF_MEM_POOL_H_ 6 7 /* System headers */ 8 #include <sys/types.h> 9 10 /* QAT specific headers */ 11 #include "cpa.h" 12 #include "cpa_cy_sym_dp.h" 13 #include "icp_qat_fw_la.h" 14 15 #define QAT_OCF_MAX_LEN (64 * 1024) 16 #define QAT_OCF_MAX_FLATS (32) 17 #define QAT_OCF_MAX_DIGEST SHA512_DIGEST_LENGTH 18 #define QAT_OCF_MAX_SYMREQ (256) 19 #define QAT_OCF_MEM_POOL_SIZE ((QAT_OCF_MAX_SYMREQ * 2 + 1) * 2) 20 #define QAT_OCF_MAXLEN 64 * 1024 21 22 /* Dedicated structure due to flexible arrays not allowed to be 23 * allocated on stack */ 24 struct qat_ocf_buffer_list { 25 Cpa64U reserved0; 26 Cpa32U numBuffers; 27 Cpa32U reserved1; 28 CpaPhysFlatBuffer flatBuffers[QAT_OCF_MAX_FLATS]; 29 }; 30 31 struct qat_ocf_dma_mem { 32 bus_dma_tag_t dma_tag; 33 bus_dmamap_t dma_map; 34 bus_dma_segment_t dma_seg; 35 void *dma_vaddr; 36 } __aligned(64); 37 38 struct qat_ocf_cookie { 39 /* Source SGLs */ 40 struct qat_ocf_buffer_list src_buffers; 41 /* Destination SGL */ 42 struct qat_ocf_buffer_list dst_buffers; 43 44 /* Cache OP data */ 45 CpaCySymDpOpData pOpdata; 46 47 /* IV max size taken from cryptdev */ 48 uint8_t qat_ocf_iv_buf[EALG_MAX_BLOCK_LEN]; 49 bus_addr_t qat_ocf_iv_buf_paddr; 50 uint8_t qat_ocf_digest[QAT_OCF_MAX_DIGEST]; 51 bus_addr_t qat_ocf_digest_paddr; 52 /* Used only in case of separated AAD and GCM, CCM and RC4 */ 53 uint8_t qat_ocf_gcm_aad[ICP_QAT_FW_CCM_GCM_AAD_SZ_MAX]; 54 bus_addr_t qat_ocf_gcm_aad_paddr; 55 56 /* Source SGLs */ 57 struct qat_ocf_dma_mem src_dma_mem; 58 bus_addr_t src_buffer_list_paddr; 59 60 /* Destination SGL */ 61 struct qat_ocf_dma_mem dst_dma_mem; 62 bus_addr_t dst_buffer_list_paddr; 63 64 /* AAD - used only if separated AAD is used by OCF and HW requires 65 * to have it at the beginning of source buffer */ 66 struct qat_ocf_dma_mem gcm_aad_dma_mem; 67 bus_addr_t gcm_aad_buffer_list_paddr; 68 CpaBoolean is_sep_aad_used; 69 70 /* Cache OP data */ 71 bus_addr_t pOpData_paddr; 72 /* misc */ 73 struct cryptop *crp_op; 74 75 /* This cookie tag and map */ 76 bus_dma_tag_t dma_tag; 77 bus_dmamap_t dma_map; 78 }; 79 80 struct qat_ocf_session { 81 CpaCySymSessionCtx sessionCtx; 82 Cpa32U sessionCtxSize; 83 Cpa32U authLen; 84 Cpa32U aadLen; 85 }; 86 87 struct qat_ocf_dsession { 88 struct qat_ocf_instance *qatInstance; 89 struct qat_ocf_session encSession; 90 struct qat_ocf_session decSession; 91 }; 92 93 struct qat_ocf_load_cb_arg { 94 struct cryptop *crp_op; 95 struct qat_ocf_cookie *qat_cookie; 96 CpaCySymDpOpData *pOpData; 97 int error; 98 }; 99 100 struct qat_ocf_instance { 101 CpaInstanceHandle cyInstHandle; 102 struct mtx cyInstMtx; 103 struct qat_ocf_dma_mem cookie_dmamem[QAT_OCF_MEM_POOL_SIZE]; 104 struct qat_ocf_cookie *cookie_pool[QAT_OCF_MEM_POOL_SIZE]; 105 struct qat_ocf_cookie *free_cookie[QAT_OCF_MEM_POOL_SIZE]; 106 int free_cookie_ptr; 107 struct mtx cookie_pool_mtx; 108 int32_t driver_id; 109 }; 110 111 /* Init/deinit */ 112 CpaStatus qat_ocf_cookie_pool_init(struct qat_ocf_instance *instance, 113 device_t dev); 114 void qat_ocf_cookie_pool_deinit(struct qat_ocf_instance *instance); 115 /* Alloc/free */ 116 CpaStatus qat_ocf_cookie_alloc(struct qat_ocf_instance *instance, 117 struct qat_ocf_cookie **buffers_out); 118 void qat_ocf_cookie_free(struct qat_ocf_instance *instance, 119 struct qat_ocf_cookie *cookie); 120 /* Pre/post sync */ 121 CpaStatus qat_ocf_cookie_dma_pre_sync(struct cryptop *crp, 122 CpaCySymDpOpData *pOpData); 123 CpaStatus qat_ocf_cookie_dma_post_sync(struct cryptop *crp, 124 CpaCySymDpOpData *pOpData); 125 /* Bus DMA unload */ 126 CpaStatus qat_ocf_cookie_dma_unload(struct cryptop *crp, 127 CpaCySymDpOpData *pOpData); 128 /* Bus DMA load callbacks */ 129 void qat_ocf_crypto_load_buf_cb(void *_arg, 130 bus_dma_segment_t *segs, 131 int nseg, 132 int error); 133 void qat_ocf_crypto_load_obuf_cb(void *_arg, 134 bus_dma_segment_t *segs, 135 int nseg, 136 int error); 137 void qat_ocf_crypto_load_aadbuf_cb(void *_arg, 138 bus_dma_segment_t *segs, 139 int nseg, 140 int error); 141 142 #endif /* _QAT_OCF_MEM_POOL_H_ */ 143