MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cdx_scan_one

Function cdx_scan_one

dpdk/drivers/bus/cdx/cdx.c:189–258  ·  view source on GitHub ↗

* Scan one cdx sysfs entry, and fill the devices list from it. * It checks if the CDX device is bound to vfio-cdx driver. In case * the device is vfio bound, it reads the vendor and device id and * stores it for device-driver matching. */

Source from the content-addressed store, hash-verified

187 * stores it for device-driver matching.
188 */
189static int
190cdx_scan_one(const char *dirname, const char *dev_name)
191{
192 char filename[PATH_MAX];
193 struct rte_cdx_device *dev = NULL;
194 char driver[PATH_MAX];
195 unsigned long tmp;
196 int ret;
197
198 dev = calloc(1, sizeof(*dev));
199 if (!dev)
200 return -ENOMEM;
201
202 dev->device.bus = &rte_cdx_bus.bus;
203 memcpy(dev->name, dev_name, RTE_DEV_NAME_MAX_LEN);
204 dev->device.name = dev->name;
205
206 /* parse driver */
207 snprintf(filename, sizeof(filename), "%s/driver", dirname);
208 ret = cdx_get_kernel_driver_by_path(filename, driver, sizeof(driver));
209 if (ret < 0) {
210 CDX_BUS_ERR("Fail to get kernel driver");
211 free(dev);
212 return -1;
213 }
214
215 /* Allocate interrupt instance for cdx device */
216 dev->intr_handle =
217 rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
218 if (dev->intr_handle == NULL) {
219 CDX_BUS_ERR("Failed to create interrupt instance for %s",
220 dev->device.name);
221 free(dev);
222 return -ENOMEM;
223 }
224
225 /*
226 * Check if device is bound to 'vfio-cdx' driver, so that user-space
227 * can gracefully access the device.
228 */
229 if (ret || strcmp(driver, "vfio-cdx")) {
230 ret = 0;
231 goto err;
232 }
233
234 /* get vendor id */
235 snprintf(filename, sizeof(filename), "%s/vendor", dirname);
236 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
237 ret = -1;
238 goto err;
239 }
240 dev->id.vendor_id = (uint16_t)tmp;
241
242 /* get device id */
243 snprintf(filename, sizeof(filename), "%s/device", dirname);
244 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
245 ret = -1;
246 goto err;

Callers 1

cdx_scanFunction · 0.85

Calls 10

callocFunction · 0.85
snprintfFunction · 0.85
rte_intr_instance_allocFunction · 0.85
strcmpFunction · 0.85
eal_parse_sysfs_valueFunction · 0.85
cdx_add_deviceFunction · 0.85
rte_intr_instance_freeFunction · 0.85
memcpyFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected