3b038a76f87acab86b69c2d4a969d07170d94cd3
[dpdk.git] / drivers / crypto / virtio / virtio_rxtx.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD.
3  */
4 #include "virtqueue.h"
5 #include "virtio_cryptodev.h"
6
7 static int
8 virtio_crypto_vring_start(struct virtqueue *vq)
9 {
10         struct virtio_crypto_hw *hw = vq->hw;
11         int i, size = vq->vq_nentries;
12         struct vring *vr = &vq->vq_ring;
13         uint8_t *ring_mem = vq->vq_ring_virt_mem;
14
15         PMD_INIT_FUNC_TRACE();
16
17         vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN);
18         vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
19         vq->vq_free_cnt = vq->vq_nentries;
20
21         /* Chain all the descriptors in the ring with an END */
22         for (i = 0; i < size - 1; i++)
23                 vr->desc[i].next = (uint16_t)(i + 1);
24         vr->desc[i].next = VQ_RING_DESC_CHAIN_END;
25
26         /*
27          * Disable device(host) interrupting guest
28          */
29         virtqueue_disable_intr(vq);
30
31         /*
32          * Set guest physical address of the virtqueue
33          * in VIRTIO_PCI_QUEUE_PFN config register of device
34          * to share with the backend
35          */
36         if (VTPCI_OPS(hw)->setup_queue(hw, vq) < 0) {
37                 VIRTIO_CRYPTO_INIT_LOG_ERR("setup_queue failed");
38                 return -EINVAL;
39         }
40
41         return 0;
42 }
43
44 void
45 virtio_crypto_ctrlq_start(struct rte_cryptodev *dev)
46 {
47         struct virtio_crypto_hw *hw = dev->data->dev_private;
48
49         if (hw->cvq) {
50                 virtio_crypto_vring_start(hw->cvq);
51                 VIRTQUEUE_DUMP((struct virtqueue *)hw->cvq);
52         }
53 }
54
55 void
56 virtio_crypto_dataq_start(struct rte_cryptodev *dev)
57 {
58         /*
59          * Start data vrings
60          * -    Setup vring structure for data queues
61          */
62         uint16_t i;
63         struct virtio_crypto_hw *hw = dev->data->dev_private;
64
65         PMD_INIT_FUNC_TRACE();
66
67         /* Start data vring. */
68         for (i = 0; i < hw->max_dataqueues; i++) {
69                 virtio_crypto_vring_start(dev->data->queue_pairs[i]);
70                 VIRTQUEUE_DUMP((struct virtqueue *)dev->data->queue_pairs[i]);
71         }
72 }
73
74 uint16_t
75 virtio_crypto_pkt_rx_burst(
76         void *tx_queue __rte_unused,
77         struct rte_crypto_op **rx_pkts __rte_unused,
78         uint16_t nb_pkts __rte_unused)
79 {
80         uint16_t nb_rx = 0;
81
82         return nb_rx;
83 }
84
85 uint16_t
86 virtio_crypto_pkt_tx_burst(
87         void *tx_queue __rte_unused,
88         struct rte_crypto_op **tx_pkts __rte_unused,
89         uint16_t nb_pkts __rte_unused)
90 {
91         uint16_t nb_tx = 0;
92
93         return nb_tx;
94 }