Imported Upstream version 16.04
[deb_dpdk.git] / drivers / net / enic / base / vnic_rq.h
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
35 #ifndef _VNIC_RQ_H_
36 #define _VNIC_RQ_H_
37
38
39 #include "vnic_dev.h"
40 #include "vnic_cq.h"
41
42 /* Receive queue control */
43 struct vnic_rq_ctrl {
44         u64 ring_base;                  /* 0x00 */
45         u32 ring_size;                  /* 0x08 */
46         u32 pad0;
47         u32 posted_index;               /* 0x10 */
48         u32 pad1;
49         u32 cq_index;                   /* 0x18 */
50         u32 pad2;
51         u32 enable;                     /* 0x20 */
52         u32 pad3;
53         u32 running;                    /* 0x28 */
54         u32 pad4;
55         u32 fetch_index;                /* 0x30 */
56         u32 pad5;
57         u32 error_interrupt_enable;     /* 0x38 */
58         u32 pad6;
59         u32 error_interrupt_offset;     /* 0x40 */
60         u32 pad7;
61         u32 error_status;               /* 0x48 */
62         u32 pad8;
63         u32 dropped_packet_count;       /* 0x50 */
64         u32 pad9;
65         u32 dropped_packet_count_rc;    /* 0x58 */
66         u32 pad10;
67 };
68
69 struct vnic_rq {
70         unsigned int index;
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 */
77         void *os_buf_head;
78         unsigned int pkts_outstanding;
79         uint16_t rx_nb_hold;
80         uint16_t rx_free_thresh;
81         unsigned int socket_id;
82         struct rte_mempool *mp;
83         uint16_t rxst_idx;
84         uint32_t tot_pkts;
85 };
86
87 static inline unsigned int vnic_rq_desc_avail(struct vnic_rq *rq)
88 {
89         /* how many does SW own? */
90         return rq->ring.desc_avail;
91 }
92
93 static inline unsigned int vnic_rq_desc_used(struct vnic_rq *rq)
94 {
95         /* how many does HW own? */
96         return rq->ring.desc_count - rq->ring.desc_avail - 1;
97 }
98
99
100
101 enum desc_return_options {
102         VNIC_RQ_RETURN_DESC,
103         VNIC_RQ_DEFER_RETURN_DESC,
104 };
105
106 static inline int vnic_rq_fill(struct vnic_rq *rq,
107         int (*buf_fill)(struct vnic_rq *rq))
108 {
109         int err;
110
111         while (vnic_rq_desc_avail(rq) > 0) {
112
113                 err = (*buf_fill)(rq);
114                 if (err)
115                         return err;
116         }
117
118         return 0;
119 }
120
121 static inline int vnic_rq_fill_count(struct vnic_rq *rq,
122         int (*buf_fill)(struct vnic_rq *rq), unsigned int count)
123 {
124         int err;
125
126         while ((vnic_rq_desc_avail(rq) > 0) && (count--)) {
127
128                 err = (*buf_fill)(rq);
129                 if (err)
130                         return err;
131         }
132
133         return 0;
134 }
135
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_ */