1 /* Common header for Virtio crypto device.
3 * Copyright 2016 HUAWEI TECHNOLOGIES CO., LTD.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #ifndef _VIRTIO_CRYPTO_COMMON_H
20 #define _VIRTIO_CRYPTO_COMMON_H
22 #include <linux/virtio.h>
23 #include <linux/crypto.h>
24 #include <linux/spinlock.h>
25 #include <crypto/aead.h>
26 #include <crypto/aes.h>
27 #include <crypto/authenc.h>
28 #include <crypto/engine.h>
31 /* Internal representation of a data virtqueue */
33 /* Virtqueue associated with this send _queue */
36 /* To protect the vq operations for the dataq */
39 /* Name of the tx queue: dataq.$index */
42 struct crypto_engine
*engine
;
45 struct virtio_crypto
{
46 struct virtio_device
*vdev
;
47 struct virtqueue
*ctrl_vq
;
48 struct data_queue
*data_vq
;
50 /* To protect the vq operations for the controlq */
53 /* Maximum of data queues supported by the device */
56 /* Number of queue currently used by the driver */
59 /* Maximum length of cipher key */
60 u32 max_cipher_key_len
;
61 /* Maximum length of authenticated key */
63 /* Maximum size of per request */
66 /* Control VQ buffers: protected by the ctrl_lock */
67 struct virtio_crypto_op_ctrl_req ctrl
;
68 struct virtio_crypto_session_input input
;
69 struct virtio_crypto_inhdr ctrl_status
;
73 struct list_head list
;
77 /* Does the affinity hint is set for virtqueues? */
78 bool affinity_hint_set
;
81 struct virtio_crypto_sym_session_info
{
82 /* Backend session id, which come from the host side */
86 struct virtio_crypto_request
;
87 typedef void (*virtio_crypto_data_callback
)
88 (struct virtio_crypto_request
*vc_req
, int len
);
90 struct virtio_crypto_request
{
92 struct virtio_crypto_op_data_req
*req_data
;
93 struct scatterlist
**sgs
;
94 struct data_queue
*dataq
;
95 virtio_crypto_data_callback alg_cb
;
98 int virtcrypto_devmgr_add_dev(struct virtio_crypto
*vcrypto_dev
);
99 struct list_head
*virtcrypto_devmgr_get_head(void);
100 void virtcrypto_devmgr_rm_dev(struct virtio_crypto
*vcrypto_dev
);
101 struct virtio_crypto
*virtcrypto_devmgr_get_first(void);
102 int virtcrypto_dev_in_use(struct virtio_crypto
*vcrypto_dev
);
103 int virtcrypto_dev_get(struct virtio_crypto
*vcrypto_dev
);
104 void virtcrypto_dev_put(struct virtio_crypto
*vcrypto_dev
);
105 int virtcrypto_dev_started(struct virtio_crypto
*vcrypto_dev
);
106 struct virtio_crypto
*virtcrypto_get_dev_node(int node
);
107 int virtcrypto_dev_start(struct virtio_crypto
*vcrypto
);
108 void virtcrypto_dev_stop(struct virtio_crypto
*vcrypto
);
109 int virtio_crypto_ablkcipher_crypt_req(
110 struct crypto_engine
*engine
,
111 struct ablkcipher_request
*req
);
114 virtcrypto_clear_request(struct virtio_crypto_request
*vc_req
);
116 static inline int virtio_crypto_get_current_node(void)
121 node
= topology_physical_package_id(cpu
);
127 int virtio_crypto_algs_register(void);
128 void virtio_crypto_algs_unregister(void);
130 #endif /* _VIRTIO_CRYPTO_COMMON_H */