in sdk/linux_kernel_drivers/xdma/xdma_cdev.c [473:607]
int xpdev_create_interfaces(struct xdma_pci_dev *xpdev)
{
struct xdma_dev *xdev = xpdev->xdev;
struct xdma_engine *engine;
int i;
int rv = 0;
/* initialize control character device */
rv = create_xcdev(xpdev, &xpdev->ctrl_cdev, xdev->config_bar_idx,
NULL, CHAR_CTRL);
if (rv < 0) {
pr_err("create_char(ctrl_cdev) failed\n");
goto fail;
}
xpdev_flag_set(xpdev, XDF_CDEV_CTRL);
/* initialize events character device */
for (i = 0; i < xpdev->user_max; i++) {
rv = create_xcdev(xpdev, &xpdev->events_cdev[i], i, NULL,
CHAR_EVENTS);
if (rv < 0) {
pr_err("create char event %d failed, %d.\n", i, rv);
goto fail;
}
}
xpdev_flag_set(xpdev, XDF_CDEV_EVENT);
/* iterate over channels */
for (i = 0; i < xpdev->h2c_channel_max; i++) {
engine = &xdev->engine_h2c[i];
if (engine->magic != MAGIC_ENGINE)
continue;
rv = create_xcdev(xpdev, &xpdev->sgdma_h2c_cdev[i], i, engine,
CHAR_XDMA_H2C);
if (rv < 0) {
pr_err("create char h2c %d failed, %d.\n", i, rv);
goto fail;
}
}
for (i = 0; i < xpdev->c2h_channel_max; i++) {
engine = &xdev->engine_c2h[i];
if (engine->magic != MAGIC_ENGINE)
continue;
rv = create_xcdev(xpdev, &xpdev->sgdma_c2h_cdev[i], i, engine,
CHAR_XDMA_C2H);
if (rv < 0) {
pr_err("create char c2h %d failed, %d.\n", i, rv);
goto fail;
}
}
xpdev_flag_set(xpdev, XDF_CDEV_SG);
/* Initialize Bypass Character Device */
if (xdev->bypass_bar_idx > 0) {
for (i = 0; i < xpdev->h2c_channel_max; i++) {
engine = &xdev->engine_h2c[i];
if (engine->magic != MAGIC_ENGINE)
continue;
rv = create_xcdev(xpdev, &xpdev->bypass_h2c_cdev[i], i,
engine, CHAR_BYPASS_H2C);
if (rv < 0) {
pr_err("create h2c %d bypass I/F failed, %d.\n",
i, rv);
goto fail;
}
}
for (i = 0; i < xpdev->c2h_channel_max; i++) {
engine = &xdev->engine_c2h[i];
if (engine->magic != MAGIC_ENGINE)
continue;
rv = create_xcdev(xpdev, &xpdev->bypass_c2h_cdev[i], i,
engine, CHAR_BYPASS_C2H);
if (rv < 0) {
pr_err("create c2h %d bypass I/F failed, %d.\n",
i, rv);
goto fail;
}
}
rv = create_xcdev(xpdev, &xpdev->bypass_cdev_base,
xdev->bypass_bar_idx, NULL, CHAR_BYPASS);
if (rv < 0) {
pr_err("create bypass failed %d.\n", rv);
goto fail;
}
xpdev_flag_set(xpdev, XDF_CDEV_BYPASS);
}
/* initialize user character device */
if (xdev->user_bar_idx >= 0) {
rv = create_xcdev(xpdev, &xpdev->user_cdev, xdev->user_bar_idx,
NULL, CHAR_USER);
if (rv < 0) {
pr_err("create_char(user_cdev) failed\n");
goto fail;
}
xpdev_flag_set(xpdev, XDF_CDEV_USER);
/* xvc */
rv = create_xcdev(xpdev, &xpdev->xvc_cdev, xdev->user_bar_idx,
NULL, CHAR_XVC);
if (rv < 0) {
pr_err("create xvc failed, %d.\n", rv);
goto fail;
}
xpdev_flag_set(xpdev, XDF_CDEV_XVC);
}
#ifdef __XDMA_SYSFS__
/* sys file */
rv = device_create_file(&xpdev->pdev->dev,
&dev_attr_xdma_dev_instance);
if (rv) {
pr_err("Failed to create device file\n");
goto fail;
}
#endif
return 0;
fail:
rv = -1;
xpdev_destroy_interfaces(xpdev);
return rv;
}