int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index, #ifdef ENIC_PMD unsigned int socket_id, #endif unsigned int desc_count, unsigned int desc_size) { int err; #ifdef ENIC_PMD char res_name[NAME_MAX]; static int instance; #endif cq->index = index; cq->vdev = vdev; cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index); if (!cq->ctrl) { pr_err("Failed to hook CQ[%d] resource\n", index); return -EINVAL; } #ifdef ENIC_PMD snprintf(res_name, sizeof(res_name), "%d-cq-%d", instance++, index); err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size, socket_id, res_name); #else err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size); #endif if (err) return err; return 0; }
int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, unsigned int desc_count, unsigned int desc_size) { int err; char res_name[NAME_MAX]; static int instance; rq->index = index; rq->vdev = vdev; rq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_RQ, index); if (!rq->ctrl) { pr_err("Failed to hook RQ[%d] resource\n", index); return -EINVAL; } vnic_rq_disable(rq); snprintf(res_name, sizeof(res_name), "%d-rq-%d", instance++, index); err = vnic_dev_alloc_desc_ring(vdev, &rq->ring, desc_count, desc_size, rq->socket_id, res_name); if (err) return err; err = vnic_rq_alloc_bufs(rq); if (err) { vnic_rq_free(rq); return err; } return 0; }
int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, unsigned int desc_count, unsigned int desc_size) { int err; rq->index = index; rq->vdev = vdev; rq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_RQ, index); if (!rq->ctrl) { printk(KERN_ERR "Failed to hook RQ[%d] resource\n", index); return -EINVAL; } vnic_rq_disable(rq); err = vnic_dev_alloc_desc_ring(vdev, &rq->ring, desc_count, desc_size); if (err) return err; err = vnic_rq_alloc_bufs(rq); if (err) { vnic_rq_free(rq); return err; } return 0; }
int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, unsigned int desc_count, unsigned int desc_size) { int err; wq->index = index; wq->vdev = vdev; wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index); if (!wq->ctrl) { pr_err("Failed to hook WQ[%d] resource\n", index); return -EINVAL; } vnic_wq_disable(wq); err = vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size); if (err) return err; err = vnic_wq_alloc_bufs(wq); if (err) { vnic_wq_free(wq); return err; } return 0; }
static inline int vnic_wq_alloc_ring(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int desc_count, unsigned int desc_size) { char res_name[NAME_MAX]; static int instance; snprintf(res_name, sizeof(res_name), "%d-wq-%d", instance++, wq->index); return vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size, wq->socket_id, res_name); }
int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index, unsigned int desc_count, unsigned int desc_size) { int err; cq->index = index; cq->vdev = vdev; cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index); if (!cq->ctrl) { printk(KERN_ERR "Failed to hook CQ[%d] resource\n", index); return -EINVAL; } err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size); if (err) return err; return 0; }
int vnic_wq_copy_alloc(struct vnic_dev *vdev, struct vnic_wq_copy *wq, unsigned int index, unsigned int desc_count, unsigned int desc_size) { int err; wq->index = index; wq->vdev = vdev; wq->to_use_index = wq->to_clean_index = 0; wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index); if (!wq->ctrl) { printk(KERN_ERR "Failed to hook COPY WQ[%d] resource\n", index); return -EINVAL; } vnic_wq_copy_disable(wq); err = vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size); if (err) return err; return 0; }
int vnic_dev_init_devcmd2(struct vnic_dev *vdev) { int err; unsigned int fetch_index; if (vdev->devcmd2) return 0; vdev->devcmd2 = kzalloc(sizeof(*vdev->devcmd2), GFP_ATOMIC); if (!vdev->devcmd2) return -ENOMEM; vdev->devcmd2->color = 1; vdev->devcmd2->result_size = DEVCMD2_RING_SIZE; err = vnic_wq_devcmd2_alloc(vdev, &vdev->devcmd2->wq, DEVCMD2_RING_SIZE, DEVCMD2_DESC_SIZE); if (err) goto err_free_devcmd2; fetch_index = ioread32(&vdev->devcmd2->wq.ctrl->fetch_index); if (fetch_index == 0xFFFFFFFF) { /* check for hardware gone */ pr_err("error in devcmd2 init"); return -ENODEV; } /* * Don't change fetch_index ever and * set posted_index same as fetch_index * when setting up the WQ for devcmd2. */ vnic_wq_init_start(&vdev->devcmd2->wq, 0, fetch_index, fetch_index, 0, 0); vnic_wq_enable(&vdev->devcmd2->wq); err = vnic_dev_alloc_desc_ring(vdev, &vdev->devcmd2->results_ring, DEVCMD2_RING_SIZE, DEVCMD2_DESC_SIZE); if (err) goto err_free_wq; vdev->devcmd2->result = (struct devcmd2_result *) vdev->devcmd2->results_ring.descs; vdev->devcmd2->cmd_ring = (struct vnic_devcmd2 *) vdev->devcmd2->wq.ring.descs; vdev->devcmd2->wq_ctrl = vdev->devcmd2->wq.ctrl; vdev->args[0] = (u64) vdev->devcmd2->results_ring.base_addr | VNIC_PADDR_TARGET; vdev->args[1] = DEVCMD2_RING_SIZE; err = vnic_dev_cmd2(vdev, CMD_INITIALIZE_DEVCMD2, 1000); if (err) goto err_free_desc_ring; vdev->devcmd_rtn = &vnic_dev_cmd2; return 0; err_free_desc_ring: vnic_dev_free_desc_ring(vdev, &vdev->devcmd2->results_ring); err_free_wq: vnic_wq_disable(&vdev->devcmd2->wq); vnic_wq_free(&vdev->devcmd2->wq); err_free_devcmd2: kfree(vdev->devcmd2); vdev->devcmd2 = NULL; return err; }
static inline int vnic_wq_alloc_ring(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int desc_count, unsigned int desc_size) { return vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size); }
static int vnic_dev_init_devcmd2(struct vnic_dev *vdev) { int err; unsigned int fetch_index; if (vdev->devcmd2) return 0; vdev->devcmd2 = kzalloc(sizeof(*vdev->devcmd2), GFP_KERNEL); if (!vdev->devcmd2) return -ENOMEM; vdev->devcmd2->color = 1; vdev->devcmd2->result_size = DEVCMD2_RING_SIZE; err = enic_wq_devcmd2_alloc(vdev, &vdev->devcmd2->wq, DEVCMD2_RING_SIZE, DEVCMD2_DESC_SIZE); if (err) goto err_free_devcmd2; fetch_index = ioread32(&vdev->devcmd2->wq.ctrl->fetch_index); if (fetch_index == 0xFFFFFFFF) { /* check for hardware gone */ vdev_err(vdev, "Fatal error in devcmd2 init - hardware surprise removal\n"); return -ENODEV; } enic_wq_init_start(&vdev->devcmd2->wq, 0, fetch_index, fetch_index, 0, 0); vdev->devcmd2->posted = fetch_index; vnic_wq_enable(&vdev->devcmd2->wq); err = vnic_dev_alloc_desc_ring(vdev, &vdev->devcmd2->results_ring, DEVCMD2_RING_SIZE, DEVCMD2_DESC_SIZE); if (err) goto err_free_wq; vdev->devcmd2->result = vdev->devcmd2->results_ring.descs; vdev->devcmd2->cmd_ring = vdev->devcmd2->wq.ring.descs; vdev->devcmd2->wq_ctrl = vdev->devcmd2->wq.ctrl; vdev->args[0] = (u64)vdev->devcmd2->results_ring.base_addr | VNIC_PADDR_TARGET; vdev->args[1] = DEVCMD2_RING_SIZE; err = _vnic_dev_cmd2(vdev, CMD_INITIALIZE_DEVCMD2, 1000); if (err) goto err_free_desc_ring; vdev->devcmd_rtn = _vnic_dev_cmd2; return 0; err_free_desc_ring: vnic_dev_free_desc_ring(vdev, &vdev->devcmd2->results_ring); err_free_wq: vnic_wq_disable(&vdev->devcmd2->wq); vnic_wq_free(&vdev->devcmd2->wq); err_free_devcmd2: kfree(vdev->devcmd2); vdev->devcmd2 = NULL; return err; }