xref: /freebsd/sys/ofed/include/rdma/rdmavt_cq.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 #ifndef DEF_RDMAVT_INCCQ_H
2 #define DEF_RDMAVT_INCCQ_H
3 
4 /*-
5  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
6  *
7  * This file is provided under a dual BSD/GPLv2 license.  When using or
8  * redistributing this file, you may do so under either license.
9  *
10  * GPL LICENSE SUMMARY
11  *
12  * Copyright(c) 2016 Intel Corporation.
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of version 2 of the GNU General Public License as
16  * published by the Free Software Foundation.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * General Public License for more details.
22  *
23  * BSD LICENSE
24  *
25  * Copyright(c) 2015 Intel Corporation.
26  *
27  * Redistribution and use in source and binary forms, with or without
28  * modification, are permitted provided that the following conditions
29  * are met:
30  *
31  *  - Redistributions of source code must retain the above copyright
32  *    notice, this list of conditions and the following disclaimer.
33  *  - Redistributions in binary form must reproduce the above copyright
34  *    notice, this list of conditions and the following disclaimer in
35  *    the documentation and/or other materials provided with the
36  *    distribution.
37  *  - Neither the name of Intel Corporation nor the names of its
38  *    contributors may be used to endorse or promote products derived
39  *    from this software without specific prior written permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
42  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
43  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
44  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
45  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52  *
53  * $FreeBSD$
54  */
55 
56 #include <linux/kthread.h>
57 #include <rdma/ib_user_verbs.h>
58 
59 /*
60  * Define an ib_cq_notify value that is not valid so we know when CQ
61  * notifications are armed.
62  */
63 #define RVT_CQ_NONE      (IB_CQ_NEXT_COMP + 1)
64 
65 /*
66  * This structure is used to contain the head pointer, tail pointer,
67  * and completion queue entries as a single memory allocation so
68  * it can be mmap'ed into user space.
69  */
70 struct rvt_cq_wc {
71 	u32 head;               /* index of next entry to fill */
72 	u32 tail;               /* index of next ib_poll_cq() entry */
73 	union {
74 		/* these are actually size ibcq.cqe + 1 */
75 		struct ib_uverbs_wc uqueue[0];
76 		struct ib_wc kqueue[0];
77 	};
78 };
79 
80 /*
81  * The completion queue structure.
82  */
83 struct rvt_cq {
84 	struct ib_cq ibcq;
85 	struct kthread_work comptask;
86 	spinlock_t lock; /* protect changes in this struct */
87 	u8 notify;
88 	u8 triggered;
89 	struct rvt_dev_info *rdi;
90 	struct rvt_cq_wc *queue;
91 	struct rvt_mmap_info *ip;
92 };
93 
94 static inline struct rvt_cq *ibcq_to_rvtcq(struct ib_cq *ibcq)
95 {
96 	return container_of(ibcq, struct rvt_cq, ibcq);
97 }
98 
99 void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited);
100 
101 #endif          /* DEF_RDMAVT_INCCQH */
102