Path: blob/master/drivers/crypto/marvell/octeontx/otx_cptvf_reqmgr.h
26289 views
/* SPDX-License-Identifier: GPL-2.01* Marvell OcteonTX CPT driver2*3* Copyright (C) 2019 Marvell International Ltd.4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*/910#ifndef __OTX_CPTVF_REQUEST_MANAGER_H11#define __OTX_CPTVF_REQUEST_MANAGER_H1213#include <linux/types.h>14#include <linux/crypto.h>15#include <linux/pci.h>16#include "otx_cpt_hw_types.h"1718/*19* Maximum total number of SG buffers is 100, we divide it equally20* between input and output21*/22#define OTX_CPT_MAX_SG_IN_CNT 5023#define OTX_CPT_MAX_SG_OUT_CNT 502425/* DMA mode direct or SG */26#define OTX_CPT_DMA_DIRECT_DIRECT 027#define OTX_CPT_DMA_GATHER_SCATTER 12829/* Context source CPTR or DPTR */30#define OTX_CPT_FROM_CPTR 031#define OTX_CPT_FROM_DPTR 13233/* CPT instruction queue alignment */34#define OTX_CPT_INST_Q_ALIGNMENT 12835#define OTX_CPT_MAX_REQ_SIZE 655353637/* Default command timeout in seconds */38#define OTX_CPT_COMMAND_TIMEOUT 439#define OTX_CPT_TIMER_HOLD 0x03F40#define OTX_CPT_COUNT_HOLD 3241#define OTX_CPT_TIME_IN_RESET_COUNT 54243/* Minimum and maximum values for interrupt coalescing */44#define OTX_CPT_COALESC_MIN_TIME_WAIT 0x045#define OTX_CPT_COALESC_MAX_TIME_WAIT ((1<<16)-1)46#define OTX_CPT_COALESC_MIN_NUM_WAIT 0x047#define OTX_CPT_COALESC_MAX_NUM_WAIT ((1<<20)-1)4849union otx_cpt_opcode_info {50u16 flags;51struct {52u8 major;53u8 minor;54} s;55};5657struct otx_cptvf_request {58u32 param1;59u32 param2;60u16 dlen;61union otx_cpt_opcode_info opcode;62};6364struct otx_cpt_buf_ptr {65u8 *vptr;66dma_addr_t dma_addr;67u16 size;68};6970union otx_cpt_ctrl_info {71u32 flags;72struct {73#if defined(__BIG_ENDIAN_BITFIELD)74u32 reserved0:26;75u32 grp:3; /* Group bits */76u32 dma_mode:2; /* DMA mode */77u32 se_req:1; /* To SE core */78#else79u32 se_req:1; /* To SE core */80u32 dma_mode:2; /* DMA mode */81u32 grp:3; /* Group bits */82u32 reserved0:26;83#endif84} s;85};8687/*88* CPT_INST_S software command definitions89* Words EI (0-3)90*/91union otx_cpt_iq_cmd_word0 {92u64 u64;93struct {94__be16 opcode;95__be16 param1;96__be16 param2;97__be16 dlen;98} s;99};100101union otx_cpt_iq_cmd_word3 {102u64 u64;103struct {104#if defined(__BIG_ENDIAN_BITFIELD)105u64 grp:3;106u64 cptr:61;107#else108u64 cptr:61;109u64 grp:3;110#endif111} s;112};113114struct otx_cpt_iq_cmd {115union otx_cpt_iq_cmd_word0 cmd;116u64 dptr;117u64 rptr;118union otx_cpt_iq_cmd_word3 cptr;119};120121struct otx_cpt_sglist_component {122union {123u64 len;124struct {125__be16 len0;126__be16 len1;127__be16 len2;128__be16 len3;129} s;130} u;131__be64 ptr0;132__be64 ptr1;133__be64 ptr2;134__be64 ptr3;135};136137struct otx_cpt_pending_entry {138u64 *completion_addr; /* Completion address */139struct otx_cpt_info_buffer *info;140/* Kernel async request callback */141void (*callback)(int status, void *arg1, void *arg2);142struct crypto_async_request *areq; /* Async request callback arg */143u8 resume_sender; /* Notify sender to resume sending requests */144u8 busy; /* Entry status (free/busy) */145};146147struct otx_cpt_pending_queue {148struct otx_cpt_pending_entry *head; /* Head of the queue */149u32 front; /* Process work from here */150u32 rear; /* Append new work here */151u32 pending_count; /* Pending requests count */152u32 qlen; /* Queue length */153spinlock_t lock; /* Queue lock */154};155156struct otx_cpt_req_info {157/* Kernel async request callback */158void (*callback)(int status, void *arg1, void *arg2);159struct crypto_async_request *areq; /* Async request callback arg */160struct otx_cptvf_request req;/* Request information (core specific) */161union otx_cpt_ctrl_info ctrl;/* User control information */162struct otx_cpt_buf_ptr in[OTX_CPT_MAX_SG_IN_CNT];163struct otx_cpt_buf_ptr out[OTX_CPT_MAX_SG_OUT_CNT];164u8 *iv_out; /* IV to send back */165u16 rlen; /* Output length */166u8 incnt; /* Number of input buffers */167u8 outcnt; /* Number of output buffers */168u8 req_type; /* Type of request */169u8 is_enc; /* Is a request an encryption request */170u8 is_trunc_hmac;/* Is truncated hmac used */171};172173struct otx_cpt_info_buffer {174struct otx_cpt_pending_entry *pentry;175struct otx_cpt_req_info *req;176struct pci_dev *pdev;177u64 *completion_addr;178u8 *out_buffer;179u8 *in_buffer;180dma_addr_t dptr_baddr;181dma_addr_t rptr_baddr;182dma_addr_t comp_baddr;183unsigned long time_in;184u32 dlen;185u32 dma_len;186u8 extra_time;187};188189static inline void do_request_cleanup(struct pci_dev *pdev,190struct otx_cpt_info_buffer *info)191{192struct otx_cpt_req_info *req;193int i;194195if (info->dptr_baddr)196dma_unmap_single(&pdev->dev, info->dptr_baddr,197info->dma_len, DMA_BIDIRECTIONAL);198199if (info->req) {200req = info->req;201for (i = 0; i < req->outcnt; i++) {202if (req->out[i].dma_addr)203dma_unmap_single(&pdev->dev,204req->out[i].dma_addr,205req->out[i].size,206DMA_BIDIRECTIONAL);207}208209for (i = 0; i < req->incnt; i++) {210if (req->in[i].dma_addr)211dma_unmap_single(&pdev->dev,212req->in[i].dma_addr,213req->in[i].size,214DMA_BIDIRECTIONAL);215}216}217kfree_sensitive(info);218}219220struct otx_cptvf_wqe;221void otx_cpt_dump_sg_list(struct pci_dev *pdev, struct otx_cpt_req_info *req);222void otx_cpt_post_process(struct otx_cptvf_wqe *wqe);223int otx_cpt_do_request(struct pci_dev *pdev, struct otx_cpt_req_info *req,224int cpu_num);225226#endif /* __OTX_CPTVF_REQUEST_MANAGER_H */227228229