xref: /OK3568_Linux_fs/kernel/drivers/crypto/rockchip/cryptodev_linux/rk_cryptodev.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 /* Copyright (c) 2021 Rockchip Electronics Co. Ltd. */
4 
5 #ifndef __RK_CRYPTODEV_H__
6 #define __RK_CRYPTODEV_H__
7 
8 #include <linux/device.h>
9 #include <uapi/linux/rk_cryptodev.h>
10 #include "cryptodev.h"
11 
12 /* compatibility stuff */
13 #ifdef CONFIG_COMPAT
14 #include <linux/compat.h>
15 
16 /* input of RIOCCRYPT_FD */
17 struct compat_crypt_fd_op {
18 	uint32_t	ses;		/* session identifier */
19 	uint16_t	op;		/* COP_ENCRYPT or COP_DECRYPT */
20 	uint16_t	flags;		/* see COP_FLAG_* */
21 	uint32_t	len;		/* length of source data */
22 	int		src_fd;		/* source data */
23 	int		dst_fd;		/* pointer to output data */
24 	compat_uptr_t	mac;/* pointer to output data for hash/MAC operations */
25 	compat_uptr_t	iv;/* initialization vector for encryption operations */
26 };
27 
28 /* input of RIOCCRYPT_FD_MAP/RIOCCRYPT_FD_UNMAP */
29 struct compat_crypt_fd_map_op {
30 	int		dma_fd;		/* session identifier */
31 	uint32_t	phys_addr;	/* physics addr */
32 };
33 
34 /* compat ioctls, defined for the above structs */
35 #define COMPAT_RIOCCRYPT_FD		_IOWR('r', 104, struct compat_crypt_fd_op)
36 #define COMPAT_RIOCCRYPT_FD_MAP		_IOWR('r', 105, struct compat_crypt_fd_map_op)
37 #define COMPAT_RIOCCRYPT_FD_UNMAP	_IOW('r',  106, struct compat_crypt_fd_map_op)
38 #define COMPAT_RIOCCRYPT_CPU_ACCESS	_IOW('r',  107, struct compat_crypt_fd_map_op)
39 #define COMPAT_RIOCCRYPT_DEV_ACCESS	_IOW('r',  108, struct compat_crypt_fd_map_op)
40 
41 
42 #endif /* CONFIG_COMPAT */
43 
44 /* kernel-internal extension to struct crypt_op */
45 struct kernel_crypt_fd_op {
46 	struct crypt_fd_op cop;
47 
48 	int ivlen;
49 	__u8 iv[EALG_MAX_BLOCK_LEN];
50 
51 	int digestsize;
52 	uint8_t hash_output[AALG_MAX_RESULT_LEN];
53 
54 	struct task_struct *task;
55 	struct mm_struct *mm;
56 };
57 
58 struct kernel_crypt_auth_fd_op {
59 	struct crypt_auth_fd_op caop;
60 
61 	int dst_len; /* based on src_len */
62 	__u8 iv[EALG_MAX_BLOCK_LEN];
63 	int ivlen;
64 
65 	struct task_struct *task;
66 	struct mm_struct *mm;
67 };
68 
69 /* kernel-internal extension to struct crypt_fd_map_op */
70 struct kernel_crypt_fd_map_op {
71 	struct crypt_fd_map_op mop;
72 };
73 
74 /* kernel-internal extension to struct crypt_op */
75 struct kernel_crypt_rsa_op {
76 	struct crypt_rsa_op rop;
77 
78 	struct task_struct *task;
79 	struct mm_struct *mm;
80 };
81 
82 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ROCKCHIP_DEV)
83 int rk_cryptodev_register_dev(struct device *dev, const char *name);
84 int rk_cryptodev_unregister_dev(struct device *dev);
85 #else
rk_cryptodev_register_dev(struct device * dev,const char * name)86 static inline int rk_cryptodev_register_dev(struct device *dev, const char *name)
87 {
88 	return 0;
89 }
90 
rk_cryptodev_unregister_dev(struct device * dev)91 static inline int rk_cryptodev_unregister_dev(struct device *dev)
92 {
93 	return 0;
94 }
95 #endif
96 
97 long
98 rk_cryptodev_ioctl(struct fcrypt *fcr, unsigned int cmd, unsigned long arg_);
99 
100 long
101 rk_compat_cryptodev_ioctl(struct fcrypt *fcr, unsigned int cmd, unsigned long arg_);
102 
103 const char *rk_get_cipher_name(uint32_t id, int *is_stream, int *is_aead);
104 
105 const char *rk_get_hash_name(uint32_t id, int *is_hmac);
106 
107 bool rk_cryptodev_multi_thread(const char *name);
108 
109 #endif
110