aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/hw/ipath/ipath_rc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband/hw/ipath/ipath_rc.c')
-rw-r--r--drivers/infiniband/hw/ipath/ipath_rc.c204
1 files changed, 32 insertions, 172 deletions
diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
index 33b8c78fcdcc..0ca89af3e10d 100644
--- a/drivers/infiniband/hw/ipath/ipath_rc.c
+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
@@ -73,9 +73,9 @@ static void ipath_init_restart(struct ipath_qp *qp, struct ipath_swqe *wqe)
73 * Return bth0 if constructed; otherwise, return 0. 73 * Return bth0 if constructed; otherwise, return 0.
74 * Note the QP s_lock must be held. 74 * Note the QP s_lock must be held.
75 */ 75 */
76static inline u32 ipath_make_rc_ack(struct ipath_qp *qp, 76u32 ipath_make_rc_ack(struct ipath_qp *qp,
77 struct ipath_other_headers *ohdr, 77 struct ipath_other_headers *ohdr,
78 u32 pmtu) 78 u32 pmtu)
79{ 79{
80 struct ipath_sge_state *ss; 80 struct ipath_sge_state *ss;
81 u32 hwords; 81 u32 hwords;
@@ -96,8 +96,7 @@ static inline u32 ipath_make_rc_ack(struct ipath_qp *qp,
96 if (len > pmtu) { 96 if (len > pmtu) {
97 len = pmtu; 97 len = pmtu;
98 qp->s_ack_state = OP(RDMA_READ_RESPONSE_FIRST); 98 qp->s_ack_state = OP(RDMA_READ_RESPONSE_FIRST);
99 } 99 } else
100 else
101 qp->s_ack_state = OP(RDMA_READ_RESPONSE_ONLY); 100 qp->s_ack_state = OP(RDMA_READ_RESPONSE_ONLY);
102 qp->s_rdma_len -= len; 101 qp->s_rdma_len -= len;
103 bth0 = qp->s_ack_state << 24; 102 bth0 = qp->s_ack_state << 24;
@@ -177,9 +176,9 @@ static inline u32 ipath_make_rc_ack(struct ipath_qp *qp,
177 * Return 1 if constructed; otherwise, return 0. 176 * Return 1 if constructed; otherwise, return 0.
178 * Note the QP s_lock must be held. 177 * Note the QP s_lock must be held.
179 */ 178 */
180static inline int ipath_make_rc_req(struct ipath_qp *qp, 179int ipath_make_rc_req(struct ipath_qp *qp,
181 struct ipath_other_headers *ohdr, 180 struct ipath_other_headers *ohdr,
182 u32 pmtu, u32 *bth0p, u32 *bth2p) 181 u32 pmtu, u32 *bth0p, u32 *bth2p)
183{ 182{
184 struct ipath_ibdev *dev = to_idev(qp->ibqp.device); 183 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
185 struct ipath_sge_state *ss; 184 struct ipath_sge_state *ss;
@@ -497,160 +496,33 @@ done:
497 return 0; 496 return 0;
498} 497}
499 498
500static inline void ipath_make_rc_grh(struct ipath_qp *qp,
501 struct ib_global_route *grh,
502 u32 nwords)
503{
504 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
505
506 /* GRH header size in 32-bit words. */
507 qp->s_hdrwords += 10;
508 qp->s_hdr.u.l.grh.version_tclass_flow =
509 cpu_to_be32((6 << 28) |
510 (grh->traffic_class << 20) |
511 grh->flow_label);
512 qp->s_hdr.u.l.grh.paylen =
513 cpu_to_be16(((qp->s_hdrwords - 12) + nwords +
514 SIZE_OF_CRC) << 2);
515 /* next_hdr is defined by C8-7 in ch. 8.4.1 */
516 qp->s_hdr.u.l.grh.next_hdr = 0x1B;
517 qp->s_hdr.u.l.grh.hop_limit = grh->hop_limit;
518 /* The SGID is 32-bit aligned. */
519 qp->s_hdr.u.l.grh.sgid.global.subnet_prefix = dev->gid_prefix;
520 qp->s_hdr.u.l.grh.sgid.global.interface_id =
521 ipath_layer_get_guid(dev->dd);
522 qp->s_hdr.u.l.grh.dgid = grh->dgid;
523}
524
525/** 499/**
526 * ipath_do_rc_send - perform a send on an RC QP 500 * send_rc_ack - Construct an ACK packet and send it
527 * @data: contains a pointer to the QP 501 * @qp: a pointer to the QP
528 * 502 *
529 * Process entries in the send work queue until credit or queue is 503 * This is called from ipath_rc_rcv() and only uses the receive
530 * exhausted. Only allow one CPU to send a packet per QP (tasklet). 504 * side QP state.
531 * Otherwise, after we drop the QP s_lock, two threads could send 505 * Note that RDMA reads are handled in the send side QP state and tasklet.
532 * packets out of order.
533 */ 506 */
534void ipath_do_rc_send(unsigned long data)
535{
536 struct ipath_qp *qp = (struct ipath_qp *)data;
537 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
538 unsigned long flags;
539 u16 lrh0;
540 u32 nwords;
541 u32 extra_bytes;
542 u32 bth0;
543 u32 bth2;
544 u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
545 struct ipath_other_headers *ohdr;
546
547 if (test_and_set_bit(IPATH_S_BUSY, &qp->s_flags))
548 goto bail;
549
550 if (unlikely(qp->remote_ah_attr.dlid ==
551 ipath_layer_get_lid(dev->dd))) {
552 struct ib_wc wc;
553
554 /*
555 * Pass in an uninitialized ib_wc to be consistent with
556 * other places where ipath_ruc_loopback() is called.
557 */
558 ipath_ruc_loopback(qp, &wc);
559 goto clear;
560 }
561
562 ohdr = &qp->s_hdr.u.oth;
563 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
564 ohdr = &qp->s_hdr.u.l.oth;
565
566again:
567 /* Check for a constructed packet to be sent. */
568 if (qp->s_hdrwords != 0) {
569 /*
570 * If no PIO bufs are available, return. An interrupt will
571 * call ipath_ib_piobufavail() when one is available.
572 */
573 _VERBS_INFO("h %u %p\n", qp->s_hdrwords, &qp->s_hdr);
574 _VERBS_INFO("d %u %p %u %p %u %u %u %u\n", qp->s_cur_size,
575 qp->s_cur_sge->sg_list,
576 qp->s_cur_sge->num_sge,
577 qp->s_cur_sge->sge.vaddr,
578 qp->s_cur_sge->sge.sge_length,
579 qp->s_cur_sge->sge.length,
580 qp->s_cur_sge->sge.m,
581 qp->s_cur_sge->sge.n);
582 if (ipath_verbs_send(dev->dd, qp->s_hdrwords,
583 (u32 *) &qp->s_hdr, qp->s_cur_size,
584 qp->s_cur_sge)) {
585 ipath_no_bufs_available(qp, dev);
586 goto bail;
587 }
588 dev->n_unicast_xmit++;
589 /* Record that we sent the packet and s_hdr is empty. */
590 qp->s_hdrwords = 0;
591 }
592
593 /*
594 * The lock is needed to synchronize between setting
595 * qp->s_ack_state, resend timer, and post_send().
596 */
597 spin_lock_irqsave(&qp->s_lock, flags);
598
599 /* Sending responses has higher priority over sending requests. */
600 if (qp->s_ack_state != OP(ACKNOWLEDGE) &&
601 (bth0 = ipath_make_rc_ack(qp, ohdr, pmtu)) != 0)
602 bth2 = qp->s_ack_psn++ & IPS_PSN_MASK;
603 else if (!ipath_make_rc_req(qp, ohdr, pmtu, &bth0, &bth2))
604 goto done;
605
606 spin_unlock_irqrestore(&qp->s_lock, flags);
607
608 /* Construct the header. */
609 extra_bytes = (4 - qp->s_cur_size) & 3;
610 nwords = (qp->s_cur_size + extra_bytes) >> 2;
611 lrh0 = IPS_LRH_BTH;
612 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
613 ipath_make_rc_grh(qp, &qp->remote_ah_attr.grh, nwords);
614 lrh0 = IPS_LRH_GRH;
615 }
616 lrh0 |= qp->remote_ah_attr.sl << 4;
617 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0);
618 qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
619 qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords +
620 SIZE_OF_CRC);
621 qp->s_hdr.lrh[3] = cpu_to_be16(ipath_layer_get_lid(dev->dd));
622 bth0 |= ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
623 bth0 |= extra_bytes << 20;
624 ohdr->bth[0] = cpu_to_be32(bth0);
625 ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
626 ohdr->bth[2] = cpu_to_be32(bth2);
627
628 /* Check for more work to do. */
629 goto again;
630
631done:
632 spin_unlock_irqrestore(&qp->s_lock, flags);
633clear:
634 clear_bit(IPATH_S_BUSY, &qp->s_flags);
635bail:
636 return;
637}
638
639static void send_rc_ack(struct ipath_qp *qp) 507static void send_rc_ack(struct ipath_qp *qp)
640{ 508{
641 struct ipath_ibdev *dev = to_idev(qp->ibqp.device); 509 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
642 u16 lrh0; 510 u16 lrh0;
643 u32 bth0; 511 u32 bth0;
512 u32 hwords;
513 struct ipath_ib_header hdr;
644 struct ipath_other_headers *ohdr; 514 struct ipath_other_headers *ohdr;
645 515
646 /* Construct the header. */ 516 /* Construct the header. */
647 ohdr = &qp->s_hdr.u.oth; 517 ohdr = &hdr.u.oth;
648 lrh0 = IPS_LRH_BTH; 518 lrh0 = IPS_LRH_BTH;
649 /* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4. */ 519 /* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4. */
650 qp->s_hdrwords = 6; 520 hwords = 6;
651 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) { 521 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
652 ipath_make_rc_grh(qp, &qp->remote_ah_attr.grh, 0); 522 hwords += ipath_make_grh(dev, &hdr.u.l.grh,
653 ohdr = &qp->s_hdr.u.l.oth; 523 &qp->remote_ah_attr.grh,
524 hwords, 0);
525 ohdr = &hdr.u.l.oth;
654 lrh0 = IPS_LRH_GRH; 526 lrh0 = IPS_LRH_GRH;
655 } 527 }
656 bth0 = ipath_layer_get_pkey(dev->dd, qp->s_pkey_index); 528 bth0 = ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
@@ -658,15 +530,14 @@ static void send_rc_ack(struct ipath_qp *qp)
658 if (qp->s_ack_state >= OP(COMPARE_SWAP)) { 530 if (qp->s_ack_state >= OP(COMPARE_SWAP)) {
659 bth0 |= IB_OPCODE_ATOMIC_ACKNOWLEDGE << 24; 531 bth0 |= IB_OPCODE_ATOMIC_ACKNOWLEDGE << 24;
660 ohdr->u.at.atomic_ack_eth = cpu_to_be64(qp->s_ack_atomic); 532 ohdr->u.at.atomic_ack_eth = cpu_to_be64(qp->s_ack_atomic);
661 qp->s_hdrwords += sizeof(ohdr->u.at.atomic_ack_eth) / 4; 533 hwords += sizeof(ohdr->u.at.atomic_ack_eth) / 4;
662 } 534 } else
663 else
664 bth0 |= OP(ACKNOWLEDGE) << 24; 535 bth0 |= OP(ACKNOWLEDGE) << 24;
665 lrh0 |= qp->remote_ah_attr.sl << 4; 536 lrh0 |= qp->remote_ah_attr.sl << 4;
666 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0); 537 hdr.lrh[0] = cpu_to_be16(lrh0);
667 qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid); 538 hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
668 qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + SIZE_OF_CRC); 539 hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC);
669 qp->s_hdr.lrh[3] = cpu_to_be16(ipath_layer_get_lid(dev->dd)); 540 hdr.lrh[3] = cpu_to_be16(ipath_layer_get_lid(dev->dd));
670 ohdr->bth[0] = cpu_to_be32(bth0); 541 ohdr->bth[0] = cpu_to_be32(bth0);
671 ohdr->bth[1] = cpu_to_be32(qp->remote_qpn); 542 ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
672 ohdr->bth[2] = cpu_to_be32(qp->s_ack_psn & IPS_PSN_MASK); 543 ohdr->bth[2] = cpu_to_be32(qp->s_ack_psn & IPS_PSN_MASK);
@@ -674,8 +545,7 @@ static void send_rc_ack(struct ipath_qp *qp)
674 /* 545 /*
675 * If we can send the ACK, clear the ACK state. 546 * If we can send the ACK, clear the ACK state.
676 */ 547 */
677 if (ipath_verbs_send(dev->dd, qp->s_hdrwords, (u32 *) &qp->s_hdr, 548 if (ipath_verbs_send(dev->dd, hwords, (u32 *) &hdr, 0, NULL) == 0) {
678 0, NULL) == 0) {
679 qp->s_ack_state = OP(ACKNOWLEDGE); 549 qp->s_ack_state = OP(ACKNOWLEDGE);
680 dev->n_rc_qacks++; 550 dev->n_rc_qacks++;
681 dev->n_unicast_xmit++; 551 dev->n_unicast_xmit++;
@@ -805,7 +675,7 @@ bail:
805 * @qp: the QP 675 * @qp: the QP
806 * @psn: the packet sequence number to restart at 676 * @psn: the packet sequence number to restart at
807 * 677 *
808 * This is called from ipath_rc_rcv() to process an incoming RC ACK 678 * This is called from ipath_rc_rcv_resp() to process an incoming RC ACK
809 * for the given QP. 679 * for the given QP.
810 * Called at interrupt level with the QP s_lock held. 680 * Called at interrupt level with the QP s_lock held.
811 */ 681 */
@@ -1231,18 +1101,12 @@ static inline void ipath_rc_rcv_resp(struct ipath_ibdev *dev,
1231 * ICRC (4). 1101 * ICRC (4).
1232 */ 1102 */
1233 if (unlikely(tlen <= (hdrsize + pad + 8))) { 1103 if (unlikely(tlen <= (hdrsize + pad + 8))) {
1234 /* 1104 /* XXX Need to generate an error CQ entry. */
1235 * XXX Need to generate an error CQ
1236 * entry.
1237 */
1238 goto ack_done; 1105 goto ack_done;
1239 } 1106 }
1240 tlen -= hdrsize + pad + 8; 1107 tlen -= hdrsize + pad + 8;
1241 if (unlikely(tlen != qp->s_len)) { 1108 if (unlikely(tlen != qp->s_len)) {
1242 /* 1109 /* XXX Need to generate an error CQ entry. */
1243 * XXX Need to generate an error CQ
1244 * entry.
1245 */
1246 goto ack_done; 1110 goto ack_done;
1247 } 1111 }
1248 if (!header_in_data) 1112 if (!header_in_data)
@@ -1384,7 +1248,7 @@ static inline int ipath_rc_rcv_error(struct ipath_ibdev *dev,
1384 case OP(COMPARE_SWAP): 1248 case OP(COMPARE_SWAP):
1385 case OP(FETCH_ADD): 1249 case OP(FETCH_ADD):
1386 /* 1250 /*
1387 * Check for the PSN of the last atomic operations 1251 * Check for the PSN of the last atomic operation
1388 * performed and resend the result if found. 1252 * performed and resend the result if found.
1389 */ 1253 */
1390 if ((psn & IPS_PSN_MASK) != qp->r_atomic_psn) { 1254 if ((psn & IPS_PSN_MASK) != qp->r_atomic_psn) {
@@ -1454,11 +1318,6 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1454 } else 1318 } else
1455 psn = be32_to_cpu(ohdr->bth[2]); 1319 psn = be32_to_cpu(ohdr->bth[2]);
1456 } 1320 }
1457 /*
1458 * The opcode is in the low byte when its in network order
1459 * (top byte when in host order).
1460 */
1461 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
1462 1321
1463 /* 1322 /*
1464 * Process responses (ACKs) before anything else. Note that the 1323 * Process responses (ACKs) before anything else. Note that the
@@ -1466,6 +1325,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1466 * queue rather than the expected receive packet sequence number. 1325 * queue rather than the expected receive packet sequence number.
1467 * In other words, this QP is the requester. 1326 * In other words, this QP is the requester.
1468 */ 1327 */
1328 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
1469 if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) && 1329 if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) &&
1470 opcode <= OP(ATOMIC_ACKNOWLEDGE)) { 1330 opcode <= OP(ATOMIC_ACKNOWLEDGE)) {
1471 ipath_rc_rcv_resp(dev, ohdr, data, tlen, qp, opcode, psn, 1331 ipath_rc_rcv_resp(dev, ohdr, data, tlen, qp, opcode, psn,