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.
42 /* Receive queue control */
44 u64 ring_base; /* 0x00 */
45 u32 ring_size; /* 0x08 */
47 u32 posted_index; /* 0x10 */
49 u32 cq_index; /* 0x18 */
51 u32 enable; /* 0x20 */
53 u32 running; /* 0x28 */
55 u32 fetch_index; /* 0x30 */
57 u32 error_interrupt_enable; /* 0x38 */
59 u32 error_interrupt_offset; /* 0x40 */
61 u32 error_status; /* 0x48 */
63 u32 dropped_packet_count; /* 0x50 */
65 u32 dropped_packet_count_rc; /* 0x58 */
71 unsigned int posted_index;
72 struct vnic_dev *vdev;
73 struct vnic_rq_ctrl __iomem *ctrl; /* memory-mapped */
74 struct vnic_dev_ring ring;
75 struct rte_mbuf **mbuf_ring; /* array of allocated mbufs */
76 unsigned int mbuf_next_idx; /* next mb to consume */
78 unsigned int pkts_outstanding;
80 uint16_t rx_free_thresh;
81 unsigned int socket_id;
82 struct rte_mempool *mp;
87 static inline unsigned int vnic_rq_desc_avail(struct vnic_rq *rq)
89 /* how many does SW own? */
90 return rq->ring.desc_avail;
93 static inline unsigned int vnic_rq_desc_used(struct vnic_rq *rq)
95 /* how many does HW own? */
96 return rq->ring.desc_count - rq->ring.desc_avail - 1;
101 enum desc_return_options {
103 VNIC_RQ_DEFER_RETURN_DESC,
106 static inline int vnic_rq_fill(struct vnic_rq *rq,
107 int (*buf_fill)(struct vnic_rq *rq))
111 while (vnic_rq_desc_avail(rq) > 0) {
113 err = (*buf_fill)(rq);
121 static inline int vnic_rq_fill_count(struct vnic_rq *rq,
122 int (*buf_fill)(struct vnic_rq *rq), unsigned int count)
126 while ((vnic_rq_desc_avail(rq) > 0) && (count--)) {
128 err = (*buf_fill)(rq);
136 void vnic_rq_free(struct vnic_rq *rq);
137 int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
138 unsigned int desc_count, unsigned int desc_size);
139 void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
140 unsigned int fetch_index, unsigned int posted_index,
141 unsigned int error_interrupt_enable,
142 unsigned int error_interrupt_offset);
143 void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
144 unsigned int error_interrupt_enable,
145 unsigned int error_interrupt_offset);
146 void vnic_rq_error_out(struct vnic_rq *rq, unsigned int error);
147 unsigned int vnic_rq_error_status(struct vnic_rq *rq);
148 void vnic_rq_enable(struct vnic_rq *rq);
149 int vnic_rq_disable(struct vnic_rq *rq);
150 void vnic_rq_clean(struct vnic_rq *rq,
151 void (*buf_clean)(struct rte_mbuf **buf));
152 #endif /* _VNIC_RQ_H_ */