Back to home page

OSCL-LXR

 
 

    


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