compress/zlib: add basic ops
[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         dev->dev_ops = rte_zlib_pmd_ops;
25
26         return 0;
27 }
28
29 static int
30 zlib_probe(struct rte_vdev_device *vdev)
31 {
32         struct rte_compressdev_pmd_init_params init_params = {
33                 "",
34                 rte_socket_id()
35         };
36         const char *name;
37         const char *input_args;
38         int retval;
39
40         name = rte_vdev_device_name(vdev);
41
42         if (name == NULL)
43                 return -EINVAL;
44
45         input_args = rte_vdev_device_args(vdev);
46
47         retval = rte_compressdev_pmd_parse_input_args(&init_params, input_args);
48         if (retval < 0) {
49                 ZLIB_PMD_LOG(ERR,
50                         "Failed to parse initialisation arguments[%s]\n",
51                         input_args);
52                 return -EINVAL;
53         }
54
55         return zlib_create(name, vdev, &init_params);
56 }
57
58 static int
59 zlib_remove(struct rte_vdev_device *vdev)
60 {
61         struct rte_compressdev *compressdev;
62         const char *name;
63
64         name = rte_vdev_device_name(vdev);
65         if (name == NULL)
66                 return -EINVAL;
67
68         compressdev = rte_compressdev_pmd_get_named_dev(name);
69         if (compressdev == NULL)
70                 return -ENODEV;
71
72         return rte_compressdev_pmd_destroy(compressdev);
73 }
74
75 static struct rte_vdev_driver zlib_pmd_drv = {
76         .probe = zlib_probe,
77         .remove = zlib_remove
78 };
79
80 RTE_PMD_REGISTER_VDEV(COMPRESSDEV_NAME_ZLIB_PMD, zlib_pmd_drv);
81 RTE_INIT(zlib_init_log);
82
83 static void
84 zlib_init_log(void)
85 {
86         zlib_logtype_driver = rte_log_register("pmd.compress.zlib");
87         if (zlib_logtype_driver >= 0)
88                 rte_log_set_level(zlib_logtype_driver, RTE_LOG_INFO);
89 }