2 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * Copyright (c) 2014, Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
38 int vnic_cq_mem_size(struct vnic_cq *cq, unsigned int desc_count,
39 unsigned int desc_size)
43 mem_size = vnic_dev_desc_ring_size(&cq->ring, desc_count, desc_size);
48 void vnic_cq_free(struct vnic_cq *cq)
50 vnic_dev_free_desc_ring(cq->vdev, &cq->ring);
55 int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
56 unsigned int socket_id,
57 unsigned int desc_count, unsigned int desc_size)
60 char res_name[NAME_MAX];
66 cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index);
68 pr_err("Failed to hook CQ[%d] resource\n", index);
72 snprintf(res_name, sizeof(res_name), "%d-cq-%d", instance++, index);
73 err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size,
81 void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
82 unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
83 unsigned int cq_tail_color, unsigned int interrupt_enable,
84 unsigned int cq_entry_enable, unsigned int cq_message_enable,
85 unsigned int interrupt_offset, u64 cq_message_addr)
89 paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
90 writeq(paddr, &cq->ctrl->ring_base);
91 iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
92 iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
93 iowrite32(color_enable, &cq->ctrl->color_enable);
94 iowrite32(cq_head, &cq->ctrl->cq_head);
95 iowrite32(cq_tail, &cq->ctrl->cq_tail);
96 iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
97 iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
98 iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
99 iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
100 iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
101 writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
103 cq->interrupt_offset = interrupt_offset;
106 void vnic_cq_clean(struct vnic_cq *cq)
111 iowrite32(0, &cq->ctrl->cq_head);
112 iowrite32(0, &cq->ctrl->cq_tail);
113 iowrite32(1, &cq->ctrl->cq_tail_color);
115 vnic_dev_clear_desc_ring(&cq->ring);