![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * Public definitions for the CAAM/QI (Queue Interface) backend. 0004 * 0005 * Copyright 2013-2016 Freescale Semiconductor, Inc. 0006 * Copyright 2016-2017, 2020 NXP 0007 */ 0008 0009 #ifndef __QI_H__ 0010 #define __QI_H__ 0011 0012 #include <soc/fsl/qman.h> 0013 #include "compat.h" 0014 #include "desc.h" 0015 #include "desc_constr.h" 0016 0017 /* Length of a single buffer in the QI driver memory cache */ 0018 #define CAAM_QI_MEMCACHE_SIZE 768 0019 0020 extern bool caam_congested __read_mostly; 0021 0022 /* 0023 * This is the request structure the driver application should fill while 0024 * submitting a job to driver. 0025 */ 0026 struct caam_drv_req; 0027 0028 /* 0029 * caam_qi_cbk - application's callback function invoked by the driver when the 0030 * request has been successfully processed. 0031 * @drv_req: original request that was submitted 0032 * @status: completion status of request (0 - success, non-zero - error code) 0033 */ 0034 typedef void (*caam_qi_cbk)(struct caam_drv_req *drv_req, u32 status); 0035 0036 enum optype { 0037 ENCRYPT, 0038 DECRYPT, 0039 NUM_OP 0040 }; 0041 0042 /** 0043 * caam_drv_ctx - CAAM/QI backend driver context 0044 * 0045 * The jobs are processed by the driver against a driver context. 0046 * With every cryptographic context, a driver context is attached. 0047 * The driver context contains data for private use by driver. 0048 * For the applications, this is an opaque structure. 0049 * 0050 * @prehdr: preheader placed before shrd desc 0051 * @sh_desc: shared descriptor 0052 * @context_a: shared descriptor dma address 0053 * @req_fq: to-CAAM request frame queue 0054 * @rsp_fq: from-CAAM response frame queue 0055 * @refcnt: reference counter incremented for each frame enqueued in to-CAAM FQ 0056 * @cpu: cpu on which to receive CAAM response 0057 * @op_type: operation type 0058 * @qidev: device pointer for CAAM/QI backend 0059 */ 0060 struct caam_drv_ctx { 0061 u32 prehdr[2]; 0062 u32 sh_desc[MAX_SDLEN]; 0063 dma_addr_t context_a; 0064 struct qman_fq *req_fq; 0065 struct qman_fq *rsp_fq; 0066 refcount_t refcnt; 0067 int cpu; 0068 enum optype op_type; 0069 struct device *qidev; 0070 } ____cacheline_aligned; 0071 0072 /** 0073 * caam_drv_req - The request structure the driver application should fill while 0074 * submitting a job to driver. 0075 * @fd_sgt: QMan S/G pointing to output (fd_sgt[0]) and input (fd_sgt[1]) 0076 * buffers. 0077 * @cbk: callback function to invoke when job is completed 0078 * @app_ctx: arbitrary context attached with request by the application 0079 * 0080 * The fields mentioned below should not be used by application. 0081 * These are for private use by driver. 0082 * 0083 * @hdr__: linked list header to maintain list of outstanding requests to CAAM 0084 * @hwaddr: DMA address for the S/G table. 0085 */ 0086 struct caam_drv_req { 0087 struct qm_sg_entry fd_sgt[2]; 0088 struct caam_drv_ctx *drv_ctx; 0089 caam_qi_cbk cbk; 0090 void *app_ctx; 0091 } ____cacheline_aligned; 0092 0093 /** 0094 * caam_drv_ctx_init - Initialise a CAAM/QI driver context 0095 * 0096 * A CAAM/QI driver context must be attached with each cryptographic context. 0097 * This function allocates memory for CAAM/QI context and returns a handle to 0098 * the application. This handle must be submitted along with each enqueue 0099 * request to the driver by the application. 0100 * 0101 * @cpu: CPU where the application prefers to the driver to receive CAAM 0102 * responses. The request completion callback would be issued from this 0103 * CPU. 0104 * @sh_desc: shared descriptor pointer to be attached with CAAM/QI driver 0105 * context. 0106 * 0107 * Returns a driver context on success or negative error code on failure. 0108 */ 0109 struct caam_drv_ctx *caam_drv_ctx_init(struct device *qidev, int *cpu, 0110 u32 *sh_desc); 0111 0112 /** 0113 * caam_qi_enqueue - Submit a request to QI backend driver. 0114 * 0115 * The request structure must be properly filled as described above. 0116 * 0117 * @qidev: device pointer for QI backend 0118 * @req: CAAM QI request structure 0119 * 0120 * Returns 0 on success or negative error code on failure. 0121 */ 0122 int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req); 0123 0124 /** 0125 * caam_drv_ctx_busy - Check if there are too many jobs pending with CAAM 0126 * or too many CAAM responses are pending to be processed. 0127 * @drv_ctx: driver context for which job is to be submitted 0128 * 0129 * Returns caam congestion status 'true/false' 0130 */ 0131 bool caam_drv_ctx_busy(struct caam_drv_ctx *drv_ctx); 0132 0133 /** 0134 * caam_drv_ctx_update - Update QI driver context 0135 * 0136 * Invoked when shared descriptor is required to be change in driver context. 0137 * 0138 * @drv_ctx: driver context to be updated 0139 * @sh_desc: new shared descriptor pointer to be updated in QI driver context 0140 * 0141 * Returns 0 on success or negative error code on failure. 0142 */ 0143 int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc); 0144 0145 /** 0146 * caam_drv_ctx_rel - Release a QI driver context 0147 * @drv_ctx: context to be released 0148 */ 0149 void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx); 0150 0151 int caam_qi_init(struct platform_device *pdev); 0152 0153 /** 0154 * qi_cache_alloc - Allocate buffers from CAAM-QI cache 0155 * 0156 * Invoked when a user of the CAAM-QI (i.e. caamalg-qi) needs data which has 0157 * to be allocated on the hotpath. Instead of using malloc, one can use the 0158 * services of the CAAM QI memory cache (backed by kmem_cache). The buffers 0159 * will have a size of 256B, which is sufficient for hosting 16 SG entries. 0160 * 0161 * @flags: flags that would be used for the equivalent malloc(..) call 0162 * 0163 * Returns a pointer to a retrieved buffer on success or NULL on failure. 0164 */ 0165 void *qi_cache_alloc(gfp_t flags); 0166 0167 /** 0168 * qi_cache_free - Frees buffers allocated from CAAM-QI cache 0169 * 0170 * Invoked when a user of the CAAM-QI (i.e. caamalg-qi) no longer needs 0171 * the buffer previously allocated by a qi_cache_alloc call. 0172 * No checking is being done, the call is a passthrough call to 0173 * kmem_cache_free(...) 0174 * 0175 * @obj: object previously allocated using qi_cache_alloc() 0176 */ 0177 void qi_cache_free(void *obj); 0178 0179 #endif /* __QI_H__ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |