remove extra parentheses in return statement
[dpdk.git] / drivers / net / vmxnet3 / vmxnet3_ring.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _VMXNET3_RING_H_
35 #define _VMXNET3_RING_H_
36
37 #define VMXNET3_RX_CMDRING_SIZE 2
38
39 #define VMXNET3_DRIVER_VERSION_NUM 0x01012000
40
41 /* Default ring size */
42 #define VMXNET3_DEF_TX_RING_SIZE 512
43 #define VMXNET3_DEF_RX_RING_SIZE 128
44
45 #define VMXNET3_SUCCESS 0
46 #define VMXNET3_FAIL   -1
47
48 #define TRUE  1
49 #define FALSE 0
50
51
52 typedef struct vmxnet3_buf_info {
53         uint16_t               len;
54         struct rte_mbuf        *m;
55         uint64_t               bufPA;
56 } vmxnet3_buf_info_t;
57
58 typedef struct vmxnet3_cmd_ring {
59         vmxnet3_buf_info_t     *buf_info;
60         uint32_t               size;
61         uint32_t               next2fill;
62         uint32_t               next2comp;
63         uint8_t                gen;
64         uint8_t                rid;
65         Vmxnet3_GenericDesc    *base;
66         uint64_t               basePA;
67 } vmxnet3_cmd_ring_t;
68
69 static inline void
70 vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring)
71 {
72         ring->next2fill++;
73         if (unlikely(ring->next2fill == ring->size)) {
74                 ring->next2fill = 0;
75                 ring->gen = (uint8_t)(ring->gen ^ 1);
76         }
77 }
78
79 static inline void
80 vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring)
81 {
82         VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size);
83 }
84
85 static inline uint32_t
86 vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring)
87 {
88         return (ring->next2comp > ring->next2fill ? 0 : ring->size) +
89                    ring->next2comp - ring->next2fill - 1;
90 }
91
92 static inline bool
93 vmxnet3_cmd_ring_desc_empty(struct vmxnet3_cmd_ring *ring)
94 {
95         return ring->next2comp == ring->next2fill;
96 }
97
98 typedef struct vmxnet3_comp_ring {
99         uint32_t               size;
100         uint32_t               next2proc;
101         uint8_t                gen;
102         uint8_t                intr_idx;
103         Vmxnet3_GenericDesc    *base;
104         uint64_t               basePA;
105 } vmxnet3_comp_ring_t;
106
107 struct vmxnet3_data_ring {
108         struct Vmxnet3_TxDataDesc *base;
109         uint32_t                  size;
110         uint64_t                  basePA;
111 };
112
113 static inline void
114 vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring)
115 {
116         ring->next2proc++;
117         if (unlikely(ring->next2proc == ring->size)) {
118                 ring->next2proc = 0;
119                 ring->gen = (uint8_t)(ring->gen ^ 1);
120         }
121 }
122
123 struct vmxnet3_txq_stats {
124         uint64_t        drop_total; /* # of pkts dropped by the driver,
125                                      * the counters below track droppings due to
126                                      * different reasons
127                                      */
128         uint64_t        drop_too_many_segs;
129         uint64_t        drop_tso;
130         uint64_t        tx_ring_full;
131 };
132
133 typedef struct vmxnet3_tx_ctx {
134         int      ip_type;
135         bool     is_vlan;
136         bool     is_cso;
137
138         uint16_t evl_tag;               /* only valid when is_vlan == TRUE */
139         uint32_t eth_hdr_size;  /* only valid for pkts requesting tso or csum
140                                                          * offloading */
141         uint32_t ip_hdr_size;
142         uint32_t l4_hdr_size;
143 } vmxnet3_tx_ctx_t;
144
145 typedef struct vmxnet3_tx_queue {
146         struct vmxnet3_hw            *hw;
147         struct vmxnet3_cmd_ring      cmd_ring;
148         struct vmxnet3_comp_ring     comp_ring;
149         struct vmxnet3_data_ring     data_ring;
150         uint32_t                     qid;
151         struct Vmxnet3_TxQueueDesc   *shared;
152         struct vmxnet3_txq_stats     stats;
153         bool                         stopped;
154         uint16_t                     queue_id;      /**< Device TX queue index. */
155         uint8_t                      port_id;       /**< Device port identifier. */
156 } vmxnet3_tx_queue_t;
157
158
159 struct vmxnet3_rxq_stats {
160         uint64_t                     drop_total;
161         uint64_t                     drop_err;
162         uint64_t                     drop_fcs;
163         uint64_t                     rx_buf_alloc_failure;
164 };
165
166 typedef struct vmxnet3_rx_queue {
167         struct rte_mempool          *mp;
168         struct vmxnet3_hw           *hw;
169         struct vmxnet3_cmd_ring     cmd_ring[VMXNET3_RX_CMDRING_SIZE];
170         struct vmxnet3_comp_ring    comp_ring;
171         uint32_t                    qid1;
172         uint32_t                    qid2;
173         Vmxnet3_RxQueueDesc         *shared;
174         struct vmxnet3_rxq_stats    stats;
175         bool                        stopped;
176         uint16_t                    queue_id;      /**< Device RX queue index. */
177         uint8_t                     port_id;       /**< Device port identifier. */
178 } vmxnet3_rx_queue_t;
179
180 #endif /* _VMXNET3_RING_H_ */