Back to home page

OSCL-LXR

 
 

    


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