e1000: move to drivers/net/
[dpdk.git] / lib / librte_pmd_enic / vnic / vnic_cq.c
1 /*
2  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 #ident "$Id: vnic_cq.c 171146 2014-05-02 07:08:20Z ssujith $"
35
36 #include "vnic_dev.h"
37 #include "vnic_cq.h"
38
39 int vnic_cq_mem_size(struct vnic_cq *cq, unsigned int desc_count,
40         unsigned int desc_size)
41 {
42         int mem_size;
43
44         mem_size = vnic_dev_desc_ring_size(&cq->ring, desc_count, desc_size);
45
46         return mem_size;
47 }
48
49 void vnic_cq_free(struct vnic_cq *cq)
50 {
51         vnic_dev_free_desc_ring(cq->vdev, &cq->ring);
52
53         cq->ctrl = NULL;
54 }
55
56 int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
57         unsigned int socket_id,
58         unsigned int desc_count, unsigned int desc_size)
59 {
60         int err;
61         char res_name[NAME_MAX];
62         static int instance;
63
64         cq->index = index;
65         cq->vdev = vdev;
66
67         cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index);
68         if (!cq->ctrl) {
69                 pr_err("Failed to hook CQ[%d] resource\n", index);
70                 return -EINVAL;
71         }
72
73         snprintf(res_name, sizeof(res_name), "%d-cq-%d", instance++, index);
74         err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size,
75                 socket_id, res_name);
76         if (err)
77                 return err;
78
79         return 0;
80 }
81
82 void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
83         unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
84         unsigned int cq_tail_color, unsigned int interrupt_enable,
85         unsigned int cq_entry_enable, unsigned int cq_message_enable,
86         unsigned int interrupt_offset, u64 cq_message_addr)
87 {
88         u64 paddr;
89
90         paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
91         writeq(paddr, &cq->ctrl->ring_base);
92         iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
93         iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
94         iowrite32(color_enable, &cq->ctrl->color_enable);
95         iowrite32(cq_head, &cq->ctrl->cq_head);
96         iowrite32(cq_tail, &cq->ctrl->cq_tail);
97         iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
98         iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
99         iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
100         iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
101         iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
102         writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
103
104         cq->interrupt_offset = interrupt_offset;
105 }
106
107 void vnic_cq_clean(struct vnic_cq *cq)
108 {
109         cq->to_clean = 0;
110         cq->last_color = 0;
111
112         iowrite32(0, &cq->ctrl->cq_head);
113         iowrite32(0, &cq->ctrl->cq_tail);
114         iowrite32(1, &cq->ctrl->cq_tail_color);
115
116         vnic_dev_clear_desc_ring(&cq->ring);
117 }