Loading...
1// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2/*
3 * Copyright(c) 2015 - 2020 Intel Corporation.
4 */
5
6#include <linux/err.h>
7#include <linux/vmalloc.h>
8#include <linux/hash.h>
9#include <linux/module.h>
10#include <linux/seq_file.h>
11#include <rdma/rdma_vt.h>
12#include <rdma/rdmavt_qp.h>
13#include <rdma/ib_verbs.h>
14
15#include "hfi.h"
16#include "qp.h"
17#include "trace.h"
18#include "verbs_txreq.h"
19
20unsigned int hfi1_qp_table_size = 256;
21module_param_named(qp_table_size, hfi1_qp_table_size, uint, S_IRUGO);
22MODULE_PARM_DESC(qp_table_size, "QP table size");
23
24static void flush_tx_list(struct rvt_qp *qp);
25static int iowait_sleep(
26 struct sdma_engine *sde,
27 struct iowait_work *wait,
28 struct sdma_txreq *stx,
29 unsigned int seq,
30 bool pkts_sent);
31static void iowait_wakeup(struct iowait *wait, int reason);
32static void iowait_sdma_drained(struct iowait *wait);
33static void qp_pio_drain(struct rvt_qp *qp);
34
35const struct rvt_operation_params hfi1_post_parms[RVT_OPERATION_MAX] = {
36[IB_WR_RDMA_WRITE] = {
37 .length = sizeof(struct ib_rdma_wr),
38 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
39},
40
41[IB_WR_RDMA_READ] = {
42 .length = sizeof(struct ib_rdma_wr),
43 .qpt_support = BIT(IB_QPT_RC),
44 .flags = RVT_OPERATION_ATOMIC,
45},
46
47[IB_WR_ATOMIC_CMP_AND_SWP] = {
48 .length = sizeof(struct ib_atomic_wr),
49 .qpt_support = BIT(IB_QPT_RC),
50 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
51},
52
53[IB_WR_ATOMIC_FETCH_AND_ADD] = {
54 .length = sizeof(struct ib_atomic_wr),
55 .qpt_support = BIT(IB_QPT_RC),
56 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
57},
58
59[IB_WR_RDMA_WRITE_WITH_IMM] = {
60 .length = sizeof(struct ib_rdma_wr),
61 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
62},
63
64[IB_WR_SEND] = {
65 .length = sizeof(struct ib_send_wr),
66 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
67 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
68},
69
70[IB_WR_SEND_WITH_IMM] = {
71 .length = sizeof(struct ib_send_wr),
72 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
73 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
74},
75
76[IB_WR_REG_MR] = {
77 .length = sizeof(struct ib_reg_wr),
78 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
79 .flags = RVT_OPERATION_LOCAL,
80},
81
82[IB_WR_LOCAL_INV] = {
83 .length = sizeof(struct ib_send_wr),
84 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
85 .flags = RVT_OPERATION_LOCAL,
86},
87
88[IB_WR_SEND_WITH_INV] = {
89 .length = sizeof(struct ib_send_wr),
90 .qpt_support = BIT(IB_QPT_RC),
91},
92
93[IB_WR_OPFN] = {
94 .length = sizeof(struct ib_atomic_wr),
95 .qpt_support = BIT(IB_QPT_RC),
96 .flags = RVT_OPERATION_USE_RESERVE,
97},
98
99[IB_WR_TID_RDMA_WRITE] = {
100 .length = sizeof(struct ib_rdma_wr),
101 .qpt_support = BIT(IB_QPT_RC),
102 .flags = RVT_OPERATION_IGN_RNR_CNT,
103},
104
105};
106
107static void flush_list_head(struct list_head *l)
108{
109 while (!list_empty(l)) {
110 struct sdma_txreq *tx;
111
112 tx = list_first_entry(
113 l,
114 struct sdma_txreq,
115 list);
116 list_del_init(&tx->list);
117 hfi1_put_txreq(
118 container_of(tx, struct verbs_txreq, txreq));
119 }
120}
121
122static void flush_tx_list(struct rvt_qp *qp)
123{
124 struct hfi1_qp_priv *priv = qp->priv;
125
126 flush_list_head(&iowait_get_ib_work(&priv->s_iowait)->tx_head);
127 flush_list_head(&iowait_get_tid_work(&priv->s_iowait)->tx_head);
128}
129
130static void flush_iowait(struct rvt_qp *qp)
131{
132 struct hfi1_qp_priv *priv = qp->priv;
133 unsigned long flags;
134 seqlock_t *lock = priv->s_iowait.lock;
135
136 if (!lock)
137 return;
138 write_seqlock_irqsave(lock, flags);
139 if (!list_empty(&priv->s_iowait.list)) {
140 list_del_init(&priv->s_iowait.list);
141 priv->s_iowait.lock = NULL;
142 rvt_put_qp(qp);
143 }
144 write_sequnlock_irqrestore(lock, flags);
145}
146
147/*
148 * This function is what we would push to the core layer if we wanted to be a
149 * "first class citizen". Instead we hide this here and rely on Verbs ULPs
150 * to blindly pass the MTU enum value from the PathRecord to us.
151 */
152static inline int verbs_mtu_enum_to_int(struct ib_device *dev, enum ib_mtu mtu)
153{
154 /* Constraining 10KB packets to 8KB packets */
155 if (mtu == (enum ib_mtu)OPA_MTU_10240)
156 mtu = (enum ib_mtu)OPA_MTU_8192;
157 return opa_mtu_enum_to_int((enum opa_mtu)mtu);
158}
159
160int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
161 int attr_mask, struct ib_udata *udata)
162{
163 struct ib_qp *ibqp = &qp->ibqp;
164 struct hfi1_ibdev *dev = to_idev(ibqp->device);
165 struct hfi1_devdata *dd = dd_from_dev(dev);
166 u8 sc;
167
168 if (attr_mask & IB_QP_AV) {
169 sc = ah_to_sc(ibqp->device, &attr->ah_attr);
170 if (sc == 0xf)
171 return -EINVAL;
172
173 if (!qp_to_sdma_engine(qp, sc) &&
174 dd->flags & HFI1_HAS_SEND_DMA)
175 return -EINVAL;
176
177 if (!qp_to_send_context(qp, sc))
178 return -EINVAL;
179 }
180
181 if (attr_mask & IB_QP_ALT_PATH) {
182 sc = ah_to_sc(ibqp->device, &attr->alt_ah_attr);
183 if (sc == 0xf)
184 return -EINVAL;
185
186 if (!qp_to_sdma_engine(qp, sc) &&
187 dd->flags & HFI1_HAS_SEND_DMA)
188 return -EINVAL;
189
190 if (!qp_to_send_context(qp, sc))
191 return -EINVAL;
192 }
193
194 return 0;
195}
196
197/*
198 * qp_set_16b - Set the hdr_type based on whether the slid or the
199 * dlid in the connection is extended. Only applicable for RC and UC
200 * QPs. UD QPs determine this on the fly from the ah in the wqe
201 */
202static inline void qp_set_16b(struct rvt_qp *qp)
203{
204 struct hfi1_pportdata *ppd;
205 struct hfi1_ibport *ibp;
206 struct hfi1_qp_priv *priv = qp->priv;
207
208 /* Update ah_attr to account for extended LIDs */
209 hfi1_update_ah_attr(qp->ibqp.device, &qp->remote_ah_attr);
210
211 /* Create 32 bit LIDs */
212 hfi1_make_opa_lid(&qp->remote_ah_attr);
213
214 if (!(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH))
215 return;
216
217 ibp = to_iport(qp->ibqp.device, qp->port_num);
218 ppd = ppd_from_ibp(ibp);
219 priv->hdr_type = hfi1_get_hdr_type(ppd->lid, &qp->remote_ah_attr);
220}
221
222void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
223 int attr_mask, struct ib_udata *udata)
224{
225 struct ib_qp *ibqp = &qp->ibqp;
226 struct hfi1_qp_priv *priv = qp->priv;
227
228 if (attr_mask & IB_QP_AV) {
229 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
230 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
231 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
232 qp_set_16b(qp);
233 }
234
235 if (attr_mask & IB_QP_PATH_MIG_STATE &&
236 attr->path_mig_state == IB_MIG_MIGRATED &&
237 qp->s_mig_state == IB_MIG_ARMED) {
238 qp->s_flags |= HFI1_S_AHG_CLEAR;
239 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
240 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
241 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
242 qp_set_16b(qp);
243 }
244
245 opfn_qp_init(qp, attr, attr_mask);
246}
247
248/**
249 * hfi1_setup_wqe - set up the wqe
250 * @qp: The qp
251 * @wqe: The built wqe
252 * @call_send: Determine if the send should be posted or scheduled.
253 *
254 * Perform setup of the wqe. This is called
255 * prior to inserting the wqe into the ring but after
256 * the wqe has been setup by RDMAVT. This function
257 * allows the driver the opportunity to perform
258 * validation and additional setup of the wqe.
259 *
260 * Returns 0 on success, -EINVAL on failure
261 *
262 */
263int hfi1_setup_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe, bool *call_send)
264{
265 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
266 struct rvt_ah *ah;
267 struct hfi1_pportdata *ppd;
268 struct hfi1_devdata *dd;
269
270 switch (qp->ibqp.qp_type) {
271 case IB_QPT_RC:
272 hfi1_setup_tid_rdma_wqe(qp, wqe);
273 fallthrough;
274 case IB_QPT_UC:
275 if (wqe->length > 0x80000000U)
276 return -EINVAL;
277 if (wqe->length > qp->pmtu)
278 *call_send = false;
279 break;
280 case IB_QPT_SMI:
281 /*
282 * SM packets should exclusively use VL15 and their SL is
283 * ignored (IBTA v1.3, Section 3.5.8.2). Therefore, when ah
284 * is created, SL is 0 in most cases and as a result some
285 * fields (vl and pmtu) in ah may not be set correctly,
286 * depending on the SL2SC and SC2VL tables at the time.
287 */
288 ppd = ppd_from_ibp(ibp);
289 dd = dd_from_ppd(ppd);
290 if (wqe->length > dd->vld[15].mtu)
291 return -EINVAL;
292 break;
293 case IB_QPT_GSI:
294 case IB_QPT_UD:
295 ah = rvt_get_swqe_ah(wqe);
296 if (wqe->length > (1 << ah->log_pmtu))
297 return -EINVAL;
298 if (ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)] == 0xf)
299 return -EINVAL;
300 break;
301 default:
302 break;
303 }
304
305 /*
306 * System latency between send and schedule is large enough that
307 * forcing call_send to true for piothreshold packets is necessary.
308 */
309 if (wqe->length <= piothreshold)
310 *call_send = true;
311 return 0;
312}
313
314/**
315 * _hfi1_schedule_send - schedule progress
316 * @qp: the QP
317 *
318 * This schedules qp progress w/o regard to the s_flags.
319 *
320 * It is only used in the post send, which doesn't hold
321 * the s_lock.
322 */
323bool _hfi1_schedule_send(struct rvt_qp *qp)
324{
325 struct hfi1_qp_priv *priv = qp->priv;
326 struct hfi1_ibport *ibp =
327 to_iport(qp->ibqp.device, qp->port_num);
328 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
329 struct hfi1_devdata *dd = ppd->dd;
330
331 if (dd->flags & HFI1_SHUTDOWN)
332 return true;
333
334 return iowait_schedule(&priv->s_iowait, ppd->hfi1_wq,
335 priv->s_sde ?
336 priv->s_sde->cpu :
337 cpumask_first(cpumask_of_node(dd->node)));
338}
339
340static void qp_pio_drain(struct rvt_qp *qp)
341{
342 struct hfi1_qp_priv *priv = qp->priv;
343
344 if (!priv->s_sendcontext)
345 return;
346 while (iowait_pio_pending(&priv->s_iowait)) {
347 write_seqlock_irq(&priv->s_sendcontext->waitlock);
348 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 1);
349 write_sequnlock_irq(&priv->s_sendcontext->waitlock);
350 iowait_pio_drain(&priv->s_iowait);
351 write_seqlock_irq(&priv->s_sendcontext->waitlock);
352 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 0);
353 write_sequnlock_irq(&priv->s_sendcontext->waitlock);
354 }
355}
356
357/**
358 * hfi1_schedule_send - schedule progress
359 * @qp: the QP
360 *
361 * This schedules qp progress and caller should hold
362 * the s_lock.
363 * @return true if the first leg is scheduled;
364 * false if the first leg is not scheduled.
365 */
366bool hfi1_schedule_send(struct rvt_qp *qp)
367{
368 lockdep_assert_held(&qp->s_lock);
369 if (hfi1_send_ok(qp)) {
370 _hfi1_schedule_send(qp);
371 return true;
372 }
373 if (qp->s_flags & HFI1_S_ANY_WAIT_IO)
374 iowait_set_flag(&((struct hfi1_qp_priv *)qp->priv)->s_iowait,
375 IOWAIT_PENDING_IB);
376 return false;
377}
378
379static void hfi1_qp_schedule(struct rvt_qp *qp)
380{
381 struct hfi1_qp_priv *priv = qp->priv;
382 bool ret;
383
384 if (iowait_flag_set(&priv->s_iowait, IOWAIT_PENDING_IB)) {
385 ret = hfi1_schedule_send(qp);
386 if (ret)
387 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_IB);
388 }
389 if (iowait_flag_set(&priv->s_iowait, IOWAIT_PENDING_TID)) {
390 ret = hfi1_schedule_tid_send(qp);
391 if (ret)
392 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_TID);
393 }
394}
395
396void hfi1_qp_wakeup(struct rvt_qp *qp, u32 flag)
397{
398 unsigned long flags;
399
400 spin_lock_irqsave(&qp->s_lock, flags);
401 if (qp->s_flags & flag) {
402 qp->s_flags &= ~flag;
403 trace_hfi1_qpwakeup(qp, flag);
404 hfi1_qp_schedule(qp);
405 }
406 spin_unlock_irqrestore(&qp->s_lock, flags);
407 /* Notify hfi1_destroy_qp() if it is waiting. */
408 rvt_put_qp(qp);
409}
410
411void hfi1_qp_unbusy(struct rvt_qp *qp, struct iowait_work *wait)
412{
413 struct hfi1_qp_priv *priv = qp->priv;
414
415 if (iowait_set_work_flag(wait) == IOWAIT_IB_SE) {
416 qp->s_flags &= ~RVT_S_BUSY;
417 /*
418 * If we are sending a first-leg packet from the second leg,
419 * we need to clear the busy flag from priv->s_flags to
420 * avoid a race condition when the qp wakes up before
421 * the call to hfi1_verbs_send() returns to the second
422 * leg. In that case, the second leg will terminate without
423 * being re-scheduled, resulting in failure to send TID RDMA
424 * WRITE DATA and TID RDMA ACK packets.
425 */
426 if (priv->s_flags & HFI1_S_TID_BUSY_SET) {
427 priv->s_flags &= ~(HFI1_S_TID_BUSY_SET |
428 RVT_S_BUSY);
429 iowait_set_flag(&priv->s_iowait, IOWAIT_PENDING_TID);
430 }
431 } else {
432 priv->s_flags &= ~RVT_S_BUSY;
433 }
434}
435
436static int iowait_sleep(
437 struct sdma_engine *sde,
438 struct iowait_work *wait,
439 struct sdma_txreq *stx,
440 uint seq,
441 bool pkts_sent)
442{
443 struct verbs_txreq *tx = container_of(stx, struct verbs_txreq, txreq);
444 struct rvt_qp *qp;
445 struct hfi1_qp_priv *priv;
446 unsigned long flags;
447 int ret = 0;
448
449 qp = tx->qp;
450 priv = qp->priv;
451
452 spin_lock_irqsave(&qp->s_lock, flags);
453 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
454 /*
455 * If we couldn't queue the DMA request, save the info
456 * and try again later rather than destroying the
457 * buffer and undoing the side effects of the copy.
458 */
459 /* Make a common routine? */
460 list_add_tail(&stx->list, &wait->tx_head);
461 write_seqlock(&sde->waitlock);
462 if (sdma_progress(sde, seq, stx))
463 goto eagain;
464 if (list_empty(&priv->s_iowait.list)) {
465 struct hfi1_ibport *ibp =
466 to_iport(qp->ibqp.device, qp->port_num);
467
468 ibp->rvp.n_dmawait++;
469 qp->s_flags |= RVT_S_WAIT_DMA_DESC;
470 iowait_get_priority(&priv->s_iowait);
471 iowait_queue(pkts_sent, &priv->s_iowait,
472 &sde->dmawait);
473 priv->s_iowait.lock = &sde->waitlock;
474 trace_hfi1_qpsleep(qp, RVT_S_WAIT_DMA_DESC);
475 rvt_get_qp(qp);
476 }
477 write_sequnlock(&sde->waitlock);
478 hfi1_qp_unbusy(qp, wait);
479 spin_unlock_irqrestore(&qp->s_lock, flags);
480 ret = -EBUSY;
481 } else {
482 spin_unlock_irqrestore(&qp->s_lock, flags);
483 hfi1_put_txreq(tx);
484 }
485 return ret;
486eagain:
487 write_sequnlock(&sde->waitlock);
488 spin_unlock_irqrestore(&qp->s_lock, flags);
489 list_del_init(&stx->list);
490 return -EAGAIN;
491}
492
493static void iowait_wakeup(struct iowait *wait, int reason)
494{
495 struct rvt_qp *qp = iowait_to_qp(wait);
496
497 WARN_ON(reason != SDMA_AVAIL_REASON);
498 hfi1_qp_wakeup(qp, RVT_S_WAIT_DMA_DESC);
499}
500
501static void iowait_sdma_drained(struct iowait *wait)
502{
503 struct rvt_qp *qp = iowait_to_qp(wait);
504 unsigned long flags;
505
506 /*
507 * This happens when the send engine notes
508 * a QP in the error state and cannot
509 * do the flush work until that QP's
510 * sdma work has finished.
511 */
512 spin_lock_irqsave(&qp->s_lock, flags);
513 if (qp->s_flags & RVT_S_WAIT_DMA) {
514 qp->s_flags &= ~RVT_S_WAIT_DMA;
515 hfi1_schedule_send(qp);
516 }
517 spin_unlock_irqrestore(&qp->s_lock, flags);
518}
519
520static void hfi1_init_priority(struct iowait *w)
521{
522 struct rvt_qp *qp = iowait_to_qp(w);
523 struct hfi1_qp_priv *priv = qp->priv;
524
525 if (qp->s_flags & RVT_S_ACK_PENDING)
526 w->priority++;
527 if (priv->s_flags & RVT_S_ACK_PENDING)
528 w->priority++;
529}
530
531/**
532 * qp_to_sdma_engine - map a qp to a send engine
533 * @qp: the QP
534 * @sc5: the 5 bit sc
535 *
536 * Return:
537 * A send engine for the qp or NULL for SMI type qp.
538 */
539struct sdma_engine *qp_to_sdma_engine(struct rvt_qp *qp, u8 sc5)
540{
541 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
542 struct sdma_engine *sde;
543
544 if (!(dd->flags & HFI1_HAS_SEND_DMA))
545 return NULL;
546 switch (qp->ibqp.qp_type) {
547 case IB_QPT_SMI:
548 return NULL;
549 default:
550 break;
551 }
552 sde = sdma_select_engine_sc(dd, qp->ibqp.qp_num >> dd->qos_shift, sc5);
553 return sde;
554}
555
556/**
557 * qp_to_send_context - map a qp to a send context
558 * @qp: the QP
559 * @sc5: the 5 bit sc
560 *
561 * Return:
562 * A send context for the qp
563 */
564struct send_context *qp_to_send_context(struct rvt_qp *qp, u8 sc5)
565{
566 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
567
568 switch (qp->ibqp.qp_type) {
569 case IB_QPT_SMI:
570 /* SMA packets to VL15 */
571 return dd->vld[15].sc;
572 default:
573 break;
574 }
575
576 return pio_select_send_context_sc(dd, qp->ibqp.qp_num >> dd->qos_shift,
577 sc5);
578}
579
580static const char * const qp_type_str[] = {
581 "SMI", "GSI", "RC", "UC", "UD",
582};
583
584static int qp_idle(struct rvt_qp *qp)
585{
586 return
587 qp->s_last == qp->s_acked &&
588 qp->s_acked == qp->s_cur &&
589 qp->s_cur == qp->s_tail &&
590 qp->s_tail == qp->s_head;
591}
592
593/**
594 * qp_iter_print - print the qp information to seq_file
595 * @s: the seq_file to emit the qp information on
596 * @iter: the iterator for the qp hash list
597 */
598void qp_iter_print(struct seq_file *s, struct rvt_qp_iter *iter)
599{
600 struct rvt_swqe *wqe;
601 struct rvt_qp *qp = iter->qp;
602 struct hfi1_qp_priv *priv = qp->priv;
603 struct sdma_engine *sde;
604 struct send_context *send_context;
605 struct rvt_ack_entry *e = NULL;
606 struct rvt_srq *srq = qp->ibqp.srq ?
607 ibsrq_to_rvtsrq(qp->ibqp.srq) : NULL;
608
609 sde = qp_to_sdma_engine(qp, priv->s_sc);
610 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
611 send_context = qp_to_send_context(qp, priv->s_sc);
612 if (qp->s_ack_queue)
613 e = &qp->s_ack_queue[qp->s_tail_ack_queue];
614 seq_printf(s,
615 "N %d %s QP %x R %u %s %u %u f=%x %u %u %u %u %u %u SPSN %x %x %x %x %x RPSN %x S(%u %u %u %u %u %u %u) R(%u %u %u) RQP %x LID %x SL %u MTU %u %u %u %u %u SDE %p,%u SC %p,%u SCQ %u %u PID %d OS %x %x E %x %x %x RNR %d %s %d\n",
616 iter->n,
617 qp_idle(qp) ? "I" : "B",
618 qp->ibqp.qp_num,
619 atomic_read(&qp->refcount),
620 qp_type_str[qp->ibqp.qp_type],
621 qp->state,
622 wqe ? wqe->wr.opcode : 0,
623 qp->s_flags,
624 iowait_sdma_pending(&priv->s_iowait),
625 iowait_pio_pending(&priv->s_iowait),
626 !list_empty(&priv->s_iowait.list),
627 qp->timeout,
628 wqe ? wqe->ssn : 0,
629 qp->s_lsn,
630 qp->s_last_psn,
631 qp->s_psn, qp->s_next_psn,
632 qp->s_sending_psn, qp->s_sending_hpsn,
633 qp->r_psn,
634 qp->s_last, qp->s_acked, qp->s_cur,
635 qp->s_tail, qp->s_head, qp->s_size,
636 qp->s_avail,
637 /* ack_queue ring pointers, size */
638 qp->s_tail_ack_queue, qp->r_head_ack_queue,
639 rvt_max_atomic(&to_idev(qp->ibqp.device)->rdi),
640 /* remote QP info */
641 qp->remote_qpn,
642 rdma_ah_get_dlid(&qp->remote_ah_attr),
643 rdma_ah_get_sl(&qp->remote_ah_attr),
644 qp->pmtu,
645 qp->s_retry,
646 qp->s_retry_cnt,
647 qp->s_rnr_retry_cnt,
648 qp->s_rnr_retry,
649 sde,
650 sde ? sde->this_idx : 0,
651 send_context,
652 send_context ? send_context->sw_index : 0,
653 ib_cq_head(qp->ibqp.send_cq),
654 ib_cq_tail(qp->ibqp.send_cq),
655 qp->pid,
656 qp->s_state,
657 qp->s_ack_state,
658 /* ack queue information */
659 e ? e->opcode : 0,
660 e ? e->psn : 0,
661 e ? e->lpsn : 0,
662 qp->r_min_rnr_timer,
663 srq ? "SRQ" : "RQ",
664 srq ? srq->rq.size : qp->r_rq.size
665 );
666}
667
668void *qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp)
669{
670 struct hfi1_qp_priv *priv;
671
672 priv = kzalloc_node(sizeof(*priv), GFP_KERNEL, rdi->dparms.node);
673 if (!priv)
674 return ERR_PTR(-ENOMEM);
675
676 priv->owner = qp;
677
678 priv->s_ahg = kzalloc_node(sizeof(*priv->s_ahg), GFP_KERNEL,
679 rdi->dparms.node);
680 if (!priv->s_ahg) {
681 kfree(priv);
682 return ERR_PTR(-ENOMEM);
683 }
684 iowait_init(
685 &priv->s_iowait,
686 1,
687 _hfi1_do_send,
688 _hfi1_do_tid_send,
689 iowait_sleep,
690 iowait_wakeup,
691 iowait_sdma_drained,
692 hfi1_init_priority);
693 /* Init to a value to start the running average correctly */
694 priv->s_running_pkt_size = piothreshold / 2;
695 return priv;
696}
697
698void qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp)
699{
700 struct hfi1_qp_priv *priv = qp->priv;
701
702 hfi1_qp_priv_tid_free(rdi, qp);
703 kfree(priv->s_ahg);
704 kfree(priv);
705}
706
707unsigned free_all_qps(struct rvt_dev_info *rdi)
708{
709 struct hfi1_ibdev *verbs_dev = container_of(rdi,
710 struct hfi1_ibdev,
711 rdi);
712 struct hfi1_devdata *dd = container_of(verbs_dev,
713 struct hfi1_devdata,
714 verbs_dev);
715 int n;
716 unsigned qp_inuse = 0;
717
718 for (n = 0; n < dd->num_pports; n++) {
719 struct hfi1_ibport *ibp = &dd->pport[n].ibport_data;
720
721 rcu_read_lock();
722 if (rcu_dereference(ibp->rvp.qp[0]))
723 qp_inuse++;
724 if (rcu_dereference(ibp->rvp.qp[1]))
725 qp_inuse++;
726 rcu_read_unlock();
727 }
728
729 return qp_inuse;
730}
731
732void flush_qp_waiters(struct rvt_qp *qp)
733{
734 lockdep_assert_held(&qp->s_lock);
735 flush_iowait(qp);
736 hfi1_tid_rdma_flush_wait(qp);
737}
738
739void stop_send_queue(struct rvt_qp *qp)
740{
741 struct hfi1_qp_priv *priv = qp->priv;
742
743 iowait_cancel_work(&priv->s_iowait);
744 if (cancel_work_sync(&priv->tid_rdma.trigger_work))
745 rvt_put_qp(qp);
746}
747
748void quiesce_qp(struct rvt_qp *qp)
749{
750 struct hfi1_qp_priv *priv = qp->priv;
751
752 hfi1_del_tid_reap_timer(qp);
753 hfi1_del_tid_retry_timer(qp);
754 iowait_sdma_drain(&priv->s_iowait);
755 qp_pio_drain(qp);
756 flush_tx_list(qp);
757}
758
759void notify_qp_reset(struct rvt_qp *qp)
760{
761 hfi1_qp_kern_exp_rcv_clear_all(qp);
762 qp->r_adefered = 0;
763 clear_ahg(qp);
764
765 /* Clear any OPFN state */
766 if (qp->ibqp.qp_type == IB_QPT_RC)
767 opfn_conn_error(qp);
768}
769
770/*
771 * Switch to alternate path.
772 * The QP s_lock should be held and interrupts disabled.
773 */
774void hfi1_migrate_qp(struct rvt_qp *qp)
775{
776 struct hfi1_qp_priv *priv = qp->priv;
777 struct ib_event ev;
778
779 qp->s_mig_state = IB_MIG_MIGRATED;
780 qp->remote_ah_attr = qp->alt_ah_attr;
781 qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr);
782 qp->s_pkey_index = qp->s_alt_pkey_index;
783 qp->s_flags |= HFI1_S_AHG_CLEAR;
784 priv->s_sc = ah_to_sc(qp->ibqp.device, &qp->remote_ah_attr);
785 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
786 qp_set_16b(qp);
787
788 ev.device = qp->ibqp.device;
789 ev.element.qp = &qp->ibqp;
790 ev.event = IB_EVENT_PATH_MIG;
791 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
792}
793
794int mtu_to_path_mtu(u32 mtu)
795{
796 return mtu_to_enum(mtu, OPA_MTU_8192);
797}
798
799u32 mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu)
800{
801 u32 mtu;
802 struct hfi1_ibdev *verbs_dev = container_of(rdi,
803 struct hfi1_ibdev,
804 rdi);
805 struct hfi1_devdata *dd = container_of(verbs_dev,
806 struct hfi1_devdata,
807 verbs_dev);
808 struct hfi1_ibport *ibp;
809 u8 sc, vl;
810
811 ibp = &dd->pport[qp->port_num - 1].ibport_data;
812 sc = ibp->sl_to_sc[rdma_ah_get_sl(&qp->remote_ah_attr)];
813 vl = sc_to_vlt(dd, sc);
814
815 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, pmtu);
816 if (vl < PER_VL_SEND_CONTEXTS)
817 mtu = min_t(u32, mtu, dd->vld[vl].mtu);
818 return mtu;
819}
820
821int get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
822 struct ib_qp_attr *attr)
823{
824 int mtu, pidx = qp->port_num - 1;
825 struct hfi1_ibdev *verbs_dev = container_of(rdi,
826 struct hfi1_ibdev,
827 rdi);
828 struct hfi1_devdata *dd = container_of(verbs_dev,
829 struct hfi1_devdata,
830 verbs_dev);
831 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, attr->path_mtu);
832 if (mtu == -1)
833 return -1; /* values less than 0 are error */
834
835 if (mtu > dd->pport[pidx].ibmtu)
836 return mtu_to_enum(dd->pport[pidx].ibmtu, IB_MTU_2048);
837 else
838 return attr->path_mtu;
839}
840
841void notify_error_qp(struct rvt_qp *qp)
842{
843 struct hfi1_qp_priv *priv = qp->priv;
844 seqlock_t *lock = priv->s_iowait.lock;
845
846 if (lock) {
847 write_seqlock(lock);
848 if (!list_empty(&priv->s_iowait.list) &&
849 !(qp->s_flags & RVT_S_BUSY) &&
850 !(priv->s_flags & RVT_S_BUSY)) {
851 qp->s_flags &= ~HFI1_S_ANY_WAIT_IO;
852 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_IB);
853 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_TID);
854 list_del_init(&priv->s_iowait.list);
855 priv->s_iowait.lock = NULL;
856 rvt_put_qp(qp);
857 }
858 write_sequnlock(lock);
859 }
860
861 if (!(qp->s_flags & RVT_S_BUSY) && !(priv->s_flags & RVT_S_BUSY)) {
862 qp->s_hdrwords = 0;
863 if (qp->s_rdma_mr) {
864 rvt_put_mr(qp->s_rdma_mr);
865 qp->s_rdma_mr = NULL;
866 }
867 flush_tx_list(qp);
868 }
869}
870
871/**
872 * hfi1_qp_iter_cb - callback for iterator
873 * @qp: the qp
874 * @v: the sl in low bits of v
875 *
876 * This is called from the iterator callback to work
877 * on an individual qp.
878 */
879static void hfi1_qp_iter_cb(struct rvt_qp *qp, u64 v)
880{
881 int lastwqe;
882 struct ib_event ev;
883 struct hfi1_ibport *ibp =
884 to_iport(qp->ibqp.device, qp->port_num);
885 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
886 u8 sl = (u8)v;
887
888 if (qp->port_num != ppd->port ||
889 (qp->ibqp.qp_type != IB_QPT_UC &&
890 qp->ibqp.qp_type != IB_QPT_RC) ||
891 rdma_ah_get_sl(&qp->remote_ah_attr) != sl ||
892 !(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))
893 return;
894
895 spin_lock_irq(&qp->r_lock);
896 spin_lock(&qp->s_hlock);
897 spin_lock(&qp->s_lock);
898 lastwqe = rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
899 spin_unlock(&qp->s_lock);
900 spin_unlock(&qp->s_hlock);
901 spin_unlock_irq(&qp->r_lock);
902 if (lastwqe) {
903 ev.device = qp->ibqp.device;
904 ev.element.qp = &qp->ibqp;
905 ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
906 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
907 }
908}
909
910/**
911 * hfi1_error_port_qps - put a port's RC/UC qps into error state
912 * @ibp: the ibport.
913 * @sl: the service level.
914 *
915 * This function places all RC/UC qps with a given service level into error
916 * state. It is generally called to force upper lay apps to abandon stale qps
917 * after an sl->sc mapping change.
918 */
919void hfi1_error_port_qps(struct hfi1_ibport *ibp, u8 sl)
920{
921 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
922 struct hfi1_ibdev *dev = &ppd->dd->verbs_dev;
923
924 rvt_qp_iter(&dev->rdi, sl, hfi1_qp_iter_cb);
925}
1/*
2 * Copyright(c) 2015 - 2019 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
48#include <linux/err.h>
49#include <linux/vmalloc.h>
50#include <linux/hash.h>
51#include <linux/module.h>
52#include <linux/seq_file.h>
53#include <rdma/rdma_vt.h>
54#include <rdma/rdmavt_qp.h>
55#include <rdma/ib_verbs.h>
56
57#include "hfi.h"
58#include "qp.h"
59#include "trace.h"
60#include "verbs_txreq.h"
61
62unsigned int hfi1_qp_table_size = 256;
63module_param_named(qp_table_size, hfi1_qp_table_size, uint, S_IRUGO);
64MODULE_PARM_DESC(qp_table_size, "QP table size");
65
66static void flush_tx_list(struct rvt_qp *qp);
67static int iowait_sleep(
68 struct sdma_engine *sde,
69 struct iowait_work *wait,
70 struct sdma_txreq *stx,
71 unsigned int seq,
72 bool pkts_sent);
73static void iowait_wakeup(struct iowait *wait, int reason);
74static void iowait_sdma_drained(struct iowait *wait);
75static void qp_pio_drain(struct rvt_qp *qp);
76
77const struct rvt_operation_params hfi1_post_parms[RVT_OPERATION_MAX] = {
78[IB_WR_RDMA_WRITE] = {
79 .length = sizeof(struct ib_rdma_wr),
80 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
81},
82
83[IB_WR_RDMA_READ] = {
84 .length = sizeof(struct ib_rdma_wr),
85 .qpt_support = BIT(IB_QPT_RC),
86 .flags = RVT_OPERATION_ATOMIC,
87},
88
89[IB_WR_ATOMIC_CMP_AND_SWP] = {
90 .length = sizeof(struct ib_atomic_wr),
91 .qpt_support = BIT(IB_QPT_RC),
92 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
93},
94
95[IB_WR_ATOMIC_FETCH_AND_ADD] = {
96 .length = sizeof(struct ib_atomic_wr),
97 .qpt_support = BIT(IB_QPT_RC),
98 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
99},
100
101[IB_WR_RDMA_WRITE_WITH_IMM] = {
102 .length = sizeof(struct ib_rdma_wr),
103 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
104},
105
106[IB_WR_SEND] = {
107 .length = sizeof(struct ib_send_wr),
108 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
109 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
110},
111
112[IB_WR_SEND_WITH_IMM] = {
113 .length = sizeof(struct ib_send_wr),
114 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
115 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
116},
117
118[IB_WR_REG_MR] = {
119 .length = sizeof(struct ib_reg_wr),
120 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
121 .flags = RVT_OPERATION_LOCAL,
122},
123
124[IB_WR_LOCAL_INV] = {
125 .length = sizeof(struct ib_send_wr),
126 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
127 .flags = RVT_OPERATION_LOCAL,
128},
129
130[IB_WR_SEND_WITH_INV] = {
131 .length = sizeof(struct ib_send_wr),
132 .qpt_support = BIT(IB_QPT_RC),
133},
134
135[IB_WR_OPFN] = {
136 .length = sizeof(struct ib_atomic_wr),
137 .qpt_support = BIT(IB_QPT_RC),
138 .flags = RVT_OPERATION_USE_RESERVE,
139},
140
141[IB_WR_TID_RDMA_WRITE] = {
142 .length = sizeof(struct ib_rdma_wr),
143 .qpt_support = BIT(IB_QPT_RC),
144 .flags = RVT_OPERATION_IGN_RNR_CNT,
145},
146
147};
148
149static void flush_list_head(struct list_head *l)
150{
151 while (!list_empty(l)) {
152 struct sdma_txreq *tx;
153
154 tx = list_first_entry(
155 l,
156 struct sdma_txreq,
157 list);
158 list_del_init(&tx->list);
159 hfi1_put_txreq(
160 container_of(tx, struct verbs_txreq, txreq));
161 }
162}
163
164static void flush_tx_list(struct rvt_qp *qp)
165{
166 struct hfi1_qp_priv *priv = qp->priv;
167
168 flush_list_head(&iowait_get_ib_work(&priv->s_iowait)->tx_head);
169 flush_list_head(&iowait_get_tid_work(&priv->s_iowait)->tx_head);
170}
171
172static void flush_iowait(struct rvt_qp *qp)
173{
174 struct hfi1_qp_priv *priv = qp->priv;
175 unsigned long flags;
176 seqlock_t *lock = priv->s_iowait.lock;
177
178 if (!lock)
179 return;
180 write_seqlock_irqsave(lock, flags);
181 if (!list_empty(&priv->s_iowait.list)) {
182 list_del_init(&priv->s_iowait.list);
183 priv->s_iowait.lock = NULL;
184 rvt_put_qp(qp);
185 }
186 write_sequnlock_irqrestore(lock, flags);
187}
188
189static inline int opa_mtu_enum_to_int(int mtu)
190{
191 switch (mtu) {
192 case OPA_MTU_8192: return 8192;
193 case OPA_MTU_10240: return 10240;
194 default: return -1;
195 }
196}
197
198/**
199 * This function is what we would push to the core layer if we wanted to be a
200 * "first class citizen". Instead we hide this here and rely on Verbs ULPs
201 * to blindly pass the MTU enum value from the PathRecord to us.
202 */
203static inline int verbs_mtu_enum_to_int(struct ib_device *dev, enum ib_mtu mtu)
204{
205 int val;
206
207 /* Constraining 10KB packets to 8KB packets */
208 if (mtu == (enum ib_mtu)OPA_MTU_10240)
209 mtu = OPA_MTU_8192;
210 val = opa_mtu_enum_to_int((int)mtu);
211 if (val > 0)
212 return val;
213 return ib_mtu_enum_to_int(mtu);
214}
215
216int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
217 int attr_mask, struct ib_udata *udata)
218{
219 struct ib_qp *ibqp = &qp->ibqp;
220 struct hfi1_ibdev *dev = to_idev(ibqp->device);
221 struct hfi1_devdata *dd = dd_from_dev(dev);
222 u8 sc;
223
224 if (attr_mask & IB_QP_AV) {
225 sc = ah_to_sc(ibqp->device, &attr->ah_attr);
226 if (sc == 0xf)
227 return -EINVAL;
228
229 if (!qp_to_sdma_engine(qp, sc) &&
230 dd->flags & HFI1_HAS_SEND_DMA)
231 return -EINVAL;
232
233 if (!qp_to_send_context(qp, sc))
234 return -EINVAL;
235 }
236
237 if (attr_mask & IB_QP_ALT_PATH) {
238 sc = ah_to_sc(ibqp->device, &attr->alt_ah_attr);
239 if (sc == 0xf)
240 return -EINVAL;
241
242 if (!qp_to_sdma_engine(qp, sc) &&
243 dd->flags & HFI1_HAS_SEND_DMA)
244 return -EINVAL;
245
246 if (!qp_to_send_context(qp, sc))
247 return -EINVAL;
248 }
249
250 return 0;
251}
252
253/*
254 * qp_set_16b - Set the hdr_type based on whether the slid or the
255 * dlid in the connection is extended. Only applicable for RC and UC
256 * QPs. UD QPs determine this on the fly from the ah in the wqe
257 */
258static inline void qp_set_16b(struct rvt_qp *qp)
259{
260 struct hfi1_pportdata *ppd;
261 struct hfi1_ibport *ibp;
262 struct hfi1_qp_priv *priv = qp->priv;
263
264 /* Update ah_attr to account for extended LIDs */
265 hfi1_update_ah_attr(qp->ibqp.device, &qp->remote_ah_attr);
266
267 /* Create 32 bit LIDs */
268 hfi1_make_opa_lid(&qp->remote_ah_attr);
269
270 if (!(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH))
271 return;
272
273 ibp = to_iport(qp->ibqp.device, qp->port_num);
274 ppd = ppd_from_ibp(ibp);
275 priv->hdr_type = hfi1_get_hdr_type(ppd->lid, &qp->remote_ah_attr);
276}
277
278void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
279 int attr_mask, struct ib_udata *udata)
280{
281 struct ib_qp *ibqp = &qp->ibqp;
282 struct hfi1_qp_priv *priv = qp->priv;
283
284 if (attr_mask & IB_QP_AV) {
285 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
286 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
287 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
288 qp_set_16b(qp);
289 }
290
291 if (attr_mask & IB_QP_PATH_MIG_STATE &&
292 attr->path_mig_state == IB_MIG_MIGRATED &&
293 qp->s_mig_state == IB_MIG_ARMED) {
294 qp->s_flags |= HFI1_S_AHG_CLEAR;
295 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
296 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
297 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
298 qp_set_16b(qp);
299 }
300
301 opfn_qp_init(qp, attr, attr_mask);
302}
303
304/**
305 * hfi1_setup_wqe - set up the wqe
306 * @qp - The qp
307 * @wqe - The built wqe
308 * @call_send - Determine if the send should be posted or scheduled.
309 *
310 * Perform setup of the wqe. This is called
311 * prior to inserting the wqe into the ring but after
312 * the wqe has been setup by RDMAVT. This function
313 * allows the driver the opportunity to perform
314 * validation and additional setup of the wqe.
315 *
316 * Returns 0 on success, -EINVAL on failure
317 *
318 */
319int hfi1_setup_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe, bool *call_send)
320{
321 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
322 struct rvt_ah *ah;
323 struct hfi1_pportdata *ppd;
324 struct hfi1_devdata *dd;
325
326 switch (qp->ibqp.qp_type) {
327 case IB_QPT_RC:
328 hfi1_setup_tid_rdma_wqe(qp, wqe);
329 /* fall through */
330 case IB_QPT_UC:
331 if (wqe->length > 0x80000000U)
332 return -EINVAL;
333 if (wqe->length > qp->pmtu)
334 *call_send = false;
335 break;
336 case IB_QPT_SMI:
337 /*
338 * SM packets should exclusively use VL15 and their SL is
339 * ignored (IBTA v1.3, Section 3.5.8.2). Therefore, when ah
340 * is created, SL is 0 in most cases and as a result some
341 * fields (vl and pmtu) in ah may not be set correctly,
342 * depending on the SL2SC and SC2VL tables at the time.
343 */
344 ppd = ppd_from_ibp(ibp);
345 dd = dd_from_ppd(ppd);
346 if (wqe->length > dd->vld[15].mtu)
347 return -EINVAL;
348 break;
349 case IB_QPT_GSI:
350 case IB_QPT_UD:
351 ah = rvt_get_swqe_ah(wqe);
352 if (wqe->length > (1 << ah->log_pmtu))
353 return -EINVAL;
354 if (ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)] == 0xf)
355 return -EINVAL;
356 default:
357 break;
358 }
359
360 /*
361 * System latency between send and schedule is large enough that
362 * forcing call_send to true for piothreshold packets is necessary.
363 */
364 if (wqe->length <= piothreshold)
365 *call_send = true;
366 return 0;
367}
368
369/**
370 * _hfi1_schedule_send - schedule progress
371 * @qp: the QP
372 *
373 * This schedules qp progress w/o regard to the s_flags.
374 *
375 * It is only used in the post send, which doesn't hold
376 * the s_lock.
377 */
378bool _hfi1_schedule_send(struct rvt_qp *qp)
379{
380 struct hfi1_qp_priv *priv = qp->priv;
381 struct hfi1_ibport *ibp =
382 to_iport(qp->ibqp.device, qp->port_num);
383 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
384 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
385
386 return iowait_schedule(&priv->s_iowait, ppd->hfi1_wq,
387 priv->s_sde ?
388 priv->s_sde->cpu :
389 cpumask_first(cpumask_of_node(dd->node)));
390}
391
392static void qp_pio_drain(struct rvt_qp *qp)
393{
394 struct hfi1_qp_priv *priv = qp->priv;
395
396 if (!priv->s_sendcontext)
397 return;
398 while (iowait_pio_pending(&priv->s_iowait)) {
399 write_seqlock_irq(&priv->s_sendcontext->waitlock);
400 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 1);
401 write_sequnlock_irq(&priv->s_sendcontext->waitlock);
402 iowait_pio_drain(&priv->s_iowait);
403 write_seqlock_irq(&priv->s_sendcontext->waitlock);
404 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 0);
405 write_sequnlock_irq(&priv->s_sendcontext->waitlock);
406 }
407}
408
409/**
410 * hfi1_schedule_send - schedule progress
411 * @qp: the QP
412 *
413 * This schedules qp progress and caller should hold
414 * the s_lock.
415 * @return true if the first leg is scheduled;
416 * false if the first leg is not scheduled.
417 */
418bool hfi1_schedule_send(struct rvt_qp *qp)
419{
420 lockdep_assert_held(&qp->s_lock);
421 if (hfi1_send_ok(qp)) {
422 _hfi1_schedule_send(qp);
423 return true;
424 }
425 if (qp->s_flags & HFI1_S_ANY_WAIT_IO)
426 iowait_set_flag(&((struct hfi1_qp_priv *)qp->priv)->s_iowait,
427 IOWAIT_PENDING_IB);
428 return false;
429}
430
431static void hfi1_qp_schedule(struct rvt_qp *qp)
432{
433 struct hfi1_qp_priv *priv = qp->priv;
434 bool ret;
435
436 if (iowait_flag_set(&priv->s_iowait, IOWAIT_PENDING_IB)) {
437 ret = hfi1_schedule_send(qp);
438 if (ret)
439 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_IB);
440 }
441 if (iowait_flag_set(&priv->s_iowait, IOWAIT_PENDING_TID)) {
442 ret = hfi1_schedule_tid_send(qp);
443 if (ret)
444 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_TID);
445 }
446}
447
448void hfi1_qp_wakeup(struct rvt_qp *qp, u32 flag)
449{
450 unsigned long flags;
451
452 spin_lock_irqsave(&qp->s_lock, flags);
453 if (qp->s_flags & flag) {
454 qp->s_flags &= ~flag;
455 trace_hfi1_qpwakeup(qp, flag);
456 hfi1_qp_schedule(qp);
457 }
458 spin_unlock_irqrestore(&qp->s_lock, flags);
459 /* Notify hfi1_destroy_qp() if it is waiting. */
460 rvt_put_qp(qp);
461}
462
463void hfi1_qp_unbusy(struct rvt_qp *qp, struct iowait_work *wait)
464{
465 struct hfi1_qp_priv *priv = qp->priv;
466
467 if (iowait_set_work_flag(wait) == IOWAIT_IB_SE) {
468 qp->s_flags &= ~RVT_S_BUSY;
469 /*
470 * If we are sending a first-leg packet from the second leg,
471 * we need to clear the busy flag from priv->s_flags to
472 * avoid a race condition when the qp wakes up before
473 * the call to hfi1_verbs_send() returns to the second
474 * leg. In that case, the second leg will terminate without
475 * being re-scheduled, resulting in failure to send TID RDMA
476 * WRITE DATA and TID RDMA ACK packets.
477 */
478 if (priv->s_flags & HFI1_S_TID_BUSY_SET) {
479 priv->s_flags &= ~(HFI1_S_TID_BUSY_SET |
480 RVT_S_BUSY);
481 iowait_set_flag(&priv->s_iowait, IOWAIT_PENDING_TID);
482 }
483 } else {
484 priv->s_flags &= ~RVT_S_BUSY;
485 }
486}
487
488static int iowait_sleep(
489 struct sdma_engine *sde,
490 struct iowait_work *wait,
491 struct sdma_txreq *stx,
492 uint seq,
493 bool pkts_sent)
494{
495 struct verbs_txreq *tx = container_of(stx, struct verbs_txreq, txreq);
496 struct rvt_qp *qp;
497 struct hfi1_qp_priv *priv;
498 unsigned long flags;
499 int ret = 0;
500
501 qp = tx->qp;
502 priv = qp->priv;
503
504 spin_lock_irqsave(&qp->s_lock, flags);
505 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
506 /*
507 * If we couldn't queue the DMA request, save the info
508 * and try again later rather than destroying the
509 * buffer and undoing the side effects of the copy.
510 */
511 /* Make a common routine? */
512 list_add_tail(&stx->list, &wait->tx_head);
513 write_seqlock(&sde->waitlock);
514 if (sdma_progress(sde, seq, stx))
515 goto eagain;
516 if (list_empty(&priv->s_iowait.list)) {
517 struct hfi1_ibport *ibp =
518 to_iport(qp->ibqp.device, qp->port_num);
519
520 ibp->rvp.n_dmawait++;
521 qp->s_flags |= RVT_S_WAIT_DMA_DESC;
522 iowait_get_priority(&priv->s_iowait);
523 iowait_queue(pkts_sent, &priv->s_iowait,
524 &sde->dmawait);
525 priv->s_iowait.lock = &sde->waitlock;
526 trace_hfi1_qpsleep(qp, RVT_S_WAIT_DMA_DESC);
527 rvt_get_qp(qp);
528 }
529 write_sequnlock(&sde->waitlock);
530 hfi1_qp_unbusy(qp, wait);
531 spin_unlock_irqrestore(&qp->s_lock, flags);
532 ret = -EBUSY;
533 } else {
534 spin_unlock_irqrestore(&qp->s_lock, flags);
535 hfi1_put_txreq(tx);
536 }
537 return ret;
538eagain:
539 write_sequnlock(&sde->waitlock);
540 spin_unlock_irqrestore(&qp->s_lock, flags);
541 list_del_init(&stx->list);
542 return -EAGAIN;
543}
544
545static void iowait_wakeup(struct iowait *wait, int reason)
546{
547 struct rvt_qp *qp = iowait_to_qp(wait);
548
549 WARN_ON(reason != SDMA_AVAIL_REASON);
550 hfi1_qp_wakeup(qp, RVT_S_WAIT_DMA_DESC);
551}
552
553static void iowait_sdma_drained(struct iowait *wait)
554{
555 struct rvt_qp *qp = iowait_to_qp(wait);
556 unsigned long flags;
557
558 /*
559 * This happens when the send engine notes
560 * a QP in the error state and cannot
561 * do the flush work until that QP's
562 * sdma work has finished.
563 */
564 spin_lock_irqsave(&qp->s_lock, flags);
565 if (qp->s_flags & RVT_S_WAIT_DMA) {
566 qp->s_flags &= ~RVT_S_WAIT_DMA;
567 hfi1_schedule_send(qp);
568 }
569 spin_unlock_irqrestore(&qp->s_lock, flags);
570}
571
572static void hfi1_init_priority(struct iowait *w)
573{
574 struct rvt_qp *qp = iowait_to_qp(w);
575 struct hfi1_qp_priv *priv = qp->priv;
576
577 if (qp->s_flags & RVT_S_ACK_PENDING)
578 w->priority++;
579 if (priv->s_flags & RVT_S_ACK_PENDING)
580 w->priority++;
581}
582
583/**
584 * qp_to_sdma_engine - map a qp to a send engine
585 * @qp: the QP
586 * @sc5: the 5 bit sc
587 *
588 * Return:
589 * A send engine for the qp or NULL for SMI type qp.
590 */
591struct sdma_engine *qp_to_sdma_engine(struct rvt_qp *qp, u8 sc5)
592{
593 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
594 struct sdma_engine *sde;
595
596 if (!(dd->flags & HFI1_HAS_SEND_DMA))
597 return NULL;
598 switch (qp->ibqp.qp_type) {
599 case IB_QPT_SMI:
600 return NULL;
601 default:
602 break;
603 }
604 sde = sdma_select_engine_sc(dd, qp->ibqp.qp_num >> dd->qos_shift, sc5);
605 return sde;
606}
607
608/*
609 * qp_to_send_context - map a qp to a send context
610 * @qp: the QP
611 * @sc5: the 5 bit sc
612 *
613 * Return:
614 * A send context for the qp
615 */
616struct send_context *qp_to_send_context(struct rvt_qp *qp, u8 sc5)
617{
618 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
619
620 switch (qp->ibqp.qp_type) {
621 case IB_QPT_SMI:
622 /* SMA packets to VL15 */
623 return dd->vld[15].sc;
624 default:
625 break;
626 }
627
628 return pio_select_send_context_sc(dd, qp->ibqp.qp_num >> dd->qos_shift,
629 sc5);
630}
631
632static const char * const qp_type_str[] = {
633 "SMI", "GSI", "RC", "UC", "UD",
634};
635
636static int qp_idle(struct rvt_qp *qp)
637{
638 return
639 qp->s_last == qp->s_acked &&
640 qp->s_acked == qp->s_cur &&
641 qp->s_cur == qp->s_tail &&
642 qp->s_tail == qp->s_head;
643}
644
645/**
646 * qp_iter_print - print the qp information to seq_file
647 * @s: the seq_file to emit the qp information on
648 * @iter: the iterator for the qp hash list
649 */
650void qp_iter_print(struct seq_file *s, struct rvt_qp_iter *iter)
651{
652 struct rvt_swqe *wqe;
653 struct rvt_qp *qp = iter->qp;
654 struct hfi1_qp_priv *priv = qp->priv;
655 struct sdma_engine *sde;
656 struct send_context *send_context;
657 struct rvt_ack_entry *e = NULL;
658 struct rvt_srq *srq = qp->ibqp.srq ?
659 ibsrq_to_rvtsrq(qp->ibqp.srq) : NULL;
660
661 sde = qp_to_sdma_engine(qp, priv->s_sc);
662 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
663 send_context = qp_to_send_context(qp, priv->s_sc);
664 if (qp->s_ack_queue)
665 e = &qp->s_ack_queue[qp->s_tail_ack_queue];
666 seq_printf(s,
667 "N %d %s QP %x R %u %s %u %u f=%x %u %u %u %u %u %u SPSN %x %x %x %x %x RPSN %x S(%u %u %u %u %u %u %u) R(%u %u %u) RQP %x LID %x SL %u MTU %u %u %u %u %u SDE %p,%u SC %p,%u SCQ %u %u PID %d OS %x %x E %x %x %x RNR %d %s %d\n",
668 iter->n,
669 qp_idle(qp) ? "I" : "B",
670 qp->ibqp.qp_num,
671 atomic_read(&qp->refcount),
672 qp_type_str[qp->ibqp.qp_type],
673 qp->state,
674 wqe ? wqe->wr.opcode : 0,
675 qp->s_flags,
676 iowait_sdma_pending(&priv->s_iowait),
677 iowait_pio_pending(&priv->s_iowait),
678 !list_empty(&priv->s_iowait.list),
679 qp->timeout,
680 wqe ? wqe->ssn : 0,
681 qp->s_lsn,
682 qp->s_last_psn,
683 qp->s_psn, qp->s_next_psn,
684 qp->s_sending_psn, qp->s_sending_hpsn,
685 qp->r_psn,
686 qp->s_last, qp->s_acked, qp->s_cur,
687 qp->s_tail, qp->s_head, qp->s_size,
688 qp->s_avail,
689 /* ack_queue ring pointers, size */
690 qp->s_tail_ack_queue, qp->r_head_ack_queue,
691 rvt_max_atomic(&to_idev(qp->ibqp.device)->rdi),
692 /* remote QP info */
693 qp->remote_qpn,
694 rdma_ah_get_dlid(&qp->remote_ah_attr),
695 rdma_ah_get_sl(&qp->remote_ah_attr),
696 qp->pmtu,
697 qp->s_retry,
698 qp->s_retry_cnt,
699 qp->s_rnr_retry_cnt,
700 qp->s_rnr_retry,
701 sde,
702 sde ? sde->this_idx : 0,
703 send_context,
704 send_context ? send_context->sw_index : 0,
705 ib_cq_head(qp->ibqp.send_cq),
706 ib_cq_tail(qp->ibqp.send_cq),
707 qp->pid,
708 qp->s_state,
709 qp->s_ack_state,
710 /* ack queue information */
711 e ? e->opcode : 0,
712 e ? e->psn : 0,
713 e ? e->lpsn : 0,
714 qp->r_min_rnr_timer,
715 srq ? "SRQ" : "RQ",
716 srq ? srq->rq.size : qp->r_rq.size
717 );
718}
719
720void *qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp)
721{
722 struct hfi1_qp_priv *priv;
723
724 priv = kzalloc_node(sizeof(*priv), GFP_KERNEL, rdi->dparms.node);
725 if (!priv)
726 return ERR_PTR(-ENOMEM);
727
728 priv->owner = qp;
729
730 priv->s_ahg = kzalloc_node(sizeof(*priv->s_ahg), GFP_KERNEL,
731 rdi->dparms.node);
732 if (!priv->s_ahg) {
733 kfree(priv);
734 return ERR_PTR(-ENOMEM);
735 }
736 iowait_init(
737 &priv->s_iowait,
738 1,
739 _hfi1_do_send,
740 _hfi1_do_tid_send,
741 iowait_sleep,
742 iowait_wakeup,
743 iowait_sdma_drained,
744 hfi1_init_priority);
745 /* Init to a value to start the running average correctly */
746 priv->s_running_pkt_size = piothreshold / 2;
747 return priv;
748}
749
750void qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp)
751{
752 struct hfi1_qp_priv *priv = qp->priv;
753
754 hfi1_qp_priv_tid_free(rdi, qp);
755 kfree(priv->s_ahg);
756 kfree(priv);
757}
758
759unsigned free_all_qps(struct rvt_dev_info *rdi)
760{
761 struct hfi1_ibdev *verbs_dev = container_of(rdi,
762 struct hfi1_ibdev,
763 rdi);
764 struct hfi1_devdata *dd = container_of(verbs_dev,
765 struct hfi1_devdata,
766 verbs_dev);
767 int n;
768 unsigned qp_inuse = 0;
769
770 for (n = 0; n < dd->num_pports; n++) {
771 struct hfi1_ibport *ibp = &dd->pport[n].ibport_data;
772
773 rcu_read_lock();
774 if (rcu_dereference(ibp->rvp.qp[0]))
775 qp_inuse++;
776 if (rcu_dereference(ibp->rvp.qp[1]))
777 qp_inuse++;
778 rcu_read_unlock();
779 }
780
781 return qp_inuse;
782}
783
784void flush_qp_waiters(struct rvt_qp *qp)
785{
786 lockdep_assert_held(&qp->s_lock);
787 flush_iowait(qp);
788 hfi1_tid_rdma_flush_wait(qp);
789}
790
791void stop_send_queue(struct rvt_qp *qp)
792{
793 struct hfi1_qp_priv *priv = qp->priv;
794
795 iowait_cancel_work(&priv->s_iowait);
796 if (cancel_work_sync(&priv->tid_rdma.trigger_work))
797 rvt_put_qp(qp);
798}
799
800void quiesce_qp(struct rvt_qp *qp)
801{
802 struct hfi1_qp_priv *priv = qp->priv;
803
804 hfi1_del_tid_reap_timer(qp);
805 hfi1_del_tid_retry_timer(qp);
806 iowait_sdma_drain(&priv->s_iowait);
807 qp_pio_drain(qp);
808 flush_tx_list(qp);
809}
810
811void notify_qp_reset(struct rvt_qp *qp)
812{
813 hfi1_qp_kern_exp_rcv_clear_all(qp);
814 qp->r_adefered = 0;
815 clear_ahg(qp);
816
817 /* Clear any OPFN state */
818 if (qp->ibqp.qp_type == IB_QPT_RC)
819 opfn_conn_error(qp);
820}
821
822/*
823 * Switch to alternate path.
824 * The QP s_lock should be held and interrupts disabled.
825 */
826void hfi1_migrate_qp(struct rvt_qp *qp)
827{
828 struct hfi1_qp_priv *priv = qp->priv;
829 struct ib_event ev;
830
831 qp->s_mig_state = IB_MIG_MIGRATED;
832 qp->remote_ah_attr = qp->alt_ah_attr;
833 qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr);
834 qp->s_pkey_index = qp->s_alt_pkey_index;
835 qp->s_flags |= HFI1_S_AHG_CLEAR;
836 priv->s_sc = ah_to_sc(qp->ibqp.device, &qp->remote_ah_attr);
837 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
838 qp_set_16b(qp);
839
840 ev.device = qp->ibqp.device;
841 ev.element.qp = &qp->ibqp;
842 ev.event = IB_EVENT_PATH_MIG;
843 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
844}
845
846int mtu_to_path_mtu(u32 mtu)
847{
848 return mtu_to_enum(mtu, OPA_MTU_8192);
849}
850
851u32 mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu)
852{
853 u32 mtu;
854 struct hfi1_ibdev *verbs_dev = container_of(rdi,
855 struct hfi1_ibdev,
856 rdi);
857 struct hfi1_devdata *dd = container_of(verbs_dev,
858 struct hfi1_devdata,
859 verbs_dev);
860 struct hfi1_ibport *ibp;
861 u8 sc, vl;
862
863 ibp = &dd->pport[qp->port_num - 1].ibport_data;
864 sc = ibp->sl_to_sc[rdma_ah_get_sl(&qp->remote_ah_attr)];
865 vl = sc_to_vlt(dd, sc);
866
867 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, pmtu);
868 if (vl < PER_VL_SEND_CONTEXTS)
869 mtu = min_t(u32, mtu, dd->vld[vl].mtu);
870 return mtu;
871}
872
873int get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
874 struct ib_qp_attr *attr)
875{
876 int mtu, pidx = qp->port_num - 1;
877 struct hfi1_ibdev *verbs_dev = container_of(rdi,
878 struct hfi1_ibdev,
879 rdi);
880 struct hfi1_devdata *dd = container_of(verbs_dev,
881 struct hfi1_devdata,
882 verbs_dev);
883 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, attr->path_mtu);
884 if (mtu == -1)
885 return -1; /* values less than 0 are error */
886
887 if (mtu > dd->pport[pidx].ibmtu)
888 return mtu_to_enum(dd->pport[pidx].ibmtu, IB_MTU_2048);
889 else
890 return attr->path_mtu;
891}
892
893void notify_error_qp(struct rvt_qp *qp)
894{
895 struct hfi1_qp_priv *priv = qp->priv;
896 seqlock_t *lock = priv->s_iowait.lock;
897
898 if (lock) {
899 write_seqlock(lock);
900 if (!list_empty(&priv->s_iowait.list) &&
901 !(qp->s_flags & RVT_S_BUSY) &&
902 !(priv->s_flags & RVT_S_BUSY)) {
903 qp->s_flags &= ~HFI1_S_ANY_WAIT_IO;
904 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_IB);
905 iowait_clear_flag(&priv->s_iowait, IOWAIT_PENDING_TID);
906 list_del_init(&priv->s_iowait.list);
907 priv->s_iowait.lock = NULL;
908 rvt_put_qp(qp);
909 }
910 write_sequnlock(lock);
911 }
912
913 if (!(qp->s_flags & RVT_S_BUSY) && !(priv->s_flags & RVT_S_BUSY)) {
914 qp->s_hdrwords = 0;
915 if (qp->s_rdma_mr) {
916 rvt_put_mr(qp->s_rdma_mr);
917 qp->s_rdma_mr = NULL;
918 }
919 flush_tx_list(qp);
920 }
921}
922
923/**
924 * hfi1_qp_iter_cb - callback for iterator
925 * @qp - the qp
926 * @v - the sl in low bits of v
927 *
928 * This is called from the iterator callback to work
929 * on an individual qp.
930 */
931static void hfi1_qp_iter_cb(struct rvt_qp *qp, u64 v)
932{
933 int lastwqe;
934 struct ib_event ev;
935 struct hfi1_ibport *ibp =
936 to_iport(qp->ibqp.device, qp->port_num);
937 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
938 u8 sl = (u8)v;
939
940 if (qp->port_num != ppd->port ||
941 (qp->ibqp.qp_type != IB_QPT_UC &&
942 qp->ibqp.qp_type != IB_QPT_RC) ||
943 rdma_ah_get_sl(&qp->remote_ah_attr) != sl ||
944 !(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))
945 return;
946
947 spin_lock_irq(&qp->r_lock);
948 spin_lock(&qp->s_hlock);
949 spin_lock(&qp->s_lock);
950 lastwqe = rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
951 spin_unlock(&qp->s_lock);
952 spin_unlock(&qp->s_hlock);
953 spin_unlock_irq(&qp->r_lock);
954 if (lastwqe) {
955 ev.device = qp->ibqp.device;
956 ev.element.qp = &qp->ibqp;
957 ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
958 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
959 }
960}
961
962/**
963 * hfi1_error_port_qps - put a port's RC/UC qps into error state
964 * @ibp: the ibport.
965 * @sl: the service level.
966 *
967 * This function places all RC/UC qps with a given service level into error
968 * state. It is generally called to force upper lay apps to abandon stale qps
969 * after an sl->sc mapping change.
970 */
971void hfi1_error_port_qps(struct hfi1_ibport *ibp, u8 sl)
972{
973 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
974 struct hfi1_ibdev *dev = &ppd->dd->verbs_dev;
975
976 rvt_qp_iter(&dev->rdi, sl, hfi1_qp_iter_cb);
977}