vdpa/sfc: support device initialization
[dpdk.git] / drivers / vdpa / sfc / sfc_vdpa_ops.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020-2021 Xilinx, Inc.
3  */
4
5 #include <rte_malloc.h>
6 #include <rte_vdpa.h>
7 #include <rte_vhost.h>
8
9 #include <vdpa_driver.h>
10
11 #include "sfc_vdpa_ops.h"
12 #include "sfc_vdpa.h"
13
14 /* Dummy functions for mandatory vDPA ops to pass vDPA device registration.
15  * In subsequent patches these ops would be implemented.
16  */
17 static int
18 sfc_vdpa_get_queue_num(struct rte_vdpa_device *vdpa_dev, uint32_t *queue_num)
19 {
20         RTE_SET_USED(vdpa_dev);
21         RTE_SET_USED(queue_num);
22
23         return -1;
24 }
25
26 static int
27 sfc_vdpa_get_features(struct rte_vdpa_device *vdpa_dev, uint64_t *features)
28 {
29         RTE_SET_USED(vdpa_dev);
30         RTE_SET_USED(features);
31
32         return -1;
33 }
34
35 static int
36 sfc_vdpa_get_protocol_features(struct rte_vdpa_device *vdpa_dev,
37                                uint64_t *features)
38 {
39         RTE_SET_USED(vdpa_dev);
40         RTE_SET_USED(features);
41
42         return -1;
43 }
44
45 static int
46 sfc_vdpa_dev_config(int vid)
47 {
48         RTE_SET_USED(vid);
49
50         return -1;
51 }
52
53 static int
54 sfc_vdpa_dev_close(int vid)
55 {
56         RTE_SET_USED(vid);
57
58         return -1;
59 }
60
61 static int
62 sfc_vdpa_set_vring_state(int vid, int vring, int state)
63 {
64         RTE_SET_USED(vid);
65         RTE_SET_USED(vring);
66         RTE_SET_USED(state);
67
68         return -1;
69 }
70
71 static int
72 sfc_vdpa_set_features(int vid)
73 {
74         RTE_SET_USED(vid);
75
76         return -1;
77 }
78
79 static struct rte_vdpa_dev_ops sfc_vdpa_ops = {
80         .get_queue_num = sfc_vdpa_get_queue_num,
81         .get_features = sfc_vdpa_get_features,
82         .get_protocol_features = sfc_vdpa_get_protocol_features,
83         .dev_conf = sfc_vdpa_dev_config,
84         .dev_close = sfc_vdpa_dev_close,
85         .set_vring_state = sfc_vdpa_set_vring_state,
86         .set_features = sfc_vdpa_set_features,
87 };
88
89 struct sfc_vdpa_ops_data *
90 sfc_vdpa_device_init(void *dev_handle, enum sfc_vdpa_context context)
91 {
92         struct sfc_vdpa_ops_data *ops_data;
93         struct rte_pci_device *pci_dev;
94
95         /* Create vDPA ops context */
96         ops_data = rte_zmalloc("vdpa", sizeof(struct sfc_vdpa_ops_data), 0);
97         if (ops_data == NULL)
98                 return NULL;
99
100         ops_data->vdpa_context = context;
101         ops_data->dev_handle = dev_handle;
102
103         pci_dev = sfc_vdpa_adapter_by_dev_handle(dev_handle)->pdev;
104
105         /* Register vDPA Device */
106         sfc_vdpa_log_init(dev_handle, "register vDPA device");
107         ops_data->vdpa_dev =
108                 rte_vdpa_register_device(&pci_dev->device, &sfc_vdpa_ops);
109         if (ops_data->vdpa_dev == NULL) {
110                 sfc_vdpa_err(dev_handle, "vDPA device registration failed");
111                 goto fail_register_device;
112         }
113
114         ops_data->state = SFC_VDPA_STATE_INITIALIZED;
115
116         return ops_data;
117
118 fail_register_device:
119         rte_free(ops_data);
120         return NULL;
121 }
122
123 void
124 sfc_vdpa_device_fini(struct sfc_vdpa_ops_data *ops_data)
125 {
126         rte_vdpa_unregister_device(ops_data->vdpa_dev);
127
128         rte_free(ops_data);
129 }