1*e6550b3eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2a6a5580cSJeff Kirsher /*
3a6a5580cSJeff Kirsher  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
4a6a5580cSJeff Kirsher  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5a6a5580cSJeff Kirsher  */
6a6a5580cSJeff Kirsher 
7a6a5580cSJeff Kirsher #include <linux/kernel.h>
8a6a5580cSJeff Kirsher #include <linux/errno.h>
9a6a5580cSJeff Kirsher #include <linux/types.h>
10a6a5580cSJeff Kirsher #include <linux/pci.h>
11a6a5580cSJeff Kirsher 
12a6a5580cSJeff Kirsher #include "vnic_dev.h"
13a6a5580cSJeff Kirsher #include "vnic_cq.h"
146a3c2f83SGovindarajulu Varadarajan #include "enic.h"
15a6a5580cSJeff Kirsher 
vnic_cq_free(struct vnic_cq * cq)16a6a5580cSJeff Kirsher void vnic_cq_free(struct vnic_cq *cq)
17a6a5580cSJeff Kirsher {
18a6a5580cSJeff Kirsher 	vnic_dev_free_desc_ring(cq->vdev, &cq->ring);
19a6a5580cSJeff Kirsher 
20a6a5580cSJeff Kirsher 	cq->ctrl = NULL;
21a6a5580cSJeff Kirsher }
22a6a5580cSJeff Kirsher 
vnic_cq_alloc(struct vnic_dev * vdev,struct vnic_cq * cq,unsigned int index,unsigned int desc_count,unsigned int desc_size)23a6a5580cSJeff Kirsher int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
24a6a5580cSJeff Kirsher 	unsigned int desc_count, unsigned int desc_size)
25a6a5580cSJeff Kirsher {
26a6a5580cSJeff Kirsher 	cq->index = index;
27a6a5580cSJeff Kirsher 	cq->vdev = vdev;
28a6a5580cSJeff Kirsher 
29a6a5580cSJeff Kirsher 	cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index);
30a6a5580cSJeff Kirsher 	if (!cq->ctrl) {
31e327f4e1SJoe Perches 		vdev_err(vdev, "Failed to hook CQ[%d] resource\n", index);
32a6a5580cSJeff Kirsher 		return -EINVAL;
33a6a5580cSJeff Kirsher 	}
34a6a5580cSJeff Kirsher 
35d867bc3aSZheng Yongjun 	return vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size);
36a6a5580cSJeff Kirsher }
37a6a5580cSJeff Kirsher 
vnic_cq_init(struct vnic_cq * cq,unsigned int flow_control_enable,unsigned int color_enable,unsigned int cq_head,unsigned int cq_tail,unsigned int cq_tail_color,unsigned int interrupt_enable,unsigned int cq_entry_enable,unsigned int cq_message_enable,unsigned int interrupt_offset,u64 cq_message_addr)38a6a5580cSJeff Kirsher void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
39a6a5580cSJeff Kirsher 	unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
40a6a5580cSJeff Kirsher 	unsigned int cq_tail_color, unsigned int interrupt_enable,
41a6a5580cSJeff Kirsher 	unsigned int cq_entry_enable, unsigned int cq_message_enable,
42a6a5580cSJeff Kirsher 	unsigned int interrupt_offset, u64 cq_message_addr)
43a6a5580cSJeff Kirsher {
44a6a5580cSJeff Kirsher 	u64 paddr;
45a6a5580cSJeff Kirsher 
46a6a5580cSJeff Kirsher 	paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
47a6a5580cSJeff Kirsher 	writeq(paddr, &cq->ctrl->ring_base);
48a6a5580cSJeff Kirsher 	iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
49a6a5580cSJeff Kirsher 	iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
50a6a5580cSJeff Kirsher 	iowrite32(color_enable, &cq->ctrl->color_enable);
51a6a5580cSJeff Kirsher 	iowrite32(cq_head, &cq->ctrl->cq_head);
52a6a5580cSJeff Kirsher 	iowrite32(cq_tail, &cq->ctrl->cq_tail);
53a6a5580cSJeff Kirsher 	iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
54a6a5580cSJeff Kirsher 	iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
55a6a5580cSJeff Kirsher 	iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
56a6a5580cSJeff Kirsher 	iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
57a6a5580cSJeff Kirsher 	iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
58a6a5580cSJeff Kirsher 	writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
59a6a5580cSJeff Kirsher 
60a6a5580cSJeff Kirsher 	cq->interrupt_offset = interrupt_offset;
61a6a5580cSJeff Kirsher }
62a6a5580cSJeff Kirsher 
vnic_cq_clean(struct vnic_cq * cq)63a6a5580cSJeff Kirsher void vnic_cq_clean(struct vnic_cq *cq)
64a6a5580cSJeff Kirsher {
65a6a5580cSJeff Kirsher 	cq->to_clean = 0;
66a6a5580cSJeff Kirsher 	cq->last_color = 0;
67a6a5580cSJeff Kirsher 
68a6a5580cSJeff Kirsher 	iowrite32(0, &cq->ctrl->cq_head);
69a6a5580cSJeff Kirsher 	iowrite32(0, &cq->ctrl->cq_tail);
70a6a5580cSJeff Kirsher 	iowrite32(1, &cq->ctrl->cq_tail_color);
71a6a5580cSJeff Kirsher 
72a6a5580cSJeff Kirsher 	vnic_dev_clear_desc_ring(&cq->ring);
73a6a5580cSJeff Kirsher }
74