Imported Upstream version 16.04
[deb_dpdk.git] / drivers / crypto / qat / rte_qat_cryptodev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <rte_common.h>
35 #include <rte_dev.h>
36 #include <rte_malloc.h>
37 #include <rte_cryptodev_pmd.h>
38
39 #include "qat_crypto.h"
40 #include "qat_logs.h"
41
42 static struct rte_cryptodev_ops crypto_qat_ops = {
43
44                 /* Device related operations */
45                 .dev_configure          = qat_dev_config,
46                 .dev_start              = qat_dev_start,
47                 .dev_stop               = qat_dev_stop,
48                 .dev_close              = qat_dev_close,
49                 .dev_infos_get          = qat_dev_info_get,
50
51                 .stats_get              = qat_crypto_sym_stats_get,
52                 .stats_reset            = qat_crypto_sym_stats_reset,
53                 .queue_pair_setup       = qat_crypto_sym_qp_setup,
54                 .queue_pair_release     = qat_crypto_sym_qp_release,
55                 .queue_pair_start       = NULL,
56                 .queue_pair_stop        = NULL,
57                 .queue_pair_count       = NULL,
58
59                 /* Crypto related operations */
60                 .session_get_size       = qat_crypto_sym_get_session_private_size,
61                 .session_configure      = qat_crypto_sym_configure_session,
62                 .session_initialize     = qat_crypto_sym_session_init,
63                 .session_clear          = qat_crypto_sym_clear_session
64 };
65
66 /*
67  * The set of PCI devices this driver supports
68  */
69
70 static struct rte_pci_id pci_id_qat_map[] = {
71                 {
72                         .vendor_id = 0x8086,
73                         .device_id = 0x0443,
74                         .subsystem_vendor_id = PCI_ANY_ID,
75                         .subsystem_device_id = PCI_ANY_ID
76                 },
77                 {.device_id = 0},
78 };
79
80 static int
81 crypto_qat_dev_init(__attribute__((unused)) struct rte_cryptodev_driver *crypto_drv,
82                         struct rte_cryptodev *cryptodev)
83 {
84         struct qat_pmd_private *internals;
85
86         PMD_INIT_FUNC_TRACE();
87         PMD_DRV_LOG(DEBUG, "Found crypto device at %02x:%02x.%x",
88                 cryptodev->pci_dev->addr.bus,
89                 cryptodev->pci_dev->addr.devid,
90                 cryptodev->pci_dev->addr.function);
91
92         cryptodev->dev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
93         cryptodev->dev_ops = &crypto_qat_ops;
94
95         cryptodev->enqueue_burst = qat_pmd_enqueue_op_burst;
96         cryptodev->dequeue_burst = qat_pmd_dequeue_op_burst;
97
98         cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
99                         RTE_CRYPTODEV_FF_HW_ACCELERATED |
100                         RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
101
102         internals = cryptodev->data->dev_private;
103         internals->max_nb_sessions = RTE_QAT_PMD_MAX_NB_SESSIONS;
104
105         /*
106          * For secondary processes, we don't initialise any further as primary
107          * has already done this work. Only check we don't need a different
108          * RX function
109          */
110         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
111                 PMD_DRV_LOG(DEBUG, "Device already initialised by primary process");
112                 return 0;
113         }
114
115         return 0;
116 }
117
118 static struct rte_cryptodev_driver rte_qat_pmd = {
119         {
120                 .name = "rte_qat_pmd",
121                 .id_table = pci_id_qat_map,
122                 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
123         },
124         .cryptodev_init = crypto_qat_dev_init,
125         .dev_private_size = sizeof(struct qat_pmd_private),
126 };
127
128 static int
129 rte_qat_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
130 {
131         PMD_INIT_FUNC_TRACE();
132         return rte_cryptodev_pmd_driver_register(&rte_qat_pmd, PMD_PDEV);
133 }
134
135 static struct rte_driver pmd_qat_drv = {
136         .type = PMD_PDEV,
137         .init = rte_qat_pmd_init,
138 };
139
140 PMD_REGISTER_DRIVER(pmd_qat_drv);