compress/zlib: introduce zlib PMD
[dpdk.git] / drivers / compress / zlib / zlib_pmd.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium Networks
3  */
4
5 #include <rte_bus_vdev.h>
6 #include <rte_common.h>
7
8 #include "zlib_pmd_private.h"
9
10 static int
11 zlib_create(const char *name,
12                 struct rte_vdev_device *vdev,
13                 struct rte_compressdev_pmd_init_params *init_params)
14 {
15         struct rte_compressdev *dev;
16
17         dev = rte_compressdev_pmd_create(name, &vdev->device,
18                         sizeof(struct zlib_private), init_params);
19         if (dev == NULL) {
20                 ZLIB_PMD_ERR("driver %s: create failed", init_params->name);
21                 return -ENODEV;
22         }
23
24         return 0;
25 }
26
27 static int
28 zlib_probe(struct rte_vdev_device *vdev)
29 {
30         struct rte_compressdev_pmd_init_params init_params = {
31                 "",
32                 rte_socket_id()
33         };
34         const char *name;
35         const char *input_args;
36         int retval;
37
38         name = rte_vdev_device_name(vdev);
39
40         if (name == NULL)
41                 return -EINVAL;
42
43         input_args = rte_vdev_device_args(vdev);
44
45         retval = rte_compressdev_pmd_parse_input_args(&init_params, input_args);
46         if (retval < 0) {
47                 ZLIB_PMD_LOG(ERR,
48                         "Failed to parse initialisation arguments[%s]\n",
49                         input_args);
50                 return -EINVAL;
51         }
52
53         return zlib_create(name, vdev, &init_params);
54 }
55
56 static int
57 zlib_remove(struct rte_vdev_device *vdev)
58 {
59         struct rte_compressdev *compressdev;
60         const char *name;
61
62         name = rte_vdev_device_name(vdev);
63         if (name == NULL)
64                 return -EINVAL;
65
66         compressdev = rte_compressdev_pmd_get_named_dev(name);
67         if (compressdev == NULL)
68                 return -ENODEV;
69
70         return rte_compressdev_pmd_destroy(compressdev);
71 }
72
73 static struct rte_vdev_driver zlib_pmd_drv = {
74         .probe = zlib_probe,
75         .remove = zlib_remove
76 };
77
78 RTE_PMD_REGISTER_VDEV(COMPRESSDEV_NAME_ZLIB_PMD, zlib_pmd_drv);
79 RTE_INIT(zlib_init_log);
80
81 static void
82 zlib_init_log(void)
83 {
84         zlib_logtype_driver = rte_log_register("pmd.compress.zlib");
85         if (zlib_logtype_driver >= 0)
86                 rte_log_set_level(zlib_logtype_driver, RTE_LOG_INFO);
87 }