]>
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
);
134 * hfi1_error_qp - put a QP into the error state
135 * @qp: the QP to put into the error state
136 * @err: the receive completion error to signal if a RWQE is active
138 * Flushes both send and receive work queues.
139 * Returns true if last WQE event should be generated.
140 * The QP r_lock and s_lock should be held and interrupts disabled.
141 * If we are already in error state, just return.
143 int hfi1_error_qp(struct hfi1_qp
*qp
, enum ib_wc_status err
);
146 * hfi1_modify_qp - modify the attributes of a queue pair
147 * @ibqp: the queue pair who's attributes we're modifying
148 * @attr: the new attributes
149 * @attr_mask: the mask of attributes to modify
150 * @udata: user data for libibverbs.so
152 * Returns 0 on success, otherwise returns an errno.
154 int hfi1_modify_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
155 int attr_mask
, struct ib_udata
*udata
);
157 int hfi1_query_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
158 int attr_mask
, struct ib_qp_init_attr
*init_attr
);
161 * hfi1_compute_aeth - compute the AETH (syndrome + MSN)
162 * @qp: the queue pair to compute the AETH for
166 __be32
hfi1_compute_aeth(struct hfi1_qp
*qp
);
169 * hfi1_create_qp - create a queue pair for a device
170 * @ibpd: the protection domain who's device we create the queue pair for
171 * @init_attr: the attributes of the queue pair
172 * @udata: user data for libibverbs.so
174 * Returns the queue pair on success, otherwise returns an errno.
176 * Called by the ib_create_qp() core verbs function.
178 struct ib_qp
*hfi1_create_qp(struct ib_pd
*ibpd
,
179 struct ib_qp_init_attr
*init_attr
,
180 struct ib_udata
*udata
);
182 * hfi1_destroy_qp - destroy a queue pair
183 * @ibqp: the queue pair to destroy
185 * Returns 0 on success.
187 * Note that this can be called while the QP is actively sending or
190 int hfi1_destroy_qp(struct ib_qp
*ibqp
);
193 * hfi1_get_credit - flush the send work queue of a QP
194 * @qp: the qp who's send work queue to flush
195 * @aeth: the Acknowledge Extended Transport Header
197 * The QP s_lock should be held.
199 void hfi1_get_credit(struct hfi1_qp
*qp
, u32 aeth
);
202 * hfi1_qp_init - allocate QP tables
203 * @dev: a pointer to the hfi1_ibdev
205 int hfi1_qp_init(struct hfi1_ibdev
*dev
);
208 * hfi1_qp_exit - free the QP related structures
209 * @dev: a pointer to the hfi1_ibdev
211 void hfi1_qp_exit(struct hfi1_ibdev
*dev
);
214 * hfi1_qp_wakeup - wake up on the indicated event
216 * @flag: flag the qp on which the qp is stalled
218 void hfi1_qp_wakeup(struct hfi1_qp
*qp
, u32 flag
);
220 struct sdma_engine
*qp_to_sdma_engine(struct hfi1_qp
*qp
, u8 sc5
);
225 * qp_iter_init - initialize the iterator for the qp hash list
226 * @dev: the hfi1_ibdev
228 struct qp_iter
*qp_iter_init(struct hfi1_ibdev
*dev
);
231 * qp_iter_next - Find the next qp in the hash list
232 * @iter: the iterator for the qp hash list
234 int qp_iter_next(struct qp_iter
*iter
);
237 * qp_iter_print - print the qp information to seq_file
238 * @s: the seq_file to emit the qp information on
239 * @iter: the iterator for the qp hash list
241 void qp_iter_print(struct seq_file
*s
, struct qp_iter
*iter
);
244 * qp_comm_est - handle trap with QP established
247 void qp_comm_est(struct hfi1_qp
*qp
);
250 * _hfi1_schedule_send - schedule progress
253 * This schedules qp progress w/o regard to the s_flags.
255 * It is only used in the post send, which doesn't hold
258 static inline void _hfi1_schedule_send(struct hfi1_qp
*qp
)
260 struct hfi1_ibport
*ibp
=
261 to_iport(qp
->ibqp
.device
, qp
->port_num
);
262 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
263 struct hfi1_devdata
*dd
= dd_from_ibdev(qp
->ibqp
.device
);
265 iowait_schedule(&qp
->s_iowait
, ppd
->hfi1_wq
,
268 cpumask_first(cpumask_of_node(dd
->assigned_node_id
)));
272 * hfi1_schedule_send - schedule progress
275 * This schedules qp progress and caller should hold
278 static inline void hfi1_schedule_send(struct hfi1_qp
*qp
)
280 if (hfi1_send_ok(qp
))
281 _hfi1_schedule_send(qp
);
284 void hfi1_migrate_qp(struct hfi1_qp
*qp
);