67 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2// Copyright 2014 Cisco Systems, Inc. All rights reserved.3 4#include <linux/errno.h>5#include <linux/types.h>6#include <linux/pci.h>7#include "vnic_dev.h"8#include "vnic_cq.h"9 10void svnic_cq_free(struct vnic_cq *cq)11{12 svnic_dev_free_desc_ring(cq->vdev, &cq->ring);13 14 cq->ctrl = NULL;15}16 17int svnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq,18 unsigned int index, unsigned int desc_count, unsigned int desc_size)19{20 cq->index = index;21 cq->vdev = vdev;22 23 cq->ctrl = svnic_dev_get_res(vdev, RES_TYPE_CQ, index);24 if (!cq->ctrl) {25 pr_err("Failed to hook CQ[%d] resource\n", index);26 27 return -EINVAL;28 }29 30 return svnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size);31}32 33void svnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,34 unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,35 unsigned int cq_tail_color, unsigned int interrupt_enable,36 unsigned int cq_entry_enable, unsigned int cq_message_enable,37 unsigned int interrupt_offset, u64 cq_message_addr)38{39 u64 paddr;40 41 paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;42 writeq(paddr, &cq->ctrl->ring_base);43 iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);44 iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);45 iowrite32(color_enable, &cq->ctrl->color_enable);46 iowrite32(cq_head, &cq->ctrl->cq_head);47 iowrite32(cq_tail, &cq->ctrl->cq_tail);48 iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);49 iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);50 iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);51 iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);52 iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);53 writeq(cq_message_addr, &cq->ctrl->cq_message_addr);54}55 56void svnic_cq_clean(struct vnic_cq *cq)57{58 cq->to_clean = 0;59 cq->last_color = 0;60 61 iowrite32(0, &cq->ctrl->cq_head);62 iowrite32(0, &cq->ctrl->cq_tail);63 iowrite32(1, &cq->ctrl->cq_tail_color);64 65 svnic_dev_clear_desc_ring(&cq->ring);66}67