Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
0003 
0004 #ifndef _CQ_DESC_H_
0005 #define _CQ_DESC_H_
0006 
0007 /*
0008  * Completion queue descriptor types
0009  */
0010 enum cq_desc_types {
0011     CQ_DESC_TYPE_WQ_ENET = 0,
0012     CQ_DESC_TYPE_DESC_COPY = 1,
0013     CQ_DESC_TYPE_WQ_EXCH = 2,
0014     CQ_DESC_TYPE_RQ_ENET = 3,
0015     CQ_DESC_TYPE_RQ_FCP = 4,
0016 };
0017 
0018 /* Completion queue descriptor: 16B
0019  *
0020  * All completion queues have this basic layout.  The
0021  * type_specific area is unique for each completion
0022  * queue type.
0023  */
0024 struct cq_desc {
0025     __le16 completed_index;
0026     __le16 q_number;
0027     u8 type_specific[11];
0028     u8 type_color;
0029 };
0030 
0031 #define CQ_DESC_TYPE_BITS        4
0032 #define CQ_DESC_TYPE_MASK        ((1 << CQ_DESC_TYPE_BITS) - 1)
0033 #define CQ_DESC_COLOR_MASK       1
0034 #define CQ_DESC_COLOR_SHIFT      7
0035 #define CQ_DESC_Q_NUM_BITS       10
0036 #define CQ_DESC_Q_NUM_MASK       ((1 << CQ_DESC_Q_NUM_BITS) - 1)
0037 #define CQ_DESC_COMP_NDX_BITS    12
0038 #define CQ_DESC_COMP_NDX_MASK    ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
0039 
0040 static inline void cq_desc_dec(const struct cq_desc *desc_arg,
0041     u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
0042 {
0043     const struct cq_desc *desc = desc_arg;
0044     const u8 type_color = desc->type_color;
0045 
0046     *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
0047 
0048     /*
0049      * Make sure color bit is read from desc *before* other fields
0050      * are read from desc.  Hardware guarantees color bit is last
0051      * bit (byte) written.  Adding the rmb() prevents the compiler
0052      * and/or CPU from reordering the reads which would potentially
0053      * result in reading stale values.
0054      */
0055     rmb();
0056 
0057     *type = type_color & CQ_DESC_TYPE_MASK;
0058     *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
0059     *completed_index = le16_to_cpu(desc->completed_index) &
0060         CQ_DESC_COMP_NDX_MASK;
0061 }
0062 
0063 #endif /* _CQ_DESC_H_ */