xref: /freebsd/sys/ofed/include/rdma/rdmavt_cq.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1478d3005SHans Petter Selasky #ifndef DEF_RDMAVT_INCCQ_H
2478d3005SHans Petter Selasky #define DEF_RDMAVT_INCCQ_H
3478d3005SHans Petter Selasky 
4*09938b21SHans Petter Selasky /*-
5*09938b21SHans Petter Selasky  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
6478d3005SHans Petter Selasky  *
7478d3005SHans Petter Selasky  * This file is provided under a dual BSD/GPLv2 license.  When using or
8478d3005SHans Petter Selasky  * redistributing this file, you may do so under either license.
9478d3005SHans Petter Selasky  *
10478d3005SHans Petter Selasky  * GPL LICENSE SUMMARY
11478d3005SHans Petter Selasky  *
12478d3005SHans Petter Selasky  * Copyright(c) 2016 Intel Corporation.
13478d3005SHans Petter Selasky  *
14478d3005SHans Petter Selasky  * This program is free software; you can redistribute it and/or modify
15478d3005SHans Petter Selasky  * it under the terms of version 2 of the GNU General Public License as
16478d3005SHans Petter Selasky  * published by the Free Software Foundation.
17478d3005SHans Petter Selasky  *
18478d3005SHans Petter Selasky  * This program is distributed in the hope that it will be useful, but
19478d3005SHans Petter Selasky  * WITHOUT ANY WARRANTY; without even the implied warranty of
20478d3005SHans Petter Selasky  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21478d3005SHans Petter Selasky  * General Public License for more details.
22478d3005SHans Petter Selasky  *
23478d3005SHans Petter Selasky  * BSD LICENSE
24478d3005SHans Petter Selasky  *
25478d3005SHans Petter Selasky  * Copyright(c) 2015 Intel Corporation.
26478d3005SHans Petter Selasky  *
27478d3005SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
28478d3005SHans Petter Selasky  * modification, are permitted provided that the following conditions
29478d3005SHans Petter Selasky  * are met:
30478d3005SHans Petter Selasky  *
31478d3005SHans Petter Selasky  *  - Redistributions of source code must retain the above copyright
32478d3005SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
33478d3005SHans Petter Selasky  *  - Redistributions in binary form must reproduce the above copyright
34478d3005SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in
35478d3005SHans Petter Selasky  *    the documentation and/or other materials provided with the
36478d3005SHans Petter Selasky  *    distribution.
37478d3005SHans Petter Selasky  *  - Neither the name of Intel Corporation nor the names of its
38478d3005SHans Petter Selasky  *    contributors may be used to endorse or promote products derived
39478d3005SHans Petter Selasky  *    from this software without specific prior written permission.
40478d3005SHans Petter Selasky  *
41478d3005SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
42478d3005SHans Petter Selasky  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
43478d3005SHans Petter Selasky  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
44478d3005SHans Petter Selasky  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
45478d3005SHans Petter Selasky  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46478d3005SHans Petter Selasky  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47478d3005SHans Petter Selasky  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48478d3005SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49478d3005SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50478d3005SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51478d3005SHans Petter Selasky  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52478d3005SHans Petter Selasky  */
53478d3005SHans Petter Selasky 
54478d3005SHans Petter Selasky #include <linux/kthread.h>
55478d3005SHans Petter Selasky #include <rdma/ib_user_verbs.h>
56478d3005SHans Petter Selasky 
57478d3005SHans Petter Selasky /*
58478d3005SHans Petter Selasky  * Define an ib_cq_notify value that is not valid so we know when CQ
59478d3005SHans Petter Selasky  * notifications are armed.
60478d3005SHans Petter Selasky  */
61478d3005SHans Petter Selasky #define RVT_CQ_NONE      (IB_CQ_NEXT_COMP + 1)
62478d3005SHans Petter Selasky 
63478d3005SHans Petter Selasky /*
64478d3005SHans Petter Selasky  * This structure is used to contain the head pointer, tail pointer,
65478d3005SHans Petter Selasky  * and completion queue entries as a single memory allocation so
66478d3005SHans Petter Selasky  * it can be mmap'ed into user space.
67478d3005SHans Petter Selasky  */
68478d3005SHans Petter Selasky struct rvt_cq_wc {
69478d3005SHans Petter Selasky 	u32 head;               /* index of next entry to fill */
70478d3005SHans Petter Selasky 	u32 tail;               /* index of next ib_poll_cq() entry */
71478d3005SHans Petter Selasky 	union {
72478d3005SHans Petter Selasky 		/* these are actually size ibcq.cqe + 1 */
73478d3005SHans Petter Selasky 		struct ib_uverbs_wc uqueue[0];
74478d3005SHans Petter Selasky 		struct ib_wc kqueue[0];
75478d3005SHans Petter Selasky 	};
76478d3005SHans Petter Selasky };
77478d3005SHans Petter Selasky 
78478d3005SHans Petter Selasky /*
79478d3005SHans Petter Selasky  * The completion queue structure.
80478d3005SHans Petter Selasky  */
81478d3005SHans Petter Selasky struct rvt_cq {
82478d3005SHans Petter Selasky 	struct ib_cq ibcq;
83478d3005SHans Petter Selasky 	struct kthread_work comptask;
84478d3005SHans Petter Selasky 	spinlock_t lock; /* protect changes in this struct */
85478d3005SHans Petter Selasky 	u8 notify;
86478d3005SHans Petter Selasky 	u8 triggered;
87478d3005SHans Petter Selasky 	struct rvt_dev_info *rdi;
88478d3005SHans Petter Selasky 	struct rvt_cq_wc *queue;
89478d3005SHans Petter Selasky 	struct rvt_mmap_info *ip;
90478d3005SHans Petter Selasky };
91478d3005SHans Petter Selasky 
ibcq_to_rvtcq(struct ib_cq * ibcq)92478d3005SHans Petter Selasky static inline struct rvt_cq *ibcq_to_rvtcq(struct ib_cq *ibcq)
93478d3005SHans Petter Selasky {
94478d3005SHans Petter Selasky 	return container_of(ibcq, struct rvt_cq, ibcq);
95478d3005SHans Petter Selasky }
96478d3005SHans Petter Selasky 
97478d3005SHans Petter Selasky void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited);
98478d3005SHans Petter Selasky 
99478d3005SHans Petter Selasky #endif          /* DEF_RDMAVT_INCCQH */
100