aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/ulp/ipoib/ipoib_cm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband/ulp/ipoib/ipoib_cm.c')
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c112
1 files changed, 45 insertions, 67 deletions
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index ddf0c54493c..87610772a97 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -87,7 +87,7 @@ static int ipoib_cm_post_receive(struct net_device *dev, int id)
87 struct ib_recv_wr *bad_wr; 87 struct ib_recv_wr *bad_wr;
88 int i, ret; 88 int i, ret;
89 89
90 priv->cm.rx_wr.wr_id = id | IPOIB_CM_OP_SRQ; 90 priv->cm.rx_wr.wr_id = id | IPOIB_OP_CM | IPOIB_OP_RECV;
91 91
92 for (i = 0; i < IPOIB_CM_RX_SG; ++i) 92 for (i = 0; i < IPOIB_CM_RX_SG; ++i)
93 priv->cm.rx_sge[i].addr = priv->cm.srq_ring[id].mapping[i]; 93 priv->cm.rx_sge[i].addr = priv->cm.srq_ring[id].mapping[i];
@@ -401,7 +401,7 @@ static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
401void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc) 401void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
402{ 402{
403 struct ipoib_dev_priv *priv = netdev_priv(dev); 403 struct ipoib_dev_priv *priv = netdev_priv(dev);
404 unsigned int wr_id = wc->wr_id & ~IPOIB_CM_OP_SRQ; 404 unsigned int wr_id = wc->wr_id & ~(IPOIB_OP_CM | IPOIB_OP_RECV);
405 struct sk_buff *skb, *newskb; 405 struct sk_buff *skb, *newskb;
406 struct ipoib_cm_rx *p; 406 struct ipoib_cm_rx *p;
407 unsigned long flags; 407 unsigned long flags;
@@ -412,7 +412,7 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
412 wr_id, wc->status); 412 wr_id, wc->status);
413 413
414 if (unlikely(wr_id >= ipoib_recvq_size)) { 414 if (unlikely(wr_id >= ipoib_recvq_size)) {
415 if (wr_id == (IPOIB_CM_RX_DRAIN_WRID & ~IPOIB_CM_OP_SRQ)) { 415 if (wr_id == (IPOIB_CM_RX_DRAIN_WRID & ~(IPOIB_OP_CM | IPOIB_OP_RECV))) {
416 spin_lock_irqsave(&priv->lock, flags); 416 spin_lock_irqsave(&priv->lock, flags);
417 list_splice_init(&priv->cm.rx_drain_list, &priv->cm.rx_reap_list); 417 list_splice_init(&priv->cm.rx_drain_list, &priv->cm.rx_reap_list);
418 ipoib_cm_start_rx_drain(priv); 418 ipoib_cm_start_rx_drain(priv);
@@ -498,7 +498,7 @@ static inline int post_send(struct ipoib_dev_priv *priv,
498 priv->tx_sge.addr = addr; 498 priv->tx_sge.addr = addr;
499 priv->tx_sge.length = len; 499 priv->tx_sge.length = len;
500 500
501 priv->tx_wr.wr_id = wr_id; 501 priv->tx_wr.wr_id = wr_id | IPOIB_OP_CM;
502 502
503 return ib_post_send(tx->qp, &priv->tx_wr, &bad_wr); 503 return ib_post_send(tx->qp, &priv->tx_wr, &bad_wr);
504} 504}
@@ -549,20 +549,19 @@ void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_
549 dev->trans_start = jiffies; 549 dev->trans_start = jiffies;
550 ++tx->tx_head; 550 ++tx->tx_head;
551 551
552 if (tx->tx_head - tx->tx_tail == ipoib_sendq_size) { 552 if (++priv->tx_outstanding == ipoib_sendq_size) {
553 ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n", 553 ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n",
554 tx->qp->qp_num); 554 tx->qp->qp_num);
555 netif_stop_queue(dev); 555 netif_stop_queue(dev);
556 set_bit(IPOIB_FLAG_NETIF_STOPPED, &tx->flags);
557 } 556 }
558 } 557 }
559} 558}
560 559
561static void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ipoib_cm_tx *tx, 560void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
562 struct ib_wc *wc)
563{ 561{
564 struct ipoib_dev_priv *priv = netdev_priv(dev); 562 struct ipoib_dev_priv *priv = netdev_priv(dev);
565 unsigned int wr_id = wc->wr_id; 563 struct ipoib_cm_tx *tx = wc->qp->qp_context;
564 unsigned int wr_id = wc->wr_id & ~IPOIB_OP_CM;
566 struct ipoib_tx_buf *tx_req; 565 struct ipoib_tx_buf *tx_req;
567 unsigned long flags; 566 unsigned long flags;
568 567
@@ -587,11 +586,10 @@ static void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ipoib_cm_tx *tx
587 586
588 spin_lock_irqsave(&priv->tx_lock, flags); 587 spin_lock_irqsave(&priv->tx_lock, flags);
589 ++tx->tx_tail; 588 ++tx->tx_tail;
590 if (unlikely(test_bit(IPOIB_FLAG_NETIF_STOPPED, &tx->flags)) && 589 if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
591 tx->tx_head - tx->tx_tail <= ipoib_sendq_size >> 1) { 590 netif_queue_stopped(dev) &&
592 clear_bit(IPOIB_FLAG_NETIF_STOPPED, &tx->flags); 591 test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
593 netif_wake_queue(dev); 592 netif_wake_queue(dev);
594 }
595 593
596 if (wc->status != IB_WC_SUCCESS && 594 if (wc->status != IB_WC_SUCCESS &&
597 wc->status != IB_WC_WR_FLUSH_ERR) { 595 wc->status != IB_WC_WR_FLUSH_ERR) {
@@ -614,11 +612,6 @@ static void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ipoib_cm_tx *tx
614 tx->neigh = NULL; 612 tx->neigh = NULL;
615 } 613 }
616 614
617 /* queue would be re-started anyway when TX is destroyed,
618 * but it makes sense to do it ASAP here. */
619 if (test_and_clear_bit(IPOIB_FLAG_NETIF_STOPPED, &tx->flags))
620 netif_wake_queue(dev);
621
622 if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) { 615 if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
623 list_move(&tx->list, &priv->cm.reap_list); 616 list_move(&tx->list, &priv->cm.reap_list);
624 queue_work(ipoib_workqueue, &priv->cm.reap_task); 617 queue_work(ipoib_workqueue, &priv->cm.reap_task);
@@ -632,19 +625,6 @@ static void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ipoib_cm_tx *tx
632 spin_unlock_irqrestore(&priv->tx_lock, flags); 625 spin_unlock_irqrestore(&priv->tx_lock, flags);
633} 626}
634 627
635static void ipoib_cm_tx_completion(struct ib_cq *cq, void *tx_ptr)
636{
637 struct ipoib_cm_tx *tx = tx_ptr;
638 int n, i;
639
640 ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
641 do {
642 n = ib_poll_cq(cq, IPOIB_NUM_WC, tx->ibwc);
643 for (i = 0; i < n; ++i)
644 ipoib_cm_handle_tx_wc(tx->dev, tx, tx->ibwc + i);
645 } while (n == IPOIB_NUM_WC);
646}
647
648int ipoib_cm_dev_open(struct net_device *dev) 628int ipoib_cm_dev_open(struct net_device *dev)
649{ 629{
650 struct ipoib_dev_priv *priv = netdev_priv(dev); 630 struct ipoib_dev_priv *priv = netdev_priv(dev);
@@ -807,17 +787,18 @@ static int ipoib_cm_rep_handler(struct ib_cm_id *cm_id, struct ib_cm_event *even
807 return 0; 787 return 0;
808} 788}
809 789
810static struct ib_qp *ipoib_cm_create_tx_qp(struct net_device *dev, struct ib_cq *cq) 790static struct ib_qp *ipoib_cm_create_tx_qp(struct net_device *dev, struct ipoib_cm_tx *tx)
811{ 791{
812 struct ipoib_dev_priv *priv = netdev_priv(dev); 792 struct ipoib_dev_priv *priv = netdev_priv(dev);
813 struct ib_qp_init_attr attr = { 793 struct ib_qp_init_attr attr = {
814 .send_cq = cq, 794 .send_cq = priv->cq,
815 .recv_cq = priv->cq, 795 .recv_cq = priv->cq,
816 .srq = priv->cm.srq, 796 .srq = priv->cm.srq,
817 .cap.max_send_wr = ipoib_sendq_size, 797 .cap.max_send_wr = ipoib_sendq_size,
818 .cap.max_send_sge = 1, 798 .cap.max_send_sge = 1,
819 .sq_sig_type = IB_SIGNAL_ALL_WR, 799 .sq_sig_type = IB_SIGNAL_ALL_WR,
820 .qp_type = IB_QPT_RC, 800 .qp_type = IB_QPT_RC,
801 .qp_context = tx
821 }; 802 };
822 803
823 return ib_create_qp(priv->pd, &attr); 804 return ib_create_qp(priv->pd, &attr);
@@ -899,21 +880,7 @@ static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 qpn,
899 goto err_tx; 880 goto err_tx;
900 } 881 }
901 882
902 p->cq = ib_create_cq(priv->ca, ipoib_cm_tx_completion, NULL, p, 883 p->qp = ipoib_cm_create_tx_qp(p->dev, p);
903 ipoib_sendq_size + 1, 0);
904 if (IS_ERR(p->cq)) {
905 ret = PTR_ERR(p->cq);
906 ipoib_warn(priv, "failed to allocate tx cq: %d\n", ret);
907 goto err_cq;
908 }
909
910 ret = ib_req_notify_cq(p->cq, IB_CQ_NEXT_COMP);
911 if (ret) {
912 ipoib_warn(priv, "failed to request completion notification: %d\n", ret);
913 goto err_req_notify;
914 }
915
916 p->qp = ipoib_cm_create_tx_qp(p->dev, p->cq);
917 if (IS_ERR(p->qp)) { 884 if (IS_ERR(p->qp)) {
918 ret = PTR_ERR(p->qp); 885 ret = PTR_ERR(p->qp);
919 ipoib_warn(priv, "failed to allocate tx qp: %d\n", ret); 886 ipoib_warn(priv, "failed to allocate tx qp: %d\n", ret);
@@ -950,12 +917,8 @@ err_modify:
950err_id: 917err_id:
951 p->id = NULL; 918 p->id = NULL;
952 ib_destroy_qp(p->qp); 919 ib_destroy_qp(p->qp);
953err_req_notify:
954err_qp: 920err_qp:
955 p->qp = NULL; 921 p->qp = NULL;
956 ib_destroy_cq(p->cq);
957err_cq:
958 p->cq = NULL;
959err_tx: 922err_tx:
960 return ret; 923 return ret;
961} 924}
@@ -964,6 +927,8 @@ static void ipoib_cm_tx_destroy(struct ipoib_cm_tx *p)
964{ 927{
965 struct ipoib_dev_priv *priv = netdev_priv(p->dev); 928 struct ipoib_dev_priv *priv = netdev_priv(p->dev);
966 struct ipoib_tx_buf *tx_req; 929 struct ipoib_tx_buf *tx_req;
930 unsigned long flags;
931 unsigned long begin;
967 932
968 ipoib_dbg(priv, "Destroy active connection 0x%x head 0x%x tail 0x%x\n", 933 ipoib_dbg(priv, "Destroy active connection 0x%x head 0x%x tail 0x%x\n",
969 p->qp ? p->qp->qp_num : 0, p->tx_head, p->tx_tail); 934 p->qp ? p->qp->qp_num : 0, p->tx_head, p->tx_tail);
@@ -971,27 +936,40 @@ static void ipoib_cm_tx_destroy(struct ipoib_cm_tx *p)
971 if (p->id) 936 if (p->id)
972 ib_destroy_cm_id(p->id); 937 ib_destroy_cm_id(p->id);
973 938
974 if (p->qp)
975 ib_destroy_qp(p->qp);
976
977 if (p->cq)
978 ib_destroy_cq(p->cq);
979
980 if (test_bit(IPOIB_FLAG_NETIF_STOPPED, &p->flags))
981 netif_wake_queue(p->dev);
982
983 if (p->tx_ring) { 939 if (p->tx_ring) {
940 /* Wait for all sends to complete */
941 begin = jiffies;
984 while ((int) p->tx_tail - (int) p->tx_head < 0) { 942 while ((int) p->tx_tail - (int) p->tx_head < 0) {
985 tx_req = &p->tx_ring[p->tx_tail & (ipoib_sendq_size - 1)]; 943 if (time_after(jiffies, begin + 5 * HZ)) {
986 ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len, 944 ipoib_warn(priv, "timing out; %d sends not completed\n",
987 DMA_TO_DEVICE); 945 p->tx_head - p->tx_tail);
988 dev_kfree_skb_any(tx_req->skb); 946 goto timeout;
989 ++p->tx_tail; 947 }
948
949 msleep(1);
990 } 950 }
951 }
991 952
992 kfree(p->tx_ring); 953timeout:
954
955 while ((int) p->tx_tail - (int) p->tx_head < 0) {
956 tx_req = &p->tx_ring[p->tx_tail & (ipoib_sendq_size - 1)];
957 ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len,
958 DMA_TO_DEVICE);
959 dev_kfree_skb_any(tx_req->skb);
960 ++p->tx_tail;
961 spin_lock_irqsave(&priv->tx_lock, flags);
962 if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
963 netif_queue_stopped(p->dev) &&
964 test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
965 netif_wake_queue(p->dev);
966 spin_unlock_irqrestore(&priv->tx_lock, flags);
993 } 967 }
994 968
969 if (p->qp)
970 ib_destroy_qp(p->qp);
971
972 kfree(p->tx_ring);
995 kfree(p); 973 kfree(p);
996} 974}
997 975