u8 redirect_seq_cnt;
        /* ctxt rcvhdrq head offset */
        u32 head;
-       /* lookaside fields */
-       struct rvt_qp *lookaside_qp;
-       u32 lookaside_qpn;
        /* QPs waiting for context processing */
        struct list_head qp_wait_list;
 #ifdef CONFIG_DEBUG_FS
 
                struct qib_ib_header *hdr = (struct qib_ib_header *) rhdr;
                struct qib_other_headers *ohdr = NULL;
                struct qib_ibport *ibp = &ppd->ibport_data;
+               struct qib_devdata *dd = ppd->dd;
+               struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
                struct rvt_qp *qp = NULL;
                u32 tlen = qib_hdrget_length_in_bytes(rhf_addr);
                u16 lid  = be16_to_cpu(hdr->lrh[1]);
                if (qp_num != QIB_MULTICAST_QPN) {
                        int ruc_res;
 
-                       qp = qib_lookup_qpn(ibp, qp_num);
-                       if (!qp)
+                       rcu_read_lock();
+                       qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
+                       if (!qp) {
+                               rcu_read_unlock();
                                goto drop;
+                       }
 
                        /*
                         * Handle only RC QPs - for other QP types drop error
 
 unlock:
                        spin_unlock(&qp->r_lock);
-                       /*
-                        * Notify qib_destroy_qp() if it is waiting
-                        * for us to finish.
-                        */
-                       if (atomic_dec_and_test(&qp->refcount))
-                               wake_up(&qp->wait);
+                       rcu_read_unlock();
                } /* Unicast QP */
        } /* Valid packet with TIDErr */
 
                        updegr = 0;
                }
        }
-       /*
-        * Notify qib_destroy_qp() if it is waiting
-        * for lookaside_qp to finish.
-        */
-       if (rcd->lookaside_qp) {
-               if (atomic_dec_and_test(&rcd->lookaside_qp->refcount))
-                       wake_up(&rcd->lookaside_qp->wait);
-               rcd->lookaside_qp = NULL;
-       }
 
        rcd->head = l;
 
 
 
 #include <linux/err.h>
 #include <linux/vmalloc.h>
-#include <linux/jhash.h>
 #include <rdma/rdma_vt.h>
 #ifdef CONFIG_DEBUG_FS
 #include <linux/seq_file.h>
 
 static inline unsigned qpn_hash(struct qib_ibdev *dev, u32 qpn)
 {
-       return jhash_1word(qpn, dev->qp_rnd) &
-               (dev->rdi.qp_dev->qp_table_size - 1);
+       return hash_32(qpn, dev->rdi.qp_dev->qp_table_bits);
 }
 
 
        spin_unlock_irqrestore(&dev->rdi.qp_dev->qpt_lock, flags);
        if (removed) {
                synchronize_rcu();
-               atomic_dec(&qp->refcount);
+               if (atomic_dec_and_test(&qp->refcount))
+                       wake_up(&qp->wait);
        }
 }
 
        return qp_inuse;
 }
 
-/**
- * qib_lookup_qpn - return the QP with the given QPN
- * @qpt: the QP table
- * @qpn: the QP number to look up
- *
- * The caller is responsible for decrementing the QP reference count
- * when done.
- */
-struct rvt_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn)
-{
-       struct rvt_qp *qp = NULL;
-
-       rcu_read_lock();
-       if (unlikely(qpn <= 1)) {
-               if (qpn == 0)
-                       qp = rcu_dereference(ibp->rvp.qp[0]);
-               else
-                       qp = rcu_dereference(ibp->rvp.qp[1]);
-               if (qp)
-                       atomic_inc(&qp->refcount);
-       } else {
-               struct qib_ibdev *dev = &ppd_from_ibp(ibp)->dd->verbs_dev;
-               unsigned n = qpn_hash(dev, qpn);
-
-               for (qp = rcu_dereference(dev->rdi.qp_dev->qp_table[n]); qp;
-                       qp = rcu_dereference(qp->next))
-                       if (qp->ibqp.qp_num == qpn) {
-                               atomic_inc(&qp->refcount);
-                               break;
-                       }
-       }
-       rcu_read_unlock();
-       return qp;
-}
-
 void notify_qp_reset(struct rvt_qp *qp)
 {
        struct qib_qp_priv *priv = qp->priv;
 
 static void qib_ruc_loopback(struct rvt_qp *sqp)
 {
        struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
+       struct qib_pportdata *ppd = ppd_from_ibp(ibp);
+       struct qib_devdata *dd = ppd->dd;
+       struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
        struct rvt_qp *qp;
        struct rvt_swqe *wqe;
        struct rvt_sge *sge;
        int release;
        int ret;
 
+       rcu_read_lock();
        /*
         * Note that we check the responder QP state after
         * checking the requester's state.
         */
-       qp = qib_lookup_qpn(ibp, sqp->remote_qpn);
+       qp = rvt_lookup_qpn(rdi, &ibp->rvp, sqp->remote_qpn);
+       if (!qp)
+               goto done;
 
        spin_lock_irqsave(&sqp->s_lock, flags);
 
 unlock:
        spin_unlock_irqrestore(&sqp->s_lock, flags);
 done:
-       if (qp && atomic_dec_and_test(&qp->refcount))
-               wake_up(&qp->wait);
+       rcu_read_unlock();
 }
 
 /**
 
 static void qib_ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
 {
        struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
-       struct qib_pportdata *ppd;
+       struct qib_pportdata *ppd = ppd_from_ibp(ibp);
+       struct qib_devdata *dd = ppd->dd;
+       struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
        struct rvt_qp *qp;
        struct ib_ah_attr *ah_attr;
        unsigned long flags;
        u32 length;
        enum ib_qp_type sqptype, dqptype;
 
-       qp = qib_lookup_qpn(ibp, swqe->ud_wr.remote_qpn);
+       rcu_read_lock();
+       qp = rvt_lookup_qpn(rdi, &ibp->rvp, swqe->ud_wr.remote_qpn);
        if (!qp) {
                ibp->rvp.n_pkt_drops++;
+               rcu_read_unlock();
                return;
        }
 
 bail_unlock:
        spin_unlock_irqrestore(&qp->r_lock, flags);
 drop:
-       if (atomic_dec_and_test(&qp->refcount))
-               wake_up(&qp->wait);
+       rcu_read_unlock();
 }
 
 /**
 
        struct qib_pportdata *ppd = rcd->ppd;
        struct qib_ibport *ibp = &ppd->ibport_data;
        struct qib_ib_header *hdr = rhdr;
+       struct qib_devdata *dd = ppd->dd;
+       struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
        struct qib_other_headers *ohdr;
        struct rvt_qp *qp;
        u32 qp_num;
                if (atomic_dec_return(&mcast->refcount) <= 1)
                        wake_up(&mcast->wait);
        } else {
-               if (rcd->lookaside_qp) {
-                       if (rcd->lookaside_qpn != qp_num) {
-                               if (atomic_dec_and_test(
-                                       &rcd->lookaside_qp->refcount))
-                                       wake_up(
-                                        &rcd->lookaside_qp->wait);
-                               rcd->lookaside_qp = NULL;
-                       }
+               rcu_read_lock();
+               qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
+               if (!qp) {
+                       rcu_read_unlock();
+                       goto drop;
                }
-               if (!rcd->lookaside_qp) {
-                       qp = qib_lookup_qpn(ibp, qp_num);
-                       if (!qp)
-                               goto drop;
-                       rcd->lookaside_qp = qp;
-                       rcd->lookaside_qpn = qp_num;
-               } else
-                       qp = rcd->lookaside_qp;
                this_cpu_inc(ibp->pmastats->n_unicast_rcv);
                qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp);
+               rcu_read_unlock();
        }
        return;
 
        qp = tx->qp;
        dev = to_idev(qp->ibqp.device);
 
-       if (atomic_dec_and_test(&qp->refcount))
-               wake_up(&qp->wait);
        if (tx->mr) {
                rvt_put_mr(tx->mr);
                tx->mr = NULL;
        control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
                                       be16_to_cpu(hdr->lrh[0]) >> 12);
        tx->qp = qp;
-       atomic_inc(&qp->refcount);
        tx->wqe = qp->s_wqe;
        tx->mr = qp->s_rdma_mr;
        if (qp->s_rdma_mr)
 
 
 __be32 qib_compute_aeth(struct rvt_qp *qp);
 
-struct rvt_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn);
-
 int qib_destroy_qp(struct ib_qp *ibqp);
 
 int qib_error_qp(struct rvt_qp *qp, enum ib_wc_status err);