1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 *wait,
70 struct sdma_txreq *stx,
71 unsigned seq);
72static void iowait_wakeup(struct iowait *wait, int reason);
73static void iowait_sdma_drained(struct iowait *wait);
74static void qp_pio_drain(struct rvt_qp *qp);
75
76static inline unsigned mk_qpn(struct rvt_qpn_table *qpt,
77 struct rvt_qpn_map *map, unsigned off)
78{
79 return (map - qpt->map) * RVT_BITS_PER_PAGE + off;
80}
81
82const struct rvt_operation_params hfi1_post_parms[RVT_OPERATION_MAX] = {
83[IB_WR_RDMA_WRITE] = {
84 .length = sizeof(struct ib_rdma_wr),
85 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
86},
87
88[IB_WR_RDMA_READ] = {
89 .length = sizeof(struct ib_rdma_wr),
90 .qpt_support = BIT(IB_QPT_RC),
91 .flags = RVT_OPERATION_ATOMIC,
92},
93
94[IB_WR_ATOMIC_CMP_AND_SWP] = {
95 .length = sizeof(struct ib_atomic_wr),
96 .qpt_support = BIT(IB_QPT_RC),
97 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
98},
99
100[IB_WR_ATOMIC_FETCH_AND_ADD] = {
101 .length = sizeof(struct ib_atomic_wr),
102 .qpt_support = BIT(IB_QPT_RC),
103 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
104},
105
106[IB_WR_RDMA_WRITE_WITH_IMM] = {
107 .length = sizeof(struct ib_rdma_wr),
108 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
109},
110
111[IB_WR_SEND] = {
112 .length = sizeof(struct ib_send_wr),
113 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
114 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
115},
116
117[IB_WR_SEND_WITH_IMM] = {
118 .length = sizeof(struct ib_send_wr),
119 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
120 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
121},
122
123[IB_WR_REG_MR] = {
124 .length = sizeof(struct ib_reg_wr),
125 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
126 .flags = RVT_OPERATION_LOCAL,
127},
128
129[IB_WR_LOCAL_INV] = {
130 .length = sizeof(struct ib_send_wr),
131 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
132 .flags = RVT_OPERATION_LOCAL,
133},
134
135[IB_WR_SEND_WITH_INV] = {
136 .length = sizeof(struct ib_send_wr),
137 .qpt_support = BIT(IB_QPT_RC),
138},
139
140};
141
142static void flush_tx_list(struct rvt_qp *qp)
143{
144 struct hfi1_qp_priv *priv = qp->priv;
145
146 while (!list_empty(&priv->s_iowait.tx_head)) {
147 struct sdma_txreq *tx;
148
149 tx = list_first_entry(
150 &priv->s_iowait.tx_head,
151 struct sdma_txreq,
152 list);
153 list_del_init(&tx->list);
154 hfi1_put_txreq(
155 container_of(tx, struct verbs_txreq, txreq));
156 }
157}
158
159static void flush_iowait(struct rvt_qp *qp)
160{
161 struct hfi1_qp_priv *priv = qp->priv;
162 unsigned long flags;
163 seqlock_t *lock = priv->s_iowait.lock;
164
165 if (!lock)
166 return;
167 write_seqlock_irqsave(lock, flags);
168 if (!list_empty(&priv->s_iowait.list)) {
169 list_del_init(&priv->s_iowait.list);
170 priv->s_iowait.lock = NULL;
171 rvt_put_qp(qp);
172 }
173 write_sequnlock_irqrestore(lock, flags);
174}
175
176static inline int opa_mtu_enum_to_int(int mtu)
177{
178 switch (mtu) {
179 case OPA_MTU_8192: return 8192;
180 case OPA_MTU_10240: return 10240;
181 default: return -1;
182 }
183}
184
185
186
187
188
189
190static inline int verbs_mtu_enum_to_int(struct ib_device *dev, enum ib_mtu mtu)
191{
192 int val;
193
194
195 if (mtu == (enum ib_mtu)OPA_MTU_10240)
196 mtu = OPA_MTU_8192;
197 val = opa_mtu_enum_to_int((int)mtu);
198 if (val > 0)
199 return val;
200 return ib_mtu_enum_to_int(mtu);
201}
202
203int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
204 int attr_mask, struct ib_udata *udata)
205{
206 struct ib_qp *ibqp = &qp->ibqp;
207 struct hfi1_ibdev *dev = to_idev(ibqp->device);
208 struct hfi1_devdata *dd = dd_from_dev(dev);
209 u8 sc;
210
211 if (attr_mask & IB_QP_AV) {
212 sc = ah_to_sc(ibqp->device, &attr->ah_attr);
213 if (sc == 0xf)
214 return -EINVAL;
215
216 if (!qp_to_sdma_engine(qp, sc) &&
217 dd->flags & HFI1_HAS_SEND_DMA)
218 return -EINVAL;
219
220 if (!qp_to_send_context(qp, sc))
221 return -EINVAL;
222 }
223
224 if (attr_mask & IB_QP_ALT_PATH) {
225 sc = ah_to_sc(ibqp->device, &attr->alt_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 return 0;
238}
239
240void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
241 int attr_mask, struct ib_udata *udata)
242{
243 struct ib_qp *ibqp = &qp->ibqp;
244 struct hfi1_qp_priv *priv = qp->priv;
245
246 if (attr_mask & IB_QP_AV) {
247 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
248 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
249 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
250 }
251
252 if (attr_mask & IB_QP_PATH_MIG_STATE &&
253 attr->path_mig_state == IB_MIG_MIGRATED &&
254 qp->s_mig_state == IB_MIG_ARMED) {
255 qp->s_flags |= RVT_S_AHG_CLEAR;
256 priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
257 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
258 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
259 }
260}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275int hfi1_check_send_wqe(struct rvt_qp *qp,
276 struct rvt_swqe *wqe)
277{
278 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
279 struct rvt_ah *ah;
280
281 switch (qp->ibqp.qp_type) {
282 case IB_QPT_RC:
283 case IB_QPT_UC:
284 if (wqe->length > 0x80000000U)
285 return -EINVAL;
286 break;
287 case IB_QPT_SMI:
288 ah = ibah_to_rvtah(wqe->ud_wr.ah);
289 if (wqe->length > (1 << ah->log_pmtu))
290 return -EINVAL;
291 break;
292 case IB_QPT_GSI:
293 case IB_QPT_UD:
294 ah = ibah_to_rvtah(wqe->ud_wr.ah);
295 if (wqe->length > (1 << ah->log_pmtu))
296 return -EINVAL;
297 if (ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)] == 0xf)
298 return -EINVAL;
299 default:
300 break;
301 }
302 return wqe->length <= piothreshold;
303}
304
305
306
307
308
309
310
311
312
313
314void _hfi1_schedule_send(struct rvt_qp *qp)
315{
316 struct hfi1_qp_priv *priv = qp->priv;
317 struct hfi1_ibport *ibp =
318 to_iport(qp->ibqp.device, qp->port_num);
319 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
320 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
321
322 iowait_schedule(&priv->s_iowait, ppd->hfi1_wq,
323 priv->s_sde ?
324 priv->s_sde->cpu :
325 cpumask_first(cpumask_of_node(dd->node)));
326}
327
328static void qp_pio_drain(struct rvt_qp *qp)
329{
330 struct hfi1_ibdev *dev;
331 struct hfi1_qp_priv *priv = qp->priv;
332
333 if (!priv->s_sendcontext)
334 return;
335 dev = to_idev(qp->ibqp.device);
336 while (iowait_pio_pending(&priv->s_iowait)) {
337 write_seqlock_irq(&dev->iowait_lock);
338 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 1);
339 write_sequnlock_irq(&dev->iowait_lock);
340 iowait_pio_drain(&priv->s_iowait);
341 write_seqlock_irq(&dev->iowait_lock);
342 hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 0);
343 write_sequnlock_irq(&dev->iowait_lock);
344 }
345}
346
347
348
349
350
351
352
353
354void hfi1_schedule_send(struct rvt_qp *qp)
355{
356 lockdep_assert_held(&qp->s_lock);
357 if (hfi1_send_ok(qp))
358 _hfi1_schedule_send(qp);
359}
360
361void hfi1_qp_wakeup(struct rvt_qp *qp, u32 flag)
362{
363 unsigned long flags;
364
365 spin_lock_irqsave(&qp->s_lock, flags);
366 if (qp->s_flags & flag) {
367 qp->s_flags &= ~flag;
368 trace_hfi1_qpwakeup(qp, flag);
369 hfi1_schedule_send(qp);
370 }
371 spin_unlock_irqrestore(&qp->s_lock, flags);
372
373 rvt_put_qp(qp);
374}
375
376static int iowait_sleep(
377 struct sdma_engine *sde,
378 struct iowait *wait,
379 struct sdma_txreq *stx,
380 unsigned seq)
381{
382 struct verbs_txreq *tx = container_of(stx, struct verbs_txreq, txreq);
383 struct rvt_qp *qp;
384 struct hfi1_qp_priv *priv;
385 unsigned long flags;
386 int ret = 0;
387 struct hfi1_ibdev *dev;
388
389 qp = tx->qp;
390 priv = qp->priv;
391
392 spin_lock_irqsave(&qp->s_lock, flags);
393 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
394
395
396
397
398
399
400 dev = &sde->dd->verbs_dev;
401 list_add_tail(&stx->list, &wait->tx_head);
402 write_seqlock(&dev->iowait_lock);
403 if (sdma_progress(sde, seq, stx))
404 goto eagain;
405 if (list_empty(&priv->s_iowait.list)) {
406 struct hfi1_ibport *ibp =
407 to_iport(qp->ibqp.device, qp->port_num);
408
409 ibp->rvp.n_dmawait++;
410 qp->s_flags |= RVT_S_WAIT_DMA_DESC;
411 list_add_tail(&priv->s_iowait.list, &sde->dmawait);
412 priv->s_iowait.lock = &dev->iowait_lock;
413 trace_hfi1_qpsleep(qp, RVT_S_WAIT_DMA_DESC);
414 rvt_get_qp(qp);
415 }
416 write_sequnlock(&dev->iowait_lock);
417 qp->s_flags &= ~RVT_S_BUSY;
418 spin_unlock_irqrestore(&qp->s_lock, flags);
419 ret = -EBUSY;
420 } else {
421 spin_unlock_irqrestore(&qp->s_lock, flags);
422 hfi1_put_txreq(tx);
423 }
424 return ret;
425eagain:
426 write_sequnlock(&dev->iowait_lock);
427 spin_unlock_irqrestore(&qp->s_lock, flags);
428 list_del_init(&stx->list);
429 return -EAGAIN;
430}
431
432static void iowait_wakeup(struct iowait *wait, int reason)
433{
434 struct rvt_qp *qp = iowait_to_qp(wait);
435
436 WARN_ON(reason != SDMA_AVAIL_REASON);
437 hfi1_qp_wakeup(qp, RVT_S_WAIT_DMA_DESC);
438}
439
440static void iowait_sdma_drained(struct iowait *wait)
441{
442 struct rvt_qp *qp = iowait_to_qp(wait);
443 unsigned long flags;
444
445
446
447
448
449
450
451 spin_lock_irqsave(&qp->s_lock, flags);
452 if (qp->s_flags & RVT_S_WAIT_DMA) {
453 qp->s_flags &= ~RVT_S_WAIT_DMA;
454 hfi1_schedule_send(qp);
455 }
456 spin_unlock_irqrestore(&qp->s_lock, flags);
457}
458
459
460
461
462
463
464
465
466
467
468struct sdma_engine *qp_to_sdma_engine(struct rvt_qp *qp, u8 sc5)
469{
470 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
471 struct sdma_engine *sde;
472
473 if (!(dd->flags & HFI1_HAS_SEND_DMA))
474 return NULL;
475 switch (qp->ibqp.qp_type) {
476 case IB_QPT_SMI:
477 return NULL;
478 default:
479 break;
480 }
481 sde = sdma_select_engine_sc(dd, qp->ibqp.qp_num >> dd->qos_shift, sc5);
482 return sde;
483}
484
485
486
487
488
489
490
491
492
493struct send_context *qp_to_send_context(struct rvt_qp *qp, u8 sc5)
494{
495 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
496
497 switch (qp->ibqp.qp_type) {
498 case IB_QPT_SMI:
499
500 return dd->vld[15].sc;
501 default:
502 break;
503 }
504
505 return pio_select_send_context_sc(dd, qp->ibqp.qp_num >> dd->qos_shift,
506 sc5);
507}
508
509struct qp_iter {
510 struct hfi1_ibdev *dev;
511 struct rvt_qp *qp;
512 int specials;
513 int n;
514};
515
516struct qp_iter *qp_iter_init(struct hfi1_ibdev *dev)
517{
518 struct qp_iter *iter;
519
520 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
521 if (!iter)
522 return NULL;
523
524 iter->dev = dev;
525 iter->specials = dev->rdi.ibdev.phys_port_cnt * 2;
526
527 return iter;
528}
529
530int qp_iter_next(struct qp_iter *iter)
531{
532 struct hfi1_ibdev *dev = iter->dev;
533 int n = iter->n;
534 int ret = 1;
535 struct rvt_qp *pqp = iter->qp;
536 struct rvt_qp *qp;
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552 for (; n < dev->rdi.qp_dev->qp_table_size + iter->specials; n++) {
553 if (pqp) {
554 qp = rcu_dereference(pqp->next);
555 } else {
556 if (n < iter->specials) {
557 struct hfi1_pportdata *ppd;
558 struct hfi1_ibport *ibp;
559 int pidx;
560
561 pidx = n % dev->rdi.ibdev.phys_port_cnt;
562 ppd = &dd_from_dev(dev)->pport[pidx];
563 ibp = &ppd->ibport_data;
564
565 if (!(n & 1))
566 qp = rcu_dereference(ibp->rvp.qp[0]);
567 else
568 qp = rcu_dereference(ibp->rvp.qp[1]);
569 } else {
570 qp = rcu_dereference(
571 dev->rdi.qp_dev->qp_table[
572 (n - iter->specials)]);
573 }
574 }
575 pqp = qp;
576 if (qp) {
577 iter->qp = qp;
578 iter->n = n;
579 return 0;
580 }
581 }
582 return ret;
583}
584
585static const char * const qp_type_str[] = {
586 "SMI", "GSI", "RC", "UC", "UD",
587};
588
589static int qp_idle(struct rvt_qp *qp)
590{
591 return
592 qp->s_last == qp->s_acked &&
593 qp->s_acked == qp->s_cur &&
594 qp->s_cur == qp->s_tail &&
595 qp->s_tail == qp->s_head;
596}
597
598void qp_iter_print(struct seq_file *s, struct 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
606 sde = qp_to_sdma_engine(qp, priv->s_sc);
607 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
608 send_context = qp_to_send_context(qp, priv->s_sc);
609 seq_printf(s,
610 "N %d %s QP %x R %u %s %u %u %u f=%x %u %u %u %u %u %u SPSN %x %x %x %x %x RPSN %x (%u %u %u %u %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\n",
611 iter->n,
612 qp_idle(qp) ? "I" : "B",
613 qp->ibqp.qp_num,
614 atomic_read(&qp->refcount),
615 qp_type_str[qp->ibqp.qp_type],
616 qp->state,
617 wqe ? wqe->wr.opcode : 0,
618 qp->s_hdrwords,
619 qp->s_flags,
620 iowait_sdma_pending(&priv->s_iowait),
621 iowait_pio_pending(&priv->s_iowait),
622 !list_empty(&priv->s_iowait.list),
623 qp->timeout,
624 wqe ? wqe->ssn : 0,
625 qp->s_lsn,
626 qp->s_last_psn,
627 qp->s_psn, qp->s_next_psn,
628 qp->s_sending_psn, qp->s_sending_hpsn,
629 qp->r_psn,
630 qp->s_last, qp->s_acked, qp->s_cur,
631 qp->s_tail, qp->s_head, qp->s_size,
632 qp->s_avail,
633 qp->remote_qpn,
634 rdma_ah_get_dlid(&qp->remote_ah_attr),
635 rdma_ah_get_sl(&qp->remote_ah_attr),
636 qp->pmtu,
637 qp->s_retry,
638 qp->s_retry_cnt,
639 qp->s_rnr_retry_cnt,
640 qp->s_rnr_retry,
641 sde,
642 sde ? sde->this_idx : 0,
643 send_context,
644 send_context ? send_context->sw_index : 0,
645 ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->head,
646 ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->tail,
647 qp->pid);
648}
649
650void *qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp)
651{
652 struct hfi1_qp_priv *priv;
653
654 priv = kzalloc_node(sizeof(*priv), GFP_KERNEL, rdi->dparms.node);
655 if (!priv)
656 return ERR_PTR(-ENOMEM);
657
658 priv->owner = qp;
659
660 priv->s_ahg = kzalloc_node(sizeof(*priv->s_ahg), GFP_KERNEL,
661 rdi->dparms.node);
662 if (!priv->s_ahg) {
663 kfree(priv);
664 return ERR_PTR(-ENOMEM);
665 }
666 iowait_init(
667 &priv->s_iowait,
668 1,
669 _hfi1_do_send,
670 iowait_sleep,
671 iowait_wakeup,
672 iowait_sdma_drained);
673 return priv;
674}
675
676void qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp)
677{
678 struct hfi1_qp_priv *priv = qp->priv;
679
680 kfree(priv->s_ahg);
681 kfree(priv);
682}
683
684unsigned free_all_qps(struct rvt_dev_info *rdi)
685{
686 struct hfi1_ibdev *verbs_dev = container_of(rdi,
687 struct hfi1_ibdev,
688 rdi);
689 struct hfi1_devdata *dd = container_of(verbs_dev,
690 struct hfi1_devdata,
691 verbs_dev);
692 int n;
693 unsigned qp_inuse = 0;
694
695 for (n = 0; n < dd->num_pports; n++) {
696 struct hfi1_ibport *ibp = &dd->pport[n].ibport_data;
697
698 rcu_read_lock();
699 if (rcu_dereference(ibp->rvp.qp[0]))
700 qp_inuse++;
701 if (rcu_dereference(ibp->rvp.qp[1]))
702 qp_inuse++;
703 rcu_read_unlock();
704 }
705
706 return qp_inuse;
707}
708
709void flush_qp_waiters(struct rvt_qp *qp)
710{
711 lockdep_assert_held(&qp->s_lock);
712 flush_iowait(qp);
713}
714
715void stop_send_queue(struct rvt_qp *qp)
716{
717 struct hfi1_qp_priv *priv = qp->priv;
718
719 cancel_work_sync(&priv->s_iowait.iowork);
720}
721
722void quiesce_qp(struct rvt_qp *qp)
723{
724 struct hfi1_qp_priv *priv = qp->priv;
725
726 iowait_sdma_drain(&priv->s_iowait);
727 qp_pio_drain(qp);
728 flush_tx_list(qp);
729}
730
731void notify_qp_reset(struct rvt_qp *qp)
732{
733 qp->r_adefered = 0;
734 clear_ahg(qp);
735}
736
737
738
739
740
741void hfi1_migrate_qp(struct rvt_qp *qp)
742{
743 struct hfi1_qp_priv *priv = qp->priv;
744 struct ib_event ev;
745
746 qp->s_mig_state = IB_MIG_MIGRATED;
747 qp->remote_ah_attr = qp->alt_ah_attr;
748 qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr);
749 qp->s_pkey_index = qp->s_alt_pkey_index;
750 qp->s_flags |= RVT_S_AHG_CLEAR;
751 priv->s_sc = ah_to_sc(qp->ibqp.device, &qp->remote_ah_attr);
752 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
753
754 ev.device = qp->ibqp.device;
755 ev.element.qp = &qp->ibqp;
756 ev.event = IB_EVENT_PATH_MIG;
757 qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
758}
759
760int mtu_to_path_mtu(u32 mtu)
761{
762 return mtu_to_enum(mtu, OPA_MTU_8192);
763}
764
765u32 mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu)
766{
767 u32 mtu;
768 struct hfi1_ibdev *verbs_dev = container_of(rdi,
769 struct hfi1_ibdev,
770 rdi);
771 struct hfi1_devdata *dd = container_of(verbs_dev,
772 struct hfi1_devdata,
773 verbs_dev);
774 struct hfi1_ibport *ibp;
775 u8 sc, vl;
776
777 ibp = &dd->pport[qp->port_num - 1].ibport_data;
778 sc = ibp->sl_to_sc[rdma_ah_get_sl(&qp->remote_ah_attr)];
779 vl = sc_to_vlt(dd, sc);
780
781 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, pmtu);
782 if (vl < PER_VL_SEND_CONTEXTS)
783 mtu = min_t(u32, mtu, dd->vld[vl].mtu);
784 return mtu;
785}
786
787int get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
788 struct ib_qp_attr *attr)
789{
790 int mtu, pidx = qp->port_num - 1;
791 struct hfi1_ibdev *verbs_dev = container_of(rdi,
792 struct hfi1_ibdev,
793 rdi);
794 struct hfi1_devdata *dd = container_of(verbs_dev,
795 struct hfi1_devdata,
796 verbs_dev);
797 mtu = verbs_mtu_enum_to_int(qp->ibqp.device, attr->path_mtu);
798 if (mtu == -1)
799 return -1;
800
801 if (mtu > dd->pport[pidx].ibmtu)
802 return mtu_to_enum(dd->pport[pidx].ibmtu, IB_MTU_2048);
803 else
804 return attr->path_mtu;
805}
806
807void notify_error_qp(struct rvt_qp *qp)
808{
809 struct hfi1_qp_priv *priv = qp->priv;
810 seqlock_t *lock = priv->s_iowait.lock;
811
812 if (lock) {
813 write_seqlock(lock);
814 if (!list_empty(&priv->s_iowait.list) &&
815 !(qp->s_flags & RVT_S_BUSY)) {
816 qp->s_flags &= ~RVT_S_ANY_WAIT_IO;
817 list_del_init(&priv->s_iowait.list);
818 priv->s_iowait.lock = NULL;
819 rvt_put_qp(qp);
820 }
821 write_sequnlock(lock);
822 }
823
824 if (!(qp->s_flags & RVT_S_BUSY)) {
825 qp->s_hdrwords = 0;
826 if (qp->s_rdma_mr) {
827 rvt_put_mr(qp->s_rdma_mr);
828 qp->s_rdma_mr = NULL;
829 }
830 flush_tx_list(qp);
831 }
832}
833
834
835
836
837
838
839
840
841
842
843void hfi1_error_port_qps(struct hfi1_ibport *ibp, u8 sl)
844{
845 struct rvt_qp *qp = NULL;
846 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
847 struct hfi1_ibdev *dev = &ppd->dd->verbs_dev;
848 int n;
849 int lastwqe;
850 struct ib_event ev;
851
852 rcu_read_lock();
853
854
855 for (n = 0; n < dev->rdi.qp_dev->qp_table_size; n++) {
856 for (qp = rcu_dereference(dev->rdi.qp_dev->qp_table[n]); qp;
857 qp = rcu_dereference(qp->next)) {
858 if (qp->port_num == ppd->port &&
859 (qp->ibqp.qp_type == IB_QPT_UC ||
860 qp->ibqp.qp_type == IB_QPT_RC) &&
861 rdma_ah_get_sl(&qp->remote_ah_attr) == sl &&
862 (ib_rvt_state_ops[qp->state] &
863 RVT_POST_SEND_OK)) {
864 spin_lock_irq(&qp->r_lock);
865 spin_lock(&qp->s_hlock);
866 spin_lock(&qp->s_lock);
867 lastwqe = rvt_error_qp(qp,
868 IB_WC_WR_FLUSH_ERR);
869 spin_unlock(&qp->s_lock);
870 spin_unlock(&qp->s_hlock);
871 spin_unlock_irq(&qp->r_lock);
872 if (lastwqe) {
873 ev.device = qp->ibqp.device;
874 ev.element.qp = &qp->ibqp;
875 ev.event =
876 IB_EVENT_QP_LAST_WQE_REACHED;
877 qp->ibqp.event_handler(&ev,
878 qp->ibqp.qp_context);
879 }
880 }
881 }
882 }
883
884 rcu_read_unlock();
885}
886