e1000: move to drivers/net/
[dpdk.git] / lib / librte_pmd_enic / vnic / cq_desc.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 #ident "$Id: cq_desc.h 129574 2013-04-26 22:11:14Z rfaucett $"
35
36 #ifndef _CQ_DESC_H_
37 #define _CQ_DESC_H_
38
39 /*
40  * Completion queue descriptor types
41  */
42 enum cq_desc_types {
43         CQ_DESC_TYPE_WQ_ENET = 0,
44         CQ_DESC_TYPE_DESC_COPY = 1,
45         CQ_DESC_TYPE_WQ_EXCH = 2,
46         CQ_DESC_TYPE_RQ_ENET = 3,
47         CQ_DESC_TYPE_RQ_FCP = 4,
48         CQ_DESC_TYPE_IOMMU_MISS = 5,
49         CQ_DESC_TYPE_SGL = 6,
50         CQ_DESC_TYPE_CLASSIFIER = 7,
51         CQ_DESC_TYPE_TEST = 127,
52 };
53
54 /* Completion queue descriptor: 16B
55  *
56  * All completion queues have this basic layout.  The
57  * type_specfic area is unique for each completion
58  * queue type.
59  */
60 struct cq_desc {
61         __le16 completed_index;
62         __le16 q_number;
63         u8 type_specfic[11];
64         u8 type_color;
65 };
66
67 #define CQ_DESC_TYPE_BITS        4
68 #define CQ_DESC_TYPE_MASK        ((1 << CQ_DESC_TYPE_BITS) - 1)
69 #define CQ_DESC_COLOR_MASK       1
70 #define CQ_DESC_COLOR_SHIFT      7
71 #define CQ_DESC_Q_NUM_BITS       10
72 #define CQ_DESC_Q_NUM_MASK       ((1 << CQ_DESC_Q_NUM_BITS) - 1)
73 #define CQ_DESC_COMP_NDX_BITS    12
74 #define CQ_DESC_COMP_NDX_MASK    ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
75
76 static inline void cq_color_enc(struct cq_desc *desc, const u8 color)
77 {
78         if (color)
79                 desc->type_color |=  (1 << CQ_DESC_COLOR_SHIFT);
80         else
81                 desc->type_color &= ~(1 << CQ_DESC_COLOR_SHIFT);
82 }
83
84 static inline void cq_desc_enc(struct cq_desc *desc,
85         const u8 type, const u8 color, const u16 q_number,
86         const u16 completed_index)
87 {
88         desc->type_color = (type & CQ_DESC_TYPE_MASK) |
89                 ((color & CQ_DESC_COLOR_MASK) << CQ_DESC_COLOR_SHIFT);
90         desc->q_number = cpu_to_le16(q_number & CQ_DESC_Q_NUM_MASK);
91         desc->completed_index = cpu_to_le16(completed_index &
92                 CQ_DESC_COMP_NDX_MASK);
93 }
94
95 static inline void cq_desc_dec(const struct cq_desc *desc_arg,
96         u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
97 {
98         const struct cq_desc *desc = desc_arg;
99         const u8 type_color = desc->type_color;
100
101         *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
102
103         /*
104          * Make sure color bit is read from desc *before* other fields
105          * are read from desc.  Hardware guarantees color bit is last
106          * bit (byte) written.  Adding the rmb() prevents the compiler
107          * and/or CPU from reordering the reads which would potentially
108          * result in reading stale values.
109          */
110
111         rmb();
112
113         *type = type_color & CQ_DESC_TYPE_MASK;
114         *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
115         *completed_index = le16_to_cpu(desc->completed_index) &
116                 CQ_DESC_COMP_NDX_MASK;
117 }
118
119 static inline void cq_color_dec(const struct cq_desc *desc_arg, u8 *color)
120 {
121         volatile const struct cq_desc *desc = desc_arg;
122
123         *color = (desc->type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
124 }
125
126 #endif /* _CQ_DESC_H_ */