linux/drivers/crypto/hisilicon/sec/sec_drv.h

/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2016-2017 HiSilicon Limited. */

#ifndef _SEC_DRV_H_
#define _SEC_DRV_H_

#include <crypto/algapi.h>
#include <linux/kfifo.h>

#define SEC_MAX_SGE_NUM
#define SEC_HW_RING_NUM

#define SEC_CMD_RING
#define SEC_OUTORDER_RING
#define SEC_DBG_RING

/* A reasonable length to balance memory use against flexibility */
#define SEC_QUEUE_LEN

#define SEC_MAX_SGE_NUM

struct sec_bd_info {};

enum sec_mem_region {};

#define SEC_NAME_SIZE
#define SEC_Q_NUM


/**
 * struct sec_queue_ring_cmd - store information about a SEC HW cmd ring
 * @used: Local counter used to cheaply establish if the ring is empty.
 * @lock: Protect against simultaneous adjusting of the read and write pointers.
 * @vaddr: Virtual address for the ram pages used for the ring.
 * @paddr: Physical address of the dma mapped region of ram used for the ring.
 * @callback: Callback function called on a ring element completing.
 */
struct sec_queue_ring_cmd {};

struct sec_debug_bd_info;
struct sec_queue_ring_db {};

struct sec_out_bd_info;
struct sec_queue_ring_cq {};

struct sec_dev_info;

enum sec_cipher_alg {};

/**
 * struct sec_alg_tfm_ctx - hardware specific tranformation context
 * @cipher_alg: Cipher algorithm enabled include encryption mode.
 * @key: Key storage if required.
 * @pkey: DMA address for the key storage.
 * @req_template: Request template to save time on setup.
 * @queue: The hardware queue associated with this tfm context.
 * @lock: Protect key and pkey to ensure they are consistent
 * @auth_buf: Current context buffer for auth operations.
 * @backlog: The backlog queue used for cases where our buffers aren't
 * large enough.
 */
struct sec_alg_tfm_ctx {};

/**
 * struct sec_request - data associate with a single crypto request
 * @elements: List of subparts of this request (hardware size restriction)
 * @num_elements: The number of subparts (used as an optimization)
 * @lock: Protect elements of this structure against concurrent change.
 * @tfm_ctx: hardware specific context.
 * @len_in: length of in sgl from upper layers
 * @len_out: length of out sgl from upper layers
 * @dma_iv: initialization vector - phsyical address
 * @err: store used to track errors across subelements of this request.
 * @req_base: pointer to base element of associate crypto context.
 * This is needed to allow shared handling skcipher, ahash etc.
 * @cb: completion callback.
 * @backlog_head: list head to allow backlog maintenance.
 *
 * The hardware is limited in the maximum size of data that it can
 * process from a single BD.  Typically this is fairly large (32MB)
 * but still requires the complexity of splitting the incoming
 * skreq up into a number of elements complete with appropriate
 * iv chaining.
 */
struct sec_request {};

/**
 * struct sec_request_el - A subpart of a request.
 * @head: allow us to attach this to the list in the sec_request
 * @req: hardware block descriptor corresponding to this request subpart
 * @in: hardware sgl for input - virtual address
 * @dma_in: hardware sgl for input - physical address
 * @sgl_in: scatterlist for this request subpart
 * @out: hardware sgl for output - virtual address
 * @dma_out: hardware sgl for output - physical address
 * @sgl_out: scatterlist for this request subpart
 * @sec_req: The request which this subpart forms a part of
 * @el_length: Number of bytes in this subpart. Needed to locate
 * last ivsize chunk for iv chaining.
 */
struct sec_request_el {};

/**
 * struct sec_queue - All the information about a HW queue
 * @dev_info: The parent SEC device to which this queue belongs.
 * @task_irq: Completion interrupt for the queue.
 * @name: Human readable queue description also used as irq name.
 * @ring: The several HW rings associated with one queue.
 * @regs: The iomapped device registers
 * @queue_id: Index of the queue used for naming and resource selection.
 * @in_use: Flag to say if the queue is in use.
 * @expected: The next expected element to finish assuming we were in order.
 * @uprocessed: A bitmap to track which OoO elements are done but not handled.
 * @softqueue: A software queue used when chaining requirements prevent direct
 *   use of the hardware queues.
 * @havesoftqueue: A flag to say we have a queues - as we may need one for the
 *   current mode.
 * @queuelock: Protect the soft queue from concurrent changes to avoid some
 *   potential loss of data races.
 * @shadow: Pointers back to the shadow copy of the hardware ring element
 *   need because we can't store any context reference in the bd element.
 */
struct sec_queue {};

/**
 * struct sec_hw_sge: Track each of the 64 element SEC HW SGL entries
 * @buf: The IOV dma address for this entry.
 * @len: Length of this IOV.
 * @pad: Reserved space.
 */
struct sec_hw_sge {};

/**
 * struct sec_hw_sgl: One hardware SGL entry.
 * @next_sgl: The next entry if we need to chain dma address. Null if last.
 * @entry_sum_in_chain: The full count of SGEs - only matters for first SGL.
 * @entry_sum_in_sgl: The number of SGEs in this SGL element.
 * @flag: Unused in skciphers.
 * @serial_num: Unsued in skciphers.
 * @cpuid: Currently unused.
 * @data_bytes_in_sgl: Count of bytes from all SGEs in this SGL.
 * @next: Virtual address used to stash the next sgl - useful in completion.
 * @reserved: A reserved field not currently used.
 * @sge_entries: The (up to) 64 Scatter Gather Entries, representing IOVs.
 * @node: Currently unused.
 */
struct sec_hw_sgl {};

struct dma_pool;

/**
 * struct sec_dev_info: The full SEC unit comprising queues and processors.
 * @sec_id: Index used to track which SEC this is when more than one is present.
 * @num_saas: The number of backed processors enabled.
 * @regs: iomapped register regions shared by whole SEC unit.
 * @dev_lock: Protects concurrent queue allocation / freeing for the SEC.
 * @queues: The 16 queues that this SEC instance provides.
 * @dev: Device pointer.
 * @hw_sgl_pool: DMA pool used to mimise mapping for the scatter gather lists.
 */
struct sec_dev_info {};

int sec_queue_send(struct sec_queue *queue, struct sec_bd_info *msg, void *ctx);
bool sec_queue_can_enqueue(struct sec_queue *queue, int num);
int sec_queue_stop_release(struct sec_queue *queue);
struct sec_queue *sec_queue_alloc_start_safe(void);
bool sec_queue_empty(struct sec_queue *queue);

/* Algorithm specific elements from sec_algs.c */
void sec_alg_callback(struct sec_bd_info *resp, void *ctx);
int sec_algs_register(void);
void sec_algs_unregister(void);

#endif /* _SEC_DRV_H_ */