drivers/net: build Intel NIC PMDs with meson
[dpdk.git] / drivers / net / enic / base / vnic_cq.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  */
5
6 #include "vnic_dev.h"
7 #include "vnic_cq.h"
8
9 void vnic_cq_free(struct vnic_cq *cq)
10 {
11         vnic_dev_free_desc_ring(cq->vdev, &cq->ring);
12
13         cq->ctrl = NULL;
14 }
15
16 int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
17         unsigned int socket_id,
18         unsigned int desc_count, unsigned int desc_size)
19 {
20         int err;
21         char res_name[NAME_MAX];
22         static int instance;
23
24         cq->index = index;
25         cq->vdev = vdev;
26
27         cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index);
28         if (!cq->ctrl) {
29                 pr_err("Failed to hook CQ[%u] resource\n", index);
30                 return -EINVAL;
31         }
32
33         snprintf(res_name, sizeof(res_name), "%d-cq-%u", instance++, index);
34         err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size,
35                 socket_id, res_name);
36         if (err)
37                 return err;
38
39         return 0;
40 }
41
42 void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
43         unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
44         unsigned int cq_tail_color, unsigned int interrupt_enable,
45         unsigned int cq_entry_enable, unsigned int cq_message_enable,
46         unsigned int interrupt_offset, u64 cq_message_addr)
47 {
48         u64 paddr;
49
50         paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
51         writeq(paddr, &cq->ctrl->ring_base);
52         iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
53         iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
54         iowrite32(color_enable, &cq->ctrl->color_enable);
55         iowrite32(cq_head, &cq->ctrl->cq_head);
56         iowrite32(cq_tail, &cq->ctrl->cq_tail);
57         iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
58         iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
59         iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
60         iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
61         iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
62         writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
63
64         cq->interrupt_offset = interrupt_offset;
65 }
66
67 void vnic_cq_clean(struct vnic_cq *cq)
68 {
69         cq->to_clean = 0;
70         cq->last_color = 0;
71
72         iowrite32(0, &cq->ctrl->cq_head);
73         iowrite32(0, &cq->ctrl->cq_tail);
74         iowrite32(1, &cq->ctrl->cq_tail_color);
75
76         vnic_dev_clear_desc_ring(&cq->ring);
77 }