| 565 | } |
| 566 | |
| 567 | int |
| 568 | idxd_dmadev_create(const char *name, struct rte_device *dev, |
| 569 | const struct idxd_dmadev *base_idxd, |
| 570 | const struct rte_dma_dev_ops *ops) |
| 571 | { |
| 572 | struct idxd_dmadev *idxd = NULL; |
| 573 | struct rte_dma_dev *dmadev = NULL; |
| 574 | int ret = 0; |
| 575 | |
| 576 | RTE_BUILD_BUG_ON(sizeof(struct idxd_hw_desc) != 64); |
| 577 | RTE_BUILD_BUG_ON(offsetof(struct idxd_hw_desc, size) != 32); |
| 578 | RTE_BUILD_BUG_ON(sizeof(struct idxd_completion) != 32); |
| 579 | |
| 580 | if (!name) { |
| 581 | IDXD_PMD_ERR("Invalid name of the device!"); |
| 582 | ret = -EINVAL; |
| 583 | goto cleanup; |
| 584 | } |
| 585 | |
| 586 | /* Allocate device structure */ |
| 587 | dmadev = rte_dma_pmd_allocate(name, dev->numa_node, sizeof(struct idxd_dmadev)); |
| 588 | if (dmadev == NULL) { |
| 589 | IDXD_PMD_ERR("Unable to allocate dma device"); |
| 590 | ret = -ENOMEM; |
| 591 | goto cleanup; |
| 592 | } |
| 593 | dmadev->dev_ops = ops; |
| 594 | dmadev->device = dev; |
| 595 | |
| 596 | dmadev->fp_obj->copy = idxd_enqueue_copy; |
| 597 | dmadev->fp_obj->fill = idxd_enqueue_fill; |
| 598 | dmadev->fp_obj->submit = idxd_submit; |
| 599 | dmadev->fp_obj->completed = idxd_completed; |
| 600 | dmadev->fp_obj->completed_status = idxd_completed_status; |
| 601 | dmadev->fp_obj->burst_capacity = idxd_burst_capacity; |
| 602 | dmadev->fp_obj->dev_private = dmadev->data->dev_private; |
| 603 | |
| 604 | if (rte_eal_process_type() != RTE_PROC_PRIMARY) |
| 605 | return 0; |
| 606 | |
| 607 | idxd = dmadev->data->dev_private; |
| 608 | *idxd = *base_idxd; /* copy over the main fields already passed in */ |
| 609 | idxd->dmadev = dmadev; |
| 610 | |
| 611 | /* allocate batch index ring and completion ring. |
| 612 | * The +1 is because we can never fully use |
| 613 | * the ring, otherwise read == write means both full and empty. |
| 614 | */ |
| 615 | idxd->batch_comp_ring = rte_zmalloc_socket(NULL, (sizeof(idxd->batch_idx_ring[0]) + |
| 616 | sizeof(idxd->batch_comp_ring[0])) * (idxd->max_batches + 1), |
| 617 | sizeof(idxd->batch_comp_ring[0]), dev->numa_node); |
| 618 | if (idxd->batch_comp_ring == NULL) { |
| 619 | IDXD_PMD_ERR("Unable to reserve memory for batch data"); |
| 620 | ret = -ENOMEM; |
| 621 | goto cleanup; |
| 622 | } |
| 623 | idxd->batch_idx_ring = (void *)&idxd->batch_comp_ring[idxd->max_batches+1]; |
| 624 | idxd->batch_iova = rte_mem_virt2iova(idxd->batch_comp_ring); |
no test coverage detected