Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma
[deliverable/linux.git] / drivers / scsi / snic / cq_desc.h
1 /*
2 * Copyright 2014 Cisco Systems, Inc. All rights reserved.
3 *
4 * This program is free software; you may redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15 * SOFTWARE.
16 */
17
18 #ifndef _CQ_DESC_H_
19 #define _CQ_DESC_H_
20
21 /*
22 * Completion queue descriptor types
23 */
24 enum cq_desc_types {
25 CQ_DESC_TYPE_WQ_ENET = 0,
26 CQ_DESC_TYPE_DESC_COPY = 1,
27 CQ_DESC_TYPE_WQ_EXCH = 2,
28 CQ_DESC_TYPE_RQ_ENET = 3,
29 CQ_DESC_TYPE_RQ_FCP = 4,
30 };
31
32 /* Completion queue descriptor: 16B
33 *
34 * All completion queues have this basic layout. The
35 * type_specific area is unique for each completion
36 * queue type.
37 */
38 struct cq_desc {
39 __le16 completed_index;
40 __le16 q_number;
41 u8 type_specific[11];
42 u8 type_color;
43 };
44
45 #define CQ_DESC_TYPE_BITS 4
46 #define CQ_DESC_TYPE_MASK ((1 << CQ_DESC_TYPE_BITS) - 1)
47 #define CQ_DESC_COLOR_MASK 1
48 #define CQ_DESC_COLOR_SHIFT 7
49 #define CQ_DESC_Q_NUM_BITS 10
50 #define CQ_DESC_Q_NUM_MASK ((1 << CQ_DESC_Q_NUM_BITS) - 1)
51 #define CQ_DESC_COMP_NDX_BITS 12
52 #define CQ_DESC_COMP_NDX_MASK ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
53
54 static inline void cq_desc_dec(const struct cq_desc *desc_arg,
55 u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
56 {
57 const struct cq_desc *desc = desc_arg;
58 const u8 type_color = desc->type_color;
59
60 *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
61
62 /*
63 * Make sure color bit is read from desc *before* other fields
64 * are read from desc. Hardware guarantees color bit is last
65 * bit (byte) written. Adding the rmb() prevents the compiler
66 * and/or CPU from reordering the reads which would potentially
67 * result in reading stale values.
68 */
69 rmb();
70
71 *type = type_color & CQ_DESC_TYPE_MASK;
72 *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
73 *completed_index = le16_to_cpu(desc->completed_index) &
74 CQ_DESC_COMP_NDX_MASK;
75 }
76
77 #endif /* _CQ_DESC_H_ */
This page took 0.030954 seconds and 5 git commands to generate.