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.
39 * Completion queue descriptor types
42 CQ_DESC_TYPE_WQ_ENET = 0,
43 CQ_DESC_TYPE_DESC_COPY = 1,
44 CQ_DESC_TYPE_WQ_EXCH = 2,
45 CQ_DESC_TYPE_RQ_ENET = 3,
46 CQ_DESC_TYPE_RQ_FCP = 4,
47 CQ_DESC_TYPE_IOMMU_MISS = 5,
49 CQ_DESC_TYPE_CLASSIFIER = 7,
50 CQ_DESC_TYPE_TEST = 127,
53 /* Completion queue descriptor: 16B
55 * All completion queues have this basic layout. The
56 * type_specfic area is unique for each completion
60 __le16 completed_index;
66 #define CQ_DESC_TYPE_BITS 4
67 #define CQ_DESC_TYPE_MASK ((1 << CQ_DESC_TYPE_BITS) - 1)
68 #define CQ_DESC_COLOR_MASK 1
69 #define CQ_DESC_COLOR_SHIFT 7
70 #define CQ_DESC_Q_NUM_BITS 10
71 #define CQ_DESC_Q_NUM_MASK ((1 << CQ_DESC_Q_NUM_BITS) - 1)
72 #define CQ_DESC_COMP_NDX_BITS 12
73 #define CQ_DESC_COMP_NDX_MASK ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
75 static inline void cq_color_enc(struct cq_desc *desc, const u8 color)
78 desc->type_color |= (1 << CQ_DESC_COLOR_SHIFT);
80 desc->type_color &= ~(1 << CQ_DESC_COLOR_SHIFT);
83 static inline void cq_desc_enc(struct cq_desc *desc,
84 const u8 type, const u8 color, const u16 q_number,
85 const u16 completed_index)
87 desc->type_color = (type & CQ_DESC_TYPE_MASK) |
88 ((color & CQ_DESC_COLOR_MASK) << CQ_DESC_COLOR_SHIFT);
89 desc->q_number = cpu_to_le16(q_number & CQ_DESC_Q_NUM_MASK);
90 desc->completed_index = cpu_to_le16(completed_index &
91 CQ_DESC_COMP_NDX_MASK);
94 static inline void cq_desc_dec(const struct cq_desc *desc_arg,
95 u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
97 const struct cq_desc *desc = desc_arg;
98 const u8 type_color = desc->type_color;
100 *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
103 * Make sure color bit is read from desc *before* other fields
104 * are read from desc. Hardware guarantees color bit is last
105 * bit (byte) written. Adding the rmb() prevents the compiler
106 * and/or CPU from reordering the reads which would potentially
107 * result in reading stale values.
112 *type = type_color & CQ_DESC_TYPE_MASK;
113 *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
114 *completed_index = le16_to_cpu(desc->completed_index) &
115 CQ_DESC_COMP_NDX_MASK;
118 static inline void cq_color_dec(const struct cq_desc *desc_arg, u8 *color)
120 volatile const struct cq_desc *desc = desc_arg;
122 *color = (desc->type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
125 #endif /* _CQ_DESC_H_ */