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.
34 #ident "$Id: vnic_cq.h 173398 2014-05-19 09:17:02Z gvaradar $"
44 /* Completion queue control */
46 u64 ring_base; /* 0x00 */
47 u32 ring_size; /* 0x08 */
49 u32 flow_control_enable; /* 0x10 */
51 u32 color_enable; /* 0x18 */
53 u32 cq_head; /* 0x20 */
55 u32 cq_tail; /* 0x28 */
57 u32 cq_tail_color; /* 0x30 */
59 u32 interrupt_enable; /* 0x38 */
61 u32 cq_entry_enable; /* 0x40 */
63 u32 cq_message_enable; /* 0x48 */
65 u32 interrupt_offset; /* 0x50 */
67 u64 cq_message_addr; /* 0x58 */
72 struct vnic_rx_bytes_counter {
73 unsigned int small_pkt_bytes_cnt;
74 unsigned int large_pkt_bytes_cnt;
80 struct vnic_dev *vdev;
81 struct vnic_cq_ctrl __iomem *ctrl; /* memory-mapped */
82 struct vnic_dev_ring ring;
83 unsigned int to_clean;
84 unsigned int last_color;
85 unsigned int interrupt_offset;
87 struct vnic_rx_bytes_counter pkt_size_counter;
88 unsigned int cur_rx_coal_timeval;
89 unsigned int tobe_rx_coal_timeval;
94 static inline unsigned int vnic_cq_service(struct vnic_cq *cq,
95 unsigned int work_to_do,
96 int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc,
97 u8 type, u16 q_number, u16 completed_index, void *opaque),
100 struct cq_desc *cq_desc;
101 unsigned int work_done = 0;
102 u16 q_number, completed_index;
104 struct rte_mbuf **rx_pkts = opaque;
107 cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
108 cq->ring.desc_size * cq->to_clean);
109 cq_desc_dec(cq_desc, &type, &color,
110 &q_number, &completed_index);
112 while (color != cq->last_color) {
114 opaque = (void *)&(rx_pkts[work_done]);
116 ret = (*q_service)(cq->vdev, cq_desc, type,
117 q_number, completed_index, opaque);
119 if (cq->to_clean == cq->ring.desc_count) {
121 cq->last_color = cq->last_color ? 0 : 1;
124 cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
125 cq->ring.desc_size * cq->to_clean);
126 cq_desc_dec(cq_desc, &type, &color,
127 &q_number, &completed_index);
131 if (work_done >= work_to_do)
138 void vnic_cq_free(struct vnic_cq *cq);
139 int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
140 unsigned int socket_id,
141 unsigned int desc_count, unsigned int desc_size);
142 void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
143 unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
144 unsigned int cq_tail_color, unsigned int interrupt_enable,
145 unsigned int cq_entry_enable, unsigned int message_enable,
146 unsigned int interrupt_offset, u64 message_addr);
147 void vnic_cq_clean(struct vnic_cq *cq);
148 int vnic_cq_mem_size(struct vnic_cq *cq, unsigned int desc_count,
149 unsigned int desc_size);
151 #endif /* _VNIC_CQ_H_ */