Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2022 Intel Corporation.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #define ALLOW_INTERNAL_API
7 : : #include <rte_config.h>
8 : : #include <rte_version.h>
9 : : #include "pci_dpdk.h"
10 : : #include "22.11/bus_pci_driver.h"
11 : : #include "22.11/bus_driver.h"
12 : : #include "22.11/rte_bus_pci.h"
13 : : #include "spdk/assert.h"
14 : :
15 : : SPDK_STATIC_ASSERT(offsetof(struct spdk_pci_driver, driver_buf) == 0, "driver_buf must be first");
16 : : SPDK_STATIC_ASSERT(offsetof(struct spdk_pci_driver, driver) >= sizeof(struct rte_pci_driver),
17 : : "driver_buf not big enough");
18 : :
19 : : /* Following API was added in versions later than DPDK 22.11.
20 : : * It is unused right now, if this changes a new pci_dpdk_* should be added.
21 : : */
22 : : #define rte_pci_mmio_read(...) SPDK_STATIC_ASSERT(false, "rte_pci_mmio_read requires new pci_dpdk_2307 compat layer")
23 : : #define rte_pci_mmio_write(...) SPDK_STATIC_ASSERT(false, "rte_pci_mmio_write requires new pci_dpdk_2307 compat layer")
24 : : #define rte_pci_pasid_set_state(...) SPDK_STATIC_ASSERT(false, "rte_pci_pasid_set_state requires new pci_dpdk_2307 compat layer")
25 : :
26 : : static struct rte_mem_resource *
27 : 18125 : pci_device_get_mem_resource_2211(struct rte_pci_device *dev, uint32_t bar)
28 : : {
29 [ + + ]: 18125 : if (bar >= PCI_MAX_RESOURCE) {
30 [ # # ]: 0 : assert(false);
31 : : return NULL;
32 : : }
33 : :
34 [ + - + - : 18125 : return &dev->mem_resource[bar];
+ - ]
35 : : }
36 : :
37 : : static const char *
38 : 1131 : pci_device_get_name_2211(struct rte_pci_device *rte_dev)
39 : : {
40 [ + - ]: 1131 : return rte_dev->name;
41 : : }
42 : :
43 : : static struct rte_devargs *
44 : 3968 : pci_device_get_devargs_2211(struct rte_pci_device *rte_dev)
45 : : {
46 [ + - + - : 3968 : return rte_dev->device.devargs;
+ - ]
47 : : }
48 : :
49 : : static struct rte_pci_addr *
50 : 1881 : pci_device_get_addr_2211(struct rte_pci_device *_dev)
51 : : {
52 [ + - ]: 1881 : return &_dev->addr;
53 : : }
54 : :
55 : : static struct rte_pci_id *
56 : 1881 : pci_device_get_id_2211(struct rte_pci_device *_dev)
57 : : {
58 [ + - ]: 1881 : return &_dev->id;
59 : : }
60 : :
61 : : static int
62 : 1881 : pci_device_get_numa_node_2211(struct rte_pci_device *_dev)
63 : : {
64 [ + - + - : 1881 : return _dev->device.numa_node;
+ - ]
65 : : }
66 : :
67 : : static int
68 : 1159 : pci_device_read_config_2211(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
69 : : {
70 : : int rc;
71 : :
72 : 1159 : rc = rte_pci_read_config(dev, value, len, offset);
73 : :
74 [ + - + - ]: 1159 : return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
75 : : }
76 : :
77 : : static int
78 : 1159 : pci_device_write_config_2211(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
79 : : {
80 : : int rc;
81 : :
82 : 1159 : rc = rte_pci_write_config(dev, value, len, offset);
83 : :
84 : : #ifdef __FreeBSD__
85 : : /* DPDK returns 0 on success and -1 on failure */
86 : 28 : return rc;
87 : : #endif
88 [ + - + - ]: 1131 : return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
89 : : }
90 : :
91 : : /* translate spdk_pci_driver to an rte_pci_driver and register it to dpdk */
92 : : static int
93 : 12967 : pci_driver_register_2211(struct spdk_pci_driver *driver,
94 : : int (*probe_fn)(struct rte_pci_driver *driver, struct rte_pci_device *device),
95 : : int (*remove_fn)(struct rte_pci_device *device))
96 : :
97 : : {
98 : 12967 : unsigned pci_id_count = 0;
99 : : struct rte_pci_id *rte_id_table;
100 : : char *rte_name;
101 : : size_t rte_name_len;
102 : : uint32_t rte_flags;
103 : :
104 [ + + + - : 12967 : assert(driver->id_table);
+ - # # ]
105 [ + + + - : 164341 : while (driver->id_table[pci_id_count].vendor_id) {
+ - + - +
- + + ]
106 : 151374 : pci_id_count++;
107 : : }
108 [ + + # # ]: 12967 : assert(pci_id_count > 0);
109 : :
110 : 12967 : rte_id_table = calloc(pci_id_count + 1, sizeof(*rte_id_table));
111 [ + + ]: 12967 : if (!rte_id_table) {
112 : 0 : return -ENOMEM;
113 : : }
114 : :
115 [ + + ]: 164341 : while (pci_id_count > 0) {
116 [ + - ]: 151374 : struct rte_pci_id *rte_id = &rte_id_table[pci_id_count - 1];
117 [ + - + - : 151374 : const struct spdk_pci_id *spdk_id = &driver->id_table[pci_id_count - 1];
+ - ]
118 : :
119 [ + - + - : 151374 : rte_id->class_id = spdk_id->class_id;
+ - + - ]
120 [ + - + - : 151374 : rte_id->vendor_id = spdk_id->vendor_id;
+ - + - ]
121 [ + - + - : 151374 : rte_id->device_id = spdk_id->device_id;
+ - + - ]
122 [ + - + - : 151374 : rte_id->subsystem_vendor_id = spdk_id->subvendor_id;
+ - + - ]
123 [ + - + - : 151374 : rte_id->subsystem_device_id = spdk_id->subdevice_id;
+ - + - ]
124 : 151374 : pci_id_count--;
125 : : }
126 : :
127 [ + + + - : 12967 : assert(driver->name);
+ - # # ]
128 [ + + + - : 12967 : rte_name_len = strlen(driver->name) + strlen("spdk_") + 1;
+ - ]
129 : 12967 : rte_name = calloc(rte_name_len, 1);
130 [ + + ]: 12967 : if (!rte_name) {
131 : 0 : free(rte_id_table);
132 : 0 : return -ENOMEM;
133 : : }
134 : :
135 [ + - + - ]: 12967 : snprintf(rte_name, rte_name_len, "spdk_%s", driver->name);
136 [ + - + - : 12967 : driver->driver->driver.name = rte_name;
+ - + - +
- ]
137 [ + - + - : 12967 : driver->driver->id_table = rte_id_table;
+ - + - ]
138 : :
139 : 12967 : rte_flags = 0;
140 [ + + + - : 12967 : if (driver->drv_flags & SPDK_PCI_DRIVER_NEED_MAPPING) {
- + ]
141 : 12967 : rte_flags |= RTE_PCI_DRV_NEED_MAPPING;
142 : 488 : }
143 [ + + + - : 12967 : if (driver->drv_flags & SPDK_PCI_DRIVER_WC_ACTIVATE) {
+ + ]
144 : 7743 : rte_flags |= RTE_PCI_DRV_WC_ACTIVATE;
145 : 292 : }
146 [ + - + - : 12967 : driver->driver->drv_flags = rte_flags;
+ - + - ]
147 : :
148 [ + - + - : 12967 : driver->driver->probe = probe_fn;
+ - + - ]
149 [ + - + - : 12967 : driver->driver->remove = remove_fn;
+ - + - ]
150 : :
151 [ + - + - ]: 12967 : rte_pci_register(driver->driver);
152 : 12967 : return 0;
153 : 488 : }
154 : :
155 : : static int
156 : 1 : pci_device_enable_interrupt_2211(struct rte_pci_device *rte_dev)
157 : : {
158 [ # # # # ]: 1 : return rte_intr_enable(rte_dev->intr_handle);
159 : : }
160 : :
161 : : static int
162 : 1 : pci_device_disable_interrupt_2211(struct rte_pci_device *rte_dev)
163 : : {
164 [ # # # # ]: 1 : return rte_intr_disable(rte_dev->intr_handle);
165 : : }
166 : :
167 : : static int
168 : 1 : pci_device_get_interrupt_efd_2211(struct rte_pci_device *rte_dev)
169 : : {
170 [ # # # # ]: 1 : return rte_intr_fd_get(rte_dev->intr_handle);
171 : : }
172 : :
173 : : static int
174 : 1 : pci_device_create_interrupt_efds_2211(struct rte_pci_device *rte_dev, uint32_t count)
175 : : {
176 [ # # # # ]: 1 : return rte_intr_efd_enable(rte_dev->intr_handle, count);
177 : : }
178 : :
179 : : static void
180 : 1 : pci_device_delete_interrupt_efds_2211(struct rte_pci_device *rte_dev)
181 : : {
182 [ # # # # ]: 1 : return rte_intr_efd_disable(rte_dev->intr_handle);
183 : : }
184 : :
185 : : static int
186 : 4 : pci_device_get_interrupt_efd_by_index_2211(struct rte_pci_device *rte_dev, uint32_t index)
187 : : {
188 [ # # # # ]: 4 : return rte_intr_efds_index_get(rte_dev->intr_handle, index);
189 : : }
190 : :
191 : : static int
192 : 1 : pci_device_interrupt_cap_multi_2211(struct rte_pci_device *rte_dev)
193 : : {
194 [ # # # # ]: 1 : return rte_intr_cap_multiple(rte_dev->intr_handle);
195 : : }
196 : :
197 : : static int
198 : 110167 : bus_probe_2211(void)
199 : : {
200 : 110167 : return rte_bus_probe();
201 : : }
202 : :
203 : : static void
204 : 112973 : bus_scan_2211(void)
205 : : {
206 : 112973 : rte_bus_scan();
207 : 112973 : }
208 : :
209 : : static struct rte_devargs *
210 : 1192850 : device_get_devargs_2211(struct rte_device *dev)
211 : : {
212 [ + - + - ]: 1192850 : return dev->devargs;
213 : : }
214 : :
215 : : static void
216 : 90426 : device_set_devargs_2211(struct rte_device *dev, struct rte_devargs *devargs)
217 : : {
218 [ + - + - ]: 90426 : dev->devargs = devargs;
219 : 90426 : }
220 : :
221 : : static const char *
222 : 90426 : device_get_name_2211(struct rte_device *dev)
223 : : {
224 [ + - + - ]: 90426 : return dev->name;
225 : : }
226 : :
227 : : static bool
228 : 90426 : device_scan_allowed_2211(struct rte_device *dev)
229 : : {
230 [ + - + - : 90426 : return dev->bus->conf.scan_mode == RTE_BUS_SCAN_ALLOWLIST;
+ - + - +
- ]
231 : : }
232 : :
233 : : struct dpdk_fn_table fn_table_2211 = {
234 : : .pci_device_get_mem_resource = pci_device_get_mem_resource_2211,
235 : : .pci_device_get_name = pci_device_get_name_2211,
236 : : .pci_device_get_devargs = pci_device_get_devargs_2211,
237 : : .pci_device_get_addr = pci_device_get_addr_2211,
238 : : .pci_device_get_id = pci_device_get_id_2211,
239 : : .pci_device_get_numa_node = pci_device_get_numa_node_2211,
240 : : .pci_device_read_config = pci_device_read_config_2211,
241 : : .pci_device_write_config = pci_device_write_config_2211,
242 : : .pci_driver_register = pci_driver_register_2211,
243 : : .pci_device_enable_interrupt = pci_device_enable_interrupt_2211,
244 : : .pci_device_disable_interrupt = pci_device_disable_interrupt_2211,
245 : : .pci_device_get_interrupt_efd = pci_device_get_interrupt_efd_2211,
246 : : .pci_device_create_interrupt_efds = pci_device_create_interrupt_efds_2211,
247 : : .pci_device_delete_interrupt_efds = pci_device_delete_interrupt_efds_2211,
248 : : .pci_device_get_interrupt_efd_by_index = pci_device_get_interrupt_efd_by_index_2211,
249 : : .pci_device_interrupt_cap_multi = pci_device_interrupt_cap_multi_2211,
250 : : .bus_scan = bus_scan_2211,
251 : : .bus_probe = bus_probe_2211,
252 : : .device_get_devargs = device_get_devargs_2211,
253 : : .device_set_devargs = device_set_devargs_2211,
254 : : .device_get_name = device_get_name_2211,
255 : : .device_scan_allowed = device_scan_allowed_2211,
256 : : };
|