]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/rdma/hfi1/qp.h
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
10 * Copyright(c) 2015 Intel Corporation.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
23 * Copyright(c) 2015 Intel Corporation.
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
29 * - Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * - Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
35 * - Neither the name of Intel Corporation nor the names of its
36 * contributors may be used to endorse or promote products derived
37 * from this software without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
42 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
43 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <linux/hash.h>
57 #define QPN_MAX (1 << 24)
58 #define QPNMAP_ENTRIES (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
61 * QPN-map pages start out as NULL, they get allocated upon
62 * first use and are never deallocated. This way,
63 * large bitmaps are not allocated unless large numbers of QPs are used.
69 struct hfi1_qpn_table
{
70 spinlock_t lock
; /* protect changes in this struct */
71 unsigned flags
; /* flags for QP0/1 allocated for each port */
72 u32 last
; /* last QP number allocated */
73 u32 nmaps
; /* size of the map table */
76 /* bit map of free QP numbers other than 0/1 */
77 struct qpn_map map
[QPNMAP_ENTRIES
];
80 struct hfi1_qp_ibdev
{
83 struct hfi1_qp __rcu
**qp_table
;
85 struct hfi1_qpn_table qpn_table
;
88 static inline u32
qpn_hash(struct hfi1_qp_ibdev
*dev
, u32 qpn
)
90 return hash_32(qpn
, dev
->qp_table_bits
);
94 * hfi1_lookup_qpn - return the QP with the given QPN
96 * @qpn: the QP number to look up
98 * The caller must hold the rcu_read_lock(), and keep the lock until
99 * the returned qp is no longer in use.
101 static inline struct hfi1_qp
*hfi1_lookup_qpn(struct hfi1_ibport
*ibp
,
102 u32 qpn
) __must_hold(RCU
)
104 struct hfi1_qp
*qp
= NULL
;
106 if (unlikely(qpn
<= 1)) {
107 qp
= rcu_dereference(ibp
->qp
[qpn
]);
109 struct hfi1_ibdev
*dev
= &ppd_from_ibp(ibp
)->dd
->verbs_dev
;
110 u32 n
= qpn_hash(dev
->qp_dev
, qpn
);
112 for (qp
= rcu_dereference(dev
->qp_dev
->qp_table
[n
]); qp
;
113 qp
= rcu_dereference(qp
->next
))
114 if (qp
->ibqp
.qp_num
== qpn
)
121 * clear_ahg - reset ahg status in qp
124 static inline void clear_ahg(struct hfi1_qp
*qp
)
126 qp
->s_hdr
->ahgcount
= 0;
127 qp
->s_flags
&= ~(HFI1_S_AHG_VALID
| HFI1_S_AHG_CLEAR
);
128 if (qp
->s_sde
&& qp
->s_ahgidx
>= 0)
129 sdma_ahg_free(qp
->s_sde
, qp
->s_ahgidx
);
135 * hfi1_error_qp - put a QP into the error state
136 * @qp: the QP to put into the error state
137 * @err: the receive completion error to signal if a RWQE is active
139 * Flushes both send and receive work queues.
140 * Returns true if last WQE event should be generated.
141 * The QP r_lock and s_lock should be held and interrupts disabled.
142 * If we are already in error state, just return.
144 int hfi1_error_qp(struct hfi1_qp
*qp
, enum ib_wc_status err
);
147 * hfi1_modify_qp - modify the attributes of a queue pair
148 * @ibqp: the queue pair who's attributes we're modifying
149 * @attr: the new attributes
150 * @attr_mask: the mask of attributes to modify
151 * @udata: user data for libibverbs.so
153 * Returns 0 on success, otherwise returns an errno.
155 int hfi1_modify_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
156 int attr_mask
, struct ib_udata
*udata
);
158 int hfi1_query_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
159 int attr_mask
, struct ib_qp_init_attr
*init_attr
);
162 * hfi1_compute_aeth - compute the AETH (syndrome + MSN)
163 * @qp: the queue pair to compute the AETH for
167 __be32
hfi1_compute_aeth(struct hfi1_qp
*qp
);
170 * hfi1_create_qp - create a queue pair for a device
171 * @ibpd: the protection domain who's device we create the queue pair for
172 * @init_attr: the attributes of the queue pair
173 * @udata: user data for libibverbs.so
175 * Returns the queue pair on success, otherwise returns an errno.
177 * Called by the ib_create_qp() core verbs function.
179 struct ib_qp
*hfi1_create_qp(struct ib_pd
*ibpd
,
180 struct ib_qp_init_attr
*init_attr
,
181 struct ib_udata
*udata
);
183 * hfi1_destroy_qp - destroy a queue pair
184 * @ibqp: the queue pair to destroy
186 * Returns 0 on success.
188 * Note that this can be called while the QP is actively sending or
191 int hfi1_destroy_qp(struct ib_qp
*ibqp
);
194 * hfi1_get_credit - flush the send work queue of a QP
195 * @qp: the qp who's send work queue to flush
196 * @aeth: the Acknowledge Extended Transport Header
198 * The QP s_lock should be held.
200 void hfi1_get_credit(struct hfi1_qp
*qp
, u32 aeth
);
203 * hfi1_qp_init - allocate QP tables
204 * @dev: a pointer to the hfi1_ibdev
206 int hfi1_qp_init(struct hfi1_ibdev
*dev
);
209 * hfi1_qp_exit - free the QP related structures
210 * @dev: a pointer to the hfi1_ibdev
212 void hfi1_qp_exit(struct hfi1_ibdev
*dev
);
215 * hfi1_qp_waitup - wake up on the indicated event
217 * @flag: flag the qp on which the qp is stalled
219 void hfi1_qp_wakeup(struct hfi1_qp
*qp
, u32 flag
);
221 struct sdma_engine
*qp_to_sdma_engine(struct hfi1_qp
*qp
, u8 sc5
);
226 * qp_iter_init - wake up on the indicated event
227 * @dev: the hfi1_ibdev
229 struct qp_iter
*qp_iter_init(struct hfi1_ibdev
*dev
);
232 * qp_iter_next - wakeup on the indicated event
233 * @iter: the iterator for the qp hash list
235 int qp_iter_next(struct qp_iter
*iter
);
238 * qp_iter_next - wake up on the indicated event
239 * @s: the seq_file to emit the qp information on
240 * @iter: the iterator for the qp hash list
242 void qp_iter_print(struct seq_file
*s
, struct qp_iter
*iter
);
245 * qp_comm_est - handle trap with QP established
248 void qp_comm_est(struct hfi1_qp
*qp
);