compress/octeontx: introduce octeontx zip PMD
[dpdk.git] / drivers / compress / octeontx / otx_zip_pmd.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium, Inc
3  */
4
5 #include <string.h>
6
7 #include <rte_byteorder.h>
8 #include <rte_common.h>
9 #include <rte_cpuflags.h>
10 #include <rte_malloc.h>
11
12 #include "otx_zip.h"
13
14 struct rte_compressdev_ops octtx_zip_pmd_ops = {
15
16 };
17
18 static int
19 zip_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
20         struct rte_pci_device *pci_dev)
21 {
22         int ret = 0;
23         char compressdev_name[RTE_COMPRESSDEV_NAME_MAX_LEN];
24         struct rte_compressdev *compressdev;
25         struct rte_compressdev_pmd_init_params init_params = {
26                 "",
27                 rte_socket_id(),
28         };
29
30         ZIP_PMD_INFO("vendor_id=0x%x device_id=0x%x",
31                         (unsigned int)pci_dev->id.vendor_id,
32                         (unsigned int)pci_dev->id.device_id);
33
34         rte_pci_device_name(&pci_dev->addr, compressdev_name,
35                             sizeof(compressdev_name));
36
37         compressdev = rte_compressdev_pmd_create(compressdev_name,
38                 &pci_dev->device, sizeof(struct zip_vf), &init_params);
39         if (compressdev == NULL) {
40                 ZIP_PMD_ERR("driver %s: create failed", init_params.name);
41                 return -ENODEV;
42         }
43
44         /*
45          * create only if proc_type is primary.
46          */
47         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
48                 /*  create vf dev with given pmd dev id */
49                 ret = zipvf_create(compressdev);
50                 if (ret < 0) {
51                         ZIP_PMD_ERR("Device creation failed");
52                         rte_compressdev_pmd_destroy(compressdev);
53                         return ret;
54                 }
55         }
56
57         compressdev->dev_ops = &octtx_zip_pmd_ops;
58         /* register rx/tx burst functions for data path */
59         compressdev->feature_flags = RTE_COMPDEV_FF_HW_ACCELERATED;
60         return ret;
61 }
62
63 static int
64 zip_pci_remove(struct rte_pci_device *pci_dev)
65 {
66         struct rte_compressdev *compressdev;
67         char compressdev_name[RTE_COMPRESSDEV_NAME_MAX_LEN];
68
69         if (pci_dev == NULL) {
70                 ZIP_PMD_ERR(" Invalid PCI Device\n");
71                 return -EINVAL;
72         }
73         rte_pci_device_name(&pci_dev->addr, compressdev_name,
74                         sizeof(compressdev_name));
75
76         compressdev = rte_compressdev_pmd_get_named_dev(compressdev_name);
77         if (compressdev == NULL)
78                 return -ENODEV;
79
80         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
81                 if (zipvf_destroy(compressdev) < 0)
82                         return -ENODEV;
83         }
84         return rte_compressdev_pmd_destroy(compressdev);
85 }
86
87 static struct rte_pci_id pci_id_octtx_zipvf_table[] = {
88         {
89                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
90                         PCI_DEVICE_ID_OCTEONTX_ZIPVF),
91         },
92         {
93                 .device_id = 0
94         },
95 };
96
97 /**
98  * Structure that represents a PCI driver
99  */
100 static struct rte_pci_driver octtx_zip_pmd = {
101         .id_table    = pci_id_octtx_zipvf_table,
102         .drv_flags   = RTE_PCI_DRV_NEED_MAPPING,
103         .probe       = zip_pci_probe,
104         .remove      = zip_pci_remove,
105 };
106
107 RTE_PMD_REGISTER_PCI(COMPRESSDEV_NAME_ZIP_PMD, octtx_zip_pmd);
108 RTE_PMD_REGISTER_PCI_TABLE(COMPRESSDEV_NAME_ZIP_PMD, pci_id_octtx_zipvf_table);
109
110 RTE_INIT(octtx_zip_init_log);
111
112 static void
113 octtx_zip_init_log(void)
114 {
115         octtx_zip_logtype_driver = rte_log_register("pmd.compress.octeontx");
116         if (octtx_zip_logtype_driver >= 0)
117                 rte_log_set_level(octtx_zip_logtype_driver, RTE_LOG_INFO);
118 }