/* SPDX-License-Identifier: GPL-2.0 */1/*2* Public definitions for the CAAM/QI (Queue Interface) backend.3*4* Copyright 2013-2016 Freescale Semiconductor, Inc.5* Copyright 2016-2017, 2020 NXP6*/78#ifndef __QI_H__9#define __QI_H__1011#include <crypto/algapi.h>12#include <linux/compiler_attributes.h>13#include <soc/fsl/qman.h>14#include "compat.h"15#include "desc.h"16#include "desc_constr.h"1718/* Length of a single buffer in the QI driver memory cache */19#define CAAM_QI_MEMCACHE_SIZE 7682021extern bool caam_congested __read_mostly;2223/*24* This is the request structure the driver application should fill while25* submitting a job to driver.26*/27struct caam_drv_req;2829/*30* caam_qi_cbk - application's callback function invoked by the driver when the31* request has been successfully processed.32* @drv_req: original request that was submitted33* @status: completion status of request (0 - success, non-zero - error code)34*/35typedef void (*caam_qi_cbk)(struct caam_drv_req *drv_req, u32 status);3637enum optype {38ENCRYPT,39DECRYPT,40NUM_OP41};4243/**44* caam_drv_ctx - CAAM/QI backend driver context45*46* The jobs are processed by the driver against a driver context.47* With every cryptographic context, a driver context is attached.48* The driver context contains data for private use by driver.49* For the applications, this is an opaque structure.50*51* @prehdr: preheader placed before shrd desc52* @sh_desc: shared descriptor53* @context_a: shared descriptor dma address54* @req_fq: to-CAAM request frame queue55* @rsp_fq: from-CAAM response frame queue56* @refcnt: reference counter incremented for each frame enqueued in to-CAAM FQ57* @cpu: cpu on which to receive CAAM response58* @op_type: operation type59* @qidev: device pointer for CAAM/QI backend60*/61struct caam_drv_ctx {62struct {63u32 prehdr[2];64u32 sh_desc[MAX_SDLEN];65} __aligned(CRYPTO_DMA_ALIGN);66dma_addr_t context_a;67struct qman_fq *req_fq;68struct qman_fq *rsp_fq;69refcount_t refcnt;70int cpu;71enum optype op_type;72struct device *qidev;73};7475/**76* caam_drv_req - The request structure the driver application should fill while77* submitting a job to driver.78* @fd_sgt: QMan S/G pointing to output (fd_sgt[0]) and input (fd_sgt[1])79* buffers.80* @cbk: callback function to invoke when job is completed81* @app_ctx: arbitrary context attached with request by the application82*83* The fields mentioned below should not be used by application.84* These are for private use by driver.85*86* @hdr__: linked list header to maintain list of outstanding requests to CAAM87* @hwaddr: DMA address for the S/G table.88*/89struct caam_drv_req {90struct qm_sg_entry fd_sgt[2];91struct caam_drv_ctx *drv_ctx;92caam_qi_cbk cbk;93void *app_ctx;94} __aligned(CRYPTO_DMA_ALIGN);9596/**97* caam_drv_ctx_init - Initialise a CAAM/QI driver context98*99* A CAAM/QI driver context must be attached with each cryptographic context.100* This function allocates memory for CAAM/QI context and returns a handle to101* the application. This handle must be submitted along with each enqueue102* request to the driver by the application.103*104* @cpu: CPU where the application prefers to the driver to receive CAAM105* responses. The request completion callback would be issued from this106* CPU.107* @sh_desc: shared descriptor pointer to be attached with CAAM/QI driver108* context.109*110* Returns a driver context on success or negative error code on failure.111*/112struct caam_drv_ctx *caam_drv_ctx_init(struct device *qidev, int *cpu,113u32 *sh_desc);114115/**116* caam_qi_enqueue - Submit a request to QI backend driver.117*118* The request structure must be properly filled as described above.119*120* @qidev: device pointer for QI backend121* @req: CAAM QI request structure122*123* Returns 0 on success or negative error code on failure.124*/125int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req);126127/**128* caam_drv_ctx_busy - Check if there are too many jobs pending with CAAM129* or too many CAAM responses are pending to be processed.130* @drv_ctx: driver context for which job is to be submitted131*132* Returns caam congestion status 'true/false'133*/134bool caam_drv_ctx_busy(struct caam_drv_ctx *drv_ctx);135136/**137* caam_drv_ctx_update - Update QI driver context138*139* Invoked when shared descriptor is required to be change in driver context.140*141* @drv_ctx: driver context to be updated142* @sh_desc: new shared descriptor pointer to be updated in QI driver context143*144* Returns 0 on success or negative error code on failure.145*/146int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc);147148/**149* caam_drv_ctx_rel - Release a QI driver context150* @drv_ctx: context to be released151*/152void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx);153154int caam_qi_init(struct platform_device *pdev);155156/**157* qi_cache_alloc - Allocate buffers from CAAM-QI cache158*159* Invoked when a user of the CAAM-QI (i.e. caamalg-qi) needs data which has160* to be allocated on the hotpath. Instead of using malloc, one can use the161* services of the CAAM QI memory cache (backed by kmem_cache). The buffers162* will have a size of 256B, which is sufficient for hosting 16 SG entries.163*164* @flags: flags that would be used for the equivalent malloc(..) call165*166* Returns a pointer to a retrieved buffer on success or NULL on failure.167*/168void *qi_cache_alloc(gfp_t flags);169170/**171* qi_cache_free - Frees buffers allocated from CAAM-QI cache172*173* Invoked when a user of the CAAM-QI (i.e. caamalg-qi) no longer needs174* the buffer previously allocated by a qi_cache_alloc call.175* No checking is being done, the call is a passthrough call to176* kmem_cache_free(...)177*178* @obj: object previously allocated using qi_cache_alloc()179*/180void qi_cache_free(void *obj);181182#endif /* __QI_H__ */183184185