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