Imported Upstream version 16.07-rc1
[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 tcp_sn;                     /* 0x50 */
64         u32 pad9;
65         u32 unused;                     /* 0x58 */
66         u32 pad10;
67         u32 dca_select;                 /* 0x60 */
68         u32 pad11;
69         u32 dca_value;                  /* 0x68 */
70         u32 pad12;
71         u32 data_ring;                  /* 0x70 */
72         u32 pad13;
73         u32 header_split;               /* 0x78 */
74         u32 pad14;
75 };
76
77 struct vnic_rq {
78         unsigned int index;
79         unsigned int posted_index;
80         struct vnic_dev *vdev;
81         struct vnic_rq_ctrl __iomem *ctrl;      /* memory-mapped */
82         struct vnic_dev_ring ring;
83         struct rte_mbuf **mbuf_ring;            /* array of allocated mbufs */
84         unsigned int mbuf_next_idx;             /* next mb to consume */
85         void *os_buf_head;
86         unsigned int pkts_outstanding;
87         uint16_t rx_nb_hold;
88         uint16_t rx_free_thresh;
89         unsigned int socket_id;
90         struct rte_mempool *mp;
91         uint16_t rxst_idx;
92         uint32_t tot_pkts;
93         uint16_t data_queue_idx;
94         uint8_t is_sop;
95         uint8_t in_use;
96         struct rte_mbuf *pkt_first_seg;
97         struct rte_mbuf *pkt_last_seg;
98         unsigned int max_mbufs_per_pkt;
99 };
100
101 static inline unsigned int vnic_rq_desc_avail(struct vnic_rq *rq)
102 {
103         /* how many does SW own? */
104         return rq->ring.desc_avail;
105 }
106
107 static inline unsigned int vnic_rq_desc_used(struct vnic_rq *rq)
108 {
109         /* how many does HW own? */
110         return rq->ring.desc_count - rq->ring.desc_avail - 1;
111 }
112
113
114
115 enum desc_return_options {
116         VNIC_RQ_RETURN_DESC,
117         VNIC_RQ_DEFER_RETURN_DESC,
118 };
119
120 static inline int vnic_rq_fill(struct vnic_rq *rq,
121         int (*buf_fill)(struct vnic_rq *rq))
122 {
123         int err;
124
125         while (vnic_rq_desc_avail(rq) > 0) {
126
127                 err = (*buf_fill)(rq);
128                 if (err)
129                         return err;
130         }
131
132         return 0;
133 }
134
135 static inline int vnic_rq_fill_count(struct vnic_rq *rq,
136         int (*buf_fill)(struct vnic_rq *rq), unsigned int count)
137 {
138         int err;
139
140         while ((vnic_rq_desc_avail(rq) > 0) && (count--)) {
141
142                 err = (*buf_fill)(rq);
143                 if (err)
144                         return err;
145         }
146
147         return 0;
148 }
149
150 void vnic_rq_free(struct vnic_rq *rq);
151 int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
152         unsigned int desc_count, unsigned int desc_size);
153 void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
154         unsigned int fetch_index, unsigned int posted_index,
155         unsigned int error_interrupt_enable,
156         unsigned int error_interrupt_offset);
157 void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
158         unsigned int error_interrupt_enable,
159         unsigned int error_interrupt_offset);
160 void vnic_rq_error_out(struct vnic_rq *rq, unsigned int error);
161 unsigned int vnic_rq_error_status(struct vnic_rq *rq);
162 void vnic_rq_enable(struct vnic_rq *rq);
163 int vnic_rq_disable(struct vnic_rq *rq);
164 void vnic_rq_clean(struct vnic_rq *rq,
165         void (*buf_clean)(struct rte_mbuf **buf));
166 #endif /* _VNIC_RQ_H_ */