mirror of https://gitee.com/openkylin/linux.git
qedr: Add wrapping generic structure for qpidr and adjust idr routines.
Today, we are using idr mechanism for QP's only. This patch prepares the qedr_idr stuctures and the idr routines for both QP's and SRQ's. Signed-off-by: Yuval Bason <yuval.bason@cavium.com> Signed-off-by: Michal Kalderon <michal.kalderon@cavium.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:
parent
0625b4ba1a
commit
1212767e23
|
@ -325,8 +325,8 @@ static int qedr_alloc_resources(struct qedr_dev *dev)
|
|||
spin_lock_init(&dev->sgid_lock);
|
||||
|
||||
if (IS_IWARP(dev)) {
|
||||
spin_lock_init(&dev->idr_lock);
|
||||
idr_init(&dev->qpidr);
|
||||
spin_lock_init(&dev->qpidr.idr_lock);
|
||||
idr_init(&dev->qpidr.idr);
|
||||
dev->iwarp_wq = create_singlethread_workqueue("qedr_iwarpq");
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,11 @@ struct qedr_device_attr {
|
|||
|
||||
#define QEDR_ENET_STATE_BIT (0)
|
||||
|
||||
struct qedr_idr {
|
||||
spinlock_t idr_lock; /* Protect idr data-structure */
|
||||
struct idr idr;
|
||||
};
|
||||
|
||||
struct qedr_dev {
|
||||
struct ib_device ibdev;
|
||||
struct qed_dev *cdev;
|
||||
|
@ -165,8 +170,7 @@ struct qedr_dev {
|
|||
struct qedr_cq *gsi_rqcq;
|
||||
struct qedr_qp *gsi_qp;
|
||||
enum qed_rdma_type rdma_type;
|
||||
spinlock_t idr_lock; /* Protect qpidr data-structure */
|
||||
struct idr qpidr;
|
||||
struct qedr_idr qpidr;
|
||||
struct workqueue_struct *iwarp_wq;
|
||||
u16 iwarp_max_mtu;
|
||||
|
||||
|
|
|
@ -491,7 +491,7 @@ int qedr_iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
|
|||
int rc = 0;
|
||||
int i;
|
||||
|
||||
qp = idr_find(&dev->qpidr, conn_param->qpn);
|
||||
qp = idr_find(&dev->qpidr.idr, conn_param->qpn);
|
||||
|
||||
laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
|
||||
raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
|
||||
|
@ -679,7 +679,7 @@ int qedr_iw_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
|
|||
|
||||
DP_DEBUG(dev, QEDR_MSG_IWARP, "Accept on qpid=%d\n", conn_param->qpn);
|
||||
|
||||
qp = idr_find(&dev->qpidr, conn_param->qpn);
|
||||
qp = idr_find(&dev->qpidr.idr, conn_param->qpn);
|
||||
if (!qp) {
|
||||
DP_ERR(dev, "Invalid QP number %d\n", conn_param->qpn);
|
||||
return -EINVAL;
|
||||
|
@ -737,9 +737,9 @@ void qedr_iw_qp_rem_ref(struct ib_qp *ibqp)
|
|||
struct qedr_qp *qp = get_qedr_qp(ibqp);
|
||||
|
||||
if (atomic_dec_and_test(&qp->refcnt)) {
|
||||
spin_lock_irq(&qp->dev->idr_lock);
|
||||
idr_remove(&qp->dev->qpidr, qp->qp_id);
|
||||
spin_unlock_irq(&qp->dev->idr_lock);
|
||||
spin_lock_irq(&qp->dev->qpidr.idr_lock);
|
||||
idr_remove(&qp->dev->qpidr.idr, qp->qp_id);
|
||||
spin_unlock_irq(&qp->dev->qpidr.idr_lock);
|
||||
kfree(qp);
|
||||
}
|
||||
}
|
||||
|
@ -748,5 +748,5 @@ struct ib_qp *qedr_iw_get_qp(struct ib_device *ibdev, int qpn)
|
|||
{
|
||||
struct qedr_dev *dev = get_qedr_dev(ibdev);
|
||||
|
||||
return idr_find(&dev->qpidr, qpn);
|
||||
return idr_find(&dev->qpidr.idr, qpn);
|
||||
}
|
||||
|
|
|
@ -1311,32 +1311,27 @@ static inline void qedr_qp_user_print(struct qedr_dev *dev, struct qedr_qp *qp)
|
|||
qp->usq.buf_len, qp->urq.buf_addr, qp->urq.buf_len);
|
||||
}
|
||||
|
||||
static int qedr_idr_add(struct qedr_dev *dev, void *ptr, u32 id)
|
||||
static int qedr_idr_add(struct qedr_dev *dev, struct qedr_idr *qidr,
|
||||
void *ptr, u32 id)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!rdma_protocol_iwarp(&dev->ibdev, 1))
|
||||
return 0;
|
||||
|
||||
idr_preload(GFP_KERNEL);
|
||||
spin_lock_irq(&dev->idr_lock);
|
||||
spin_lock_irq(&qidr->idr_lock);
|
||||
|
||||
rc = idr_alloc(&dev->qpidr, ptr, id, id + 1, GFP_ATOMIC);
|
||||
rc = idr_alloc(&qidr->idr, ptr, id, id + 1, GFP_ATOMIC);
|
||||
|
||||
spin_unlock_irq(&dev->idr_lock);
|
||||
spin_unlock_irq(&qidr->idr_lock);
|
||||
idr_preload_end();
|
||||
|
||||
return rc < 0 ? rc : 0;
|
||||
}
|
||||
|
||||
static void qedr_idr_remove(struct qedr_dev *dev, u32 id)
|
||||
static void qedr_idr_remove(struct qedr_dev *dev, struct qedr_idr *qidr, u32 id)
|
||||
{
|
||||
if (!rdma_protocol_iwarp(&dev->ibdev, 1))
|
||||
return;
|
||||
|
||||
spin_lock_irq(&dev->idr_lock);
|
||||
idr_remove(&dev->qpidr, id);
|
||||
spin_unlock_irq(&dev->idr_lock);
|
||||
spin_lock_irq(&qidr->idr_lock);
|
||||
idr_remove(&qidr->idr, id);
|
||||
spin_unlock_irq(&qidr->idr_lock);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -1708,9 +1703,11 @@ struct ib_qp *qedr_create_qp(struct ib_pd *ibpd,
|
|||
|
||||
qp->ibqp.qp_num = qp->qp_id;
|
||||
|
||||
rc = qedr_idr_add(dev, qp, qp->qp_id);
|
||||
if (rc)
|
||||
goto err;
|
||||
if (rdma_protocol_iwarp(&dev->ibdev, 1)) {
|
||||
rc = qedr_idr_add(dev, &dev->qpidr, qp, qp->qp_id);
|
||||
if (rc)
|
||||
goto err;
|
||||
}
|
||||
|
||||
return &qp->ibqp;
|
||||
|
||||
|
@ -2279,8 +2276,9 @@ int qedr_destroy_qp(struct ib_qp *ibqp)
|
|||
|
||||
qedr_free_qp_resources(dev, qp);
|
||||
|
||||
if (atomic_dec_and_test(&qp->refcnt)) {
|
||||
qedr_idr_remove(dev, qp->qp_id);
|
||||
if (atomic_dec_and_test(&qp->refcnt) &&
|
||||
rdma_protocol_iwarp(&dev->ibdev, 1)) {
|
||||
qedr_idr_remove(dev, &dev->qpidr, qp->qp_id);
|
||||
kfree(qp);
|
||||
}
|
||||
return rc;
|
||||
|
|
Loading…
Reference in New Issue