compress/isal: add device init and de-init
[dpdk.git] / drivers / compress / isal / isal_compress_pmd.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #include <rte_bus_vdev.h>
6 #include <rte_common.h>
7 #include <rte_malloc.h>
8 #include <rte_compressdev_pmd.h>
9
10 #include "isal_compress_pmd_private.h"
11
12 int isal_logtype_driver;
13
14 /* Create ISA-L compression device */
15 static int
16 compdev_isal_create(const char *name, struct rte_vdev_device *vdev,
17                 struct rte_compressdev_pmd_init_params *init_params)
18 {
19         struct rte_compressdev *dev;
20
21         dev = rte_compressdev_pmd_create(name, &vdev->device,
22                         sizeof(struct isal_comp_private), init_params);
23         if (dev == NULL) {
24                 ISAL_PMD_LOG(ERR, "failed to create compressdev vdev");
25                 return -EFAULT;
26         }
27
28         dev->dev_ops = isal_compress_pmd_ops;
29
30         return 0;
31 }
32
33 /** Remove compression device */
34 static int
35 compdev_isal_remove_dev(struct rte_vdev_device *vdev)
36 {
37         struct rte_compressdev *compdev;
38         const char *name;
39
40         name = rte_vdev_device_name(vdev);
41         if (name == NULL)
42                 return -EINVAL;
43
44         compdev = rte_compressdev_pmd_get_named_dev(name);
45         if (compdev == NULL)
46                 return -ENODEV;
47
48         return rte_compressdev_pmd_destroy(compdev);
49 }
50
51 /** Initialise ISA-L compression device */
52 static int
53 compdev_isal_probe(struct rte_vdev_device *dev)
54 {
55         struct rte_compressdev_pmd_init_params init_params = {
56                 "",
57                 rte_socket_id(),
58         };
59         const char *name, *args;
60         int retval;
61
62         name = rte_vdev_device_name(dev);
63         if (name == NULL)
64                 return -EINVAL;
65
66         args = rte_vdev_device_args(dev);
67
68         retval = rte_compressdev_pmd_parse_input_args(&init_params, args);
69         if (retval) {
70                 ISAL_PMD_LOG(ERR,
71                         "Failed to parse initialisation arguments[%s]\n", args);
72                 return -EINVAL;
73         }
74
75         return compdev_isal_create(name, dev, &init_params);
76 }
77
78 static struct rte_vdev_driver compdev_isal_pmd_drv = {
79         .probe = compdev_isal_probe,
80         .remove = compdev_isal_remove_dev,
81 };
82
83 RTE_PMD_REGISTER_VDEV(COMPDEV_NAME_ISAL_PMD, compdev_isal_pmd_drv);
84 RTE_PMD_REGISTER_PARAM_STRING(COMPDEV_NAME_ISAL_PMD,
85         "socket_id=<int>");
86
87 RTE_INIT(isal_init_log);
88
89 static void
90 isal_init_log(void)
91 {
92         isal_logtype_driver = rte_log_register("comp_isal");
93         if (isal_logtype_driver >= 0)
94                 rte_log_set_level(isal_logtype_driver, RTE_LOG_INFO);
95 }