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/net.h>
49#include <rdma/ib_smi.h>
50
51#include "hfi.h"
52#include "mad.h"
53#include "verbs_txreq.h"
54#include "qp.h"
55
56
57
58
59
60
61
62
63
64
65
66static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
67{
68 struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
69 struct hfi1_pportdata *ppd;
70 struct rvt_qp *qp;
71 struct ib_ah_attr *ah_attr;
72 unsigned long flags;
73 struct rvt_sge_state ssge;
74 struct rvt_sge *sge;
75 struct ib_wc wc;
76 u32 length;
77 enum ib_qp_type sqptype, dqptype;
78
79 rcu_read_lock();
80
81 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp,
82 swqe->ud_wr.remote_qpn);
83 if (!qp) {
84 ibp->rvp.n_pkt_drops++;
85 rcu_read_unlock();
86 return;
87 }
88
89 sqptype = sqp->ibqp.qp_type == IB_QPT_GSI ?
90 IB_QPT_UD : sqp->ibqp.qp_type;
91 dqptype = qp->ibqp.qp_type == IB_QPT_GSI ?
92 IB_QPT_UD : qp->ibqp.qp_type;
93
94 if (dqptype != sqptype ||
95 !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
96 ibp->rvp.n_pkt_drops++;
97 goto drop;
98 }
99
100 ah_attr = &ibah_to_rvtah(swqe->ud_wr.ah)->attr;
101 ppd = ppd_from_ibp(ibp);
102
103 if (qp->ibqp.qp_num > 1) {
104 u16 pkey;
105 u16 slid;
106 u8 sc5 = ibp->sl_to_sc[ah_attr->sl];
107
108 pkey = hfi1_get_pkey(ibp, sqp->s_pkey_index);
109 slid = ppd->lid | (ah_attr->src_path_bits &
110 ((1 << ppd->lmc) - 1));
111 if (unlikely(ingress_pkey_check(ppd, pkey, sc5,
112 qp->s_pkey_index, slid))) {
113 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, pkey,
114 ah_attr->sl,
115 sqp->ibqp.qp_num, qp->ibqp.qp_num,
116 slid, ah_attr->dlid);
117 goto drop;
118 }
119 }
120
121
122
123
124
125
126 if (qp->ibqp.qp_num) {
127 u32 qkey;
128
129 qkey = (int)swqe->ud_wr.remote_qkey < 0 ?
130 sqp->qkey : swqe->ud_wr.remote_qkey;
131 if (unlikely(qkey != qp->qkey)) {
132 u16 lid;
133
134 lid = ppd->lid | (ah_attr->src_path_bits &
135 ((1 << ppd->lmc) - 1));
136 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey,
137 ah_attr->sl,
138 sqp->ibqp.qp_num, qp->ibqp.qp_num,
139 lid,
140 ah_attr->dlid);
141 goto drop;
142 }
143 }
144
145
146
147
148
149 length = swqe->length;
150 memset(&wc, 0, sizeof(wc));
151 wc.byte_len = length + sizeof(struct ib_grh);
152
153 if (swqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
154 wc.wc_flags = IB_WC_WITH_IMM;
155 wc.ex.imm_data = swqe->wr.ex.imm_data;
156 }
157
158 spin_lock_irqsave(&qp->r_lock, flags);
159
160
161
162
163 if (qp->r_flags & RVT_R_REUSE_SGE) {
164 qp->r_flags &= ~RVT_R_REUSE_SGE;
165 } else {
166 int ret;
167
168 ret = hfi1_rvt_get_rwqe(qp, 0);
169 if (ret < 0) {
170 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
171 goto bail_unlock;
172 }
173 if (!ret) {
174 if (qp->ibqp.qp_num == 0)
175 ibp->rvp.n_vl15_dropped++;
176 goto bail_unlock;
177 }
178 }
179
180 if (unlikely(wc.byte_len > qp->r_len)) {
181 qp->r_flags |= RVT_R_REUSE_SGE;
182 ibp->rvp.n_pkt_drops++;
183 goto bail_unlock;
184 }
185
186 if (ah_attr->ah_flags & IB_AH_GRH) {
187 struct ib_grh grh;
188 struct ib_global_route grd = ah_attr->grh;
189
190 hfi1_make_grh(ibp, &grh, &grd, 0, 0);
191 hfi1_copy_sge(&qp->r_sge, &grh,
192 sizeof(grh), 1, 0);
193 wc.wc_flags |= IB_WC_GRH;
194 } else {
195 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
196 }
197 ssge.sg_list = swqe->sg_list + 1;
198 ssge.sge = *swqe->sg_list;
199 ssge.num_sge = swqe->wr.num_sge;
200 sge = &ssge.sge;
201 while (length) {
202 u32 len = sge->length;
203
204 if (len > length)
205 len = length;
206 if (len > sge->sge_length)
207 len = sge->sge_length;
208 WARN_ON_ONCE(len == 0);
209 hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, 1, 0);
210 sge->vaddr += len;
211 sge->length -= len;
212 sge->sge_length -= len;
213 if (sge->sge_length == 0) {
214 if (--ssge.num_sge)
215 *sge = *ssge.sg_list++;
216 } else if (sge->length == 0 && sge->mr->lkey) {
217 if (++sge->n >= RVT_SEGSZ) {
218 if (++sge->m >= sge->mr->mapsz)
219 break;
220 sge->n = 0;
221 }
222 sge->vaddr =
223 sge->mr->map[sge->m]->segs[sge->n].vaddr;
224 sge->length =
225 sge->mr->map[sge->m]->segs[sge->n].length;
226 }
227 length -= len;
228 }
229 rvt_put_ss(&qp->r_sge);
230 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
231 goto bail_unlock;
232 wc.wr_id = qp->r_wr_id;
233 wc.status = IB_WC_SUCCESS;
234 wc.opcode = IB_WC_RECV;
235 wc.qp = &qp->ibqp;
236 wc.src_qp = sqp->ibqp.qp_num;
237 if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI) {
238 if (sqp->ibqp.qp_type == IB_QPT_GSI ||
239 sqp->ibqp.qp_type == IB_QPT_SMI)
240 wc.pkey_index = swqe->ud_wr.pkey_index;
241 else
242 wc.pkey_index = sqp->s_pkey_index;
243 } else {
244 wc.pkey_index = 0;
245 }
246 wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1));
247
248 if (wc.slid == 0 && sqp->ibqp.qp_type == IB_QPT_GSI)
249 wc.slid = be16_to_cpu(IB_LID_PERMISSIVE);
250 wc.sl = ah_attr->sl;
251 wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1);
252 wc.port_num = qp->port_num;
253
254 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
255 swqe->wr.send_flags & IB_SEND_SOLICITED);
256 ibp->rvp.n_loop_pkts++;
257bail_unlock:
258 spin_unlock_irqrestore(&qp->r_lock, flags);
259drop:
260 rcu_read_unlock();
261}
262
263
264
265
266
267
268
269
270
271int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
272{
273 struct hfi1_qp_priv *priv = qp->priv;
274 struct ib_other_headers *ohdr;
275 struct ib_ah_attr *ah_attr;
276 struct hfi1_pportdata *ppd;
277 struct hfi1_ibport *ibp;
278 struct rvt_swqe *wqe;
279 u32 nwords;
280 u32 extra_bytes;
281 u32 bth0;
282 u16 lrh0;
283 u16 lid;
284 int next_cur;
285 u8 sc5;
286
287 ps->s_txreq = get_txreq(ps->dev, qp);
288 if (IS_ERR(ps->s_txreq))
289 goto bail_no_tx;
290
291 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
292 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
293 goto bail;
294
295 smp_read_barrier_depends();
296 if (qp->s_last == ACCESS_ONCE(qp->s_head))
297 goto bail;
298
299 if (iowait_sdma_pending(&priv->s_iowait)) {
300 qp->s_flags |= RVT_S_WAIT_DMA;
301 goto bail;
302 }
303 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
304 hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
305 goto done_free_tx;
306 }
307
308
309 smp_read_barrier_depends();
310 if (qp->s_cur == ACCESS_ONCE(qp->s_head))
311 goto bail;
312
313 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
314 next_cur = qp->s_cur + 1;
315 if (next_cur >= qp->s_size)
316 next_cur = 0;
317
318
319 ibp = to_iport(qp->ibqp.device, qp->port_num);
320 ppd = ppd_from_ibp(ibp);
321 ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
322 if (ah_attr->dlid < be16_to_cpu(IB_MULTICAST_LID_BASE) ||
323 ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
324 lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1);
325 if (unlikely(!loopback &&
326 (lid == ppd->lid ||
327 (lid == be16_to_cpu(IB_LID_PERMISSIVE) &&
328 qp->ibqp.qp_type == IB_QPT_GSI)))) {
329 unsigned long tflags = ps->flags;
330
331
332
333
334
335
336
337 if (iowait_sdma_pending(&priv->s_iowait)) {
338 qp->s_flags |= RVT_S_WAIT_DMA;
339 goto bail;
340 }
341 qp->s_cur = next_cur;
342 spin_unlock_irqrestore(&qp->s_lock, tflags);
343 ud_loopback(qp, wqe);
344 spin_lock_irqsave(&qp->s_lock, tflags);
345 ps->flags = tflags;
346 hfi1_send_complete(qp, wqe, IB_WC_SUCCESS);
347 goto done_free_tx;
348 }
349 }
350
351 qp->s_cur = next_cur;
352 extra_bytes = -wqe->length & 3;
353 nwords = (wqe->length + extra_bytes) >> 2;
354
355
356 qp->s_hdrwords = 7;
357 qp->s_cur_size = wqe->length;
358 qp->s_cur_sge = &qp->s_sge;
359 qp->s_srate = ah_attr->static_rate;
360 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate);
361 qp->s_wqe = wqe;
362 qp->s_sge.sge = wqe->sg_list[0];
363 qp->s_sge.sg_list = wqe->sg_list + 1;
364 qp->s_sge.num_sge = wqe->wr.num_sge;
365 qp->s_sge.total_len = wqe->length;
366
367 if (ah_attr->ah_flags & IB_AH_GRH) {
368
369 qp->s_hdrwords += hfi1_make_grh(ibp,
370 &ps->s_txreq->phdr.hdr.u.l.grh,
371 &ah_attr->grh,
372 qp->s_hdrwords, nwords);
373 lrh0 = HFI1_LRH_GRH;
374 ohdr = &ps->s_txreq->phdr.hdr.u.l.oth;
375
376
377
378
379 } else {
380
381 lrh0 = HFI1_LRH_BTH;
382 ohdr = &ps->s_txreq->phdr.hdr.u.oth;
383 }
384 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
385 qp->s_hdrwords++;
386 ohdr->u.ud.imm_data = wqe->wr.ex.imm_data;
387 bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
388 } else {
389 bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
390 }
391 sc5 = ibp->sl_to_sc[ah_attr->sl];
392 lrh0 |= (ah_attr->sl & 0xf) << 4;
393 if (qp->ibqp.qp_type == IB_QPT_SMI) {
394 lrh0 |= 0xF000;
395 priv->s_sc = 0xf;
396 } else {
397 lrh0 |= (sc5 & 0xf) << 12;
398 priv->s_sc = sc5;
399 }
400 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
401 ps->s_txreq->sde = priv->s_sde;
402 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
403 ps->s_txreq->psc = priv->s_sendcontext;
404 ps->s_txreq->phdr.hdr.lrh[0] = cpu_to_be16(lrh0);
405 ps->s_txreq->phdr.hdr.lrh[1] = cpu_to_be16(ah_attr->dlid);
406 ps->s_txreq->phdr.hdr.lrh[2] =
407 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
408 if (ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
409 ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE;
410 } else {
411 lid = ppd->lid;
412 if (lid) {
413 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1);
414 ps->s_txreq->phdr.hdr.lrh[3] = cpu_to_be16(lid);
415 } else {
416 ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE;
417 }
418 }
419 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
420 bth0 |= IB_BTH_SOLICITED;
421 bth0 |= extra_bytes << 20;
422 if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI)
423 bth0 |= hfi1_get_pkey(ibp, wqe->ud_wr.pkey_index);
424 else
425 bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index);
426 ohdr->bth[0] = cpu_to_be32(bth0);
427 ohdr->bth[1] = cpu_to_be32(wqe->ud_wr.remote_qpn);
428 ohdr->bth[2] = cpu_to_be32(mask_psn(wqe->psn));
429
430
431
432
433 ohdr->u.ud.deth[0] = cpu_to_be32((int)wqe->ud_wr.remote_qkey < 0 ?
434 qp->qkey : wqe->ud_wr.remote_qkey);
435 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
436
437 priv->s_ahg->ahgcount = 0;
438 priv->s_ahg->ahgidx = 0;
439 priv->s_ahg->tx_flags = 0;
440
441 ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2;
442
443 return 1;
444
445done_free_tx:
446 hfi1_put_txreq(ps->s_txreq);
447 ps->s_txreq = NULL;
448 return 1;
449
450bail:
451 hfi1_put_txreq(ps->s_txreq);
452
453bail_no_tx:
454 ps->s_txreq = NULL;
455 qp->s_flags &= ~RVT_S_BUSY;
456 qp->s_hdrwords = 0;
457 return 0;
458}
459
460
461
462
463
464
465
466
467
468
469int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey)
470{
471 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
472 unsigned i;
473
474 if (pkey == FULL_MGMT_P_KEY || pkey == LIM_MGMT_P_KEY) {
475 unsigned lim_idx = -1;
476
477 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) {
478
479 if (ppd->pkeys[i] == pkey)
480 return i;
481 if (ppd->pkeys[i] == LIM_MGMT_P_KEY)
482 lim_idx = i;
483 }
484
485
486 if (pkey == FULL_MGMT_P_KEY)
487 return lim_idx;
488
489
490 return -1;
491 }
492
493 pkey &= 0x7fff;
494
495 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i)
496 if ((ppd->pkeys[i] & 0x7fff) == pkey)
497 return i;
498
499
500
501
502 return -1;
503}
504
505void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
506 u32 pkey, u32 slid, u32 dlid, u8 sc5,
507 const struct ib_grh *old_grh)
508{
509 u64 pbc, pbc_flags = 0;
510 u32 bth0, plen, vl, hwords = 5;
511 u16 lrh0;
512 u8 sl = ibp->sc_to_sl[sc5];
513 struct ib_header hdr;
514 struct ib_other_headers *ohdr;
515 struct pio_buf *pbuf;
516 struct send_context *ctxt = qp_to_send_context(qp, sc5);
517 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
518
519 if (old_grh) {
520 struct ib_grh *grh = &hdr.u.l.grh;
521
522 grh->version_tclass_flow = old_grh->version_tclass_flow;
523 grh->paylen = cpu_to_be16((hwords - 2 + SIZE_OF_CRC) << 2);
524 grh->hop_limit = 0xff;
525 grh->sgid = old_grh->dgid;
526 grh->dgid = old_grh->sgid;
527 ohdr = &hdr.u.l.oth;
528 lrh0 = HFI1_LRH_GRH;
529 hwords += sizeof(struct ib_grh) / sizeof(u32);
530 } else {
531 ohdr = &hdr.u.oth;
532 lrh0 = HFI1_LRH_BTH;
533 }
534
535 lrh0 |= (sc5 & 0xf) << 12 | sl << 4;
536
537 bth0 = pkey | (IB_OPCODE_CNP << 24);
538 ohdr->bth[0] = cpu_to_be32(bth0);
539
540 ohdr->bth[1] = cpu_to_be32(remote_qpn | (1 << HFI1_BECN_SHIFT));
541 ohdr->bth[2] = 0;
542
543 hdr.lrh[0] = cpu_to_be16(lrh0);
544 hdr.lrh[1] = cpu_to_be16(dlid);
545 hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC);
546 hdr.lrh[3] = cpu_to_be16(slid);
547
548 plen = 2 + hwords;
549 pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
550 vl = sc_to_vlt(ppd->dd, sc5);
551 pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
552 if (ctxt) {
553 pbuf = sc_buffer_alloc(ctxt, plen, NULL, NULL);
554 if (pbuf)
555 ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc,
556 &hdr, hwords);
557 }
558}
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5,
579 struct rvt_qp *qp, u16 slid, struct opa_smp *smp)
580{
581 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
582
583
584
585
586
587 if (sc5 != 0xf)
588 return 1;
589
590 if (rcv_pkey_check(ppd, pkey, sc5, slid))
591 return 1;
592
593
594
595
596
597
598 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE &&
599 smp->mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED) {
600 ingress_pkey_table_fail(ppd, pkey, slid);
601 return 1;
602 }
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624 switch (smp->method) {
625 case IB_MGMT_METHOD_GET_RESP:
626 case IB_MGMT_METHOD_REPORT_RESP:
627 break;
628 case IB_MGMT_METHOD_GET:
629 case IB_MGMT_METHOD_SET:
630 case IB_MGMT_METHOD_REPORT:
631 case IB_MGMT_METHOD_TRAP_REPRESS:
632 if (pkey != FULL_MGMT_P_KEY) {
633 ingress_pkey_table_fail(ppd, pkey, slid);
634 return 1;
635 }
636 break;
637 default:
638 if (ibp->rvp.port_cap_flags & IB_PORT_SM)
639 return 0;
640 if (smp->method == IB_MGMT_METHOD_TRAP)
641 return 1;
642 if (pkey == FULL_MGMT_P_KEY) {
643 smp->status |= IB_SMP_UNSUP_METHOD;
644 return 0;
645 }
646 ingress_pkey_table_fail(ppd, pkey, slid);
647 return 1;
648 }
649 return 0;
650}
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665void hfi1_ud_rcv(struct hfi1_packet *packet)
666{
667 struct ib_other_headers *ohdr = packet->ohdr;
668 int opcode;
669 u32 hdrsize = packet->hlen;
670 struct ib_wc wc;
671 u32 qkey;
672 u32 src_qp;
673 u16 dlid, pkey;
674 int mgmt_pkey_idx = -1;
675 struct hfi1_ibport *ibp = &packet->rcd->ppd->ibport_data;
676 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
677 struct ib_header *hdr = packet->hdr;
678 u32 rcv_flags = packet->rcv_flags;
679 void *data = packet->ebuf;
680 u32 tlen = packet->tlen;
681 struct rvt_qp *qp = packet->qp;
682 bool has_grh = rcv_flags & HFI1_HAS_GRH;
683 u8 sc5 = hdr2sc(hdr, packet->rhf);
684 u32 bth1;
685 u8 sl_from_sc, sl;
686 u16 slid;
687 u8 extra_bytes;
688
689 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
690 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
691 dlid = be16_to_cpu(hdr->lrh[1]);
692 bth1 = be32_to_cpu(ohdr->bth[1]);
693 slid = be16_to_cpu(hdr->lrh[3]);
694 pkey = (u16)be32_to_cpu(ohdr->bth[0]);
695 sl = (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf;
696 extra_bytes = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
697 extra_bytes += (SIZE_OF_CRC << 2);
698 sl_from_sc = ibp->sc_to_sl[sc5];
699
700 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
701 opcode &= 0xff;
702
703 process_ecn(qp, packet, (opcode != IB_OPCODE_CNP));
704
705
706
707
708 if (unlikely(tlen < (hdrsize + extra_bytes)))
709 goto drop;
710
711 tlen -= hdrsize + extra_bytes;
712
713
714
715
716
717 if (qp->ibqp.qp_num) {
718 if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE ||
719 hdr->lrh[3] == IB_LID_PERMISSIVE))
720 goto drop;
721 if (qp->ibqp.qp_num > 1) {
722 if (unlikely(rcv_pkey_check(ppd, pkey, sc5, slid))) {
723
724
725
726
727
728
729 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY,
730 pkey, sl,
731 src_qp, qp->ibqp.qp_num,
732 slid, dlid);
733 return;
734 }
735 } else {
736
737 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
738 if (mgmt_pkey_idx < 0)
739 goto drop;
740 }
741 if (unlikely(qkey != qp->qkey)) {
742 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey, sl,
743 src_qp, qp->ibqp.qp_num,
744 slid, dlid);
745 return;
746 }
747
748 if (unlikely(qp->ibqp.qp_num == 1 &&
749 (tlen > 2048 || (sc5 == 0xF))))
750 goto drop;
751 } else {
752
753 struct opa_smp *smp = (struct opa_smp *)data;
754
755 if (opa_smp_check(ibp, pkey, sc5, qp, slid, smp))
756 goto drop;
757
758 if (tlen > 2048)
759 goto drop;
760 if ((hdr->lrh[1] == IB_LID_PERMISSIVE ||
761 hdr->lrh[3] == IB_LID_PERMISSIVE) &&
762 smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
763 goto drop;
764
765
766 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
767 if (mgmt_pkey_idx < 0)
768 goto drop;
769 }
770
771 if (qp->ibqp.qp_num > 1 &&
772 opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
773 wc.ex.imm_data = ohdr->u.ud.imm_data;
774 wc.wc_flags = IB_WC_WITH_IMM;
775 tlen -= sizeof(u32);
776 } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
777 wc.ex.imm_data = 0;
778 wc.wc_flags = 0;
779 } else {
780 goto drop;
781 }
782
783
784
785
786
787 wc.byte_len = tlen + sizeof(struct ib_grh);
788
789
790
791
792 if (qp->r_flags & RVT_R_REUSE_SGE) {
793 qp->r_flags &= ~RVT_R_REUSE_SGE;
794 } else {
795 int ret;
796
797 ret = hfi1_rvt_get_rwqe(qp, 0);
798 if (ret < 0) {
799 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
800 return;
801 }
802 if (!ret) {
803 if (qp->ibqp.qp_num == 0)
804 ibp->rvp.n_vl15_dropped++;
805 return;
806 }
807 }
808
809 if (unlikely(wc.byte_len > qp->r_len)) {
810 qp->r_flags |= RVT_R_REUSE_SGE;
811 goto drop;
812 }
813 if (has_grh) {
814 hfi1_copy_sge(&qp->r_sge, &hdr->u.l.grh,
815 sizeof(struct ib_grh), 1, 0);
816 wc.wc_flags |= IB_WC_GRH;
817 } else {
818 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
819 }
820 hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
821 1, 0);
822 rvt_put_ss(&qp->r_sge);
823 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
824 return;
825 wc.wr_id = qp->r_wr_id;
826 wc.status = IB_WC_SUCCESS;
827 wc.opcode = IB_WC_RECV;
828 wc.vendor_err = 0;
829 wc.qp = &qp->ibqp;
830 wc.src_qp = src_qp;
831
832 if (qp->ibqp.qp_type == IB_QPT_GSI ||
833 qp->ibqp.qp_type == IB_QPT_SMI) {
834 if (mgmt_pkey_idx < 0) {
835 if (net_ratelimit()) {
836 struct hfi1_devdata *dd = ppd->dd;
837
838 dd_dev_err(dd, "QP type %d mgmt_pkey_idx < 0 and packet not dropped???\n",
839 qp->ibqp.qp_type);
840 mgmt_pkey_idx = 0;
841 }
842 }
843 wc.pkey_index = (unsigned)mgmt_pkey_idx;
844 } else {
845 wc.pkey_index = 0;
846 }
847
848 wc.slid = slid;
849 wc.sl = sl_from_sc;
850
851
852
853
854 wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 :
855 dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
856 wc.port_num = qp->port_num;
857
858 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
859 (ohdr->bth[0] &
860 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
861 return;
862
863drop:
864 ibp->rvp.n_pkt_drops++;
865}
866